// SkFuchsiaFontDataCache keep track of SkData created from `fuchsia::mem::Buffer` where each buffer // is identified with a unique identifier. It allows to share the same SkData instances between all // SkTypeface instances created from the same buffer. class SkFuchsiaFontDataCache : public SkRefCnt { public:
SkFuchsiaFontDataCache() = default;
~SkFuchsiaFontDataCache() { SkASSERT(fBuffers.empty()); }
auto context = new ReleaseSkDataContext{sk_ref_sp(this), bufferId}; auto data = SkData::MakeWithProc( reinterpret_cast<void*>(mapped_addr), size, ReleaseSkData, context);
SkASSERT(data);
fuchsia::fonts::Slant SkToFuchsiaSlant(SkFontStyle::Slant slant) { switch (slant) { case SkFontStyle::kOblique_Slant: return fuchsia::fonts::Slant::OBLIQUE; case SkFontStyle::kItalic_Slant: return fuchsia::fonts::Slant::ITALIC; case SkFontStyle::kUpright_Slant: default: return fuchsia::fonts::Slant::UPRIGHT;
}
}
SkFontStyle::Slant FuchsiaToSkSlant(fuchsia::fonts::Slant slant) { switch (slant) { case fuchsia::fonts::Slant::OBLIQUE: return SkFontStyle::kOblique_Slant; case fuchsia::fonts::Slant::ITALIC: return SkFontStyle::kItalic_Slant; case fuchsia::fonts::Slant::UPRIGHT: default: return SkFontStyle::kUpright_Slant;
}
}
fuchsia::fonts::Width SkToFuchsiaWidth(SkFontStyle::Width width) { switch (width) { case SkFontStyle::Width::kUltraCondensed_Width: return fuchsia::fonts::Width::ULTRA_CONDENSED; case SkFontStyle::Width::kExtraCondensed_Width: return fuchsia::fonts::Width::EXTRA_CONDENSED; case SkFontStyle::Width::kCondensed_Width: return fuchsia::fonts::Width::CONDENSED; case SkFontStyle::Width::kSemiCondensed_Width: return fuchsia::fonts::Width::SEMI_CONDENSED; case SkFontStyle::Width::kNormal_Width: return fuchsia::fonts::Width::NORMAL; case SkFontStyle::Width::kSemiExpanded_Width: return fuchsia::fonts::Width::SEMI_EXPANDED; case SkFontStyle::Width::kExpanded_Width: return fuchsia::fonts::Width::EXPANDED; case SkFontStyle::Width::kExtraExpanded_Width: return fuchsia::fonts::Width::EXTRA_EXPANDED; case SkFontStyle::Width::kUltraExpanded_Width: return fuchsia::fonts::Width::ULTRA_EXPANDED;
}
}
// Tries to convert the given integer Skia style width value to the Fuchsia equivalent. // // On success, returns true. On failure, returns false, and `outFuchsiaWidth` is left untouched. bool SkToFuchsiaWidth(int skWidth, fuchsia::fonts::Width* outFuchsiaWidth) { if (skWidth < SkFontStyle::Width::kUltraCondensed_Width ||
skWidth > SkFontStyle::Width::kUltraExpanded_Width) { returnfalse;
} auto typedSkWidth = static_cast<SkFontStyle::Width>(skWidth);
*outFuchsiaWidth = SkToFuchsiaWidth(typedSkWidth); returntrue;
}
SkFontStyle::Width FuchsiaToSkWidth(fuchsia::fonts::Width width) { switch (width) { case fuchsia::fonts::Width::ULTRA_CONDENSED: return SkFontStyle::Width::kUltraCondensed_Width; case fuchsia::fonts::Width::EXTRA_CONDENSED: return SkFontStyle::Width::kExtraCondensed_Width; case fuchsia::fonts::Width::CONDENSED: return SkFontStyle::Width::kCondensed_Width; case fuchsia::fonts::Width::SEMI_CONDENSED: return SkFontStyle::Width::kSemiCondensed_Width; case fuchsia::fonts::Width::NORMAL: return SkFontStyle::Width::kNormal_Width; case fuchsia::fonts::Width::SEMI_EXPANDED: return SkFontStyle::Width::kSemiExpanded_Width; case fuchsia::fonts::Width::EXPANDED: return SkFontStyle::Width::kExpanded_Width; case fuchsia::fonts::Width::EXTRA_EXPANDED: return SkFontStyle::Width::kExtraExpanded_Width; case fuchsia::fonts::Width::ULTRA_EXPANDED: return SkFontStyle::Width::kUltraExpanded_Width;
}
}
// Tries to find a generic font family with the given name. If none is found, returns false. bool GetGenericFontFamilyByName(constchar* name,
fuchsia::fonts::GenericFontFamily* outGenericFamily) { if (!name) returnfalse; for (auto& genericFamily : kGenericFontFamiliesByName) { if (strcasecmp(genericFamily.fName, name) == 0) {
*outGenericFamily = genericFamily.fGenericFontFamily; returntrue;
}
} returnfalse;
}
if (bcp47Count > 0) {
std::vector<fuchsia::intl::LocaleId> languages{}; for (int i = 0; i < bcp47Count; i++) {
fuchsia::intl::LocaleId localeId;
localeId.id = bcp47[i];
languages.push_back(localeId);
}
query.set_languages(std::move(languages));
}
if (character) {
query.set_code_points({static_cast<uint32_t>(character)});
}
// If family name is not specified or is a generic family name (e.g. "serif"), then enable // fallback; otherwise, pass the family name as is.
fuchsia::fonts::GenericFontFamily genericFontFamily =
fuchsia::fonts::GenericFontFamily::SANS_SERIF; bool isGenericFontFamily = GetGenericFontFamilyByName(familyName, &genericFontFamily); if (!familyName || *familyName == '\0' || isGenericFontFamily) { if (isGenericFontFamily) {
query.set_fallback_family(genericFontFamily);
}
allow_fallback = true;
} else {
fuchsia::fonts::FamilyName typedFamilyName{};
typedFamilyName.name = familyName;
query.set_family(typedFamilyName);
}
fuchsia::fonts::TypefaceRequestFlags flags{}; if (!allow_fallback) flags |= fuchsia::fonts::TypefaceRequestFlags::EXACT_FAMILY; if (exact_style_match) flags |= fuchsia::fonts::TypefaceRequestFlags::EXACT_STYLE;
fuchsia::fonts::TypefaceResponse response; int result = fFontProvider->GetTypeface(std::move(request), &response); if (result != ZX_OK) return nullptr;
// The service may return an empty response if there is no font matching the request. if (response.IsEmpty()) return nullptr;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.