45 , fFamilyName(familyName)
49 void onGetFamilyName(
SkString* familyName)
const override {
50 *familyName = fFamilyName;
59class SkTypeface_AndroidSystem :
public SkTypeface_Android {
61 SkTypeface_AndroidSystem(
const SkString& pathName,
62 const bool cacheFontFiles,
64 const SkFixed* axes,
int axesCount,
70 :
INHERITED(style, isFixedPitch, familyName)
73 , fAxes(axes, axesCount)
75 , fVariantStyle(variantStyle)
82 std::unique_ptr<SkStreamAsset> makeStream()
const {
85 return data ? std::make_unique<SkMemoryStream>(std::move(
data)) : nullptr;
93 desc->setFamilyName(fFamilyName.c_str());
94 desc->setStyle(this->fontStyle());
98 std::unique_ptr<SkStreamAsset> onOpenStream(
int* ttcIndex)
const override {
100 return this->makeStream();
102 std::unique_ptr<SkFontData> onMakeFontData()
const override {
103 return std::make_unique<SkFontData>(
104 this->makeStream(), fIndex, 0, fAxes.begin(), fAxes.size(),
nullptr, 0);
108 std::unique_ptr<SkFontData>
data = this->cloneFontData(
args, &style);
112 return sk_make_sp<SkTypeface_AndroidSystem>(fPathName,
116 data->getAxisCount(),
118 this->isFixedPitch(),
135 return sk_sp<D>(
static_cast<D*
>(
s.release()));
141 const bool cacheFontFiles) {
142 const SkString* cannonicalFamilyName =
nullptr;
144 cannonicalFamilyName = &family.
fNames[0];
157 SkDEBUGF(
"Requested font file %s does not exist or cannot be opened.\n",
162 const int ttcIndex = fontFile.
fIndex;
168 &familyName, &style, &isFixedWidth, &axisDefinitions))
170 SkDEBUGF(
"Requested font file %s exists, but is not a valid font.\n",
177 switch (fontFile.
fStyle) {
193 if (cannonicalFamilyName !=
nullptr) {
194 familyName = *cannonicalFamilyName;
203 axisDefinitions, position, axisValues, familyName, &style);
205 fStyles.push_back().reset(
new SkTypeface_AndroidSystem(
206 pathName, cacheFontFiles, ttcIndex, axisValues.get(), axisDefinitions.
size(),
207 style, isFixedWidth, familyName, family.
fLanguages, variant));
211 int count()
override {
212 return fStyles.size();
215 if (index < 0 || fStyles.size() <= index) {
219 *style = fStyles[index]->fontStyle();
226 if (index < 0 || fStyles.size() <= index) {
229 return fStyles[index];
233 return sk_sp_static_cast<SkTypeface_AndroidSystem>(this->matchStyleCSS3(pattern));
236 return this->matchAStyle(pattern);
243 friend struct NameToFamily;
244 friend class SkFontMgr_Android;
256 SkFontStyleSet_Android* styleSet;
259class SkFontMgr_Android :
public SkFontMgr {
262 std::unique_ptr<SkFontScanner> scanner)
263 : fScanner(
std::move(scanner)) {
280 this->buildNameToFamilyMap(families, custom ? custom->
fIsolated :
false);
281 this->findDefaultStyleSet();
292 int onCountFamilies()
const override {
293 return fNameToFamilyMap.size();
296 void onGetFamilyName(
int index,
SkString* familyName)
const override {
297 if (index < 0 || fNameToFamilyMap.size() <= index) {
301 familyName->
set(fNameToFamilyMap[index].
name);
305 if (index < 0 || fNameToFamilyMap.size() <= index) {
308 return sk_ref_sp(fNameToFamilyMap[index].styleSet);
316 for (
int i = 0;
i < fNameToFamilyMap.size(); ++
i) {
317 if (fNameToFamilyMap[
i].
name.equals(tolc.lc())) {
318 return sk_ref_sp(fNameToFamilyMap[
i].styleSet);
322 for (
int i = 0;
i < fFallbackNameToFamilyMap.size(); ++
i) {
323 if (fFallbackNameToFamilyMap[
i].
name.equals(tolc.lc())) {
324 return sk_ref_sp(fFallbackNameToFamilyMap[
i].styleSet);
333 return sset->matchStyle(style);
342 for (
int i = 0;
i < fallbackNameToFamilyMap.
size(); ++
i) {
343 SkFontStyleSet_Android* family = fallbackNameToFamilyMap[
i].styleSet;
344 if (familyName != family->fFallbackFor) {
350 std::none_of(face->fLang.begin(), face->fLang.end(), [&](
const SkLanguage&
lang){
351 return lang.getTag().startsWith(langTag.c_str());
361 if (face->unicharToGlyph(
character) != 0) {
378 SkString familyNameString(familyName);
379 for (
const SkString& currentFamilyName : { familyNameString,
SkString() }) {
381 for (
int elegant = 2; elegant --> 0;) {
382 for (
int bcp47Index = bcp47Count; bcp47Index --> 0;) {
384 while (!
lang.getTag().isEmpty()) {
386 find_family_style_character(currentFamilyName, fFallbackNameToFamilyMap,
389 if (matchingTypeface) {
390 return matchingTypeface;
397 find_family_style_character(currentFamilyName, fFallbackNameToFamilyMap,
400 if (matchingTypeface) {
401 return matchingTypeface;
409 return this->makeFromStream(std::unique_ptr<SkStreamAsset>(
new SkMemoryStream(std::move(
data))),
415 return stream ? this->makeFromStream(std::move(
stream), ttcIndex) : nullptr;
419 int ttcIndex)
const override {
420 return this->makeFromStream(std::move(
stream),
443 std::unique_ptr<SkFontScanner> fScanner;
451 void addFamily(
FontFamily& family,
const bool isolated,
int familyIndex) {
454 nameToFamily = &fFallbackNameToFamilyMap;
458 fallbackName.
printf(
"%.2x##fallback", (uint32_t)familyIndex);
463 sk_make_sp<SkFontStyleSet_Android>(family, fScanner.get(), isolated);
464 if (0 == newSet->count()) {
476 addFamily(*family, isolated, familyIndex++);
478 addFamily(*fallbackFamily, isolated, familyIndex++);
483 void findDefaultStyleSet() {
486 static const char* defaultNames[] = {
"sans-serif" };
487 for (
const char* defaultName : defaultNames) {
488 fDefaultStyleSet = this->onMatchFamily(defaultName);
489 if (fDefaultStyleSet) {
493 if (
nullptr == fDefaultStyleSet) {
494 fDefaultStyleSet = fStyleSets[0];
503static char const *
const gSystemFontUseStrings[] = {
504 "OnlyCustom",
"PreferCustom",
"PreferSystem"
519 SkDEBUGF(
"SystemFontUse: %s BasePath: %s Fonts: %s FallbackFonts: %s\n",
525 return sk_make_sp<SkFontMgr_Android>(custom, std::move(scanner));
sk_sp< SkFontMgr > SkFontMgr_New_Android(const SkFontMgr_Android_CustomFonts *custom)
FILE * sk_fopen(const char path[], SkFILE_Flags)
#define INHERITED(method,...)
sk_sp< T > sk_ref_sp(T *obj)
static constexpr bool SkToBool(const T &x)
const void * data() const
static sk_sp< SkData > MakeFromFILE(FILE *f)
static void computeAxisValues(AxisDefinitions axisDefinitions, const SkFontArguments::VariationPosition position, SkFixed *axisValues, const SkString &name, SkFontStyle *style, const SkFontArguments::VariationPosition::Coordinate *currentPosition=nullptr)
virtual bool scanInstance(SkStreamAsset *stream, int faceIndex, int instanceIndex, SkString *name, SkFontStyle *style, bool *isFixedPitch, AxisDefinitions *axes) const =0
static std::unique_ptr< SkStreamAsset > MakeFromFile(const char path[])
void printf(const char format[],...) SK_PRINTF_LIKE(2
void set(const SkString &src)
void append(const char text[])
const char * c_str() const
static sk_sp< SkTypeface > MakeFromStream(std::unique_ptr< SkStreamAsset >, const SkFontArguments &)
T & emplace_back(Args &&... args)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
void GetCustomFontFamilies(SkTDArray< FontFamily * > &fontFamilies, const SkString &basePath, const char *fontsXml, const char *fallbackFontsXml, const char *langFallbackFontsDir=nullptr)
void GetSystemFontFamilies(SkTDArray< FontFamily * > &fontFamilies)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
DEF_SWITCHES_START aot vmservice shared library name
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
skia_private::TArray< SkString, true > fNames
skia_private::THashMap< SkString, std::unique_ptr< FontFamily > > fallbackFamilies
skia_private::TArray< SkLanguage, true > fLanguages
skia_private::TArray< FontFileInfo, true > fFonts
enum FontFileInfo::Style fStyle
skia_private::TArray< SkFontArguments::VariationPosition::Coordinate, true > fVariationDesignPosition
const char * fFallbackFontsXml
SystemFontUse fSystemFontUse