lottie: code clean up

This commit is contained in:
Hermet Park 2024-11-01 22:43:07 +09:00
parent 4f2e725da0
commit c75ec0f333
3 changed files with 20 additions and 24 deletions

View file

@ -985,7 +985,7 @@ void LottieBuilder::updateImage(LottieGroup* layer)
void LottieBuilder::updateText(LottieLayer* layer, float frameNo)
{
auto text = static_cast<LottieText*>(layer->children.first());
auto textGrouping = text->alignmentOption.grouping;
auto textGrouping = text->alignOption.grouping;
auto& doc = text->doc(frameNo);
auto p = doc.text;
@ -1127,7 +1127,7 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo)
identity(&textGroupMatrix);
translate(&textGroupMatrix, cursor.x, cursor.y);
auto alignment = text->alignmentOption.anchor(frameNo);
auto alignment = text->alignOption.anchor(frameNo);
// center pivoting
textGroupMatrix.e13 += alignment.x;

View file

@ -179,29 +179,26 @@ struct LottieGlyph
};
struct LottieTextStyle
{
LottieColor fillColor = RGB24{255, 255, 255};
LottieColor strokeColor = RGB24{255, 255, 255};
LottiePosition position = Point{0, 0};
LottiePoint scale = Point{100, 100};
LottieFloat letterSpacing = 0.0f;
LottieFloat lineSpacing = 0.0f;
LottieFloat strokeWidth = 0.0f;
LottieFloat rotation = 0.0f;
LottieOpacity fillOpacity = 255;
LottieOpacity strokeOpacity = 255;
LottieOpacity opacity = 255;
};
struct LottieTextRange
{
enum Based : uint8_t { Chars = 1, CharsExcludingSpaces, Words, Lines };
enum Shape : uint8_t { Square = 1, RampUp, RampDown, Triangle, Round, Smooth };
enum Unit : uint8_t { Percent = 1, Index };
LottieTextStyle style;
struct {
LottieColor fillColor = RGB24{255, 255, 255};
LottieColor strokeColor = RGB24{255, 255, 255};
LottiePosition position = Point{0, 0};
LottiePoint scale = Point{100, 100};
LottieFloat letterSpacing = 0.0f;
LottieFloat lineSpacing = 0.0f;
LottieFloat strokeWidth = 0.0f;
LottieFloat rotation = 0.0f;
LottieOpacity fillOpacity = 255;
LottieOpacity strokeOpacity = 255;
LottieOpacity opacity = 255;
} style;
LottieFloat offset = 0.0f;
LottieFloat maxEase = 0.0f;
LottieFloat minEase = 0.0f;
@ -257,8 +254,8 @@ struct LottieText : LottieObject, LottieRenderPooler<tvg::Shape>
{
enum Group : uint8_t { Chars = 1, Word = 2, Line = 3, All = 4 };
Group grouping = Chars;
LottiePoint anchor = Point{0.0f, 0.0f};
};
LottiePoint anchor{};
} alignOption;
void prepare()
{
@ -280,7 +277,6 @@ struct LottieText : LottieObject, LottieRenderPooler<tvg::Shape>
LottieTextDoc doc;
LottieFont* font;
Array<LottieTextRange*> ranges;
AlignOption alignmentOption;
~LottieText()
{

View file

@ -1133,8 +1133,8 @@ void LottieParser::parseTextAlignmentOption(LottieText* text)
{
enterObject();
while (auto key = nextObjectKey()) {
if (KEY_AS("g")) text->alignmentOption.grouping = (LottieText::AlignOption::Group) getInt();
else if (KEY_AS("a")) parseProperty<LottieProperty::Type::Point>(text->alignmentOption.anchor);
if (KEY_AS("g")) text->alignOption.grouping = (LottieText::AlignOption::Group) getInt();
else if (KEY_AS("a")) parseProperty<LottieProperty::Type::Point>(text->alignOption.anchor);
else skip(key);
}
}