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, fcCompFontObj); 1168 (*env)->DeleteLocalRef(env, fcNameStr); 1169 continue; 1170 } 1171 pattern = (*FcNameParse)((FcChar8 *)fcName); 1172 (*env)->ReleaseStringUTFChars(env, fcNameStr, (const char*)fcName); 1173 (*env)->DeleteLocalRef(env, fcNameStr); 1174 if (pattern == NULL) { 1175 closeFontConfig(libfontconfig, JNI_FALSE); 1176 return; 1177 } 1178 1179 /* locale may not usually be necessary as fontconfig appears to apply 1180 * this anyway based on the user's environment. However we want 1181 * to use the value of the JDK startup locale so this should take 1182 * care of it. 1183 */ 1184 if (locale != NULL) { 1185 (*FcPatternAddString)(pattern, FC_LANG, (unsigned char*)locale); 1186 } 1187 (*FcConfigSubstitute)(NULL, pattern, FcMatchPattern); 1188 (*FcDefaultSubstitute)(pattern); 1189 fontset = (*FcFontSort)(NULL, pattern, FcTrue, NULL, &result); 1190 if (fontset == NULL) { 1191 (*FcPatternDestroy)(pattern); 1192 closeFontConfig(libfontconfig, JNI_FALSE); 1193 return; 1313 free(fullname); 1314 free(styleStr); 1315 free(file); 1316 (*FcPatternDestroy)(pattern); 1317 (*FcFontSetDestroy)(fontset); 1318 closeFontConfig(libfontconfig, JNI_FALSE); 1319 return; 1320 } 1321 (*env)->SetObjectField(env,fcCompFontObj, fcAllFontsID, fcFontArr); 1322 } 1323 fn=0; 1324 1325 for (j=0;j<nfonts;j++) { 1326 if (family[j] != NULL) { 1327 jobject fcFont = 1328 (*env)->NewObject(env, fcFontClass, fcFontCons); 1329 if (IS_NULL(fcFont)) break; 1330 jstr = (*env)->NewStringUTF(env, (const char*)family[j]); 1331 if (IS_NULL(jstr)) break; 1332 (*env)->SetObjectField(env, fcFont, familyNameID, jstr); 1333 (*env)->DeleteLocalRef(env, jstr); 1334 if (file[j] != NULL) { 1335 jstr = (*env)->NewStringUTF(env, (const char*)file[j]); 1336 if (IS_NULL(jstr)) break; 1337 (*env)->SetObjectField(env, fcFont, fontFileID, jstr); 1338 (*env)->DeleteLocalRef(env, jstr); 1339 } 1340 if (styleStr[j] != NULL) { 1341 jstr = (*env)->NewStringUTF(env, (const char*)styleStr[j]); 1342 if (IS_NULL(jstr)) break; 1343 (*env)->SetObjectField(env, fcFont, styleNameID, jstr); 1344 (*env)->DeleteLocalRef(env, jstr); 1345 } 1346 if (fullname[j] != NULL) { 1347 jstr = (*env)->NewStringUTF(env, (const char*)fullname[j]); 1348 if (IS_NULL(jstr)) break; 1349 (*env)->SetObjectField(env, fcFont, fullNameID, jstr); 1350 (*env)->DeleteLocalRef(env, jstr); 1351 } 1352 if (fn==0) { 1353 (*env)->SetObjectField(env, fcCompFontObj, 1354 fcFirstFontID, fcFont); 1355 } 1356 if (includeFallbacks) { 1357 (*env)->SetObjectArrayElement(env, fcFontArr, fn++,fcFont); 1358 } else { 1359 (*env)->DeleteLocalRef(env, fcFont); 1360 break; 1361 } 1362 (*env)->DeleteLocalRef(env, fcFont); 1363 } 1364 } 1365 if (includeFallbacks) { 1366 (*env)->DeleteLocalRef(env, fcFontArr); 1367 } 1368 (*env)->DeleteLocalRef(env, fcCompFontObj); 1369 (*FcFontSetDestroy)(fontset); 1370 (*FcPatternDestroy)(pattern); 1371 free(family); 1372 free(styleStr); 1373 free(fullname); 1374 free(file); 1375 } 1376 1377 /* release resources and close the ".so" */ 1378 1379 if (locale) { 1380 (*env)->ReleaseStringUTFChars (env, localeStr, (const char*)locale); 1381 } 1382 closeFontConfig(libfontconfig, JNI_TRUE); 1383 } |