Move Android SkFontMgr::Factory to its own file.

Review URL: https://codereview.chromium.org/1190993002
This commit is contained in:
bungeman 2015-06-17 12:07:10 -07:00 committed by Commit bot
parent 2a4685f8bb
commit 77f85adadb
5 changed files with 55 additions and 36 deletions

View File

@ -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',
],

View File

@ -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 {

View File

@ -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

View File

@ -15,16 +15,10 @@
#include "SkTDArray.h"
#include "SkTSearch.h"
#include "SkTypeface.h"
#include "SkTypeface_android.h"
#include "SkTypefaceCache.h"
#include <limits>
// 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));
}

View File

@ -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);
}