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
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 }