のねのBlog

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

harfbuzzGetGlyph

    341 hb_font_funcs_t* getHbFontFuncs() {
    342     static hb_font_funcs_t* hbFontFuncs = 0;
    343 
    344     if (hbFontFuncs == 0) {
    345         hbFontFuncs = hb_font_funcs_create();
    346         hb_font_funcs_set_glyph_func(           hbFontFuncs, harfbuzzGetGlyph,                  0, 0);
    347         hb_font_funcs_set_glyph_h_advance_func( hbFontFuncs, harfbuzzGetGlyphHorizontalAdvance, 0, 0);
    348         hb_font_funcs_set_glyph_h_origin_func(  hbFontFuncs, harfbuzzGetGlyphHorizontalOrigin,  0, 0);
    349         hb_font_funcs_make_immutable(           hbFontFuncs);
    350     }
    351     return hbFontFuncs;
    352 }
    308 static hb_bool_t harfbuzzGetGlyph(
                                  hb_font_t* hbFont, 
                                  void* fontData,
                                  hb_codepoint_t unicode,
                                  hb_codepoint_t variationSelector,
                                  hb_codepoint_t* glyph,
                                  void* userData)
    309 {
    310     MinikinPaint* paint = reinterpret_cast<MinikinPaint*>(fontData);
    311     MinikinFont* font = paint->font;
    312     uint32_t glyph_id;
    313     /* HarfBuzz replaces broken input codepoints with (unsigned int) -1.
    314      * Skia expects valid Unicode.
    315      * Replace invalid codepoints with U+FFFD REPLACEMENT CHARACTER.
    316      */
    317     if (unicode > 0x10FFFF)
    318         unicode = 0xFFFD;
    319     bool ok = font->GetGlyph(unicode, &glyph_id);
    320     if (ok) {
    321         *glyph = glyph_id;
    322     }
    323     return ok;
    324 }
     35 bool MinikinFontSkia::GetGlyph(uint32_t codepoint, uint32_t *glyph) const {
     36     SkPaint paint;
     37     paint.setTypeface(mTypeface);
     38     paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
     39     uint16_t glyph16;
     40     paint.textToGlyphs(&codepoint, sizeof(codepoint), &glyph16);
     41     *glyph  = glyph16;
     42     return !!glyph16;
     43 }