SkFontMgr_android.cpp 23 KB

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