Index: src/ports/SkFontMgr_android.cpp |
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp |
index 523deca0e3a0bd932c2be98e40600ee83fca7c3d..431bc962d5b76eefa294eb5219943e9663730a8a 100644 |
--- a/src/ports/SkFontMgr_android.cpp |
+++ b/src/ports/SkFontMgr_android.cpp |
@@ -9,6 +9,7 @@ |
#include "SkFontDescriptor.h" |
#include "SkFontHost_FreeType_common.h" |
#include "SkFontMgr.h" |
+#include "SkFontMgr_android.h" |
#include "SkFontStyle.h" |
#include "SkStream.h" |
#include "SkTDArray.h" |
@@ -18,11 +19,6 @@ |
#include "SkTypefaceCache.h" |
#include <limits> |
-#include <stdlib.h> |
- |
-#ifndef SK_FONT_FILE_PREFIX |
-# define SK_FONT_FILE_PREFIX "/fonts/" |
-#endif |
#ifndef SK_DEBUG_FONTS |
#define SK_DEBUG_FONTS 0 |
@@ -126,19 +122,9 @@ private: |
typedef SkTypeface_Android INHERITED; |
}; |
-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, const char* basePath, |
+ explicit SkFontStyleSet_Android(const FontFamily& family, |
const SkTypeface_FreeType::Scanner& scanner) |
{ |
const SkString* cannonicalFamilyName = NULL; |
@@ -149,8 +135,8 @@ public: |
for (int i = 0; i < family.fFonts.count(); ++i) { |
const FontFileInfo& fontFile = family.fFonts[i]; |
- SkString pathName; |
- get_path_for_sys_fonts(basePath, fontFile.fFileName, &pathName); |
+ SkString pathName(family.fBasePath); |
+ pathName.append(fontFile.fFileName); |
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(pathName.c_str())); |
if (!stream.get()) { |
@@ -265,19 +251,26 @@ struct NameToFamily { |
class SkFontMgr_Android : public SkFontMgr { |
public: |
- SkFontMgr_Android() { |
- SkTDArray<FontFamily*> fontFamilies; |
- SkFontConfigParser::GetFontFamilies(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); |
+ SkFontMgr_Android(const SkFontMgr_Android_CustomFonts* custom) { |
+ SkTDArray<FontFamily*> families; |
+ if (custom && SkFontMgr_Android_CustomFonts::kPreferSystem != custom->fSystemFontUse) { |
+ SkString base(custom->fBasePath); |
+ SkFontConfigParser::GetCustomFontFamilies(families, base, |
+ custom->fFontsXml, custom->fFallbackFontsXml); |
+ } |
+ if (!custom || |
+ (custom && SkFontMgr_Android_CustomFonts::kOnlyCustom != custom->fSystemFontUse)) |
+ { |
+ SkFontConfigParser::GetSystemFontFamilies(families); |
+ } |
+ if (custom && SkFontMgr_Android_CustomFonts::kPreferSystem == custom->fSystemFontUse) { |
+ SkString base(custom->fBasePath); |
+ SkFontConfigParser::GetCustomFontFamilies(families, base, |
+ custom->fFontsXml, custom->fFallbackFontsXml); |
+ } |
+ this->buildNameToFamilyMap(families); |
this->findDefaultFont(); |
+ families.deleteAll(); |
} |
protected: |
@@ -456,7 +449,7 @@ private: |
SkTDArray<NameToFamily> fNameToFamilyMap; |
SkTDArray<NameToFamily> fFallbackNameToFamilyMap; |
- void buildNameToFamilyMap(SkTDArray<FontFamily*> families, const char* basePath) { |
+ void buildNameToFamilyMap(SkTDArray<FontFamily*> families) { |
for (int i = 0; i < families.count(); i++) { |
FontFamily& family = *families[i]; |
@@ -471,7 +464,7 @@ private: |
} |
SkFontStyleSet_Android* newSet = |
- SkNEW_ARGS(SkFontStyleSet_Android, (family, basePath, fScanner)); |
+ SkNEW_ARGS(SkFontStyleSet_Android, (family, fScanner)); |
if (0 == newSet->count()) { |
SkDELETE(newSet); |
continue; |
@@ -516,19 +509,41 @@ private: |
/////////////////////////////////////////////////////////////////////////////// |
+SkFontMgr* SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) { |
+#define COMMA , |
djsollen
2015/02/04 23:11:06
what is the point of this define? Just use a comm
bungeman-skia
2015/02/04 23:32:11
SkDEBUGCODE is a macro, so any literal comma is se
bungeman-skia
2015/02/04 23:48:50
Done.
|
+ SkDEBUGCODE(static char const * const SystemFontUseStrings[] = { |
+ "OnlyCustom" COMMA "PreferCustom" COMMA "PreferSystem" |
+ };) |
+#undef COMMA |
+ if (custom) { |
+ SkASSERT(0 <= custom->fSystemFontUse); |
+ SkASSERT( custom->fSystemFontUse < SK_ARRAY_COUNT(SystemFontUseStrings)); |
djsollen
2015/02/04 23:11:07
nit: fix spacing
bungeman-skia
2015/02/04 23:32:11
I'm just trying to show very obviously that I'm te
bungeman-skia
2015/02/04 23:48:50
Done.
|
+ SkDEBUGF(("SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s", |
+ SystemFontUseStrings[custom->fSystemFontUse], |
+ custom->fBasePath, |
+ custom->fFontsXml, |
+ custom->fFallbackFontsXml)); |
+ } |
+ |
+ return SkNEW_ARGS(SkFontMgr_Android, (custom)); |
+} |
+ |
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* fontsXml; |
+ const char* fallbackFontsXml; |
const char* basePath; |
- SkGetTestFontConfiguration(&mainConfigFile, &fallbackConfigFile, &basePath); |
- if (mainConfigFile) { |
- return SkNEW_ARGS(SkFontMgr_Android, (mainConfigFile, fallbackConfigFile, basePath)); |
+ SkGetTestFontConfiguration(&fontsXml, &fallbackFontsXml, &basePath); |
+ if ((fontsXml || fallbackFontsXml) && basePath) { |
+ SkFontMgr_Android_CustomFonts custom = { |
+ SkFontMgr_Android_CustomFonts::kOnlyCustom, basePath, fontsXml, fallbackFontsXml |
+ }; |
+ return SkFontMgr_New_Android(&custom); |
} |
- return SkNEW(SkFontMgr_Android); |
+ return SkFontMgr_New_Android(NULL); |
} |
void SkUseTestFontConfigFile(const char* mainconf, const char* fallbackconf, |