Changeset 54601 in webkit


Ignore:
Timestamp:
Feb 10, 2010 8:28:27 AM (14 years ago)
Author:
jchaffraix@webkit.org
Message:

Bug 23287 - Avoid using FontPlatformData outside the FontCache

Patch by Julien Chaffraix <jchaffraix@pleyo.com> on 2010-02-10
Reviewed by Eric Seidel.

No functional change, only refactored the code using FontPlatformData to use SimpleFontData.

This change leaves the class FontCached as it needs some thoughts and more refactoring.

  • css/CSSFontFaceSource.cpp:

(WebCore::CSSFontFaceSource::getFontData): Call getCachedFontData with the 2 parameters directly.

  • css/CSSFontSelector.cpp:

(WebCore::fontDataForGenericFamily): Ditto.

  • platform/graphics/FontCache.cpp:

(WebCore::FontCache::getCachedFontData): This method is meant to replace getCachedFontPlatformData
that was moved in the private section of the class. It calls getCachedFontPlatformData and cache
the returned FontPlatformData if it is not null.
(WebCore::FontCache::getFontData): Updated to use the new getCachedFontData.

  • platform/graphics/FontCache.h: Updated several methods to return a SimpleFontData in lieu of a

FontPlatformData. Moved some method in the private sections.

  • platform/graphics/chromium/FontCacheChromiumWin.cpp:

(WebCore::FontCache::getSimilarFontPlatformData):
(WebCore::FontCache::getLastResortFallbackFont):

  • platform/graphics/chromium/FontCacheLinux.cpp:

(WebCore::FontCache::getSimilarFontPlatformData):
(WebCore::FontCache::getLastResortFallbackFont):

  • platform/graphics/gtk/FontCacheGtk.cpp:

(WebCore::FontCache::getSimilarFontPlatformData):
(WebCore::FontCache::getLastResortFallbackFont):

  • platform/graphics/haiku/FontCacheHaiku.cpp:

(WebCore::FontCache::getSimilarFontPlatformData):
(WebCore::FontCache::getLastResortFallbackFont):

  • platform/graphics/qt/FontCacheQt.cpp:

(WebCore::FontCache::getLastResortFallbackFont):

  • platform/graphics/win/FontCacheWin.cpp:

(WebCore::FontCache::getSimilarFontPlatformData):
(WebCore::FontCache::getLastResortFallbackFont):

  • platform/graphics/wince/FontCacheWince.cpp:
  • platform/graphics/wx/FontCacheWx.cpp:

(WebCore::FontCache::getSimilarFontPlatformData):
(WebCore::FontCache::getLastResortFallbackFont):
Updated all the previous platform methods to return a SimpleFontData.

  • platform/graphics/mac/FontCacheMac.mm:

(WebCore::FontCache::getSimilarFontPlatformData): Updated to return a SimpleFontData.
(WebCore::FontCache::getLastResortFallbackFont): Ditto. Also refactored the code
and moved a DEFINE_STATIC_LOCAL where it is needed.

