author | prr |
Wed, 12 Jan 2011 15:58:15 -0800 | |
changeset 7932 | f4ec6ef455c3 |
parent 7151 | 8db734b13eb6 |
child 7949 | 073e8ab25a02 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#ifdef __linux__ |
|
27 |
#include <string.h> |
|
28 |
#endif /* __linux__ */ |
|
29 |
#include <stdio.h> |
|
30 |
#include <stdlib.h> |
|
31 |
#include <strings.h> |
|
32 |
#include <sys/types.h> |
|
33 |
#include <sys/stat.h> |
|
34 |
#include <sys/mman.h> |
|
35 |
#include <fcntl.h> |
|
36 |
#include <unistd.h> |
|
37 |
#ifdef __solaris__ |
|
38 |
#include <sys/systeminfo.h> |
|
39 |
#endif |
|
40 |
||
41 |
#include <jni.h> |
|
42 |
#include <jni_util.h> |
|
43 |
#include <sun_font_FontManager.h> |
|
44 |
#ifndef HEADLESS |
|
45 |
#include <X11/Xlib.h> |
|
46 |
#include <awt.h> |
|
47 |
#else |
|
48 |
/* locks ought to be included from awt.h */ |
|
49 |
#define AWT_LOCK() |
|
50 |
#define AWT_UNLOCK() |
|
51 |
#endif /* !HEADLESS */ |
|
52 |
||
53 |
#if defined(__linux__) && !defined(MAP_FAILED) |
|
54 |
#define MAP_FAILED ((caddr_t)-1) |
|
55 |
#endif |
|
56 |
||
57 |
#ifndef HEADLESS |
|
58 |
extern Display *awt_display; |
|
59 |
#endif /* !HEADLESS */ |
|
60 |
||
61 |
||
62 |
#define MAXFDIRS 512 /* Max number of directories that contain fonts */ |
|
63 |
||
64 |
#ifndef __linux__ |
|
65 |
/* |
|
66 |
* This can be set in the makefile to "/usr/X11" if so desired. |
|
67 |
*/ |
|
68 |
#ifndef OPENWINHOMELIB |
|
69 |
#define OPENWINHOMELIB "/usr/openwin/lib/" |
|
70 |
#endif |
|
71 |
||
72 |
/* This is all known Solaris X11 directories on Solaris 8, 9 and 10. |
|
73 |
* It is ordered to give precedence to TrueType directories. |
|
74 |
* It is needed if fontconfig is not installed or configured properly. |
|
75 |
*/ |
|
76 |
static char *fullSolarisFontPath[] = { |
|
77 |
OPENWINHOMELIB "X11/fonts/TrueType", |
|
78 |
OPENWINHOMELIB "locale/euro_fonts/X11/fonts/TrueType", |
|
79 |
OPENWINHOMELIB "locale/iso_8859_2/X11/fonts/TrueType", |
|
80 |
OPENWINHOMELIB "locale/iso_8859_5/X11/fonts/TrueType", |
|
81 |
OPENWINHOMELIB "locale/iso_8859_7/X11/fonts/TrueType", |
|
82 |
OPENWINHOMELIB "locale/iso_8859_8/X11/fonts/TrueType", |
|
83 |
OPENWINHOMELIB "locale/iso_8859_9/X11/fonts/TrueType", |
|
84 |
OPENWINHOMELIB "locale/iso_8859_13/X11/fonts/TrueType", |
|
85 |
OPENWINHOMELIB "locale/iso_8859_15/X11/fonts/TrueType", |
|
86 |
OPENWINHOMELIB "locale/ar/X11/fonts/TrueType", |
|
87 |
OPENWINHOMELIB "locale/hi_IN.UTF-8/X11/fonts/TrueType", |
|
88 |
OPENWINHOMELIB "locale/ja/X11/fonts/TT", |
|
89 |
OPENWINHOMELIB "locale/ko/X11/fonts/TrueType", |
|
90 |
OPENWINHOMELIB "locale/ko.UTF-8/X11/fonts/TrueType", |
|
91 |
OPENWINHOMELIB "locale/KOI8-R/X11/fonts/TrueType", |
|
92 |
OPENWINHOMELIB "locale/ru.ansi-1251/X11/fonts/TrueType", |
|
93 |
OPENWINHOMELIB "locale/th_TH/X11/fonts/TrueType", |
|
94 |
OPENWINHOMELIB "locale/zh_TW/X11/fonts/TrueType", |
|
95 |
OPENWINHOMELIB "locale/zh_TW.BIG5/X11/fonts/TT", |
|
96 |
OPENWINHOMELIB "locale/zh_HK.BIG5HK/X11/fonts/TT", |
|
97 |
OPENWINHOMELIB "locale/zh_CN.GB18030/X11/fonts/TrueType", |
|
98 |
OPENWINHOMELIB "locale/zh/X11/fonts/TrueType", |
|
99 |
OPENWINHOMELIB "locale/zh.GBK/X11/fonts/TrueType", |
|
100 |
OPENWINHOMELIB "X11/fonts/Type1", |
|
101 |
OPENWINHOMELIB "X11/fonts/Type1/sun", |
|
102 |
OPENWINHOMELIB "X11/fonts/Type1/sun/outline", |
|
103 |
OPENWINHOMELIB "locale/iso_8859_2/X11/fonts/Type1", |
|
104 |
OPENWINHOMELIB "locale/iso_8859_4/X11/fonts/Type1", |
|
105 |
OPENWINHOMELIB "locale/iso_8859_5/X11/fonts/Type1", |
|
106 |
OPENWINHOMELIB "locale/iso_8859_7/X11/fonts/Type1", |
|
107 |
OPENWINHOMELIB "locale/iso_8859_8/X11/fonts/Type1", |
|
108 |
OPENWINHOMELIB "locale/iso_8859_9/X11/fonts/Type1", |
|
109 |
OPENWINHOMELIB "locale/iso_8859_13/X11/fonts/Type1", |
|
110 |
OPENWINHOMELIB "locale/ar/X11/fonts/Type1", |
|
111 |
NULL, /* terminates the list */ |
|
112 |
}; |
|
113 |
||
114 |
#else /* __linux */ |
|
115 |
/* All the known interesting locations we have discovered on |
|
116 |
* various flavors of Linux |
|
117 |
*/ |
|
118 |
static char *fullLinuxFontPath[] = { |
|
119 |
"/usr/X11R6/lib/X11/fonts/TrueType", /* RH 7.1+ */ |
|
120 |
"/usr/X11R6/lib/X11/fonts/truetype", /* SuSE */ |
|
121 |
"/usr/X11R6/lib/X11/fonts/tt", |
|
122 |
"/usr/X11R6/lib/X11/fonts/TTF", |
|
123 |
"/usr/X11R6/lib/X11/fonts/OTF", /* RH 9.0 (but empty!) */ |
|
124 |
"/usr/share/fonts/ja/TrueType", /* RH 7.2+ */ |
|
125 |
"/usr/share/fonts/truetype", |
|
126 |
"/usr/share/fonts/ko/TrueType", /* RH 9.0 */ |
|
127 |
"/usr/share/fonts/zh_CN/TrueType", /* RH 9.0 */ |
|
128 |
"/usr/share/fonts/zh_TW/TrueType", /* RH 9.0 */ |
|
129 |
"/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType", /* Debian */ |
|
130 |
"/usr/X11R6/lib/X11/fonts/Type1", |
|
131 |
"/usr/share/fonts/default/Type1", /* RH 9.0 */ |
|
132 |
NULL, /* terminates the list */ |
|
133 |
}; |
|
134 |
#endif |
|
135 |
||
136 |
static char **getFontConfigLocations(); |
|
137 |
||
138 |
typedef struct { |
|
139 |
const char *name[MAXFDIRS]; |
|
140 |
int num; |
|
141 |
} fDirRecord, *fDirRecordPtr; |
|
142 |
||
143 |
#ifndef HEADLESS |
|
144 |
||
145 |
/* |
|
146 |
* Returns True if display is local, False of it's remote. |
|
147 |
*/ |
|
148 |
jboolean isDisplayLocal(JNIEnv *env) { |
|
149 |
static jboolean isLocal = False; |
|
150 |
static jboolean isLocalSet = False; |
|
151 |
jboolean ret; |
|
152 |
||
3928 | 153 |
if (! isLocalSet) { |
154 |
jclass geCls = (*env)->FindClass(env, "java/awt/GraphicsEnvironment"); |
|
155 |
jmethodID getLocalGE = (*env)->GetStaticMethodID(env, geCls, |
|
156 |
"getLocalGraphicsEnvironment", |
|
157 |
"()Ljava/awt/GraphicsEnvironment;"); |
|
158 |
jobject ge = (*env)->CallStaticObjectMethod(env, geCls, getLocalGE); |
|
159 |
||
160 |
jclass sgeCls = (*env)->FindClass(env, |
|
161 |
"sun/java2d/SunGraphicsEnvironment"); |
|
162 |
if ((*env)->IsInstanceOf(env, ge, sgeCls)) { |
|
163 |
jmethodID isDisplayLocal = (*env)->GetMethodID(env, sgeCls, |
|
164 |
"isDisplayLocal", |
|
165 |
"()Z"); |
|
166 |
isLocal = (*env)->CallBooleanMethod(env, ge, isDisplayLocal); |
|
167 |
} else { |
|
168 |
isLocal = True; |
|
169 |
} |
|
170 |
isLocalSet = True; |
|
2 | 171 |
} |
172 |
||
173 |
return isLocal; |
|
174 |
} |
|
175 |
||
176 |
static void AddFontsToX11FontPath ( fDirRecord *fDirP ) |
|
177 |
{ |
|
178 |
char *onePath; |
|
179 |
int index, nPaths; |
|
180 |
int origNumPaths, length; |
|
181 |
int origIndex; |
|
182 |
int totalDirCount; |
|
183 |
char **origFontPath; |
|
184 |
char **tempFontPath; |
|
185 |
int doNotAppend; |
|
186 |
int *appendDirList; |
|
187 |
char **newFontPath; |
|
188 |
int err, compareLength; |
|
189 |
char fontDirPath[512]; |
|
190 |
int dirFile; |
|
191 |
||
192 |
doNotAppend = 0; |
|
193 |
||
194 |
if ( fDirP->num == 0 ) return; |
|
195 |
||
196 |
appendDirList = malloc ( fDirP->num * sizeof ( int )); |
|
197 |
if ( appendDirList == NULL ) { |
|
198 |
return; /* if it fails we cannot do much */ |
|
199 |
} |
|
200 |
||
201 |
origFontPath = XGetFontPath ( awt_display, &nPaths ); |
|
202 |
||
203 |
totalDirCount = nPaths; |
|
204 |
origNumPaths = nPaths; |
|
205 |
tempFontPath = origFontPath; |
|
206 |
||
207 |
||
208 |
for (index = 0; index < fDirP->num; index++ ) { |
|
209 |
||
210 |
doNotAppend = 0; |
|
211 |
||
212 |
tempFontPath = origFontPath; |
|
213 |
for ( origIndex = 0; origIndex < nPaths; origIndex++ ) { |
|
214 |
||
215 |
onePath = *tempFontPath; |
|
216 |
||
217 |
compareLength = strlen ( onePath ); |
|
218 |
if ( onePath[compareLength -1] == '/' ) |
|
219 |
compareLength--; |
|
220 |
||
221 |
/* there is a slash at the end of every solaris X11 font path name */ |
|
222 |
if ( strncmp ( onePath, fDirP->name[index], compareLength ) == 0 ) { |
|
223 |
doNotAppend = 1; |
|
224 |
break; |
|
225 |
} |
|
226 |
tempFontPath++; |
|
227 |
} |
|
228 |
||
229 |
appendDirList[index] = 0; |
|
230 |
if ( doNotAppend == 0 ) { |
|
231 |
strcpy ( fontDirPath, fDirP->name[index] ); |
|
232 |
strcat ( fontDirPath, "/fonts.dir" ); |
|
233 |
dirFile = open ( fontDirPath, O_RDONLY, 0 ); |
|
234 |
if ( dirFile == -1 ) { |
|
235 |
doNotAppend = 1; |
|
236 |
} else { |
|
237 |
close ( dirFile ); |
|
238 |
totalDirCount++; |
|
239 |
appendDirList[index] = 1; |
|
240 |
} |
|
241 |
} |
|
242 |
||
243 |
} |
|
244 |
||
245 |
/* if no changes are required do not bother to do a setfontpath */ |
|
246 |
if ( totalDirCount == nPaths ) { |
|
247 |
free ( ( void *) appendDirList ); |
|
248 |
XFreeFontPath ( origFontPath ); |
|
249 |
return; |
|
250 |
} |
|
251 |
||
252 |
||
253 |
newFontPath = malloc ( totalDirCount * sizeof ( char **) ); |
|
254 |
/* if it fails free things and get out */ |
|
255 |
if ( newFontPath == NULL ) { |
|
256 |
free ( ( void *) appendDirList ); |
|
257 |
XFreeFontPath ( origFontPath ); |
|
258 |
return; |
|
259 |
} |
|
260 |
||
261 |
for ( origIndex = 0; origIndex < nPaths; origIndex++ ) { |
|
262 |
onePath = origFontPath[origIndex]; |
|
263 |
newFontPath[origIndex] = onePath; |
|
264 |
} |
|
265 |
||
266 |
/* now add the other font paths */ |
|
267 |
||
268 |
for (index = 0; index < fDirP->num; index++ ) { |
|
269 |
||
270 |
if ( appendDirList[index] == 1 ) { |
|
271 |
||
272 |
/* printf ( "Appending %s\n", fDirP->name[index] ); */ |
|
273 |
||
274 |
onePath = malloc ( ( strlen (fDirP->name[index]) + 2 )* sizeof( char ) ); |
|
275 |
strcpy ( onePath, fDirP->name[index] ); |
|
276 |
strcat ( onePath, "/" ); |
|
277 |
newFontPath[nPaths++] = onePath; |
|
278 |
/* printf ( "The path to be appended is %s\n", onePath ); */ |
|
279 |
} |
|
280 |
} |
|
281 |
||
282 |
/* printf ( "The dir count = %d\n", totalDirCount ); */ |
|
283 |
free ( ( void *) appendDirList ); |
|
284 |
||
285 |
XSetFontPath ( awt_display, newFontPath, totalDirCount ); |
|
286 |
||
287 |
for ( index = origNumPaths; index < totalDirCount; index++ ) { |
|
288 |
free( newFontPath[index] ); |
|
289 |
} |
|
290 |
||
291 |
free ( (void *) newFontPath ); |
|
292 |
XFreeFontPath ( origFontPath ); |
|
293 |
return; |
|
294 |
} |
|
295 |
#endif /* !HEADLESS */ |
|
296 |
||
297 |
||
298 |
#ifndef HEADLESS |
|
299 |
static char **getX11FontPath () |
|
300 |
{ |
|
301 |
char **x11Path, **fontdirs; |
|
302 |
int i, pos, slen, nPaths, numDirs; |
|
303 |
||
304 |
x11Path = XGetFontPath (awt_display, &nPaths); |
|
305 |
||
306 |
/* This isn't ever going to be perfect: the font path may contain |
|
307 |
* much we aren't interested in, but the cost should be moderate |
|
308 |
* Exclude all directories that contain the strings "Speedo","/F3/", |
|
309 |
* "75dpi", "100dpi", "misc" or "bitmap", or don't begin with a "/", |
|
310 |
* the last of which should exclude font servers. |
|
311 |
* Also exclude the user specific ".gnome*" directories which |
|
312 |
* aren't going to contain the system fonts we need. |
|
313 |
* Hopefully we are left only with Type1 and TrueType directories. |
|
314 |
* It doesn't matter much if there are extraneous directories, it'll just |
|
315 |
* cost us a little wasted effort upstream. |
|
316 |
*/ |
|
317 |
fontdirs = (char**)calloc(nPaths+1, sizeof(char*)); |
|
318 |
pos = 0; |
|
319 |
for (i=0; i < nPaths; i++) { |
|
320 |
if (x11Path[i][0] != '/') { |
|
321 |
continue; |
|
322 |
} |
|
323 |
if (strstr(x11Path[i], "/75dpi") != NULL) { |
|
324 |
continue; |
|
325 |
} |
|
326 |
if (strstr(x11Path[i], "/100dpi") != NULL) { |
|
327 |
continue; |
|
328 |
} |
|
329 |
if (strstr(x11Path[i], "/misc") != NULL) { |
|
330 |
continue; |
|
331 |
} |
|
332 |
if (strstr(x11Path[i], "/Speedo") != NULL) { |
|
333 |
continue; |
|
334 |
} |
|
335 |
if (strstr(x11Path[i], ".gnome") != NULL) { |
|
336 |
continue; |
|
337 |
} |
|
338 |
#ifdef __solaris__ |
|
339 |
if (strstr(x11Path[i], "/F3/") != NULL) { |
|
340 |
continue; |
|
341 |
} |
|
342 |
if (strstr(x11Path[i], "bitmap") != NULL) { |
|
343 |
continue; |
|
344 |
} |
|
345 |
#endif |
|
346 |
fontdirs[pos] = strdup(x11Path[i]); |
|
347 |
slen = strlen(fontdirs[pos]); |
|
348 |
if (slen > 0 && fontdirs[pos][slen-1] == '/') { |
|
349 |
fontdirs[pos][slen-1] = '\0'; /* null out trailing "/" */ |
|
350 |
} |
|
351 |
pos++; |
|
352 |
} |
|
353 |
||
354 |
XFreeFontPath(x11Path); |
|
355 |
if (pos == 0) { |
|
356 |
free(fontdirs); |
|
357 |
fontdirs = NULL; |
|
358 |
} |
|
359 |
return fontdirs; |
|
360 |
} |
|
361 |
||
362 |
||
363 |
#endif /* !HEADLESS */ |
|
364 |
||
365 |
#ifdef __linux__ |
|
366 |
/* from awt_LoadLibrary.c */ |
|
367 |
JNIEXPORT jboolean JNICALL AWTIsHeadless(); |
|
368 |
#endif |
|
369 |
||
370 |
/* This eliminates duplicates, at a non-linear but acceptable cost |
|
371 |
* since the lists are expected to be reasonably short, and then |
|
372 |
* deletes references to non-existent directories, and returns |
|
373 |
* a single path consisting of unique font directories. |
|
374 |
*/ |
|
375 |
static char* mergePaths(char **p1, char **p2, char **p3, jboolean noType1) { |
|
376 |
||
377 |
int len1=0, len2=0, len3=0, totalLen=0, numDirs=0, |
|
378 |
currLen, i, j, found, pathLen=0; |
|
379 |
char **ptr, **fontdirs; |
|
380 |
char *fontPath = NULL; |
|
381 |
||
382 |
if (p1 != NULL) { |
|
383 |
ptr = p1; |
|
384 |
while (*ptr++ != NULL) len1++; |
|
385 |
} |
|
386 |
if (p2 != NULL) { |
|
387 |
ptr = p2; |
|
388 |
||
389 |
while (*ptr++ != NULL) len2++; |
|
390 |
} |
|
391 |
if (p3 != NULL) { |
|
392 |
ptr = p3; |
|
393 |
while (*ptr++ != NULL) len3++; |
|
394 |
} |
|
395 |
totalLen = len1+len2+len3; |
|
396 |
fontdirs = (char**)calloc(totalLen, sizeof(char*)); |
|
397 |
||
398 |
for (i=0; i < len1; i++) { |
|
399 |
if (noType1 && strstr(p1[i], "Type1") != NULL) { |
|
400 |
continue; |
|
401 |
} |
|
402 |
fontdirs[numDirs++] = p1[i]; |
|
403 |
} |
|
404 |
||
405 |
currLen = numDirs; /* only compare against previous path dirs */ |
|
406 |
for (i=0; i < len2; i++) { |
|
407 |
if (noType1 && strstr(p2[i], "Type1") != NULL) { |
|
408 |
continue; |
|
409 |
} |
|
410 |
found = 0; |
|
411 |
for (j=0; j < currLen; j++) { |
|
412 |
if (strcmp(fontdirs[j], p2[i]) == 0) { |
|
413 |
found = 1; |
|
414 |
break; |
|
415 |
} |
|
416 |
} |
|
417 |
if (!found) { |
|
418 |
fontdirs[numDirs++] = p2[i]; |
|
419 |
} |
|
420 |
} |
|
421 |
||
422 |
currLen = numDirs; /* only compare against previous path dirs */ |
|
423 |
for (i=0; i < len3; i++) { |
|
424 |
if (noType1 && strstr(p3[i], "Type1") != NULL) { |
|
425 |
continue; |
|
426 |
} |
|
427 |
found = 0; |
|
428 |
for (j=0; j < currLen; j++) { |
|
429 |
if (strcmp(fontdirs[j], p3[i]) == 0) { |
|
430 |
found = 1; |
|
431 |
break; |
|
432 |
} |
|
433 |
} |
|
434 |
if (!found) { |
|
435 |
fontdirs[numDirs++] = p3[i]; |
|
436 |
} |
|
437 |
} |
|
438 |
||
439 |
/* Now fontdirs contains unique dirs and numDirs records how many. |
|
440 |
* What we don't know is if they all exist. On reflection I think |
|
441 |
* this isn't an issue, so for now I will return all these locations, |
|
442 |
* converted to one string */ |
|
443 |
for (i=0; i<numDirs; i++) { |
|
444 |
pathLen += (strlen(fontdirs[i]) + 1); |
|
445 |
} |
|
446 |
if (pathLen > 0 && (fontPath = malloc(pathLen))) { |
|
447 |
*fontPath = '\0'; |
|
448 |
for (i = 0; i<numDirs; i++) { |
|
449 |
if (i != 0) { |
|
450 |
strcat(fontPath, ":"); |
|
451 |
} |
|
452 |
strcat(fontPath, fontdirs[i]); |
|
453 |
} |
|
454 |
} |
|
455 |
free (fontdirs); |
|
456 |
||
457 |
return fontPath; |
|
458 |
} |
|
459 |
||
460 |
/* |
|
461 |
* The goal of this function is to find all "system" fonts which |
|
462 |
* are needed by the JRE to display text in supported locales etc, and |
|
463 |
* to support APIs which allow users to enumerate all system fonts and use |
|
464 |
* them from their Java applications. |
|
465 |
* The preferred mechanism is now using the new "fontconfig" library |
|
466 |
* This exists on newer versions of Linux and Solaris (S10 and above) |
|
467 |
* The library is dynamically located. The results are merged with |
|
468 |
* a set of "known" locations and with the X11 font path, if running in |
|
469 |
* a local X11 environment. |
|
470 |
* The hardwired paths are built into the JDK binary so as new font locations |
|
471 |
* are created on a host plaform for them to be located by the JRE they will |
|
472 |
* need to be added ito the host's font configuration database, typically |
|
473 |
* /etc/fonts/local.conf, and to ensure that directory contains a fonts.dir |
|
474 |
* NB: Fontconfig also depends heavily for performance on the host O/S |
|
475 |
* maintaining up to date caches. |
|
476 |
* This is consistent with the requirements of the desktop environments |
|
477 |
* on these OSes. |
|
478 |
* This also frees us from X11 APIs as JRE is required to function in |
|
479 |
* a "headless" mode where there is no Xserver. |
|
480 |
*/ |
|
481 |
static char *getPlatformFontPathChars(JNIEnv *env, jboolean noType1) { |
|
482 |
||
483 |
char **fcdirs = NULL, **x11dirs = NULL, **knowndirs = NULL, *path = NULL; |
|
484 |
||
485 |
/* As of 1.5 we try to use fontconfig on both Solaris and Linux. |
|
486 |
* If its not available NULL is returned. |
|
487 |
*/ |
|
488 |
fcdirs = getFontConfigLocations(); |
|
489 |
||
490 |
#ifdef __linux__ |
|
491 |
knowndirs = fullLinuxFontPath; |
|
492 |
#else /* IF SOLARIS */ |
|
493 |
knowndirs = fullSolarisFontPath; |
|
494 |
#endif |
|
495 |
||
496 |
/* REMIND: this code requires to be executed when the GraphicsEnvironment |
|
497 |
* is already initialised. That is always true, but if it were not so, |
|
498 |
* this code could throw an exception and the fontpath would fail to |
|
499 |
* be initialised. |
|
500 |
*/ |
|
501 |
#ifndef HEADLESS |
|
502 |
#ifdef __linux__ /* There's no headless build on linux ... */ |
|
503 |
if (!AWTIsHeadless()) { /* .. so need to call a function to check */ |
|
504 |
#endif |
|
7932
f4ec6ef455c3
6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents:
7151
diff
changeset
|
505 |
/* Using the X11 font path to locate font files is now a fallback |
f4ec6ef455c3
6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents:
7151
diff
changeset
|
506 |
* useful only if fontconfig failed, or is incomplete. So we could |
f4ec6ef455c3
6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents:
7151
diff
changeset
|
507 |
* remove this code completely and the consequences should be rare |
f4ec6ef455c3
6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents:
7151
diff
changeset
|
508 |
* and non-fatal. If this happens, then the calling Java code can |
f4ec6ef455c3
6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents:
7151
diff
changeset
|
509 |
* be modified to no longer require that the AWT lock (the X11GE) |
f4ec6ef455c3
6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents:
7151
diff
changeset
|
510 |
* be initialised prior to calling this code. |
f4ec6ef455c3
6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents:
7151
diff
changeset
|
511 |
*/ |
2 | 512 |
AWT_LOCK(); |
513 |
if (isDisplayLocal(env)) { |
|
514 |
x11dirs = getX11FontPath(); |
|
515 |
} |
|
516 |
AWT_UNLOCK(); |
|
517 |
#ifdef __linux__ |
|
518 |
} |
|
519 |
#endif |
|
520 |
#endif /* !HEADLESS */ |
|
521 |
path = mergePaths(fcdirs, x11dirs, knowndirs, noType1); |
|
522 |
if (fcdirs != NULL) { |
|
523 |
char **p = fcdirs; |
|
524 |
while (*p != NULL) free(*p++); |
|
525 |
free(fcdirs); |
|
526 |
} |
|
527 |
||
528 |
if (x11dirs != NULL) { |
|
529 |
char **p = x11dirs; |
|
530 |
while (*p != NULL) free(*p++); |
|
531 |
free(x11dirs); |
|
532 |
} |
|
533 |
||
534 |
return path; |
|
535 |
} |
|
536 |
||
7932
f4ec6ef455c3
6958221: java.awt.Font.getFamily() leads to JVM crash on Linux on JDK7 for "custom" fonts
prr
parents:
7151
diff
changeset
|
537 |
JNIEXPORT jstring JNICALL Java_sun_awt_X11FontManager_getFontPathNative |
3928 | 538 |
(JNIEnv *env, jobject thiz, jboolean noType1) { |
2 | 539 |
jstring ret; |
540 |
static char *ptr = NULL; /* retain result across calls */ |
|
541 |
||
542 |
if (ptr == NULL) { |
|
543 |
ptr = getPlatformFontPathChars(env, noType1); |
|
544 |
} |
|
545 |
ret = (*env)->NewStringUTF(env, ptr); |
|
546 |
return ret; |
|
547 |
} |
|
548 |
||
549 |
#include <dlfcn.h> |
|
550 |
#ifndef __linux__ /* i.e. is solaris */ |
|
551 |
#include <link.h> |
|
552 |
#endif |
|
553 |
||
554 |
#include "fontconfig.h" |
|
555 |
||
556 |
||
557 |
static void* openFontConfig() { |
|
558 |
||
559 |
char *homeEnv; |
|
560 |
static char *homeEnvStr = "HOME="; /* must be static */ |
|
561 |
void* libfontconfig = NULL; |
|
562 |
#ifdef __solaris__ |
|
563 |
#define SYSINFOBUFSZ 8 |
|
564 |
char sysinfobuf[SYSINFOBUFSZ]; |
|
565 |
#endif |
|
566 |
||
567 |
/* Private workaround to not use fontconfig library. |
|
568 |
* May be useful during testing/debugging |
|
569 |
*/ |
|
570 |
char *useFC = getenv("USE_J2D_FONTCONFIG"); |
|
571 |
if (useFC != NULL && !strcmp(useFC, "no")) { |
|
572 |
return NULL; |
|
573 |
} |
|
574 |
||
575 |
#ifdef __solaris__ |
|
576 |
/* fontconfig is likely not properly configured on S8/S9 - skip it, |
|
577 |
* although allow user to override this behaviour with an env. variable |
|
578 |
* ie if USE_J2D_FONTCONFIG=yes then we skip this test. |
|
579 |
* NB "4" is the length of a string which matches our patterns. |
|
580 |
*/ |
|
581 |
if (useFC == NULL || strcmp(useFC, "yes")) { |
|
582 |
if (sysinfo(SI_RELEASE, sysinfobuf, SYSINFOBUFSZ) == 4) { |
|
583 |
if ((!strcmp(sysinfobuf, "5.8") || !strcmp(sysinfobuf, "5.9"))) { |
|
584 |
return NULL; |
|
585 |
} |
|
586 |
} |
|
587 |
} |
|
588 |
#endif |
|
589 |
/* 64 bit sparc should pick up the right version from the lib path. |
|
590 |
* New features may be added to libfontconfig, this is expected to |
|
591 |
* be compatible with old features, but we may need to start |
|
592 |
* distinguishing the library version, to know whether to expect |
|
593 |
* certain symbols - and functionality - to be available. |
|
594 |
* Also add explicit search for .so.1 in case .so symlink doesn't exist. |
|
595 |
*/ |
|
596 |
libfontconfig = dlopen("libfontconfig.so.1", RTLD_LOCAL|RTLD_LAZY); |
|
597 |
if (libfontconfig == NULL) { |
|
598 |
libfontconfig = dlopen("libfontconfig.so", RTLD_LOCAL|RTLD_LAZY); |
|
599 |
if (libfontconfig == NULL) { |
|
600 |
return NULL; |
|
601 |
} |
|
602 |
} |
|
603 |
||
604 |
/* Version 1.0 of libfontconfig crashes if HOME isn't defined in |
|
605 |
* the environment. This should generally never happen, but we can't |
|
606 |
* control it, and can't control the version of fontconfig, so iff |
|
607 |
* its not defined we set it to an empty value which is sufficient |
|
608 |
* to prevent a crash. I considered unsetting it before exit, but |
|
609 |
* it doesn't appear to work on Solaris, so I will leave it set. |
|
610 |
*/ |
|
611 |
homeEnv = getenv("HOME"); |
|
612 |
if (homeEnv == NULL) { |
|
613 |
putenv(homeEnvStr); |
|
614 |
} |
|
615 |
||
616 |
return libfontconfig; |
|
617 |
} |
|
618 |
||
619 |
typedef void* (FcFiniFuncType)(); |
|
620 |
||
621 |
static void closeFontConfig(void* libfontconfig, jboolean fcFini) { |
|
622 |
||
623 |
/* NB FcFini is not in (eg) the Solaris 10 version of fontconfig. Its not |
|
624 |
* clear if this means we are really leaking resources in those cases |
|
625 |
* but it seems we should call this function when its available. |
|
626 |
* But since the Swing GTK code may be still accessing the lib, its probably |
|
627 |
* safest for now to just let this "leak" rather than potentially |
|
628 |
* concurrently free global data still in use by other code. |
|
629 |
*/ |
|
630 |
#if 0 |
|
631 |
if (fcFini) { /* release resources */ |
|
632 |
FcFiniFuncType FcFini = (FcFiniFuncType)dlsym(libfontconfig, "FcFini"); |
|
633 |
||
634 |
if (FcFini != NULL) { |
|
635 |
(*FcFini)(); |
|
636 |
} |
|
637 |
} |
|
638 |
#endif |
|
639 |
dlclose(libfontconfig); |
|
640 |
} |
|
641 |
||
642 |
typedef FcConfig* (*FcInitLoadConfigFuncType)(); |
|
643 |
typedef FcPattern* (*FcPatternBuildFuncType)(FcPattern *orig, ...); |
|
644 |
typedef FcObjectSet* (*FcObjectSetFuncType)(const char *first, ...); |
|
645 |
typedef FcFontSet* (*FcFontListFuncType)(FcConfig *config, |
|
646 |
FcPattern *p, |
|
647 |
FcObjectSet *os); |
|
648 |
typedef FcResult (*FcPatternGetBoolFuncType)(const FcPattern *p, |
|
649 |
const char *object, |
|
650 |
int n, |
|
651 |
FcBool *b); |
|
652 |
typedef FcResult (*FcPatternGetIntegerFuncType)(const FcPattern *p, |
|
653 |
const char *object, |
|
654 |
int n, |
|
655 |
int *i); |
|
656 |
typedef FcResult (*FcPatternGetStringFuncType)(const FcPattern *p, |
|
657 |
const char *object, |
|
658 |
int n, |
|
659 |
FcChar8 ** s); |
|
660 |
typedef FcChar8* (*FcStrDirnameFuncType)(const FcChar8 *file); |
|
661 |
typedef void (*FcPatternDestroyFuncType)(FcPattern *p); |
|
662 |
typedef void (*FcFontSetDestroyFuncType)(FcFontSet *s); |
|
663 |
typedef FcPattern* (*FcNameParseFuncType)(const FcChar8 *name); |
|
664 |
typedef FcBool (*FcPatternAddStringFuncType)(FcPattern *p, |
|
665 |
const char *object, |
|
666 |
const FcChar8 *s); |
|
667 |
typedef void (*FcDefaultSubstituteFuncType)(FcPattern *p); |
|
668 |
typedef FcBool (*FcConfigSubstituteFuncType)(FcConfig *config, |
|
669 |
FcPattern *p, |
|
670 |
FcMatchKind kind); |
|
671 |
typedef FcPattern* (*FcFontMatchFuncType)(FcConfig *config, |
|
672 |
FcPattern *p, |
|
673 |
FcResult *result); |
|
674 |
typedef FcFontSet* (*FcFontSetCreateFuncType)(); |
|
675 |
typedef FcBool (*FcFontSetAddFuncType)(FcFontSet *s, FcPattern *font); |
|
676 |
||
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
677 |
typedef FcResult (*FcPatternGetCharSetFuncType)(FcPattern *p, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
678 |
const char *object, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
679 |
int n, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
680 |
FcCharSet **c); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
681 |
typedef FcFontSet* (*FcFontSortFuncType)(FcConfig *config, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
682 |
FcPattern *p, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
683 |
FcBool trim, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
684 |
FcCharSet **csp, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
685 |
FcResult *result); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
686 |
typedef FcCharSet* (*FcCharSetUnionFuncType)(const FcCharSet *a, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
687 |
const FcCharSet *b); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
688 |
typedef FcChar32 (*FcCharSetSubtractCountFuncType)(const FcCharSet *a, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
689 |
const FcCharSet *b); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
690 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
691 |
typedef int (*FcGetVersionFuncType)(); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
692 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
693 |
typedef FcStrList* (*FcConfigGetCacheDirsFuncType)(FcConfig *config); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
694 |
typedef FcChar8* (*FcStrListNextFuncType)(FcStrList *list); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
695 |
typedef FcChar8* (*FcStrListDoneFuncType)(FcStrList *list); |
2 | 696 |
|
697 |
static char **getFontConfigLocations() { |
|
698 |
||
699 |
char **fontdirs; |
|
700 |
int numdirs = 0; |
|
701 |
FcInitLoadConfigFuncType FcInitLoadConfig; |
|
702 |
FcPatternBuildFuncType FcPatternBuild; |
|
703 |
FcObjectSetFuncType FcObjectSetBuild; |
|
704 |
FcFontListFuncType FcFontList; |
|
705 |
FcPatternGetStringFuncType FcPatternGetString; |
|
706 |
FcStrDirnameFuncType FcStrDirname; |
|
707 |
FcPatternDestroyFuncType FcPatternDestroy; |
|
708 |
FcFontSetDestroyFuncType FcFontSetDestroy; |
|
709 |
||
710 |
FcConfig *fontconfig; |
|
711 |
FcPattern *pattern; |
|
712 |
FcObjectSet *objset; |
|
713 |
FcFontSet *fontSet; |
|
714 |
FcStrList *strList; |
|
715 |
FcChar8 *str; |
|
716 |
int i, f, found, len=0; |
|
717 |
char **fontPath; |
|
718 |
||
719 |
void* libfontconfig = openFontConfig(); |
|
720 |
||
721 |
if (libfontconfig == NULL) { |
|
722 |
return NULL; |
|
723 |
} |
|
724 |
||
725 |
FcPatternBuild = |
|
726 |
(FcPatternBuildFuncType)dlsym(libfontconfig, "FcPatternBuild"); |
|
727 |
FcObjectSetBuild = |
|
728 |
(FcObjectSetFuncType)dlsym(libfontconfig, "FcObjectSetBuild"); |
|
729 |
FcFontList = |
|
730 |
(FcFontListFuncType)dlsym(libfontconfig, "FcFontList"); |
|
731 |
FcPatternGetString = |
|
732 |
(FcPatternGetStringFuncType)dlsym(libfontconfig, "FcPatternGetString"); |
|
733 |
FcStrDirname = |
|
734 |
(FcStrDirnameFuncType)dlsym(libfontconfig, "FcStrDirname"); |
|
735 |
FcPatternDestroy = |
|
736 |
(FcPatternDestroyFuncType)dlsym(libfontconfig, "FcPatternDestroy"); |
|
737 |
FcFontSetDestroy = |
|
738 |
(FcFontSetDestroyFuncType)dlsym(libfontconfig, "FcFontSetDestroy"); |
|
739 |
||
740 |
if (FcPatternBuild == NULL || |
|
741 |
FcObjectSetBuild == NULL || |
|
742 |
FcPatternGetString == NULL || |
|
743 |
FcFontList == NULL || |
|
744 |
FcStrDirname == NULL || |
|
745 |
FcPatternDestroy == NULL || |
|
746 |
FcFontSetDestroy == NULL) { /* problem with the library: return. */ |
|
747 |
closeFontConfig(libfontconfig, JNI_FALSE); |
|
748 |
return NULL; |
|
749 |
} |
|
750 |
||
751 |
/* Make calls into the fontconfig library to build a search for |
|
752 |
* outline fonts, and to get the set of full file paths from the matches. |
|
753 |
* This set is returned from the call to FcFontList(..) |
|
754 |
* We allocate an array of char* pointers sufficient to hold all |
|
755 |
* the matches + 1 extra which ensures there will be a NULL after all |
|
756 |
* valid entries. |
|
757 |
* We call FcStrDirname strip the file name from the path, and |
|
758 |
* check if we have yet seen this directory. If not we add a pointer to |
|
759 |
* it into our array of char*. Note that FcStrDirname returns newly |
|
760 |
* allocated storage so we can use this in the return char** value. |
|
761 |
* Finally we clean up, freeing allocated resources, and return the |
|
762 |
* array of unique directories. |
|
763 |
*/ |
|
764 |
pattern = (*FcPatternBuild)(NULL, FC_OUTLINE, FcTypeBool, FcTrue, NULL); |
|
765 |
objset = (*FcObjectSetBuild)(FC_FILE, NULL); |
|
766 |
fontSet = (*FcFontList)(NULL, pattern, objset); |
|
767 |
fontdirs = (char**)calloc(fontSet->nfont+1, sizeof(char*)); |
|
768 |
for (f=0; f < fontSet->nfont; f++) { |
|
769 |
FcChar8 *file; |
|
770 |
FcChar8 *dir; |
|
771 |
if ((*FcPatternGetString)(fontSet->fonts[f], FC_FILE, 0, &file) == |
|
772 |
FcResultMatch) { |
|
773 |
dir = (*FcStrDirname)(file); |
|
774 |
found = 0; |
|
775 |
for (i=0;i<numdirs; i++) { |
|
776 |
if (strcmp(fontdirs[i], (char*)dir) == 0) { |
|
777 |
found = 1; |
|
778 |
break; |
|
779 |
} |
|
780 |
} |
|
781 |
if (!found) { |
|
782 |
fontdirs[numdirs++] = (char*)dir; |
|
783 |
} else { |
|
784 |
free((char*)dir); |
|
785 |
} |
|
786 |
} |
|
787 |
} |
|
788 |
||
789 |
/* Free memory and close the ".so" */ |
|
790 |
(*FcFontSetDestroy)(fontSet); |
|
791 |
(*FcPatternDestroy)(pattern); |
|
792 |
closeFontConfig(libfontconfig, JNI_TRUE); |
|
793 |
return fontdirs; |
|
794 |
} |
|
795 |
||
796 |
/* These are copied from sun.awt.SunHints. |
|
797 |
* Consider initialising them as ints using JNI for more robustness. |
|
798 |
*/ |
|
799 |
#define TEXT_AA_OFF 1 |
|
800 |
#define TEXT_AA_ON 2 |
|
801 |
#define TEXT_AA_LCD_HRGB 4 |
|
802 |
#define TEXT_AA_LCD_HBGR 5 |
|
803 |
#define TEXT_AA_LCD_VRGB 6 |
|
804 |
#define TEXT_AA_LCD_VBGR 7 |
|
805 |
||
806 |
JNIEXPORT jint JNICALL |
|
3928 | 807 |
Java_sun_font_FontConfigManager_getFontConfigAASettings |
2 | 808 |
(JNIEnv *env, jclass obj, jstring localeStr, jstring fcNameStr) { |
809 |
||
810 |
FcNameParseFuncType FcNameParse; |
|
811 |
FcPatternAddStringFuncType FcPatternAddString; |
|
812 |
FcConfigSubstituteFuncType FcConfigSubstitute; |
|
813 |
FcDefaultSubstituteFuncType FcDefaultSubstitute; |
|
814 |
FcFontMatchFuncType FcFontMatch; |
|
815 |
FcPatternGetBoolFuncType FcPatternGetBool; |
|
816 |
FcPatternGetIntegerFuncType FcPatternGetInteger; |
|
817 |
FcPatternDestroyFuncType FcPatternDestroy; |
|
818 |
||
819 |
FcPattern *pattern, *matchPattern; |
|
820 |
FcResult result; |
|
821 |
FcBool antialias = FcFalse; |
|
822 |
int rgba = 0; |
|
823 |
const char *locale=NULL, *fcName=NULL; |
|
824 |
void* libfontconfig; |
|
825 |
||
826 |
if (fcNameStr == NULL || localeStr == NULL) { |
|
827 |
return -1; |
|
828 |
} |
|
829 |
||
830 |
fcName = (*env)->GetStringUTFChars(env, fcNameStr, 0); |
|
831 |
if (fcName == NULL) { |
|
832 |
return -1; |
|
833 |
} |
|
834 |
locale = (*env)->GetStringUTFChars(env, localeStr, 0); |
|
835 |
||
836 |
if ((libfontconfig = openFontConfig()) == NULL) { |
|
837 |
(*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName); |
|
838 |
if (locale) { |
|
839 |
(*env)->ReleaseStringUTFChars (env, localeStr,(const char*)locale); |
|
840 |
} |
|
841 |
return -1; |
|
842 |
} |
|
843 |
||
844 |
FcNameParse = (FcNameParseFuncType)dlsym(libfontconfig, "FcNameParse"); |
|
845 |
FcPatternAddString = |
|
846 |
(FcPatternAddStringFuncType)dlsym(libfontconfig, "FcPatternAddString"); |
|
847 |
FcConfigSubstitute = |
|
848 |
(FcConfigSubstituteFuncType)dlsym(libfontconfig, "FcConfigSubstitute"); |
|
849 |
FcDefaultSubstitute = (FcDefaultSubstituteFuncType) |
|
850 |
dlsym(libfontconfig, "FcDefaultSubstitute"); |
|
851 |
FcFontMatch = (FcFontMatchFuncType)dlsym(libfontconfig, "FcFontMatch"); |
|
852 |
FcPatternGetBool = (FcPatternGetBoolFuncType) |
|
853 |
dlsym(libfontconfig, "FcPatternGetBool"); |
|
854 |
FcPatternGetInteger = (FcPatternGetIntegerFuncType) |
|
855 |
dlsym(libfontconfig, "FcPatternGetInteger"); |
|
856 |
FcPatternDestroy = |
|
857 |
(FcPatternDestroyFuncType)dlsym(libfontconfig, "FcPatternDestroy"); |
|
858 |
||
859 |
if (FcNameParse == NULL || |
|
860 |
FcPatternAddString == NULL || |
|
861 |
FcConfigSubstitute == NULL || |
|
862 |
FcDefaultSubstitute == NULL || |
|
863 |
FcFontMatch == NULL || |
|
864 |
FcPatternGetBool == NULL || |
|
865 |
FcPatternGetInteger == NULL || |
|
866 |
FcPatternDestroy == NULL) { /* problem with the library: return. */ |
|
867 |
||
868 |
(*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName); |
|
869 |
if (locale) { |
|
870 |
(*env)->ReleaseStringUTFChars (env, localeStr,(const char*)locale); |
|
871 |
} |
|
872 |
closeFontConfig(libfontconfig, JNI_FALSE); |
|
873 |
return -1; |
|
874 |
} |
|
875 |
||
876 |
||
877 |
pattern = (*FcNameParse)((FcChar8 *)fcName); |
|
878 |
if (locale != NULL) { |
|
879 |
(*FcPatternAddString)(pattern, FC_LANG, (unsigned char*)locale); |
|
880 |
} |
|
881 |
(*FcConfigSubstitute)(NULL, pattern, FcMatchPattern); |
|
882 |
(*FcDefaultSubstitute)(pattern); |
|
883 |
matchPattern = (*FcFontMatch)(NULL, pattern, &result); |
|
884 |
/* Perhaps should call FcFontRenderPrepare() here as some pattern |
|
885 |
* elements might change as a result of that call, but I'm not seeing |
|
886 |
* any difference in testing. |
|
887 |
*/ |
|
888 |
if (matchPattern) { |
|
889 |
(*FcPatternGetBool)(matchPattern, FC_ANTIALIAS, 0, &antialias); |
|
890 |
(*FcPatternGetInteger)(matchPattern, FC_RGBA, 0, &rgba); |
|
891 |
(*FcPatternDestroy)(matchPattern); |
|
892 |
} |
|
893 |
(*FcPatternDestroy)(pattern); |
|
894 |
||
895 |
(*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName); |
|
896 |
if (locale) { |
|
897 |
(*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale); |
|
898 |
} |
|
899 |
closeFontConfig(libfontconfig, JNI_TRUE); |
|
900 |
||
901 |
if (antialias == FcFalse) { |
|
902 |
return TEXT_AA_OFF; |
|
903 |
} else if (rgba <= FC_RGBA_UNKNOWN || rgba >= FC_RGBA_NONE) { |
|
904 |
return TEXT_AA_ON; |
|
905 |
} else { |
|
906 |
switch (rgba) { |
|
907 |
case FC_RGBA_RGB : return TEXT_AA_LCD_HRGB; |
|
908 |
case FC_RGBA_BGR : return TEXT_AA_LCD_HBGR; |
|
909 |
case FC_RGBA_VRGB : return TEXT_AA_LCD_VRGB; |
|
910 |
case FC_RGBA_VBGR : return TEXT_AA_LCD_VBGR; |
|
911 |
default : return TEXT_AA_LCD_HRGB; // should not get here. |
|
912 |
} |
|
913 |
} |
|
914 |
} |
|
915 |
||
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
916 |
JNIEXPORT jint JNICALL |
3928 | 917 |
Java_sun_font_FontConfigManager_getFontConfigVersion |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
918 |
(JNIEnv *env, jclass obj) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
919 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
920 |
void* libfontconfig; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
921 |
FcGetVersionFuncType FcGetVersion; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
922 |
int version = 0; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
923 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
924 |
if ((libfontconfig = openFontConfig()) == NULL) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
925 |
return 0; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
926 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
927 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
928 |
FcGetVersion = (FcGetVersionFuncType)dlsym(libfontconfig, "FcGetVersion"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
929 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
930 |
if (FcGetVersion == NULL) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
931 |
closeFontConfig(libfontconfig, JNI_FALSE); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
932 |
return 0; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
933 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
934 |
version = (*FcGetVersion)(); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
935 |
closeFontConfig(libfontconfig, JNI_FALSE); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
936 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
937 |
return version; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
938 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
939 |
|
2 | 940 |
|
941 |
JNIEXPORT void JNICALL |
|
3928 | 942 |
Java_sun_font_FontConfigManager_getFontConfig |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
943 |
(JNIEnv *env, jclass obj, jstring localeStr, jobject fcInfoObj, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
944 |
jobjectArray fcCompFontArray, jboolean includeFallbacks) { |
2 | 945 |
|
946 |
FcNameParseFuncType FcNameParse; |
|
947 |
FcPatternAddStringFuncType FcPatternAddString; |
|
948 |
FcConfigSubstituteFuncType FcConfigSubstitute; |
|
949 |
FcDefaultSubstituteFuncType FcDefaultSubstitute; |
|
950 |
FcFontMatchFuncType FcFontMatch; |
|
951 |
FcPatternGetStringFuncType FcPatternGetString; |
|
952 |
FcPatternDestroyFuncType FcPatternDestroy; |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
953 |
FcPatternGetCharSetFuncType FcPatternGetCharSet; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
954 |
FcFontSortFuncType FcFontSort; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
955 |
FcFontSetDestroyFuncType FcFontSetDestroy; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
956 |
FcCharSetUnionFuncType FcCharSetUnion; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
957 |
FcCharSetSubtractCountFuncType FcCharSetSubtractCount; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
958 |
FcGetVersionFuncType FcGetVersion; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
959 |
FcConfigGetCacheDirsFuncType FcConfigGetCacheDirs; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
960 |
FcStrListNextFuncType FcStrListNext; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
961 |
FcStrListDoneFuncType FcStrListDone; |
2 | 962 |
|
963 |
int i, arrlen; |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
964 |
jobject fcCompFontObj; |
2 | 965 |
jstring fcNameStr, jstr; |
966 |
const char *locale, *fcName; |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
967 |
FcPattern *pattern; |
2 | 968 |
FcResult result; |
969 |
void* libfontconfig; |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
970 |
jfieldID fcNameID, fcFirstFontID, fcAllFontsID, fcVersionID, fcCacheDirsID; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
971 |
jfieldID familyNameID, styleNameID, fullNameID, fontFileID; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
972 |
jmethodID fcFontCons; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
973 |
char* debugMinGlyphsStr = getenv("J2D_DEBUG_MIN_GLYPHS"); |
2 | 974 |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
975 |
jclass fcInfoClass = |
3928 | 976 |
(*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigInfo"); |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
977 |
jclass fcCompFontClass = |
3928 | 978 |
(*env)->FindClass(env, "sun/font/FontConfigManager$FcCompFont"); |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
979 |
jclass fcFontClass = |
3928 | 980 |
(*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigFont"); |
2 | 981 |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
982 |
if (fcInfoObj == NULL || fcCompFontArray == NULL || fcInfoClass == NULL || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
983 |
fcCompFontClass == NULL || fcFontClass == NULL) { |
2 | 984 |
return; |
985 |
} |
|
986 |
||
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
987 |
fcVersionID = (*env)->GetFieldID(env, fcInfoClass, "fcVersion", "I"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
988 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
989 |
fcCacheDirsID = (*env)->GetFieldID(env, fcInfoClass, "cacheDirs", |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
990 |
"[Ljava/lang/String;"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
991 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
992 |
fcNameID = (*env)->GetFieldID(env, fcCompFontClass, |
2 | 993 |
"fcName", "Ljava/lang/String;"); |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
994 |
fcFirstFontID = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
995 |
(*env)->GetFieldID(env, fcCompFontClass, "firstFont", |
3928 | 996 |
"Lsun/font/FontConfigManager$FontConfigFont;"); |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
997 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
998 |
fcAllFontsID = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
999 |
(*env)->GetFieldID(env, fcCompFontClass, "allFonts", |
3928 | 1000 |
"[Lsun/font/FontConfigManager$FontConfigFont;"); |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1001 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1002 |
fcFontCons = (*env)->GetMethodID(env, fcFontClass, "<init>", "()V"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1003 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1004 |
familyNameID = (*env)->GetFieldID(env, fcFontClass, |
2 | 1005 |
"familyName", "Ljava/lang/String;"); |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1006 |
styleNameID = (*env)->GetFieldID(env, fcFontClass, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1007 |
"styleStr", "Ljava/lang/String;"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1008 |
fullNameID = (*env)->GetFieldID(env, fcFontClass, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1009 |
"fullName", "Ljava/lang/String;"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1010 |
fontFileID = (*env)->GetFieldID(env, fcFontClass, |
2 | 1011 |
"fontFile", "Ljava/lang/String;"); |
1012 |
||
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1013 |
if (fcVersionID == NULL || fcCacheDirsID == NULL || fcNameID == NULL || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1014 |
fcFirstFontID == NULL || fcAllFontsID == NULL || fcFontCons == NULL || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1015 |
familyNameID == NULL || styleNameID == NULL || fullNameID == NULL || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1016 |
fontFileID == NULL) { |
2 | 1017 |
return; |
1018 |
} |
|
1019 |
||
1020 |
if ((libfontconfig = openFontConfig()) == NULL) { |
|
1021 |
return; |
|
1022 |
} |
|
1023 |
||
1024 |
FcNameParse = (FcNameParseFuncType)dlsym(libfontconfig, "FcNameParse"); |
|
1025 |
FcPatternAddString = |
|
1026 |
(FcPatternAddStringFuncType)dlsym(libfontconfig, "FcPatternAddString"); |
|
1027 |
FcConfigSubstitute = |
|
1028 |
(FcConfigSubstituteFuncType)dlsym(libfontconfig, "FcConfigSubstitute"); |
|
1029 |
FcDefaultSubstitute = (FcDefaultSubstituteFuncType) |
|
1030 |
dlsym(libfontconfig, "FcDefaultSubstitute"); |
|
1031 |
FcFontMatch = (FcFontMatchFuncType)dlsym(libfontconfig, "FcFontMatch"); |
|
1032 |
FcPatternGetString = |
|
1033 |
(FcPatternGetStringFuncType)dlsym(libfontconfig, "FcPatternGetString"); |
|
1034 |
FcPatternDestroy = |
|
1035 |
(FcPatternDestroyFuncType)dlsym(libfontconfig, "FcPatternDestroy"); |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1036 |
FcPatternGetCharSet = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1037 |
(FcPatternGetCharSetFuncType)dlsym(libfontconfig, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1038 |
"FcPatternGetCharSet"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1039 |
FcFontSort = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1040 |
(FcFontSortFuncType)dlsym(libfontconfig, "FcFontSort"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1041 |
FcFontSetDestroy = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1042 |
(FcFontSetDestroyFuncType)dlsym(libfontconfig, "FcFontSetDestroy"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1043 |
FcCharSetUnion = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1044 |
(FcCharSetUnionFuncType)dlsym(libfontconfig, "FcCharSetUnion"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1045 |
FcCharSetSubtractCount = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1046 |
(FcCharSetSubtractCountFuncType)dlsym(libfontconfig, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1047 |
"FcCharSetSubtractCount"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1048 |
FcGetVersion = (FcGetVersionFuncType)dlsym(libfontconfig, "FcGetVersion"); |
2 | 1049 |
|
1050 |
if (FcNameParse == NULL || |
|
1051 |
FcPatternAddString == NULL || |
|
1052 |
FcConfigSubstitute == NULL || |
|
1053 |
FcDefaultSubstitute == NULL || |
|
1054 |
FcFontMatch == NULL || |
|
1055 |
FcPatternGetString == NULL || |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1056 |
FcPatternDestroy == NULL || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1057 |
FcPatternGetCharSet == NULL || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1058 |
FcFontSetDestroy == NULL || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1059 |
FcCharSetUnion == NULL || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1060 |
FcGetVersion == NULL || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1061 |
FcCharSetSubtractCount == NULL) {/* problem with the library: return.*/ |
2 | 1062 |
closeFontConfig(libfontconfig, JNI_FALSE); |
1063 |
return; |
|
1064 |
} |
|
1065 |
||
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1066 |
(*env)->SetIntField(env, fcInfoObj, fcVersionID, (*FcGetVersion)()); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1067 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1068 |
/* Optionally get the cache dir locations. This isn't |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1069 |
* available until v 2.4.x, but this is OK since on those later versions |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1070 |
* we can check the time stamps on the cache dirs to see if we |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1071 |
* are out of date. There are a couple of assumptions here. First |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1072 |
* that the time stamp on the directory changes when the contents are |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1073 |
* updated. Secondly that the locations don't change. The latter is |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1074 |
* most likely if a new version of fontconfig is installed, but we also |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1075 |
* invalidate the cache if we detect that. Arguably even that is "rare", |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1076 |
* and most likely is tied to an OS upgrade which gets a new file anyway. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1077 |
*/ |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1078 |
FcConfigGetCacheDirs = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1079 |
(FcConfigGetCacheDirsFuncType)dlsym(libfontconfig, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1080 |
"FcConfigGetCacheDirs"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1081 |
FcStrListNext = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1082 |
(FcStrListNextFuncType)dlsym(libfontconfig, "FcStrListNext"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1083 |
FcStrListDone = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1084 |
(FcStrListDoneFuncType)dlsym(libfontconfig, "FcStrListDone"); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1085 |
if (FcStrListNext != NULL && FcStrListDone != NULL && |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1086 |
FcConfigGetCacheDirs != NULL) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1087 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1088 |
FcStrList* cacheDirs; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1089 |
FcChar8* cacheDir; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1090 |
int cnt = 0; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1091 |
jobject cacheDirArray = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1092 |
(*env)->GetObjectField(env, fcInfoObj, fcCacheDirsID); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1093 |
int max = (*env)->GetArrayLength(env, cacheDirArray); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1094 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1095 |
cacheDirs = (*FcConfigGetCacheDirs)(NULL); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1096 |
if (cacheDirs != NULL) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1097 |
while ((cnt < max) && (cacheDir = (*FcStrListNext)(cacheDirs))) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1098 |
jstr = (*env)->NewStringUTF(env, (const char*)cacheDir); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1099 |
(*env)->SetObjectArrayElement(env, cacheDirArray, cnt++, jstr); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1100 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1101 |
(*FcStrListDone)(cacheDirs); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1102 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1103 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1104 |
|
2 | 1105 |
locale = (*env)->GetStringUTFChars(env, localeStr, 0); |
1106 |
||
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1107 |
arrlen = (*env)->GetArrayLength(env, fcCompFontArray); |
2 | 1108 |
for (i=0; i<arrlen; i++) { |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1109 |
FcFontSet* fontset; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1110 |
int fn, j, fontCount, nfonts, minGlyphs; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1111 |
FcChar8 **family, **styleStr, **fullname, **file; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1112 |
jarray fcFontArr; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1113 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1114 |
fcCompFontObj = (*env)->GetObjectArrayElement(env, fcCompFontArray, i); |
2 | 1115 |
fcNameStr = |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1116 |
(jstring)((*env)->GetObjectField(env, fcCompFontObj, fcNameID)); |
2 | 1117 |
fcName = (*env)->GetStringUTFChars(env, fcNameStr, 0); |
1118 |
if (fcName == NULL) { |
|
1119 |
continue; |
|
1120 |
} |
|
1121 |
pattern = (*FcNameParse)((FcChar8 *)fcName); |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1122 |
if (pattern == NULL) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1123 |
closeFontConfig(libfontconfig, JNI_FALSE); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1124 |
return; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1125 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1126 |
|
2 | 1127 |
/* locale may not usually be necessary as fontconfig appears to apply |
1128 |
* this anyway based on the user's environment. However we want |
|
1129 |
* to use the value of the JDK startup locale so this should take |
|
1130 |
* care of it. |
|
1131 |
*/ |
|
1132 |
if (locale != NULL) { |
|
1133 |
(*FcPatternAddString)(pattern, FC_LANG, (unsigned char*)locale); |
|
1134 |
} |
|
1135 |
(*FcConfigSubstitute)(NULL, pattern, FcMatchPattern); |
|
1136 |
(*FcDefaultSubstitute)(pattern); |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1137 |
fontset = (*FcFontSort)(NULL, pattern, FcTrue, NULL, &result); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1138 |
if (fontset == NULL) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1139 |
closeFontConfig(libfontconfig, JNI_FALSE); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1140 |
return; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1141 |
} |
2 | 1142 |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1143 |
/* fontconfig returned us "nfonts". If we are just getting the |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1144 |
* first font, we set nfont to zero. Otherwise we use "nfonts". |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1145 |
* Next create separate C arrrays of length nfonts for family file etc. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1146 |
* Inspect the returned fonts and the ones we like (adds enough glyphs) |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1147 |
* are added to the arrays and we increment 'fontCount'. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1148 |
*/ |
3931
81071c37cc91
6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents:
3928
diff
changeset
|
1149 |
nfonts = fontset->nfont; |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1150 |
family = (FcChar8**)calloc(nfonts, sizeof(FcChar8*)); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1151 |
styleStr = (FcChar8**)calloc(nfonts, sizeof(FcChar8*)); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1152 |
fullname = (FcChar8**)calloc(nfonts, sizeof(FcChar8*)); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1153 |
file = (FcChar8**)calloc(nfonts, sizeof(FcChar8*)); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1154 |
if (family == NULL || styleStr == NULL || |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1155 |
fullname == NULL || file == NULL) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1156 |
closeFontConfig(libfontconfig, JNI_FALSE); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1157 |
return; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1158 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1159 |
fontCount = 0; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1160 |
minGlyphs = 20; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1161 |
if (debugMinGlyphsStr != NULL) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1162 |
int val = minGlyphs; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1163 |
sscanf(debugMinGlyphsStr, "%5d", &val); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1164 |
if (val >= 0 && val <= 65536) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1165 |
minGlyphs = val; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1166 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1167 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1168 |
for (j=0; j<nfonts; j++) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1169 |
FcPattern *fontPattern = fontset->fonts[j]; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1170 |
FcChar8 *fontformat; |
1731
830101735cdb
6764543: SIGSEGV in libfontconfig.so starting from jdk7b33
prr
parents:
1724
diff
changeset
|
1171 |
FcCharSet *unionCharset = NULL, *charset; |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1172 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1173 |
fontformat = NULL; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1174 |
(*FcPatternGetString)(fontPattern, FC_FONTFORMAT, 0, &fontformat); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1175 |
if (fontformat != NULL && strcmp((char*)fontformat, "TrueType") |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1176 |
!= 0) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1177 |
continue; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1178 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1179 |
result = (*FcPatternGetCharSet)(fontPattern, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1180 |
FC_CHARSET, 0, &charset); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1181 |
if (result != FcResultMatch) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1182 |
closeFontConfig(libfontconfig, JNI_FALSE); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1183 |
return; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1184 |
} |
2 | 1185 |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1186 |
/* We don't want 20 or 30 fonts, so once we hit 10 fonts, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1187 |
* then require that they really be adding value. Too many |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1188 |
* adversely affects load time for minimal value-add. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1189 |
* This is still likely far more than we've had in the past. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1190 |
*/ |
3931
81071c37cc91
6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents:
3928
diff
changeset
|
1191 |
if (j==10) { |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1192 |
minGlyphs = 50; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1193 |
} |
1731
830101735cdb
6764543: SIGSEGV in libfontconfig.so starting from jdk7b33
prr
parents:
1724
diff
changeset
|
1194 |
if (unionCharset == NULL) { |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1195 |
unionCharset = charset; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1196 |
} else { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1197 |
if ((*FcCharSetSubtractCount)(charset, unionCharset) |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1198 |
> minGlyphs) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1199 |
unionCharset = (* FcCharSetUnion)(unionCharset, charset); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1200 |
} else { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1201 |
continue; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1202 |
} |
2 | 1203 |
} |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1204 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1205 |
fontCount++; // found a font we will use. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1206 |
(*FcPatternGetString)(fontPattern, FC_FILE, 0, &file[j]); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1207 |
(*FcPatternGetString)(fontPattern, FC_FAMILY, 0, &family[j]); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1208 |
(*FcPatternGetString)(fontPattern, FC_STYLE, 0, &styleStr[j]); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1209 |
(*FcPatternGetString)(fontPattern, FC_FULLNAME, 0, &fullname[j]); |
3931
81071c37cc91
6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents:
3928
diff
changeset
|
1210 |
if (!includeFallbacks) { |
81071c37cc91
6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents:
3928
diff
changeset
|
1211 |
break; |
81071c37cc91
6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents:
3928
diff
changeset
|
1212 |
} |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1213 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1214 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1215 |
/* Once we get here 'fontCount' is the number of returned fonts |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1216 |
* we actually want to use, so we create 'fcFontArr' of that length. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1217 |
* The non-null entries of "family[]" etc are those fonts. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1218 |
* Then loop again over all nfonts adding just those non-null ones |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1219 |
* to 'fcFontArr'. If its null (we didn't want the font) |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1220 |
* then we don't enter the main body. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1221 |
* So we should never get more than 'fontCount' entries. |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1222 |
*/ |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1223 |
if (includeFallbacks) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1224 |
fcFontArr = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1225 |
(*env)->NewObjectArray(env, fontCount, fcFontClass, NULL); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1226 |
(*env)->SetObjectField(env,fcCompFontObj, fcAllFontsID, fcFontArr); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1227 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1228 |
fn=0; |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1229 |
|
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1230 |
for (j=0;j<nfonts;j++) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1231 |
if (family[j] != NULL) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1232 |
jobject fcFont = |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1233 |
(*env)->NewObject(env, fcFontClass, fcFontCons); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1234 |
jstr = (*env)->NewStringUTF(env, (const char*)family[j]); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1235 |
(*env)->SetObjectField(env, fcFont, familyNameID, jstr); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1236 |
if (file[j] != NULL) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1237 |
jstr = (*env)->NewStringUTF(env, (const char*)file[j]); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1238 |
(*env)->SetObjectField(env, fcFont, fontFileID, jstr); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1239 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1240 |
if (styleStr[j] != NULL) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1241 |
jstr = (*env)->NewStringUTF(env, (const char*)styleStr[j]); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1242 |
(*env)->SetObjectField(env, fcFont, styleNameID, jstr); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1243 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1244 |
if (fullname[j] != NULL) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1245 |
jstr = (*env)->NewStringUTF(env, (const char*)fullname[j]); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1246 |
(*env)->SetObjectField(env, fcFont, fullNameID, jstr); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1247 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1248 |
if (fn==0) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1249 |
(*env)->SetObjectField(env, fcCompFontObj, |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1250 |
fcFirstFontID, fcFont); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1251 |
} |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1252 |
if (includeFallbacks) { |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1253 |
(*env)->SetObjectArrayElement(env, fcFontArr, fn++,fcFont); |
3931
81071c37cc91
6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents:
3928
diff
changeset
|
1254 |
} else { |
81071c37cc91
6867603: sun.font.FontManager.getDefaultPlatformFont throws NPE in OpenJDK on Solaris 10 10/08
prr
parents:
3928
diff
changeset
|
1255 |
break; |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1256 |
} |
2 | 1257 |
} |
1258 |
} |
|
1259 |
(*env)->ReleaseStringUTFChars (env, fcNameStr, (const char*)fcName); |
|
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1260 |
(*FcFontSetDestroy)(fontset); |
2 | 1261 |
(*FcPatternDestroy)(pattern); |
883
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1262 |
free(family); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1263 |
free(styleStr); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1264 |
free(fullname); |
c3e81f0acd3d
6378099: RFE: Use libfontconfig to create/synthesise a fontconfig.properties
prr
parents:
2
diff
changeset
|
1265 |
free(file); |
2 | 1266 |
} |
1267 |
||
1268 |
/* release resources and close the ".so" */ |
|
1269 |
||
1270 |
if (locale) { |
|
1271 |
(*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale); |
|
1272 |
} |
|
1273 |
closeFontConfig(libfontconfig, JNI_TRUE); |
|
1274 |
} |