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

Side by Side Diff: Source/platform/fonts/win/FontCacheSkiaWin.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
« no previous file with comments | « Source/platform/fonts/skia/FontCacheSkia.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007 Apple Computer, Inc. 2 * Copyright (C) 2006, 2007 Apple Computer, Inc.
3 * Copyright (c) 2006, 2007, 2008, 2009, 2012 Google Inc. All rights reserved. 3 * Copyright (c) 2006, 2007, 2008, 2009, 2012 Google Inc. All rights reserved.
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 are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * 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 18 matching lines...) Expand all
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32 #include "config.h" 32 #include "config.h"
33 #include "platform/fonts/FontCache.h" 33 #include "platform/fonts/FontCache.h"
34 34
35 #include "SkFontMgr.h" 35 #include "SkFontMgr.h"
36 #include "SkTypeface_win.h" 36 #include "SkTypeface_win.h"
37 #include "platform/RuntimeEnabledFeatures.h" 37 #include "platform/RuntimeEnabledFeatures.h"
38 #include "platform/fonts/FontDescription.h" 38 #include "platform/fonts/FontDescription.h"
39 #include "platform/fonts/FontFaceCreationParams.h"
39 #include "platform/fonts/SimpleFontData.h" 40 #include "platform/fonts/SimpleFontData.h"
40 #include "platform/fonts/harfbuzz/FontPlatformDataHarfbuzz.h" 41 #include "platform/fonts/harfbuzz/FontPlatformDataHarfbuzz.h"
41 #include "platform/fonts/win/FontFallbackWin.h" 42 #include "platform/fonts/win/FontFallbackWin.h"
42 43
43 namespace WebCore { 44 namespace WebCore {
44 45
45 HashMap<String, SkTypeface*>* FontCache::s_sideloadedFonts = 0; 46 HashMap<String, SkTypeface*>* FontCache::s_sideloadedFonts = 0;
46 47
47 // static 48 // static
48 void FontCache::addSideloadedFontForTesting(SkTypeface* typeface) 49 void FontCache::addSideloadedFontForTesting(SkTypeface* typeface)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip tion& fontDescription, UChar32 character, const SimpleFontData*) 89 PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(const FontDescrip tion& fontDescription, UChar32 character, const SimpleFontData*)
89 { 90 {
90 // FIXME: Consider passing fontDescription.dominantScript() 91 // FIXME: Consider passing fontDescription.dominantScript()
91 // to GetFallbackFamily here. 92 // to GetFallbackFamily here.
92 UScriptCode script; 93 UScriptCode script;
93 const wchar_t* family = getFallbackFamily(character, 94 const wchar_t* family = getFallbackFamily(character,
94 fontDescription.genericFamily(), 95 fontDescription.genericFamily(),
95 &script, 96 &script,
96 m_fontManager.get()); 97 m_fontManager.get());
97 FontPlatformData* data = 0; 98 FontPlatformData* data = 0;
98 if (family) 99 if (family) {
99 data = getFontPlatformData(fontDescription, AtomicString(family, wcslen (family))); 100 FontFaceCreationParams createByFamily(AtomicString(family, wcslen(family )));
101 data = getFontPlatformData(fontDescription, createByFamily);
102 }
100 103
101 // Last resort font list : PanUnicode. CJK fonts have a pretty 104 // Last resort font list : PanUnicode. CJK fonts have a pretty
102 // large repertoire. Eventually, we need to scan all the fonts 105 // large repertoire. Eventually, we need to scan all the fonts
103 // on the system to have a Firefox-like coverage. 106 // on the system to have a Firefox-like coverage.
104 // Make sure that all of them are lowercased. 107 // Make sure that all of them are lowercased.
105 const static wchar_t* const cjkFonts[] = { 108 const static wchar_t* const cjkFonts[] = {
106 L"arial unicode ms", 109 L"arial unicode ms",
107 L"ms pgothic", 110 L"ms pgothic",
108 L"simsun", 111 L"simsun",
109 L"gulim", 112 L"gulim",
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 panUniFonts = commonFonts; 151 panUniFonts = commonFonts;
149 numFonts = WTF_ARRAY_LENGTH(commonFonts); 152 numFonts = WTF_ARRAY_LENGTH(commonFonts);
150 } 153 }
151 // Font returned from getFallbackFamily may not cover |character| 154 // Font returned from getFallbackFamily may not cover |character|
152 // because it's based on script to font mapping. This problem is 155 // because it's based on script to font mapping. This problem is
153 // critical enough for non-Latin scripts (especially Han) to 156 // critical enough for non-Latin scripts (especially Han) to
154 // warrant an additional (real coverage) check with fontCotainsCharacter. 157 // warrant an additional (real coverage) check with fontCotainsCharacter.
155 int i; 158 int i;
156 for (i = 0; (!data || !fontContainsCharacter(data, family, character)) && i < numFonts; ++i) { 159 for (i = 0; (!data || !fontContainsCharacter(data, family, character)) && i < numFonts; ++i) {
157 family = panUniFonts[i]; 160 family = panUniFonts[i];
158 data = getFontPlatformData(fontDescription, AtomicString(family, wcslen( family))); 161 FontFaceCreationParams createByFamily(AtomicString(family, wcslen(family )));
162 data = getFontPlatformData(fontDescription, createByFamily);
159 } 163 }
160 164
161 // When i-th font (0-base) in |panUniFonts| contains a character and 165 // When i-th font (0-base) in |panUniFonts| contains a character and
162 // we get out of the loop, |i| will be |i + 1|. That is, if only the 166 // we get out of the loop, |i| will be |i + 1|. That is, if only the
163 // last font in the array covers the character, |i| will be numFonts. 167 // last font in the array covers the character, |i| will be numFonts.
164 // So, we have to use '<=" rather than '<' to see if we found a font 168 // So, we have to use '<=" rather than '<' to see if we found a font
165 // covering the character. 169 // covering the character.
166 if (i <= numFonts) 170 if (i <= numFonts)
167 return fontDataFromFontPlatformData(data, DoNotRetain); 171 return fontDataFromFontPlatformData(data, DoNotRetain);
168 172
(...skipping 25 matching lines...) Expand all
194 if (!matchesRequestedFamily) { 198 if (!matchesRequestedFamily) {
195 SkString familyName; 199 SkString familyName;
196 tf->getFamilyName(&familyName); 200 tf->getFamilyName(&familyName);
197 if (equalIgnoringCase(family, familyName)) 201 if (equalIgnoringCase(family, familyName))
198 matchesRequestedFamily = true; 202 matchesRequestedFamily = true;
199 } 203 }
200 204
201 return matchesRequestedFamily; 205 return matchesRequestedFamily;
202 } 206 }
203 207
204 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const AtomicString& family, float fontSize) 208 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const FontFaceCreationParams& creationParams, float fontSize)
205 { 209 {
210 ASSERT(creationParams.creationType() == CreateFontByFamily);
206 CString name; 211 CString name;
207 RefPtr<SkTypeface> tf = createTypeface(fontDescription, family, name); 212 RefPtr<SkTypeface> tf = createTypeface(fontDescription, creationParams, name );
208 if (!tf) 213 if (!tf)
209 return 0; 214 return 0;
210 215
211 // Windows will always give us a valid pointer here, even if the face name 216 // Windows will always give us a valid pointer here, even if the face name
212 // is non-existent. We have to double-check and see if the family name was 217 // is non-existent. We have to double-check and see if the family name was
213 // really used. 218 // really used.
214 // FIXME: Do we need to use predefined fonts "guaranteed" to exist 219 // FIXME: Do we need to use predefined fonts "guaranteed" to exist
215 // when we're running in layout-test mode? 220 // when we're running in layout-test mode?
216 if (!typefacesMatchesFamily(tf.get(), family)) { 221 if (!typefacesMatchesFamily(tf.get(), creationParams.family())) {
217 return 0; 222 return 0;
218 } 223 }
219 224
220 FontPlatformData* result = new FontPlatformData(tf, 225 FontPlatformData* result = new FontPlatformData(tf,
221 name.data(), 226 name.data(),
222 fontSize, 227 fontSize,
223 fontDescription.weight() >= FontWeightBold && !tf->isBold() || fontDescr iption.isSyntheticBold(), 228 fontDescription.weight() >= FontWeightBold && !tf->isBold() || fontDescr iption.isSyntheticBold(),
224 fontDescription.style() == FontStyleItalic && !tf->isItalic() || fontDes cription.isSyntheticItalic(), 229 fontDescription.style() == FontStyleItalic && !tf->isItalic() || fontDes cription.isSyntheticItalic(),
225 fontDescription.orientation(), 230 fontDescription.orientation(),
226 s_useSubpixelPositioning); 231 s_useSubpixelPositioning);
(...skipping 13 matching lines...) Expand all
240 if (typefacesMatchesFamily(tf.get(), entry.family)) { 245 if (typefacesMatchesFamily(tf.get(), entry.family)) {
241 result->setMinSizeForAntiAlias(entry.minSize); 246 result->setMinSizeForAntiAlias(entry.minSize);
242 break; 247 break;
243 } 248 }
244 } 249 }
245 250
246 return result; 251 return result;
247 } 252 }
248 253
249 } 254 }
OLDNEW
« no previous file with comments | « Source/platform/fonts/skia/FontCacheSkia.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698