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 "SkFixed.h" | 8 #include "SkFixed.h" |
9 #include "SkFontDescriptor.h" | 9 #include "SkFontDescriptor.h" |
10 #include "SkFontHost_FreeType_common.h" | 10 #include "SkFontHost_FreeType_common.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 (axisDefinition.fTag ) & 0xFF, | 197 (axisDefinition.fTag ) & 0xFF, |
198 SkFixedToDouble(axisSpecified.fValue), | 198 SkFixedToDouble(axisSpecified.fValue), |
199 SkFixedToDouble(axisValues[i]))); | 199 SkFixedToDouble(axisValues[i]))); |
200 } | 200 } |
201 break; | 201 break; |
202 } | 202 } |
203 } | 203 } |
204 // TODO: warn on defaulted axis? | 204 // TODO: warn on defaulted axis? |
205 } | 205 } |
206 | 206 |
207 SkDEBUGCODE ( | 207 SkDEBUGCODE( |
208 // Check for axis specified, but not matched in font. | 208 // Check for axis specified, but not matched in font. |
209 for (int i = 0; i < fontFile.fAxes.count(); ++i) { | 209 for (int i = 0; i < fontFile.fAxes.count(); ++i) { |
210 SkFourByteTag skTag = fontFile.fAxes[i].fTag; | 210 SkFourByteTag skTag = fontFile.fAxes[i].fTag; |
211 bool found = false; | 211 bool found = false; |
212 for (int j = 0; j < axisDefinitions.count(); ++j) { | 212 for (int j = 0; j < axisDefinitions.count(); ++j) { |
213 if (skTag == axisDefinitions[j].fTag) { | 213 if (skTag == axisDefinitions[j].fTag) { |
214 found = true; | 214 found = true; |
215 break; | 215 break; |
| 216 } |
216 } | 217 } |
217 } | 218 if (!found) { |
218 if (!found) { | 219 SkDEBUGF(("Requested font axis not found: %s '%c%c%c
%c'\n", |
219 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\
n", | 220 familyName.c_str(), (skTag >> 24) & 0xFF, |
220 familyName.c_str(), | 221 (skTag >> 16) & 0xFF, (skTag >> 8) & 0xFF,
(skTag)&0xFF)); |
221 (skTag >> 24) & 0xFF, | 222 } |
222 (skTag >> 16) & 0xFF, | 223 }) |
223 (skTag >> 8) & 0xFF, | |
224 (skTag ) & 0xFF)); | |
225 } | |
226 } | |
227 ) | |
228 | 224 |
229 fStyles.push_back().reset(SkNEW_ARGS(SkTypeface_AndroidSystem, | 225 fStyles.push_back().reset(new SkTypeface_AndroidSystem( |
230 (pathName, ttcIndex, | 226 pathName, ttcIndex, axisValues.get(), axisDefinition
s.count(), style, |
231 axisValues.get(), axisDefiniti
ons.count(), | 227 isFixedWidth, familyName, lang, variant)); |
232 style, isFixedWidth, familyNam
e, | |
233 lang, variant))); | |
234 } | 228 } |
235 } | 229 } |
236 | 230 |
237 int count() override { | 231 int count() override { |
238 return fStyles.count(); | 232 return fStyles.count(); |
239 } | 233 } |
240 void getStyle(int index, SkFontStyle* style, SkString* name) override { | 234 void getStyle(int index, SkFontStyle* style, SkString* name) override { |
241 if (index < 0 || fStyles.count() <= index) { | 235 if (index < 0 || fStyles.count() <= index) { |
242 return; | 236 return; |
243 } | 237 } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 | 463 |
470 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { | 464 SkTypeface* onCreateFromStream(SkStreamAsset* bareStream, int ttcIndex) cons
t override { |
471 SkAutoTDelete<SkStreamAsset> stream(bareStream); | 465 SkAutoTDelete<SkStreamAsset> stream(bareStream); |
472 bool isFixedPitch; | 466 bool isFixedPitch; |
473 SkFontStyle style; | 467 SkFontStyle style; |
474 SkString name; | 468 SkString name; |
475 if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, N
ULL)) { | 469 if (!fScanner.scanFont(stream, ttcIndex, &name, &style, &isFixedPitch, N
ULL)) { |
476 return NULL; | 470 return NULL; |
477 } | 471 } |
478 SkFontData* data(new SkFontData(stream.detach(), ttcIndex, NULL, 0)); | 472 SkFontData* data(new SkFontData(stream.detach(), ttcIndex, NULL, 0)); |
479 return SkNEW_ARGS(SkTypeface_AndroidStream, (data, style, isFixedPitch,
name)); | 473 return new SkTypeface_AndroidStream(data, style, isFixedPitch, name); |
480 } | 474 } |
481 | 475 |
482 SkTypeface* onCreateFromFontData(SkFontData* data) const override { | 476 SkTypeface* onCreateFromFontData(SkFontData* data) const override { |
483 SkStreamAsset* stream(data->getStream()); | 477 SkStreamAsset* stream(data->getStream()); |
484 bool isFixedPitch; | 478 bool isFixedPitch; |
485 SkFontStyle style; | 479 SkFontStyle style; |
486 SkString name; | 480 SkString name; |
487 if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixed
Pitch, NULL)) { | 481 if (!fScanner.scanFont(stream, data->getIndex(), &name, &style, &isFixed
Pitch, NULL)) { |
488 return NULL; | 482 return NULL; |
489 } | 483 } |
490 return SkNEW_ARGS(SkTypeface_AndroidStream, (data, style, isFixedPitch,
name)); | 484 return new SkTypeface_AndroidStream(data, style, isFixedPitch, name); |
491 } | 485 } |
492 | 486 |
493 | 487 |
494 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], | 488 virtual SkTypeface* onLegacyCreateTypeface(const char familyName[], |
495 unsigned styleBits) const overrid
e { | 489 unsigned styleBits) const overrid
e { |
496 SkFontStyle style = SkFontStyle(styleBits); | 490 SkFontStyle style = SkFontStyle(styleBits); |
497 | 491 |
498 if (familyName) { | 492 if (familyName) { |
499 // On Android, we must return NULL when we can't find the requested | 493 // On Android, we must return NULL when we can't find the requested |
500 // named typeface so that the system/app can provide their own recov
ery | 494 // named typeface so that the system/app can provide their own recov
ery |
(...skipping 23 matching lines...) Expand all Loading... |
524 SkTDArray<NameToFamily>* nameToFamily = &fNameToFamilyMap; | 518 SkTDArray<NameToFamily>* nameToFamily = &fNameToFamilyMap; |
525 if (family.fIsFallbackFont) { | 519 if (family.fIsFallbackFont) { |
526 nameToFamily = &fFallbackNameToFamilyMap; | 520 nameToFamily = &fFallbackNameToFamilyMap; |
527 | 521 |
528 if (0 == family.fNames.count()) { | 522 if (0 == family.fNames.count()) { |
529 SkString& fallbackName = family.fNames.push_back(); | 523 SkString& fallbackName = family.fNames.push_back(); |
530 fallbackName.printf("%.2x##fallback", i); | 524 fallbackName.printf("%.2x##fallback", i); |
531 } | 525 } |
532 } | 526 } |
533 | 527 |
534 SkFontStyleSet_Android* newSet = | 528 SkFontStyleSet_Android* newSet = new SkFontStyleSet_Android(family,
fScanner); |
535 SkNEW_ARGS(SkFontStyleSet_Android, (family, fScanner)); | |
536 if (0 == newSet->count()) { | 529 if (0 == newSet->count()) { |
537 SkDELETE(newSet); | 530 delete newSet; |
538 continue; | 531 continue; |
539 } | 532 } |
540 fFontStyleSets.push_back().reset(newSet); | 533 fFontStyleSets.push_back().reset(newSet); |
541 | 534 |
542 for (int j = 0; j < family.fNames.count(); j++) { | 535 for (int j = 0; j < family.fNames.count(); j++) { |
543 NameToFamily* nextEntry = nameToFamily->append(); | 536 NameToFamily* nextEntry = nameToFamily->append(); |
544 SkNEW_PLACEMENT_ARGS(&nextEntry->name, SkString, (family.fNames[
j])); | 537 new (&nextEntry->name) SkString(family.fNames[j]); |
545 nextEntry->styleSet = newSet; | 538 nextEntry->styleSet = newSet; |
546 } | 539 } |
547 } | 540 } |
548 } | 541 } |
549 | 542 |
550 void findDefaultFont() { | 543 void findDefaultFont() { |
551 SkASSERT(!fFontStyleSets.empty()); | 544 SkASSERT(!fFontStyleSets.empty()); |
552 | 545 |
553 static const char* gDefaultNames[] = { "sans-serif" }; | 546 static const char* gDefaultNames[] = { "sans-serif" }; |
554 for (size_t i = 0; i < SK_ARRAY_COUNT(gDefaultNames); ++i) { | 547 for (size_t i = 0; i < SK_ARRAY_COUNT(gDefaultNames); ++i) { |
(...skipping 29 matching lines...) Expand all Loading... |
584 if (custom) { | 577 if (custom) { |
585 SkASSERT(0 <= custom->fSystemFontUse); | 578 SkASSERT(0 <= custom->fSystemFontUse); |
586 SkASSERT(custom->fSystemFontUse < SK_ARRAY_COUNT(gSystemFontUseStrings))
; | 579 SkASSERT(custom->fSystemFontUse < SK_ARRAY_COUNT(gSystemFontUseStrings))
; |
587 SkDEBUGF(("SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s\n"
, | 580 SkDEBUGF(("SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s\n"
, |
588 gSystemFontUseStrings[custom->fSystemFontUse], | 581 gSystemFontUseStrings[custom->fSystemFontUse], |
589 custom->fBasePath, | 582 custom->fBasePath, |
590 custom->fFontsXml, | 583 custom->fFontsXml, |
591 custom->fFallbackFontsXml)); | 584 custom->fFallbackFontsXml)); |
592 } | 585 } |
593 | 586 |
594 return SkNEW_ARGS(SkFontMgr_Android, (custom)); | 587 return new SkFontMgr_Android(custom); |
595 } | 588 } |
OLD | NEW |