mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 05:33:36 +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) {
|
||||||
if (!type) return nullptr;
|
type = getString();
|
||||||
|
if (!type) return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (!strcmp(type, "gr")) return parseGroup();
|
if (!strcmp(type, "gr")) return parseGroup();
|
||||||
else if (!strcmp(type, "rc")) return parseRect();
|
else if (!strcmp(type, "rc")) return parseRect();
|
||||||
|
@ -882,6 +884,24 @@ LottieObject* LottieParser::parseObject()
|
||||||
void LottieParser::parseObject(Array<LottieObject*>& parent)
|
void LottieParser::parseObject(Array<LottieObject*>& parent)
|
||||||
{
|
{
|
||||||
enterObject();
|
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()) {
|
while (auto key = nextObjectKey()) {
|
||||||
if (KEY_AS("ty")) {
|
if (KEY_AS("ty")) {
|
||||||
if (auto child = parseObject()) {
|
if (auto child = parseObject()) {
|
||||||
|
@ -1096,20 +1116,7 @@ void LottieParser::parseTimeRemap(LottieLayer* layer)
|
||||||
void LottieParser::parseShapes(Array<LottieObject*>& parent)
|
void LottieParser::parseShapes(Array<LottieObject*>& parent)
|
||||||
{
|
{
|
||||||
enterArray();
|
enterArray();
|
||||||
while (nextArrayValue()) {
|
while (nextArrayValue()) parseObject(parent);
|
||||||
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 parseProperty(T& prop, LottieObject* obj = nullptr);
|
||||||
template<typename T> void parseSlotProperty(T& prop);
|
template<typename T> void parseSlotProperty(T& prop);
|
||||||
|
|
||||||
LottieObject* parseObject();
|
LottieObject* parseObject(const char* type = nullptr);
|
||||||
LottieObject* parseAsset();
|
LottieObject* parseAsset();
|
||||||
void parseImage(LottieImage* image, const char* data, const char* subPath, bool embedded, float width, float height);
|
void parseImage(LottieImage* image, const char* data, const char* subPath, bool embedded, float width, float height);
|
||||||
LottieLayer* parseLayer(LottieLayer* precomp);
|
LottieLayer* parseLayer(LottieLayer* precomp);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2023 - 2025 the ThorVG project. All rights reserved.
|
* Copyright (c) 2023 - 2025 the ThorVG project. All rights reserved.
|
||||||
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
@ -44,6 +44,7 @@
|
||||||
|
|
||||||
#include "tvgStr.h"
|
#include "tvgStr.h"
|
||||||
#include "tvgLottieParserHandler.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)
|
void LookaheadParserHandler::skipOut(int depth)
|
||||||
{
|
{
|
||||||
do {
|
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()
|
char* LookaheadParserHandler::getPos()
|
||||||
{
|
{
|
||||||
return iss.src_;
|
return iss.src_;
|
||||||
|
|
|
@ -197,6 +197,8 @@ struct LookaheadParserHandler
|
||||||
void skip();
|
void skip();
|
||||||
void skipOut(int depth);
|
void skipOut(int depth);
|
||||||
int peekType();
|
int peekType();
|
||||||
|
Value* peekValue();
|
||||||
|
char* findObjectType();
|
||||||
char* getPos();
|
char* getPos();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue