Changeset 53039 in webkit


Ignore:
Timestamp:
Jan 9, 2010, 10:45:06 AM (15 years ago)
Author:
mitz@apple.com
Message:

<rdar://problem/7525778> Font fallback kills SVG kerning
https://bugs.webkit.org/show_bug.cgi?id=33400

Reviewed by Nikolas Zimmermann.

WebCore:

Test: platform/mac/fast/text/sticky-typesetting-features.html

Cache font attributes separately for different typesetting features.

  • platform/graphics/SimpleFontData.h: Replaced single-element caches

with maps.

  • platform/graphics/mac/ComplexTextControllerATSUI.cpp:

(WebCore::disableLigatures): Added an ATSUStyle parameter.
(WebCore::initializeATSUStyle): Look up the ATSUStyle in the map and
initialize if necessary. Return the ATSUStyle.
(WebCore::ComplexTextController::collectComplexTextRunsForCharactersATSUI):
Use the ATSUStyle returned from initializeATSUStyle().

  • platform/graphics/mac/SimpleFontDataMac.mm:

(WebCore::SimpleFontData::platformInit):
(WebCore::SimpleFontData::platformDestroy): Destroy the ATSUStyles in the
map.
(WebCore::SimpleFontData::getCFStringAttributes): Look up the attributes
dictionary in the map and initialize if necessary.

LayoutTests:

  • platform/mac/fast/text/sticky-typesetting-features-expected.checksum: Added.
  • platform/mac/fast/text/sticky-typesetting-features-expected.png: Added.
  • platform/mac/fast/text/sticky-typesetting-features-expected.txt: Added.
  • platform/mac/fast/text/sticky-typesetting-features.html: Added.
