diff options
author | bungeman <bungeman@google.com> | 2014-11-04 10:54:31 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-04 10:54:32 -0800 |
commit | 4b86bacb0428b07cba01fd46452d5c46e6f21af0 (patch) | |
tree | b273459e0f50bec0fc419f15846988a43aee4c24 /src | |
parent | 47eda52e8fb88f0725b401762a3e0bddc98e9fb3 (diff) |
Allow all font weights on Android and respect overrides.
This removes the code which forces 400 and 700 weights only,
and also overrides the font weight with the configured weight.
Review URL: https://codereview.chromium.org/694533006
Diffstat (limited to 'src')
-rw-r--r-- | src/ports/SkFontConfigParser_android.cpp | 53 | ||||
-rw-r--r-- | src/ports/SkFontMgr_android.cpp | 23 |
2 files changed, 11 insertions, 65 deletions
diff --git a/src/ports/SkFontConfigParser_android.cpp b/src/ports/SkFontConfigParser_android.cpp index 41f5c4aac9..a9ce0c9d31 100644 --- a/src/ports/SkFontConfigParser_android.cpp +++ b/src/ports/SkFontConfigParser_android.cpp @@ -203,54 +203,7 @@ void aliasElementHandler(FamilyData* familyData, const char** attributes) { } } -bool findWeight400(FontFamily* family) { - for (int i = 0; i < family->fFonts.count(); i++) { - if (family->fFonts[i].fWeight == 400) { - return true; - } - } - return false; -} - -bool desiredWeight(int weight) { - return (weight == 400 || weight == 700); -} - -int countDesiredWeight(FontFamily* family) { - int count = 0; - for (int i = 0; i < family->fFonts.count(); i++) { - if (desiredWeight(family->fFonts[i].fWeight)) { - count++; - } - } - return count; -} - -// To meet Skia's expectations, any family that contains weight=400 -// fonts should *only* contain {400,700} -void purgeUndesiredWeights(FontFamily* family) { - int count = countDesiredWeight(family); - for (int i = 1, j = 0; i < family->fFonts.count(); i++) { - if (desiredWeight(family->fFonts[j].fWeight)) { - j++; - } - if ((i != j) && desiredWeight(family->fFonts[i].fWeight)) { - family->fFonts[j] = family->fFonts[i]; - } - } - family->fFonts.resize_back(count); -} - -void familysetElementEndHandler(FamilyData* familyData) { - for (int i = 0; i < familyData->families.count(); i++) { - if (findWeight400(familyData->families[i])) { - purgeUndesiredWeights(familyData->families[i]); - } - } -} - -void startElementHandler(void* data, const char* tag, - const char** attributes) { +void startElementHandler(void* data, const char* tag, const char** attributes) { FamilyData* familyData = (FamilyData*) data; size_t len = strlen(tag); if (len == 6 && !strncmp(tag, "family", len)) { @@ -268,9 +221,7 @@ void startElementHandler(void* data, const char* tag, void endElementHandler(void* data, const char* tag) { FamilyData* familyData = (FamilyData*) data; size_t len = strlen(tag); - if (len == 9 && strncmp(tag, "familyset", len) == 0) { - familysetElementEndHandler(familyData); - } else if (len == 6 && strncmp(tag, "family", len) == 0) { + if (len == 6 && strncmp(tag, "family", len) == 0) { *familyData->families.append() = familyData->currentFamily; familyData->currentFamily = NULL; } else if (len == 4 && !strncmp(tag, "font", len)) { diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp index 4677a1f86d..508ad4c9c1 100644 --- a/src/ports/SkFontMgr_android.cpp +++ b/src/ports/SkFontMgr_android.cpp @@ -44,7 +44,7 @@ public: SkTypeface_Android(int index, const SkFontStyle& style, bool isFixedPitch, - const SkString familyName) + const SkString& familyName) : INHERITED(style, SkTypefaceCache::NewFontID(), isFixedPitch) , fIndex(index) , fFamilyName(familyName) { } @@ -63,11 +63,11 @@ private: class SkTypeface_AndroidSystem : public SkTypeface_Android { public: - SkTypeface_AndroidSystem(const SkString pathName, + SkTypeface_AndroidSystem(const SkString& pathName, int index, const SkFontStyle& style, bool isFixedPitch, - const SkString familyName, + const SkString& familyName, const SkLanguage& lang, FontVariant variantStyle) : INHERITED(index, style, isFixedPitch, familyName) @@ -102,7 +102,7 @@ public: int index, const SkFontStyle& style, bool isFixedPitch, - const SkString familyName) + const SkString& familyName) : INHERITED(index, style, isFixedPitch, familyName) , fStream(SkRef(stream)) { } @@ -167,6 +167,10 @@ public: continue; } + if (fontFile.fWeight != 0) { + style = SkFontStyle(fontFile.fWeight, style.width(), style.slant()); + } + const SkLanguage& lang = family.fLanguage; uint32_t variant = family.fVariant; if (kDefault_FontVariant == variant) { @@ -231,16 +235,7 @@ public: private: SkFontStyle style(int index) { - return SkFontStyle(this->weight(index), SkFontStyle::kNormal_Width, - this->slant(index)); - } - SkFontStyle::Weight weight(int index) { - if (fStyles[index]->isBold()) return SkFontStyle::kBold_Weight; - return SkFontStyle::kNormal_Weight; - } - SkFontStyle::Slant slant(int index) { - if (fStyles[index]->isItalic()) return SkFontStyle::kItalic_Slant; - return SkFontStyle::kUpright_Slant; + return fStyles[index]->fontStyle(); } static int match_score(const SkFontStyle& pattern, const SkFontStyle& candidate) { int score = 0; |