mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +00:00
lottie/text: added range selector flags
Duplicated text document properties (fill color, stroke color, and stroke width) to the text range. If these properties are not defined in the range selector, ThorVG incorrectly overrides them with default values. The correct behavior is to preserve the original values. The added flags address this issue. Co-Authored-By: Hermet Park<hermet@lottiefiles.com>
This commit is contained in:
parent
2b3cdb0d97
commit
fbe10255d7
3 changed files with 48 additions and 19 deletions
|
@ -1082,25 +1082,13 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo)
|
||||||
opacity = (uint8_t)(opacity - f * (opacity - range->style.opacity(frameNo, tween, exps)));
|
opacity = (uint8_t)(opacity - f * (opacity - range->style.opacity(frameNo, tween, exps)));
|
||||||
shape->opacity(opacity);
|
shape->opacity(opacity);
|
||||||
|
|
||||||
auto rangeColor = range->style.fillColor(frameNo, tween, exps); //TODO: use flag to check whether it was really set
|
range->color(frameNo, color, strokeColor, f, tween, exps);
|
||||||
if (tvg::equal(f, 1.0f)) color = rangeColor;
|
|
||||||
else {
|
|
||||||
color.rgb[0] = tvg::lerp<uint8_t>(color.rgb[0], rangeColor.rgb[0], f);
|
|
||||||
color.rgb[1] = tvg::lerp<uint8_t>(color.rgb[1], rangeColor.rgb[1], f);
|
|
||||||
color.rgb[2] = tvg::lerp<uint8_t>(color.rgb[2], rangeColor.rgb[2], f);
|
|
||||||
}
|
|
||||||
fillOpacity = (uint8_t)(fillOpacity - f * (fillOpacity - range->style.fillOpacity(frameNo, tween, exps)));
|
fillOpacity = (uint8_t)(fillOpacity - f * (fillOpacity - range->style.fillOpacity(frameNo, tween, exps)));
|
||||||
shape->fill(color.rgb[0], color.rgb[1], color.rgb[2], fillOpacity);
|
shape->fill(color.rgb[0], color.rgb[1], color.rgb[2], fillOpacity);
|
||||||
|
|
||||||
shape->strokeWidth(f * range->style.strokeWidth(frameNo, tween, exps) / scale);
|
if (range->style.flags.strokeWidth) shape->strokeWidth(f * range->style.strokeWidth(frameNo, tween, exps) / scale);
|
||||||
if (shape->strokeWidth() > 0.0f) {
|
if (shape->strokeWidth() > 0.0f) {
|
||||||
auto rangeColor = range->style.strokeColor(frameNo, tween, exps); //TODO: use flag to check whether it was really set
|
|
||||||
if (tvg::equal(f, 1.0f)) strokeColor = rangeColor;
|
|
||||||
else {
|
|
||||||
strokeColor.rgb[0] = tvg::lerp<uint8_t>(strokeColor.rgb[0], rangeColor.rgb[0], f);
|
|
||||||
strokeColor.rgb[1] = tvg::lerp<uint8_t>(strokeColor.rgb[1], rangeColor.rgb[1], f);
|
|
||||||
strokeColor.rgb[2] = tvg::lerp<uint8_t>(strokeColor.rgb[2], rangeColor.rgb[2], f);
|
|
||||||
}
|
|
||||||
strokeOpacity = (uint8_t)(strokeOpacity - f * (strokeOpacity - range->style.strokeOpacity(frameNo, tween, exps)));
|
strokeOpacity = (uint8_t)(strokeOpacity - f * (strokeOpacity - range->style.strokeOpacity(frameNo, tween, exps)));
|
||||||
shape->strokeFill(strokeColor.rgb[0], strokeColor.rgb[1], strokeColor.rgb[2], strokeOpacity);
|
shape->strokeFill(strokeColor.rgb[0], strokeColor.rgb[1], strokeColor.rgb[2], strokeOpacity);
|
||||||
shape->order(doc.stroke.below);
|
shape->order(doc.stroke.below);
|
||||||
|
|
|
@ -258,6 +258,13 @@ struct LottieTextRange
|
||||||
enum Shape : uint8_t { Square = 1, RampUp, RampDown, Triangle, Round, Smooth };
|
enum Shape : uint8_t { Square = 1, RampUp, RampDown, Triangle, Round, Smooth };
|
||||||
enum Unit : uint8_t { Percent = 1, Index };
|
enum Unit : uint8_t { Percent = 1, Index };
|
||||||
|
|
||||||
|
LottieTextRange()
|
||||||
|
{
|
||||||
|
style.flags.fillColor = 0;
|
||||||
|
style.flags.strokeColor = 0;
|
||||||
|
style.flags.strokeWidth = 0;
|
||||||
|
}
|
||||||
|
|
||||||
~LottieTextRange()
|
~LottieTextRange()
|
||||||
{
|
{
|
||||||
tvg::free(interpolator);
|
tvg::free(interpolator);
|
||||||
|
@ -275,6 +282,11 @@ struct LottieTextRange
|
||||||
LottieOpacity fillOpacity = 255;
|
LottieOpacity fillOpacity = 255;
|
||||||
LottieOpacity strokeOpacity = 255;
|
LottieOpacity strokeOpacity = 255;
|
||||||
LottieOpacity opacity = 255;
|
LottieOpacity opacity = 255;
|
||||||
|
struct {
|
||||||
|
bool fillColor : 1;
|
||||||
|
bool strokeColor : 1;
|
||||||
|
bool strokeWidth : 1;
|
||||||
|
} flags;
|
||||||
} style;
|
} style;
|
||||||
|
|
||||||
LottieFloat offset = 0.0f;
|
LottieFloat offset = 0.0f;
|
||||||
|
@ -292,6 +304,22 @@ struct LottieTextRange
|
||||||
bool expressible = false;
|
bool expressible = false;
|
||||||
|
|
||||||
float factor(float frameNo, float totalLen, float idx);
|
float factor(float frameNo, float totalLen, float idx);
|
||||||
|
|
||||||
|
void color(float frameNo, RGB24& fillColor, RGB24& strokeColor, float factor, Tween& tween, LottieExpressions* exps)
|
||||||
|
{
|
||||||
|
if (style.flags.fillColor) {
|
||||||
|
auto color = style.fillColor(frameNo, tween, exps);
|
||||||
|
fillColor.rgb[0] = tvg::lerp<uint8_t>(fillColor.rgb[0], color.rgb[0], factor);
|
||||||
|
fillColor.rgb[1] = tvg::lerp<uint8_t>(fillColor.rgb[1], color.rgb[1], factor);
|
||||||
|
fillColor.rgb[2] = tvg::lerp<uint8_t>(fillColor.rgb[2], color.rgb[2], factor);
|
||||||
|
}
|
||||||
|
if (style.flags.strokeColor) {
|
||||||
|
auto color = style.strokeColor(frameNo, tween, exps);
|
||||||
|
strokeColor.rgb[0] = tvg::lerp<uint8_t>(strokeColor.rgb[0], color.rgb[0], factor);
|
||||||
|
strokeColor.rgb[1] = tvg::lerp<uint8_t>(strokeColor.rgb[1], color.rgb[1], factor);
|
||||||
|
strokeColor.rgb[2] = tvg::lerp<uint8_t>(strokeColor.rgb[2], color.rgb[2], factor);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1132,7 +1132,8 @@ void LottieParser::parseTextRange(LottieText* text)
|
||||||
enterObject();
|
enterObject();
|
||||||
while (auto key = nextObjectKey()) {
|
while (auto key = nextObjectKey()) {
|
||||||
if (KEY_AS("t")) selector->expressible = (bool) getInt();
|
if (KEY_AS("t")) selector->expressible = (bool) getInt();
|
||||||
else if (KEY_AS("xe")) {
|
else if (KEY_AS("xe"))
|
||||||
|
{
|
||||||
parseProperty(selector->maxEase);
|
parseProperty(selector->maxEase);
|
||||||
selector->interpolator = tvg::malloc<LottieInterpolator*>(sizeof(LottieInterpolator));
|
selector->interpolator = tvg::malloc<LottieInterpolator*>(sizeof(LottieInterpolator));
|
||||||
}
|
}
|
||||||
|
@ -1153,10 +1154,22 @@ void LottieParser::parseTextRange(LottieText* text)
|
||||||
while (auto key = nextObjectKey()) {
|
while (auto key = nextObjectKey()) {
|
||||||
if (KEY_AS("t")) parseProperty(selector->style.letterSpacing);
|
if (KEY_AS("t")) parseProperty(selector->style.letterSpacing);
|
||||||
else if (KEY_AS("ls")) parseProperty(selector->style.lineSpacing);
|
else if (KEY_AS("ls")) parseProperty(selector->style.lineSpacing);
|
||||||
else if (KEY_AS("fc")) parseProperty(selector->style.fillColor);
|
else if (KEY_AS("fc"))
|
||||||
|
{
|
||||||
|
parseProperty(selector->style.fillColor);
|
||||||
|
selector->style.flags.fillColor = true;
|
||||||
|
}
|
||||||
else if (KEY_AS("fo")) parseProperty(selector->style.fillOpacity);
|
else if (KEY_AS("fo")) parseProperty(selector->style.fillOpacity);
|
||||||
else if (KEY_AS("sw")) parseProperty(selector->style.strokeWidth);
|
else if (KEY_AS("sw"))
|
||||||
else if (KEY_AS("sc")) parseProperty(selector->style.strokeColor);
|
{
|
||||||
|
parseProperty(selector->style.strokeWidth);
|
||||||
|
selector->style.flags.strokeWidth = true;
|
||||||
|
}
|
||||||
|
else if (KEY_AS("sc"))
|
||||||
|
{
|
||||||
|
parseProperty(selector->style.strokeColor);
|
||||||
|
selector->style.flags.strokeColor = true;
|
||||||
|
}
|
||||||
else if (KEY_AS("so")) parseProperty(selector->style.strokeOpacity);
|
else if (KEY_AS("so")) parseProperty(selector->style.strokeOpacity);
|
||||||
else if (KEY_AS("o")) parseProperty(selector->style.opacity);
|
else if (KEY_AS("o")) parseProperty(selector->style.opacity);
|
||||||
else if (KEY_AS("p")) parseProperty(selector->style.position);
|
else if (KEY_AS("p")) parseProperty(selector->style.position);
|
||||||
|
|
Loading…
Add table
Reference in a new issue