のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

hb_font_set_funcs

    163 hb_font_t* createFont(hb_face_t* face, SkPaint* paint, float sizeX, float sizeY) {
    164     hb_font_t* font = hb_font_create(face);
    165 
    166     // Note: this needs to be reworked when we do subpixels
    167     int x_ppem = floor(sizeX + 0.5);
    168     int y_ppem = floor(sizeY + 0.5);
    169     hb_font_set_ppem(font, x_ppem, y_ppem);
    170     hb_font_set_scale(font, HBFloatToFixed(sizeX), HBFloatToFixed(sizeY));
    171 
    172     HarfBuzzFontData* data = new HarfBuzzFontData(paint);
    173     hb_font_set_funcs(font, harfbuzzSkiaGetFontFuncs(), data, destroyHarfBuzzFontData); <==関数セット
    174 
    175     return font;
    176 }
 121 static hb_font_funcs_t* harfbuzzSkiaGetFontFuncs()
    122 {
    123     static hb_font_funcs_t* harfbuzzSkiaFontFuncs = 0;
    124 
    125     // We don't set callback functions which we can't support.
    126     // Harfbuzz will use the fallback implementation if they aren't set.
    127     if (!harfbuzzSkiaFontFuncs) {
    128         harfbuzzSkiaFontFuncs = hb_font_funcs_create();
    129         hb_font_funcs_set_glyph_func(          harfbuzzSkiaFontFuncs, harfbuzzGetGlyph, 0, 0);
    130         hb_font_funcs_set_glyph_h_advance_func(harfbuzzSkiaFontFuncs, harfbuzzGetGlyphHorizontalAdvance, 0, 0);
    131         hb_font_funcs_set_glyph_h_origin_func( harfbuzzSkiaFontFuncs, harfbuzzGetGlyphHorizontalOrigin, 0, 0);
    132         hb_font_funcs_set_glyph_extents_func(  harfbuzzSkiaFontFuncs, harfbuzzGetGlyphExtents, 0, 0);
    133         hb_font_funcs_make_immutable(          harfbuzzSkiaFontFuncs);
    134     }
    135     return harfbuzzSkiaFontFuncs;
    136 }
    383 #define HB_FONT_FUNC_IMPLEMENT(name) \
    384                                                                          \
    385 void                                                                     \
    386 hb_font_funcs_set_##name##_func (hb_font_funcs_t             *ffuncs,    \
    387                                  hb_font_get_##name##_func_t  func,      \
    388                                  void                        *user_data, \
    389                                  hb_destroy_func_t            destroy)   \
    390 {                                                                        \
    391   if (ffuncs->immutable) {                                               \
    392     if (destroy)                                                         \
    393       destroy (user_data);                                               \
    394     return;                                                              \
    395   }                                                                      \
    396                                                                          \
    397   if (ffuncs->destroy.name)                                              \
    398     ffuncs->destroy.name (ffuncs->user_data.name);                       \
    399                                                                          \
    400   if (func) {                                                            \
    401     ffuncs->get.name = func;                                             \
    402     ffuncs->user_data.name = user_data;                                  \
    403     ffuncs->destroy.name = destroy;                                      \
    404   } else {                                                               \
    405     ffuncs->get.name = hb_font_get_##name##_nil;                         \
    406     ffuncs->user_data.name = NULL;                                       \
    407     ffuncs->destroy.name = NULL;                                         \
    408   }                                                                      \
    409 }
     44 #define HB_FONT_FUNCS_IMPLEMENT_CALLBACKS \
     45   HB_FONT_FUNC_IMPLEMENT (glyph) \
     46   HB_FONT_FUNC_IMPLEMENT (glyph_h_advance) \
     47   HB_FONT_FUNC_IMPLEMENT (glyph_v_advance) \
     48   HB_FONT_FUNC_IMPLEMENT (glyph_h_origin) \
     49   HB_FONT_FUNC_IMPLEMENT (glyph_v_origin) \
     50   HB_FONT_FUNC_IMPLEMENT (glyph_h_kerning) \
     51   HB_FONT_FUNC_IMPLEMENT (glyph_v_kerning) \
     52   HB_FONT_FUNC_IMPLEMENT (glyph_extents) \
     53   HB_FONT_FUNC_IMPLEMENT (glyph_contour_point) \
     54   HB_FONT_FUNC_IMPLEMENT (glyph_name) \
     55   HB_FONT_FUNC_IMPLEMENT (glyph_from_name) \
     56   /* ^--- Add new callbacks here */
    431 hb_font_get_glyph (hb_font_t *font,
    432 		   hb_codepoint_t unicode, hb_codepoint_t variation_selector,
    433 		   hb_codepoint_t *glyph)
    434 {
    435   return font->get_glyph (unicode, variation_selector, glyph);
    436 }