OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 Google Inc. All rights reserved. | 2 * Copyright (c) 2011 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 164 } |
165 | 165 |
166 int style = SkTypeface::kNormal; | 166 int style = SkTypeface::kNormal; |
167 if (fontDescription.weight() >= FontWeightBold) | 167 if (fontDescription.weight() >= FontWeightBold) |
168 style |= SkTypeface::kBold; | 168 style |= SkTypeface::kBold; |
169 if (fontDescription.italic()) | 169 if (fontDescription.italic()) |
170 style |= SkTypeface::kItalic; | 170 style |= SkTypeface::kItalic; |
171 | 171 |
172 SkTypeface* typeface = 0; | 172 SkTypeface* typeface = 0; |
173 FontPlatformData* result = 0; | 173 FontPlatformData* result = 0; |
174 FallbackScripts fallbackScript = SkGetFallbackScriptFromID(name); | 174 typeface = SkTypeface::CreateFromName(name, SkTypeface::kNormal); |
175 if (SkTypeface_ValidScript(fallbackScript)) { | |
176 typeface = SkCreateTypefaceForScript(fallbackScript); | |
177 if (typeface) | |
178 result = new FontPlatformData(typeface, name, fontDescription.comput
edSize(), | |
179 (style & SkTypeface::kBold) && !typefa
ce->isBold(), | |
180 (style & SkTypeface::kItalic) && !type
face->isItalic(), | |
181 fontDescription.orientation()); | |
182 } else { | |
183 typeface = SkTypeface::CreateFromName(name, SkTypeface::kNormal); | |
184 | 175 |
185 // CreateFromName always returns a typeface, falling back to a default f
ont | 176 // CreateFromName always returns a typeface, falling back to a default font |
186 // if the one requested could not be found. Calling Equal() with a null | 177 // if the one requested could not be found. Calling Equal() with a null |
187 // pointer will compare the returned font against the default, with the | 178 // pointer will compare the returned font against the default, with the |
188 // caveat that the default is always of normal style. When that happens, | 179 // caveat that the default is always of normal style. When that happens, |
189 // ignore the default font and allow WebCore to provide the next font on
the | 180 // ignore the default font and allow WebCore to provide the next font on the |
190 // CSS fallback list. The only exception to this occurs when the family
name | 181 // CSS fallback list. The only exception to this occurs when the family name |
191 // is a commonly used generic family, which is the case when called by | 182 // is a commonly used generic family, which is the case when called by |
192 // getSimilarFontPlatformData() or getLastResortFallbackFont(). In that
case | 183 // getSimilarFontPlatformData() or getLastResortFallbackFont(). In that case |
193 // the default font is an acceptable result. | 184 // the default font is an acceptable result. |
194 | 185 |
195 if (!SkTypeface::Equal(typeface, 0) || isFallbackFamily(family.string())
) { | 186 if (!SkTypeface::Equal(typeface, 0) || isFallbackFamily(family.string())) { |
196 // We had to use normal styling to see if this was a default font. I
f | 187 // We had to use normal styling to see if this was a default font. If |
197 // we need bold or italic, replace with the corrected typeface. | 188 // we need bold or italic, replace with the corrected typeface. |
198 if (style != SkTypeface::kNormal) { | 189 if (style != SkTypeface::kNormal) { |
199 typeface->unref(); | 190 typeface->unref(); |
200 typeface = SkTypeface::CreateFromName(name, static_cast<SkTypefa
ce::Style>(style)); | 191 typeface = SkTypeface::CreateFromName(name, static_cast<SkTypeface::
Style>(style)); |
201 } | |
202 result = new FontPlatformData(typeface, name, fontDescription.comput
edSize(), | |
203 (style & SkTypeface::kBold) && !typefa
ce->isBold(), | |
204 (style & SkTypeface::kItalic) && !type
face->isItalic(), | |
205 fontDescription.orientation()); | |
206 } | 192 } |
| 193 result = new FontPlatformData(typeface, name, fontDescription.computedSi
ze(), |
| 194 (style & SkTypeface::kBold) && !typeface->
isBold(), |
| 195 (style & SkTypeface::kItalic) && !typeface
->isItalic(), |
| 196 fontDescription.orientation()); |
207 } | 197 } |
208 | 198 |
209 SkSafeUnref(typeface); | 199 SkSafeUnref(typeface); |
210 return result; | 200 return result; |
211 } | 201 } |
212 | 202 |
213 } // namespace WebCore | 203 } // namespace WebCore |
OLD | NEW |