[pango/simple-fontmap: 23/31] Add some more PangoHbFace and PangoHbFont tests




commit 181a3336225db1ca83cc5a1d44b43bf8b8306822
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Dec 24 17:46:09 2021 -0500

    Add some more PangoHbFace and PangoHbFont tests
    
    Test roundtripping font descriptions.

 tests/testmisc.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 118 insertions(+)
---
diff --git a/tests/testmisc.c b/tests/testmisc.c
index 1337a91e..e10491bd 100644
--- a/tests/testmisc.c
+++ b/tests/testmisc.c
@@ -900,6 +900,122 @@ test_hbfont_monospace (void)
   g_object_unref (map);
 }
 
+static void
+test_hbface_roundtrip (void)
+{
+  char *path;
+  PangoHbFace *face;
+  PangoHbFace *face2;
+  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));
+  g_assert_cmpstr (pango_font_face_get_face_name (PANGO_FONT_FACE (face)), ==, "Regular");
+  desc = pango_font_face_describe (PANGO_FONT_FACE (face));
+  g_assert_cmpint (pango_font_description_get_set_fields (desc), ==, PANGO_FONT_MASK_FAMILY |
+                                                                     PANGO_FONT_MASK_STYLE |
+                                                                     PANGO_FONT_MASK_WEIGHT |
+                                                                     PANGO_FONT_MASK_STRETCH);
+  g_assert_cmpstr (pango_font_description_get_family (desc), ==, "Cantarell");
+  g_assert_cmpint (pango_font_description_get_style (desc), ==, PANGO_STYLE_NORMAL);
+  g_assert_cmpint (pango_font_description_get_weight (desc), ==, PANGO_WEIGHT_NORMAL);
+  g_assert_cmpint (pango_font_description_get_stretch (desc), ==, PANGO_STRETCH_NORMAL);
+  pango_font_description_free (desc);
+
+  desc = pango_font_description_new ();
+  pango_font_description_set_style (desc, PANGO_STYLE_OBLIQUE);
+  face2 = pango_hb_face_new_variant (face, &(PangoMatrix){ 1, 0.2, 0, 1, 0, 0 }, FALSE, desc);
+  pango_font_description_free (desc);
+  g_assert_true (PANGO_IS_HB_FACE (face2));
+  g_assert_cmpstr (pango_font_face_get_face_name (PANGO_FONT_FACE (face2)), ==, "Oblique");
+  desc = pango_font_face_describe (PANGO_FONT_FACE (face2));
+  g_assert_cmpint (pango_font_description_get_set_fields (desc), ==, PANGO_FONT_MASK_FAMILY |
+                                                                     PANGO_FONT_MASK_STYLE |
+                                                                     PANGO_FONT_MASK_WEIGHT |
+                                                                     PANGO_FONT_MASK_STRETCH);
+  g_assert_cmpstr (pango_font_description_get_family (desc), ==, "Cantarell");
+  g_assert_cmpint (pango_font_description_get_style (desc), ==, PANGO_STYLE_OBLIQUE);
+  g_assert_cmpint (pango_font_description_get_weight (desc), ==, PANGO_WEIGHT_NORMAL);
+  g_assert_cmpint (pango_font_description_get_stretch (desc), ==, PANGO_STRETCH_NORMAL);
+  pango_font_description_free (desc);
+  g_object_unref (face2);
+
+  desc = pango_font_description_new ();
+  pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD);
+  face2 = pango_hb_face_new_variant (face, NULL, TRUE, desc);
+  pango_font_description_free (desc);
+  g_assert_true (PANGO_IS_HB_FACE (face2));
+  g_assert_cmpstr (pango_font_face_get_face_name (PANGO_FONT_FACE (face2)), ==, "Bold");
+  desc = pango_font_face_describe (PANGO_FONT_FACE (face2));
+  g_assert_cmpint (pango_font_description_get_set_fields (desc), ==, PANGO_FONT_MASK_FAMILY |
+                                                                     PANGO_FONT_MASK_STYLE |
+                                                                     PANGO_FONT_MASK_WEIGHT |
+                                                                     PANGO_FONT_MASK_STRETCH);
+  g_assert_cmpstr (pango_font_description_get_family (desc), ==, "Cantarell");
+  g_assert_cmpint (pango_font_description_get_style (desc), ==, PANGO_STYLE_NORMAL);
+  g_assert_cmpint (pango_font_description_get_weight (desc), ==, PANGO_WEIGHT_BOLD);
+  g_assert_cmpint (pango_font_description_get_stretch (desc), ==, PANGO_STRETCH_NORMAL);
+  pango_font_description_free (desc);
+  g_object_unref (face2);
+
+  desc = pango_font_description_new ();
+  pango_font_description_set_family (desc, "Cantarellagain");
+  face2 = pango_hb_face_new_variant (face, NULL, FALSE, desc);
+  pango_font_description_free (desc);
+  g_assert_true (PANGO_IS_HB_FACE (face2));
+  g_assert_cmpstr (pango_font_face_get_face_name (PANGO_FONT_FACE (face2)), ==, "Regular");
+  desc = pango_font_face_describe (PANGO_FONT_FACE (face2));
+  g_assert_cmpint (pango_font_description_get_set_fields (desc), ==, PANGO_FONT_MASK_FAMILY |
+                                                                     PANGO_FONT_MASK_STYLE |
+                                                                     PANGO_FONT_MASK_WEIGHT |
+                                                                     PANGO_FONT_MASK_STRETCH);
+  g_assert_cmpstr (pango_font_description_get_family (desc), ==, "Cantarellagain");
+  g_assert_cmpint (pango_font_description_get_style (desc), ==, PANGO_STYLE_NORMAL);
+  g_assert_cmpint (pango_font_description_get_weight (desc), ==, PANGO_WEIGHT_NORMAL);
+  g_assert_cmpint (pango_font_description_get_stretch (desc), ==, PANGO_STRETCH_NORMAL);
+  pango_font_description_free (desc);
+  g_object_unref (face2);
+
+  g_object_unref (face);
+  g_free (path);
+}
+
+static void
+test_hbfont_roundtrip (void)
+{
+  char *path;
+  PangoHbFace *face;
+  PangoHbFont *font;
+  PangoFontDescription *desc;
+  hb_feature_t features[10];
+  unsigned int n_features;
+
+  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));
+  g_assert_true (pango_font_get_face (PANGO_FONT (font)) == PANGO_FONT_FACE (face));
+  pango_font_get_features (PANGO_FONT (font), features, 10, &n_features);
+  g_assert_cmpint (n_features, ==, 0);
+
+  desc = pango_font_describe (PANGO_FONT (font));
+  g_assert_cmpstr (pango_font_description_get_family (desc), ==, "Cantarell");
+  g_assert_cmpint (pango_font_description_get_style (desc), ==, PANGO_STYLE_NORMAL);
+  g_assert_cmpint (pango_font_description_get_weight (desc), ==, PANGO_WEIGHT_NORMAL);
+  g_assert_cmpint (pango_font_description_get_stretch (desc), ==, PANGO_STRETCH_NORMAL);
+  g_assert_cmpint (pango_font_description_get_size (desc), ==, 11 * PANGO_SCALE);
+  pango_font_description_free (desc);
+
+  g_object_unref (font);
+  g_object_unref (face);
+  g_free (path);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -937,6 +1053,8 @@ main (int argc, char *argv[])
   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);
+  g_test_add_func ("/hbface/roundtrip", test_hbface_roundtrip);
+  g_test_add_func ("/hbfont/roundtrip", test_hbfont_roundtrip);
 
   return g_test_run ();
 }


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