From 77f85adadbc3448f4302559c14d8abf8724160da Mon Sep 17 00:00:00 2001 From: bungeman Date: Wed, 17 Jun 2015 12:07:10 -0700 Subject: [PATCH] Move Android SkFontMgr::Factory to its own file. Review URL: https://codereview.chromium.org/1190993002 --- gyp/ports.gyp | 3 ++ include/ports/SkFontMgr_android.h | 7 ++++ include/ports/SkTypeface_android.h | 2 ++ src/ports/SkFontMgr_android.cpp | 36 --------------------- src/ports/SkFontMgr_android_factory.cpp | 43 +++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 36 deletions(-) create mode 100644 src/ports/SkFontMgr_android_factory.cpp diff --git a/gyp/ports.gyp b/gyp/ports.gyp index 954199f14f..be47bc08cc 100644 --- a/gyp/ports.gyp +++ b/gyp/ports.gyp @@ -32,6 +32,7 @@ '../src/fonts/SkFontMgr_indirect.cpp', '../src/fonts/SkRemotableFontMgr.cpp', '../src/ports/SkFontHost_win.cpp', + '../src/ports/SkFontMgr_android_factory.cpp', '../src/ports/SkFontMgr_custom_directory_factory.cpp', '../src/ports/SkFontMgr_custom_embedded_factory.cpp', '../src/ports/SkFontMgr_fontconfig_factory.cpp', @@ -60,6 +61,7 @@ '../include/ports/SkAtomics_sync.h', '../include/ports/SkFontConfigInterface.h', '../include/ports/SkFontMgr.h', + '../include/ports/SkFontMgr_android.h', '../include/ports/SkFontMgr_custom.h', '../include/ports/SkFontMgr_fontconfig.h', '../include/ports/SkFontMgr_indirect.h', @@ -215,6 +217,7 @@ '../src/ports/SkFontConfigParser_android.cpp', '../src/ports/SkFontMgr_android.cpp', ], + 'sources/': [['include', '../src/ports/SkFontMgr_android_factory.cpp']], 'dependencies': [ 'android_deps.gyp:expat', ], diff --git a/include/ports/SkFontMgr_android.h b/include/ports/SkFontMgr_android.h index 8d1cafd2cc..e489b161b2 100644 --- a/include/ports/SkFontMgr_android.h +++ b/include/ports/SkFontMgr_android.h @@ -12,6 +12,13 @@ class SkFontMgr; +/** + * For test only -- this only affects the default factory. + * Load font config from given xml files, instead of those from Android system. + */ +SK_API void SkUseTestFontConfigFile(const char* mainconf, const char* fallbackconf, + const char* fontsdir); + struct SkFontMgr_Android_CustomFonts { /** When specifying custom fonts, indicates how to use system fonts. */ enum SystemFontUse { diff --git a/include/ports/SkTypeface_android.h b/include/ports/SkTypeface_android.h index f6fb3cbd08..704f9c7603 100644 --- a/include/ports/SkTypeface_android.h +++ b/include/ports/SkTypeface_android.h @@ -5,6 +5,8 @@ * found in the LICENSE file. */ +// THIS FILE IS DEPRECATED. USE SkFontMgr_android.h instead. + #ifndef SkTypeface_android_DEFINED #define SkTypeface_android_DEFINED diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp index a67c6814ea..f176b9cbec 100644 --- a/src/ports/SkFontMgr_android.cpp +++ b/src/ports/SkFontMgr_android.cpp @@ -15,16 +15,10 @@ #include "SkTDArray.h" #include "SkTSearch.h" #include "SkTypeface.h" -#include "SkTypeface_android.h" #include "SkTypefaceCache.h" #include -// For test only. -static const char* gTestFontsXml = NULL; -static const char* gTestFallbackFontsXml = NULL; -static const char* gTestBasePath = NULL; - class SkTypeface_Android : public SkTypeface_FreeType { public: SkTypeface_Android(const SkFontStyle& style, @@ -574,7 +568,6 @@ private: typedef SkFontMgr INHERITED; }; -/////////////////////////////////////////////////////////////////////////////// #ifdef SK_DEBUG static char const * const gSystemFontUseStrings[] = { "OnlyCustom", "PreferCustom", "PreferSystem" @@ -593,32 +586,3 @@ SkFontMgr* SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) { return SkNEW_ARGS(SkFontMgr_Android, (custom)); } - -SkFontMgr* SkFontMgr::Factory() { - // These globals exist so that Chromium can override the environment. - // TODO: these globals need to be removed, and Chromium use SkFontMgr_New_Android instead. - if ((gTestFontsXml || gTestFallbackFontsXml) && gTestBasePath) { - SkFontMgr_Android_CustomFonts custom = { - SkFontMgr_Android_CustomFonts::kOnlyCustom, - gTestBasePath, - gTestFontsXml, - gTestFallbackFontsXml - }; - return SkFontMgr_New_Android(&custom); - } - - return SkFontMgr_New_Android(NULL); -} - -void SkUseTestFontConfigFile(const char* fontsXml, const char* fallbackFontsXml, - const char* basePath) -{ - gTestFontsXml = fontsXml; - gTestFallbackFontsXml = fallbackFontsXml; - gTestBasePath = basePath; - SkASSERT(gTestFontsXml); - SkASSERT(gTestFallbackFontsXml); - SkASSERT(gTestBasePath); - SkDEBUGF(("Test BasePath: %s Fonts: %s FallbackFonts: %s\n", - gTestBasePath, gTestFontsXml, gTestFallbackFontsXml)); -} diff --git a/src/ports/SkFontMgr_android_factory.cpp b/src/ports/SkFontMgr_android_factory.cpp new file mode 100644 index 0000000000..7f48561479 --- /dev/null +++ b/src/ports/SkFontMgr_android_factory.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "SkFontMgr.h" +#include "SkFontMgr_android.h" + +// For test only. +static const char* gTestFontsXml = NULL; +static const char* gTestFallbackFontsXml = NULL; +static const char* gTestBasePath = NULL; + +void SkUseTestFontConfigFile(const char* fontsXml, const char* fallbackFontsXml, + const char* basePath) +{ + gTestFontsXml = fontsXml; + gTestFallbackFontsXml = fallbackFontsXml; + gTestBasePath = basePath; + SkASSERT(gTestFontsXml); + SkASSERT(gTestFallbackFontsXml); + SkASSERT(gTestBasePath); + SkDEBUGF(("Test BasePath: %s Fonts: %s FallbackFonts: %s\n", + gTestBasePath, gTestFontsXml, gTestFallbackFontsXml)); +} + +SkFontMgr* SkFontMgr::Factory() { + // These globals exist so that Chromium can override the environment. + // TODO: these globals need to be removed, and Chromium use SkFontMgr_New_Android instead. + if ((gTestFontsXml || gTestFallbackFontsXml) && gTestBasePath) { + SkFontMgr_Android_CustomFonts custom = { + SkFontMgr_Android_CustomFonts::kOnlyCustom, + gTestBasePath, + gTestFontsXml, + gTestFallbackFontsXml + }; + return SkFontMgr_New_Android(&custom); + } + + return SkFontMgr_New_Android(NULL); +}