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

Side by Side Diff: webkit/port/platform/graphics/chromium/FontCacheLinux.cpp

Issue 13108: Linux: use other fonts when the primary is missing glyphs (Closed)
Patch Set: Addressing comments Created 12 years 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 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "FontCache.h" 6 #include "FontCache.h"
7 7
8 #include <fontconfig/fontconfig.h>
9
8 #include "AtomicString.h" 10 #include "AtomicString.h"
9 #include "CString.h" 11 #include "CString.h"
12 #include "Font.h"
10 #include "FontDescription.h" 13 #include "FontDescription.h"
11 #include "FontPlatformData.h" 14 #include "FontPlatformData.h"
12 #include "Logging.h" 15 #include "Logging.h"
13 #include "NotImplemented.h" 16 #include "NotImplemented.h"
17 #include "SimpleFontData.h"
14 18
15 #include "SkPaint.h" 19 #include "SkPaint.h"
16 #include "SkTypeface.h" 20 #include "SkTypeface.h"
17 #include "SkUtils.h" 21 #include "SkUtils.h"
18 22
19 namespace WebCore { 23 namespace WebCore {
20 24
21 void FontCache::platformInit() 25 void FontCache::platformInit()
22 { 26 {
23 } 27 }
24 28
25 const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, 29 const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font,
26 const UChar* character s, 30 const UChar* character s,
27 int length) 31 int length)
28 { 32 {
29 notImplemented(); 33 FcCharSet* cset = FcCharSetCreate();
30 return NULL; 34 for (int i = 0; i < length; ++i)
35 FcCharSetAddChar(cset, characters[i]);
36
37 FcPattern* pattern = FcPatternCreate();
38
39 FcValue fcvalue;
40 fcvalue.type = FcTypeCharSet;
41 fcvalue.u.c = cset;
42 FcPatternAdd(pattern, FC_CHARSET, fcvalue, 0);
43
44 FcConfigSubstitute(0, pattern, FcMatchPattern);
45 FcDefaultSubstitute(pattern);
46
47 FcResult result;
48 FcPattern* match = FcFontMatch(0, pattern, &result);
49 FcPatternDestroy(pattern);
50
51 SimpleFontData* ret = NULL;
52
53 if (match) {
54 FcChar8* family;
55 if (FcPatternGetString(match, FC_FAMILY, 0, &family) == FcResultMatch) {
56 FontPlatformData* fpd =
57 createFontPlatformData(font.fontDescription(),
58 AtomicString((char *) family));
59 ret = new SimpleFontData(*fpd);
60 }
61 FcPatternDestroy(match);
62 }
63
64 FcCharSetDestroy(cset);
65
66 return ret;
31 } 67 }
32 68
33 const AtomicString& FontCache::alternateFamilyName(const AtomicString& familyNam e) 69 const AtomicString& FontCache::alternateFamilyName(const AtomicString& familyNam e)
34 { 70 {
35 notImplemented(); 71 notImplemented();
36 72
37 // This is just to stop GCC emitting a warning about returning a reference 73 // This is just to stop GCC emitting a warning about returning a reference
38 // to a temporary variable 74 // to a temporary variable
39 static AtomicString a; 75 static AtomicString a;
40 return a; 76 return a;
(...skipping 14 matching lines...) Expand all
55 Vector<unsigned>& traitsMasks) 91 Vector<unsigned>& traitsMasks)
56 { 92 {
57 notImplemented(); 93 notImplemented();
58 } 94 }
59 95
60 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, 96 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription,
61 const AtomicString& family) 97 const AtomicString& family)
62 { 98 {
63 const char* name = 0; 99 const char* name = 0;
64 CString s; 100 CString s;
65 101
66 if (family.length() == 0) { 102 if (family.length() == 0) {
67 static const struct { 103 static const struct {
68 FontDescription::GenericFamilyType mType; 104 FontDescription::GenericFamilyType mType;
69 const char* mName; 105 const char* mName;
70 } gNames[] = { 106 } gNames[] = {
71 { FontDescription::SerifFamily, "serif" }, 107 { FontDescription::SerifFamily, "serif" },
72 { FontDescription::SansSerifFamily, "sans-serif" }, 108 { FontDescription::SansSerifFamily, "sans-serif" },
73 { FontDescription::MonospaceFamily, "monospace" }, 109 { FontDescription::MonospaceFamily, "monospace" },
74 { FontDescription::CursiveFamily, "cursive" }, 110 { FontDescription::CursiveFamily, "cursive" },
75 { FontDescription::FantasyFamily, "fantasy" } 111 { FontDescription::FantasyFamily, "fantasy" }
76 }; 112 };
77 113
78 FontDescription::GenericFamilyType type = fontDescription.genericFamily( ); 114 FontDescription::GenericFamilyType type = fontDescription.genericFamily( );
79 for (unsigned i = 0; i < SK_ARRAY_COUNT(gNames); i++) { 115 for (unsigned i = 0; i < SK_ARRAY_COUNT(gNames); i++) {
80 if (type == gNames[i].mType) { 116 if (type == gNames[i].mType) {
81 name = gNames[i].mName; 117 name = gNames[i].mName;
82 break; 118 break;
83 } 119 }
84 } 120 }
85 // if we fall out of the loop, it's ok for name to still be 0 121 // if we fall out of the loop, it's ok for name to still be 0
86 } 122 }
87 else { // convert the name to utf8 123 else { // convert the name to utf8
88 s = family.string().utf8(); 124 s = family.string().utf8();
89 name = s.data(); 125 name = s.data();
90 } 126 }
91 127
92 int style = SkTypeface::kNormal; 128 int style = SkTypeface::kNormal;
93 if (fontDescription.weight() >= FontWeightBold) 129 if (fontDescription.weight() >= FontWeightBold)
94 style |= SkTypeface::kBold; 130 style |= SkTypeface::kBold;
95 if (fontDescription.italic()) 131 if (fontDescription.italic())
96 style |= SkTypeface::kItalic; 132 style |= SkTypeface::kItalic;
97 133
98 SkTypeface* tf = SkTypeface::Create(name, (SkTypeface::Style)style); 134 SkTypeface* tf = SkTypeface::Create(name, (SkTypeface::Style)style);
99 if (!tf) 135 if (!tf)
100 return NULL; 136 return NULL;
101 137
102 FontPlatformData* result = 138 FontPlatformData* result =
103 new FontPlatformData(tf, 139 new FontPlatformData(tf,
104 fontDescription.computedSize(), 140 fontDescription.computedSize(),
105 (style & SkTypeface::kBold) && !tf->isBold(), 141 (style & SkTypeface::kBold) && !tf->isBold(),
106 (style & SkTypeface::kItalic) && !tf->isItalic()); 142 (style & SkTypeface::kItalic) && !tf->isItalic());
107 tf->unref(); 143 tf->unref();
108 return result; 144 return result;
109 } 145 }
110 146
111 AtomicString FontCache::getGenericFontForScript(UScriptCode script, 147 AtomicString FontCache::getGenericFontForScript(UScriptCode script,
112 const FontDescription&) 148 const FontDescription& descript)
113 { 149 {
114 notImplemented(); 150 notImplemented();
115 return AtomicString(); 151 return AtomicString();
116 } 152 }
117 153
118 } // namespace WebCore 154 } // namespace WebCore
OLDNEW
« no previous file with comments | « build/install-build-deps.sh ('k') | webkit/port/platform/graphics/chromium/GlyphPageTreeNodeLinux.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698