mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-10 06:34:01 +00:00
lottie: specify the explicit parsing type.
these explicit type values are expected to be referenced by the expressions.
This commit is contained in:
parent
acd42f3bfa
commit
060f858568
2 changed files with 46 additions and 49 deletions
|
@ -339,11 +339,11 @@ void LottieParser::getInperpolatorPoint(Point& pt)
|
|||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
template<LottieProperty::Type type, typename T>
|
||||
void LottieParser::parseSlotProperty(T& prop)
|
||||
{
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("p")) parseProperty(prop);
|
||||
if (KEY_AS("p")) parseProperty<type>(prop);
|
||||
else skip(key);
|
||||
}
|
||||
}
|
||||
|
@ -499,9 +499,9 @@ LottieRect* LottieParser::parseRect()
|
|||
context.parent = rect;
|
||||
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("s")) parseProperty(rect->size);
|
||||
else if (KEY_AS("p")) parseProperty(rect->position);
|
||||
else if (KEY_AS("r")) parseProperty(rect->radius);
|
||||
if (KEY_AS("s")) parseProperty<LottieProperty::Type::Point>(rect->size);
|
||||
else if (KEY_AS("p"))parseProperty<LottieProperty::Type::Position>(rect->position);
|
||||
else if (KEY_AS("r")) parseProperty<LottieProperty::Type::Float>(rect->radius);
|
||||
else if (KEY_AS("nm")) rect->name = getStringCopy();
|
||||
else if (KEY_AS("hd")) rect->hidden = getBool();
|
||||
else skip(key);
|
||||
|
@ -520,8 +520,8 @@ LottieEllipse* LottieParser::parseEllipse()
|
|||
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("nm")) ellipse->name = getStringCopy();
|
||||
else if (KEY_AS("p")) parseProperty(ellipse->position);
|
||||
else if (KEY_AS("s")) parseProperty(ellipse->size);
|
||||
else if (KEY_AS("p")) parseProperty<LottieProperty::Type::Position>(ellipse->position);
|
||||
else if (KEY_AS("s")) parseProperty<LottieProperty::Type::Point>(ellipse->size);
|
||||
else if (KEY_AS("hd")) ellipse->hidden = getBool();
|
||||
else skip(key);
|
||||
}
|
||||
|
@ -548,23 +548,20 @@ LottieTransform* LottieParser::parseTransform(bool ddd)
|
|||
enterObject();
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("k")) parsePropertyInternal(transform->position);
|
||||
else if (KEY_AS("s")) {
|
||||
if (getBool()) transform->coords = new LottieTransform::SeparateCoord;
|
||||
else if (KEY_AS("s") && getBool()) transform->coords = new LottieTransform::SeparateCoord;
|
||||
//check separateCoord to figure out whether "x(expression)" / "x(coord)"
|
||||
} else if (transform->coords && KEY_AS("x")) {
|
||||
parseProperty(transform->coords->x);
|
||||
} else if (transform->coords && KEY_AS("y")) {
|
||||
parseProperty(transform->coords->y);
|
||||
} else skip(key);
|
||||
else if (transform->coords && KEY_AS("x")) parseProperty<LottieProperty::Type::Float>(transform->coords->x);
|
||||
else if (transform->coords && KEY_AS("y")) parseProperty<LottieProperty::Type::Float>(transform->coords->y);
|
||||
else skip(key);
|
||||
}
|
||||
}
|
||||
else if (KEY_AS("a")) parseProperty(transform->anchor);
|
||||
else if (KEY_AS("s")) parseProperty(transform->scale);
|
||||
else if (KEY_AS("r")) parseProperty(transform->rotation);
|
||||
else if (KEY_AS("o")) parseProperty(transform->opacity);
|
||||
else if (transform->rotationEx && KEY_AS("rx")) parseProperty(transform->rotationEx->x);
|
||||
else if (transform->rotationEx && KEY_AS("ry")) parseProperty(transform->rotationEx->y);
|
||||
else if (transform->rotationEx && KEY_AS("rz")) parseProperty(transform->rotation);
|
||||
else if (KEY_AS("a")) parseProperty<LottieProperty::Type::Point>(transform->anchor);
|
||||
else if (KEY_AS("s")) parseProperty<LottieProperty::Type::Point>(transform->scale);
|
||||
else if (KEY_AS("r")) parseProperty<LottieProperty::Type::Float>(transform->rotation);
|
||||
else if (KEY_AS("o")) parseProperty<LottieProperty::Type::Opacity>(transform->opacity);
|
||||
else if (transform->rotationEx && KEY_AS("rx")) parseProperty<LottieProperty::Type::Float>(transform->rotationEx->x);
|
||||
else if (transform->rotationEx && KEY_AS("ry")) parseProperty<LottieProperty::Type::Float>(transform->rotationEx->y);
|
||||
else if (transform->rotationEx && KEY_AS("rz")) parseProperty<LottieProperty::Type::Float>(transform->rotation);
|
||||
else if (KEY_AS("nm")) transform->name = getStringCopy();
|
||||
//else if (KEY_AS("sk")) //TODO: skew
|
||||
//else if (KEY_AS("sa")) //TODO: skew axis
|
||||
|
@ -609,7 +606,7 @@ void LottieParser::parseStrokeDash(LottieStroke* stroke)
|
|||
else if (!strcmp("d", style)) idx = 1; //dash
|
||||
else if (!strcmp("g", style)) idx = 2; //gap
|
||||
} else if (KEY_AS("v")) {
|
||||
parseProperty(stroke->dash(idx));
|
||||
parseProperty<LottieProperty::Type::Float>(stroke->dash(idx));
|
||||
} else skip(key);
|
||||
}
|
||||
}
|
||||
|
@ -682,13 +679,13 @@ LottiePolyStar* LottieParser::parsePolyStar()
|
|||
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("nm")) star->name = getStringCopy();
|
||||
else if (KEY_AS("p")) parseProperty(star->position);
|
||||
else if (KEY_AS("pt")) parseProperty(star->ptsCnt);
|
||||
else if (KEY_AS("ir")) parseProperty(star->innerRadius);
|
||||
else if (KEY_AS("is")) parseProperty(star->innerRoundness);
|
||||
else if (KEY_AS("or")) parseProperty(star->outerRadius);
|
||||
else if (KEY_AS("os")) parseProperty(star->outerRoundness);
|
||||
else if (KEY_AS("r")) parseProperty(star->rotation);
|
||||
else if (KEY_AS("p")) parseProperty<LottieProperty::Type::Position>(star->position);
|
||||
else if (KEY_AS("pt")) parseProperty<LottieProperty::Type::Float>(star->ptsCnt);
|
||||
else if (KEY_AS("ir")) parseProperty<LottieProperty::Type::Float>(star->innerRadius);
|
||||
else if (KEY_AS("is")) parseProperty<LottieProperty::Type::Float>(star->innerRoundness);
|
||||
else if (KEY_AS("or")) parseProperty<LottieProperty::Type::Float>(star->outerRadius);
|
||||
else if (KEY_AS("os")) parseProperty<LottieProperty::Type::Float>(star->outerRoundness);
|
||||
else if (KEY_AS("r")) parseProperty<LottieProperty::Type::Float>(star->rotation);
|
||||
else if (KEY_AS("sy")) star->type = (LottiePolyStar::Type) getInt();
|
||||
else if (KEY_AS("hd")) star->hidden = getBool();
|
||||
else skip(key);
|
||||
|
@ -707,7 +704,7 @@ LottieRoundedCorner* LottieParser::parseRoundedCorner()
|
|||
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("nm")) corner->name = getStringCopy();
|
||||
else if (KEY_AS("r")) parseProperty(corner->radius);
|
||||
else if (KEY_AS("r")) parseProperty<LottieProperty::Type::Float>(corner->radius);
|
||||
else if (KEY_AS("hd")) corner->hidden = getBool();
|
||||
else skip(key);
|
||||
}
|
||||
|
@ -770,7 +767,7 @@ LottieGradientStroke* LottieParser::parseGradientStroke()
|
|||
else if (KEY_AS("lj")) stroke->join = getStrokeJoin();
|
||||
else if (KEY_AS("ml")) stroke->miterLimit = getFloat();
|
||||
else if (KEY_AS("hd")) stroke->hidden = getBool();
|
||||
else if (KEY_AS("w")) parseProperty(stroke->width);
|
||||
else if (KEY_AS("w")) parseProperty<LottieProperty::Type::Float>(stroke->width);
|
||||
else if (KEY_AS("d")) parseStrokeDash(stroke);
|
||||
else parseGradient(stroke, key);
|
||||
}
|
||||
|
@ -789,9 +786,9 @@ LottieTrimpath* LottieParser::parseTrimpath()
|
|||
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("nm")) trim->name = getStringCopy();
|
||||
else if (KEY_AS("s")) parseProperty(trim->start);
|
||||
else if (KEY_AS("e")) parseProperty(trim->end);
|
||||
else if (KEY_AS("o")) parseProperty(trim->offset);
|
||||
else if (KEY_AS("s")) parseProperty<LottieProperty::Type::Float>(trim->start);
|
||||
else if (KEY_AS("e")) parseProperty<LottieProperty::Type::Float>(trim->end);
|
||||
else if (KEY_AS("o")) parseProperty<LottieProperty::Type::Float>(trim->offset);
|
||||
else if (KEY_AS("m")) trim->type = static_cast<LottieTrimpath::Type>(getInt());
|
||||
else if (KEY_AS("hd")) trim->hidden = getBool();
|
||||
else skip(key);
|
||||
|
@ -811,19 +808,19 @@ LottieRepeater* LottieParser::parseRepeater()
|
|||
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("nm")) repeater->name = getStringCopy();
|
||||
else if (KEY_AS("c")) parseProperty(repeater->copies);
|
||||
else if (KEY_AS("o")) parseProperty(repeater->offset);
|
||||
else if (KEY_AS("c")) parseProperty<LottieProperty::Type::Float>(repeater->copies);
|
||||
else if (KEY_AS("o")) parseProperty<LottieProperty::Type::Float>(repeater->offset);
|
||||
else if (KEY_AS("m")) repeater->inorder = getInt();
|
||||
else if (KEY_AS("tr"))
|
||||
{
|
||||
enterObject();
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("a")) parseProperty(repeater->anchor);
|
||||
else if (KEY_AS("p")) parseProperty(repeater->position);
|
||||
else if (KEY_AS("r")) parseProperty(repeater->rotation);
|
||||
else if (KEY_AS("s")) parseProperty(repeater->scale);
|
||||
else if (KEY_AS("so")) parseProperty(repeater->startOpacity);
|
||||
else if (KEY_AS("eo")) parseProperty(repeater->endOpacity);
|
||||
if (KEY_AS("a")) parseProperty<LottieProperty::Type::Point>(repeater->anchor);
|
||||
else if (KEY_AS("p")) parseProperty<LottieProperty::Type::Position>(repeater->position);
|
||||
else if (KEY_AS("r")) parseProperty<LottieProperty::Type::Float>(repeater->rotation);
|
||||
else if (KEY_AS("s")) parseProperty<LottieProperty::Type::Point>(repeater->scale);
|
||||
else if (KEY_AS("so")) parseProperty<LottieProperty::Type::Opacity>(repeater->startOpacity);
|
||||
else if (KEY_AS("eo")) parseProperty<LottieProperty::Type::Opacity>(repeater->endOpacity);
|
||||
else skip(key);
|
||||
}
|
||||
}
|
||||
|
@ -1057,7 +1054,7 @@ LottieObject* LottieParser::parseGroup()
|
|||
|
||||
void LottieParser::parseTimeRemap(LottieLayer* layer)
|
||||
{
|
||||
parseProperty(layer->timeRemap);
|
||||
parseProperty<LottieProperty::Type::Float>(layer->timeRemap);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1105,7 +1102,7 @@ void LottieParser::parseTextRange(LottieText* text)
|
|||
if (KEY_AS("a")) { //text style
|
||||
enterObject();
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("t")) parseProperty(text->spacing);
|
||||
if (KEY_AS("t")) parseProperty<LottieProperty::Type::Float>(text->spacing);
|
||||
else skip(key);
|
||||
}
|
||||
} else skip(key);
|
||||
|
@ -1155,7 +1152,7 @@ LottieMask* LottieParser::parseMask()
|
|||
if (KEY_AS("inv")) mask->inverse = getBool();
|
||||
else if (KEY_AS("mode")) mask->method = getMaskMethod(mask->inverse);
|
||||
else if (KEY_AS("pt")) getPathSet(mask->pathset);
|
||||
else if (KEY_AS("o")) parseProperty(mask->opacity);
|
||||
else if (KEY_AS("o")) parseProperty<LottieProperty::Type::Opacity>(mask->opacity);
|
||||
else skip(key);
|
||||
}
|
||||
|
||||
|
@ -1307,19 +1304,19 @@ bool LottieParser::apply(LottieSlot* slot)
|
|||
case LottieProperty::Type::ColorStop: {
|
||||
obj = new LottieGradient;
|
||||
context.parent = obj;
|
||||
parseSlotProperty(static_cast<LottieGradient*>(obj)->colorStops);
|
||||
parseSlotProperty<LottieProperty::Type::ColorStop>(static_cast<LottieGradient*>(obj)->colorStops);
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::Color: {
|
||||
obj = new LottieSolid;
|
||||
context.parent = obj;
|
||||
parseSlotProperty(static_cast<LottieSolid*>(obj)->color);
|
||||
parseSlotProperty<LottieProperty::Type::Color>(static_cast<LottieSolid*>(obj)->color);
|
||||
break;
|
||||
}
|
||||
case LottieProperty::Type::TextDoc: {
|
||||
obj = new LottieText;
|
||||
context.parent = obj;
|
||||
parseSlotProperty(static_cast<LottieText*>(obj)->doc);
|
||||
parseSlotProperty<LottieProperty::Type::TextDoc>(static_cast<LottieText*>(obj)->doc);
|
||||
break;
|
||||
}
|
||||
default: break;
|
||||
|
|
|
@ -70,7 +70,7 @@ private:
|
|||
template<typename T> void parseKeyFrame(T& prop);
|
||||
template<typename T> void parsePropertyInternal(T& prop);
|
||||
template<LottieProperty::Type type = LottieProperty::Type::Invalid, typename T> void parseProperty(T& prop, LottieObject* obj = nullptr);
|
||||
template<typename T> void parseSlotProperty(T& prop);
|
||||
template<LottieProperty::Type type = LottieProperty::Type::Invalid, typename T> void parseSlotProperty(T& prop);
|
||||
|
||||
LottieObject* parseObject();
|
||||
LottieObject* parseAsset();
|
||||
|
|
Loading…
Add table
Reference in a new issue