From 4f13d4f4b5bc15d84b55464c69d2b62b4d749a65 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 30 Aug 2021 16:28:43 -0400 Subject: coretext: Set size on font descriptions Set a size on the font description returned by pango_font_describe(). Otherwise, scaling it doesn't work. Fixes: #610 --- pango/pangocoretext-fontmap.c | 7 +++++++ pango/pangocoretext.c | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pango/pangocoretext-fontmap.c b/pango/pangocoretext-fontmap.c index 0980303b..3d8544c6 100644 --- a/pango/pangocoretext-fontmap.c +++ b/pango/pangocoretext-fontmap.c @@ -407,6 +407,8 @@ _pango_core_text_font_description_from_ct_font_descriptor (CTFontDescriptorRef d char *family_name; char *style_name; PangoFontDescription *font_desc; + CFNumberRef cf_number; + CGFloat pointsize; font_desc = pango_font_description_new (); @@ -419,6 +421,11 @@ _pango_core_text_font_description_from_ct_font_descriptor (CTFontDescriptorRef d pango_font_description_set_family (font_desc, family_name); g_free (family_name); + /* Size (if we have one) */ + cf_number = CTFontDescriptorCopyAttribute (desc, kCTFontSizeAttribute); + if (cf_number != NULL && CFNumberGetValue (cf_number, kCFNumberCGFloatType, &pointsize)) + pango_font_description_set_size (font_desc, (pointsize / (96./72.)) * 1024); + /* Weight */ pango_font_description_set_weight (font_desc, ct_font_descriptor_get_weight (desc)); diff --git a/pango/pangocoretext.c b/pango/pangocoretext.c index ccb3f674..25358cac 100644 --- a/pango/pangocoretext.c +++ b/pango/pangocoretext.c @@ -64,10 +64,13 @@ pango_core_text_font_describe (PangoFont *font) PangoCoreTextFont *ctfont = (PangoCoreTextFont *)font; PangoCoreTextFontPrivate *priv = ctfont->priv; CTFontDescriptorRef ctfontdesc; + PangoFontDescription *desc; - ctfontdesc = pango_core_text_font_key_get_ctfontdescriptor (priv->key); + ctfontdesc = CTFontCopyFontDescriptor (priv->font_ref); + desc = _pango_core_text_font_description_from_ct_font_descriptor (ctfontdesc); + CFRelease (ctfontdesc); - return _pango_core_text_font_description_from_ct_font_descriptor (ctfontdesc); + return desc; } static PangoCoverage * -- cgit v1.2.1 From 01b028153ecd8e8398d578765de20421f8a0801a Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 30 Aug 2021 17:05:44 -0400 Subject: tests: Test font roundtrips on MacOs We were skipping the test that would have found the brokenness in the previous fix. Lets see if we can get the test working on MacOs. --- tests/test-font.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/test-font.c b/tests/test-font.c index 1d3290c7..c3a1c29f 100644 --- a/tests/test-font.c +++ b/tests/test-font.c @@ -258,20 +258,19 @@ test_roundtrip_plain (void) PangoFont *font; #ifdef HAVE_CARBON - /* We probably don't have the right fonts */ - g_test_skip ("Skipping font-dependent tests on OS X"); - return; + desc = pango_font_description_from_string ("Helvetica 11"); +#else + desc = pango_font_description_from_string ("Cantarell 11"); #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)); + g_assert_true (pango_font_description_equal (desc2, desc)); pango_font_description_free (desc2); g_object_unref (font); @@ -287,12 +286,6 @@ test_roundtrip_emoji (void) 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); @@ -308,7 +301,7 @@ test_roundtrip_emoji (void) */ 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)); + g_assert_true (pango_font_description_equal (desc2, desc)); pango_font_description_free (desc2); g_object_unref (font); -- cgit v1.2.1