[pango/simple-fontmap: 14/22] Add a PangoFcHbFontMap test
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/simple-fontmap: 14/22] Add a PangoFcHbFontMap test
- Date: Wed, 29 Dec 2021 20:14:59 +0000 (UTC)
commit 56ea1dc92fea78a1334512ae2d1579073954fd3f
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 28 09:35:44 2021 -0500
Add a PangoFcHbFontMap test
pango/pangofc-hbfontmap.c | 122 +++++++---------------------------------------
tests/testhbfont.c | 47 ++++++++++++++++++
2 files changed, 64 insertions(+), 105 deletions(-)
---
diff --git a/pango/pangofc-hbfontmap.c b/pango/pangofc-hbfontmap.c
index e0f45570..ccbc25c4 100644
--- a/pango/pangofc-hbfontmap.c
+++ b/pango/pangofc-hbfontmap.c
@@ -70,11 +70,11 @@ find_face_by_file (PangoFcHbFontMap *self,
unsigned int index,
int instance_id)
{
- PangoHbFontMap *simple = PANGO_HB_FONT_MAP (self);
+ PangoHbFontMap *map = PANGO_HB_FONT_MAP (self);
- for (int i = 0; i < simple->families->len; i++)
+ for (int i = 0; i < map->families->len; i++)
{
- PangoHbFamily *family = g_ptr_array_index (simple->families, i);
+ PangoHbFamily *family = g_ptr_array_index (map->families, i);
for (int j = 0; j < family->faces->len; j++)
{
@@ -91,7 +91,7 @@ find_face_by_file (PangoFcHbFontMap *self,
}
/* }}} */
-/* {{{ Fontconfig utilities */
+/* {{{ Fontconfig utilities */
static gboolean
is_supported_font_format (FcPattern *pattern)
@@ -361,9 +361,9 @@ pango_hb_face_from_pattern (FcPattern *pattern,
}
static void
-pango_fc_hb_font_map_populate (PangoHbFontMap *simple)
+pango_fc_hb_font_map_populate (PangoHbFontMap *map)
{
- PangoFcHbFontMap *self = PANGO_FC_HB_FONT_MAP (simple);
+ PangoFcHbFontMap *self = PANGO_FC_HB_FONT_MAP (map);
FcPattern *pat;
FcFontSet *fontset;
int k;
@@ -399,9 +399,15 @@ pango_fc_hb_font_map_populate (PangoHbFontMap *simple)
FcFontSetDestroy (fontset);
- /* Add alias families */
+ /* Add generic aliases */
const char *alias_names[] = {
- "monospace", "sans-serif", "serif", "cursive", "fantasy", "system-ui", "emoji"
+ "monospace",
+ "sans-serif",
+ "serif",
+ "cursive",
+ "fantasy",
+ "system-ui",
+ "emoji"
};
FcLangSet *no_langs = FcLangSetCreate ();
FcLangSet *emoji_langs = FcLangSetCreate ();
@@ -491,101 +497,7 @@ pango_fc_hb_font_map_populate (PangoHbFontMap *simple)
FcObjectSetDestroy (os);
- /* Synthesize missing Bold and Italics */
- for (int i = 0; i < PANGO_HB_FONT_MAP (self)->families->len; i++)
- {
- PangoHbFamily *family = g_ptr_array_index (PANGO_HB_FONT_MAP (self)->families, i);
- PangoHbFace *regular_face = NULL;
- int regular_weight = 0;
- int bold_weight = 1000;
- gboolean has_italic = FALSE;
- gboolean has_bold = FALSE;
- gboolean has_bold_italic = FALSE;
-
- for (int j = 0; j < g_list_model_get_n_items (G_LIST_MODEL (family)); j++)
- {
- PangoFontFace *face = g_list_model_get_item (G_LIST_MODEL (family), j);
- PangoFontDescription *desc;
- int weight;
- PangoStyle style;
-
- desc = pango_font_face_describe (face);
- weight = pango_font_description_get_weight (desc);
- style = pango_font_description_get_style (desc);
- pango_font_description_free (desc);
-
- if (style == PANGO_STYLE_NORMAL)
- {
- if (abs (weight - (int)PANGO_WEIGHT_NORMAL) < abs (regular_weight - (int)PANGO_WEIGHT_NORMAL))
- {
- regular_weight = weight;
- regular_face = PANGO_HB_FACE (face);
- }
- if (abs (weight - (int)PANGO_WEIGHT_BOLD) < abs (bold_weight - (int)PANGO_WEIGHT_BOLD))
- {
- bold_weight = weight;
- has_bold = TRUE;
- }
- }
- else
- {
- if (weight < PANGO_WEIGHT_SEMIBOLD)
- has_italic = TRUE;
- else
- has_bold_italic = TRUE;
- }
-
- g_object_unref (face);
- }
-
- if (regular_face && !has_italic)
- {
- PangoFontDescription *desc;
- PangoHbFace *face;
-
- desc = pango_font_description_new ();
- pango_font_description_set_style (desc, PANGO_STYLE_ITALIC);
- face = pango_hb_face_new_variant (regular_face,
- &(PangoMatrix) { 1, -0.2, 0, 1, 0, 0 },
- FALSE,
- desc);
- pango_hb_family_add_face (family, face);
- g_object_unref (face);
- pango_font_description_free (desc);
- }
-
- if (regular_face && !has_bold)
- {
- PangoFontDescription *desc;
- PangoHbFace *face;
-
- desc = pango_font_description_new ();
- pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD);
- face = pango_hb_face_new_variant (regular_face, NULL, TRUE, desc);
- pango_hb_family_add_face (family, face);
- g_object_unref (face);
- pango_font_description_free (desc);
- }
-
- if (regular_face && !has_bold_italic)
- {
- PangoFontDescription *desc;
- PangoHbFace *face;
-
- desc = pango_font_description_new ();
- pango_font_description_set_style (desc, PANGO_STYLE_ITALIC);
- pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD);
- face = pango_hb_face_new_variant (regular_face,
- &(PangoMatrix) { 1, -0.2, 0, 1, 0, 0 },
- TRUE,
- desc);
- pango_hb_family_add_face (family, face);
- g_object_unref (face);
- pango_font_description_free (desc);
- }
- }
-
- pango_trace_mark (before, "populate FcFontMap2", NULL);
+ pango_trace_mark (before, "populate FcHbFontMap", NULL);
}
/* }}} */
@@ -596,7 +508,7 @@ G_DEFINE_TYPE (PangoFcHbFontMap, pango_fc_hb_font_map, PANGO_TYPE_HB_FONT_MAP)
static void
pango_fc_hb_font_map_init (PangoFcHbFontMap *self)
{
- pango_hb_font_map_repopulate (PANGO_HB_FONT_MAP (self));
+ pango_hb_font_map_repopulate (PANGO_HB_FONT_MAP (self), TRUE);
}
static void
@@ -672,7 +584,7 @@ pango_fc_hb_font_map_set_config (PangoFcHbFontMap *self,
if (self->config)
FcConfigReference (self->config);
- pango_hb_font_map_repopulate (PANGO_HB_FONT_MAP (self));
+ pango_hb_font_map_repopulate (PANGO_HB_FONT_MAP (self), TRUE);
}
/* }}} */
diff --git a/tests/testhbfont.c b/tests/testhbfont.c
index 8c956b65..34fba825 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>
#ifdef HAVE_CAIRO_FREETYPE
#include <pango/pango-ot.h>
@@ -222,6 +223,51 @@ test_hbfont_describe (void)
g_free (path);
}
+/* 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);
+ g_object_unref (context);
+ g_object_unref (map);
+}
+
int
main (int argc, char *argv[])
{
@@ -231,6 +277,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/describe", test_hbfont_describe);
+ 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]