Location:
trunk/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r54599 r54601  
     12010-02-10 Julien Chaffraix  <jchaffraix@pleyo.com>
     2
     3        Reviewed by Eric Seidel.
     4
     5        Bug 23287 -  Avoid using FontPlatformData outside the FontCache
     6
     7        No functional change, only refactored the code using FontPlatformData to use SimpleFontData.
     8
     9        This change leaves the class FontCached as it needs some thoughts and more refactoring.
     10
     11        * css/CSSFontFaceSource.cpp:
     12        (WebCore::CSSFontFaceSource::getFontData): Call getCachedFontData with the 2 parameters directly.
     13        * css/CSSFontSelector.cpp:
     14        (WebCore::fontDataForGenericFamily): Ditto.
     15        * platform/graphics/FontCache.cpp:
     16        (WebCore::FontCache::getCachedFontData): This method is meant to replace getCachedFontPlatformData
     17        that was moved in the private section of the class. It calls getCachedFontPlatformData and cache
     18        the returned FontPlatformData if it is not null.
     19        (WebCore::FontCache::getFontData): Updated to use the new getCachedFontData.
     20        * platform/graphics/FontCache.h: Updated several methods to return a SimpleFontData in lieu of a
     21        FontPlatformData. Moved some method in the private sections.
     22
     23        * platform/graphics/chromium/FontCacheChromiumWin.cpp:
     24        (WebCore::FontCache::getSimilarFontPlatformData):
     25        (WebCore::FontCache::getLastResortFallbackFont):
     26        * platform/graphics/chromium/FontCacheLinux.cpp:
     27        (WebCore::FontCache::getSimilarFontPlatformData):
     28        (WebCore::FontCache::getLastResortFallbackFont):
     29        * platform/graphics/gtk/FontCacheGtk.cpp:
     30        (WebCore::FontCache::getSimilarFontPlatformData):
     31        (WebCore::FontCache::getLastResortFallbackFont):
     32        * platform/graphics/haiku/FontCacheHaiku.cpp:
     33        (WebCore::FontCache::getSimilarFontPlatformData):
     34        (WebCore::FontCache::getLastResortFallbackFont):
     35        * platform/graphics/qt/FontCacheQt.cpp:
     36        (WebCore::FontCache::getLastResortFallbackFont):
     37        * platform/graphics/win/FontCacheWin.cpp:
     38        (WebCore::FontCache::getSimilarFontPlatformData):
     39        (WebCore::FontCache::getLastResortFallbackFont):
     40        * platform/graphics/wince/FontCacheWince.cpp:
     41        * platform/graphics/wx/FontCacheWx.cpp:
     42        (WebCore::FontCache::getSimilarFontPlatformData):
     43        (WebCore::FontCache::getLastResortFallbackFont):
     44        Updated all the previous platform methods to return a SimpleFontData.
     45
     46        * platform/graphics/mac/FontCacheMac.mm:
     47        (WebCore::FontCache::getSimilarFontPlatformData): Updated to return a SimpleFontData.
     48        (WebCore::FontCache::getLastResortFallbackFont): Ditto. Also refactored the code
     49        and moved a DEFINE_STATIC_LOCAL where it is needed.
     50
    1512010-02-10  Alexander Pavlov  <apavlov@chromium.org>
    252
  • trunk/WebCore/css/CSSFontFaceSource.cpp

    r39823 r54601  
    108108    if (!m_font) {
    109109#endif
    110         FontPlatformData* data = fontCache()->getCachedFontPlatformData(fontDescription, m_string);
    111         SimpleFontData* fontData = fontCache()->getCachedFontData(data);
     110        SimpleFontData* fontData = fontCache()->getCachedFontData(fontDescription, m_string);
    112111
    113112        // We're local. Just return a SimpleFontData from the normal cache.
     
    180179            m_font->beginLoadIfNeeded(docLoader);
    181180        // FIXME: m_string is a URL so it makes no sense to pass it as a family name.
    182         FontPlatformData* tempData = fontCache()->getCachedFontPlatformData(fontDescription, m_string);
     181        SimpleFontData* tempData = fontCache()->getCachedFontData(fontDescription, m_string);
    183182        if (!tempData)
    184183            tempData = fontCache()->getLastResortFallbackFont(fontDescription);
    185         fontData.set(new SimpleFontData(*tempData, true, true));
     184
     185        fontData.set(new SimpleFontData(tempData->platformData(), true, true));
    186186    }
    187187
  • trunk/WebCore/css/CSSFontSelector.cpp

    r51473 r54601  
    395395
    396396    if (!genericFamily.isEmpty())
    397         return fontCache()->getCachedFontData(fontCache()->getCachedFontPlatformData(fontDescription, genericFamily));
     397        return fontCache()->getCachedFontData(fontDescription, genericFamily);
    398398
    399399    return 0;
  • trunk/WebCore/platform/graphics/FontCache.cpp

    r52791 r54601  
    258258static ListHashSet<const SimpleFontData*>* gInactiveFontData = 0;
    259259
     260SimpleFontData* FontCache::getCachedFontData(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName)
     261{
     262    FontPlatformData* platformData = getCachedFontPlatformData(fontDescription, family, checkingAlternateName);
     263    if (!platformData)
     264        return 0;
     265
     266    return getCachedFontData(platformData);
     267}
     268
    260269SimpleFontData* FontCache::getCachedFontData(const FontPlatformData* platformData)
    261270{
     
    362371const FontData* FontCache::getFontData(const Font& font, int& familyIndex, FontSelector* fontSelector)
    363372{
    364     FontPlatformData* result = 0;
     373    SimpleFontData* result = 0;
    365374
    366375    int startIndex = familyIndex;
     
    377386                    return data;
    378387            }
    379             result = getCachedFontPlatformData(font.fontDescription(), currFamily->family());
     388            result = getCachedFontData(font.fontDescription(), currFamily->family());
    380389        }
    381390        currFamily = currFamily->next();
     
    404413        result = getLastResortFallbackFont(font.fontDescription());
    405414    }
    406 
    407     // Now that we have a result, we need to go from FontPlatformData -> FontData.
    408     return getCachedFontData(result);
     415    return result;
    409416}
    410417
  • trunk/WebCore/platform/graphics/FontCache.h

    r52791 r54601  
    7979    void getTraitsInFamily(const AtomicString&, Vector<unsigned>&);
    8080
    81     FontPlatformData* getCachedFontPlatformData(const FontDescription&, const AtomicString& family, bool checkingAlternateName = false);
    82     SimpleFontData* getCachedFontData(const FontPlatformData*);
    83     FontPlatformData* getLastResortFallbackFont(const FontDescription&);
     81    SimpleFontData* getCachedFontData(const FontDescription& fontDescription, const AtomicString& family, bool checkingAlternateName = false);
     82    SimpleFontData* getLastResortFallbackFont(const FontDescription&);
    8483
    8584    void addClient(FontSelector*);
     
    9796    ~FontCache();
    9897
     98    // FIXME: This method should eventually be removed.
     99    FontPlatformData* getCachedFontPlatformData(const FontDescription&, const AtomicString& family, bool checkingAlternateName = false);
     100
    99101    // These methods are implemented by each platform.
    100     FontPlatformData* getSimilarFontPlatformData(const Font&);
     102    SimpleFontData* getSimilarFontPlatformData(const Font&);
    101103    FontPlatformData* createFontPlatformData(const FontDescription&, const AtomicString& family);
    102104
    103     friend class SimpleFontData;
     105    SimpleFontData* getCachedFontData(const FontPlatformData*);
     106
     107    friend class SimpleFontData; // For getCachedFontData(const FontPlatformData*)
    104108    friend class FontFallbackList;
    105109};
     
    107111// Get the global fontCache.
    108112FontCache* fontCache();
     113
    109114}
    110115
  • trunk/WebCore/platform/graphics/chromium/FontCacheChromiumWin.cpp

    r47506 r54601  
    407407}
    408408
    409 FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font)
     409SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font)
    410410{
    411411    return 0;
    412412}
    413413
    414 FontPlatformData* FontCache::getLastResortFallbackFont(const FontDescription& description)
     414SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& description)
    415415{
    416416    FontDescription::GenericFamilyType generic = description.genericFamily();
     
    429429        fontStr = courierStr;
    430430
    431     return getCachedFontPlatformData(description, fontStr);
     431    return getCachedFontData(description, fontStr);
    432432}
    433433
  • trunk/WebCore/platform/graphics/chromium/FontCacheLinux.cpp

    r45191 r54601  
    6767}
    6868
    69 FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font)
     69SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font)
    7070{
    7171    return 0;
    7272}
    7373
    74 FontPlatformData* FontCache::getLastResortFallbackFont(const FontDescription& description)
     74SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& description)
    7575{
    7676    static const AtomicString sansStr("Sans");
     
    9393
    9494    ASSERT(fontPlatformData);
    95     return fontPlatformData;
     95    return getCachedFontData(fontPlatformData);
    9696}
    9797
  • trunk/WebCore/platform/graphics/gtk/FontCacheGtk.cpp

    r44456 r54601  
    6060}
    6161
    62 FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font)
     62SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font)
    6363{
    6464    return 0;
    6565}
    6666
    67 FontPlatformData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
     67SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
    6868{
    6969    // FIXME: Would be even better to somehow get the user's default font here.
    7070    // For now we'll pick the default that the user would get without changing any prefs.
    7171    static AtomicString timesStr("Times New Roman");
    72     return getCachedFontPlatformData(fontDescription, timesStr);
     72    return getCachedFontData(fontDescription, timesStr);
    7373}
    7474
  • trunk/WebCore/platform/graphics/haiku/FontCacheHaiku.cpp

    r47637 r54601  
    5252}
    5353
    54 FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font)
     54SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font)
    5555{
    5656    notImplemented();
     
    5858}
    5959
    60 FontPlatformData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
     60SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
    6161{
    6262    // FIXME: Would be even better to somehow get the user's default font here.
    6363    // For now we'll pick the default that the user would get without changing any prefs.
    6464    static AtomicString defaultString("DejaVu Serif");
    65     return getCachedFontPlatformData(fontDescription, defaultString);
     65    return getCachedFontData(fontDescription, defaultString);
    6666}
    6767
  • trunk/WebCore/platform/graphics/mac/FontCacheMac.mm

    r44389 r54601  
    147147}
    148148
    149 FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font)
     149SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font)
    150150{
    151151    // Attempt to find an appropriate font using a match based on
    152152    // the presence of keywords in the the requested names.  For example, we'll
    153153    // match any name that contains "Arabic" to Geeza Pro.
    154     FontPlatformData* platformData = 0;
     154    SimpleFontData* simpleFontData = 0;
    155155    const FontFamily* currFamily = &font.fontDescription().family();
    156     while (currFamily && !platformData) {
     156    while (currFamily && !simpleFontData) {
    157157        if (currFamily->family().length()) {
    158158            static String* matchWords[3] = { new String("Arabic"), new String("Pashto"), new String("Urdu") };
    159159            DEFINE_STATIC_LOCAL(AtomicString, geezaStr, ("Geeza Pro"));
    160             for (int j = 0; j < 3 && !platformData; ++j)
     160            for (int j = 0; j < 3 && !simpleFontData; ++j)
    161161                if (currFamily->family().contains(*matchWords[j], false))
    162                     platformData = getCachedFontPlatformData(font.fontDescription(), geezaStr);
     162                    simpleFontData = getCachedFontData(font.fontDescription(), geezaStr);
    163163        }
    164164        currFamily = currFamily->next();
    165165    }
    166166
    167     return platformData;
    168 }
    169 
    170 FontPlatformData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
     167    return simpleFontData;
     168}
     169
     170SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
    171171{
    172172    DEFINE_STATIC_LOCAL(AtomicString, timesStr, ("Times"));
    173     DEFINE_STATIC_LOCAL(AtomicString, lucidaGrandeStr, ("Lucida Grande"));
    174173
    175174    // FIXME: Would be even better to somehow get the user's default font here.  For now we'll pick
    176175    // the default that the user would get without changing any prefs.
    177     FontPlatformData* platformFont = getCachedFontPlatformData(fontDescription, timesStr);
    178     if (!platformFont)
    179         // The Times fallback will almost always work, but in the highly unusual case where
    180         // the user doesn't have it, we fall back on Lucida Grande because that's
    181         // guaranteed to be there, according to Nathan Taylor. This is good enough
    182         // to avoid a crash at least.
    183         platformFont = getCachedFontPlatformData(fontDescription, lucidaGrandeStr);
    184 
    185     return platformFont;
     176    SimpleFontData* simpleFontData = getCachedFontData(fontDescription, timesStr);
     177    if (simpleFontData)
     178        return simpleFontData;
     179
     180    // The Times fallback will almost always work, but in the highly unusual case where
     181    // the user doesn't have it, we fall back on Lucida Grande because that's
     182    // guaranteed to be there, according to Nathan Taylor. This is good enough
     183    // to avoid a crash at least.
     184    DEFINE_STATIC_LOCAL(AtomicString, lucidaGrandeStr, ("Lucida Grande"));
     185    return getCachedFontData(fontDescription, lucidaGrandeStr);
    186186}
    187187
  • trunk/WebCore/platform/graphics/qt/FontCacheQt.cpp

    r52310 r54601  
    5050}
    5151
    52 FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font)
     52SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font)
    5353{
    5454    return 0;
    5555}
    5656
    57 FontPlatformData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
     57SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
    5858{
    5959    const AtomicString fallbackFamily = QFont(fontDescription.family().family()).lastResortFamily();
    60     return new FontPlatformData(fontDescription, fallbackFamily);
     60    return getCachedFontData(new FontPlatformData(fontDescription, fallbackFamily));
    6161}
    6262
  • trunk/WebCore/platform/graphics/win/FontCacheWin.cpp

    r52371 r54601  
    297297}
    298298
    299 FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font)
     299SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font)
    300300{
    301301    return 0;
    302302}
    303303
    304 FontPlatformData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
     304SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
    305305{
    306306    // FIXME: Would be even better to somehow get the user's default font here.  For now we'll pick
     
    317317        defaultGUIFontFamily = String(logFont.lfFaceName, wcsnlen(logFont.lfFaceName, LF_FACESIZE));
    318318    }
    319     return getCachedFontPlatformData(fontDescription, defaultGUIFontFamily);
     319    return getCachedFontData(fontDescription, defaultGUIFontFamily);
    320320}
    321321
  • trunk/WebCore/platform/graphics/wince/FontCacheWince.cpp

    r46196 r54601  
    317317}
    318318
    319 FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font)
     319SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font)
    320320{
    321321    return 0;
    322322}
    323323
    324 FontPlatformData* FontCache::getLastResortFallbackFont(const FontDescription& fontDesc)
     324SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& fontDesc)
    325325{
    326326    // FIXME: Would be even better to somehow get the user's default font here.  For now we'll pick
    327327    // the default that the user would get without changing any prefs.
    328     return getCachedFontPlatformData(fontDesc, FontPlatformData::defaultFontFamily());
     328    return getCachedFontData(fontDesc, FontPlatformData::defaultFontFamily());
    329329}
    330330
  • trunk/WebCore/platform/graphics/wx/FontCacheWx.cpp

    r37118 r54601  
    4747}
    4848
    49 FontPlatformData* FontCache::getSimilarFontPlatformData(const Font& font)
     49SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font)
    5050{
    51     return new FontPlatformData(font.fontDescription(), font.family().family());
     51    return getCachedFontData(font.fontDescription(), font.family().family());
    5252}
    5353
    54 FontPlatformData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
     54SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& fontDescription)
    5555{
    5656    // FIXME: Would be even better to somehow get the user's default font here.  For now we'll pick
    5757    // the default that the user would get without changing any prefs.
    5858    static AtomicString timesStr("systemfont");
    59     return getCachedFontPlatformData(fontDescription, timesStr);
     59    return getCachedFontData(fontDescription, timesStr);
    6060}
    6161
Note: See TracChangeset for help on using the changeset viewer.