Title: [91209] trunk/Source/WebCore
Revision
91209
Author
m...@apple.com
Date
2011-07-18 14:10:52 -0700 (Mon, 18 Jul 2011)

Log Message

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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (91208 => 91209)


--- trunk/Source/WebCore/ChangeLog	2011-07-18 21:04:51 UTC (rev 91208)
+++ trunk/Source/WebCore/ChangeLog	2011-07-18 21:10:52 UTC (rev 91209)
@@ -1,3 +1,22 @@
+2011-07-18  Dan Bernstein  <m...@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  <jam...@chromium.org>
 
         Timer scheduling should be based off the monotonic clock

Modified: trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm (91208 => 91209)


--- trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm	2011-07-18 21:04:51 UTC (rev 91208)
+++ trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm	2011-07-18 21:10:52 UTC (rev 91209)
@@ -176,28 +176,46 @@
     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();
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to