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

Side by Side Diff: Source/platform/fonts/win/FontFallbackWin.cpp

Issue 182383002: Reland "Change FontFallbackWin to use FamilyNameIterator" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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, 2008, 2009, 2010, 2012 Google Inc. All rights reser ved. 2 * Copyright (c) 2006, 2007, 2008, 2009, 2010, 2012 Google Inc. All rights reser ved.
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
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 #include "platform/fonts/win/FontFallbackWin.h" 32 #include "platform/fonts/win/FontFallbackWin.h"
33 33
34 #include "platform/win/HWndDC.h" 34 #include "SkTypeface.h"
35 #include "wtf/HashMap.h" 35 #include "wtf/HashMap.h"
36 #include "wtf/text/StringHash.h" 36 #include "wtf/text/StringHash.h"
37 #include "wtf/text/WTFString.h" 37 #include "wtf/text/WTFString.h"
38 #include <limits> 38 #include <limits>
39 #include <unicode/locid.h> 39 #include <unicode/locid.h>
40 #include <unicode/uchar.h> 40 #include <unicode/uchar.h>
41 41
42 namespace WebCore { 42 namespace WebCore {
43 43
44 namespace { 44 namespace {
45 45
46 bool isFontPresent(const UChar* fontName) 46 static inline bool isFontPresent(const UChar* fontName)
47 { 47 {
48 HFONT hfont = CreateFont(12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, fontName); 48 String family = fontName;
49 if (!hfont) 49 RefPtr<SkTypeface> tf = adoptRef(SkTypeface::CreateFromName(family.utf8().da ta(), SkTypeface::kNormal));
50 if (!tf)
50 return false; 51 return false;
51 HWndDC dc(0); 52
52 HGDIOBJ oldFont = static_cast<HFONT>(SelectObject(dc, hfont)); 53 SkTypeface::LocalizedStrings* actualFamilies = tf->createFamilyNameIterator( );
53 WCHAR actualFontName[LF_FACESIZE]; 54 bool matchesRequestedFamily = false;
54 GetTextFace(dc, LF_FACESIZE, actualFontName); 55 SkTypeface::LocalizedString actualFamily;
55 actualFontName[LF_FACESIZE - 1] = 0; 56 while (actualFamilies->next(&actualFamily)) {
56 SelectObject(dc, oldFont); 57 if (equalIgnoringCase(family, AtomicString::fromUTF8(actualFamily.fStrin g.c_str()))) {
57 DeleteObject(hfont); 58 matchesRequestedFamily = true;
58 // We don't have to worry about East Asian fonts with locale-dependent 59 break;
59 // names here for now. 60 }
60 // FIXME: Why not? 61 }
61 return !wcscmp(fontName, actualFontName); 62 actualFamilies->unref();
63
64 return matchesRequestedFamily;
62 } 65 }
63 66
64 // A simple mapping from UScriptCode to family name. This is a sparse array, 67 // A simple mapping from UScriptCode to family name. This is a sparse array,
65 // which works well since the range of UScriptCode values is small. 68 // which works well since the range of UScriptCode values is small.
66 typedef const UChar* ScriptToFontMap[USCRIPT_CODE_LIMIT]; 69 typedef const UChar* ScriptToFontMap[USCRIPT_CODE_LIMIT];
67 70
68 void initializeScriptFontMap(ScriptToFontMap& scriptFontMap) 71 void initializeScriptFontMap(ScriptToFontMap& scriptFontMap)
69 { 72 {
70 struct FontMap { 73 struct FontMap {
71 UScriptCode script; 74 UScriptCode script;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 U16_NEXT(characters, i, length, ucs4); 342 U16_NEXT(characters, i, length, ucs4);
340 script = getScript(ucs4); 343 script = getScript(ucs4);
341 } 344 }
342 345
343 const UChar* family = getFallbackFamily(ucs4, generic, 0); 346 const UChar* family = getFallbackFamily(ucs4, generic, 0);
344 347
345 return family; 348 return family;
346 } 349 }
347 350
348 } // namespace WebCore 351 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698