37template <
typename T,
typename TMap>
38const char* parse_map(
const TMap&
map,
const char* str,
T*
result) {
40 while (*str ==
' ') ++str;
42 const char* next_tok = strchr(str,
' ');
44 if (
const auto len = next_tok ? (next_tok - str) : strlen(str)) {
45 for (
const auto&
e :
map) {
58 static constexpr std::tuple<const char*, SkFontStyle::Weight> gWeightMap[] = {
84 static constexpr std::tuple<const char*, SkFontStyle::Slant> gSlantMap[] = {
94 style = lc_style.lc();
95 style = parse_map(gWeightMap, style, &weight);
96 style = parse_map(gSlantMap , style, &slant );
99 while (*style ==
' ') ++style;
151 if (!jname || !jname->
size() ||
152 !jfamily || !jfamily->
size() ||
160 SkString(jfamily->begin(), jfamily->size()),
161 SkString( jstyle->begin(), jstyle->size()),
162 jpath ? SkString( jpath->begin(), jpath->size()) : SkString(),
163 ParseDefault((*jfont)[
"ascent"] , 0.0f),
165 CustomFont::Builder()
178 if (ParseDefault<int>((*jchar)[
"t"], 0) == 1) {
193 const auto prioritize_embedded_fonts =
197 if (jchars && prioritize_embedded_fonts && this->resolveEmbeddedTypefaces(*jchars)) {
202 if (this->resolveNativeTypefaces()) {
207 if (jchars && !prioritize_embedded_fonts) {
208 this->resolveEmbeddedTypefaces(*jchars);
212bool AnimationBuilder::resolveNativeTypefaces() {
213 bool has_unresolved =
false;
215 fFonts.foreach([&](
const SkString&
name, FontInfo* finfo) {
218 if (finfo->fTypeface) {
228 finfo->fTypeface = fResourceProvider->loadTypeface(
name.c_str(), finfo->fPath.c_str());
232 if (!finfo->fTypeface && fFontMgr) {
234 fResourceProvider->loadFont(
name.c_str(), finfo->fPath.c_str()));
237 if (!finfo->fTypeface && fFontMgr) {
241 if (!finfo->fTypeface) {
243 finfo->fFamily.c_str(), finfo->fStyle.c_str());
248 has_unresolved |= !finfo->fTypeface;
251 if (!finfo->fTypeface && !fFontMgr) {
253 "Could not load typeface for %s|%s because no SkFontMgr provided.",
254 finfo->fFamily.c_str(), finfo->fStyle.c_str());
258 return !has_unresolved;
270 FontInfo* current_font =
nullptr;
280 if (!jfamily || !jstyle) {
284 const auto* family = jfamily->
begin();
285 const auto* style = jstyle->
begin();
291 if (!current_font || !current_font->matches(family, style)) {
292 current_font =
nullptr;
293 fFonts.foreach([&](
const SkString&
name, FontInfo* finfo) {
294 if (finfo->matches(family, style)) {
295 current_font = finfo;
301 "Font not found (%s, %s).", family, style);
306 if (!current_font->fCustomFontBuilder.parseGlyph(
this, *jchar)) {
312 bool has_unresolved =
false;
313 std::vector<std::unique_ptr<CustomFont>> custom_fonts;
314 fFonts.foreach([&has_unresolved, &custom_fonts](
const SkString&, FontInfo* finfo) {
315 if (finfo->fTypeface) {
319 auto font = finfo->fCustomFontBuilder.detach();
321 finfo->fTypeface =
font->typeface();
323 if (
font->glyphCompCount() > 0) {
324 custom_fonts.push_back(std::move(font));
327 has_unresolved |= !finfo->fTypeface;
331 if (!custom_fonts.empty()) {
332 custom_fonts.shrink_to_fit();
333 fCustomGlyphMapper = sk_make_sp<CustomFont::GlyphCompMapper>(std::move(custom_fonts));
336 return !has_unresolved;
341 return this->attachDiscardableAdapter<TextAdapter>(jlayer,
350 return fFonts.find(font_name);
sk_sp< SkTypeface > makeFromData(sk_sp< SkData >, int ttcIndex=0) const
sk_sp< SkTypeface > legacyMakeTypeface(const char familyName[], SkFontStyle style) const
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
const char * c_str() const
const char * begin() const
void parseFonts(const skjson::ObjectValue *jfonts, const skjson::ArrayValue *jchars)
void log(Logger::Level, const skjson::Value *, const char fmt[],...) const SK_PRINTF_LIKE(4
const FontInfo * findFont(const SkString &name) const
DEF_SWITCHES_START aot vmservice shared library name
font
Font Metadata and Metrics.
const myers::Point & get< 1 >(const myers::Segment &s)
const myers::Point & get< 0 >(const myers::Segment &s)
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
bool matches(const char family[], const char style[]) const