mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-07 21:23:32 +00:00
Merge 927fd537e5
into 0fa5d41c8d
This commit is contained in:
commit
483f0edec2
4 changed files with 62 additions and 19 deletions
|
@ -852,10 +852,12 @@ LottieOffsetPath* LottieParser::parseOffsetPath()
|
|||
}
|
||||
|
||||
|
||||
LottieObject* LottieParser::parseObject()
|
||||
LottieObject* LottieParser::parseObject(const char* type)
|
||||
{
|
||||
auto type = getString();
|
||||
if (!type) {
|
||||
type = getString();
|
||||
if (!type) return nullptr;
|
||||
}
|
||||
|
||||
if (!strcmp(type, "gr")) return parseGroup();
|
||||
else if (!strcmp(type, "rc")) return parseRect();
|
||||
|
@ -882,6 +884,24 @@ LottieObject* LottieParser::parseObject()
|
|||
void LottieParser::parseObject(Array<LottieObject*>& parent)
|
||||
{
|
||||
enterObject();
|
||||
|
||||
|
||||
//object type key is not listed as the first one
|
||||
auto value = peekValue();
|
||||
if (value && strcmp(value->GetString(), "ty")) {
|
||||
if (auto type = findObjectType()) {
|
||||
if (auto child = parseObject(type)) {
|
||||
if (child->hidden) delete (child);
|
||||
else parent.push(child);
|
||||
} else {
|
||||
//skip unsupported type
|
||||
while (nextObjectKey()) skip();
|
||||
}
|
||||
free(type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//object type key either listed as the first one or never - skip the entire object
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("ty")) {
|
||||
if (auto child = parseObject()) {
|
||||
|
@ -1095,21 +1115,8 @@ void LottieParser::parseTimeRemap(LottieLayer* layer)
|
|||
|
||||
void LottieParser::parseShapes(Array<LottieObject*>& parent)
|
||||
{
|
||||
enterArray();
|
||||
while (nextArrayValue()) {
|
||||
enterObject();
|
||||
while (auto key = nextObjectKey()) {
|
||||
if (KEY_AS("it")) {
|
||||
enterArray();
|
||||
while (nextArrayValue()) parseObject(parent);
|
||||
} else if (KEY_AS("ty")) {
|
||||
if (auto child = parseObject()) {
|
||||
if (child->hidden) delete(child);
|
||||
else parent.push(child);
|
||||
}
|
||||
} else skip();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ private:
|
|||
template<typename T> void parseProperty(T& prop, LottieObject* obj = nullptr);
|
||||
template<typename T> void parseSlotProperty(T& prop);
|
||||
|
||||
LottieObject* parseObject();
|
||||
LottieObject* parseObject(const char* type = nullptr);
|
||||
LottieObject* parseAsset();
|
||||
void parseImage(LottieImage* image, const char* data, const char* subPath, bool embedded, float width, float height);
|
||||
LottieLayer* parseLayer(LottieLayer* precomp);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/*
|
||||
/*
|
||||
* Copyright (c) 2023 - 2025 the ThorVG project. All rights reserved.
|
||||
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
@ -44,6 +44,7 @@
|
|||
|
||||
#include "tvgStr.h"
|
||||
#include "tvgLottieParserHandler.h"
|
||||
#include "tvgStr.h"
|
||||
|
||||
|
||||
/************************************************************************/
|
||||
|
@ -174,6 +175,14 @@ int LookaheadParserHandler::peekType()
|
|||
}
|
||||
|
||||
|
||||
Value* LookaheadParserHandler::peekValue() {
|
||||
if (state >= kHasNull && state <= kHasKey) {
|
||||
return &val;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void LookaheadParserHandler::skipOut(int depth)
|
||||
{
|
||||
do {
|
||||
|
@ -223,6 +232,31 @@ void LookaheadParserHandler::skip()
|
|||
}
|
||||
|
||||
|
||||
char* LookaheadParserHandler::findObjectType()
|
||||
{
|
||||
auto level = 0;
|
||||
for (auto p = iss.src_; *p != '\0'; ++p) {
|
||||
if (*p == '{') level++;
|
||||
else if (*p == '}') {
|
||||
if (--level < 0) break;
|
||||
} else if (level == 0) {
|
||||
if (!strncmp(p, "\"ty\"", 4)) {
|
||||
p += 4;
|
||||
while (*p != '\0' && (isspace(*p) || *p == '\n')) ++p;
|
||||
if (*p++ != ':') return nullptr;
|
||||
while (*p != '\0' && (isspace(*p) || *p == '\n')) ++p;
|
||||
if (*p++ != '\"') return nullptr;
|
||||
const char* start = p;
|
||||
while (*p != '\0' && *p != '\"') ++p;
|
||||
if (*p == '\"') return strDuplicate(start, p - start);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
char* LookaheadParserHandler::getPos()
|
||||
{
|
||||
return iss.src_;
|
||||
|
|
|
@ -197,6 +197,8 @@ struct LookaheadParserHandler
|
|||
void skip();
|
||||
void skipOut(int depth);
|
||||
int peekType();
|
||||
Value* peekValue();
|
||||
char* findObjectType();
|
||||
char* getPos();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue