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 28 matching lines...) Expand all Loading... |
39 #include "wtf/Assertions.h" | 39 #include "wtf/Assertions.h" |
40 #include "wtf/text/AtomicString.h" | 40 #include "wtf/text/AtomicString.h" |
41 #include "wtf/text/CString.h" | 41 #include "wtf/text/CString.h" |
42 | 42 |
43 namespace WebCore { | 43 namespace WebCore { |
44 | 44 |
45 void FontCache::platformInit() | 45 void FontCache::platformInit() |
46 { | 46 { |
47 } | 47 } |
48 | 48 |
| 49 #if !OS(WINDOWS) |
49 PassRefPtr<SimpleFontData> FontCache::getFontDataForCharacter(const Font& font,
UChar32 c) | 50 PassRefPtr<SimpleFontData> FontCache::getFontDataForCharacter(const Font& font,
UChar32 c) |
50 { | 51 { |
51 icu::Locale locale = icu::Locale::getDefault(); | 52 icu::Locale locale = icu::Locale::getDefault(); |
52 FontCache::SimpleFontFamily family; | 53 FontCache::SimpleFontFamily family; |
53 FontCache::getFontFamilyForCharacter(c, locale.getLanguage(), &family); | 54 FontCache::getFontFamilyForCharacter(c, locale.getLanguage(), &family); |
54 if (family.name.isEmpty()) | 55 if (family.name.isEmpty()) |
55 return 0; | 56 return 0; |
56 | 57 |
57 AtomicString atomicFamily(family.name); | 58 AtomicString atomicFamily(family.name); |
58 // Changes weight and/or italic of given FontDescription depends on | 59 // Changes weight and/or italic of given FontDescription depends on |
(...skipping 17 matching lines...) Expand all Loading... |
76 | 77 |
77 FontPlatformData* substitutePlatformData = getFontResourcePlatformData(descr
iption, atomicFamily, DoNotRetain); | 78 FontPlatformData* substitutePlatformData = getFontResourcePlatformData(descr
iption, atomicFamily, DoNotRetain); |
78 if (!substitutePlatformData) | 79 if (!substitutePlatformData) |
79 return 0; | 80 return 0; |
80 FontPlatformData platformData = FontPlatformData(*substitutePlatformData); | 81 FontPlatformData platformData = FontPlatformData(*substitutePlatformData); |
81 platformData.setFakeBold(shouldSetFakeBold); | 82 platformData.setFakeBold(shouldSetFakeBold); |
82 platformData.setFakeItalic(shouldSetFakeItalic); | 83 platformData.setFakeItalic(shouldSetFakeItalic); |
83 return getFontResourceData(&platformData, DoNotRetain); | 84 return getFontResourceData(&platformData, DoNotRetain); |
84 } | 85 } |
85 | 86 |
| 87 #endif // !OS(WINDOWNS) |
| 88 |
86 PassRefPtr<SimpleFontData> FontCache::getSimilarFontPlatformData(const Font& fon
t) | 89 PassRefPtr<SimpleFontData> FontCache::getSimilarFontPlatformData(const Font& fon
t) |
87 { | 90 { |
88 return 0; | 91 return 0; |
89 } | 92 } |
90 | 93 |
91 PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescri
ption& description, ShouldRetain shouldRetain) | 94 PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescri
ption& description, ShouldRetain shouldRetain) |
92 { | 95 { |
93 const FontPlatformData* fontPlatformData = getFallbackFontData(description); | 96 const FontPlatformData* fontPlatformData = getFallbackFontData(description); |
94 if (!fontPlatformData) { | 97 if (!fontPlatformData) { |
95 // we should at least have Arial; this is the SkFontHost_fontconfig last
resort fallback | 98 // we should at least have Arial; this is the SkFontHost_fontconfig last
resort fallback |
96 DEFINE_STATIC_LOCAL(const AtomicString, arialStr, ("Arial", AtomicString
::ConstructFromLiteral)); | 99 DEFINE_STATIC_LOCAL(const AtomicString, arialStr, ("Arial", AtomicString
::ConstructFromLiteral)); |
97 fontPlatformData = getFontResourcePlatformData(description, arialStr); | 100 fontPlatformData = getFontResourcePlatformData(description, arialStr); |
98 } | 101 } |
99 | 102 |
100 ASSERT(fontPlatformData); | 103 ASSERT(fontPlatformData); |
101 return getFontResourceData(fontPlatformData, shouldRetain); | 104 return getFontResourceData(fontPlatformData, shouldRetain); |
102 } | 105 } |
103 | 106 |
104 void FontCache::getTraitsInFamily(const AtomicString& familyName, | 107 void FontCache::getTraitsInFamily(const AtomicString& familyName, |
105 Vector<unsigned>& traitsMasks) | 108 Vector<unsigned>& traitsMasks) |
106 { | 109 { |
107 notImplemented(); | 110 notImplemented(); |
108 } | 111 } |
109 | 112 |
110 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
escription, | 113 SkTypeface* FontCache::createTypeface(const FontDescription& fontDescription, co
nst AtomicString& family, CString& name) |
111 const AtomicString& family) | |
112 { | 114 { |
113 const char* name = 0; | 115 name = ""; |
114 CString s; | |
115 | 116 |
116 // If we're creating a fallback font (e.g. "-webkit-monospace"), convert the
name into | 117 // If we're creating a fallback font (e.g. "-webkit-monospace"), convert the
name into |
117 // the fallback name (like "monospace") that fontconfig understands. | 118 // the fallback name (like "monospace") that fontconfig understands. |
118 if (!family.length() || family.startsWith("-webkit-")) { | 119 if (!family.length() || family.startsWith("-webkit-")) { |
119 static const struct { | 120 static const struct { |
120 FontDescription::GenericFamilyType mType; | 121 FontDescription::GenericFamilyType mType; |
121 const char* mName; | 122 const char* mName; |
122 } fontDescriptions[] = { | 123 } fontDescriptions[] = { |
123 { FontDescription::SerifFamily, "serif" }, | 124 { FontDescription::SerifFamily, "serif" }, |
124 { FontDescription::SansSerifFamily, "sans-serif" }, | 125 { FontDescription::SansSerifFamily, "sans-serif" }, |
125 { FontDescription::MonospaceFamily, "monospace" }, | 126 { FontDescription::MonospaceFamily, "monospace" }, |
126 { FontDescription::CursiveFamily, "cursive" }, | 127 { FontDescription::CursiveFamily, "cursive" }, |
127 { FontDescription::FantasyFamily, "fantasy" } | 128 { FontDescription::FantasyFamily, "fantasy" } |
128 }; | 129 }; |
129 | 130 |
130 FontDescription::GenericFamilyType type = fontDescription.genericFamily(
); | 131 FontDescription::GenericFamilyType type = fontDescription.genericFamily(
); |
131 for (unsigned i = 0; i < SK_ARRAY_COUNT(fontDescriptions); i++) { | 132 for (unsigned i = 0; i < SK_ARRAY_COUNT(fontDescriptions); i++) { |
132 if (type == fontDescriptions[i].mType) { | 133 if (type == fontDescriptions[i].mType) { |
133 name = fontDescriptions[i].mName; | 134 name = fontDescriptions[i].mName; |
134 break; | 135 break; |
135 } | 136 } |
136 } | 137 } |
137 if (!name) | |
138 name = ""; | |
139 } else { | 138 } else { |
140 // convert the name to utf8 | 139 // convert the name to utf8 |
141 s = family.string().utf8(); | 140 name = family.string().utf8(); |
142 name = s.data(); | |
143 } | 141 } |
144 | 142 |
145 int style = SkTypeface::kNormal; | 143 int style = SkTypeface::kNormal; |
146 if (fontDescription.weight() >= FontWeightBold) | 144 if (fontDescription.weight() >= FontWeightBold) |
147 style |= SkTypeface::kBold; | 145 style |= SkTypeface::kBold; |
148 if (fontDescription.italic()) | 146 if (fontDescription.italic()) |
149 style |= SkTypeface::kItalic; | 147 style |= SkTypeface::kItalic; |
150 | 148 |
151 SkTypeface* tf = SkTypeface::CreateFromName(name, static_cast<SkTypeface::St
yle>(style)); | 149 return SkTypeface::CreateFromName(name.data(), static_cast<SkTypeface::Style
>(style)); |
| 150 } |
| 151 |
| 152 #if !OS(WINDOWS) |
| 153 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
escription, const AtomicString& family) |
| 154 { |
| 155 CString name; |
| 156 SkTypeface* tf = createTypeface(fontDescription, family, name); |
152 if (!tf) | 157 if (!tf) |
153 return 0; | 158 return 0; |
154 | 159 |
155 FontPlatformData* result = | 160 FontPlatformData* result = new FontPlatformData(tf, |
156 new FontPlatformData(tf, | 161 name.data(), |
157 name, | 162 fontDescription.computedSize(), |
158 fontDescription.computedSize(), | 163 fontDescription.weight() >= FontWeightBold && !tf->isBold(), |
159 (style & SkTypeface::kBold) && !tf->isBold(), | 164 fontDescription.italic() && !tf->isItalic(), |
160 (style & SkTypeface::kItalic) && !tf->isItalic(), | 165 fontDescription.orientation()); |
161 fontDescription.orientation()); | |
162 tf->unref(); | 166 tf->unref(); |
163 return result; | 167 return result; |
164 } | 168 } |
| 169 #endif // !OS(WINDOWNS) |
165 | 170 |
166 } // namespace WebCore | 171 } // namespace WebCore |
OLD | NEW |