svg_loader: SvgCompositeNode type introduced

Clips and masks require to implement some additional variables,
so the new node type has been introduced. Implementation of the usage
of these additional variables will be the subject of a separate
commit.
This commit is contained in:
Mira Grudzinska 2021-11-03 12:31:41 +01:00 committed by Hermet Park
parent eadb7fc4af
commit 40f2baabae
2 changed files with 17 additions and 4 deletions

View file

@ -1022,6 +1022,7 @@ static bool _attrParseClipPathNode(void* data, const char* key, const char* valu
{ {
SvgLoaderData* loader = (SvgLoaderData*)data; SvgLoaderData* loader = (SvgLoaderData*)data;
SvgNode* node = loader->svgParse->node; SvgNode* node = loader->svgParse->node;
SvgCompositeNode* comp = &(node->node.comp);
if (!strcmp(key, "style")) { if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, _parseStyleAttr, loader); return simpleXmlParseW3CAttribute(value, _parseStyleAttr, loader);
@ -1030,6 +1031,8 @@ static bool _attrParseClipPathNode(void* data, const char* key, const char* valu
} else if (!strcmp(key, "id")) { } else if (!strcmp(key, "id")) {
if (node->id && value) delete node->id; if (node->id && value) delete node->id;
node->id = _copyId(value); node->id = _copyId(value);
} else if (!strcmp(key, "clipPathUnits")) {
if (!strcmp(value, "objectBoundingBox")) comp->userSpace = false;
} else { } else {
return _parseStyleAttr(loader, key, value, false); return _parseStyleAttr(loader, key, value, false);
} }
@ -1041,6 +1044,7 @@ static bool _attrParseMaskNode(void* data, const char* key, const char* value)
{ {
SvgLoaderData* loader = (SvgLoaderData*)data; SvgLoaderData* loader = (SvgLoaderData*)data;
SvgNode* node = loader->svgParse->node; SvgNode* node = loader->svgParse->node;
SvgCompositeNode* comp = &(node->node.comp);
if (!strcmp(key, "style")) { if (!strcmp(key, "style")) {
return simpleXmlParseW3CAttribute(value, _parseStyleAttr, loader); return simpleXmlParseW3CAttribute(value, _parseStyleAttr, loader);
@ -1049,6 +1053,8 @@ static bool _attrParseMaskNode(void* data, const char* key, const char* value)
} else if (!strcmp(key, "id")) { } else if (!strcmp(key, "id")) {
if (node->id && value) delete node->id; if (node->id && value) delete node->id;
node->id = _copyId(value); node->id = _copyId(value);
} else if (!strcmp(key, "maskContentUnits")) {
if (!strcmp(value, "objectBoundingBox")) comp->userSpace = false;
} else { } else {
return _parseStyleAttr(loader, key, value, false); return _parseStyleAttr(loader, key, value, false);
} }
@ -1158,6 +1164,8 @@ static SvgNode* _createMaskNode(SvgLoaderData* loader, SvgNode* parent, TVG_UNUS
loader->svgParse->node = _createNode(parent, SvgNodeType::Mask); loader->svgParse->node = _createNode(parent, SvgNodeType::Mask);
if (!loader->svgParse->node) return nullptr; if (!loader->svgParse->node) return nullptr;
loader->svgParse->node->node.comp.userSpace = true;
simpleXmlParseAttributes(buf, bufLength, _attrParseMaskNode, loader); simpleXmlParseAttributes(buf, bufLength, _attrParseMaskNode, loader);
return loader->svgParse->node; return loader->svgParse->node;
@ -1167,10 +1175,10 @@ static SvgNode* _createMaskNode(SvgLoaderData* loader, SvgNode* parent, TVG_UNUS
static SvgNode* _createClipPathNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength) static SvgNode* _createClipPathNode(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength)
{ {
loader->svgParse->node = _createNode(parent, SvgNodeType::ClipPath); loader->svgParse->node = _createNode(parent, SvgNodeType::ClipPath);
if (!loader->svgParse->node) return nullptr; if (!loader->svgParse->node) return nullptr;
loader->svgParse->node->display = false; loader->svgParse->node->display = false;
loader->svgParse->node->node.comp.userSpace = true;
simpleXmlParseAttributes(buf, bufLength, _attrParseClipPathNode, loader); simpleXmlParseAttributes(buf, bufLength, _attrParseClipPathNode, loader);
@ -2632,11 +2640,11 @@ static void _updateGradient(SvgNode* node, Array<SvgStyleGradient*>* gradients)
static void _updateComposite(SvgNode* node, SvgNode* root) static void _updateComposite(SvgNode* node, SvgNode* root)
{ {
if (node->style->clipPath.url && !node->style->clipPath.node) { if (node->style->clipPath.url && !node->style->clipPath.node) {
SvgNode *findResult = _findNodeById(root, node->style->clipPath.url); SvgNode* findResult = _findNodeById(root, node->style->clipPath.url);
if (findResult) node->style->clipPath.node = findResult; if (findResult) node->style->clipPath.node = findResult;
} }
if (node->style->mask.url && !node->style->mask.node) { if (node->style->mask.url && !node->style->mask.node) {
SvgNode *findResult = _findNodeById(root, node->style->mask.url); SvgNode* findResult = _findNodeById(root, node->style->mask.url);
if (findResult) node->style->mask.node = findResult; if (findResult) node->style->mask.node = findResult;
} }
if (node->child.count > 0) { if (node->child.count > 0) {

View file

@ -215,6 +215,11 @@ struct SvgPolygonNode
float* points; float* points;
}; };
struct SvgCompositeNode
{
bool userSpace;
};
struct SvgLinearGradient struct SvgLinearGradient
{ {
float x1; float x1;
@ -225,7 +230,6 @@ struct SvgLinearGradient
bool isY1Percentage; bool isY1Percentage;
bool isX2Percentage; bool isX2Percentage;
bool isY2Percentage; bool isY2Percentage;
}; };
struct SvgRadialGradient struct SvgRadialGradient
@ -348,6 +352,7 @@ struct SvgNode
SvgPathNode path; SvgPathNode path;
SvgLineNode line; SvgLineNode line;
SvgImageNode image; SvgImageNode image;
SvgCompositeNode comp;
} node; } node;
bool display; bool display;
~SvgNode(); ~SvgNode();