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