Specify a cascade list consisting of the last resort font for Core Text
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Jul 2011 21:10:52 +0000 (21:10 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 18 Jul 2011 21:10:52 +0000 (21:10 +0000)
https://bugs.webkit.org/show_bug.cgi?id=64747

Reviewed by Sam Weinig.

No new tests, because this does not affect behavior.

This prevents Core Text from taking its default, longer fallback list when the primary font does
not include a character. This is OK to do because WebKit never uses the results of Core Text
fallback anyway.

* platform/graphics/cocoa/FontPlatformDataCocoa.mm:
(WebCore::cascadeToLastResortFontDescriptor): Added. Returns a CTFontDescriptor with a cascade
list consisting of the last resort font.
(WebCore::FontPlatformData::ctFont): Changed to include the cascadeToLastResortFontDescriptor
in the returned font.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@91209 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm

index 72130464622a6610a3a51f413e360c0b09c484fe..25af44c9d60320b011b5b77f0da8a6ebcd3bbb1e 100644 (file)
@@ -1,3 +1,22 @@
+2011-07-18  Dan Bernstein  <mitz@apple.com>
+
+        Specify a cascade list consisting of the last resort font for Core Text
+        https://bugs.webkit.org/show_bug.cgi?id=64747
+
+        Reviewed by Sam Weinig.
+
+        No new tests, because this does not affect behavior.
+
+        This prevents Core Text from taking its default, longer fallback list when the primary font does
+        not include a character. This is OK to do because WebKit never uses the results of Core Text
+        fallback anyway.
+
+        * platform/graphics/cocoa/FontPlatformDataCocoa.mm:
+        (WebCore::cascadeToLastResortFontDescriptor): Added. Returns a CTFontDescriptor with a cascade
+        list consisting of the last resort font.
+        (WebCore::FontPlatformData::ctFont): Changed to include the cascadeToLastResortFontDescriptor
+        in the returned font.
+
 2011-07-18  James Robinson  <jamesr@chromium.org>
 
         Timer scheduling should be based off the monotonic clock
index 048ba9c13a1e73fe412b7c5683e289a79042d9c6..aa5be1ad7b8ee7b79b153773916c2f58abe3754e 100644 (file)
@@ -176,28 +176,46 @@ inline int mapFontWidthVariantToCTFeatureSelector(FontWidthVariant variant)
     return TextSpacingProportional;
 }
 
+static CTFontDescriptorRef cascadeToLastResortFontDescriptor()
+{
+    static CTFontDescriptorRef descriptor;
+    if (descriptor)
+        return descriptor;
+
+    const void* keys[] = { kCTFontCascadeListAttribute };
+    const void* descriptors[] = { CTFontDescriptorCreateWithNameAndSize(CFSTR("LastResort"), 0) };
+    const void* values[] = { CFArrayCreate(kCFAllocatorDefault, descriptors, sizeof(descriptors) / sizeof(*descriptors), &kCFTypeArrayCallBacks) };
+    RetainPtr<CFDictionaryRef> attributes(AdoptCF, CFDictionaryCreate(kCFAllocatorDefault, keys, values, sizeof(keys) / sizeof(*keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
+
+    descriptor = CTFontDescriptorCreateWithAttributes(attributes.get());
+
+    return descriptor;
+}
+
 CTFontRef FontPlatformData::ctFont() const
 {
-    if (m_widthVariant == RegularWidth) {
-        if (m_font)
-            return toCTFontRef(m_font);
-        if (!m_CTFont)
-            m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), m_size, 0, 0));
+    if (m_CTFont)
         return m_CTFont.get();
-    }
-    
-    if (!m_CTFont) {
+
+    m_CTFont = toCTFontRef(m_font);
+    if (m_CTFont)
+        m_CTFont.adoptCF(CTFontCreateCopyWithAttributes(m_CTFont.get(), m_size, 0, cascadeToLastResortFontDescriptor()));
+    else
+        m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), m_size, 0, cascadeToLastResortFontDescriptor()));
+
+    if (m_widthVariant != RegularWidth) {
         int featureTypeValue = kTextSpacingType;
         int featureSelectorValue = mapFontWidthVariantToCTFeatureSelector(m_widthVariant);
-        RetainPtr<CTFontRef> sourceFont(AdoptCF, CTFontCreateWithGraphicsFont(m_cgFont.get(), m_size, 0, 0));
-        RetainPtr<CTFontDescriptorRef> sourceDescriptor(AdoptCF, CTFontCopyFontDescriptor(sourceFont.get()));
+        RetainPtr<CTFontDescriptorRef> sourceDescriptor(AdoptCF, CTFontCopyFontDescriptor(m_CTFont.get()));
         RetainPtr<CFNumberRef> featureType(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &featureTypeValue));
         RetainPtr<CFNumberRef> featureSelector(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &featureSelectorValue));
         RetainPtr<CTFontDescriptorRef> newDescriptor(AdoptCF, CTFontDescriptorCreateCopyWithFeature(sourceDescriptor.get(), featureType.get(), featureSelector.get()));
         RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(newDescriptor.get(), m_size, 0));
 
-        m_CTFont = newFont.get() ? newFont : sourceFont;
+        if (newFont)
+            m_CTFont = newFont;
     }
+
     return m_CTFont.get();
 }