Blink layout tests all assume it can provide custom font configuration files on every...
authorbungeman <bungeman@google.com>
Fri, 8 Aug 2014 19:06:51 +0000 (12:06 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 8 Aug 2014 19:06:52 +0000 (12:06 -0700)
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

include/ports/SkTypeface_android.h
src/ports/SkFontConfigInterface_android.cpp
src/ports/SkFontMgr_android.cpp

index c199bee..b25ad18 100644 (file)
@@ -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
index 1651ac9..cba9f37 100644 (file)
@@ -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;
+}
index 1ab2f29..b0af791 100644 (file)
@@ -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);
 }