mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-26 16:16:46 +00:00
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:
parent
8e5ca40250
commit
646e35484f
2 changed files with 14 additions and 9 deletions
|
@ -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);
|
||||
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();
|
||||
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->text(doc.text);
|
||||
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 (text->font->origin == LottieFont::Origin::FontURL) {
|
||||
_fontURLText(text, layer->scene, frameNo, tween, exps);
|
||||
if (text->font->origin != LottieFont::Origin::Embedded) {
|
||||
_fontText(text, layer->scene, frameNo, exps);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -886,9 +886,11 @@ static Paint* _textBuildHelper(SvgLoaderData& loaderData, const SvgNode* node, c
|
|||
text->transform(textTransform);
|
||||
|
||||
//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 fontSizePt = textNode->fontSize * ptPerPx;
|
||||
if (textNode->fontFamily) text->font(textNode->fontFamily, fontSizePt);
|
||||
auto size = textNode->fontSize * 0.75f; //1 pt = 1/72; 1 in = 96 px; -> 72/96 = 0.75
|
||||
if (text->font(textNode->fontFamily, size) != Result::Success) {
|
||||
//fallback to any available font
|
||||
text->font(nullptr, size);
|
||||
}
|
||||
text->text(textNode->text);
|
||||
|
||||
_applyTextFill(node->style, text, vBox);
|
||||
|
|
Loading…
Add table
Reference in a new issue