| 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 SkFontStyle::kThin_Weight; |
| 77 case FontWeight200: |
| 78 return SkFontStyle::kExtraLight_Weight; |
| 79 case FontWeight300: |
| 80 return SkFontStyle::kLight_Weight; |
| 81 case FontWeight400: |
| 82 return SkFontStyle::kNormal_Weight; |
| 83 case FontWeight500: |
| 84 return SkFontStyle::kMedium_Weight; |
| 85 case FontWeight600: |
| 86 return SkFontStyle::kSemiBold_Weight; |
| 87 case FontWeight700: |
| 88 return SkFontStyle::kBold_Weight; |
| 89 case FontWeight800: |
| 90 return SkFontStyle::kExtraBold_Weight; |
| 91 case FontWeight900: |
| 92 return SkFontStyle::kBlack_Weight; |
| 93 } |
| 94 ASSERT_NOT_REACHED(); |
| 95 return SkFontStyle::kNormal_Weight; |
| 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 // Numeric values matching OS/2 & Windows Metrics usWidthClass table. |
| 113 // https://www.microsoft.com/typography/otspec/os2.htm |
| 114 return static_cast<int>(stretch); |
| 115 } |
| 116 |
| 117 static SkFontStyle toSkiaFontStyle(const FontDescription& fontDescription) |
| 118 { |
| 119 return SkFontStyle(toSkiaWeight(fontDescription.weight()), |
| 120 toSkiaWidth(fontDescription.stretch()), |
| 121 toSkiaSlant(fontDescription.style())); |
| 122 } |
| 123 |
| 72 void FontCache::platformInit() | 124 void FontCache::platformInit() |
| 73 { | 125 { |
| 74 } | 126 } |
| 75 | 127 |
| 76 PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle( | 128 PassRefPtr<SimpleFontData> FontCache::fallbackOnStandardFontStyle( |
| 77 const FontDescription& fontDescription, UChar32 character) | 129 const FontDescription& fontDescription, UChar32 character) |
| 78 { | 130 { |
| 79 FontDescription substituteDescription(fontDescription); | 131 FontDescription substituteDescription(fontDescription); |
| 80 substituteDescription.setStyle(FontStyleNormal); | 132 substituteDescription.setStyle(FontStyleNormal); |
| 81 substituteDescription.setWeight(FontWeightNormal); | 133 substituteDescription.setWeight(FontWeightNormal); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 AtomicString family = creationParams.family(); | 235 AtomicString family = creationParams.family(); |
| 184 // If we're creating a fallback font (e.g. "-webkit-monospace"), convert the
name into | 236 // If we're creating a fallback font (e.g. "-webkit-monospace"), convert the
name into |
| 185 // the fallback name (like "monospace") that fontconfig understands. | 237 // the fallback name (like "monospace") that fontconfig understands. |
| 186 if (!family.length() || family.startsWith("-webkit-")) { | 238 if (!family.length() || family.startsWith("-webkit-")) { |
| 187 name = getFallbackFontFamily(fontDescription).string().utf8(); | 239 name = getFallbackFontFamily(fontDescription).string().utf8(); |
| 188 } else { | 240 } else { |
| 189 // convert the name to utf8 | 241 // convert the name to utf8 |
| 190 name = family.utf8(); | 242 name = family.utf8(); |
| 191 } | 243 } |
| 192 | 244 |
| 193 int style = SkTypeface::kNormal; | 245 SkFontStyle style = toSkiaFontStyle(fontDescription); |
| 246 RefPtr<SkFontMgr> fm = adoptRef(SkFontMgr::RefDefault()); |
| 247 RefPtr<SkTypeface> typeface = adoptRef(fm->matchFamilyStyle(name.data(), sty
le)); |
| 248 if (typeface) |
| 249 return typeface.release(); |
| 250 |
| 251 int legacyStyle = SkTypeface::kNormal; |
| 194 if (fontDescription.weight() >= FontWeight600) | 252 if (fontDescription.weight() >= FontWeight600) |
| 195 style |= SkTypeface::kBold; | 253 legacyStyle |= SkTypeface::kBold; |
| 196 if (fontDescription.style()) | 254 if (fontDescription.style()) |
| 197 style |= SkTypeface::kItalic; | 255 legacyStyle |= SkTypeface::kItalic; |
| 198 | 256 |
| 199 // FIXME: Use m_fontManager, SkFontStyle and matchFamilyStyle instead of | 257 // FIXME: Use fm, SkFontStyle and matchFamilyStyle instead of this legacy |
| 200 // CreateFromName on all platforms. | 258 // API. To make this work, we need to understand the extra fallback behavior |
| 201 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa
ce::Style>(style))); | 259 // in CreateFromName. |
| 260 return adoptRef(SkTypeface::CreateFromName(name.data(), static_cast<SkTypefa
ce::Style>(legacyStyle))); |
| 202 } | 261 } |
| 203 | 262 |
| 204 #if !OS(WIN) | 263 #if !OS(WIN) |
| 205 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
escription, const FontFaceCreationParams& creationParams, float fontSize) | 264 FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontD
escription, const FontFaceCreationParams& creationParams, float fontSize) |
| 206 { | 265 { |
| 207 CString name; | 266 CString name; |
| 208 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name))
; | 267 RefPtr<SkTypeface> tf(createTypeface(fontDescription, creationParams, name))
; |
| 209 if (!tf) | 268 if (!tf) |
| 210 return 0; | 269 return 0; |
| 211 | 270 |
| 212 FontPlatformData* result = new FontPlatformData(tf, | 271 FontPlatformData* result = new FontPlatformData(tf, |
| 213 name.data(), | 272 name.data(), |
| 214 fontSize, | 273 fontSize, |
| 215 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc
ription.isSyntheticBold(), | 274 (fontDescription.weight() >= FontWeight600 && !tf->isBold()) || fontDesc
ription.isSyntheticBold(), |
| 216 (fontDescription.style() && !tf->isItalic()) || fontDescription.isSynthe
ticItalic(), | 275 (fontDescription.style() && !tf->isItalic()) || fontDescription.isSynthe
ticItalic(), |
| 217 fontDescription.orientation(), | 276 fontDescription.orientation(), |
| 218 fontDescription.useSubpixelPositioning()); | 277 fontDescription.useSubpixelPositioning()); |
| 219 return result; | 278 return result; |
| 220 } | 279 } |
| 221 #endif // !OS(WIN) | 280 #endif // !OS(WIN) |
| 222 | 281 |
| 223 } // namespace blink | 282 } // namespace blink |
| OLD | NEW |