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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 }; | 60 }; |
61 | 61 |
62 class SkTypeface_AndroidSystem : public SkTypeface_Android { | 62 class SkTypeface_AndroidSystem : public SkTypeface_Android { |
63 public: | 63 public: |
64 SkTypeface_AndroidSystem(const SkString pathName, | 64 SkTypeface_AndroidSystem(const SkString pathName, |
65 int index, | 65 int index, |
66 Style style, | 66 Style style, |
67 bool isFixedPitch, | 67 bool isFixedPitch, |
68 const SkString familyName, | 68 const SkString familyName, |
69 const SkLanguage& lang, | 69 const SkLanguage& lang, |
70 uint32_t variantStyle) | 70 FontVariant variantStyle) |
71 : INHERITED(index, style, isFixedPitch, familyName) | 71 : INHERITED(index, style, isFixedPitch, familyName) |
72 , fPathName(pathName) | 72 , fPathName(pathName) |
73 , fLang(lang) | 73 , fLang(lang) |
74 , fVariantStyle(variantStyle) { } | 74 , fVariantStyle(variantStyle) { } |
75 | 75 |
76 virtual void onGetFontDescriptor(SkFontDescriptor* desc, | 76 virtual void onGetFontDescriptor(SkFontDescriptor* desc, |
77 bool* serialize) const SK_OVERRIDE { | 77 bool* serialize) const SK_OVERRIDE { |
78 SkASSERT(desc); | 78 SkASSERT(desc); |
79 SkASSERT(serialize); | 79 SkASSERT(serialize); |
80 desc->setFamilyName(fFamilyName.c_str()); | 80 desc->setFamilyName(fFamilyName.c_str()); |
81 desc->setFontFileName(fPathName.c_str()); | 81 desc->setFontFileName(fPathName.c_str()); |
82 *serialize = false; | 82 *serialize = false; |
83 } | 83 } |
84 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { | 84 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
85 *ttcIndex = fIndex; | 85 *ttcIndex = fIndex; |
86 return SkStream::NewFromFile(fPathName.c_str()); | 86 return SkStream::NewFromFile(fPathName.c_str()); |
87 } | 87 } |
88 | 88 |
89 const SkString fPathName; | 89 const SkString fPathName; |
90 const SkLanguage fLang; | 90 const SkLanguage fLang; |
91 const uint32_t fVariantStyle; | 91 const FontVariant fVariantStyle; |
92 | 92 |
93 typedef SkTypeface_Android INHERITED; | 93 typedef SkTypeface_Android INHERITED; |
94 }; | 94 }; |
95 | 95 |
96 class SkTypeface_AndroidStream : public SkTypeface_Android { | 96 class SkTypeface_AndroidStream : public SkTypeface_Android { |
97 public: | 97 public: |
98 SkTypeface_AndroidStream(SkStream* stream, | 98 SkTypeface_AndroidStream(SkStream* stream, |
99 int index, | 99 int index, |
100 Style style, | 100 Style style, |
101 bool isFixedPitch, | 101 bool isFixedPitch, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 const int ttcIndex = fontFile.fIndex; | 156 const int ttcIndex = fontFile.fIndex; |
157 SkString familyName; | 157 SkString familyName; |
158 SkTypeface::Style style; | 158 SkTypeface::Style style; |
159 bool isFixedWidth; | 159 bool isFixedWidth; |
160 if (!SkTypeface_FreeType::ScanFont(stream.get(), ttcIndex, | 160 if (!SkTypeface_FreeType::ScanFont(stream.get(), ttcIndex, |
161 &familyName, &style, &isFixedWidt
h)) { | 161 &familyName, &style, &isFixedWidt
h)) { |
162 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, pathNam
e.c_str())); | 162 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, pathNam
e.c_str())); |
163 continue; | 163 continue; |
164 } | 164 } |
165 | 165 |
166 const SkLanguage& lang = fontFile.fPaintOptions.getLanguage(); | 166 const SkLanguage& lang = family.fLanguage; |
167 uint32_t variant = fontFile.fPaintOptions.getFontVariant(); | 167 uint32_t variant = family.fVariant; |
168 if (SkPaintOptionsAndroid::kDefault_Variant == variant) { | 168 if (kDefault_FontVariant == variant) { |
169 variant = SkPaintOptionsAndroid::kCompact_Variant | | 169 variant = kCompact_FontVariant | kElegant_FontVariant; |
170 SkPaintOptionsAndroid::kElegant_Variant; | |
171 } | 170 } |
172 | 171 |
173 // The first specified family name overrides the family name found i
n the font. | 172 // The first specified family name overrides the family name found i
n the font. |
174 // TODO: SkTypeface_AndroidSystem::onCreateFamilyNameIterator should
return | 173 // TODO: SkTypeface_AndroidSystem::onCreateFamilyNameIterator should
return |
175 // all of the specified family names in addition to the names found
in the font. | 174 // all of the specified family names in addition to the names found
in the font. |
176 if (cannonicalFamilyName != NULL) { | 175 if (cannonicalFamilyName != NULL) { |
177 familyName = *cannonicalFamilyName; | 176 familyName = *cannonicalFamilyName; |
178 } | 177 } |
179 | 178 |
180 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem, | 179 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 const SkFontStyle& style, | 345 const SkFontStyle& style, |
347 const char bpc47[], | 346 const char bpc47[], |
348 uint32_t character) const SK
_OVERRIDE | 347 uint32_t character) const SK
_OVERRIDE |
349 { | 348 { |
350 // The variant 'elegant' is 'not squashed', 'compact' is 'stays in ascen
t/descent'. | 349 // The variant 'elegant' is 'not squashed', 'compact' is 'stays in ascen
t/descent'. |
351 // The variant 'default' means 'compact and elegant'. | 350 // The variant 'default' means 'compact and elegant'. |
352 // As a result, it is not possible to know the variant context from the
font alone. | 351 // As a result, it is not possible to know the variant context from the
font alone. |
353 // TODO: add 'is_elegant' and 'is_compact' bits to 'style' request. | 352 // TODO: add 'is_elegant' and 'is_compact' bits to 'style' request. |
354 | 353 |
355 // For compatibility, try 'elegant' fonts first in fallback. | 354 // For compatibility, try 'elegant' fonts first in fallback. |
356 uint32_t variantMask = SkPaintOptionsAndroid::kElegant_Variant; | 355 uint32_t variantMask = kElegant_FontVariant; |
357 | 356 |
358 // The first time match anything in the mask, second time anything not i
n the mask. | 357 // The first time match anything in the mask, second time anything not i
n the mask. |
359 for (bool maskMatches = true; maskMatches != false; maskMatches = false)
{ | 358 for (bool maskMatches = true; maskMatches != false; maskMatches = false)
{ |
360 SkLanguage lang(bpc47); | 359 SkLanguage lang(bpc47); |
361 // Match against the language, removing a segment each time. | 360 // Match against the language, removing a segment each time. |
362 // The last time through the loop, the language will be empty. | 361 // The last time through the loop, the language will be empty. |
363 // The empty language is special, and matches all languages. | 362 // The empty language is special, and matches all languages. |
364 do { | 363 do { |
365 const SkString& langTag = lang.getTag(); | 364 const SkString& langTag = lang.getTag(); |
366 for (int i = 0; i < fFallbackNameToFamilyMap.count(); ++i) { | 365 for (int i = 0; i < fFallbackNameToFamilyMap.count(); ++i) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", | 527 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", |
529 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); | 528 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); |
530 } | 529 } |
531 | 530 |
532 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf
, | 531 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf
, |
533 const char** fontsdir) { | 532 const char** fontsdir) { |
534 *mainconf = gTestMainConfigFile; | 533 *mainconf = gTestMainConfigFile; |
535 *fallbackconf = gTestFallbackConfigFile; | 534 *fallbackconf = gTestFallbackConfigFile; |
536 *fontsdir = gTestFontFilePrefix; | 535 *fontsdir = gTestFontFilePrefix; |
537 } | 536 } |
OLD | NEW |