summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Rietveld <kris@loopnest.org>2012-06-04 20:58:25 +0200
committerKristian Rietveld <kris@loopnest.org>2012-06-04 21:02:48 +0200
commitdaf81b13784c856cac10ed6d4883bf128aa5cee5 (patch)
tree8f19c3ba5bdae258371733d3a8ff858fc46312d6
parentf5135453d26e68f9f2fbe8f0ddb01e437df41384 (diff)
downloadpango-daf81b13784c856cac10ed6d4883bf128aa5cee5.tar.gz
coretext: implement detection of fonts supporting small caps
-rw-r--r--pango/pangocoretext-fontmap.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/pango/pangocoretext-fontmap.c b/pango/pangocoretext-fontmap.c
index 026782ac..a856593e 100644
--- a/pango/pangocoretext-fontmap.c
+++ b/pango/pangocoretext-fontmap.c
@@ -323,6 +323,51 @@ ct_font_descriptor_get_weight (CTFontDescriptorRef desc)
return weight;
}
+static gboolean
+ct_font_descriptor_is_small_caps (CTFontDescriptorRef desc)
+{
+ CFIndex i, count;
+ CFArrayRef array;
+ CFStringRef str;
+ gboolean retval = FALSE;
+
+ /* See http://stackoverflow.com/a/4811371 for why this works and an
+ * explanation of the magic number "3" used below.
+ */
+ array = CTFontDescriptorCopyAttribute (desc, kCTFontFeaturesAttribute);
+ if (!array)
+ return FALSE;
+
+ str = CFStringCreateWithCString (NULL, "CTFeatureTypeIdentifier",
+ kCFStringEncodingASCII);
+
+ count = CFArrayGetCount (array);
+ for (i = 0; i < count; i++)
+ {
+ CFDictionaryRef dict = CFArrayGetValueAtIndex (array, i);
+ CFNumberRef num;
+
+ num = (CFNumberRef)CFDictionaryGetValue (dict, str);
+ if (num)
+ {
+ int value = 0;
+
+ if (CFNumberGetValue (num, kCFNumberSInt32Type, &value) &&
+ value == 3)
+ {
+ /* This font supports small caps. */
+ retval = TRUE;
+ break;
+ }
+ }
+ }
+
+ CFRelease (str);
+ CFRelease (array);
+
+ return retval;
+}
+
static inline gboolean
pango_core_text_style_name_is_oblique (const char *style_name)
{
@@ -366,12 +411,9 @@ _pango_core_text_font_description_from_ct_font_descriptor (CTFontDescriptorRef d
else
pango_font_description_set_style (font_desc, PANGO_STYLE_NORMAL);
- /* FIXME: How can this be figured using CoreText? */
-#if 0
- if (font_traits & NSSmallCapsFontMask)
+ if (ct_font_descriptor_is_small_caps (desc))
pango_font_description_set_variant (font_desc, PANGO_VARIANT_SMALL_CAPS);
else
-#endif
pango_font_description_set_variant (font_desc, PANGO_VARIANT_NORMAL);
g_free (style_name);