[pango/simple-fontmap: 10/10] testmisc: Add a test for pango_font_describe




commit bd14d7291dffda22213d15488ab315305fe62371
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Dec 27 09:12:57 2021 -0500

    testmisc: Add a test for pango_font_describe

 tests/testhbfont.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
---
diff --git a/tests/testhbfont.c b/tests/testhbfont.c
index 2aa6ab4a..d05c5bdb 100644
--- a/tests/testhbfont.c
+++ b/tests/testhbfont.c
@@ -236,6 +236,42 @@ test_hbfont_language (void)
   g_object_unref (map);
 }
 
+/* Verify that pango_font_describe and pango_font_describe_with_absolute_size
+ * work as expected with PangoHbFont
+ */
+static void
+test_hbfont_describe (void)
+{
+  char *path;
+  PangoHbFace *face;
+  PangoHbFont *font;
+  PangoFontDescription *desc;
+
+  path = g_test_build_filename (G_TEST_DIST, "fonts", "Cantarell-VF.otf", NULL);
+
+  face = pango_hb_face_new_from_file (path, 0, -1, NULL, NULL);
+  g_assert_true (PANGO_IS_HB_FACE (face));
+
+  font = pango_hb_font_new (face, 11 * PANGO_SCALE, NULL, 0, NULL, PANGO_GRAVITY_AUTO, 96., NULL);
+  g_assert_true (PANGO_IS_HB_FONT (font));
+
+  desc = pango_font_describe (PANGO_FONT (font));
+  g_assert_cmpstr (pango_font_description_get_family (desc), ==, "Cantarell");
+  g_assert_cmpint (pango_font_description_get_size (desc), ==, 11 * PANGO_SCALE);
+  g_assert_true (!pango_font_description_get_size_is_absolute (desc));
+  pango_font_description_free (desc);
+
+  desc = pango_font_describe_with_absolute_size (PANGO_FONT (font));
+  g_assert_cmpstr (pango_font_description_get_family (desc), ==, "Cantarell");
+  g_assert_cmpint (pango_font_description_get_size (desc), ==, 11 * PANGO_SCALE * 96./72.);
+  g_assert_true (pango_font_description_get_size_is_absolute (desc));
+  pango_font_description_free (desc);
+
+  g_object_unref (font);
+  g_object_unref (face);
+  g_free (path);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -245,6 +281,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/hbface/roundtrip", test_hbface_roundtrip);
   g_test_add_func ("/hbfont/roundtrip", test_hbfont_roundtrip);
   g_test_add_func ("/hbfont/language", test_hbfont_language);
+  g_test_add_func ("/hbfont/describe", test_hbfont_describe);
 
   return g_test_run ();
 }


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