31 #include <stdlib.h> 32 33 #if defined(__GNUC__) && __GNUC__ >= 4 34 #define HB_UNUSED __attribute__((unused)) 35 #else 36 #define HB_UNUSED 37 #endif 38 39 static hb_bool_t 40 hb_jdk_get_glyph (hb_font_t *font HB_UNUSED, 41 void *font_data, 42 hb_codepoint_t unicode, 43 hb_codepoint_t variation_selector, 44 hb_codepoint_t *glyph, 45 void *user_data HB_UNUSED) 46 { 47 48 JDKFontInfo *jdkFontInfo = (JDKFontInfo*)font_data; 49 JNIEnv* env = jdkFontInfo->env; 50 jobject font2D = jdkFontInfo->font2D; 51 hb_codepoint_t u = (variation_selector==0) ? unicode : variation_selector; 52 53 *glyph = (hb_codepoint_t) 54 env->CallIntMethod(font2D, sunFontIDs.f2dCharToGlyphMID, u); 55 if ((int)*glyph < 0) { 56 *glyph = 0; 57 } 58 return (*glyph != 0); 59 } 60 61 static hb_position_t 62 hb_jdk_get_glyph_h_advance (hb_font_t *font HB_UNUSED, 63 void *font_data, 64 hb_codepoint_t glyph, 65 void *user_data HB_UNUSED) 66 { 67 68 float fadv = 0.0f; 69 if ((glyph & 0xfffe) == 0xfffe) { 70 return 0; // JDK uses this glyph code. 71 } 72 73 JDKFontInfo *jdkFontInfo = (JDKFontInfo*)font_data; 74 JNIEnv* env = jdkFontInfo->env; | 31 #include <stdlib.h> 32 33 #if defined(__GNUC__) && __GNUC__ >= 4 34 #define HB_UNUSED __attribute__((unused)) 35 #else 36 #define HB_UNUSED 37 #endif 38 39 static hb_bool_t 40 hb_jdk_get_glyph (hb_font_t *font HB_UNUSED, 41 void *font_data, 42 hb_codepoint_t unicode, 43 hb_codepoint_t variation_selector, 44 hb_codepoint_t *glyph, 45 void *user_data HB_UNUSED) 46 { 47 48 JDKFontInfo *jdkFontInfo = (JDKFontInfo*)font_data; 49 JNIEnv* env = jdkFontInfo->env; 50 jobject font2D = jdkFontInfo->font2D; 51 if (variation_selector == 0) { 52 *glyph = (hb_codepoint_t)env->CallIntMethod( 53 font2D, sunFontIDs.f2dCharToGlyphMID, unicode); 54 if (env->ExceptionOccurred()) 55 { 56 env->ExceptionDescribe(); 57 env->ExceptionClear(); 58 } 59 } else { 60 jintArray unicodes = NULL; 61 jintArray results = NULL; 62 jint* tmp = NULL; 63 64 *glyph = 0; 65 unicodes = env->NewIntArray(2); 66 if (unicodes == NULL) { 67 goto cleanup; 68 } 69 results = env->NewIntArray(2); 70 if (results == NULL) { 71 goto cleanup; 72 } 73 74 tmp = new jint[2]; 75 if (tmp == NULL) { 76 goto cleanup; 77 } 78 tmp[0] = unicode; 79 tmp[1] = variation_selector; 80 81 env->SetIntArrayRegion(unicodes, 0, 2, tmp); 82 env->CallVoidMethod(font2D, sunFontIDs.f2dCharsToGlyphsMID, 2, 83 unicodes, results); 84 if (env->ExceptionOccurred()) 85 { 86 env->ExceptionDescribe(); 87 env->ExceptionClear(); 88 goto cleanup; 89 } 90 env->GetIntArrayRegion(results, 0, 2, tmp); 91 *glyph = tmp[0]; 92 cleanup: 93 if (unicodes != NULL) { 94 env->DeleteLocalRef(unicodes); 95 } 96 if (results != NULL) { 97 env->DeleteLocalRef(results); 98 } 99 if (tmp != NULL) { 100 delete [] tmp; 101 } 102 } 103 if ((int)*glyph < 0) { 104 *glyph = 0; 105 } 106 return (*glyph != 0); 107 } 108 109 static hb_position_t 110 hb_jdk_get_glyph_h_advance (hb_font_t *font HB_UNUSED, 111 void *font_data, 112 hb_codepoint_t glyph, 113 void *user_data HB_UNUSED) 114 { 115 116 float fadv = 0.0f; 117 if ((glyph & 0xfffe) == 0xfffe) { 118 return 0; // JDK uses this glyph code. 119 } 120 121 JDKFontInfo *jdkFontInfo = (JDKFontInfo*)font_data; 122 JNIEnv* env = jdkFontInfo->env; |