Chromium Code Reviews| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 62 { | 62 { |
| 63 SkAutoTUnref<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal()); | 63 SkAutoTUnref<SkFontConfigInterface> fci(SkFontConfigInterface::RefGlobal()); |
| 64 SkFontConfigInterface::FontIdentity fontIdentity; | 64 SkFontConfigInterface::FontIdentity fontIdentity; |
| 65 fontIdentity.fID = fontconfigInterfaceId; | 65 fontIdentity.fID = fontconfigInterfaceId; |
| 66 return fci->openStream(fontIdentity); | 66 return fci->openStream(fontIdentity); |
| 67 } | 67 } |
| 68 #endif | 68 #endif |
| 69 | 69 |
| 70 namespace blink { | 70 namespace blink { |
| 71 | 71 |
| 72 static int toSkiaWeight(FontWeight weight) | |
| 73 { | |
| 74 switch (weight) { | |
| 75 case FontWeight100: | |
| 76 return 100; | |
| 77 case FontWeight200: | |
| 78 return 200; | |
| 79 case FontWeight300: | |
| 80 return 300; | |
| 81 case FontWeight400: | |
| 82 return 400; | |
| 83 case FontWeight500: | |
| 84 return 500; | |
| 85 case FontWeight600: | |
| 86 return 600; | |
| 87 case FontWeight700: | |
| 88 return 700; | |
| 89 case FontWeight800: | |
| 90 return 800; | |
| 91 case FontWeight900: | |
| 92 return 900; | |
| 93 } | |
| 94 ASSERT_NOT_REACHED(); | |
| 95 return 400; | |
| 96 } | |
| 97 | |
| 98 static SkFontStyle::Slant toSkiaSlant(FontStyle style) | |
| 99 { | |
| 100 switch (style) { | |
| 101 case FontStyleNormal: | |
| 102 return SkFontStyle::kUpright_Slant; | |
| 103 case FontStyleItalic: | |
| 104 return SkFontStyle::kItalic_Slant; | |
| 105 } | |
| 106 ASSERT_NOT_REACHED(); | |
| 107 return SkFontStyle::kUpright_Slant; | |
| 108 } | |
| 109 | |
| 110 static int toSkiaWidth(FontStretch stretch) | |
| 111 { | |
| 112 return static_cast<int>(stretch); | |
|
eseidel
2015/03/16 23:57:54
I still might add a one-line comment.
| |
| 113 } | |
| 114 | |
| 115 static SkFontStyle toSkiaFontStyle(const FontDescription& fontDescription) | |
| 116 { | |
| 117 return SkFontStyle(toSkiaWeight(fontDescription.weight()), | |
| 118 toSkiaWidth(fontDescription.stretch()), | |
| 119 toSkiaSlant(fontDescription.style())); | |
| 120 } | |
| 121 | |
| 72 void FontCache::platformInit() | 122 void FontCache::platformInit() |
| 73 { | 123 { |
| 74 } | 124 } |
| 75 | 125 |
| 76 PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle( | 126 PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle( |
| 77 const FontDescription& fontDescription, UChar32 character) | 127 const FontDescription& fontDescription, UChar32 character) |
| 78 { | 128 { |
| 79 FontDescription substituteDescription(fontDescription); | 129 FontDescription substituteDescription(fontDescription); |
| 80 substituteDescription.setStyle(FontStyleNormal); | 130 substituteDescription.setStyle(FontStyleNormal); |
| 81 substituteDescription.setWeight(FontWeightNormal); | 131 substituteDescription.setWeight(FontWeightNormal); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 AtomicString family = creationParams.family(); | 233 AtomicString family = creationParams.family(); |
| 184 // If we're creating a fallback font (e.g. "-webkit-monospace"), convert the name into | 234 // If we're creating a fallback font (e.g. "-webkit-monospace"), convert the name into |
| 185 // the fallback name (like "monospace") that fontconfig understands. | 235 // the fallback name (like "monospace") that fontconfig understands. |
| 186 if (!family.length() || family.startsWith("-webkit-")) { | 236 if (!family.length() || family.startsWith("-webkit-")) { |
| 187 name = getFallbackFontFamily(fontDescription).string().utf8(); | 237 name = getFallbackFontFamily(fontDescription).string().utf8(); |
| 188 } else { | 238 } else { |
| 189 // convert the name to utf8 | 239 // convert the name to utf8 |
| 190 name = family.utf8(); | 240 name = family.utf8(); |
| 191 } | 241 } |
| 192 | 242 |
| 193 int style = SkTypeface::kNormal; | 243 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); |
| 194 if (fontDescription.weight() >= FontWeight600) | 244 return adoptRef(fm->matchFamilyStyle(name.data(), toSkiaFontStyle(fontDescri ption))); |
| 195 style |= SkTypeface::kBold; | |
| 196 if (fontDescription.style()) | |
| 197 style |= SkTypeface::kItalic; | |
| 198 | |
| 199 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of | |
| 200 // CreateFromName on all platforms. | |
| 201 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa ce::Style>(style))); | |
| 202 } | 245 } |
| 203 | 246 |
| 204 #if !OS(WIN) | 247 #if !OS(WIN) |
| 205 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const FontFaceCreationParams& creationParams, float fontSize) | 248 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD escription, const FontFaceCreationParams& creationParams, float fontSize) |
| 206 { | 249 { |
| 207 CString name; | 250 CString name; |
| 208 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ; | 251 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name)) ; |
| 209 if (!tf) | 252 if (!tf) |
| 210 return 0; | 253 return 0; |
| 211 | 254 |
| 212 FontPlatformData* result = new FontPlatformData(tf, | 255 FontPlatformData* result = new FontPlatformData(tf, |
| 213 name.data(), | 256 name.data(), |
| 214 fontSize, | 257 fontSize, |
| 215 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(), | 258 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc ription.isSyntheticBold(), |
| 216 (fontDescription.style() && !tf->isItalic()) || fontDescription.isSynthe ticItalic(), | 259 (fontDescription.style() && !tf->isItalic()) || fontDescription.isSynthe ticItalic(), |
| 217 fontDescription.orientation(), | 260 fontDescription.orientation(), |
| 218 fontDescription.useSubpixelPositioning()); | 261 fontDescription.useSubpixelPositioning()); |
| 219 return result; | 262 return result; |
| 220 } | 263 } |
| 221 #endif // !OS(WIN) | 264 #endif // !OS(WIN) |
| 222 | 265 |
| 223 } // namespace blink | 266 } // namespace blink |
| OLD | NEW |