Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: Source/platform/fonts/skia/FontCacheSkia.cpp

Issue 307243002: Fix font family based fallback font selection (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Windows link fix. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
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 "config.h" 31 #include "config.h"
32 32
33 #if !OS(WIN) && !OS(ANDROID)
34 #include "SkFontConfigInterface.h"
35 #endif
33 #include "SkFontMgr.h" 36 #include "SkFontMgr.h"
37 #include "SkStream.h"
34 #include "SkTypeface.h" 38 #include "SkTypeface.h"
35 #include "platform/NotImplemented.h" 39 #include "platform/NotImplemented.h"
36 #include "platform/fonts/AlternateFontFamily.h" 40 #include "platform/fonts/AlternateFontFamily.h"
37 #include "platform/fonts/FontCache.h" 41 #include "platform/fonts/FontCache.h"
38 #include "platform/fonts/FontDescription.h" 42 #include "platform/fonts/FontDescription.h"
43 #include "platform/fonts/FontFaceCreationParams.h"
39 #include "platform/fonts/SimpleFontData.h" 44 #include "platform/fonts/SimpleFontData.h"
40 #include "wtf/Assertions.h" 45 #include "wtf/Assertions.h"
41 #include "wtf/text/AtomicString.h" 46 #include "wtf/text/AtomicString.h"
42 #include "wtf/text/CString.h" 47 #include "wtf/text/CString.h"
43 #include <unicode/locid.h> 48 #include <unicode/locid.h>
44 49
50 #if !OS(WIN) && !OS(ANDROID)
51 static SkStream* streamForFontconfigInterfaceId(int fontconfigInterfaceId)
52 {
53 SkAutoTUnref<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal());
54 SkFontConfigInterface::FontIdentity fontIdentity;
55 fontIdentity.fID = fontconfigInterfaceId;
56 return fci->openStream(fontIdentity);
57 }
58 #endif
59
45 namespace WebCore { 60 namespace WebCore {
46 61
47 void FontCache::platformInit() 62 void FontCache::platformInit()
48 { 63 {
49 } 64 }
50 65
51 #if !OS(WIN) && !OS(ANDROID) 66 #if !OS(WIN) && !OS(ANDROID)
52 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip tion& fontDescription, UChar32 c, const SimpleFontData*) 67 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip tion& fontDescription, UChar32 c, const SimpleFontData*)
53 { 68 {
54 icu::Locale locale = icu::Locale::getDefault(); 69 icu::Locale locale = icu::Locale::getDefault();
55 FontCache::PlatformFallbackFont fallbackFont; 70 FontCache::PlatformFallbackFont fallbackFont;
56 FontCache::getFontForCharacter(c, locale.getLanguage(), &fallbackFont); 71 FontCache::getFontForCharacter(c, locale.getLanguage(), &fallbackFont);
57 if (fallbackFont.name.isEmpty()) 72 if (fallbackFont.name.isEmpty())
58 return nullptr; 73 return nullptr;
59 74
60 AtomicString atomicFamily(fallbackFont.name); 75 FontFaceCreationParams creationParams;
76 creationParams = FontFaceCreationParams(fallbackFont.fontconfigInterfaceId, fallbackFont.ttcIndex);
77
61 // Changes weight and/or italic of given FontDescription depends on 78 // Changes weight and/or italic of given FontDescription depends on
62 // the result of fontconfig so that keeping the correct font mapping 79 // the result of fontconfig so that keeping the correct font mapping
63 // of the given character. See http://crbug.com/32109 for details. 80 // of the given character. See http://crbug.com/32109 for details.
64 bool shouldSetSyntheticBold = false; 81 bool shouldSetSyntheticBold = false;
65 bool shouldSetSyntheticItalic = false; 82 bool shouldSetSyntheticItalic = false;
66 FontDescription description(fontDescription); 83 FontDescription description(fontDescription);
67 if (fallbackFont.isBold && description.weight() < FontWeightBold) 84 if (fallbackFont.isBold && description.weight() < FontWeightBold)
68 description.setWeight(FontWeightBold); 85 description.setWeight(FontWeightBold);
69 if (!fallbackFont.isBold && description.weight() >= FontWeightBold) { 86 if (!fallbackFont.isBold && description.weight() >= FontWeightBold) {
70 shouldSetSyntheticBold = true; 87 shouldSetSyntheticBold = true;
71 description.setWeight(FontWeightNormal); 88 description.setWeight(FontWeightNormal);
72 } 89 }
73 if (fallbackFont.isItalic && description.style() == FontStyleNormal) 90 if (fallbackFont.isItalic && description.style() == FontStyleNormal)
74 description.setStyle(FontStyleItalic); 91 description.setStyle(FontStyleItalic);
75 if (!fallbackFont.isItalic && description.style() == FontStyleItalic) { 92 if (!fallbackFont.isItalic && description.style() == FontStyleItalic) {
76 shouldSetSyntheticItalic = true; 93 shouldSetSyntheticItalic = true;
77 description.setStyle(FontStyleNormal); 94 description.setStyle(FontStyleNormal);
78 } 95 }
79 96
80 FontPlatformData* substitutePlatformData = getFontPlatformData(description, atomicFamily); 97 FontPlatformData* substitutePlatformData = getFontPlatformData(description, creationParams);
81 if (!substitutePlatformData) 98 if (!substitutePlatformData)
82 return nullptr; 99 return nullptr;
83 FontPlatformData platformData = FontPlatformData(*substitutePlatformData); 100 FontPlatformData platformData = FontPlatformData(*substitutePlatformData);
84 platformData.setSyntheticBold(shouldSetSyntheticBold); 101 platformData.setSyntheticBold(shouldSetSyntheticBold);
85 platformData.setSyntheticItalic(shouldSetSyntheticItalic); 102 platformData.setSyntheticItalic(shouldSetSyntheticItalic);
86 return fontDataFromFontPlatformData(&platformData, DoNotRetain); 103 return fontDataFromFontPlatformData(&platformData, DoNotRetain);
87 } 104 }
88 105
89 #endif // !OS(WIN) && !OS(ANDROID) 106 #endif // !OS(WIN) && !OS(ANDROID)
90 107
91 PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescri ption& description, ShouldRetain shouldRetain) 108 PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescri ption& description, ShouldRetain shouldRetain)
92 { 109 {
93 const AtomicString fallbackFontFamily = getFallbackFontFamily(description); 110 const FontFaceCreationParams fallbackCreationParams(getFallbackFontFamily(de scription));
94 const FontPlatformData* fontPlatformData = getFontPlatformData(description, fallbackFontFamily); 111 const FontPlatformData* fontPlatformData = getFontPlatformData(description, fallbackCreationParams);
95 112
96 // We should at least have Sans or Arial which is the last resort fallback o f SkFontHost ports. 113 // We should at least have Sans or Arial which is the last resort fallback o f SkFontHost ports.
97 if (!fontPlatformData) { 114 if (!fontPlatformData) {
98 DEFINE_STATIC_LOCAL(const AtomicString, sansStr, ("Sans", AtomicString:: ConstructFromLiteral)); 115 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, sansCreationParams, (A tomicString("Sans", AtomicString::ConstructFromLiteral)));
99 fontPlatformData = getFontPlatformData(description, sansStr); 116 fontPlatformData = getFontPlatformData(description, sansCreationParams);
100 } 117 }
101 if (!fontPlatformData) { 118 if (!fontPlatformData) {
102 DEFINE_STATIC_LOCAL(const AtomicString, arialStr, ("Arial", AtomicString ::ConstructFromLiteral)); 119 DEFINE_STATIC_LOCAL(const FontFaceCreationParams, arialCreationParams, ( AtomicString("Arial", AtomicString::ConstructFromLiteral)));
103 fontPlatformData = getFontPlatformData(description, arialStr); 120 fontPlatformData = getFontPlatformData(description, arialCreationParams) ;
104 } 121 }
105 122
106 // TODO(scottmg|eae): Trying to identify crashes in http://crbug.com/383542 123 // TODO(scottmg|eae): Trying to identify crashes in http://crbug.com/383542
107 if (!fontPlatformData) 124 if (!fontPlatformData)
108 CRASH(); 125 CRASH();
109 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain); 126 return fontDataFromFontPlatformData(fontPlatformData, shouldRetain);
110 } 127 }
111 128
112 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc ription, const AtomicString& family, CString& name) 129 PassRefPtr<SkTypeface> FontCache::createTypeface(const FontDescription& fontDesc ription, const FontFaceCreationParams& creationParams, CString& name)
113 { 130 {
131 #if !OS(WIN) && !OS(ANDROID)
132 if (creationParams.creationType() == CreateFontByFciIdAndTtcIndex) {
133 // TODO(dro): crbug.com/381620 Use creationParams.ttcIndex() after
134 // https://code.google.com/p/skia/issues/detail?id=1186 gets fixed.
135 SkTypeface* typeface = SkTypeface::CreateFromStream(streamForFontconfigI nterfaceId(creationParams.fontconfigInterfaceId()));
136 return adoptRef(typeface);
137 }
138 #endif
139
140 AtomicString family = creationParams.family();
114 // If we're creating a fallback font (e.g. "-webkit-monospace"), convert the name into 141 // If we're creating a fallback font (e.g. "-webkit-monospace"), convert the name into
115 // the fallback name (like "monospace") that fontconfig understands. 142 // the fallback name (like "monospace") that fontconfig understands.
116 if (!family.length() || family.startsWith("-webkit-")) { 143 if (!family.length() || family.startsWith("-webkit-")) {
117 name = getFallbackFontFamily(fontDescription).string().utf8(); 144 name = getFallbackFontFamily(fontDescription).string().utf8();
118 } else { 145 } else {
119 // convert the name to utf8 146 // convert the name to utf8
120 name = family.utf8(); 147 name = family.utf8();
121 } 148 }
122 149
123 int style = SkTypeface::kNormal; 150 int style = SkTypeface::kNormal;
(...skipping 11 matching lines...) Expand all
135 } 162 }
136 // FIXME: Use SkFontStyle and matchFamilyStyle instead of legacyCreateTypefa ce. 163 // FIXME: Use SkFontStyle and matchFamilyStyle instead of legacyCreateTypefa ce.
137 if (m_fontManager) 164 if (m_fontManager)
138 return adoptRef(m_fontManager->legacyCreateTypeface(name.data(), style)) ; 165 return adoptRef(m_fontManager->legacyCreateTypeface(name.data(), style)) ;
139 #endif 166 #endif
140 167
141 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style))); 168 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style)));
142 } 169 }
143 170
144 #if !OS(WIN) 171 #if !OS(WIN)
145 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const AtomicString& family, float fontSize) 172 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const FontFaceCreationParams& creationParams, float fontSize)
146 { 173 {
147 CString name; 174 CString name;
148 RefPtr<SkTypeface> tf(createTypeface(fontDescription, family, name)); 175 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ;
149 if (!tf) 176 if (!tf)
150 return 0; 177 return 0;
151 178
152 FontPlatformData* result = new FontPlatformData(tf, 179 FontPlatformData* result = new FontPlatformData(tf,
153 name.data(), 180 name.data(),
154 fontSize, 181 fontSize,
155 (fontDescription.weight() >= FontWeightBold && !tf->isBold()) || fontDes cription.isSyntheticBold(), 182 (fontDescription.weight() >= FontWeightBold && !tf->isBold()) || fontDes cription.isSyntheticBold(),
156 (fontDescription.style() && !tf->isItalic()) || fontDescription.isSynthe ticItalic(), 183 (fontDescription.style() && !tf->isItalic()) || fontDescription.isSynthe ticItalic(),
157 fontDescription.orientation(), 184 fontDescription.orientation(),
158 fontDescription.useSubpixelPositioning()); 185 fontDescription.useSubpixelPositioning());
159 return result; 186 return result;
160 } 187 }
161 #endif // !OS(WIN) 188 #endif // !OS(WIN)
162 189
163 } // namespace WebCore 190 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/platform/fonts/mac/FontCacheMac.mm ('k') | Source/platform/fonts/win/FontCacheSkiaWin.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698