diff options
author | 2014-08-08 12:06:51 -0700 | |
---|---|---|
committer | 2014-08-08 12:06:52 -0700 | |
commit | 4e3523cf546df4079cf769b8ecc8011403420a45 (patch) | |
tree | 13c7f6d95f880ddd1d620d0dfb2adb731497e063 | |
parent | 8d9153fca25897bf40ca0ebac8b03616612cc7b4 (diff) |
Blink layout tests all assume it can provide custom font configuration files on every platform. In moving Android to the font manager, we broke those.
They're ugly, but this patch reinstates them.
R=tomhudson@google.com, djsollen@google.com, reed@google.com
TBR=reed@google.com
BUG=chromium:401954
Author: bungeman@google.com
Review URL: https://codereview.chromium.org/451093002
-rw-r--r-- | include/ports/SkTypeface_android.h | 10 | ||||
-rw-r--r-- | src/ports/SkFontConfigInterface_android.cpp | 7 | ||||
-rw-r--r-- | src/ports/SkFontMgr_android.cpp | 40 |
3 files changed, 49 insertions, 8 deletions
diff --git a/include/ports/SkTypeface_android.h b/include/ports/SkTypeface_android.h index c199bee29e..b25ad18597 100644 --- a/include/ports/SkTypeface_android.h +++ b/include/ports/SkTypeface_android.h @@ -39,5 +39,15 @@ SK_API bool SkGetFallbackFamilyNameForChar(SkUnichar uni, const char* lang, SkSt SK_API void SkUseTestFontConfigFile(const char* mainconf, const char* fallbackconf, const char* fontsdir); +/** + * For test only. + * Returns the information set by SkUseTestFontConfigFile. + * TODO: this should be removed once SkFontConfigInterface_android is removed, + * and then Chromium should be given a better way to set up it's test environment + * than SkUseTestFontConfigFile. + */ +void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf, + const char** fontsdir); + #endif // #ifdef SK_BUILD_FOR_ANDROID #endif // #ifndef SkTypeface_android_DEFINED diff --git a/src/ports/SkFontConfigInterface_android.cpp b/src/ports/SkFontConfigInterface_android.cpp index 1651ac9c05..cba9f37c35 100644 --- a/src/ports/SkFontConfigInterface_android.cpp +++ b/src/ports/SkFontConfigInterface_android.cpp @@ -577,3 +577,10 @@ void SkUseTestFontConfigFile(const char* mainconf, const char* fallbackconf, SkDEBUGF(("Use Test Config File Main %s, Fallback %s, Font Dir %s", gTestMainConfigFile, gTestFallbackConfigFile, gTestFontFilePrefix)); } + +void SkGetTestFontConfiguration(const char** mainconf, const char** fallbackconf, + const char** fontsdir) { + *mainconf = gTestMainConfigFile; + *fallbackconf = gTestFallbackConfigFile; + *fontsdir = gTestFontFilePrefix; +} diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp index 1ab2f29642..b0af791d30 100644 --- a/src/ports/SkFontMgr_android.cpp +++ b/src/ports/SkFontMgr_android.cpp @@ -14,6 +14,7 @@ #include "SkTDArray.h" #include "SkTSearch.h" #include "SkTypeface.h" +#include "SkTypeface_android.h" #include "SkTypefaceCache.h" #include <limits> @@ -117,15 +118,19 @@ private: typedef SkTypeface_Android INHERITED; }; -void get_path_for_sys_fonts(SkString* full, const SkString& name) { - full->set(getenv("ANDROID_ROOT")); - full->append(SK_FONT_FILE_PREFIX); +void get_path_for_sys_fonts(const char* basePath, const SkString& name, SkString* full) { + if (basePath) { + full->set(basePath); + } else { + full->set(getenv("ANDROID_ROOT")); + full->append(SK_FONT_FILE_PREFIX); + } full->append(name); } class SkFontStyleSet_Android : public SkFontStyleSet { public: - explicit SkFontStyleSet_Android(const FontFamily& family) { + explicit SkFontStyleSet_Android(const FontFamily& family, const char* basePath) { const SkString* cannonicalFamilyName = NULL; if (family.fNames.count() > 0) { cannonicalFamilyName = &family.fNames[0]; @@ -135,7 +140,7 @@ public: const FontFileInfo& fontFile = family.fFontFiles[i]; SkString pathName; - get_path_for_sys_fonts(&pathName, fontFile.fFileName); + get_path_for_sys_fonts(basePath, fontFile.fFileName, &pathName); SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(pathName.c_str())); if (!stream.get()) { @@ -260,7 +265,15 @@ public: SkFontMgr_Android() { SkTDArray<FontFamily*> fontFamilies; SkFontConfigParser::GetFontFamilies(fontFamilies); - this->buildNameToFamilyMap(fontFamilies); + this->buildNameToFamilyMap(fontFamilies, NULL); + this->findDefaultFont(); + } + SkFontMgr_Android(const char* mainConfigFile, const char* fallbackConfigFile, + const char* basePath) + { + SkTDArray<FontFamily*> fontFamilies; + SkFontConfigParser::GetTestFontFamilies(fontFamilies, mainConfigFile, fallbackConfigFile); + this->buildNameToFamilyMap(fontFamilies, basePath); this->findDefaultFont(); } @@ -425,7 +438,7 @@ private: SkTDArray<NameToFamily> fNameToFamilyMap; SkTDArray<NameToFamily> fFallbackNameToFamilyMap; - void buildNameToFamilyMap(SkTDArray<FontFamily*> families) { + void buildNameToFamilyMap(SkTDArray<FontFamily*> families, const char* basePath) { for (int i = 0; i < families.count(); i++) { FontFamily& family = *families[i]; @@ -439,7 +452,7 @@ private: } } - SkFontStyleSet_Android* newSet = SkNEW_ARGS(SkFontStyleSet_Android, (family)); + SkFontStyleSet_Android* newSet = SkNEW_ARGS(SkFontStyleSet_Android, (family, basePath)); if (0 == newSet->count()) { SkDELETE(newSet); continue; @@ -485,5 +498,16 @@ private: /////////////////////////////////////////////////////////////////////////////// SkFontMgr* SkFontMgr::Factory() { + // The call to SkGetTestFontConfiguration is so that Chromium can override the environment. + // TODO: these globals need to be removed, in favor of a constructor / separate Factory + // which can be used instead. + const char* mainConfigFile; + const char* fallbackConfigFile; + const char* basePath; + SkGetTestFontConfiguration(&mainConfigFile, &fallbackConfigFile, &basePath); + if (mainConfigFile) { + SkNEW_ARGS(SkFontMgr_Android, (mainConfigFile, fallbackConfigFile, basePath)); + } + return SkNEW(SkFontMgr_Android); } |