summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-05-24 17:15:19 +0000
committerMatthias Clasen <mclasen@redhat.com>2019-07-12 09:04:21 -0400
commit030182ec80730ce9c8a176721d3b3bb6d40c9335 (patch)
treecd82147029009df816233d9d236ee1cdac73cc51
parenta7a6e95d05791f171f92d4df34d7a33626523238 (diff)
downloadpango-030182ec80730ce9c8a176721d3b3bb6d40c9335.tar.gz
fc: Use harfbuzz for glyph extents
Harfbuzz has the api, no need to use freetype.
-rw-r--r--pango/pangofc-font.c91
1 files changed, 28 insertions, 63 deletions
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c
index 081cfd7e..c7fd066a 100644
--- a/pango/pangofc-font.c
+++ b/pango/pangofc-font.c
@@ -799,23 +799,6 @@ _pango_fc_font_set_font_key (PangoFcFont *fcfont,
priv->key = key;
}
-static FT_Glyph_Metrics *
-get_per_char (FT_Face face,
- FT_Int32 load_flags,
- PangoGlyph glyph)
-{
- FT_Error error;
- FT_Glyph_Metrics *result;
-
- error = FT_Load_Glyph (face, glyph, load_flags);
- if (error == FT_Err_Ok)
- result = &face->glyph->metrics;
- else
- result = NULL;
-
- return result;
-}
-
/**
* pango_fc_font_get_raw_extents:
* @fcfont: a #PangoFcFont
@@ -845,76 +828,58 @@ pango_fc_font_get_raw_extents (PangoFcFont *fcfont,
PangoRectangle *ink_rect,
PangoRectangle *logical_rect)
{
- FT_Glyph_Metrics *gm;
- FT_Face face;
-
g_return_if_fail (PANGO_IS_FC_FONT (fcfont));
- face = PANGO_FC_FONT_LOCK_FACE (fcfont);
- if (G_UNLIKELY (!face))
- {
- /* Get generic unknown-glyph extents. */
- pango_font_get_glyph_extents (NULL, glyph, ink_rect, logical_rect);
- return;
- }
-
if (glyph == PANGO_GLYPH_EMPTY)
- gm = NULL;
- else
- gm = get_per_char (face, load_flags, glyph);
-
- if (gm)
{
if (ink_rect)
{
- ink_rect->x = PANGO_UNITS_26_6 (gm->horiBearingX);
- ink_rect->width = PANGO_UNITS_26_6 (gm->width);
- ink_rect->y = -PANGO_UNITS_26_6 (gm->horiBearingY);
- ink_rect->height = PANGO_UNITS_26_6 (gm->height);
+ ink_rect->x = 0;
+ ink_rect->width = 0;
+ ink_rect->y = 0;
+ ink_rect->height = 0;
}
if (logical_rect)
{
logical_rect->x = 0;
- logical_rect->width = PANGO_UNITS_26_6 (gm->horiAdvance);
- if (fcfont->is_hinted ||
- (face->face_flags & FT_FACE_FLAG_SCALABLE) == 0)
- {
- logical_rect->y = - PANGO_UNITS_26_6 (face->size->metrics.ascender);
- logical_rect->height = PANGO_UNITS_26_6 (face->size->metrics.ascender - face->size->metrics.descender);
- }
- else
- {
- FT_Fixed ascender, descender;
-
- ascender = FT_MulFix (face->ascender, face->size->metrics.y_scale);
- descender = FT_MulFix (face->descender, face->size->metrics.y_scale);
-
- logical_rect->y = - PANGO_UNITS_26_6 (ascender);
- logical_rect->height = PANGO_UNITS_26_6 (ascender - descender);
- }
+ logical_rect->width = 0;
+ logical_rect->y = 0;
+ logical_rect->height = 0;
}
}
else
{
+ hb_font_t *hb_font = pango_font_get_hb_font (PANGO_FONT (fcfont));
+ hb_glyph_extents_t extents;
+ hb_font_extents_t font_extents;
+
+ hb_font_get_glyph_extents (hb_font, glyph, &extents);
+ hb_font_get_extents_for_direction (hb_font, HB_DIRECTION_LTR, &font_extents);
+
if (ink_rect)
{
- ink_rect->x = 0;
- ink_rect->width = 0;
- ink_rect->y = 0;
- ink_rect->height = 0;
+ ink_rect->x = extents.x_bearing;
+ ink_rect->width = extents.width;
+ ink_rect->y = -extents.y_bearing;
+ ink_rect->height = extents.height;
}
if (logical_rect)
{
+ hb_position_t x, y;
+
+ hb_font_get_glyph_advance_for_direction (hb_font,
+ glyph,
+ HB_DIRECTION_LTR,
+ &x, &y);
+
logical_rect->x = 0;
- logical_rect->width = 0;
- logical_rect->y = 0;
- logical_rect->height = 0;
+ logical_rect->width = x;
+ logical_rect->y = - font_extents.ascender;
+ logical_rect->height = font_extents.ascender - font_extents.descender;
}
}
-
- PANGO_FC_FONT_UNLOCK_FACE (fcfont);
}
static void