From e4834e91902e90de101c44acf4adedeecfb280dd Mon Sep 17 00:00:00 2001 From: Jinny You Date: Tue, 11 Mar 2025 13:39:55 +0900 Subject: [PATCH] lottie/text: render carriage return with local font (#3310) Added missing carriage return support in local font case. issue: #3301 --- src/loaders/lottie/tvgLottieBuilder.cpp | 42 +++++++++++++++++-------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/src/loaders/lottie/tvgLottieBuilder.cpp b/src/loaders/lottie/tvgLottieBuilder.cpp index 0317972c..67b8c0cd 100644 --- a/src/loaders/lottie/tvgLottieBuilder.cpp +++ b/src/loaders/lottie/tvgLottieBuilder.cpp @@ -912,26 +912,42 @@ void LottieBuilder::updateImage(LottieGroup* layer) } +//TODO: unify with the updateText() building logic static void _fontText(LottieText* text, Scene* scene, float frameNo, LottieExpressions* exps) { auto& doc = text->doc(frameNo, exps); if (!doc.text) return; + auto delim = "\r\n"; auto size = doc.size * 75.0f; //1 pt = 1/72; 1 in = 96 px; -> 72/96 = 0.75 - auto txt = Text::gen(); - if (txt->font(doc.name, size) != Result::Success) { - //fallback to any available font - txt->font(nullptr, size); + auto lineHeight = doc.size * 100.0f; + + auto buf = (char*)alloca(strlen(doc.text) + 1); + strcpy(buf, doc.text); + auto token = std::strtok(buf, delim); + + auto cnt = 0; + while (token) { + auto txt = Text::gen(); + if (txt->font(doc.name, size) != Result::Success) { + //fallback to any available font + txt->font(nullptr, size); + } + + txt->text(token); + txt->fill(doc.color.rgb[0], doc.color.rgb[1], doc.color.rgb[2]); + + float width; + txt->bounds(nullptr, nullptr, &width, nullptr); + + auto cursorX = width * doc.justify; + auto cursorY = lineHeight * cnt; + txt->translate(cursorX, -lineHeight + cursorY); + + token = std::strtok(nullptr, delim); + scene->push(txt); + cnt++; } - txt->text(doc.text); - txt->fill(doc.color.rgb[0], doc.color.rgb[1], doc.color.rgb[2]); - - float width; - txt->bounds(nullptr, nullptr, &width, nullptr); - - auto cursorX = width * doc.justify; - txt->translate(cursorX, -doc.size * 100.0f); - scene->push(txt); }