Changeset 178028 in webkit


Ignore:
Timestamp:
Jan 7, 2015 1:51:48 AM (9 years ago)
Author:
Antti Koivisto
Message:

Use HashMap instead of CFDictionary for composite font reference map
https://bugs.webkit.org/show_bug.cgi?id=140150

Reviewed by Geoff Garen.

Use WebKit types. Also use USE(APPKIT) consistently for this feature.

  • platform/graphics/SimpleFontData.cpp:

(WebCore::SimpleFontData::DerivedFontData::~DerivedFontData):

The whole desctructor gets handled implicitly.

  • platform/graphics/SimpleFontData.h:
  • platform/graphics/mac/GlyphPageMac.cpp:

(WebCore::GlyphPage::mayUseMixedFontDataWhenFilling):
(WebCore::GlyphPage::fill):

  • platform/graphics/mac/SimpleFontDataMac.mm:

(WebCore::SimpleFontData::compositeFontReferenceFontData):
(WebCore::SimpleFontData::getCompositeFontReferenceFontData): Deleted.

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r178025 r178028  
     12015-01-06  Antti Koivisto  <antti@apple.com>
     2
     3        Use HashMap instead of CFDictionary for composite font reference map
     4        https://bugs.webkit.org/show_bug.cgi?id=140150
     5
     6        Reviewed by Geoff Garen.
     7
     8        Use WebKit types. Also use USE(APPKIT) consistently for this feature.
     9
     10        * platform/graphics/SimpleFontData.cpp:
     11        (WebCore::SimpleFontData::DerivedFontData::~DerivedFontData):
     12
     13            The whole desctructor gets handled implicitly.
     14
     15        * platform/graphics/SimpleFontData.h:
     16        * platform/graphics/mac/GlyphPageMac.cpp:
     17        (WebCore::GlyphPage::mayUseMixedFontDataWhenFilling):
     18        (WebCore::GlyphPage::fill):
     19        * platform/graphics/mac/SimpleFontDataMac.mm:
     20        (WebCore::SimpleFontData::compositeFontReferenceFontData):
     21        (WebCore::SimpleFontData::getCompositeFontReferenceFontData): Deleted.
     22
    1232015-01-07  Mihnea Ovidenie  <mihnea@adobe.com>
    224
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.cpp

    r177984 r178028  
    389389SimpleFontData::DerivedFontData::~DerivedFontData()
    390390{
    391 #if PLATFORM(COCOA)
    392     if (compositeFontReferences) {
    393         // FIXME: Why don't we use WebKit types here?
    394         CFDictionaryRef dictionary = CFDictionaryRef(compositeFontReferences.get());
    395         CFIndex count = CFDictionaryGetCount(dictionary);
    396         if (count > 0) {
    397             Vector<SimpleFontData*, 2> stash(count);
    398             SimpleFontData** fonts = stash.data();
    399             CFDictionaryGetKeysAndValues(dictionary, 0, (const void **)fonts);
    400             // This deletes the fonts.
    401             while (count-- > 0 && *fonts)
    402                 adoptRef(*fonts++);
    403         }
    404     }
    405 #endif
    406391}
    407392
  • trunk/Source/WebCore/platform/graphics/SimpleFontData.h

    r177979 r178028  
    188188
    189189#if USE(APPKIT)
    190     const SimpleFontData* getCompositeFontReferenceFontData(NSFont *key) const;
     190    const SimpleFontData* compositeFontReferenceFontData(NSFont *key) const;
    191191    NSFont* getNSFont() const { return m_platformData.nsFont(); }
    192192#endif
     
    296296        RefPtr<SimpleFontData> uprightOrientation;
    297297        RefPtr<SimpleFontData> nonSyntheticItalic;
    298 #if PLATFORM(COCOA)
    299         mutable RetainPtr<CFMutableDictionaryRef> compositeFontReferences;
     298#if USE(APPKIT)
     299        HashMap<NSFont*, RefPtr<SimpleFontData>> compositeFontReferences;
    300300#endif
    301301    };
  • trunk/Source/WebCore/platform/graphics/mac/GlyphPageMac.cpp

    r177876 r178028  
    5858bool GlyphPage::mayUseMixedFontDataWhenFilling(const UChar* buffer, unsigned bufferLength, const SimpleFontData* fontData)
    5959{
    60     // FIXME: This could be smarter if the logic currently in GlyphPage::fill() got to make the decision about what kind of GlyphPage to construct.
     60#if USE(APPKIT)
     61    // FIXME: This is only really needed for composite font references.
    6162    return shouldUseCoreText(buffer, bufferLength, fontData);
     63#else
     64    return false;
     65#endif
    6266}
    6367
     
    155159                        }
    156160                    }
    157 #if !PLATFORM(IOS)
     161#if USE(APPKIT)
    158162                } else {
    159                     const SimpleFontData* runSimple = fontData->getCompositeFontReferenceFontData((NSFont *)runFont);
     163                    const SimpleFontData* runSimple = fontData->compositeFontReferenceFontData((NSFont *)runFont);
    160164                    if (runSimple) {
    161165                        for (CFIndex i = 0; i < glyphCount; ++i) {
     
    170174                        }
    171175                    }
    172 #endif // !PLATFORM(IOS)
     176#endif
    173177                }
    174178            }
  • trunk/Source/WebCore/platform/graphics/mac/SimpleFontDataMac.mm

    r177876 r178028  
    8686}
    8787
    88 const SimpleFontData* SimpleFontData::getCompositeFontReferenceFontData(NSFont *key) const
    89 {
    90     if (key && !CFEqual(adoptCF(CTFontCopyPostScriptName(CTFontRef(key))).get(), CFSTR("LastResort"))) {
    91         if (!m_derivedFontData)
    92             m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
    93         if (!m_derivedFontData->compositeFontReferences)
    94             m_derivedFontData->compositeFontReferences = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 1, &kCFTypeDictionaryKeyCallBacks, NULL));
    95         else {
    96             const SimpleFontData* found = static_cast<const SimpleFontData*>(CFDictionaryGetValue(m_derivedFontData->compositeFontReferences.get(), static_cast<const void *>(key)));
    97             if (found)
    98                 return found;
    99         }
    100         if (CFMutableDictionaryRef dictionary = m_derivedFontData->compositeFontReferences.get()) {
    101             bool isUsingPrinterFont = platformData().isPrinterFont();
    102             NSFont *substituteFont = isUsingPrinterFont ? [key printerFont] : [key screenFont];
    103 
    104             CTFontSymbolicTraits traits = CTFontGetSymbolicTraits((CTFontRef)substituteFont);
    105             bool syntheticBold = platformData().syntheticBold() && !(traits & kCTFontBoldTrait);
    106             bool syntheticOblique = platformData().syntheticOblique() && !(traits & kCTFontItalicTrait);
    107 
    108             FontPlatformData substitutePlatform(substituteFont, platformData().size(), isUsingPrinterFont, syntheticBold, syntheticOblique, platformData().orientation(), platformData().widthVariant());
    109             if (RefPtr<SimpleFontData> value = adoptRef(new SimpleFontData(substitutePlatform, isCustomFont()))) {
    110                 SimpleFontData* valuePtr = value.get();
    111                 CFDictionaryAddValue(dictionary, key, value.release().leakRef());
    112                 return valuePtr;
    113             }
    114         }
    115     }
    116     return 0;
     88const SimpleFontData* SimpleFontData::compositeFontReferenceFontData(NSFont *key) const
     89{
     90    if (!key || CFEqual(adoptCF(CTFontCopyPostScriptName(CTFontRef(key))).get(), CFSTR("LastResort")))
     91        return nullptr;
     92
     93    if (!m_derivedFontData)
     94        m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
     95
     96    auto addResult = m_derivedFontData->compositeFontReferences.add(key, nullptr);
     97    if (addResult.isNewEntry) {
     98        bool isUsingPrinterFont = platformData().isPrinterFont();
     99        NSFont *substituteFont = isUsingPrinterFont ? [key printerFont] : [key screenFont];
     100
     101        CTFontSymbolicTraits traits = CTFontGetSymbolicTraits((CTFontRef)substituteFont);
     102        bool syntheticBold = platformData().syntheticBold() && !(traits & kCTFontBoldTrait);
     103        bool syntheticOblique = platformData().syntheticOblique() && !(traits & kCTFontItalicTrait);
     104
     105        FontPlatformData substitutePlatform(substituteFont, platformData().size(), isUsingPrinterFont, syntheticBold, syntheticOblique, platformData().orientation(), platformData().widthVariant());
     106        addResult.iterator->value = SimpleFontData::create(substitutePlatform, isCustomFont());
     107    }
     108    return addResult.iterator->value.get();
    117109}
    118110
Note: See TracChangeset for help on using the changeset viewer.