diff options
author | 2016-08-19 05:03:26 -0700 | |
---|---|---|
committer | 2016-08-19 05:03:26 -0700 | |
commit | 83b24ff0825eadf200c3b5d87c669beb270a8680 (patch) | |
tree | 7a90313161f8453c7a40626eb9cbe82510a8ec18 /src/ports/SkFontMgr_android.cpp | |
parent | 15d71ff5376e2051129f88898bebb29544d03c07 (diff) |
SkFontMgr_android clean up.
This removes the never used defaultTypeface, uses 'StyleSet' in field
names consistently, fixes potential leaks of names, and moves fields to
sk_sp.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2256253003
Review-Url: https://codereview.chromium.org/2256253003
Diffstat (limited to 'src/ports/SkFontMgr_android.cpp')
-rw-r--r-- | src/ports/SkFontMgr_android.cpp | 66 |
1 files changed, 27 insertions, 39 deletions
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp index 56c1413338..8d2bc6b04a 100644 --- a/src/ports/SkFontMgr_android.cpp +++ b/src/ports/SkFontMgr_android.cpp @@ -273,7 +273,7 @@ public: families, base, custom->fFontsXml, custom->fFallbackFontsXml); } this->buildNameToFamilyMap(families, custom ? custom->fIsolated : false); - this->findDefaultFont(); + this->findDefaultStyleSet(); families.deleteAll(); } @@ -327,10 +327,10 @@ protected: virtual SkTypeface* onMatchFaceStyle(const SkTypeface* typeface, const SkFontStyle& style) const override { - for (int i = 0; i < fFontStyleSets.count(); ++i) { - for (int j = 0; j < fFontStyleSets[i]->fStyles.count(); ++j) { - if (fFontStyleSets[i]->fStyles[j] == typeface) { - return fFontStyleSets[i]->matchStyle(style); + for (int i = 0; i < fStyleSets.count(); ++i) { + for (int j = 0; j < fStyleSets[i]->fStyles.count(); ++j) { + if (fStyleSets[i]->fStyles[j] == typeface) { + return fStyleSets[i]->matchStyle(style); } } } @@ -338,7 +338,7 @@ protected: } static sk_sp<SkTypeface_AndroidSystem> find_family_style_character( - const SkTDArray<NameToFamily>& fallbackNameToFamilyMap, + const SkTArray<NameToFamily, true>& fallbackNameToFamilyMap, const SkFontStyle& style, bool elegant, const SkString& langTag, SkUnichar character) { @@ -468,7 +468,7 @@ protected: // default family instead. return this->onMatchFamilyStyle(familyName, style); } - return fDefaultFamily->matchStyle(style); + return fDefaultStyleSet->matchStyle(style); } @@ -476,18 +476,17 @@ private: SkTypeface_FreeType::Scanner fScanner; - SkTArray<SkAutoTUnref<SkFontStyleSet_Android>, true> fFontStyleSets; - SkFontStyleSet* fDefaultFamily; - SkTypeface* fDefaultTypeface; + SkTArray<sk_sp<SkFontStyleSet_Android>, true> fStyleSets; + sk_sp<SkFontStyleSet> fDefaultStyleSet; - SkTDArray<NameToFamily> fNameToFamilyMap; - SkTDArray<NameToFamily> fFallbackNameToFamilyMap; + SkTArray<NameToFamily, true> fNameToFamilyMap; + SkTArray<NameToFamily, true> fFallbackNameToFamilyMap; void buildNameToFamilyMap(SkTDArray<FontFamily*> families, const bool isolated) { for (int i = 0; i < families.count(); i++) { FontFamily& family = *families[i]; - SkTDArray<NameToFamily>* nameToFamily = &fNameToFamilyMap; + SkTArray<NameToFamily, true>* nameToFamily = &fNameToFamilyMap; if (family.fIsFallbackFont) { nameToFamily = &fFallbackNameToFamilyMap; @@ -497,44 +496,33 @@ private: } } - SkFontStyleSet_Android* newSet = new SkFontStyleSet_Android(family, fScanner, isolated); + sk_sp<SkFontStyleSet_Android> newSet = + sk_make_sp<SkFontStyleSet_Android>(family, fScanner, isolated); if (0 == newSet->count()) { - delete newSet; continue; } - fFontStyleSets.push_back().reset(newSet); - for (int j = 0; j < family.fNames.count(); j++) { - NameToFamily* nextEntry = nameToFamily->append(); - new (&nextEntry->name) SkString(family.fNames[j]); - nextEntry->styleSet = newSet; + for (const SkString& name : family.fNames) { + nameToFamily->emplace_back(NameToFamily{name, newSet.get()}); } + fStyleSets.emplace_back(std::move(newSet)); } } - void findDefaultFont() { - SkASSERT(!fFontStyleSets.empty()); + void findDefaultStyleSet() { + SkASSERT(!fStyleSets.empty()); - static const char* gDefaultNames[] = { "sans-serif" }; - for (size_t i = 0; i < SK_ARRAY_COUNT(gDefaultNames); ++i) { - SkFontStyleSet* set = this->onMatchFamily(gDefaultNames[i]); - if (nullptr == set) { - continue; - } - SkTypeface* tf = set->matchStyle(SkFontStyle()); - if (nullptr == tf) { - continue; + static const char* defaultNames[] = { "sans-serif" }; + for (const char* defaultName : defaultNames) { + fDefaultStyleSet.reset(this->onMatchFamily(defaultName)); + if (fDefaultStyleSet) { + break; } - fDefaultFamily = set; - fDefaultTypeface = tf; - break; } - if (nullptr == fDefaultTypeface) { - fDefaultFamily = fFontStyleSets[0]; - fDefaultTypeface = fDefaultFamily->createTypeface(0); + if (nullptr == fDefaultStyleSet) { + fDefaultStyleSet = fStyleSets[0]; } - SkASSERT(fDefaultFamily); - SkASSERT(fDefaultTypeface); + SkASSERT(fDefaultStyleSet); } typedef SkFontMgr INHERITED; |