summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-01-24 21:55:14 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-01-24 21:55:14 +0000
commit23e033aead84005d5d253de7f5e891b9eef60baa (patch)
treeda11169c87840011970de5e27f3ded4c3a96b3e5
parent7c99441eda0e7a79d90b7a73faf93f1c89532120 (diff)
parent49b1f80a83433e5ddb18bd4e1577171fef8641e5 (diff)
downloadpango-23e033aead84005d5d253de7f5e891b9eef60baa.tar.gz
Merge branch 'fix-font-roundtrip' into 'master'
Fix font roundtrip Closes #530 See merge request GNOME/pango!280
-rw-r--r--pango/pangofc-fontmap.c19
-rw-r--r--tests/meson.build2
-rw-r--r--tests/test-font.c72
3 files changed, 90 insertions, 3 deletions
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 764336ae..fd17309d 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -2519,7 +2519,24 @@ pango_fc_font_description_from_pattern (FcPattern *pattern, gboolean include_siz
pango_font_description_set_variant (desc, PANGO_VARIANT_NORMAL);
if (include_size && FcPatternGetDouble (pattern, FC_SIZE, 0, &size) == FcResultMatch)
- pango_font_description_set_size (desc, size * PANGO_SCALE);
+ {
+ FcMatrix *fc_matrix;
+ double scale_factor = 1;
+
+ if (FcPatternGetMatrix (pattern, FC_MATRIX, 0, &fc_matrix) == FcResultMatch)
+ {
+ PangoMatrix mat = PANGO_MATRIX_INIT;
+
+ mat.xx = fc_matrix->xx;
+ mat.xy = fc_matrix->xy;
+ mat.yx = fc_matrix->yx;
+ mat.yy = fc_matrix->yy;
+
+ scale_factor = pango_matrix_get_font_scale_factor (&mat);
+ }
+
+ pango_font_description_set_size (desc, scale_factor * size * PANGO_SCALE);
+ }
/* gravity is a bit different. we don't want to set it if it was not set on
* the pattern */
diff --git a/tests/meson.build b/tests/meson.build
index ba96ac2c..bdccd55d 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -8,6 +8,8 @@ endif
if host_system == 'windows'
test_cflags += '-DHAVE_WIN32'
+elif host_system == 'darwin'
+ test_cflags += '-DHAVE_CARBON'
endif
test_env = environment()
diff --git a/tests/test-font.c b/tests/test-font.c
index 58a5bf8c..aecf32c8 100644
--- a/tests/test-font.c
+++ b/tests/test-font.c
@@ -243,9 +243,75 @@ test_enumerate (void)
g_object_unref (font);
pango_font_description_free (desc);
g_free (faces);
- g_free (families);
+ g_free (families);
+ g_object_unref (context);
+}
+
+static void
+test_roundtrip_plain (void)
+{
+ PangoFontMap *fontmap;
+ PangoContext *context;
+ PangoFontDescription *desc, *desc2;
+ PangoFont *font;
+
+#ifdef HAVE_CARBON
+ /* We probably don't have the right fonts */
+ g_test_skip ("Skipping font-dependent tests on OS X");
+ return;
+#endif
+
+ fontmap = pango_cairo_font_map_get_default ();
+ context = pango_font_map_create_context (fontmap);
+
+ desc = pango_font_description_from_string ("Cantarell 11");
+
+ font = pango_context_load_font (context, desc);
+ desc2 = pango_font_describe (font);
+
+ g_assert (pango_font_description_equal (desc2, desc));
+
+ pango_font_description_free (desc2);
+ g_object_unref (font);
+ pango_font_description_free (desc);
+ g_object_unref (context);
+}
+
+static void
+test_roundtrip_emoji (void)
+{
+ PangoFontMap *fontmap;
+ PangoContext *context;
+ PangoFontDescription *desc, *desc2;
+ PangoFont *font;
+
+#ifdef HAVE_CARBON
+ /* We probably don't have the right fonts */
+ g_test_skip ("Skipping font-dependent tests on OS X");
+ return;
+#endif
+
+ fontmap = pango_cairo_font_map_get_default ();
+ context = pango_font_map_create_context (fontmap);
+
+ /* This is how pango_itemize creates the emoji font desc */
+ desc = pango_font_description_from_string ("Cantarell 11");
+ pango_font_description_set_family_static (desc, "emoji");
+
+ font = pango_context_load_font (context, desc);
+ desc2 = pango_font_describe (font);
+
+ /* We can't expect the family name to match, since we go in with
+ * a generic family
+ */
+ pango_font_description_unset_fields (desc, PANGO_FONT_MASK_FAMILY);
+ pango_font_description_unset_fields (desc2, PANGO_FONT_MASK_FAMILY);
+ g_assert (pango_font_description_equal (desc2, desc));
+
+ pango_font_description_free (desc2);
+ g_object_unref (font);
+ pango_font_description_free (desc);
g_object_unref (context);
- g_object_unref (fontmap);
}
int
@@ -264,6 +330,8 @@ main (int argc, char *argv[])
g_test_add_func ("/pango/fontdescription/variation", test_variation);
g_test_add_func ("/pango/font/extents", test_extents);
g_test_add_func ("/pango/font/enumerate", test_enumerate);
+ g_test_add_func ("/pango/font/roundtrip/plain", test_roundtrip_plain);
+ g_test_add_func ("/pango/font/roundtrip/emoji", test_roundtrip_emoji);
return g_test_run ();
}