[pango/simple-fontmap: 4/13] Add some more PangoHbFace and PangoHbFont tests




commit b5ff6b2a92f9b60b1bd64a54a4de8ce207d56a3f
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/testhbfont.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 123 insertions(+)
---
diff --git a/tests/testhbfont.c b/tests/testhbfont.c
index 4a6f8c3c..4db05026 100644
--- a/tests/testhbfont.c
+++ b/tests/testhbfont.c
@@ -63,12 +63,135 @@ test_hbfont_monospace (void)
   g_object_unref (map);
 }
 
+/* Verify that a description -> face -> description roundtrip works for
+ * PangoHbFaces created with pango_hb_face_new_variant
+ */
+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);
+}
+
+/* Verify that face -> font -> description works as expected for PangoHbFont */
+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[])
 {
   g_test_init (&argc, &argv, NULL);
 
   g_test_add_func ("/hbfont/monospace", test_hbfont_monospace);
+  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]