| 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 13 matching lines...) Expand all Loading... |
| 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 #include "config.h" | 30 #include "config.h" |
| 31 #include "core/platform/graphics/FontCache.h" | 31 #include "core/platform/graphics/FontCache.h" |
| 32 | 32 |
| 33 #include "FontFamilyNames.h" | 33 #include "FontFamilyNames.h" |
| 34 |
| 34 #include "RuntimeEnabledFeatures.h" | 35 #include "RuntimeEnabledFeatures.h" |
| 36 #include "core/platform/graphics/AlternateFontFamily.h" |
| 35 #include "core/platform/graphics/Font.h" | 37 #include "core/platform/graphics/Font.h" |
| 36 #include "core/platform/graphics/FontCacheKey.h" | 38 #include "core/platform/graphics/FontCacheKey.h" |
| 37 #include "core/platform/graphics/FontDescription.h" | 39 #include "core/platform/graphics/FontDescription.h" |
| 38 #include "core/platform/graphics/FontFallbackList.h" | 40 #include "core/platform/graphics/FontFallbackList.h" |
| 39 #include "core/platform/graphics/FontPlatformData.h" | 41 #include "core/platform/graphics/FontPlatformData.h" |
| 40 #include "core/platform/graphics/FontSelector.h" | 42 #include "core/platform/graphics/FontSelector.h" |
| 41 #include "core/platform/graphics/FontSmoothingMode.h" | 43 #include "core/platform/graphics/FontSmoothingMode.h" |
| 42 #include "core/platform/graphics/TextRenderingMode.h" | 44 #include "core/platform/graphics/TextRenderingMode.h" |
| 43 #include "core/platform/graphics/opentype/OpenTypeVerticalData.h" | 45 #include "core/platform/graphics/opentype/OpenTypeVerticalData.h" |
| 44 #include "wtf/HashMap.h" | 46 #include "wtf/HashMap.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 61 FontCache::FontCache() | 63 FontCache::FontCache() |
| 62 : m_purgePreventCount(0) | 64 : m_purgePreventCount(0) |
| 63 { | 65 { |
| 64 } | 66 } |
| 65 #endif // !OS(WIN) || ENABLE(GDI_FONTS_ON_WINDOWS) | 67 #endif // !OS(WIN) || ENABLE(GDI_FONTS_ON_WINDOWS) |
| 66 | 68 |
| 67 typedef HashMap<FontCacheKey, OwnPtr<FontPlatformData>, FontCacheKeyHash, FontCa
cheKeyTraits> FontPlatformDataCache; | 69 typedef HashMap<FontCacheKey, OwnPtr<FontPlatformData>, FontCacheKeyHash, FontCa
cheKeyTraits> FontPlatformDataCache; |
| 68 | 70 |
| 69 static FontPlatformDataCache* gFontPlatformDataCache = 0; | 71 static FontPlatformDataCache* gFontPlatformDataCache = 0; |
| 70 | 72 |
| 71 // We currently do not support bitmap fonts on windows (with GDI_FONTS_ON_WINDOW
S enabled). | |
| 72 // Instead of trying to construct a bitmap font and then going down the fallback
path map | |
| 73 // certain common bitmap fonts to their truetype equivalent up front. This also
allows the | |
| 74 // GDI_FONTS_ON_WINDOWS disabled code path to match our current behavior. | |
| 75 static const AtomicString& alternateFamilyNameAvoidingBitmapFonts(const AtomicSt
ring& familyName) | |
| 76 { | |
| 77 #if OS(WIN) | |
| 78 // On Windows, 'Courier New' (truetype font) is always present and | |
| 79 // 'Courier' is a bitmap font. On Mac on the other hand 'Courier' is | |
| 80 // a truetype font. Thus pages asking for Courier are better of | |
| 81 // using 'Courier New' on windows. | |
| 82 DEFINE_STATIC_LOCAL(AtomicString, courier, ("Courier", AtomicString::Constru
ctFromLiteral)); | |
| 83 DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New", AtomicString::
ConstructFromLiteral)); | |
| 84 if (equalIgnoringCase(familyName, courier)) | |
| 85 return courierNew; | |
| 86 | |
| 87 // Alias 'MS Sans Serif' (bitmap font) -> 'Microsoft Sans Serif' | |
| 88 // (truetype font). | |
| 89 DEFINE_STATIC_LOCAL(AtomicString, msSans, ("MS Sans Serif", AtomicString::Co
nstructFromLiteral)); | |
| 90 DEFINE_STATIC_LOCAL(AtomicString, microsoftSans, ("Microsoft Sans Serif", At
omicString::ConstructFromLiteral)); | |
| 91 if (equalIgnoringCase(familyName, msSans)) | |
| 92 return microsoftSans; | |
| 93 | |
| 94 // Alias 'MS Serif' (bitmap) -> 'Times New Roman' (truetype font). | |
| 95 // There's no 'Microsoft Sans Serif-equivalent' for Serif. | |
| 96 DEFINE_STATIC_LOCAL(AtomicString, msSerif, ("MS Serif", AtomicString::Constr
uctFromLiteral)); | |
| 97 DEFINE_STATIC_LOCAL(AtomicString, timesNewRoman, ("Times New Roman", AtomicS
tring::ConstructFromLiteral)); | |
| 98 if (equalIgnoringCase(familyName, msSerif)) | |
| 99 return timesNewRoman; | |
| 100 #endif | |
| 101 | |
| 102 return emptyAtom; | |
| 103 } | |
| 104 | |
| 105 static const AtomicString& alternateFamilyName(const AtomicString& familyName) | |
| 106 { | |
| 107 // Alias Courier <-> Courier New | |
| 108 DEFINE_STATIC_LOCAL(AtomicString, courier, ("Courier", AtomicString::Constru
ctFromLiteral)); | |
| 109 DEFINE_STATIC_LOCAL(AtomicString, courierNew, ("Courier New", AtomicString::
ConstructFromLiteral)); | |
| 110 if (equalIgnoringCase(familyName, courier)) | |
| 111 return courierNew; | |
| 112 #if !OS(WIN) | |
| 113 // On Windows, Courier New (truetype font) is always present and | |
| 114 // Courier is a bitmap font. So, we don't want to map Courier New to | |
| 115 // Courier. | |
| 116 if (equalIgnoringCase(familyName, courierNew)) | |
| 117 return courier; | |
| 118 #endif | |
| 119 | |
| 120 // Alias Times and Times New Roman. | |
| 121 DEFINE_STATIC_LOCAL(AtomicString, times, ("Times", AtomicString::ConstructFr
omLiteral)); | |
| 122 DEFINE_STATIC_LOCAL(AtomicString, timesNewRoman, ("Times New Roman", AtomicS
tring::ConstructFromLiteral)); | |
| 123 if (equalIgnoringCase(familyName, times)) | |
| 124 return timesNewRoman; | |
| 125 if (equalIgnoringCase(familyName, timesNewRoman)) | |
| 126 return times; | |
| 127 | |
| 128 // Alias Arial and Helvetica | |
| 129 DEFINE_STATIC_LOCAL(AtomicString, arial, ("Arial", AtomicString::ConstructFr
omLiteral)); | |
| 130 DEFINE_STATIC_LOCAL(AtomicString, helvetica, ("Helvetica", AtomicString::Con
structFromLiteral)); | |
| 131 if (equalIgnoringCase(familyName, arial)) | |
| 132 return helvetica; | |
| 133 if (equalIgnoringCase(familyName, helvetica)) | |
| 134 return arial; | |
| 135 | |
| 136 return emptyAtom; | |
| 137 } | |
| 138 | |
| 139 FontPlatformData* FontCache::getFontResourcePlatformData(const FontDescription&
fontDescription, | 73 FontPlatformData* FontCache::getFontResourcePlatformData(const FontDescription&
fontDescription, |
| 140 const AtomicString& passedFamilyName, bool checkingAlternateName) | 74 const AtomicString& passedFamilyName, bool checkingAlternateName) |
| 141 { | 75 { |
| 142 #if OS(WIN) && ENABLE(OPENTYPE_VERTICAL) | 76 #if OS(WIN) && ENABLE(OPENTYPE_VERTICAL) |
| 143 // Leading "@" in the font name enables Windows vertical flow flag for the f
ont. | 77 // Leading "@" in the font name enables Windows vertical flow flag for the f
ont. |
| 144 // Because we do vertical flow by ourselves, we don't want to use the Window
s feature. | 78 // Because we do vertical flow by ourselves, we don't want to use the Window
s feature. |
| 145 // IE disregards "@" regardless of the orientatoin, so we follow the behavio
r. | 79 // IE disregards "@" regardless of the orientatoin, so we follow the behavio
r. |
| 146 const AtomicString& familyName = (passedFamilyName.isEmpty() || passedFamily
Name[0] != '@') ? | 80 const AtomicString& familyName = (passedFamilyName.isEmpty() || passedFamily
Name[0] != '@') ? |
| 147 passedFamilyName : AtomicString(passedFamilyName.impl()->substring(1)); | 81 passedFamilyName : AtomicString(passedFamilyName.impl()->substring(1)); |
| 148 #else | 82 #else |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 for (HashSet<FontSelector*>::iterator it = gClients->begin(); it != end; ++i
t) | 452 for (HashSet<FontSelector*>::iterator it = gClients->begin(); it != end; ++i
t) |
| 519 clients.append(*it); | 453 clients.append(*it); |
| 520 | 454 |
| 521 ASSERT(numClients == clients.size()); | 455 ASSERT(numClients == clients.size()); |
| 522 for (size_t i = 0; i < numClients; ++i) | 456 for (size_t i = 0; i < numClients; ++i) |
| 523 clients[i]->fontCacheInvalidated(); | 457 clients[i]->fontCacheInvalidated(); |
| 524 | 458 |
| 525 purgeInactiveFontData(); | 459 purgeInactiveFontData(); |
| 526 } | 460 } |
| 527 | 461 |
| 528 const FontPlatformData* FontCache::getFallbackFontData(const FontDescription& de
scription) | |
| 529 { | |
| 530 DEFINE_STATIC_LOCAL(const AtomicString, sansStr, ("Sans", AtomicString::Cons
tructFromLiteral)); | |
| 531 DEFINE_STATIC_LOCAL(const AtomicString, serifStr, ("Serif", AtomicString::Co
nstructFromLiteral)); | |
| 532 DEFINE_STATIC_LOCAL(const AtomicString, monospaceStr, ("Monospace", AtomicSt
ring::ConstructFromLiteral)); | |
| 533 | |
| 534 FontPlatformData* fontPlatformData = 0; | |
| 535 switch (description.genericFamily()) { | |
| 536 case FontDescription::SerifFamily: | |
| 537 fontPlatformData = getFontResourcePlatformData(description, serifStr); | |
| 538 break; | |
| 539 case FontDescription::MonospaceFamily: | |
| 540 fontPlatformData = getFontResourcePlatformData(description, monospaceStr
); | |
| 541 break; | |
| 542 case FontDescription::SansSerifFamily: | |
| 543 default: | |
| 544 fontPlatformData = getFontResourcePlatformData(description, sansStr); | |
| 545 break; | |
| 546 } | |
| 547 | |
| 548 return fontPlatformData; | |
| 549 } | |
| 550 | |
| 551 } // namespace WebCore | 462 } // namespace WebCore |
| OLD | NEW |