Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1158)

Unified Diff: src/ports/SkFontMgr_android.cpp

Issue 2256253003: SkFontMgr_android clean up. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rename. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontMgr_android.cpp
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index 94d114d07a48bd2e78f3c251afac0d4e0aa9272b..7ac182f88c5474b63c38e76b80551f1c2f7827af 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -301,7 +301,7 @@ public:
families, base, custom->fFontsXml, custom->fFallbackFontsXml);
}
this->buildNameToFamilyMap(families, custom ? custom->fIsolated : false);
- this->findDefaultFont();
+ this->findDefaultStyleSet();
families.deleteAll();
}
@@ -355,10 +355,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);
}
}
}
@@ -366,7 +366,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)
{
@@ -496,7 +496,7 @@ protected:
// default family instead.
return this->onMatchFamilyStyle(familyName, style);
}
- return fDefaultFamily->matchStyle(style);
+ return fDefaultStyleSet->matchStyle(style);
}
@@ -504,18 +504,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;
@@ -525,44 +524,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;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698