1120 (FcStrListNextFuncType)dlsym(libfontconfig, "FcStrListNext"); 1121 FcStrListDone = 1122 (FcStrListDoneFuncType)dlsym(libfontconfig, "FcStrListDone"); 1123 if (FcStrListNext != NULL && FcStrListDone != NULL && 1124 FcConfigGetCacheDirs != NULL) { 1125 1126 FcStrList* cacheDirs; 1127 FcChar8* cacheDir; 1128 int cnt = 0; 1129 jobject cacheDirArray = 1130 (*env)->GetObjectField(env, fcInfoObj, fcCacheDirsID); 1131 int max = (*env)->GetArrayLength(env, cacheDirArray); 1132 1133 cacheDirs = (*FcConfigGetCacheDirs)(NULL); 1134 if (cacheDirs != NULL) { 1135 while ((cnt < max) && (cacheDir = (*FcStrListNext)(cacheDirs))) { 1136 jstr = (*env)->NewStringUTF(env, (const char*)cacheDir); 1137 JNU_CHECK_EXCEPTION(env); 1138 1139 (*env)->SetObjectArrayElement(env, cacheDirArray, cnt++, jstr); 1140 } 1141 (*FcStrListDone)(cacheDirs); 1142 } 1143 } 1144 1145 locale = (*env)->GetStringUTFChars(env, localeStr, 0); 1146 if (locale == NULL) { 1147 (*env)->ExceptionClear(env); 1148 JNU_ThrowOutOfMemoryError(env, "Could not create locale"); 1149 return; 1150 } 1151 1152 arrlen = (*env)->GetArrayLength(env, fcCompFontArray); 1153 for (i=0; i<arrlen; i++) { 1154 FcFontSet* fontset; 1155 int fn, j, fontCount, nfonts; 1156 unsigned int minGlyphs; 1157 FcChar8 **family, **styleStr, **fullname, **file; 1158 jarray fcFontArr = NULL; 1159 FcCharSet *unionCharset = NULL; 1160 1161 fcCompFontObj = (*env)->GetObjectArrayElement(env, fcCompFontArray, i); 1162 fcNameStr = 1163 (jstring)((*env)->GetObjectField(env, fcCompFontObj, fcNameID)); 1164 fcName = (*env)->GetStringUTFChars(env, fcNameStr, 0); 1165 if (fcName == NULL) { 1166 continue; 1167 } 1168 pattern = (*FcNameParse)((FcChar8 *)fcName); 1169 (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName); 1170 if (pattern == NULL) { 1171 closeFontConfig(libfontconfig, JNI_FALSE); 1172 return; 1173 } 1174 1175 /* locale may not usually be necessary as fontconfig appears to apply 1176 * this anyway based on the user's environment. However we want 1177 * to use the value of the JDK startup locale so this should take 1178 * care of it. 1179 */ 1180 if (locale != NULL) { 1181 (*FcPatternAddString)(pattern, FC_LANG, (unsigned char*)locale); 1182 } 1183 (*FcConfigSubstitute)(NULL, pattern, FcMatchPattern); 1184 (*FcDefaultSubstitute)(pattern); 1185 fontset = (*FcFontSort)(NULL, pattern, FcTrue, NULL, &result); 1186 if (fontset == NULL) { 1187 (*FcPatternDestroy)(pattern); 1188 closeFontConfig(libfontconfig, JNI_FALSE); 1189 return; 1309 free(fullname); 1310 free(styleStr); 1311 free(file); 1312 (*FcPatternDestroy)(pattern); 1313 (*FcFontSetDestroy)(fontset); 1314 closeFontConfig(libfontconfig, JNI_FALSE); 1315 return; 1316 } 1317 (*env)->SetObjectField(env,fcCompFontObj, fcAllFontsID, fcFontArr); 1318 } 1319 fn=0; 1320 1321 for (j=0;j<nfonts;j++) { 1322 if (family[j] != NULL) { 1323 jobject fcFont = 1324 (*env)->NewObject(env, fcFontClass, fcFontCons); 1325 if (IS_NULL(fcFont)) break; 1326 jstr = (*env)->NewStringUTF(env, (const char*)family[j]); 1327 if (IS_NULL(jstr)) break; 1328 (*env)->SetObjectField(env, fcFont, familyNameID, jstr); 1329 if (file[j] != NULL) { 1330 jstr = (*env)->NewStringUTF(env, (const char*)file[j]); 1331 if (IS_NULL(jstr)) break; 1332 (*env)->SetObjectField(env, fcFont, fontFileID, jstr); 1333 } 1334 if (styleStr[j] != NULL) { 1335 jstr = (*env)->NewStringUTF(env, (const char*)styleStr[j]); 1336 if (IS_NULL(jstr)) break; 1337 (*env)->SetObjectField(env, fcFont, styleNameID, jstr); 1338 } 1339 if (fullname[j] != NULL) { 1340 jstr = (*env)->NewStringUTF(env, (const char*)fullname[j]); 1341 if (IS_NULL(jstr)) break; 1342 (*env)->SetObjectField(env, fcFont, fullNameID, jstr); 1343 } 1344 if (fn==0) { 1345 (*env)->SetObjectField(env, fcCompFontObj, 1346 fcFirstFontID, fcFont); 1347 } 1348 if (includeFallbacks) { 1349 (*env)->SetObjectArrayElement(env, fcFontArr, fn++,fcFont); 1350 } else { 1351 break; 1352 } 1353 } 1354 } 1355 (*FcFontSetDestroy)(fontset); 1356 (*FcPatternDestroy)(pattern); 1357 free(family); 1358 free(styleStr); 1359 free(fullname); 1360 free(file); 1361 } 1362 1363 /* release resources and close the ".so" */ 1364 1365 if (locale) { 1366 (*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale); 1367 } 1368 closeFontConfig(libfontconfig, JNI_TRUE); 1369 } | 1120 (FcStrListNextFuncType)dlsym(libfontconfig, "FcStrListNext"); 1121 FcStrListDone = 1122 (FcStrListDoneFuncType)dlsym(libfontconfig, "FcStrListDone"); 1123 if (FcStrListNext != NULL && FcStrListDone != NULL && 1124 FcConfigGetCacheDirs != NULL) { 1125 1126 FcStrList* cacheDirs; 1127 FcChar8* cacheDir; 1128 int cnt = 0; 1129 jobject cacheDirArray = 1130 (*env)->GetObjectField(env, fcInfoObj, fcCacheDirsID); 1131 int max = (*env)->GetArrayLength(env, cacheDirArray); 1132 1133 cacheDirs = (*FcConfigGetCacheDirs)(NULL); 1134 if (cacheDirs != NULL) { 1135 while ((cnt < max) && (cacheDir = (*FcStrListNext)(cacheDirs))) { 1136 jstr = (*env)->NewStringUTF(env, (const char*)cacheDir); 1137 JNU_CHECK_EXCEPTION(env); 1138 1139 (*env)->SetObjectArrayElement(env, cacheDirArray, cnt++, jstr); 1140 (*env)->DeleteLocalRef(env, jstr); 1141 } 1142 (*FcStrListDone)(cacheDirs); 1143 } 1144 } 1145 1146 locale = (*env)->GetStringUTFChars(env, localeStr, 0); 1147 if (locale == NULL) { 1148 (*env)->ExceptionClear(env); 1149 JNU_ThrowOutOfMemoryError(env, "Could not create locale"); 1150 return; 1151 } 1152 1153 arrlen = (*env)->GetArrayLength(env, fcCompFontArray); 1154 for (i=0; i<arrlen; i++) { 1155 FcFontSet* fontset; 1156 int fn, j, fontCount, nfonts; 1157 unsigned int minGlyphs; 1158 FcChar8 **family, **styleStr, **fullname, **file; 1159 jarray fcFontArr = NULL; 1160 FcCharSet *unionCharset = NULL; 1161 1162 fcCompFontObj = (*env)->GetObjectArrayElement(env, fcCompFontArray, i); 1163 fcNameStr = 1164 (jstring)((*env)->GetObjectField(env, fcCompFontObj, fcNameID)); 1165 fcName = (*env)->GetStringUTFChars(env, fcNameStr, 0); 1166 if (fcName == NULL) { 1167 (*env)->DeleteLocalRef(env, fcNameStr); 1168 continue; 1169 } 1170 pattern = (*FcNameParse)((FcChar8 *)fcName); 1171 (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName); 1172 (*env)->DeleteLocalRef(env, fcNameStr); 1173 if (pattern == NULL) { 1174 closeFontConfig(libfontconfig, JNI_FALSE); 1175 return; 1176 } 1177 1178 /* locale may not usually be necessary as fontconfig appears to apply 1179 * this anyway based on the user's environment. However we want 1180 * to use the value of the JDK startup locale so this should take 1181 * care of it. 1182 */ 1183 if (locale != NULL) { 1184 (*FcPatternAddString)(pattern, FC_LANG, (unsigned char*)locale); 1185 } 1186 (*FcConfigSubstitute)(NULL, pattern, FcMatchPattern); 1187 (*FcDefaultSubstitute)(pattern); 1188 fontset = (*FcFontSort)(NULL, pattern, FcTrue, NULL, &result); 1189 if (fontset == NULL) { 1190 (*FcPatternDestroy)(pattern); 1191 closeFontConfig(libfontconfig, JNI_FALSE); 1192 return; 1312 free(fullname); 1313 free(styleStr); 1314 free(file); 1315 (*FcPatternDestroy)(pattern); 1316 (*FcFontSetDestroy)(fontset); 1317 closeFontConfig(libfontconfig, JNI_FALSE); 1318 return; 1319 } 1320 (*env)->SetObjectField(env,fcCompFontObj, fcAllFontsID, fcFontArr); 1321 } 1322 fn=0; 1323 1324 for (j=0;j<nfonts;j++) { 1325 if (family[j] != NULL) { 1326 jobject fcFont = 1327 (*env)->NewObject(env, fcFontClass, fcFontCons); 1328 if (IS_NULL(fcFont)) break; 1329 jstr = (*env)->NewStringUTF(env, (const char*)family[j]); 1330 if (IS_NULL(jstr)) break; 1331 (*env)->SetObjectField(env, fcFont, familyNameID, jstr); 1332 (*env)->DeleteLocalRef(env, jstr); 1333 if (file[j] != NULL) { 1334 jstr = (*env)->NewStringUTF(env, (const char*)file[j]); 1335 if (IS_NULL(jstr)) break; 1336 (*env)->SetObjectField(env, fcFont, fontFileID, jstr); 1337 (*env)->DeleteLocalRef(env, jstr); 1338 } 1339 if (styleStr[j] != NULL) { 1340 jstr = (*env)->NewStringUTF(env, (const char*)styleStr[j]); 1341 if (IS_NULL(jstr)) break; 1342 (*env)->SetObjectField(env, fcFont, styleNameID, jstr); 1343 (*env)->DeleteLocalRef(env, jstr); 1344 } 1345 if (fullname[j] != NULL) { 1346 jstr = (*env)->NewStringUTF(env, (const char*)fullname[j]); 1347 if (IS_NULL(jstr)) break; 1348 (*env)->SetObjectField(env, fcFont, fullNameID, jstr); 1349 (*env)->DeleteLocalRef(env, jstr); 1350 } 1351 if (fn==0) { 1352 (*env)->SetObjectField(env, fcCompFontObj, 1353 fcFirstFontID, fcFont); 1354 } 1355 if (includeFallbacks) { 1356 (*env)->SetObjectArrayElement(env, fcFontArr, fn++,fcFont); 1357 } else { 1358 (*env)->DeleteLocalRef(env, fcFont); 1359 break; 1360 } 1361 (*env)->DeleteLocalRef(env, fcFont); 1362 } 1363 } 1364 (*env)->DeleteLocalRef(env, fcCompFontObj); 1365 (*FcFontSetDestroy)(fontset); 1366 (*FcPatternDestroy)(pattern); 1367 free(family); 1368 free(styleStr); 1369 free(fullname); 1370 free(file); 1371 } 1372 1373 /* release resources and close the ".so" */ 1374 1375 if (locale) { 1376 (*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale); 1377 } 1378 closeFontConfig(libfontconfig, JNI_TRUE); 1379 } |