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
This commit is contained in:
bungeman 2016-08-19 05:03:26 -07:00 committed by Commit bot
parent 15d71ff537
commit 83b24ff082

View File

@ -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;
static const char* defaultNames[] = { "sans-serif" };
for (const char* defaultName : defaultNames) {
fDefaultStyleSet.reset(this->onMatchFamily(defaultName));
if (fDefaultStyleSet) {
break;
}
SkTypeface* tf = set->matchStyle(SkFontStyle());
if (nullptr == tf) {
continue;
}
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;