Changeset 91209 in webkit


Ignore:
Timestamp:
Jul 18, 2011 2:10:52 PM (13 years ago)
Author:
mitz@apple.com
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.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r91206 r91209  
     12011-07-18  Dan Bernstein  <mitz@apple.com>
     2
     3        Specify a cascade list consisting of the last resort font for Core Text
     4        https://bugs.webkit.org/show_bug.cgi?id=64747
     5
     6        Reviewed by Sam Weinig.
     7
     8        No new tests, because this does not affect behavior.
     9
     10        This prevents Core Text from taking its default, longer fallback list when the primary font does
     11        not include a character. This is OK to do because WebKit never uses the results of Core Text
     12        fallback anyway.
     13
     14        * platform/graphics/cocoa/FontPlatformDataCocoa.mm:
     15        (WebCore::cascadeToLastResortFontDescriptor): Added. Returns a CTFontDescriptor with a cascade
     16        list consisting of the last resort font.
     17        (WebCore::FontPlatformData::ctFont): Changed to include the cascadeToLastResortFontDescriptor
     18        in the returned font.
     19
    1202011-07-18  James Robinson  <jamesr@chromium.org>
    221
  • trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm

    r87524 r91209  
    177177}
    178178
     179static CTFontDescriptorRef cascadeToLastResortFontDescriptor()
     180{
     181    static CTFontDescriptorRef descriptor;
     182    if (descriptor)
     183        return descriptor;
     184
     185    const void* keys[] = { kCTFontCascadeListAttribute };
     186    const void* descriptors[] = { CTFontDescriptorCreateWithNameAndSize(CFSTR("LastResort"), 0) };
     187    const void* values[] = { CFArrayCreate(kCFAllocatorDefault, descriptors, sizeof(descriptors) / sizeof(*descriptors), &kCFTypeArrayCallBacks) };
     188    RetainPtr<CFDictionaryRef> attributes(AdoptCF, CFDictionaryCreate(kCFAllocatorDefault, keys, values, sizeof(keys) / sizeof(*keys), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
     189
     190    descriptor = CTFontDescriptorCreateWithAttributes(attributes.get());
     191
     192    return descriptor;
     193}
     194
    179195CTFontRef FontPlatformData::ctFont() const
    180196{
    181     if (m_widthVariant == RegularWidth) {
    182         if (m_font)
    183             return toCTFontRef(m_font);
    184         if (!m_CTFont)
    185             m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), m_size, 0, 0));
     197    if (m_CTFont)
    186198        return m_CTFont.get();
    187     }
    188    
    189     if (!m_CTFont) {
     199
     200    m_CTFont = toCTFontRef(m_font);
     201    if (m_CTFont)
     202        m_CTFont.adoptCF(CTFontCreateCopyWithAttributes(m_CTFont.get(), m_size, 0, cascadeToLastResortFontDescriptor()));
     203    else
     204        m_CTFont.adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), m_size, 0, cascadeToLastResortFontDescriptor()));
     205
     206    if (m_widthVariant != RegularWidth) {
    190207        int featureTypeValue = kTextSpacingType;
    191208        int featureSelectorValue = mapFontWidthVariantToCTFeatureSelector(m_widthVariant);
    192         RetainPtr<CTFontRef> sourceFont(AdoptCF, CTFontCreateWithGraphicsFont(m_cgFont.get(), m_size, 0, 0));
    193         RetainPtr<CTFontDescriptorRef> sourceDescriptor(AdoptCF, CTFontCopyFontDescriptor(sourceFont.get()));
     209        RetainPtr<CTFontDescriptorRef> sourceDescriptor(AdoptCF, CTFontCopyFontDescriptor(m_CTFont.get()));
    194210        RetainPtr<CFNumberRef> featureType(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &featureTypeValue));
    195211        RetainPtr<CFNumberRef> featureSelector(AdoptCF, CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &featureSelectorValue));
     
    197213        RetainPtr<CTFontRef> newFont(AdoptCF, CTFontCreateWithFontDescriptor(newDescriptor.get(), m_size, 0));
    198214
    199         m_CTFont = newFont.get() ? newFont : sourceFont;
     215        if (newFont)
     216            m_CTFont = newFont;
    200217    }
     218
    201219    return m_CTFont.get();
    202220}
Note: See TracChangeset for help on using the changeset viewer.