FX_BOOL CFX_Font::GetGlyphBBox(FX_DWORD glyph_index, FX_RECT &bbox) { if (m_Face == NULL) { return FALSE; } if (FXFT_Is_Face_Tricky(m_Face)) { int error = FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72); if (error) { return FALSE; } error = FXFT_Load_Glyph(m_Face, glyph_index, FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH); if (error) { return FALSE; } FXFT_BBox cbox; FT_Glyph glyph; error = FXFT_Get_Glyph(((FXFT_Face)m_Face)->glyph, &glyph); if (error) { return FALSE; } FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); int pixel_size_x = ((FXFT_Face)m_Face)->size->metrics.x_ppem, pixel_size_y = ((FXFT_Face)m_Face)->size->metrics.y_ppem; if (pixel_size_x == 0 || pixel_size_y == 0) { bbox.left = cbox.xMin; bbox.right = cbox.xMax; bbox.top = cbox.yMax; bbox.bottom = cbox.yMin; } else { bbox.left = cbox.xMin * 1000 / pixel_size_x; bbox.right = cbox.xMax * 1000 / pixel_size_x; bbox.top = cbox.yMax * 1000 / pixel_size_y; bbox.bottom = cbox.yMin * 1000 / pixel_size_y; } if (bbox.top > FXFT_Get_Face_Ascender(m_Face)) { bbox.top = FXFT_Get_Face_Ascender(m_Face); } if (bbox.bottom < FXFT_Get_Face_Descender(m_Face)) { bbox.bottom = FXFT_Get_Face_Descender(m_Face); } FT_Done_Glyph(glyph); return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; } if (FXFT_Load_Glyph(m_Face, glyph_index, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { return FALSE; } int em = FXFT_Get_Face_UnitsPerEM(m_Face); if (em == 0) { bbox.left = FXFT_Get_Glyph_HoriBearingX(m_Face); bbox.bottom = FXFT_Get_Glyph_HoriBearingY(m_Face); bbox.top = bbox.bottom - FXFT_Get_Glyph_Height(m_Face); bbox.right = bbox.left + FXFT_Get_Glyph_Width(m_Face); } else { bbox.left = FXFT_Get_Glyph_HoriBearingX(m_Face) * 1000 / em; bbox.top = (FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)) * 1000 / em; bbox.right = (FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)) * 1000 / em; bbox.bottom = (FXFT_Get_Glyph_HoriBearingY(m_Face)) * 1000 / em; } return TRUE; }
FX_BOOL CFPF_SkiaFont::GetGlyphBBox(FX_INT32 iGlyphIndex, FX_RECT &rtBBox) { if (!m_Face) { return FALSE; } if (FXFT_Is_Face_Tricky(m_Face)) { if (FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72)) { return FALSE; } if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { FXFT_Set_Pixel_Sizes(m_Face, 0, 64); return FALSE; } FXFT_Glyph glyph; if (FXFT_Get_Glyph(m_Face->glyph, &glyph)) { FXFT_Set_Pixel_Sizes(m_Face, 0, 64); return FALSE; } FXFT_BBox cbox; FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); FX_INT32 x_ppem = m_Face->size->metrics.x_ppem; FX_INT32 y_ppem = m_Face->size->metrics.y_ppem; rtBBox.left = FPF_EM_ADJUST(x_ppem, cbox.xMin); rtBBox.right = FPF_EM_ADJUST(x_ppem, cbox.xMax); rtBBox.top = FPF_EM_ADJUST(y_ppem, cbox.yMax); rtBBox.bottom = FPF_EM_ADJUST(y_ppem, cbox.yMin); rtBBox.top = FX_MIN(rtBBox.top, GetAscent()); rtBBox.bottom = FX_MAX(rtBBox.bottom, GetDescent()); FXFT_Done_Glyph(glyph); return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; } if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { return FALSE; } rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriBearingX(m_Face)); rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriBearingY(m_Face)); rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)); rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)); return TRUE; }