OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkFontConfigParser_android.h" | 8 #include "SkFontConfigParser_android.h" |
9 #include "SkFontDescriptor.h" | 9 #include "SkFontDescriptor.h" |
10 #include "SkFontHost_FreeType_common.h" | 10 #include "SkFontHost_FreeType_common.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 // For test only. | 37 // For test only. |
38 static const char* gTestMainConfigFile = NULL; | 38 static const char* gTestMainConfigFile = NULL; |
39 static const char* gTestFallbackConfigFile = NULL; | 39 static const char* gTestFallbackConfigFile = NULL; |
40 static const char* gTestFontFilePrefix = NULL; | 40 static const char* gTestFontFilePrefix = NULL; |
41 | 41 |
42 class SkTypeface_Android : public SkTypeface_FreeType { | 42 class SkTypeface_Android : public SkTypeface_FreeType { |
43 public: | 43 public: |
44 SkTypeface_Android(int index, | 44 SkTypeface_Android(int index, |
45 const SkFontStyle& style, | 45 const SkFontStyle& style, |
46 bool isFixedPitch, | 46 bool isFixedPitch, |
47 const SkString familyName) | 47 const SkString& familyName) |
48 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) | 48 : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) |
49 , fIndex(index) | 49 , fIndex(index) |
50 , fFamilyName(familyName) { } | 50 , fFamilyName(familyName) { } |
51 | 51 |
52 protected: | 52 protected: |
53 virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { | 53 virtual void onGetFamilyName(SkString* familyName) const SK_OVERRIDE { |
54 *familyName = fFamilyName; | 54 *familyName = fFamilyName; |
55 } | 55 } |
56 | 56 |
57 int fIndex; | 57 int fIndex; |
58 SkString fFamilyName; | 58 SkString fFamilyName; |
59 | 59 |
60 private: | 60 private: |
61 typedef SkTypeface_FreeType INHERITED; | 61 typedef SkTypeface_FreeType INHERITED; |
62 }; | 62 }; |
63 | 63 |
64 class SkTypeface_AndroidSystem : public SkTypeface_Android { | 64 class SkTypeface_AndroidSystem : public SkTypeface_Android { |
65 public: | 65 public: |
66 SkTypeface_AndroidSystem(const SkString pathName, | 66 SkTypeface_AndroidSystem(const SkString& pathName, |
67 int index, | 67 int index, |
68 const SkFontStyle& style, | 68 const SkFontStyle& style, |
69 bool isFixedPitch, | 69 bool isFixedPitch, |
70 const SkString familyName, | 70 const SkString& familyName, |
71 const SkLanguage& lang, | 71 const SkLanguage& lang, |
72 FontVariant variantStyle) | 72 FontVariant variantStyle) |
73 : INHERITED(index, style, isFixedPitch, familyName) | 73 : INHERITED(index, style, isFixedPitch, familyName) |
74 , fPathName(pathName) | 74 , fPathName(pathName) |
75 , fLang(lang) | 75 , fLang(lang) |
76 , fVariantStyle(variantStyle) { } | 76 , fVariantStyle(variantStyle) { } |
77 | 77 |
78 virtual void onGetFontDescriptor(SkFontDescriptor* desc, | 78 virtual void onGetFontDescriptor(SkFontDescriptor* desc, |
79 bool* serialize) const SK_OVERRIDE { | 79 bool* serialize) const SK_OVERRIDE { |
80 SkASSERT(desc); | 80 SkASSERT(desc); |
(...skipping 14 matching lines...) Expand all Loading... |
95 | 95 |
96 typedef SkTypeface_Android INHERITED; | 96 typedef SkTypeface_Android INHERITED; |
97 }; | 97 }; |
98 | 98 |
99 class SkTypeface_AndroidStream : public SkTypeface_Android { | 99 class SkTypeface_AndroidStream : public SkTypeface_Android { |
100 public: | 100 public: |
101 SkTypeface_AndroidStream(SkStream* stream, | 101 SkTypeface_AndroidStream(SkStream* stream, |
102 int index, | 102 int index, |
103 const SkFontStyle& style, | 103 const SkFontStyle& style, |
104 bool isFixedPitch, | 104 bool isFixedPitch, |
105 const SkString familyName) | 105 const SkString& familyName) |
106 : INHERITED(index, style, isFixedPitch, familyName) | 106 : INHERITED(index, style, isFixedPitch, familyName) |
107 , fStream(SkRef(stream)) { } | 107 , fStream(SkRef(stream)) { } |
108 | 108 |
109 virtual void onGetFontDescriptor(SkFontDescriptor* desc, | 109 virtual void onGetFontDescriptor(SkFontDescriptor* desc, |
110 bool* serialize) const SK_OVERRIDE { | 110 bool* serialize) const SK_OVERRIDE { |
111 SkASSERT(desc); | 111 SkASSERT(desc); |
112 SkASSERT(serialize); | 112 SkASSERT(serialize); |
113 desc->setFamilyName(fFamilyName.c_str()); | 113 desc->setFamilyName(fFamilyName.c_str()); |
114 desc->setFontFileName(NULL); | 114 desc->setFontFileName(NULL); |
115 *serialize = true; | 115 *serialize = true; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 160 |
161 const int ttcIndex = fontFile.fIndex; | 161 const int ttcIndex = fontFile.fIndex; |
162 SkString familyName; | 162 SkString familyName; |
163 SkFontStyle style; | 163 SkFontStyle style; |
164 bool isFixedWidth; | 164 bool isFixedWidth; |
165 if (!scanner.scanFont(stream.get(), ttcIndex, &familyName, &style, &
isFixedWidth)) { | 165 if (!scanner.scanFont(stream.get(), ttcIndex, &familyName, &style, &
isFixedWidth)) { |
166 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, pathNam
e.c_str())); | 166 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, pathNam
e.c_str())); |
167 continue; | 167 continue; |
168 } | 168 } |
169 | 169 |
| 170 if (fontFile.fWeight != 0) { |
| 171 style = SkFontStyle(fontFile.fWeight, style.width(), style.slant
()); |
| 172 } |
| 173 |
170 const SkLanguage& lang = family.fLanguage; | 174 const SkLanguage& lang = family.fLanguage; |
171 uint32_t variant = family.fVariant; | 175 uint32_t variant = family.fVariant; |
172 if (kDefault_FontVariant == variant) { | 176 if (kDefault_FontVariant == variant) { |
173 variant = kCompact_FontVariant | kElegant_FontVariant; | 177 variant = kCompact_FontVariant | kElegant_FontVariant; |
174 } | 178 } |
175 | 179 |
176 // The first specified family name overrides the family name found i
n the font. | 180 // The first specified family name overrides the family name found i
n the font. |
177 // TODO: SkTypeface_AndroidSystem::onCreateFamilyNameIterator should
return | 181 // TODO: SkTypeface_AndroidSystem::onCreateFamilyNameIterator should
return |
178 // all of the specified family names in addition to the names found
in the font. | 182 // all of the specified family names in addition to the names found
in the font. |
179 if (cannonicalFamilyName != NULL) { | 183 if (cannonicalFamilyName != NULL) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 if (score < minScore) { | 228 if (score < minScore) { |
225 closest = fStyles[i]; | 229 closest = fStyles[i]; |
226 minScore = score; | 230 minScore = score; |
227 } | 231 } |
228 } | 232 } |
229 return SkRef(closest); | 233 return SkRef(closest); |
230 } | 234 } |
231 | 235 |
232 private: | 236 private: |
233 SkFontStyle style(int index) { | 237 SkFontStyle style(int index) { |
234 return SkFontStyle(this->weight(index), SkFontStyle::kNormal_Width, | 238 return fStyles[index]->fontStyle(); |
235 this->slant(index)); | |
236 } | |
237 SkFontStyle::Weight weight(int index) { | |
238 if (fStyles[index]->isBold()) return SkFontStyle::kBold_Weight; | |
239 return SkFontStyle::kNormal_Weight; | |
240 } | |
241 SkFontStyle::Slant slant(int index) { | |
242 if (fStyles[index]->isItalic()) return SkFontStyle::kItalic_Slant; | |
243 return SkFontStyle::kUpright_Slant; | |
244 } | 239 } |
245 static int match_score(const SkFontStyle& pattern, const SkFontStyle& candid
ate) { | 240 static int match_score(const SkFontStyle& pattern, const SkFontStyle& candid
ate) { |
246 int score = 0; | 241 int score = 0; |
247 score += abs((pattern.width() - candidate.width()) * 100); | 242 score += abs((pattern.width() - candidate.width()) * 100); |
248 score += abs((pattern.isItalic() == candidate.isItalic()) ? 0 : 1000); | 243 score += abs((pattern.isItalic() == candidate.isItalic()) ? 0 : 1000); |
249 score += abs(pattern.weight() - candidate.weight()); | 244 score += abs(pattern.weight() - candidate.weight()); |
250 return score; | 245 return score; |
251 } | 246 } |
252 | 247 |
253 SkTArray<SkAutoTUnref<SkTypeface_AndroidSystem>, true> fStyles; | 248 SkTArray<SkAutoTUnref<SkTypeface_AndroidSystem>, true> fStyles; |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", | 551 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", |
557 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); | 552 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); |
558 } | 553 } |
559 | 554 |
560 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf
, | 555 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf
, |
561 const char** fontsdir) { | 556 const char** fontsdir) { |
562 *mainconf = gTestMainConfigFile; | 557 *mainconf = gTestMainConfigFile; |
563 *fallbackconf = gTestFallbackConfigFile; | 558 *fallbackconf = gTestFallbackConfigFile; |
564 *fontsdir = gTestFontFilePrefix; | 559 *fontsdir = gTestFontFilePrefix; |
565 } | 560 } |
OLD | NEW |