| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. | 2 * Copyright (c) 2006, 2007, 2008, 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "SkFontMgr.h" | 31 #include "SkFontMgr.h" |
| 32 #include "SkStream.h" | 32 #include "SkStream.h" |
| 33 #include "SkTypeface.h" | 33 #include "SkTypeface.h" |
| 34 #include "platform/Language.h" |
| 34 #include "platform/fonts/AlternateFontFamily.h" | 35 #include "platform/fonts/AlternateFontFamily.h" |
| 35 #include "platform/fonts/FontCache.h" | 36 #include "platform/fonts/FontCache.h" |
| 36 #include "platform/fonts/FontDescription.h" | 37 #include "platform/fonts/FontDescription.h" |
| 37 #include "platform/fonts/FontFaceCreationParams.h" | 38 #include "platform/fonts/FontFaceCreationParams.h" |
| 38 #include "platform/fonts/SimpleFontData.h" | 39 #include "platform/fonts/SimpleFontData.h" |
| 39 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 40 #include "public/platform/linux/WebSandboxSupport.h" | 41 #include "public/platform/linux/WebSandboxSupport.h" |
| 41 #include "wtf/Assertions.h" | 42 #include "wtf/Assertions.h" |
| 42 #include "wtf/text/AtomicString.h" | 43 #include "wtf/text/AtomicString.h" |
| 43 #include "wtf/text/CString.h" | 44 #include "wtf/text/CString.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 SkAutoTUnref<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal()); | 81 SkAutoTUnref<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal()); |
| 81 SkFontConfigInterface::FontIdentity fontIdentity; | 82 SkFontConfigInterface::FontIdentity fontIdentity; |
| 82 fontIdentity.fID = fontconfigInterfaceId; | 83 fontIdentity.fID = fontconfigInterfaceId; |
| 83 fontIdentity.fTTCIndex = ttcIndex; | 84 fontIdentity.fTTCIndex = ttcIndex; |
| 84 return adoptRef(fci->createTypeface(fontIdentity)); | 85 return adoptRef(fci->createTypeface(fontIdentity)); |
| 85 } | 86 } |
| 86 #endif | 87 #endif |
| 87 | 88 |
| 88 namespace blink { | 89 namespace blink { |
| 89 | 90 |
| 91 // SkFontMgr requires script-based locale names, like "zh-Hant" and "zh-Hans", |
| 92 // instead of "zh-CN" and "zh-TW". |
| 93 static CString toSkFontMgrLocale(const String& locale) |
| 94 { |
| 95 if (!locale.startsWith("zh", TextCaseInsensitive)) |
| 96 return locale.ascii(); |
| 97 |
| 98 switch (localeToScriptCodeForFontSelection(locale)) { |
| 99 case USCRIPT_SIMPLIFIED_HAN: |
| 100 return "zh-Hans"; |
| 101 case USCRIPT_TRADITIONAL_HAN: |
| 102 return "zh-Hant"; |
| 103 default: |
| 104 return locale.ascii(); |
| 105 } |
| 106 } |
| 107 |
| 108 |
| 109 #if OS(ANDROID) || OS(LINUX) |
| 110 // This function is called on android or when we are emulating android fonts on
linux and the |
| 111 // embedder has overriden the default fontManager with WebFontRendering::setSkia
FontMgr. |
| 112 // static |
| 113 AtomicString FontCache::getFamilyNameForCharacter(SkFontMgr* fm, UChar32 c, cons
t FontDescription& fontDescription) |
| 114 { |
| 115 ASSERT(fm); |
| 116 |
| 117 const char* bcp47Locales[2]; |
| 118 int localeCount = 0; |
| 119 CString defaultLocale = toSkFontMgrLocale(defaultLanguage()); |
| 120 bcp47Locales[localeCount++] = defaultLocale.data(); |
| 121 CString fontLocale; |
| 122 if (!fontDescription.locale().isEmpty()) { |
| 123 fontLocale = toSkFontMgrLocale(fontDescription.locale()); |
| 124 bcp47Locales[localeCount++] = fontLocale.data(); |
| 125 } |
| 126 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyleCharacter(0, SkFo
ntStyle(), bcp47Locales, localeCount, c)); |
| 127 if (!typeface) |
| 128 return emptyAtom; |
| 129 |
| 130 SkString skiaFamilyName; |
| 131 typeface->getFamilyName(&skiaFamilyName); |
| 132 return skiaFamilyName.c_str(); |
| 133 } |
| 134 #endif |
| 135 |
| 90 void FontCache::platformInit() | 136 void FontCache::platformInit() |
| 91 { | 137 { |
| 92 } | 138 } |
| 93 | 139 |
| 94 PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle( | 140 PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle( |
| 95 const FontDescription& fontDescription, UChar32 character) | 141 const FontDescription& fontDescription, UChar32 character) |
| 96 { | 142 { |
| 97 FontDescription substituteDescription(fontDescription); | 143 FontDescription substituteDescription(fontDescription); |
| 98 substituteDescription.setStyle(FontStyleNormal); | 144 substituteDescription.setStyle(FontStyleNormal); |
| 99 substituteDescription.setWeight(FontWeightNormal); | 145 substituteDescription.setWeight(FontWeightNormal); |
| 100 | 146 |
| 101 FontFaceCreationParams creationParams(substituteDescription.family().family(
)); | 147 FontFaceCreationParams creationParams(substituteDescription.family().family(
)); |
| 102 FontPlatformData* substitutePlatformData = getFontPlatformData(substituteDes
cription, creationParams); | 148 FontPlatformData* substitutePlatformData = getFontPlatformData(substituteDes
cription, creationParams); |
| 103 if (substitutePlatformData && substitutePlatformData->fontContainsCharacter(
character)) { | 149 if (substitutePlatformData && substitutePlatformData->fontContainsCharacter(
character)) { |
| 104 FontPlatformData platformData = FontPlatformData(*substitutePlatformData
); | 150 FontPlatformData platformData = FontPlatformData(*substitutePlatformData
); |
| 105 platformData.setSyntheticBold(fontDescription.weight() >= FontWeight600)
; | 151 platformData.setSyntheticBold(fontDescription.weight() >= FontWeight600)
; |
| 106 platformData.setSyntheticItalic(fontDescription.style() == FontStyleItal
ic || fontDescription.style() == FontStyleOblique); | 152 platformData.setSyntheticItalic(fontDescription.style() == FontStyleItal
ic || fontDescription.style() == FontStyleOblique); |
| 107 return fontDataFromFontPlatformData(&platformData, DoNotRetain); | 153 return fontDataFromFontPlatformData(&platformData, DoNotRetain); |
| 108 } | 154 } |
| 109 | 155 |
| 110 return nullptr; | 156 return nullptr; |
| 111 } | 157 } |
| 112 | 158 |
| 113 #if !OS(WIN) && !OS(ANDROID) | 159 #if !OS(WIN) && !OS(ANDROID) |
| 114 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip
tion& fontDescription, UChar32 c, const SimpleFontData*) | 160 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip
tion& fontDescription, UChar32 c, const SimpleFontData*) |
| 115 { | 161 { |
| 162 #if OS(LINUX) |
| 163 // On linux the m_fontManager is set only if it was provided by the embedder
with WebFontRendering::setSkiaFontManager. This is |
| 164 // used to emulate android fonts so we always request the family from the fo
nt manager and if none is found, we return |
| 165 // the LastResort fallback font and avoid using FontCache::getFontForCharact
er which would use sandbox support to |
| 166 // query the underlying system for the font family. |
| 167 if (m_fontManager) { |
| 168 AtomicString familyName = getFamilyNameForCharacter(m_fontManager.get(),
c, fontDescription); |
| 169 if (familyName.isEmpty()) |
| 170 return getLastResortFallbackFont(fontDescription, DoNotRetain); |
| 171 return fontDataFromFontPlatformData(getFontPlatformData(fontDescription,
FontFaceCreationParams(familyName)), DoNotRetain); |
| 172 } |
| 173 #endif |
| 174 |
| 116 // First try the specified font with standard style & weight. | 175 // First try the specified font with standard style & weight. |
| 117 if (fontDescription.style() == FontStyleItalic | 176 if (fontDescription.style() == FontStyleItalic |
| 118 || fontDescription.weight() >= FontWeight600) { | 177 || fontDescription.weight() >= FontWeight600) { |
| 119 RefPtr<SimpleFontData> fontData = fallbackOnStandardFontStyle( | 178 RefPtr<SimpleFontData> fontData = fallbackOnStandardFontStyle( |
| 120 fontDescription, c); | 179 fontDescription, c); |
| 121 if (fontData) | 180 if (fontData) |
| 122 return fontData; | 181 return fontData; |
| 123 } | 182 } |
| 124 | 183 |
| 125 FontCache::PlatformFallbackFont fallbackFont; | 184 FontCache::PlatformFallbackFont fallbackFont; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 } | 329 } |
| 271 | 330 |
| 272 if (m_fontManager) { | 331 if (m_fontManager) { |
| 273 return adoptRef(useDirectWrite() | 332 return adoptRef(useDirectWrite() |
| 274 ? m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescrip
tion)) | 333 ? m_fontManager->matchFamilyStyle(name.data(), fontStyle(fontDescrip
tion)) |
| 275 : m_fontManager->legacyCreateTypeface(name.data(), style) | 334 : m_fontManager->legacyCreateTypeface(name.data(), style) |
| 276 ); | 335 ); |
| 277 } | 336 } |
| 278 #endif | 337 #endif |
| 279 | 338 |
| 339 #if OS(LINUX) |
| 340 // On linux if the fontManager has been overridden then we should be calling
the embedder |
| 341 // provided font Manager rather than calling SkTypeface::CreateFromName whic
h may redirect the |
| 342 // call to the default font Manager. |
| 343 if (m_fontManager) |
| 344 return adoptRef(m_fontManager->legacyCreateTypeface(name.data(), style))
; |
| 345 #endif |
| 346 |
| 280 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of | 347 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of |
| 281 // CreateFromName on all platforms. | 348 // CreateFromName on all platforms. |
| 282 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa
ce::Style>(style))); | 349 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa
ce::Style>(style))); |
| 283 } | 350 } |
| 284 | 351 |
| 285 #if !OS(WIN) | 352 #if !OS(WIN) |
| 286 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip
tion& fontDescription, | 353 PassOwnPtr<FontPlatformData> FontCache::createFontPlatformData(const FontDescrip
tion& fontDescription, |
| 287 const FontFaceCreationParams& creationParams, float fontSize) | 354 const FontFaceCreationParams& creationParams, float fontSize) |
| 288 { | 355 { |
| 289 CString name; | 356 CString name; |
| 290 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name))
; | 357 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name))
; |
| 291 if (!tf) | 358 if (!tf) |
| 292 return nullptr; | 359 return nullptr; |
| 293 | 360 |
| 294 return adoptPtr(new FontPlatformData(tf, | 361 return adoptPtr(new FontPlatformData(tf, |
| 295 name.data(), | 362 name.data(), |
| 296 fontSize, | 363 fontSize, |
| 297 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc
ription.isSyntheticBold(), | 364 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc
ription.isSyntheticBold(), |
| 298 ((fontDescription.style() == FontStyleItalic || fontDescription.style()
== FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), | 365 ((fontDescription.style() == FontStyleItalic || fontDescription.style()
== FontStyleOblique) && !tf->isItalic()) || fontDescription.isSyntheticItalic(), |
| 299 fontDescription.orientation(), | 366 fontDescription.orientation(), |
| 300 fontDescription.useSubpixelPositioning())); | 367 fontDescription.useSubpixelPositioning())); |
| 301 } | 368 } |
| 302 #endif // !OS(WIN) | 369 #endif // !OS(WIN) |
| 303 | 370 |
| 304 } // namespace blink | 371 } // namespace blink |
| OLD | NEW |