From 2ce058cdadb320f97b424f5db6b34d0565951578 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 12 Aug 2019 23:43:49 -0400 Subject: fc: Make sure ink rectangle has positive height We are getting extents with negative height from harfbuzz, we have to flip them around. This was causing problems in lilypond. Closes: https://gitlab.gnome.org/GNOME/pango/issues/406 --- pango/pangofc-font.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pango/pangofc-font.c b/pango/pangofc-font.c index 21644b57..72b9931d 100644 --- a/pango/pangofc-font.c +++ b/pango/pangofc-font.c @@ -810,7 +810,7 @@ pango_fc_font_get_raw_extents (PangoFcFont *fcfont, ink_rect->x = extents.x_bearing; ink_rect->width = extents.width; ink_rect->y = -extents.y_bearing; - ink_rect->height = extents.height; + ink_rect->height = -extents.height; } if (logical_rect) -- cgit v1.2.1 From 090120b42847373d6cdd2198c6195b95e56c802f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 12 Aug 2019 23:45:05 -0400 Subject: Add a test for extents We want to make sure that the ink rectangles we return have positive size. --- tests/test-font.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test-font.c b/tests/test-font.c index cea7356c..6b8f45be 100644 --- a/tests/test-font.c +++ b/tests/test-font.c @@ -159,6 +159,35 @@ test_metrics (void) pango_font_description_free (desc); } +static void +test_extents (void) +{ + char *str = "Composer"; + GList *items; + PangoItem *item; + PangoGlyphString *glyphs; + PangoRectangle ink, log; + PangoContext *context; + + context = pango_font_map_create_context (pango_cairo_font_map_get_default ()); + pango_context_set_font_description (context, pango_font_description_from_string ("Cantarell 11")); + + items = pango_itemize (context, str, 0, strlen (str), NULL, NULL); + glyphs = pango_glyph_string_new (); + item = items->data; + pango_shape (str, strlen (str), &item->analysis, glyphs); + pango_glyph_string_extents (glyphs, item->analysis.font, &ink, &log); + + g_assert_cmpint (ink.width, >=, 0); + g_assert_cmpint (ink.height, >=, 0); + g_assert_cmpint (log.width, >=, 0); + g_assert_cmpint (log.height, >=, 0); + + pango_glyph_string_free (glyphs); + g_list_free_full (items, (GDestroyNotify)pango_item_free); + g_object_unref (context); +} + int main (int argc, char *argv[]) { @@ -173,6 +202,7 @@ main (int argc, char *argv[]) g_test_add_func ("/pango/fontdescription/parse", test_parse); g_test_add_func ("/pango/fontdescription/roundtrip", test_roundtrip); g_test_add_func ("/pango/fontdescription/variation", test_variation); + g_test_add_func ("/pango/font/extents", test_extents); return g_test_run (); } -- cgit v1.2.1