loader lottie: support for stroke dash style

However, dash offset is still missing.
The TVG canvas needs to add the stroke offset feature.
This commit is contained in:
Hermet Park 2023-08-09 23:16:45 +09:00 committed by Hermet Park
parent 9960cc4794
commit 1b020f70c4
7 changed files with 60 additions and 12 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -156,6 +156,13 @@ static Shape* _updateStroke(LottieSolidStroke* stroke, int32_t frameNo, Shape* b
baseShape->stroke(stroke->cap); baseShape->stroke(stroke->cap);
baseShape->stroke(stroke->join); baseShape->stroke(stroke->join);
baseShape->strokeMiterlimit(stroke->miterLimit); baseShape->strokeMiterlimit(stroke->miterLimit);
//TODO: offset
if (stroke->dashattr) {
float dashes[2] = { stroke->dashSize(frameNo), stroke->dashGap(frameNo) };
baseShape->stroke(dashes, 2);
}
return nullptr; return nullptr;
} }

View file

@ -32,20 +32,53 @@ struct LottieComposition;
struct LottieStroke struct LottieStroke
{ {
struct DashAttr
{
//0: offset, 1: dash, 2: gap
LottieFloat value[3] = {0.0f, 0.0f, 0.0f};
};
virtual ~LottieStroke()
{
delete(dashattr);
}
LottieFloat& dash(int no)
{
if (!dashattr) dashattr = new DashAttr;
return dashattr->value[no];
}
float dashOffset(int32_t frameNo)
{
return dash(0)(frameNo);
}
float dashGap(int32_t frameNo)
{
return dash(1)(frameNo) + dash(2)(frameNo);
}
float dashSize(int32_t frameNo)
{
return dash(1)(frameNo);
}
bool dynamic() bool dynamic()
{ {
if (dash.frames || width.frames) return true; if (width.frames || dashattr) return true;
return false; return false;
} }
LottieFloat dash = 0.0f;
LottieFloat width = 0.0f; LottieFloat width = 0.0f;
DashAttr* dashattr = nullptr;
float miterLimit = 0;
StrokeCap cap = StrokeCap::Butt; StrokeCap cap = StrokeCap::Butt;
StrokeJoin join = StrokeJoin::Miter; StrokeJoin join = StrokeJoin::Miter;
float miterLimit = 0;
}; };
struct LottieGradient struct LottieGradient
{ {
bool dynamic() bool dynamic()

View file

@ -586,8 +586,16 @@ void LottieParser::parseStrokeDash(LottieStroke* stroke)
enterArray(); enterArray();
while (nextArrayValue()) { while (nextArrayValue()) {
enterObject(); enterObject();
int idx = 0;
while (auto key = nextObjectKey()) { while (auto key = nextObjectKey()) {
if (!strcmp(key, "v")) { if (!strcmp(key, "n")) {
auto style = getString();
if (!strcmp("o", style)) idx = 0; //offset
else if (!strcmp("d", style)) idx = 1; //dash
else if (!strcmp("g", style)) idx = 2; //gap
else TVGERR("LOTTIE", "Unsupported Dash Style");
} else if (!strcmp(key, "v")) {
parseProperty(stroke->dash(idx));
} else skip(key); } else skip(key);
} }
} }
@ -609,12 +617,7 @@ LottieSolidStroke* LottieParser::parseSolidStroke()
else if (!strcmp(key, "nm")) stroke->name = getStringCopy(); else if (!strcmp(key, "nm")) stroke->name = getStringCopy();
else if (!strcmp(key, "hd")) stroke->hidden = getBool(); else if (!strcmp(key, "hd")) stroke->hidden = getBool();
else if (!strcmp(key, "fillEnabled")) stroke->disabled = !getBool(); else if (!strcmp(key, "fillEnabled")) stroke->disabled = !getBool();
else if (!strcmp(key, "d")) else if (!strcmp(key, "d")) parseStrokeDash(stroke);
{
TVGLOG("LOTTIE", "StrokeDash(d) is not supported");
skip(key);
//parseStrokeDash(stroke);
}
else skip(key); else skip(key);
} }
stroke->prepare(); stroke->prepare();
@ -998,6 +1001,11 @@ LottieLayer* LottieParser::parseLayer()
} }
else if (!strcmp(key, "hd")) layer->hidden = getBool(); else if (!strcmp(key, "hd")) layer->hidden = getBool();
else if (!strcmp(key, "refId")) layer->refId = getStringCopy(); else if (!strcmp(key, "refId")) layer->refId = getStringCopy();
else if (!strcmp(key, "ef"))
{
TVGLOG("LOTTIE", "Effect(ef) is not supported");
skip(key);
}
else skip(key); else skip(key);
} }