loaders: added lottie, svg font fallback mechanism

fallback for allowing any available fonts.

Co-Authored-By: Hermet Park <hermet@lottiefiles.com>
This commit is contained in:
Jinny You 2025-02-20 12:42:41 +09:00 committed by Hermet Park
parent 8e5ca40250
commit 646e35484f
2 changed files with 14 additions and 9 deletions

View file

@ -889,18 +889,21 @@ void LottieBuilder::updateImage(LottieGroup* layer)
} }
void _fontURLText(LottieText* text, Scene* main, float frameNo, Tween& tween, LottieExpressions* exps) static void _fontText(LottieText* text, Scene* scene, float frameNo, LottieExpressions* exps)
{ {
auto& doc = text->doc(frameNo, exps); auto& doc = text->doc(frameNo, exps);
if (!doc.text) return; if (!doc.text) return;
const float ptPerPx = 0.75f; //1 pt = 1/72; 1 in = 96 px; -> 72/96 = 0.75 auto size = doc.size * 75.0f; //1 pt = 1/72; 1 in = 96 px; -> 72/96 = 0.75
auto txt = Text::gen(); auto txt = Text::gen();
txt->font(doc.name, doc.size * 100.0f * ptPerPx); if (txt->font(doc.name, size) != Result::Success) {
//fallback to any available font
txt->font(nullptr, size);
}
txt->translate(0.0f, -doc.size * 100.0f); txt->translate(0.0f, -doc.size * 100.0f);
txt->text(doc.text); txt->text(doc.text);
txt->fill(doc.color.rgb[0], doc.color.rgb[1], doc.color.rgb[2]); txt->fill(doc.color.rgb[0], doc.color.rgb[1], doc.color.rgb[2]);
main->push(txt); scene->push(txt);
} }
@ -913,8 +916,8 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo)
if (!p || !text->font) return; if (!p || !text->font) return;
if (text->font->origin == LottieFont::Origin::FontURL) { if (text->font->origin != LottieFont::Origin::Embedded) {
_fontURLText(text, layer->scene, frameNo, tween, exps); _fontText(text, layer->scene, frameNo, exps);
return; return;
} }

View file

@ -886,9 +886,11 @@ static Paint* _textBuildHelper(SvgLoaderData& loaderData, const SvgNode* node, c
text->transform(textTransform); text->transform(textTransform);
//TODO: handle def values of font and size as used in a system? //TODO: handle def values of font and size as used in a system?
const float ptPerPx = 0.75f; //1 pt = 1/72; 1 in = 96 px; -> 72/96 = 0.75 auto size = textNode->fontSize * 0.75f; //1 pt = 1/72; 1 in = 96 px; -> 72/96 = 0.75
auto fontSizePt = textNode->fontSize * ptPerPx; if (text->font(textNode->fontFamily, size) != Result::Success) {
if (textNode->fontFamily) text->font(textNode->fontFamily, fontSizePt); //fallback to any available font
text->font(nullptr, size);
}
text->text(textNode->text); text->text(textNode->text);
_applyTextFill(node->style, text, vBox); _applyTextFill(node->style, text, vBox);