void* ScFace::ScFaceData::hbFont() { if (!m_hbFont) { if (!ftFace()) return NULL; if (formatCode == ScFace::SFNT || formatCode == ScFace::TTCF || formatCode == ScFace::TYPE42) { // use HarfBuzz internal font functions for formats it supports, // gives us more consistent glyph metrics. FT_Reference_Face(ftFace()); hb_face_t *hbFace = hb_face_create_for_tables(referenceTable, ftFace(), (hb_destroy_func_t) FT_Done_Face); hb_face_set_index(hbFace, ftFace()->face_index); hb_face_set_upem(hbFace, ftFace()->units_per_EM); m_hbFont = hb_font_create(hbFace); hb_ot_font_set_funcs(reinterpret_cast<hb_font_t*>(m_hbFont)); hb_face_destroy(hbFace); } else { m_hbFont = hb_ft_font_create_referenced(ftFace()); } } return m_hbFont; }
SFFontRef SFFontCreateWithFTFace(FT_Face ftFace, SFFloat size) { SFFont *sfFont = malloc(sizeof(SFFont)); sfFont->_ftFace = ftFace; sfFont->_tables = SFFontTablesCreate(); sfFont->_retainCount = 1; FT_Reference_Face(ftFace); setFontSize(sfFont, size); return sfFont; }
SFFontRef SFFontMakeCloneForFTFace(SFFontRef sfFont, FT_Face ftFace, SFFloat size) { SFFont *clone = malloc(sizeof(SFFont)); clone->_ftFace = ftFace; clone->_tables = SFFontTablesRetain(sfFont->_tables); clone->_retainCount = 1; FT_Reference_Face(ftFace); setFontSize(clone, size); return clone; }
TTFFont::TTFFont(Palette* pal, FT_Face face, int lineheight, int baseline) : Font(pal, lineheight, baseline), face(face) { // on FT < 2.4.2 the manager will defer ownership to this object #if FREETYPE_VERSION_ATLEAST(2,4,2) FT_Reference_Face(face); // retain the face or the font manager will destroy it #endif // ttf fonts dont produce glyphs for whitespace Sprite2D* blank = core->GetVideoDriver()->CreateSprite8(0, 0, NULL, NULL); // blank for returning when there is an error // TODO: ttf fonts have a "box" glyph they use for this CreateGlyphForCharSprite(0, blank); blank->Width = core->TLKEncoding.zerospace ? 1 : (LineHeight * 0.25);; CreateGlyphForCharSprite(' ', blank); blank->Width *= 4; CreateGlyphForCharSprite('\t', blank); blank->release(); }
static hb_font_t * _raqm_hb_ft_font_create_referenced (FT_Face face) { FT_Reference_Face (face); return hb_ft_font_create (face, (hb_destroy_func_t) FT_Done_Face); }