| Index: src/ports/SkFontMgr_android.cpp
|
| diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
|
| index 523deca0e3a0bd932c2be98e40600ee83fca7c3d..157153b5c9d7a1f8de26565a4349c97bd363af1a 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(SkFontMgr_Android_CustomFonts* custom) {
|
| + SkTDArray<FontFamily*> families;
|
| + if (custom && SkFontMgr_Android_CustomFonts::kPreferSystem != custom->systemFontUse) {
|
| + SkString base(custom->basePath);
|
| + SkFontConfigParser::GetCustomFontFamilies(families, base,
|
| + custom->fontsXml, custom->fallbackFontsXml);
|
| + }
|
| + if (!custom ||
|
| + (custom && SkFontMgr_Android_CustomFonts::kOnlyCustom != custom->systemFontUse))
|
| + {
|
| + SkFontConfigParser::GetSystemFontFamilies(families);
|
| + }
|
| + if (custom && SkFontMgr_Android_CustomFonts::kPreferSystem == custom->systemFontUse) {
|
| + SkString base(custom->basePath);
|
| + SkFontConfigParser::GetCustomFontFamilies(families, base,
|
| + custom->fontsXml, custom->fallbackFontsXml);
|
| + }
|
| + 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(SkFontMgr_Android_CustomFonts* custom) {
|
| +#define COMMA ,
|
| + SkDEBUGCODE(static char const * const SystemFontUseStrings[] = {
|
| + "OnlyCustom" COMMA "PreferCustom" COMMA "PreferSystem"
|
| + };)
|
| +#undef COMMA
|
| + if (custom) {
|
| + SkASSERT(0 <= custom->systemFontUse);
|
| + SkASSERT( custom->systemFontUse < SK_ARRAY_COUNT(SystemFontUseStrings));
|
| + SkDEBUGF(("SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s",
|
| + SystemFontUseStrings[custom->systemFontUse],
|
| + custom->basePath,
|
| + custom->fontsXml,
|
| + custom->fallbackFontsXml));
|
| + }
|
| +
|
| + 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,
|
|
|