summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-11-06 02:09:02 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-11-06 02:09:02 +0000
commit9d389e936707ebcf84fbc64d07b8aa17cdf2ef04 (patch)
treeafa9f0dca7dea5cf7c93ae5c4f40fb25f6692e39
parent0fb9d7159e4b18667c4a2351b9aaa62409b81f95 (diff)
parent30d6756a2984e114952431687fe11f5d9c1659dd (diff)
downloadpango-9d389e936707ebcf84fbc64d07b8aa17cdf2ef04.tar.gz
Merge branch 'small-caps' into 'main'
fc: Implement PANGO_VARIANT_SMALL_CAPS See merge request GNOME/pango!496
-rw-r--r--pango/pangofc-fontmap.c21
-rw-r--r--tests/test-font.c41
2 files changed, 62 insertions, 0 deletions
diff --git a/pango/pangofc-fontmap.c b/pango/pangofc-fontmap.c
index 1d67485a..113142fd 100644
--- a/pango/pangofc-fontmap.c
+++ b/pango/pangofc-fontmap.c
@@ -1854,6 +1854,7 @@ pango_fc_make_pattern (const PangoFontDescription *description,
int slant;
double weight;
PangoGravity gravity;
+ PangoVariant variant;
char **families;
int i;
int width;
@@ -1864,6 +1865,7 @@ pango_fc_make_pattern (const PangoFontDescription *description,
width = pango_fc_convert_width_to_fc (pango_font_description_get_stretch (description));
gravity = pango_font_description_get_gravity (description);
+ variant = pango_font_description_get_variant (description);
/* The reason for passing in FC_SIZE as well as FC_PIXEL_SIZE is
* to work around a bug in libgnomeprint where it doesn't look
@@ -1913,6 +1915,9 @@ pango_fc_make_pattern (const PangoFontDescription *description,
if (prgname)
FcPatternAddString (pattern, PANGO_FC_PRGNAME, (FcChar8*) prgname);
+ if (variant == PANGO_VARIANT_SMALL_CAPS)
+ FcPatternAddString (pattern, PANGO_FC_FONT_FEATURES, (FcChar8*) "smcp=1");
+
return pattern;
}
@@ -2787,6 +2792,22 @@ pango_fc_font_description_from_pattern (FcPattern *pattern, gboolean include_siz
pango_font_description_set_variant (desc, PANGO_VARIANT_NORMAL);
+ for (int i = 0; i < 32; i++)
+ {
+ const char *s;
+
+ if (FcPatternGetString (pattern, PANGO_FC_FONT_FEATURES, i, (FcChar8 **)&s) == FcResultMatch)
+ {
+ if (strcmp (s, "smcp=1") == 0)
+ {
+ pango_font_description_set_variant (desc, PANGO_VARIANT_SMALL_CAPS);
+ break;
+ }
+ }
+ else
+ break;
+ }
+
if (include_size && FcPatternGetDouble (pattern, FC_SIZE, 0, &size) == FcResultMatch)
{
FcMatrix *fc_matrix;
diff --git a/tests/test-font.c b/tests/test-font.c
index c3a1c29f..cd243a95 100644
--- a/tests/test-font.c
+++ b/tests/test-font.c
@@ -279,6 +279,46 @@ test_roundtrip_plain (void)
}
static void
+test_roundtrip_small_caps (void)
+{
+ PangoFontMap *fontmap;
+ PangoContext *context;
+ PangoFontDescription *desc, *desc2;
+ PangoFont *font;
+ hb_feature_t features[32];
+ guint num = 0;
+
+ if (strcmp (G_OBJECT_TYPE_NAME (pango_cairo_font_map_get_default ()), "PangoCairoCoreTextFontMap") == 0)
+ {
+ g_test_skip ("Small Caps support needs to be added to PangoCoreTextFontMap");
+ return;
+ }
+
+ desc = pango_font_description_from_string ("Cantarell Small-Caps 11");
+
+ g_assert_true (pango_font_description_get_variant (desc) == PANGO_VARIANT_SMALL_CAPS);
+
+ fontmap = pango_cairo_font_map_get_default ();
+ context = pango_font_map_create_context (fontmap);
+
+ font = pango_context_load_font (context, desc);
+ desc2 = pango_font_describe (font);
+
+ pango_font_get_features (font, features, G_N_ELEMENTS (features), &num);
+ g_assert_true (num == 1);
+ g_assert_true (features[0].tag == HB_TAG ('s', 'm', 'c', 'p'));
+ g_assert_true (features[0].value == 1);
+ g_assert_true (pango_font_description_get_variant (desc2) == PANGO_VARIANT_SMALL_CAPS);
+
+ g_assert_true (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;
@@ -472,6 +512,7 @@ main (int argc, char *argv[])
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/small-caps", test_roundtrip_small_caps);
g_test_add_func ("/pango/font/roundtrip/emoji", test_roundtrip_emoji);
g_test_add_func ("/pango/font/models", test_font_models);
g_test_add_func ("/pango/font/glyph-extents", test_glyph_extents);