[pango/simple-fontmap: 272/278] Add a test for PangoHbFont glyph extents




commit a366de58a201229642c53235fd54676a27cbfc29
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Oct 30 23:14:25 2021 -0400

    Add a test for PangoHbFont glyph extents

 tests/testmisc.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
---
diff --git a/tests/testmisc.c b/tests/testmisc.c
index 67e28495..31d78ff3 100644
--- a/tests/testmisc.c
+++ b/tests/testmisc.c
@@ -726,6 +726,53 @@ test_gravity_metrics (void)
   g_object_unref (context);
 }
 
+static void
+test_gravity_metrics2 (void)
+{
+  PangoSimpleFontMap *map;
+  PangoContext *context;
+  PangoFontDescription *desc;
+  PangoFont *font;
+  PangoGlyph glyph;
+  PangoGravity gravity;
+  PangoRectangle ink[4];
+  PangoRectangle log[4];
+
+  map = pango_simple_font_map_new ();
+  pango_simple_font_map_add_file (map, "/usr/share/fonts/cantarell/Cantarell-VF.otf", 0, 0);
+
+  context = pango_font_map_create_context (PANGO_FONT_MAP (map));
+
+  desc = pango_font_description_from_string ("Cantarell 64");
+
+  glyph = 1; /* A */
+
+  for (gravity = PANGO_GRAVITY_SOUTH; gravity <= PANGO_GRAVITY_WEST; gravity++)
+    {
+      pango_font_description_set_gravity (desc, gravity);
+      font = pango_font_map_load_font (PANGO_FONT_MAP (map), context, desc);
+      pango_font_get_glyph_extents (font, glyph, &ink[gravity], &log[gravity]);
+      g_object_unref (font);
+    }
+
+  g_assert_cmpint (ink[PANGO_GRAVITY_EAST].width, ==, ink[PANGO_GRAVITY_SOUTH].height);
+  g_assert_cmpint (ink[PANGO_GRAVITY_EAST].height, ==, ink[PANGO_GRAVITY_SOUTH].width);
+  g_assert_cmpint (ink[PANGO_GRAVITY_NORTH].width, ==, ink[PANGO_GRAVITY_SOUTH].width);
+  g_assert_cmpint (ink[PANGO_GRAVITY_NORTH].height, ==, ink[PANGO_GRAVITY_SOUTH].height);
+  g_assert_cmpint (ink[PANGO_GRAVITY_WEST].width, ==, ink[PANGO_GRAVITY_SOUTH].height);
+  g_assert_cmpint (ink[PANGO_GRAVITY_WEST].height, ==, ink[PANGO_GRAVITY_SOUTH].width);
+
+  /* Seems that harfbuzz has some off-by-one differences in advance width
+   * when fonts differ by a scale of -1.
+   */ 
+  g_assert_cmpint (log[PANGO_GRAVITY_SOUTH].width + log[PANGO_GRAVITY_NORTH].width, <=, 1);
+  g_assert_cmpint (log[PANGO_GRAVITY_EAST].width, ==, log[PANGO_GRAVITY_WEST].width);
+
+  pango_font_description_free (desc);
+  g_object_unref (context);
+  g_object_unref (map);
+}
+
 static void
 test_transform_rectangle (void)
 {
@@ -883,6 +930,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/layout/empty-line-height", test_empty_line_height);
   g_test_add_func ("/layout/gravity-metrics", test_gravity_metrics);
   g_test_add_func ("/layout/wrap-char", test_wrap_char);
+  g_test_add_func ("/layout/gravity-metrics2", test_gravity_metrics2);
   g_test_add_func ("/matrix/transform-rectangle", test_transform_rectangle);
   g_test_add_func ("/itemize/small-caps-crash", test_small_caps_crash);
   g_test_add_func ("/hbfont/monospace", test_hbfont_monospace);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]