mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-08 13:43:43 +00:00
svg_loader: code refactoring
revise code for simple & better readibility.
This commit is contained in:
parent
a37b2471ce
commit
09fce05105
2 changed files with 22 additions and 37 deletions
|
@ -1454,8 +1454,8 @@ static void _cloneNode(SvgNode* from, SvgNode* parent)
|
||||||
newNode = _createNode(parent, from->type);
|
newNode = _createNode(parent, from->type);
|
||||||
_copyAttr(newNode, from);
|
_copyAttr(newNode, from);
|
||||||
|
|
||||||
for (vector<SvgNode*>::iterator itrChild = from->child.begin(); itrChild != from->child.end(); itrChild++) {
|
for (auto child : from->child) {
|
||||||
_cloneNode(*itrChild, newNode);
|
_cloneNode(child, newNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
_freeNode(newNode);
|
_freeNode(newNode);
|
||||||
|
@ -1489,13 +1489,6 @@ static SvgNode* _createUseNode(SvgLoaderData* loader, SvgNode* parent, const cha
|
||||||
return loader->svgParse->node;
|
return loader->svgParse->node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define TAG_DEF(Name, Name1) \
|
|
||||||
{ \
|
|
||||||
#Name, sizeof(#Name), _create##Name1##Node \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: Implement 'text' primitive
|
//TODO: Implement 'text' primitive
|
||||||
static constexpr struct
|
static constexpr struct
|
||||||
{
|
{
|
||||||
|
@ -1503,14 +1496,14 @@ static constexpr struct
|
||||||
int sz;
|
int sz;
|
||||||
FactoryMethod tagHandler;
|
FactoryMethod tagHandler;
|
||||||
} graphicsTags[] = {
|
} graphicsTags[] = {
|
||||||
TAG_DEF(use, Use),
|
{"use", sizeof("use"), _createUseNode},
|
||||||
TAG_DEF(circle, Circle),
|
{"circle", sizeof("circle"), _createCircleNode},
|
||||||
TAG_DEF(ellipse, Ellipse),
|
{"ellipse", sizeof("ellipse"), _createEllipseNode},
|
||||||
TAG_DEF(path, Path),
|
{"path", sizeof("path"), _createPathNode},
|
||||||
TAG_DEF(polygon, Polygon),
|
{"polygon", sizeof("polygon"), _createPolygonNode},
|
||||||
TAG_DEF(rect, Rect),
|
{"rect", sizeof("rect"), _createRectNode},
|
||||||
TAG_DEF(polyline, Polyline),
|
{"polyline", sizeof("polyline"), _createPolylineNode},
|
||||||
TAG_DEF(line, Line),
|
{"line", sizeof("line"), _createLineNode}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1520,9 +1513,9 @@ static constexpr struct
|
||||||
int sz;
|
int sz;
|
||||||
FactoryMethod tagHandler;
|
FactoryMethod tagHandler;
|
||||||
} groupTags[] = {
|
} groupTags[] = {
|
||||||
TAG_DEF(defs, Defs),
|
{"defs", sizeof("defs"), _createDefsNode},
|
||||||
TAG_DEF(g, G),
|
{"g", sizeof("g"), _createGNode},
|
||||||
TAG_DEF(svg, Svg),
|
{"svg", sizeof("svg"), _createSvgNode}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1895,20 +1888,14 @@ static GradientFactoryMethod _findGradientFactory(const char* name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define POP_TAG(Tag) \
|
|
||||||
{ \
|
|
||||||
#Tag, sizeof(#Tag) \
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static constexpr struct
|
static constexpr struct
|
||||||
{
|
{
|
||||||
const char* tag;
|
const char* tag;
|
||||||
size_t sz;
|
size_t sz;
|
||||||
} popArray[] = {
|
} popArray[] = {
|
||||||
POP_TAG(g),
|
{"g", sizeof("g")},
|
||||||
POP_TAG(svg),
|
{"svg", sizeof("svg")},
|
||||||
POP_TAG(defs)
|
{"defs", sizeof("defs")}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2165,8 +2152,8 @@ static void _freeNode(SvgNode* node)
|
||||||
{
|
{
|
||||||
if (!node) return;
|
if (!node) return;
|
||||||
|
|
||||||
for(vector<SvgNode*>::iterator itrChild = node->child.begin(); itrChild != node->child.end(); itrChild++) {
|
for(auto child : node->child) {
|
||||||
_freeNode(*itrChild);
|
_freeNode(child);
|
||||||
}
|
}
|
||||||
node->child.clear();
|
node->child.clear();
|
||||||
|
|
||||||
|
@ -2200,7 +2187,6 @@ static void _freeNode(SvgNode* node)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!node->child.empty()) node->child.clear();
|
|
||||||
free(node);
|
free(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2376,7 +2362,6 @@ bool SvgLoader::close()
|
||||||
delete(task);
|
delete(task);
|
||||||
task = nullptr;
|
task = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loaderData.svgParse) {
|
if (loaderData.svgParse) {
|
||||||
free(loaderData.svgParse);
|
free(loaderData.svgParse);
|
||||||
loaderData.svgParse = nullptr;
|
loaderData.svgParse = nullptr;
|
||||||
|
|
|
@ -116,8 +116,8 @@ enum class SvgParserLengthType
|
||||||
Other
|
Other
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _SvgNode SvgNode;
|
struct SvgNode;
|
||||||
typedef struct _SvgStyleGradient SvgStyleGradient;
|
struct SvgStyleGradient;
|
||||||
|
|
||||||
struct SvgDocNode
|
struct SvgDocNode
|
||||||
{
|
{
|
||||||
|
@ -231,7 +231,7 @@ struct SvgDash
|
||||||
float gap;
|
float gap;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _SvgStyleGradient
|
struct SvgStyleGradient
|
||||||
{
|
{
|
||||||
SvgGradientType type;
|
SvgGradientType type;
|
||||||
string *id;
|
string *id;
|
||||||
|
@ -277,7 +277,7 @@ struct SvgStyleProperty
|
||||||
uint8_t b;
|
uint8_t b;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _SvgNode
|
struct SvgNode
|
||||||
{
|
{
|
||||||
SvgNodeType type;
|
SvgNodeType type;
|
||||||
SvgNode* parent;
|
SvgNode* parent;
|
||||||
|
|
Loading…
Add table
Reference in a new issue