256 hb_jdk_get_glyph_h_kerning, NULL, NULL); 257 hb_font_funcs_set_glyph_v_kerning_func(ff, 258 hb_jdk_get_glyph_v_kerning, NULL, NULL); 259 hb_font_funcs_set_glyph_extents_func(ff, 260 hb_jdk_get_glyph_extents, NULL, NULL); 261 hb_font_funcs_set_glyph_contour_point_func(ff, 262 hb_jdk_get_glyph_contour_point, NULL, NULL); 263 hb_font_funcs_set_glyph_name_func(ff, 264 hb_jdk_get_glyph_name, NULL, NULL); 265 hb_font_funcs_set_glyph_from_name_func(ff, 266 hb_jdk_get_glyph_from_name, NULL, NULL); 267 hb_font_funcs_make_immutable(ff); // done setting functions. 268 jdk_ffuncs = ff; 269 } 270 return jdk_ffuncs; 271 } 272 273 static void _do_nothing(void) { 274 } 275 276 static hb_blob_t * 277 reference_table(hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data) { 278 279 JDKFontInfo *jdkFontInfo = (JDKFontInfo*)user_data; 280 JNIEnv* env = jdkFontInfo->env; 281 jobject font2D = jdkFontInfo->font2D; 282 jsize length; 283 jbyte* buffer; 284 285 // HB_TAG_NONE is 0 and is used to get the whole font file. 286 // It is not expected not be needed for JDK. 287 if (tag == 0) { 288 return NULL; 289 } 290 jbyteArray tableBytes = (jbyteArray) 291 env->CallObjectMethod(font2D, sunFontIDs.getTableBytesMID, tag); 292 if (tableBytes == NULL) { 293 return NULL; 294 } 295 length = env->GetArrayLength(tableBytes); 296 buffer = (jbyte *)calloc(length, sizeof(jbyte)); 297 env->GetByteArrayRegion(tableBytes, 0, length, buffer); 298 299 return hb_blob_create((const char *)buffer, length, 300 HB_MEMORY_MODE_WRITABLE, 301 buffer, free); 302 } 303 304 hb_face_t* 305 hb_jdk_face_create(JDKFontInfo *jdkFontInfo, 306 hb_destroy_func_t destroy) { 307 308 hb_face_t *face = 309 hb_face_create_for_tables(reference_table, jdkFontInfo, destroy); 310 311 return face; 312 } 313 314 static hb_font_t* _hb_jdk_font_create(JDKFontInfo *jdkFontInfo, 315 hb_destroy_func_t destroy) { 316 317 hb_font_t *font; 318 hb_face_t *face; 319 320 face = hb_jdk_face_create(jdkFontInfo, destroy); 321 font = hb_font_create(face); 322 hb_face_destroy (face); | 256 hb_jdk_get_glyph_h_kerning, NULL, NULL); 257 hb_font_funcs_set_glyph_v_kerning_func(ff, 258 hb_jdk_get_glyph_v_kerning, NULL, NULL); 259 hb_font_funcs_set_glyph_extents_func(ff, 260 hb_jdk_get_glyph_extents, NULL, NULL); 261 hb_font_funcs_set_glyph_contour_point_func(ff, 262 hb_jdk_get_glyph_contour_point, NULL, NULL); 263 hb_font_funcs_set_glyph_name_func(ff, 264 hb_jdk_get_glyph_name, NULL, NULL); 265 hb_font_funcs_set_glyph_from_name_func(ff, 266 hb_jdk_get_glyph_from_name, NULL, NULL); 267 hb_font_funcs_make_immutable(ff); // done setting functions. 268 jdk_ffuncs = ff; 269 } 270 return jdk_ffuncs; 271 } 272 273 static void _do_nothing(void) { 274 } 275 276 static void _free_nothing(void*) { 277 } 278 279 static hb_blob_t * 280 reference_table(hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data) { 281 282 JDKFontInfo *jdkFontInfo = (JDKFontInfo*)user_data; 283 JNIEnv* env = jdkFontInfo->env; 284 jobject font2D = jdkFontInfo->font2D; 285 jsize length = 0; 286 void* buffer = NULL; 287 int cacheIdx = 0; 288 289 // HB_TAG_NONE is 0 and is used to get the whole font file. 290 // It is not expected to be needed for JDK. 291 if (tag == 0 || jdkFontInfo->layoutTables == NULL) { 292 return NULL; 293 } 294 295 for (cacheIdx=0; cacheIdx<LAYOUTCACHE_ENTRIES; cacheIdx++) { 296 if (tag == jdkFontInfo->layoutTables->entries[cacheIdx].tag) break; 297 } 298 299 if (cacheIdx < LAYOUTCACHE_ENTRIES) { // if found 300 if (jdkFontInfo->layoutTables->entries[cacheIdx].len != -1) { 301 length = jdkFontInfo->layoutTables->entries[cacheIdx].len; 302 buffer = (void*)jdkFontInfo->layoutTables->entries[cacheIdx].ptr; 303 } 304 } 305 306 if (buffer == NULL) { 307 jbyteArray tableBytes = (jbyteArray) 308 env->CallObjectMethod(font2D, sunFontIDs.getTableBytesMID, tag); 309 if (tableBytes == NULL) { 310 return NULL; 311 } 312 length = env->GetArrayLength(tableBytes); 313 buffer = calloc(length, sizeof(jbyte)); 314 env->GetByteArrayRegion(tableBytes, 0, length, (jbyte*)buffer); 315 316 if (cacheIdx >= LAYOUTCACHE_ENTRIES) { // not a cacheable table 317 return hb_blob_create((const char *)buffer, length, 318 HB_MEMORY_MODE_WRITABLE, 319 buffer, free); 320 } else { 321 jdkFontInfo->layoutTables->entries[cacheIdx].len = length; 322 jdkFontInfo->layoutTables->entries[cacheIdx].ptr = buffer; 323 } 324 } 325 326 return hb_blob_create((const char *)buffer, length, 327 HB_MEMORY_MODE_READONLY, 328 NULL, _free_nothing); 329 } 330 331 332 333 hb_face_t* 334 hb_jdk_face_create(JDKFontInfo *jdkFontInfo, 335 hb_destroy_func_t destroy) { 336 337 hb_face_t *face = 338 hb_face_create_for_tables(reference_table, jdkFontInfo, destroy); 339 340 return face; 341 } 342 343 static hb_font_t* _hb_jdk_font_create(JDKFontInfo *jdkFontInfo, 344 hb_destroy_func_t destroy) { 345 346 hb_font_t *font; 347 hb_face_t *face; 348 349 face = hb_jdk_face_create(jdkFontInfo, destroy); 350 font = hb_font_create(face); 351 hb_face_destroy (face); |