diff options
author | Matthias Clasen <mclasen@redhat.com> | 2019-05-24 16:53:28 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2019-07-18 12:47:53 -0700 |
commit | 50d4f9afe67371c96ca7aaef5571fd44abb450d9 (patch) | |
tree | 88baac216c7abd7f191539cea83cf08856745199 /pango/pangofc-font.c | |
parent | 89b8df08725a2da2fe3607fea2231ded1eb5c342 (diff) | |
download | pango-50d4f9afe67371c96ca7aaef5571fd44abb450d9.tar.gz |
fc: Use harfbuzz for font metrics
Note that some of the harfbuzz api we use here
has not landed yet.
See https://github.com/harfbuzz/harfbuzz/pull/1432
Diffstat (limited to 'pango/pangofc-font.c')
-rw-r--r-- | pango/pangofc-font.c | 139 |
1 files changed, 28 insertions, 111 deletions
diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c index 8cbf1ec7..c0f9d9e7 100644 --- a/pango/pangofc-font.c +++ b/pango/pangofc-font.c @@ -47,9 +47,6 @@ #include "pango-impl-utils.h" #include <harfbuzz/hb-ot.h> -#include <fontconfig/fcfreetype.h> - -#include FT_TRUETYPE_TABLES_H enum { PROP_0, @@ -384,135 +381,55 @@ static void get_face_metrics (PangoFcFont *fcfont, PangoFontMetrics *metrics) { - FT_Face face = PANGO_FC_FONT_LOCK_FACE (fcfont); + hb_font_t *hb_font = pango_font_get_hb_font (PANGO_FONT (fcfont)); + hb_font_extents_t extents; + FcMatrix *fc_matrix; - FT_Matrix ft_matrix; - TT_OS2 *os2; gboolean have_transform = FALSE; - if (G_UNLIKELY (!face)) - { - metrics->descent = 0; - metrics->ascent = PANGO_SCALE * PANGO_UNKNOWN_GLYPH_HEIGHT; - metrics->height = metrics->ascent; - metrics->underline_thickness = PANGO_SCALE; - metrics->underline_position = - PANGO_SCALE; - metrics->strikethrough_thickness = PANGO_SCALE; - metrics->strikethrough_position = PANGO_SCALE * (PANGO_UNKNOWN_GLYPH_HEIGHT/2); - return; - } + hb_font_get_extents_for_direction (hb_font, HB_DIRECTION_LTR, &extents); if (FcPatternGetMatrix (fcfont->font_pattern, FC_MATRIX, 0, &fc_matrix) == FcResultMatch) { - ft_matrix.xx = 0x10000L * fc_matrix->xx; - ft_matrix.yy = 0x10000L * fc_matrix->yy; - ft_matrix.xy = 0x10000L * fc_matrix->xy; - ft_matrix.yx = 0x10000L * fc_matrix->yx; - - have_transform = (ft_matrix.xx != 0x10000 || ft_matrix.xy != 0 || - ft_matrix.yx != 0 || ft_matrix.yy != 0x10000); + have_transform = (fc_matrix->xx != 1 || fc_matrix->xy != 0 || + fc_matrix->yx != 0 || fc_matrix->yy != 1); } if (have_transform) { - FT_Vector vector; - - vector.x = 0; - vector.y = face->size->metrics.descender; - FT_Vector_Transform (&vector, &ft_matrix); - metrics->descent = - PANGO_UNITS_26_6 (vector.y); - - vector.x = 0; - vector.y = face->size->metrics.ascender; - FT_Vector_Transform (&vector, &ft_matrix); - metrics->ascent = PANGO_UNITS_26_6 (vector.y); - - vector.x = 0; - vector.y = face->size->metrics.height; - FT_Vector_Transform (&vector, &ft_matrix); - metrics->height = PANGO_UNITS_26_6 (vector.y); - } - else if (fcfont->is_hinted || - (face->face_flags & FT_FACE_FLAG_SCALABLE) == 0) - { - metrics->descent = - PANGO_UNITS_26_6 (face->size->metrics.descender); - metrics->ascent = PANGO_UNITS_26_6 (face->size->metrics.ascender); - metrics->height = PANGO_UNITS_26_6 (face->size->metrics.height); + metrics->descent = - extents.descender * fc_matrix->yy; + metrics->ascent = extents.ascender * fc_matrix->yy; + metrics->height = (extents.ascender - extents.descender + extents.line_gap) * fc_matrix->yy; } else { - FT_Fixed ascender, descender, height; - - descender = FT_MulFix (face->descender, face->size->metrics.y_scale); - metrics->descent = - PANGO_UNITS_26_6 (descender); - - ascender = FT_MulFix (face->ascender, face->size->metrics.y_scale); - metrics->ascent = PANGO_UNITS_26_6 (ascender); - - height = FT_MulFix (face->height, face->size->metrics.y_scale); - metrics->height = PANGO_UNITS_26_6 (height); + metrics->descent = - extents.descender; + metrics->ascent = extents.ascender; + metrics->height = extents.ascender - extents.descender + extents.line_gap; } - metrics->underline_thickness = 0; - metrics->underline_position = 0; + metrics->underline_thickness = PANGO_SCALE; + metrics->underline_position = - PANGO_SCALE; + metrics->strikethrough_thickness = PANGO_SCALE; + metrics->strikethrough_position = metrics->ascent / 2; - { - FT_Fixed ft_thickness, ft_position; + /* FIXME: use the right hb version */ +#if HB_VERSION_ATLEAST(2,5,4) + hb_position_t position; - ft_thickness = FT_MulFix (face->underline_thickness, face->size->metrics.y_scale); - metrics->underline_thickness = PANGO_UNITS_26_6 (ft_thickness); + if (hb_ot_metrics_get_position (hb_font, HB_OT_METRICS_UNDERLINE_SIZE, &position)) + metrics->underline_thickness = position; - ft_position = FT_MulFix (face->underline_position, face->size->metrics.y_scale); - metrics->underline_position = PANGO_UNITS_26_6 (ft_position); - } - - if (metrics->underline_thickness == 0 || metrics->underline_position == 0) - { - metrics->underline_thickness = (PANGO_SCALE * face->size->metrics.y_ppem) / 14; - metrics->underline_position = - metrics->underline_thickness; - } - - - metrics->strikethrough_thickness = 0; - metrics->strikethrough_position = 0; - - os2 = FT_Get_Sfnt_Table (face, ft_sfnt_os2); - if (os2 && os2->version != 0xFFFF) - { - FT_Fixed ft_thickness, ft_position; - - ft_thickness = FT_MulFix (os2->yStrikeoutSize, face->size->metrics.y_scale); - metrics->strikethrough_thickness = PANGO_UNITS_26_6 (ft_thickness); - - ft_position = FT_MulFix (os2->yStrikeoutPosition, face->size->metrics.y_scale); - metrics->strikethrough_position = PANGO_UNITS_26_6 (ft_position); - } - - if (metrics->strikethrough_thickness == 0 || metrics->strikethrough_position == 0) - { - metrics->strikethrough_thickness = metrics->underline_thickness; - metrics->strikethrough_position = (PANGO_SCALE * face->size->metrics.y_ppem) / 4; - } + if (hb_ot_metrics_get_position (hb_font, HB_OT_METRICS_UNDERLINE_OFFSET, &position)) + metrics->underline_position = position; + if (hb_ot_metrics_get_position (hb_font, HB_OT_METRICS_STRIKEOUT_SIZE, &position)) + metrics->strikethrough_thickness = position; - /* If hinting is on for this font, quantize the underline and strikethrough position - * to integer values. - */ - if (fcfont->is_hinted) - { - pango_quantize_line_geometry (&metrics->underline_thickness, - &metrics->underline_position); - pango_quantize_line_geometry (&metrics->strikethrough_thickness, - &metrics->strikethrough_position); - - /* Quantizing may have pushed underline_position to 0. Not good */ - if (metrics->underline_position == 0) - metrics->underline_position = - metrics->underline_thickness; - } - - - PANGO_FC_FONT_UNLOCK_FACE (fcfont); + if (hb_ot_metrics_get_position (hb_font, HB_OT_METRICS_STRIKEOUT_OFFSET, &position)) + metrics->strikethrough_position = position; +#endif } PangoFontMetrics * |