| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |    2  * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 
|    3  * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> |    3  * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> | 
|    4  * |    4  * | 
|    5  * Redistribution and use in source and binary forms, with or without |    5  * Redistribution and use in source and binary forms, with or without | 
|    6  * modification, are permitted provided that the following conditions |    6  * modification, are permitted provided that the following conditions | 
|    7  * are met: |    7  * are met: | 
|    8  * |    8  * | 
|    9  * 1.  Redistributions of source code must retain the above copyright |    9  * 1.  Redistributions of source code must retain the above copyright | 
|   10  *     notice, this list of conditions and the following disclaimer. |   10  *     notice, this list of conditions and the following disclaimer. | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   70 bool FontCache::s_useSubpixelPositioning = false; |   70 bool FontCache::s_useSubpixelPositioning = false; | 
|   71 #endif // OS(WIN) |   71 #endif // OS(WIN) | 
|   72  |   72  | 
|   73 FontCache* FontCache::fontCache() |   73 FontCache* FontCache::fontCache() | 
|   74 { |   74 { | 
|   75     DEFINE_STATIC_LOCAL(FontCache, globalFontCache, ()); |   75     DEFINE_STATIC_LOCAL(FontCache, globalFontCache, ()); | 
|   76     return &globalFontCache; |   76     return &globalFontCache; | 
|   77 } |   77 } | 
|   78  |   78  | 
|   79 FontPlatformData* FontCache::getFontPlatformData(const FontDescription& fontDesc
     ription, |   79 FontPlatformData* FontCache::getFontPlatformData(const FontDescription& fontDesc
     ription, | 
|   80     const AtomicString& passedFamilyName, bool checkingAlternateName) |   80     const FontFaceCreationParams& creationParams, bool checkingAlternateName) | 
|   81 { |   81 { | 
|   82 #if OS(WIN) && ENABLE(OPENTYPE_VERTICAL) |  | 
|   83     // Leading "@" in the font name enables Windows vertical flow flag for the f
     ont. |  | 
|   84     // Because we do vertical flow by ourselves, we don't want to use the Window
     s feature. |  | 
|   85     // IE disregards "@" regardless of the orientatoin, so we follow the behavio
     r. |  | 
|   86     const AtomicString& familyName = (passedFamilyName.isEmpty() || passedFamily
     Name[0] != '@') ? |  | 
|   87         passedFamilyName : AtomicString(passedFamilyName.impl()->substring(1)); |  | 
|   88 #else |  | 
|   89     const AtomicString& familyName = passedFamilyName; |  | 
|   90 #endif |  | 
|   91  |  | 
|   92     if (!gFontPlatformDataCache) { |   82     if (!gFontPlatformDataCache) { | 
|   93         gFontPlatformDataCache = new FontPlatformDataCache; |   83         gFontPlatformDataCache = new FontPlatformDataCache; | 
|   94         platformInit(); |   84         platformInit(); | 
|   95     } |   85     } | 
|   96  |   86  | 
|   97     FontCacheKey key = fontDescription.cacheKey(familyName); |   87     FontCacheKey key = fontDescription.cacheKey(creationParams); | 
|   98     FontPlatformData* result = 0; |   88     FontPlatformData* result = 0; | 
|   99     bool foundResult; |   89     bool foundResult; | 
|  100     FontPlatformDataCache::iterator it = gFontPlatformDataCache->find(key); |   90     FontPlatformDataCache::iterator it = gFontPlatformDataCache->find(key); | 
|  101     if (it == gFontPlatformDataCache->end()) { |   91     if (it == gFontPlatformDataCache->end()) { | 
|  102         result = createFontPlatformData(fontDescription, familyName, fontDescrip
     tion.effectiveFontSize()); |   92         result = createFontPlatformData(fontDescription, creationParams, fontDes
     cription.effectiveFontSize()); | 
|  103         gFontPlatformDataCache->set(key, adoptPtr(result)); |   93         gFontPlatformDataCache->set(key, adoptPtr(result)); | 
|  104         foundResult = result; |   94         foundResult = result; | 
|  105     } else { |   95     } else { | 
|  106         result = it->value.get(); |   96         result = it->value.get(); | 
|  107         foundResult = true; |   97         foundResult = true; | 
|  108     } |   98     } | 
|  109  |   99  | 
|  110     if (!foundResult && !checkingAlternateName) { |  100     if (!foundResult && !checkingAlternateName && creationParams.creationType() 
     == CreateFontByFamily) { | 
|  111         // We were unable to find a font. We have a small set of fonts that we a
     lias to other names, |  101         // We were unable to find a font. We have a small set of fonts that we a
     lias to other names, | 
|  112         // e.g., Arial/Helvetica, Courier/Courier New, etc. Try looking up the f
     ont under the aliased name. |  102         // e.g., Arial/Helvetica, Courier/Courier New, etc. Try looking up the f
     ont under the aliased name. | 
|  113         const AtomicString& alternateName = alternateFamilyName(familyName); |  103         const AtomicString& alternateName = alternateFamilyName(creationParams.f
     amily()); | 
|  114         if (!alternateName.isEmpty()) |  104         if (!alternateName.isEmpty()) { | 
|  115             result = getFontPlatformData(fontDescription, alternateName, true); |  105             FontFaceCreationParams createByAlternateFamily(alternateName); | 
 |  106             result = getFontPlatformData(fontDescription, createByAlternateFamil
     y, true); | 
 |  107         } | 
|  116         if (result) |  108         if (result) | 
|  117             gFontPlatformDataCache->set(key, adoptPtr(new FontPlatformData(*resu
     lt))); // Cache the result under the old name. |  109             gFontPlatformDataCache->set(key, adoptPtr(new FontPlatformData(*resu
     lt))); // Cache the result under the old name. | 
|  118     } |  110     } | 
|  119  |  111  | 
|  120     return result; |  112     return result; | 
|  121 } |  113 } | 
|  122  |  114  | 
|  123 #if ENABLE(OPENTYPE_VERTICAL) |  115 #if ENABLE(OPENTYPE_VERTICAL) | 
|  124 typedef HashMap<FontCache::FontFileKey, RefPtr<OpenTypeVerticalData>, WTF::IntHa
     sh<FontCache::FontFileKey>, WTF::UnsignedWithZeroKeyHashTraits<FontCache::FontFi
     leKey> > FontVerticalDataCache; |  116 typedef HashMap<FontCache::FontFileKey, RefPtr<OpenTypeVerticalData>, WTF::IntHa
     sh<FontCache::FontFileKey>, WTF::UnsignedWithZeroKeyHashTraits<FontCache::FontFi
     leKey> > FontVerticalDataCache; | 
