diff options
author | 2017-08-10 13:49:41 -0400 | |
---|---|---|
committer | 2017-08-14 19:29:05 +0000 | |
commit | aee878d767a3965ee6409be9c72bb9ae6266bf52 (patch) | |
tree | c6f6e2cb26e624db3ab63cb9ecdfccaccd2869d1 /src | |
parent | df33fefe14837d7a7130aacb6206dbe3ebc7d081 (diff) |
Move lang to list in Android font manager.
Change-Id: Ia4af2769f4761e6b444ed0c232c48199872f3acc
Reviewed-on: https://skia-review.googlesource.com/33480
Reviewed-by: Derek Sollenberger <djsollen@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/ports/SkFontMgr_android.cpp | 14 | ||||
-rw-r--r-- | src/ports/SkFontMgr_android_parser.cpp | 28 | ||||
-rw-r--r-- | src/ports/SkFontMgr_android_parser.h | 2 |
3 files changed, 32 insertions, 12 deletions
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp index a180215e88..2dd3221466 100644 --- a/src/ports/SkFontMgr_android.cpp +++ b/src/ports/SkFontMgr_android.cpp @@ -27,6 +27,7 @@ #include "SkTemplates.h" #include "SkTypefaceCache.h" +#include <algorithm> #include <limits> class SkData; @@ -60,7 +61,7 @@ public: const SkFontStyle& style, bool isFixedPitch, const SkString& familyName, - const SkLanguage& lang, + const SkTArray<SkLanguage, true>& lang, FontVariant variantStyle) : INHERITED(style, isFixedPitch, familyName) , fPathName(pathName) @@ -101,7 +102,7 @@ public: const SkString fPathName; int fIndex; const SkSTArray<4, SkFixed, true> fAxes; - const SkLanguage fLang; + const SkSTArray<4, SkLanguage, true> fLang; const FontVariant fVariantStyle; SkAutoTCallVProc<FILE, sk_fclose> fFile; @@ -187,7 +188,6 @@ public: } style = SkFontStyle(weight, style.width(), slant); - const SkLanguage& lang = family.fLanguage; uint32_t variant = family.fVariant; if (kDefault_FontVariant == variant) { variant = kCompact_FontVariant | kElegant_FontVariant; @@ -210,7 +210,7 @@ public: fStyles.push_back().reset(new SkTypeface_AndroidSystem( pathName, cacheFontFiles, ttcIndex, axisValues.get(), axisDefinitions.count(), - style, isFixedWidth, familyName, lang, variant)); + style, isFixedWidth, familyName, family.fLanguages, variant)); } } @@ -351,7 +351,11 @@ protected: SkFontStyleSet_Android* family = fallbackNameToFamilyMap[i].styleSet; sk_sp<SkTypeface_AndroidSystem> face(family->matchStyle(style)); - if (!langTag.isEmpty() && !face->fLang.getTag().startsWith(langTag.c_str())) { + if (!langTag.isEmpty() && + std::none_of(face->fLang.begin(), face->fLang.end(), [&](SkLanguage lang){ + return lang.getTag().startsWith(langTag.c_str()); + })) + { continue; } diff --git a/src/ports/SkFontMgr_android_parser.cpp b/src/ports/SkFontMgr_android_parser.cpp index a68f791387..1269523062 100644 --- a/src/ports/SkFontMgr_android_parser.cpp +++ b/src/ports/SkFontMgr_android_parser.cpp @@ -249,7 +249,7 @@ static const TagHandler fontHandler = { static const TagHandler familyHandler = { /*start*/[](FamilyData* self, const char* tag, const char** attributes) { // 'name' (string) [optional] - // 'lang' (string) [default ""] + // 'lang' (space separated string) [default ""] // 'variant' ("elegant", "compact") [default "default"] // If there is no name, this is a fallback only font. FontFamily* family = new FontFamily(self->fBasePath, true); @@ -264,7 +264,16 @@ static const TagHandler familyHandler = { family->fNames.push_back().set(tolc.lc()); family->fIsFallbackFont = false; } else if (MEMEQ("lang", name, nameLen)) { - family->fLanguage = SkLanguage(value, valueLen); + size_t i = 0; + while (true) { + for (; i < valueLen && is_whitespace(value[i]); ++i) { } + if (i == valueLen) { break; } + size_t j; + for (j = i + 1; j < valueLen && !is_whitespace(value[j]); ++j) { } + family->fLanguages.emplace_back(value + i, j - i); + i = j; + if (i == valueLen) { break; } + } } else if (MEMEQ("variant", name, nameLen)) { if (MEMEQ("elegant", value, valueLen)) { family->fVariant = kElegant_FontVariant; @@ -400,9 +409,16 @@ static const TagHandler fileHandler = { } } else if (MEMEQ("lang", name, nameLen)) { - SkLanguage prevLang = currentFamily.fLanguage; - currentFamily.fLanguage = SkLanguage(value, valueLen); - if (currentFamily.fFonts.count() > 1 && currentFamily.fLanguage != prevLang) { + SkLanguage currentLanguage = SkLanguage(value, valueLen); + bool showWarning = false; + if (currentFamily.fLanguages.empty()) { + showWarning = (currentFamily.fFonts.count() > 1); + currentFamily.fLanguages.push_back(std::move(currentLanguage)); + } else if (currentFamily.fLanguages[0] != currentLanguage) { + showWarning = true; + currentFamily.fLanguages[0] = std::move(currentLanguage); + } + if (showWarning) { SK_FONTCONFIGPARSER_WARNING("'%s' unexpected language found\n" "Note: Every font file within a family must have identical languages.", value); @@ -705,7 +721,7 @@ static void append_fallback_font_families_for_locale(SkTDArray<FontFamily*>& fal for (int i = 0; i < langSpecificFonts.count(); ++i) { FontFamily* family = langSpecificFonts[i]; - family->fLanguage = SkLanguage(locale); + family->fLanguages.emplace_back(locale); *fallbackFonts.append() = family; } } diff --git a/src/ports/SkFontMgr_android_parser.h b/src/ports/SkFontMgr_android_parser.h index 75b31c300e..d8de6ab1fd 100644 --- a/src/ports/SkFontMgr_android_parser.h +++ b/src/ports/SkFontMgr_android_parser.h @@ -93,7 +93,7 @@ struct FontFamily { SkTArray<SkString, true> fNames; SkTArray<FontFileInfo, true> fFonts; - SkLanguage fLanguage; + SkTArray<SkLanguage, true> fLanguages; FontVariant fVariant; int fOrder; // internal to the parser, not useful to users. bool fIsFallbackFont; |