• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 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 
8 #include "include/core/SkTypes.h"
9 
10 #include "include/core/SkData.h"
11 #include "include/core/SkFontMgr.h"
12 #include "include/core/SkFontStyle.h"
13 #include "include/core/SkPaint.h"
14 #include "include/core/SkRefCnt.h"
15 #include "include/core/SkStream.h"
16 #include "include/core/SkString.h"
17 #include "include/ports/SkFontMgr_android.h"
18 #include "include/private/SkFixed.h"
19 #include "include/private/SkTArray.h"
20 #include "include/private/SkTDArray.h"
21 #include "include/private/SkTemplates.h"
22 #include "src/core/SkFontDescriptor.h"
23 #include "src/core/SkOSFile.h"
24 #include "src/core/SkTSearch.h"
25 #include "src/core/SkTypefaceCache.h"
26 #include "src/ports/SkFontHost_FreeType_common.h"
27 #include "src/ports/SkFontMgr_android_parser.h"
28 
29 #include <algorithm>
30 #include <limits>
31 
32 class SkData;
33 
34 class SkTypeface_Android : public SkTypeface_FreeType {
35 public:
SkTypeface_Android(const SkFontStyle & style,bool isFixedPitch,const SkString & familyName)36     SkTypeface_Android(const SkFontStyle& style,
37                        bool isFixedPitch,
38                        const SkString& familyName)
39         : INHERITED(style, isFixedPitch)
40         , fFamilyName(familyName)
41         { }
42 
43 protected:
onGetFamilyName(SkString * familyName) const44     void onGetFamilyName(SkString* familyName) const override {
45         *familyName = fFamilyName;
46     }
47 
48     SkString fFamilyName;
49 
50 private:
51     using INHERITED = SkTypeface_FreeType;
52 };
53 
54 class SkTypeface_AndroidSystem : public SkTypeface_Android {
55 public:
SkTypeface_AndroidSystem(const SkString & pathName,const bool cacheFontFiles,int index,const SkFixed * axes,int axesCount,const SkFontStyle & style,bool isFixedPitch,const SkString & familyName,const SkTArray<SkLanguage,true> & lang,FontVariant variantStyle)56     SkTypeface_AndroidSystem(const SkString& pathName,
57                              const bool cacheFontFiles,
58                              int index,
59                              const SkFixed* axes, int axesCount,
60                              const SkFontStyle& style,
61                              bool isFixedPitch,
62                              const SkString& familyName,
63                              const SkTArray<SkLanguage, true>& lang,
64                              FontVariant variantStyle)
65         : INHERITED(style, isFixedPitch, familyName)
66         , fPathName(pathName)
67         , fIndex(index)
68         , fAxes(axes, axesCount)
69         , fLang(lang)
70         , fVariantStyle(variantStyle)
71         , fFile(cacheFontFiles ? sk_fopen(fPathName.c_str(), kRead_SkFILE_Flag) : nullptr) {
72         if (cacheFontFiles) {
73             SkASSERT(fFile);
74         }
75     }
76 
makeStream() const77     std::unique_ptr<SkStreamAsset> makeStream() const {
78         if (fFile) {
79             sk_sp<SkData> data(SkData::MakeFromFILE(fFile));
80             return data ? std::make_unique<SkMemoryStream>(std::move(data)) : nullptr;
81         }
82         return SkStream::MakeFromFile(fPathName.c_str());
83     }
84 
onGetFontDescriptor(SkFontDescriptor * desc,bool * serialize) const85     void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override {
86         SkASSERT(desc);
87         SkASSERT(serialize);
88         desc->setFamilyName(fFamilyName.c_str());
89         desc->setStyle(this->fontStyle());
90         *serialize = false;
91     }
onOpenStream(int * ttcIndex) const92     std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override {
93         *ttcIndex = fIndex;
94         return this->makeStream();
95     }
onMakeFontData() const96     std::unique_ptr<SkFontData> onMakeFontData() const override {
97         return std::make_unique<SkFontData>(
98                 this->makeStream(), fIndex, 0, fAxes.begin(), fAxes.count(), nullptr, 0);
99     }
onMakeClone(const SkFontArguments & args) const100     sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
101         std::unique_ptr<SkFontData> data = this->cloneFontData(args);
102         if (!data) {
103             return nullptr;
104         }
105         return sk_make_sp<SkTypeface_AndroidSystem>(fPathName,
106                                                     fFile,
107                                                     fIndex,
108                                                     data->getAxis(),
109                                                     data->getAxisCount(),
110                                                     this->fontStyle(),
111                                                     this->isFixedPitch(),
112                                                     fFamilyName,
113                                                     fLang,
114                                                     fVariantStyle);
115     }
116 
117     const SkString fPathName;
118     int fIndex;
119     const SkSTArray<4, SkFixed, true> fAxes;
120     const SkSTArray<4, SkLanguage, true> fLang;
121     const FontVariant fVariantStyle;
122     SkAutoTCallVProc<FILE, sk_fclose> fFile;
123 
124     using INHERITED = SkTypeface_Android;
125 };
126 
127 class SkTypeface_AndroidStream : public SkTypeface_Android {
128 public:
SkTypeface_AndroidStream(std::unique_ptr<SkFontData> data,const SkFontStyle & style,bool isFixedPitch,const SkString & familyName)129     SkTypeface_AndroidStream(std::unique_ptr<SkFontData> data,
130                              const SkFontStyle& style,
131                              bool isFixedPitch,
132                              const SkString& familyName)
133         : INHERITED(style, isFixedPitch, familyName)
134         , fData(std::move(data))
135     { }
136 
onGetFontDescriptor(SkFontDescriptor * desc,bool * serialize) const137     void onGetFontDescriptor(SkFontDescriptor* desc, bool* serialize) const override {
138         SkASSERT(desc);
139         SkASSERT(serialize);
140         desc->setFamilyName(fFamilyName.c_str());
141         SkTypeface_FreeType::FontDataPaletteToDescriptorPalette(*fData, desc);
142         *serialize = true;
143     }
144 
onOpenStream(int * ttcIndex) const145     std::unique_ptr<SkStreamAsset> onOpenStream(int* ttcIndex) const override {
146         *ttcIndex = fData->getIndex();
147         return fData->getStream()->duplicate();
148     }
149 
onMakeFontData() const150     std::unique_ptr<SkFontData> onMakeFontData() const override {
151         return std::make_unique<SkFontData>(*fData);
152     }
153 
onMakeClone(const SkFontArguments & args) const154     sk_sp<SkTypeface> onMakeClone(const SkFontArguments& args) const override {
155         std::unique_ptr<SkFontData> data = this->cloneFontData(args);
156         if (!data) {
157             return nullptr;
158         }
159         return sk_make_sp<SkTypeface_AndroidStream>(std::move(data),
160                                                     this->fontStyle(),
161                                                     this->isFixedPitch(),
162                                                     fFamilyName);
163     }
164 
165 private:
166     const std::unique_ptr<const SkFontData> fData;
167     using INHERITED = SkTypeface_Android;
168 };
169 
170 class SkFontStyleSet_Android : public SkFontStyleSet {
171     typedef SkTypeface_FreeType::Scanner Scanner;
172 
173 public:
SkFontStyleSet_Android(const FontFamily & family,const Scanner & scanner,const bool cacheFontFiles)174     explicit SkFontStyleSet_Android(const FontFamily& family, const Scanner& scanner,
175                                     const bool cacheFontFiles) {
176         const SkString* cannonicalFamilyName = nullptr;
177         if (family.fNames.count() > 0) {
178             cannonicalFamilyName = &family.fNames[0];
179         }
180         fFallbackFor = family.fFallbackFor;
181 
182         // TODO? make this lazy
183         for (int i = 0; i < family.fFonts.count(); ++i) {
184             const FontFileInfo& fontFile = family.fFonts[i];
185 
186             SkString pathName(family.fBasePath);
187             pathName.append(fontFile.fFileName);
188 
189             std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(pathName.c_str());
190             if (!stream) {
191                 SkDEBUGF("Requested font file %s does not exist or cannot be opened.\n",
192                          pathName.c_str());
193                 continue;
194             }
195 
196             const int ttcIndex = fontFile.fIndex;
197             SkString familyName;
198             SkFontStyle style;
199             bool isFixedWidth;
200             Scanner::AxisDefinitions axisDefinitions;
201             if (!scanner.scanFont(stream.get(), ttcIndex,
202                                   &familyName, &style, &isFixedWidth, &axisDefinitions))
203             {
204                 SkDEBUGF("Requested font file %s exists, but is not a valid font.\n",
205                          pathName.c_str());
206                 continue;
207             }
208 
209             int weight = fontFile.fWeight != 0 ? fontFile.fWeight : style.weight();
210             SkFontStyle::Slant slant = style.slant();
211             switch (fontFile.fStyle) {
212                 case FontFileInfo::Style::kAuto: slant = style.slant(); break;
213                 case FontFileInfo::Style::kNormal: slant = SkFontStyle::kUpright_Slant; break;
214                 case FontFileInfo::Style::kItalic: slant = SkFontStyle::kItalic_Slant; break;
215                 default: SkASSERT(false); break;
216             }
217             style = SkFontStyle(weight, style.width(), slant);
218 
219             uint32_t variant = family.fVariant;
220             if (kDefault_FontVariant == variant) {
221                 variant = kCompact_FontVariant | kElegant_FontVariant;
222             }
223 
224             // The first specified family name overrides the family name found in the font.
225             // TODO: SkTypeface_AndroidSystem::onCreateFamilyNameIterator should return
226             // all of the specified family names in addition to the names found in the font.
227             if (cannonicalFamilyName != nullptr) {
228                 familyName = *cannonicalFamilyName;
229             }
230 
231             SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
232             SkFontArguments::VariationPosition position = {
233                 fontFile.fVariationDesignPosition.begin(),
234                 fontFile.fVariationDesignPosition.count()
235             };
236             Scanner::computeAxisValues(axisDefinitions, position,
237                                        axisValues, familyName);
238 
239             fStyles.push_back().reset(new SkTypeface_AndroidSystem(
240                     pathName, cacheFontFiles, ttcIndex, axisValues.get(), axisDefinitions.count(),
241                     style, isFixedWidth, familyName, family.fLanguages, variant));
242         }
243     }
244 
count()245     int count() override {
246         return fStyles.count();
247     }
getStyle(int index,SkFontStyle * style,SkString * name)248     void getStyle(int index, SkFontStyle* style, SkString* name) override {
249         if (index < 0 || fStyles.count() <= index) {
250             return;
251         }
252         if (style) {
253             *style = fStyles[index]->fontStyle();
254         }
255         if (name) {
256             name->reset();
257         }
258     }
createTypeface(int index)259     SkTypeface_AndroidSystem* createTypeface(int index) override {
260         if (index < 0 || fStyles.count() <= index) {
261             return nullptr;
262         }
263         return SkRef(fStyles[index].get());
264     }
265 
matchStyle(const SkFontStyle & pattern)266     SkTypeface_AndroidSystem* matchStyle(const SkFontStyle& pattern) override {
267         return static_cast<SkTypeface_AndroidSystem*>(this->matchStyleCSS3(pattern));
268     }
269 
270 private:
271     SkTArray<sk_sp<SkTypeface_AndroidSystem>> fStyles;
272     SkString fFallbackFor;
273 
274     friend struct NameToFamily;
275     friend class SkFontMgr_Android;
276 
277     using INHERITED = SkFontStyleSet;
278 };
279 
280 /** On Android a single family can have many names, but our API assumes unique names.
281  *  Map names to the back end so that all names for a given family refer to the same
282  *  (non-replicated) set of typefaces.
283  *  SkTDict<> doesn't let us do index-based lookup, so we write our own mapping.
284  */
285 struct NameToFamily {
286     SkString name;
287     SkFontStyleSet_Android* styleSet;
288 };
289 
290 class SkFontMgr_Android : public SkFontMgr {
291 public:
SkFontMgr_Android(const SkFontMgr_Android_CustomFonts * custom)292     SkFontMgr_Android(const SkFontMgr_Android_CustomFonts* custom) {
293         SkTDArray<FontFamily*> families;
294         if (custom && SkFontMgr_Android_CustomFonts::kPreferSystem != custom->fSystemFontUse) {
295             SkString base(custom->fBasePath);
296             SkFontMgr_Android_Parser::GetCustomFontFamilies(
297                 families, base, custom->fFontsXml, custom->fFallbackFontsXml);
298         }
299         if (!custom ||
300             (custom && SkFontMgr_Android_CustomFonts::kOnlyCustom != custom->fSystemFontUse))
301         {
302             SkFontMgr_Android_Parser::GetSystemFontFamilies(families);
303         }
304         if (custom && SkFontMgr_Android_CustomFonts::kPreferSystem == custom->fSystemFontUse) {
305             SkString base(custom->fBasePath);
306             SkFontMgr_Android_Parser::GetCustomFontFamilies(
307                 families, base, custom->fFontsXml, custom->fFallbackFontsXml);
308         }
309         this->buildNameToFamilyMap(families, custom ? custom->fIsolated : false);
310         this->findDefaultStyleSet();
311         families.deleteAll();
312     }
313 
314 protected:
315     /** Returns not how many families we have, but how many unique names
316      *  exist among the families.
317      */
onCountFamilies() const318     int onCountFamilies() const override {
319         return fNameToFamilyMap.count();
320     }
321 
onGetFamilyName(int index,SkString * familyName) const322     void onGetFamilyName(int index, SkString* familyName) const override {
323         if (index < 0 || fNameToFamilyMap.count() <= index) {
324             familyName->reset();
325             return;
326         }
327         familyName->set(fNameToFamilyMap[index].name);
328     }
329 
onCreateStyleSet(int index) const330     SkFontStyleSet* onCreateStyleSet(int index) const override {
331         if (index < 0 || fNameToFamilyMap.count() <= index) {
332             return nullptr;
333         }
334         return SkRef(fNameToFamilyMap[index].styleSet);
335     }
336 
onMatchFamily(const char familyName[]) const337     SkFontStyleSet* onMatchFamily(const char familyName[]) const override {
338         if (!familyName) {
339             return nullptr;
340         }
341         SkAutoAsciiToLC tolc(familyName);
342         for (int i = 0; i < fNameToFamilyMap.count(); ++i) {
343             if (fNameToFamilyMap[i].name.equals(tolc.lc())) {
344                 return SkRef(fNameToFamilyMap[i].styleSet);
345             }
346         }
347         // TODO: eventually we should not need to name fallback families.
348         for (int i = 0; i < fFallbackNameToFamilyMap.count(); ++i) {
349             if (fFallbackNameToFamilyMap[i].name.equals(tolc.lc())) {
350                 return SkRef(fFallbackNameToFamilyMap[i].styleSet);
351             }
352         }
353         return nullptr;
354     }
355 
onMatchFamilyStyle(const char familyName[],const SkFontStyle & style) const356     SkTypeface* onMatchFamilyStyle(const char familyName[],
357                                    const SkFontStyle& style) const override {
358         sk_sp<SkFontStyleSet> sset(this->matchFamily(familyName));
359         return sset->matchStyle(style);
360     }
361 
find_family_style_character(const SkString & familyName,const SkTArray<NameToFamily,true> & fallbackNameToFamilyMap,const SkFontStyle & style,bool elegant,const SkString & langTag,SkUnichar character)362     static sk_sp<SkTypeface_AndroidSystem> find_family_style_character(
363             const SkString& familyName,
364             const SkTArray<NameToFamily, true>& fallbackNameToFamilyMap,
365             const SkFontStyle& style, bool elegant,
366             const SkString& langTag, SkUnichar character)
367     {
368         for (int i = 0; i < fallbackNameToFamilyMap.count(); ++i) {
369             SkFontStyleSet_Android* family = fallbackNameToFamilyMap[i].styleSet;
370             if (familyName != family->fFallbackFor) {
371                 continue;
372             }
373             sk_sp<SkTypeface_AndroidSystem> face(family->matchStyle(style));
374 
375             if (!langTag.isEmpty() &&
376                 std::none_of(face->fLang.begin(), face->fLang.end(), [&](SkLanguage lang){
377                     return lang.getTag().startsWith(langTag.c_str());
378                 }))
379             {
380                 continue;
381             }
382 
383             if (SkToBool(face->fVariantStyle & kElegant_FontVariant) != elegant) {
384                 continue;
385             }
386 
387             if (face->unicharToGlyph(character) != 0) {
388                 return face;
389             }
390         }
391         return nullptr;
392     }
393 
onMatchFamilyStyleCharacter(const char familyName[],const SkFontStyle & style,const char * bcp47[],int bcp47Count,SkUnichar character) const394     SkTypeface* onMatchFamilyStyleCharacter(const char familyName[],
395                                             const SkFontStyle& style,
396                                             const char* bcp47[],
397                                             int bcp47Count,
398                                             SkUnichar character) const override {
399         // The variant 'elegant' is 'not squashed', 'compact' is 'stays in ascent/descent'.
400         // The variant 'default' means 'compact and elegant'.
401         // As a result, it is not possible to know the variant context from the font alone.
402         // TODO: add 'is_elegant' and 'is_compact' bits to 'style' request.
403 
404         SkString familyNameString(familyName);
405         for (const SkString& currentFamilyName : { familyNameString, SkString() }) {
406             // The first time match anything elegant, second time anything not elegant.
407             for (int elegant = 2; elegant --> 0;) {
408                 for (int bcp47Index = bcp47Count; bcp47Index --> 0;) {
409                     SkLanguage lang(bcp47[bcp47Index]);
410                     while (!lang.getTag().isEmpty()) {
411                         sk_sp<SkTypeface_AndroidSystem> matchingTypeface =
412                             find_family_style_character(currentFamilyName, fFallbackNameToFamilyMap,
413                                                         style, SkToBool(elegant),
414                                                         lang.getTag(), character);
415                         if (matchingTypeface) {
416                             return matchingTypeface.release();
417                         }
418 
419                         lang = lang.getParent();
420                     }
421                 }
422                 sk_sp<SkTypeface_AndroidSystem> matchingTypeface =
423                     find_family_style_character(currentFamilyName, fFallbackNameToFamilyMap,
424                                                 style, SkToBool(elegant),
425                                                 SkString(), character);
426                 if (matchingTypeface) {
427                     return matchingTypeface.release();
428                 }
429             }
430         }
431         return nullptr;
432     }
433 
onMakeFromData(sk_sp<SkData> data,int ttcIndex) const434     sk_sp<SkTypeface> onMakeFromData(sk_sp<SkData> data, int ttcIndex) const override {
435         return this->makeFromStream(std::unique_ptr<SkStreamAsset>(new SkMemoryStream(std::move(data))),
436                                     ttcIndex);
437     }
438 
onMakeFromFile(const char path[],int ttcIndex) const439     sk_sp<SkTypeface> onMakeFromFile(const char path[], int ttcIndex) const override {
440         std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path);
441         return stream ? this->makeFromStream(std::move(stream), ttcIndex) : nullptr;
442     }
443 
onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,int ttcIndex) const444     sk_sp<SkTypeface> onMakeFromStreamIndex(std::unique_ptr<SkStreamAsset> stream,
445                                             int ttcIndex) const override {
446         bool isFixedPitch;
447         SkFontStyle style;
448         SkString name;
449         if (!fScanner.scanFont(stream.get(), ttcIndex, &name, &style, &isFixedPitch, nullptr)) {
450             return nullptr;
451         }
452         auto data = std::make_unique<SkFontData>(std::move(stream), ttcIndex, 0,
453                                                  nullptr, 0, nullptr, 0);
454         return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data),
455                                                               style, isFixedPitch, name));
456     }
457 
onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,const SkFontArguments & args) const458     sk_sp<SkTypeface> onMakeFromStreamArgs(std::unique_ptr<SkStreamAsset> stream,
459                                            const SkFontArguments& args) const override {
460         using Scanner = SkTypeface_FreeType::Scanner;
461         bool isFixedPitch;
462         SkFontStyle style;
463         SkString name;
464         Scanner::AxisDefinitions axisDefinitions;
465         if (!fScanner.scanFont(stream.get(), args.getCollectionIndex(),
466                                &name, &style, &isFixedPitch, &axisDefinitions))
467         {
468             return nullptr;
469         }
470 
471         SkAutoSTMalloc<4, SkFixed> axisValues(axisDefinitions.count());
472         Scanner::computeAxisValues(axisDefinitions, args.getVariationDesignPosition(),
473                                    axisValues, name);
474 
475         auto data = std::make_unique<SkFontData>(
476             std::move(stream), args.getCollectionIndex(), args.getPalette().index,
477             axisValues.get(), axisDefinitions.count(),
478             args.getPalette().overrides, args.getPalette().overrideCount);
479         return sk_sp<SkTypeface>(new SkTypeface_AndroidStream(std::move(data),
480                                                               style, isFixedPitch, name));
481     }
482 
onLegacyMakeTypeface(const char familyName[],SkFontStyle style) const483     sk_sp<SkTypeface> onLegacyMakeTypeface(const char familyName[], SkFontStyle style) const override {
484         if (familyName) {
485             // On Android, we must return nullptr when we can't find the requested
486             // named typeface so that the system/app can provide their own recovery
487             // mechanism. On other platforms we'd provide a typeface from the
488             // default family instead.
489             return sk_sp<SkTypeface>(this->onMatchFamilyStyle(familyName, style));
490         }
491         return sk_sp<SkTypeface>(fDefaultStyleSet->matchStyle(style));
492     }
493 
494 
495 private:
496 
497     SkTypeface_FreeType::Scanner fScanner;
498 
499     SkTArray<sk_sp<SkFontStyleSet_Android>> fStyleSets;
500     sk_sp<SkFontStyleSet> fDefaultStyleSet;
501 
502     SkTArray<NameToFamily, true> fNameToFamilyMap;
503     SkTArray<NameToFamily, true> fFallbackNameToFamilyMap;
504 
addFamily(FontFamily & family,const bool isolated,int familyIndex)505     void addFamily(FontFamily& family, const bool isolated, int familyIndex) {
506         SkTArray<NameToFamily, true>* nameToFamily = &fNameToFamilyMap;
507         if (family.fIsFallbackFont) {
508             nameToFamily = &fFallbackNameToFamilyMap;
509 
510             if (0 == family.fNames.count()) {
511                 SkString& fallbackName = family.fNames.push_back();
512                 fallbackName.printf("%.2x##fallback", familyIndex);
513             }
514         }
515 
516         sk_sp<SkFontStyleSet_Android> newSet =
517             sk_make_sp<SkFontStyleSet_Android>(family, fScanner, isolated);
518         if (0 == newSet->count()) {
519             return;
520         }
521 
522         for (const SkString& name : family.fNames) {
523             nameToFamily->emplace_back(NameToFamily{name, newSet.get()});
524         }
525         fStyleSets.emplace_back(std::move(newSet));
526     }
buildNameToFamilyMap(SkTDArray<FontFamily * > families,const bool isolated)527     void buildNameToFamilyMap(SkTDArray<FontFamily*> families, const bool isolated) {
528         int familyIndex = 0;
529         for (FontFamily* family : families) {
530             addFamily(*family, isolated, familyIndex++);
531             for (const auto& [unused, fallbackFamily] : family->fallbackFamilies) {
532                 addFamily(*fallbackFamily, isolated, familyIndex++);
533             }
534         }
535     }
536 
findDefaultStyleSet()537     void findDefaultStyleSet() {
538         SkASSERT(!fStyleSets.empty());
539 
540         static const char* defaultNames[] = { "sans-serif" };
541         for (const char* defaultName : defaultNames) {
542             fDefaultStyleSet.reset(this->onMatchFamily(defaultName));
543             if (fDefaultStyleSet) {
544                 break;
545             }
546         }
547         if (nullptr == fDefaultStyleSet) {
548             fDefaultStyleSet = fStyleSets[0];
549         }
550         SkASSERT(fDefaultStyleSet);
551     }
552 
553     using INHERITED = SkFontMgr;
554 };
555 
556 #ifdef SK_DEBUG
557 static char const * const gSystemFontUseStrings[] = {
558     "OnlyCustom", "PreferCustom", "PreferSystem"
559 };
560 #endif
561 
SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts * custom)562 sk_sp<SkFontMgr> SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts* custom) {
563     if (custom) {
564         SkASSERT(0 <= custom->fSystemFontUse);
565         SkASSERT(custom->fSystemFontUse < SK_ARRAY_COUNT(gSystemFontUseStrings));
566         SkDEBUGF("SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s\n",
567                  gSystemFontUseStrings[custom->fSystemFontUse],
568                  custom->fBasePath,
569                  custom->fFontsXml,
570                  custom->fFallbackFontsXml);
571     }
572     return sk_make_sp<SkFontMgr_Android>(custom);
573 }
574