|  125  |  117  | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|  141         verticalData.clear(); |  133         verticalData.clear(); | 
|  142     fontVerticalDataCache.set(key, verticalData); |  134     fontVerticalDataCache.set(key, verticalData); | 
|  143     return verticalData; |  135     return verticalData; | 
|  144 } |  136 } | 
|  145 #endif |  137 #endif | 
|  146  |  138  | 
|  147 static FontDataCache* gFontDataCache = 0; |  139 static FontDataCache* gFontDataCache = 0; | 
|  148  |  140  | 
|  149 PassRefPtr<SimpleFontData> FontCache::getFontData(const FontDescription& fontDes
     cription, const AtomicString& family, bool checkingAlternateName, ShouldRetain s
     houldRetain) |  141 PassRefPtr<SimpleFontData> FontCache::getFontData(const FontDescription& fontDes
     cription, const AtomicString& family, bool checkingAlternateName, ShouldRetain s
     houldRetain) | 
|  150 { |  142 { | 
|  151     if (FontPlatformData* platformData = getFontPlatformData(fontDescription, ad
     justFamilyNameToAvoidUnsupportedFonts(family), checkingAlternateName)) |  143     if (FontPlatformData* platformData = getFontPlatformData(fontDescription, Fo
     ntFaceCreationParams(adjustFamilyNameToAvoidUnsupportedFonts(family)), checkingA
     lternateName)) | 
|  152         return fontDataFromFontPlatformData(platformData, shouldRetain); |  144         return fontDataFromFontPlatformData(platformData, shouldRetain); | 
|  153  |  145  | 
|  154     return nullptr; |  146     return nullptr; | 
|  155 } |  147 } | 
|  156  |  148  | 
|  157 PassRefPtr<SimpleFontData> FontCache::fontDataFromFontPlatformData(const FontPla
     tformData* platformData, ShouldRetain shouldRetain) |  149 PassRefPtr<SimpleFontData> FontCache::fontDataFromFontPlatformData(const FontPla
     tformData* platformData, ShouldRetain shouldRetain) | 