Location:
trunk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r53035 r53039  
     12010-01-09  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        <rdar://problem/7525778> Font fallback kills SVG kerning
     6        https://bugs.webkit.org/show_bug.cgi?id=33400
     7
     8        * platform/mac/fast/text/sticky-typesetting-features-expected.checksum: Added.
     9        * platform/mac/fast/text/sticky-typesetting-features-expected.png: Added.
     10        * platform/mac/fast/text/sticky-typesetting-features-expected.txt: Added.
     11        * platform/mac/fast/text/sticky-typesetting-features.html: Added.
     12
    1132010-01-08  Simon Fraser  <simon.fraser@apple.com>
    214
  • trunk/WebCore/ChangeLog

    r53038 r53039  
     12010-01-09  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Nikolas Zimmermann.
     4
     5        <rdar://problem/7525778> Font fallback kills SVG kerning
     6        https://bugs.webkit.org/show_bug.cgi?id=33400
     7
     8        Test: platform/mac/fast/text/sticky-typesetting-features.html
     9
     10        Cache font attributes separately for different typesetting features.
     11
     12        * platform/graphics/SimpleFontData.h: Replaced single-element caches
     13        with maps.
     14        * platform/graphics/mac/ComplexTextControllerATSUI.cpp:
     15        (WebCore::disableLigatures): Added an ATSUStyle parameter.
     16        (WebCore::initializeATSUStyle): Look up the ATSUStyle in the map and
     17        initialize if necessary. Return the ATSUStyle.
     18        (WebCore::ComplexTextController::collectComplexTextRunsForCharactersATSUI):
     19        Use the ATSUStyle returned from initializeATSUStyle().
     20        * platform/graphics/mac/SimpleFontDataMac.mm:
     21        (WebCore::SimpleFontData::platformInit):
     22        (WebCore::SimpleFontData::platformDestroy): Destroy the ATSUStyles in the
     23        map.
     24        (WebCore::SimpleFontData::getCFStringAttributes): Look up the attributes
     25        dictionary in the map and initialize if necessary.
     26
    1272010-01-08  Adam Barth  <abarth@webkit.org>
    228
  • trunk/WebCore/platform/graphics/SimpleFontData.h

    r53036 r53039  
    212212#if USE(ATSUI)
    213213public:
    214     mutable ATSUStyle m_ATSUStyle;
    215     mutable bool m_ATSUStyleInitialized;
     214    mutable HashMap<unsigned, ATSUStyle> m_ATSUStyleMap;
    216215    mutable bool m_ATSUMirrors;
    217216    mutable bool m_checkedShapesArabic;
     
    223222#if USE(CORE_TEXT)
    224223    mutable RetainPtr<CTFontRef> m_CTFont;
    225     mutable RetainPtr<CFDictionaryRef> m_CFStringAttributes;
     224    mutable HashMap<unsigned, RetainPtr<CFDictionaryRef> > m_CFStringAttributes;
    226225#endif
    227226
  • trunk/WebCore/platform/graphics/mac/ComplexTextControllerATSUI.cpp

    r52931 r53039  
    258258}
    259259
    260 static void disableLigatures(const SimpleFontData* fontData, TypesettingFeatures typesettingFeatures)
     260static void disableLigatures(const SimpleFontData* fontData, ATSUStyle atsuStyle, TypesettingFeatures typesettingFeatures)
    261261{
    262262    // Don't be too aggressive: if the font doesn't contain 'a', then assume that any ligatures it contains are
     
    268268    ATSUFontFeatureType featureTypes[] = { kLigaturesType };
    269269    ATSUFontFeatureSelector featureSelectors[] = { kCommonLigaturesOffSelector };
    270     OSStatus status = ATSUSetFontFeatures(fontData->m_ATSUStyle, 1, featureTypes, featureSelectors);
     270    OSStatus status = ATSUSetFontFeatures(atsuStyle, 1, featureTypes, featureSelectors);
    271271    if (status != noErr)
    272272        LOG_ERROR("ATSUSetFontFeatures failed (%d) -- ligatures remain enabled", static_cast<int>(status));
    273273}
    274274
    275 static void initializeATSUStyle(const SimpleFontData* fontData, TypesettingFeatures typesettingFeatures)
    276 {
    277     if (fontData->m_ATSUStyleInitialized)
    278         return;
     275static ATSUStyle initializeATSUStyle(const SimpleFontData* fontData, TypesettingFeatures typesettingFeatures)
     276{
     277    unsigned key = typesettingFeatures + 1;
     278    pair<HashMap<unsigned, ATSUStyle>::iterator, bool> addResult = fontData->m_ATSUStyleMap.add(key, 0);
     279    ATSUStyle& atsuStyle = addResult.first->second;
     280    if (!addResult.second)
     281        return atsuStyle;
    279282
    280283    ATSUFontID fontID = fontData->platformData().m_atsuFontID;
    281284    if (!fontID) {
    282285        LOG_ERROR("unable to get ATSUFontID for %p", fontData->platformData().font());
    283         return;
    284     }
    285 
    286     OSStatus status = ATSUCreateStyle(&fontData->m_ATSUStyle);
     286        fontData->m_ATSUStyleMap.remove(addResult.first);
     287        return 0;
     288    }
     289
     290    OSStatus status = ATSUCreateStyle(&atsuStyle);
    287291    if (status != noErr)
    288292        LOG_ERROR("ATSUCreateStyle failed (%d)", static_cast<int>(status));
     
    297301
    298302    bool allowKerning = typesettingFeatures & Kerning;
    299     status = ATSUSetAttributes(fontData->m_ATSUStyle, allowKerning ? 3 : 4, styleTags, styleSizes, styleValues);
     303    status = ATSUSetAttributes(atsuStyle, allowKerning ? 3 : 4, styleTags, styleSizes, styleValues);
    300304    if (status != noErr)
    301305        LOG_ERROR("ATSUSetAttributes failed (%d)", static_cast<int>(status));
     
    303307    fontData->m_ATSUMirrors = fontHasMirroringInfo(fontID);
    304308
    305     disableLigatures(fontData, typesettingFeatures);
    306 
    307     fontData->m_ATSUStyleInitialized = true;
     309    disableLigatures(fontData, atsuStyle, typesettingFeatures);
     310    return atsuStyle;
    308311}
    309312
     
    319322        m_fallbackFonts->add(fontData);
    320323
    321     initializeATSUStyle(fontData, m_font.typesettingFeatures());
     324    ATSUStyle atsuStyle = initializeATSUStyle(fontData, m_font.typesettingFeatures());
    322325
    323326    OSStatus status;
     
    325328    UniCharCount runLength = length;
    326329
    327     status = ATSUCreateTextLayoutWithTextPtr(cp, 0, length, length, 1, &runLength, &fontData->m_ATSUStyle, &atsuTextLayout);
     330    status = ATSUCreateTextLayoutWithTextPtr(cp, 0, length, length, 1, &runLength, &atsuStyle, &atsuTextLayout);
    328331    if (status != noErr) {
    329332        LOG_ERROR("ATSUCreateTextLayoutWithTextPtr failed with error %d", static_cast<int>(status));
  • trunk/WebCore/platform/graphics/mac/SimpleFontDataMac.mm

    r52931 r53039  
    149149#endif
    150150#if USE(ATSUI)
    151     m_ATSUStyleInitialized = false;
    152151    m_ATSUMirrors = false;
    153152    m_checkedShapesArabic = false;
     
    318317#endif
    319318#if USE(ATSUI)
    320     if (m_ATSUStyleInitialized)
    321         ATSUDisposeStyle(m_ATSUStyle);
     319    HashMap<unsigned, ATSUStyle>::iterator end = m_ATSUStyleMap.end();
     320    for (HashMap<unsigned, ATSUStyle>::iterator it = m_ATSUStyleMap.begin(); it != end; ++it)
     321        ATSUDisposeStyle(it->second);
    322322#endif
    323323}
     
    447447CFDictionaryRef SimpleFontData::getCFStringAttributes(TypesettingFeatures typesettingFeatures) const
    448448{
    449     if (m_CFStringAttributes)
    450         return m_CFStringAttributes.get();
     449    unsigned key = typesettingFeatures + 1;
     450    pair<HashMap<unsigned, RetainPtr<CFDictionaryRef> >::iterator, bool> addResult = m_CFStringAttributes.add(key, RetainPtr<CFDictionaryRef>());
     451    RetainPtr<CFDictionaryRef>& attributesDictionary = addResult.first->second;
     452    if (!addResult.second)
     453        return attributesDictionary.get();
    451454
    452455    bool allowLigatures = platformData().allowsLigatures() || (typesettingFeatures & Ligatures);
     
    464467        const void* valuesWithKerningDisabled[] = { getCTFont(), kerningAdjustment, allowLigatures
    465468            ? ligaturesAllowed : ligaturesNotAllowed };
    466         m_CFStringAttributes.adoptCF(CFDictionaryCreate(NULL, keysWithKerningDisabled, valuesWithKerningDisabled,
     469        attributesDictionary.adoptCF(CFDictionaryCreate(NULL, keysWithKerningDisabled, valuesWithKerningDisabled,
    467470            sizeof(keysWithKerningDisabled) / sizeof(*keysWithKerningDisabled),
    468471            &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
     
    471474        static const void* keysWithKerningEnabled[] = { kCTFontAttributeName, kCTLigatureAttributeName };
    472475        const void* valuesWithKerningEnabled[] = { getCTFont(), allowLigatures ? ligaturesAllowed : ligaturesNotAllowed };
    473         m_CFStringAttributes.adoptCF(CFDictionaryCreate(NULL, keysWithKerningEnabled, valuesWithKerningEnabled,
     476        attributesDictionary.adoptCF(CFDictionaryCreate(NULL, keysWithKerningEnabled, valuesWithKerningEnabled,
    474477            sizeof(keysWithKerningEnabled) / sizeof(*keysWithKerningEnabled),
    475478            &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
    476479    }
    477480
    478     return m_CFStringAttributes.get();
     481    return attributesDictionary.get();
    479482}
    480483
Note: See TracChangeset for help on using the changeset viewer.