1 /*
2  * Copyright 2015 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 #include "SkTypes.h"
8 #if defined(SK_BUILD_FOR_ANDROID)
9 
10 #include "SkFontMgr.h"
11 #include "SkFontMgr_android.h"
12 
13 // For test only.
14 static const char* gTestFontsXml = nullptr;
15 static const char* gTestFallbackFontsXml = nullptr;
16 static const char* gTestBasePath = nullptr;
17 
SkUseTestFontConfigFile(const char * fontsXml,const char * fallbackFontsXml,const char * basePath)18 void SkUseTestFontConfigFile(const char* fontsXml, const char* fallbackFontsXml,
19                              const char* basePath)
20 {
21     gTestFontsXml = fontsXml;
22     gTestFallbackFontsXml = fallbackFontsXml;
23     gTestBasePath = basePath;
24     SkASSERT(gTestFontsXml);
25     SkASSERT(gTestFallbackFontsXml);
26     SkASSERT(gTestBasePath);
27     SkDEBUGF(("Test BasePath: %s Fonts: %s FallbackFonts: %s\n",
28               gTestBasePath, gTestFontsXml, gTestFallbackFontsXml));
29 }
30 
Factory()31 SkFontMgr* SkFontMgr::Factory() {
32     // These globals exist so that Chromium can override the environment.
33     // TODO: these globals need to be removed, and Chromium use SkFontMgr_New_Android instead.
34     if ((gTestFontsXml || gTestFallbackFontsXml) && gTestBasePath) {
35         SkFontMgr_Android_CustomFonts custom = {
36             SkFontMgr_Android_CustomFonts::kOnlyCustom,
37             gTestBasePath,
38             gTestFontsXml,
39             gTestFallbackFontsXml,
40             false /* fIsolated */
41         };
42         return SkFontMgr_New_Android(&custom);
43     }
44 
45     return SkFontMgr_New_Android(nullptr);
46 }
47 
48 #endif//defined(SK_BUILD_FOR_ANDROID)
49