< prev index next >

src/java.desktop/unix/native/common/awt/fontpath.c

Print this page




 995     FcFontSortFuncType FcFontSort;
 996     FcFontSetDestroyFuncType FcFontSetDestroy;
 997     FcCharSetUnionFuncType FcCharSetUnion;
 998     FcCharSetSubtractCountFuncType FcCharSetSubtractCount;
 999     FcGetVersionFuncType FcGetVersion;
1000     FcConfigGetCacheDirsFuncType FcConfigGetCacheDirs;
1001     FcStrListNextFuncType FcStrListNext;
1002     FcStrListDoneFuncType FcStrListDone;
1003 
1004     int i, arrlen;
1005     jobject fcCompFontObj;
1006     jstring fcNameStr, jstr;
1007     const char *locale, *fcName;
1008     FcPattern *pattern;
1009     FcResult result;
1010     void* libfontconfig;
1011     jfieldID fcNameID, fcFirstFontID, fcAllFontsID, fcVersionID, fcCacheDirsID;
1012     jfieldID familyNameID, styleNameID, fullNameID, fontFileID;
1013     jmethodID fcFontCons;
1014     char* debugMinGlyphsStr = getenv("J2D_DEBUG_MIN_GLYPHS");



1015 
1016     CHECK_NULL(fcInfoObj);
1017     CHECK_NULL(fcCompFontArray);
1018 
1019     jclass fcInfoClass =
1020         (*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigInfo");
1021     CHECK_NULL(fcInfoClass);
1022     jclass fcCompFontClass =
1023         (*env)->FindClass(env, "sun/font/FontConfigManager$FcCompFont");
1024     CHECK_NULL(fcCompFontClass);
1025     jclass fcFontClass =
1026          (*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigFont");
1027     CHECK_NULL(fcFontClass);
1028 
1029 
1030     CHECK_NULL(fcVersionID = (*env)->GetFieldID(env, fcInfoClass, "fcVersion", "I"));
1031     CHECK_NULL(fcCacheDirsID = (*env)->GetFieldID(env, fcInfoClass, "cacheDirs",
1032                                                   "[Ljava/lang/String;"));
1033     CHECK_NULL(fcNameID = (*env)->GetFieldID(env, fcCompFontClass,
1034                                              "fcName", "Ljava/lang/String;"));
1035     CHECK_NULL(fcFirstFontID = (*env)->GetFieldID(env, fcCompFontClass, "firstFont",
1036                                         "Lsun/font/FontConfigManager$FontConfigFont;"));
1037     CHECK_NULL(fcAllFontsID = (*env)->GetFieldID(env, fcCompFontClass, "allFonts",
1038                                         "[Lsun/font/FontConfigManager$FontConfigFont;"));
1039     CHECK_NULL(fcFontCons = (*env)->GetMethodID(env, fcFontClass, "<init>", "()V"));
1040     CHECK_NULL(familyNameID = (*env)->GetFieldID(env, fcFontClass,
1041                                       "familyName", "Ljava/lang/String;"));
1042     CHECK_NULL(styleNameID = (*env)->GetFieldID(env, fcFontClass,
1043                                     "styleStr", "Ljava/lang/String;"));
1044     CHECK_NULL(fullNameID = (*env)->GetFieldID(env, fcFontClass,
1045                                     "fullName", "Ljava/lang/String;"));


1129 
1130                 (*env)->SetObjectArrayElement(env, cacheDirArray, cnt++, jstr);
1131             }
1132             (*FcStrListDone)(cacheDirs);
1133         }
1134     }
1135 
1136     locale = (*env)->GetStringUTFChars(env, localeStr, 0);
1137     if (locale == NULL) {
1138         (*env)->ExceptionClear(env);
1139         JNU_ThrowOutOfMemoryError(env, "Could not create locale");
1140         return;
1141     }
1142 
1143     arrlen = (*env)->GetArrayLength(env, fcCompFontArray);
1144     for (i=0; i<arrlen; i++) {
1145         FcFontSet* fontset;
1146         int fn, j, fontCount, nfonts;
1147         unsigned int minGlyphs;
1148         FcChar8 **family, **styleStr, **fullname, **file;
1149         jarray fcFontArr;

1150 
1151         fcCompFontObj = (*env)->GetObjectArrayElement(env, fcCompFontArray, i);
1152         fcNameStr =
1153             (jstring)((*env)->GetObjectField(env, fcCompFontObj, fcNameID));
1154         fcName = (*env)->GetStringUTFChars(env, fcNameStr, 0);
1155         if (fcName == NULL) {
1156             continue;
1157         }
1158         pattern = (*FcNameParse)((FcChar8 *)fcName);
1159         (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName);
1160         if (pattern == NULL) {
1161             closeFontConfig(libfontconfig, JNI_FALSE);
1162             return;
1163         }
1164 
1165         /* locale may not usually be necessary as fontconfig appears to apply
1166          * this anyway based on the user's environment. However we want
1167          * to use the value of the JDK startup locale so this should take
1168          * care of it.
1169          */


1201             if (fullname != NULL) {
1202                 free(fullname);
1203             }
1204             if (file != NULL) {
1205                 free(file);
1206             }
1207             (*FcPatternDestroy)(pattern);
1208             (*FcFontSetDestroy)(fontset);
1209             closeFontConfig(libfontconfig, JNI_FALSE);
1210             return;
1211         }
1212         fontCount = 0;
1213         minGlyphs = 20;
1214         if (debugMinGlyphsStr != NULL) {
1215             int val = minGlyphs;
1216             sscanf(debugMinGlyphsStr, "%5d", &val);
1217             if (val >= 0 && val <= 65536) {
1218                 minGlyphs = val;
1219             }
1220         }
1221         FcCharSet *unionCharset = NULL;
1222         for (j=0; j<nfonts; j++) {
1223             FcPattern *fontPattern = fontset->fonts[j];
1224             FcChar8 *fontformat;
1225             FcCharSet *charset = NULL;
1226 
1227             fontformat = NULL;
1228             (*FcPatternGetString)(fontPattern, FC_FONTFORMAT, 0, &fontformat);
1229             /* We only want TrueType fonts but some Linuxes still depend
1230              * on Type 1 fonts for some Locale support, so we'll allow
1231              * them there.
1232              */
1233             if (fontformat != NULL
1234                 && (strcmp((char*)fontformat, "TrueType") != 0)
1235 #if defined(__linux__) || defined(_AIX)
1236                 && (strcmp((char*)fontformat, "Type 1") != 0)
1237 #endif
1238              ) {
1239                 continue;
1240             }
1241             result = (*FcPatternGetCharSet)(fontPattern,




 995     FcFontSortFuncType FcFontSort;
 996     FcFontSetDestroyFuncType FcFontSetDestroy;
 997     FcCharSetUnionFuncType FcCharSetUnion;
 998     FcCharSetSubtractCountFuncType FcCharSetSubtractCount;
 999     FcGetVersionFuncType FcGetVersion;
1000     FcConfigGetCacheDirsFuncType FcConfigGetCacheDirs;
1001     FcStrListNextFuncType FcStrListNext;
1002     FcStrListDoneFuncType FcStrListDone;
1003 
1004     int i, arrlen;
1005     jobject fcCompFontObj;
1006     jstring fcNameStr, jstr;
1007     const char *locale, *fcName;
1008     FcPattern *pattern;
1009     FcResult result;
1010     void* libfontconfig;
1011     jfieldID fcNameID, fcFirstFontID, fcAllFontsID, fcVersionID, fcCacheDirsID;
1012     jfieldID familyNameID, styleNameID, fullNameID, fontFileID;
1013     jmethodID fcFontCons;
1014     char* debugMinGlyphsStr = getenv("J2D_DEBUG_MIN_GLYPHS");
1015     jclass fcInfoClass;
1016     jclass fcCompFontClass;
1017     jclass fcFontClass;
1018 
1019     CHECK_NULL(fcInfoObj);
1020     CHECK_NULL(fcCompFontArray);
1021 
1022     fcInfoClass =
1023         (*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigInfo");
1024     CHECK_NULL(fcInfoClass);
1025     fcCompFontClass =
1026         (*env)->FindClass(env, "sun/font/FontConfigManager$FcCompFont");
1027     CHECK_NULL(fcCompFontClass);
1028     fcFontClass =
1029          (*env)->FindClass(env, "sun/font/FontConfigManager$FontConfigFont");
1030     CHECK_NULL(fcFontClass);
1031 
1032 
1033     CHECK_NULL(fcVersionID = (*env)->GetFieldID(env, fcInfoClass, "fcVersion", "I"));
1034     CHECK_NULL(fcCacheDirsID = (*env)->GetFieldID(env, fcInfoClass, "cacheDirs",
1035                                                   "[Ljava/lang/String;"));
1036     CHECK_NULL(fcNameID = (*env)->GetFieldID(env, fcCompFontClass,
1037                                              "fcName", "Ljava/lang/String;"));
1038     CHECK_NULL(fcFirstFontID = (*env)->GetFieldID(env, fcCompFontClass, "firstFont",
1039                                         "Lsun/font/FontConfigManager$FontConfigFont;"));
1040     CHECK_NULL(fcAllFontsID = (*env)->GetFieldID(env, fcCompFontClass, "allFonts",
1041                                         "[Lsun/font/FontConfigManager$FontConfigFont;"));
1042     CHECK_NULL(fcFontCons = (*env)->GetMethodID(env, fcFontClass, "<init>", "()V"));
1043     CHECK_NULL(familyNameID = (*env)->GetFieldID(env, fcFontClass,
1044                                       "familyName", "Ljava/lang/String;"));
1045     CHECK_NULL(styleNameID = (*env)->GetFieldID(env, fcFontClass,
1046                                     "styleStr", "Ljava/lang/String;"));
1047     CHECK_NULL(fullNameID = (*env)->GetFieldID(env, fcFontClass,
1048                                     "fullName", "Ljava/lang/String;"));


1132 
1133                 (*env)->SetObjectArrayElement(env, cacheDirArray, cnt++, jstr);
1134             }
1135             (*FcStrListDone)(cacheDirs);
1136         }
1137     }
1138 
1139     locale = (*env)->GetStringUTFChars(env, localeStr, 0);
1140     if (locale == NULL) {
1141         (*env)->ExceptionClear(env);
1142         JNU_ThrowOutOfMemoryError(env, "Could not create locale");
1143         return;
1144     }
1145 
1146     arrlen = (*env)->GetArrayLength(env, fcCompFontArray);
1147     for (i=0; i<arrlen; i++) {
1148         FcFontSet* fontset;
1149         int fn, j, fontCount, nfonts;
1150         unsigned int minGlyphs;
1151         FcChar8 **family, **styleStr, **fullname, **file;
1152         jarray fcFontArr = NULL;
1153         FcCharSet *unionCharset = NULL;
1154 
1155         fcCompFontObj = (*env)->GetObjectArrayElement(env, fcCompFontArray, i);
1156         fcNameStr =
1157             (jstring)((*env)->GetObjectField(env, fcCompFontObj, fcNameID));
1158         fcName = (*env)->GetStringUTFChars(env, fcNameStr, 0);
1159         if (fcName == NULL) {
1160             continue;
1161         }
1162         pattern = (*FcNameParse)((FcChar8 *)fcName);
1163         (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName);
1164         if (pattern == NULL) {
1165             closeFontConfig(libfontconfig, JNI_FALSE);
1166             return;
1167         }
1168 
1169         /* locale may not usually be necessary as fontconfig appears to apply
1170          * this anyway based on the user's environment. However we want
1171          * to use the value of the JDK startup locale so this should take
1172          * care of it.
1173          */


1205             if (fullname != NULL) {
1206                 free(fullname);
1207             }
1208             if (file != NULL) {
1209                 free(file);
1210             }
1211             (*FcPatternDestroy)(pattern);
1212             (*FcFontSetDestroy)(fontset);
1213             closeFontConfig(libfontconfig, JNI_FALSE);
1214             return;
1215         }
1216         fontCount = 0;
1217         minGlyphs = 20;
1218         if (debugMinGlyphsStr != NULL) {
1219             int val = minGlyphs;
1220             sscanf(debugMinGlyphsStr, "%5d", &val);
1221             if (val >= 0 && val <= 65536) {
1222                 minGlyphs = val;
1223             }
1224         }
1225 
1226         for (j=0; j<nfonts; j++) {
1227             FcPattern *fontPattern = fontset->fonts[j];
1228             FcChar8 *fontformat;
1229             FcCharSet *charset = NULL;
1230 
1231             fontformat = NULL;
1232             (*FcPatternGetString)(fontPattern, FC_FONTFORMAT, 0, &fontformat);
1233             /* We only want TrueType fonts but some Linuxes still depend
1234              * on Type 1 fonts for some Locale support, so we'll allow
1235              * them there.
1236              */
1237             if (fontformat != NULL
1238                 && (strcmp((char*)fontformat, "TrueType") != 0)
1239 #if defined(__linux__) || defined(_AIX)
1240                 && (strcmp((char*)fontformat, "Type 1") != 0)
1241 #endif
1242              ) {
1243                 continue;
1244             }
1245             result = (*FcPatternGetCharSet)(fontPattern,


< prev index next >