lottie/text: render carriage return with local font (#3310)

Added missing carriage return support in local font case.

issue: #3301
This commit is contained in:
Jinny You 2025-03-11 13:39:55 +09:00 committed by GitHub
parent 488fd88ce1
commit e4834e9190
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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);
}