324 #ifndef HEADLESS
325 static char **getX11FontPath ()
326 {
327 char **x11Path, **fontdirs;
328 int i, pos, slen, nPaths, numDirs;
329
330 x11Path = XGetFontPath (awt_display, &nPaths);
331
332 /* This isn't ever going to be perfect: the font path may contain
333 * much we aren't interested in, but the cost should be moderate
334 * Exclude all directories that contain the strings "Speedo","/F3/",
335 * "75dpi", "100dpi", "misc" or "bitmap", or don't begin with a "/",
336 * the last of which should exclude font servers.
337 * Also exclude the user specific ".gnome*" directories which
338 * aren't going to contain the system fonts we need.
339 * Hopefully we are left only with Type1 and TrueType directories.
340 * It doesn't matter much if there are extraneous directories, it'll just
341 * cost us a little wasted effort upstream.
342 */
343 fontdirs = (char**)calloc(nPaths+1, sizeof(char*));
344 pos = 0;
345 for (i=0; i < nPaths; i++) {
346 if (x11Path[i][0] != '/') {
347 continue;
348 }
349 if (strstr(x11Path[i], "/75dpi") != NULL) {
350 continue;
351 }
352 if (strstr(x11Path[i], "/100dpi") != NULL) {
353 continue;
354 }
355 if (strstr(x11Path[i], "/misc") != NULL) {
356 continue;
357 }
358 if (strstr(x11Path[i], "/Speedo") != NULL) {
359 continue;
360 }
361 if (strstr(x11Path[i], ".gnome") != NULL) {
362 continue;
363 }
403 int len1=0, len2=0, len3=0, totalLen=0, numDirs=0,
404 currLen, i, j, found, pathLen=0;
405 char **ptr, **fontdirs;
406 char *fontPath = NULL;
407
408 if (p1 != NULL) {
409 ptr = p1;
410 while (*ptr++ != NULL) len1++;
411 }
412 if (p2 != NULL) {
413 ptr = p2;
414
415 while (*ptr++ != NULL) len2++;
416 }
417 if (p3 != NULL) {
418 ptr = p3;
419 while (*ptr++ != NULL) len3++;
420 }
421 totalLen = len1+len2+len3;
422 fontdirs = (char**)calloc(totalLen, sizeof(char*));
423
424 for (i=0; i < len1; i++) {
425 if (noType1 && strstr(p1[i], "Type1") != NULL) {
426 continue;
427 }
428 fontdirs[numDirs++] = p1[i];
429 }
430
431 currLen = numDirs; /* only compare against previous path dirs */
432 for (i=0; i < len2; i++) {
433 if (noType1 && strstr(p2[i], "Type1") != NULL) {
434 continue;
435 }
436 found = 0;
437 for (j=0; j < currLen; j++) {
438 if (strcmp(fontdirs[j], p2[i]) == 0) {
439 found = 1;
440 break;
441 }
442 }
799 * outline fonts, and to get the set of full file paths from the matches.
800 * This set is returned from the call to FcFontList(..)
801 * We allocate an array of char* pointers sufficient to hold all
802 * the matches + 1 extra which ensures there will be a NULL after all
803 * valid entries.
804 * We call FcStrDirname strip the file name from the path, and
805 * check if we have yet seen this directory. If not we add a pointer to
806 * it into our array of char*. Note that FcStrDirname returns newly
807 * allocated storage so we can use this in the return char** value.
808 * Finally we clean up, freeing allocated resources, and return the
809 * array of unique directories.
810 */
811 pattern = (*FcPatternBuild)(NULL, FC_OUTLINE, FcTypeBool, FcTrue, NULL);
812 objset = (*FcObjectSetBuild)(FC_FILE, NULL);
813 fontSet = (*FcFontList)(NULL, pattern, objset);
814 if (fontSet == NULL) {
815 /* FcFontList() may return NULL if fonts are not installed. */
816 fontdirs = NULL;
817 } else {
818 fontdirs = (char**)calloc(fontSet->nfont+1, sizeof(char*));
819 for (f=0; f < fontSet->nfont; f++) {
820 FcChar8 *file;
821 FcChar8 *dir;
822 if ((*FcPatternGetString)(fontSet->fonts[f], FC_FILE, 0, &file) ==
823 FcResultMatch) {
824 dir = (*FcStrDirname)(file);
825 found = 0;
826 for (i=0;i<numdirs; i++) {
827 if (strcmp(fontdirs[i], (char*)dir) == 0) {
828 found = 1;
829 break;
830 }
831 }
832 if (!found) {
833 fontdirs[numdirs++] = (char*)dir;
834 } else {
835 free((char*)dir);
836 }
837 }
838 }
839 /* Free fontset if one was returned */
840 (*FcFontSetDestroy)(fontSet);
841 }
842
843 /* Free memory and close the ".so" */
844 (*FcPatternDestroy)(pattern);
845 closeFontConfig(libfontconfig, JNI_TRUE);
846 return fontdirs;
847 }
848
849 /* These are copied from sun.awt.SunHints.
850 * Consider initialising them as ints using JNI for more robustness.
851 */
852 #define TEXT_AA_OFF 1
853 #define TEXT_AA_ON 2
854 #define TEXT_AA_LCD_HRGB 4
855 #define TEXT_AA_LCD_HBGR 5
856 #define TEXT_AA_LCD_VRGB 6
857 #define TEXT_AA_LCD_VBGR 7
858
859 JNIEXPORT jint JNICALL
860 Java_sun_font_FontConfigManager_getFontConfigAASettings
861 (JNIEnv *env, jclass obj, jstring localeStr, jstring fcNameStr) {
862
|
324 #ifndef HEADLESS
325 static char **getX11FontPath ()
326 {
327 char **x11Path, **fontdirs;
328 int i, pos, slen, nPaths, numDirs;
329
330 x11Path = XGetFontPath (awt_display, &nPaths);
331
332 /* This isn't ever going to be perfect: the font path may contain
333 * much we aren't interested in, but the cost should be moderate
334 * Exclude all directories that contain the strings "Speedo","/F3/",
335 * "75dpi", "100dpi", "misc" or "bitmap", or don't begin with a "/",
336 * the last of which should exclude font servers.
337 * Also exclude the user specific ".gnome*" directories which
338 * aren't going to contain the system fonts we need.
339 * Hopefully we are left only with Type1 and TrueType directories.
340 * It doesn't matter much if there are extraneous directories, it'll just
341 * cost us a little wasted effort upstream.
342 */
343 fontdirs = (char**)calloc(nPaths+1, sizeof(char*));
344 if (fontdirs == NULL) {
345 return NULL;
346 }
347 pos = 0;
348 for (i=0; i < nPaths; i++) {
349 if (x11Path[i][0] != '/') {
350 continue;
351 }
352 if (strstr(x11Path[i], "/75dpi") != NULL) {
353 continue;
354 }
355 if (strstr(x11Path[i], "/100dpi") != NULL) {
356 continue;
357 }
358 if (strstr(x11Path[i], "/misc") != NULL) {
359 continue;
360 }
361 if (strstr(x11Path[i], "/Speedo") != NULL) {
362 continue;
363 }
364 if (strstr(x11Path[i], ".gnome") != NULL) {
365 continue;
366 }
406 int len1=0, len2=0, len3=0, totalLen=0, numDirs=0,
407 currLen, i, j, found, pathLen=0;
408 char **ptr, **fontdirs;
409 char *fontPath = NULL;
410
411 if (p1 != NULL) {
412 ptr = p1;
413 while (*ptr++ != NULL) len1++;
414 }
415 if (p2 != NULL) {
416 ptr = p2;
417
418 while (*ptr++ != NULL) len2++;
419 }
420 if (p3 != NULL) {
421 ptr = p3;
422 while (*ptr++ != NULL) len3++;
423 }
424 totalLen = len1+len2+len3;
425 fontdirs = (char**)calloc(totalLen, sizeof(char*));
426 if (fontdirs == NULL) {
427 return NULL;
428 }
429
430 for (i=0; i < len1; i++) {
431 if (noType1 && strstr(p1[i], "Type1") != NULL) {
432 continue;
433 }
434 fontdirs[numDirs++] = p1[i];
435 }
436
437 currLen = numDirs; /* only compare against previous path dirs */
438 for (i=0; i < len2; i++) {
439 if (noType1 && strstr(p2[i], "Type1") != NULL) {
440 continue;
441 }
442 found = 0;
443 for (j=0; j < currLen; j++) {
444 if (strcmp(fontdirs[j], p2[i]) == 0) {
445 found = 1;
446 break;
447 }
448 }
805 * outline fonts, and to get the set of full file paths from the matches.
806 * This set is returned from the call to FcFontList(..)
807 * We allocate an array of char* pointers sufficient to hold all
808 * the matches + 1 extra which ensures there will be a NULL after all
809 * valid entries.
810 * We call FcStrDirname strip the file name from the path, and
811 * check if we have yet seen this directory. If not we add a pointer to
812 * it into our array of char*. Note that FcStrDirname returns newly
813 * allocated storage so we can use this in the return char** value.
814 * Finally we clean up, freeing allocated resources, and return the
815 * array of unique directories.
816 */
817 pattern = (*FcPatternBuild)(NULL, FC_OUTLINE, FcTypeBool, FcTrue, NULL);
818 objset = (*FcObjectSetBuild)(FC_FILE, NULL);
819 fontSet = (*FcFontList)(NULL, pattern, objset);
820 if (fontSet == NULL) {
821 /* FcFontList() may return NULL if fonts are not installed. */
822 fontdirs = NULL;
823 } else {
824 fontdirs = (char**)calloc(fontSet->nfont+1, sizeof(char*));
825 if (fontdirs == NULL) {
826 (*FcFontSetDestroy)(fontSet);
827 goto cleanup;
828 }
829 for (f=0; f < fontSet->nfont; f++) {
830 FcChar8 *file;
831 FcChar8 *dir;
832 if ((*FcPatternGetString)(fontSet->fonts[f], FC_FILE, 0, &file) ==
833 FcResultMatch) {
834 dir = (*FcStrDirname)(file);
835 found = 0;
836 for (i=0;i<numdirs; i++) {
837 if (strcmp(fontdirs[i], (char*)dir) == 0) {
838 found = 1;
839 break;
840 }
841 }
842 if (!found) {
843 fontdirs[numdirs++] = (char*)dir;
844 } else {
845 free((char*)dir);
846 }
847 }
848 }
849 /* Free fontset if one was returned */
850 (*FcFontSetDestroy)(fontSet);
851 }
852
853 cleanup:
854 /* Free memory and close the ".so" */
855 (*FcPatternDestroy)(pattern);
856 closeFontConfig(libfontconfig, JNI_TRUE);
857 return fontdirs;
858 }
859
860 /* These are copied from sun.awt.SunHints.
861 * Consider initialising them as ints using JNI for more robustness.
862 */
863 #define TEXT_AA_OFF 1
864 #define TEXT_AA_ON 2
865 #define TEXT_AA_LCD_HRGB 4
866 #define TEXT_AA_LCD_HBGR 5
867 #define TEXT_AA_LCD_VRGB 6
868 #define TEXT_AA_LCD_VBGR 7
869
870 JNIEXPORT jint JNICALL
871 Java_sun_font_FontConfigManager_getFontConfigAASettings
872 (JNIEnv *env, jclass obj, jstring localeStr, jstring fcNameStr) {
873
|