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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 }; | 54 }; |
55 | 55 |
56 class SkTypeface_AndroidSystem : public SkTypeface_Android { | 56 class SkTypeface_AndroidSystem : public SkTypeface_Android { |
57 public: | 57 public: |
58 SkTypeface_AndroidSystem(const SkString pathName, | 58 SkTypeface_AndroidSystem(const SkString pathName, |
59 int index, | 59 int index, |
60 Style style, | 60 Style style, |
61 bool isFixedPitch, | 61 bool isFixedPitch, |
62 const SkString familyName, | 62 const SkString familyName, |
63 const SkLanguage& lang, | 63 const SkLanguage& lang, |
64 uint32_t variantStyle) | 64 FontVariant variantStyle) |
65 : INHERITED(index, style, isFixedPitch, familyName) | 65 : INHERITED(index, style, isFixedPitch, familyName) |
66 , fPathName(pathName) | 66 , fPathName(pathName) |
67 , fLang(lang) | 67 , fLang(lang) |
68 , fVariantStyle(variantStyle) { } | 68 , fVariantStyle(variantStyle) { } |
69 | 69 |
70 virtual void onGetFontDescriptor(SkFontDescriptor* desc, | 70 virtual void onGetFontDescriptor(SkFontDescriptor* desc, |
71 bool* serialize) const SK_OVERRIDE { | 71 bool* serialize) const SK_OVERRIDE { |
72 SkASSERT(desc); | 72 SkASSERT(desc); |
73 SkASSERT(serialize); | 73 SkASSERT(serialize); |
74 desc->setFamilyName(fFamilyName.c_str()); | 74 desc->setFamilyName(fFamilyName.c_str()); |
75 desc->setFontFileName(fPathName.c_str()); | 75 desc->setFontFileName(fPathName.c_str()); |
76 *serialize = false; | 76 *serialize = false; |
77 } | 77 } |
78 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { | 78 virtual SkStream* onOpenStream(int* ttcIndex) const SK_OVERRIDE { |
79 *ttcIndex = fIndex; | 79 *ttcIndex = fIndex; |
80 return SkStream::NewFromFile(fPathName.c_str()); | 80 return SkStream::NewFromFile(fPathName.c_str()); |
81 } | 81 } |
82 | 82 |
83 const SkString fPathName; | 83 const SkString fPathName; |
84 const SkLanguage fLang; | 84 const SkLanguage fLang; |
85 const uint32_t fVariantStyle; | 85 const FontVariant fVariantStyle; |
86 | 86 |
87 typedef SkTypeface_Android INHERITED; | 87 typedef SkTypeface_Android INHERITED; |
88 }; | 88 }; |
89 | 89 |
90 class SkTypeface_AndroidStream : public SkTypeface_Android { | 90 class SkTypeface_AndroidStream : public SkTypeface_Android { |
91 public: | 91 public: |
92 SkTypeface_AndroidStream(SkStream* stream, | 92 SkTypeface_AndroidStream(SkStream* stream, |
93 int index, | 93 int index, |
94 Style style, | 94 Style style, |
95 bool isFixedPitch, | 95 bool isFixedPitch, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 const int ttcIndex = fontFile.fIndex; | 146 const int ttcIndex = fontFile.fIndex; |
147 SkString familyName; | 147 SkString familyName; |
148 SkTypeface::Style style; | 148 SkTypeface::Style style; |
149 bool isFixedWidth; | 149 bool isFixedWidth; |
150 if (!SkTypeface_FreeType::ScanFont(stream.get(), ttcIndex, | 150 if (!SkTypeface_FreeType::ScanFont(stream.get(), ttcIndex, |
151 &familyName, &style, &isFixedWidt
h)) { | 151 &familyName, &style, &isFixedWidt
h)) { |
152 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, pathNam
e.c_str())); | 152 DEBUG_FONT(("---- SystemFonts[%d] file=%s (INVALID)", i, pathNam
e.c_str())); |
153 continue; | 153 continue; |
154 } | 154 } |
155 | 155 |
156 const SkLanguage& lang = fontFile.fPaintOptions.getLanguage(); | 156 const SkLanguage& lang = family.fLanguage; |
157 uint32_t variant = fontFile.fPaintOptions.getFontVariant(); | 157 uint32_t variant = family.fVariant; |
158 if (SkPaintOptionsAndroid::kDefault_Variant == variant) { | 158 if (kDefault_FontVariant == variant) { |
159 variant = SkPaintOptionsAndroid::kCompact_Variant | | 159 variant = kCompact_FontVariant | kElegant_FontVariant; |
160 SkPaintOptionsAndroid::kElegant_Variant; | |
161 } | 160 } |
162 | 161 |
163 // The first specified family name overrides the family name found i
n the font. | 162 // The first specified family name overrides the family name found i
n the font. |
164 // TODO: SkTypeface_AndroidSystem::onCreateFamilyNameIterator should
return | 163 // TODO: SkTypeface_AndroidSystem::onCreateFamilyNameIterator should
return |
165 // all of the specified family names in addition to the names found
in the font. | 164 // all of the specified family names in addition to the names found
in the font. |
166 if (cannonicalFamilyName != NULL) { | 165 if (cannonicalFamilyName != NULL) { |
167 familyName = *cannonicalFamilyName; | 166 familyName = *cannonicalFamilyName; |
168 } | 167 } |
169 | 168 |
170 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem, | 169 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem, |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 const SkFontStyle& style, | 327 const SkFontStyle& style, |
329 const char bpc47[], | 328 const char bpc47[], |
330 uint32_t character) const SK
_OVERRIDE | 329 uint32_t character) const SK
_OVERRIDE |
331 { | 330 { |
332 // The variant 'elegant' is 'not squashed', 'compact' is 'stays in ascen
t/descent'. | 331 // The variant 'elegant' is 'not squashed', 'compact' is 'stays in ascen
t/descent'. |
333 // The variant 'default' means 'compact and elegant'. | 332 // The variant 'default' means 'compact and elegant'. |
334 // As a result, it is not possible to know the variant context from the
font alone. | 333 // As a result, it is not possible to know the variant context from the
font alone. |
335 // TODO: add 'is_elegant' and 'is_compact' bits to 'style' request. | 334 // TODO: add 'is_elegant' and 'is_compact' bits to 'style' request. |
336 | 335 |
337 // For compatibility, try 'elegant' fonts first in fallback. | 336 // For compatibility, try 'elegant' fonts first in fallback. |
338 uint32_t variantMask = SkPaintOptionsAndroid::kElegant_Variant; | 337 uint32_t variantMask = kElegant_FontVariant; |
339 | 338 |
340 // The first time match anything in the mask, second time anything not i
n the mask. | 339 // The first time match anything in the mask, second time anything not i
n the mask. |
341 for (bool maskMatches = true; maskMatches != false; maskMatches = false)
{ | 340 for (bool maskMatches = true; maskMatches != false; maskMatches = false)
{ |
342 SkLanguage lang(bpc47); | 341 SkLanguage lang(bpc47); |
343 // Match against the language, removing a segment each time. | 342 // Match against the language, removing a segment each time. |
344 // The last time through the loop, the language will be empty. | 343 // The last time through the loop, the language will be empty. |
345 // The empty language is special, and matches all languages. | 344 // The empty language is special, and matches all languages. |
346 do { | 345 do { |
347 const SkString& langTag = lang.getTag(); | 346 const SkString& langTag = lang.getTag(); |
348 for (int i = 0; i < fFallbackNameToFamilyMap.count(); ++i) { | 347 for (int i = 0; i < fFallbackNameToFamilyMap.count(); ++i) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 } | 481 } |
483 | 482 |
484 typedef SkFontMgr INHERITED; | 483 typedef SkFontMgr INHERITED; |
485 }; | 484 }; |
486 | 485 |
487 /////////////////////////////////////////////////////////////////////////////// | 486 /////////////////////////////////////////////////////////////////////////////// |
488 | 487 |
489 SkFontMgr* SkFontMgr::Factory() { | 488 SkFontMgr* SkFontMgr::Factory() { |
490 return SkNEW(SkFontMgr_Android); | 489 return SkNEW(SkFontMgr_Android); |
491 } | 490 } |
OLD | NEW |