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 FontVariant variantStyle) | 70 uint32_t 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 FontVariant fVariantStyle; | 91 const uint32_t 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 = family.fLanguage; | 166 const SkLanguage& lang = fontFile.fPaintOptions.getLanguage(); |
167 uint32_t variant = family.fVariant; | 167 uint32_t variant = fontFile.fPaintOptions.getFontVariant(); |
168 if (kDefault_FontVariant == variant) { | 168 if (SkPaintOptionsAndroid::kDefault_Variant == variant) { |
169 variant = kCompact_FontVariant | kElegant_FontVariant; | 169 variant = SkPaintOptionsAndroid::kCompact_Variant | |
| 170 SkPaintOptionsAndroid::kElegant_Variant; |
170 } | 171 } |
171 | 172 |
172 // The first specified family name overrides the family name found i
n the font. | 173 // The first specified family name overrides the family name found i
n the font. |
173 // TODO: SkTypeface_AndroidSystem::onCreateFamilyNameIterator should
return | 174 // TODO: SkTypeface_AndroidSystem::onCreateFamilyNameIterator should
return |
174 // all of the specified family names in addition to the names found
in the font. | 175 // all of the specified family names in addition to the names found
in the font. |
175 if (cannonicalFamilyName != NULL) { | 176 if (cannonicalFamilyName != NULL) { |
176 familyName = *cannonicalFamilyName; | 177 familyName = *cannonicalFamilyName; |
177 } | 178 } |
178 | 179 |
179 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem, | 180 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem, |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 const SkFontStyle& style, | 346 const SkFontStyle& style, |
346 const char bpc47[], | 347 const char bpc47[], |
347 uint32_t character) const SK
_OVERRIDE | 348 uint32_t character) const SK
_OVERRIDE |
348 { | 349 { |
349 // The variant 'elegant' is 'not squashed', 'compact' is 'stays in ascen
t/descent'. | 350 // The variant 'elegant' is 'not squashed', 'compact' is 'stays in ascen
t/descent'. |
350 // The variant 'default' means 'compact and elegant'. | 351 // The variant 'default' means 'compact and elegant'. |
351 // As a result, it is not possible to know the variant context from the
font alone. | 352 // As a result, it is not possible to know the variant context from the
font alone. |
352 // TODO: add 'is_elegant' and 'is_compact' bits to 'style' request. | 353 // TODO: add 'is_elegant' and 'is_compact' bits to 'style' request. |
353 | 354 |
354 // For compatibility, try 'elegant' fonts first in fallback. | 355 // For compatibility, try 'elegant' fonts first in fallback. |
355 uint32_t variantMask = kElegant_FontVariant; | 356 uint32_t variantMask = SkPaintOptionsAndroid::kElegant_Variant; |
356 | 357 |
357 // The first time match anything in the mask, second time anything not i
n the mask. | 358 // The first time match anything in the mask, second time anything not i
n the mask. |
358 for (bool maskMatches = true; maskMatches != false; maskMatches = false)
{ | 359 for (bool maskMatches = true; maskMatches != false; maskMatches = false)
{ |
359 SkLanguage lang(bpc47); | 360 SkLanguage lang(bpc47); |
360 // Match against the language, removing a segment each time. | 361 // Match against the language, removing a segment each time. |
361 // The last time through the loop, the language will be empty. | 362 // The last time through the loop, the language will be empty. |
362 // The empty language is special, and matches all languages. | 363 // The empty language is special, and matches all languages. |
363 do { | 364 do { |
364 const SkString& langTag = lang.getTag(); | 365 const SkString& langTag = lang.getTag(); |
365 for (int i = 0; i < fFallbackNameToFamilyMap.count(); ++i) { | 366 for (int i = 0; i < fFallbackNameToFamilyMap.count(); ++i) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", | 528 SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", |
528 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); | 529 gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)
); |
529 } | 530 } |
530 | 531 |
531 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf
, | 532 void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf
, |
532 const char** fontsdir) { | 533 const char** fontsdir) { |
533 *mainconf = gTestMainConfigFile; | 534 *mainconf = gTestMainConfigFile; |
534 *fallbackconf = gTestFallbackConfigFile; | 535 *fallbackconf = gTestFallbackConfigFile; |
535 *fontsdir = gTestFontFilePrefix; | 536 *fontsdir = gTestFontFilePrefix; |
536 } | 537 } |
OLD | NEW |