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