< prev index next >

src/java.desktop/share/native/libfontmanager/hb-jdk-font.cc

Print this page




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "hb.h"
  27 #include "hb-jdk.h"
  28 #ifdef MACOSX
  29 #include "hb-coretext.h"
  30 #endif
  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     } else {





















  55         *glyph = (hb_codepoint_t)env->CallIntMethod(
  56                      font2D, sunFontIDs.f2dCharToVariationGlyphMID, 
  57                      unicode, variation_selector);
  58     }
  59     if (env->ExceptionOccurred())
  60     {
  61         env->ExceptionClear();
  62     }
  63     if ((int)*glyph < 0) {
  64         *glyph = 0;
  65     }
  66     return (*glyph != 0);
  67 }
  68 
  69 static hb_position_t
  70 hb_jdk_get_glyph_h_advance (hb_font_t *font HB_UNUSED,
  71                            void *font_data,
  72                            hb_codepoint_t glyph,
  73                            void *user_data HB_UNUSED)
  74 {
  75 
  76     float fadv = 0.0f;
  77     if ((glyph & 0xfffe) == 0xfffe) {
  78         return 0; // JDK uses this glyph code.


 234                            void *font_data,
 235                            const char *name, int len,
 236                            hb_codepoint_t *glyph,
 237                            void *user_data HB_UNUSED)
 238 {
 239   return false;
 240 }
 241 
 242 // remind : can we initialise this from the code we call
 243 // from the class static method in Java to make it
 244 // completely thread safe.
 245 static hb_font_funcs_t *
 246 _hb_jdk_get_font_funcs (void)
 247 {
 248   static hb_font_funcs_t *jdk_ffuncs = NULL;
 249   hb_font_funcs_t *ff;
 250 
 251   if (!jdk_ffuncs) {
 252       ff = hb_font_funcs_create();
 253 
 254       hb_font_funcs_set_glyph_func(ff, hb_jdk_get_glyph, NULL, NULL);

 255       hb_font_funcs_set_glyph_h_advance_func(ff,
 256                     hb_jdk_get_glyph_h_advance, NULL, NULL);
 257       hb_font_funcs_set_glyph_v_advance_func(ff,
 258                     hb_jdk_get_glyph_v_advance, NULL, NULL);
 259       hb_font_funcs_set_glyph_h_origin_func(ff,
 260                     hb_jdk_get_glyph_h_origin, NULL, NULL);
 261       hb_font_funcs_set_glyph_v_origin_func(ff,
 262                     hb_jdk_get_glyph_v_origin, NULL, NULL);
 263       hb_font_funcs_set_glyph_h_kerning_func(ff,
 264                     hb_jdk_get_glyph_h_kerning, NULL, NULL);
 265       hb_font_funcs_set_glyph_v_kerning_func(ff,
 266                     hb_jdk_get_glyph_v_kerning, NULL, NULL);
 267       hb_font_funcs_set_glyph_extents_func(ff,
 268                     hb_jdk_get_glyph_extents, NULL, NULL);
 269       hb_font_funcs_set_glyph_contour_point_func(ff,
 270                     hb_jdk_get_glyph_contour_point, NULL, NULL);
 271       hb_font_funcs_set_glyph_name_func(ff,
 272                     hb_jdk_get_glyph_name, NULL, NULL);
 273       hb_font_funcs_set_glyph_from_name_func(ff,
 274                     hb_jdk_get_glyph_from_name, NULL, NULL);




  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "hb.h"
  27 #include "hb-jdk.h"
  28 #ifdef MACOSX
  29 #include "hb-coretext.h"
  30 #endif
  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 
  40 static hb_bool_t
  41 hb_jdk_get_nominal_glyph (hb_font_t *font HB_UNUSED,
  42                           void *font_data,
  43                           hb_codepoint_t unicode,

  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     *glyph = (hb_codepoint_t)env->CallIntMethod(
  52               font2D, sunFontIDs.f2dCharToGlyphMID, unicode);
  53     if (env->ExceptionOccurred())
  54     {
  55         env->ExceptionClear();
  56     }
  57     if ((int)*glyph < 0) {
  58         *glyph = 0;
  59     }
  60     return (*glyph != 0);
  61 }
  62 
  63 static hb_bool_t
  64 hb_jdk_get_variation_glyph (hb_font_t *font HB_UNUSED,
  65                  void *font_data,
  66                  hb_codepoint_t unicode,
  67                  hb_codepoint_t variation_selector,
  68                  hb_codepoint_t *glyph,
  69                  void *user_data HB_UNUSED)
  70 {
  71 
  72     JDKFontInfo *jdkFontInfo = (JDKFontInfo*)font_data;
  73     JNIEnv* env = jdkFontInfo->env;
  74     jobject font2D = jdkFontInfo->font2D;
  75     *glyph = (hb_codepoint_t)env->CallIntMethod(
  76               font2D, sunFontIDs.f2dCharToVariationGlyphMID, 
  77               unicode, variation_selector);

  78     if (env->ExceptionOccurred())
  79     {
  80         env->ExceptionClear();
  81     }
  82     if ((int)*glyph < 0) {
  83         *glyph = 0;
  84     }
  85     return (*glyph != 0);
  86 }
  87 
  88 static hb_position_t
  89 hb_jdk_get_glyph_h_advance (hb_font_t *font HB_UNUSED,
  90                            void *font_data,
  91                            hb_codepoint_t glyph,
  92                            void *user_data HB_UNUSED)
  93 {
  94 
  95     float fadv = 0.0f;
  96     if ((glyph & 0xfffe) == 0xfffe) {
  97         return 0; // JDK uses this glyph code.


 253                            void *font_data,
 254                            const char *name, int len,
 255                            hb_codepoint_t *glyph,
 256                            void *user_data HB_UNUSED)
 257 {
 258   return false;
 259 }
 260 
 261 // remind : can we initialise this from the code we call
 262 // from the class static method in Java to make it
 263 // completely thread safe.
 264 static hb_font_funcs_t *
 265 _hb_jdk_get_font_funcs (void)
 266 {
 267   static hb_font_funcs_t *jdk_ffuncs = NULL;
 268   hb_font_funcs_t *ff;
 269 
 270   if (!jdk_ffuncs) {
 271       ff = hb_font_funcs_create();
 272 
 273       hb_font_funcs_set_nominal_glyph_func(ff, hb_jdk_get_nominal_glyph, NULL, NULL);
 274       hb_font_funcs_set_variation_glyph_func(ff, hb_jdk_get_variation_glyph, NULL, NULL);
 275       hb_font_funcs_set_glyph_h_advance_func(ff,
 276                     hb_jdk_get_glyph_h_advance, NULL, NULL);
 277       hb_font_funcs_set_glyph_v_advance_func(ff,
 278                     hb_jdk_get_glyph_v_advance, NULL, NULL);
 279       hb_font_funcs_set_glyph_h_origin_func(ff,
 280                     hb_jdk_get_glyph_h_origin, NULL, NULL);
 281       hb_font_funcs_set_glyph_v_origin_func(ff,
 282                     hb_jdk_get_glyph_v_origin, NULL, NULL);
 283       hb_font_funcs_set_glyph_h_kerning_func(ff,
 284                     hb_jdk_get_glyph_h_kerning, NULL, NULL);
 285       hb_font_funcs_set_glyph_v_kerning_func(ff,
 286                     hb_jdk_get_glyph_v_kerning, NULL, NULL);
 287       hb_font_funcs_set_glyph_extents_func(ff,
 288                     hb_jdk_get_glyph_extents, NULL, NULL);
 289       hb_font_funcs_set_glyph_contour_point_func(ff,
 290                     hb_jdk_get_glyph_contour_point, NULL, NULL);
 291       hb_font_funcs_set_glyph_name_func(ff,
 292                     hb_jdk_get_glyph_name, NULL, NULL);
 293       hb_font_funcs_set_glyph_from_name_func(ff,
 294                     hb_jdk_get_glyph_from_name, NULL, NULL);


< prev index next >