|  158 { |  150 { | 
|  159     if (!gFontDataCache) |  151     if (!gFontDataCache) | 
|  160         gFontDataCache = new FontDataCache; |  152         gFontDataCache = new FontDataCache; | 
|  161  |  153  | 
|  162 #if ASSERT_ENABLED |  154 #if ASSERT_ENABLED | 
|  163     if (shouldRetain == DoNotRetain) |  155     if (shouldRetain == DoNotRetain) | 
|  164         ASSERT(m_purgePreventCount); |  156         ASSERT(m_purgePreventCount); | 
|  165 #endif |  157 #endif | 
|  166  |  158  | 
|  167     return gFontDataCache->get(platformData, shouldRetain); |  159     return gFontDataCache->get(platformData, shouldRetain); | 
|  168 } |  160 } | 
|  169  |  161  | 
|  170 bool FontCache::isPlatformFontAvailable(const FontDescription& fontDescription, 
     const AtomicString& family) |  162 bool FontCache::isPlatformFontAvailable(const FontDescription& fontDescription, 
     const AtomicString& family) | 
|  171 { |  163 { | 
|  172     bool checkingAlternateName = true; |  164     bool checkingAlternateName = true; | 
|  173     return getFontPlatformData(fontDescription, adjustFamilyNameToAvoidUnsupport
     edFonts(family), checkingAlternateName); |  165     return getFontPlatformData(fontDescription, FontFaceCreationParams(adjustFam
     ilyNameToAvoidUnsupportedFonts(family)), checkingAlternateName); | 
|  174 } |  166 } | 
|  175  |  167  | 
|  176 SimpleFontData* FontCache::getNonRetainedLastResortFallbackFont(const FontDescri
     ption& fontDescription) |  168 SimpleFontData* FontCache::getNonRetainedLastResortFallbackFont(const FontDescri
     ption& fontDescription) | 
|  177 { |  169 { | 
|  178     return getLastResortFallbackFont(fontDescription, DoNotRetain).leakRef(); |  170     return getLastResortFallbackFont(fontDescription, DoNotRetain).leakRef(); | 
|  179 } |  171 } | 
|  180  |  172  | 
|  181 void FontCache::releaseFontData(const SimpleFontData* fontData) |  173 void FontCache::releaseFontData(const SimpleFontData* fontData) | 
|  182 { |  174 { | 
|  183     ASSERT(gFontDataCache); |  175     ASSERT(gFontDataCache); | 
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  295         clients.append(*it); |  287         clients.append(*it); | 
|  296  |  288  | 
|  297     ASSERT(numClients == clients.size()); |  289     ASSERT(numClients == clients.size()); | 
|  298     for (size_t i = 0; i < numClients; ++i) |  290     for (size_t i = 0; i < numClients; ++i) | 
|  299         clients[i]->fontCacheInvalidated(); |  291         clients[i]->fontCacheInvalidated(); | 
|  300  |  292  | 
|  301     purge(ForcePurge); |  293     purge(ForcePurge); | 
|  302 } |  294 } | 
|  303  |  295  | 
|  304 } // namespace WebCore |  296 } // namespace WebCore | 
| OLD | NEW |