[pango/simple-fontmap: 24/31] Add a PangoFcHbFontMap test
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/simple-fontmap: 24/31] Add a PangoFcHbFontMap test
- Date: Thu, 6 Jan 2022 19:09:02 +0000 (UTC)
commit a9c9778c01d9190809fd0141dfdfa254537226e1
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jan 1 17:44:46 2022 -0500
Add a PangoFcHbFontMap test
pango/pangofc-hbfontmap.c | 15 ++-----
tests/testhbfont.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 114 insertions(+), 11 deletions(-)
---
diff --git a/pango/pangofc-hbfontmap.c b/pango/pangofc-hbfontmap.c
index 45e7adfe..0ce9d1d5 100644
--- a/pango/pangofc-hbfontmap.c
+++ b/pango/pangofc-hbfontmap.c
@@ -289,7 +289,6 @@ pango_hb_face_from_pattern (PangoFcHbFontMap *self,
int instance_id;
PangoFontDescription *description;
const char *name;
- PangoHbFace *orig;
PangoHbFace *face;
PangoMatrix font_matrix;
FcLangSet *langs;
@@ -319,11 +318,7 @@ pango_hb_face_from_pattern (PangoFcHbFontMap *self,
description = pango_font_description_from_pattern (pattern);
name = style_name_from_pattern (pattern);
- orig = find_face_by_file (self, family_name, file, index);
- if (orig)
- face = pango_hb_face_new_variant (orig, instance_id, NULL, FALSE, description);
- else
- face = pango_hb_face_new_from_file (file, index, instance_id, name, description);
+ face = pango_hb_face_new_from_file (file, index, instance_id, name, description);
pango_font_description_free (description);
@@ -466,6 +461,7 @@ pango_fc_hb_font_map_populate (PangoHbFontMap *map)
FcLangSet *langs;
int spacing;
const char *family_name;
+ const char *name;
pat = ret->fonts[j];
@@ -504,12 +500,9 @@ pango_fc_hb_font_map_populate (PangoHbFontMap *map)
desc = pango_font_description_new ();
pango_font_description_set_family (desc, generic_names[i]);
+ name = pango_font_face_get_face_name (PANGO_FONT_FACE (face));
pango_hb_font_map_add_face (PANGO_HB_FONT_MAP (self),
- pango_hb_face_new_variant (PANGO_HB_FACE (face),
- 0xffff,
- NULL,
- FALSE,
- desc));
+ pango_hb_face_new_synthetic (face, NULL, FALSE, name, desc));
pango_font_description_free (desc);
n_faces++;
diff --git a/tests/testhbfont.c b/tests/testhbfont.c
index 70004c4c..2264e1af 100644
--- a/tests/testhbfont.c
+++ b/tests/testhbfont.c
@@ -22,6 +22,7 @@
#include "config.h"
#include <glib.h>
#include <pango/pangocairo.h>
+#include <pango/pangofc-hbfontmap.h>
#include <hb-ot.h>
@@ -424,6 +425,113 @@ test_hbfont_load (void)
g_object_unref (map);
}
+/* Test font -> description -> font roundtrips with variations */
+static void
+test_hbfont_load_variation (void)
+{
+ PangoHbFontMap *map;
+ PangoContext *context;
+ char *path;
+ PangoFontDescription *desc;
+ PangoHbFace *face_fat, *face_wild;
+ char *s;
+ PangoFont *font;
+ hb_variation_t v;
+ hb_font_t *hb_font;
+ const float *coords;
+ unsigned int length;
+
+ /* Make a Cat family, with the two faces Fat and Wild */
+ map = pango_hb_font_map_new ();
+ context = pango_font_map_create_context (PANGO_FONT_MAP (map));
+
+ path = g_test_build_filename (G_TEST_DIST, "fonts", "Cantarell-VF.otf", NULL);
+ desc = pango_font_description_new ();
+ pango_font_description_set_family (desc, "Cat");
+ face_fat = pango_hb_face_new_from_file (path, 0, -1, "Fat", desc);
+ pango_font_description_free (desc);
+ g_free (path);
+
+ pango_hb_font_map_add_face (map, face_fat);
+
+ desc = pango_font_description_new ();
+ pango_font_description_set_family (desc, "Cat");
+ v.tag = HB_OT_TAG_VAR_AXIS_WEIGHT;
+ v.value = 624.;
+ face_wild = pango_hb_face_new_instance (face_fat, &v, 1, "Wild", desc);
+ pango_font_description_free (desc);
+
+ pango_hb_font_map_add_face (map, face_wild);
+
+ desc = pango_font_face_describe (PANGO_FONT_FACE (face_wild));
+
+ g_assert_cmpstr (pango_font_description_get_variations (desc), ==, "wght=624");
+
+ pango_font_description_set_size (desc, 12 * PANGO_SCALE);
+
+ s = pango_font_description_to_string (desc);
+ g_assert_cmpstr (s, ==, "Cat 12 @faceid=hb:Cantarell-Regular:0:-1:0:1:1:0:wght_624,wght=624");
+ g_free (s);
+
+ font = pango_font_map_load_font (PANGO_FONT_MAP (map), context, desc);
+ g_assert_true (pango_font_get_face (font) == PANGO_FONT_FACE (face_wild));
+
+ hb_font = pango_font_get_hb_font (font);
+ coords = hb_font_get_var_coords_design (hb_font, &length);
+ g_assert_cmpint (length, ==, 1);
+ g_assert_cmphex (coords[0], ==, 624.);
+
+ g_object_unref (font);
+
+ pango_font_description_free (desc);
+
+ g_object_unref (context);
+ g_object_unref (map);
+}
+
+/* Verify that pango_fontmap_load_fontset produces a non-empty result
+ * even if the language isn't covered - our itemization code relies
+ * on this.
+ */
+static gboolean
+get_font (PangoFontset *fontset,
+ PangoFont *font,
+ gpointer data)
+{
+ gboolean *found = data;
+
+ *found = TRUE;
+
+ return TRUE;
+}
+
+static void
+test_hbfont_language (void)
+{
+ PangoFontMap *map;
+ PangoContext *context;
+ PangoFontDescription *desc;
+ PangoFontset *fonts;
+ gboolean found;
+
+ map = PANGO_FONT_MAP (pango_fc_hb_font_map_new ());
+ context = pango_font_map_create_context (map);
+ desc = pango_font_description_from_string ("serif 11");
+
+ /* zz isn't assigned, so there should not be any fonts claiming to support
+ * this language. We are expecting to get a nonempty fontset regardless.
+ */
+ fonts = pango_font_map_load_fontset (map, context, desc, pango_language_from_string ("zz"));
+ g_assert_true (PANGO_IS_FONTSET (fonts));
+
+ found = FALSE;
+ pango_fontset_foreach (fonts, get_font, &found);
+ g_assert_true (found);
+
+ g_object_unref (fonts);
+ pango_font_description_free (desc);
+}
+
int
main (int argc, char *argv[])
{
@@ -436,6 +544,8 @@ main (int argc, char *argv[])
g_test_add_func ("/hbfont/describe/variation", test_hbfont_describe_variation);
g_test_add_func ("/hbfont/faceid", test_hbfont_faceid);
g_test_add_func ("/hbfont/load", test_hbfont_load);
+ g_test_add_func ("/hbfont/load/variation", test_hbfont_load_variation);
+ g_test_add_func ("/hbfont/language", test_hbfont_language);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]