/*
- * Copyright (c) 2020 - 2022 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd. All rights reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* SOFTWARE.
*/
-#include <cstring>
#include "tvgSvgCssStyle.h"
/************************************************************************/
/* Internal Class Implementation */
/************************************************************************/
-static void _cssStyleCopy(SvgStyleProperty* to, const SvgStyleProperty* from)
+static void _copyStyle(SvgStyleProperty* to, const SvgStyleProperty* from)
{
if (from == nullptr) return;
//Copy the properties of 'from' only if they were explicitly set (not the default ones).
/* External Class Implementation */
/************************************************************************/
-void copyCssStyleAttr(SvgNode* to, const SvgNode* from)
+void cssCopyStyleAttr(SvgNode* to, const SvgNode* from)
{
//Copy matrix attribute
if (from->transform && !((int)to->style->flags & (int)SvgStyleFlags::Transform)) {
}
}
//Copy style attribute
- _cssStyleCopy(to->style, from->style);
+ _copyStyle(to->style, from->style);
if (from->style->clipPath.url) to->style->clipPath.url = strdup(from->style->clipPath.url);
if (from->style->mask.url) to->style->mask.url = strdup(from->style->mask.url);
}
-SvgNode* findCssStyleNode(const SvgNode* cssStyle, const char* title, SvgNodeType type)
+SvgNode* cssFindStyleNode(const SvgNode* style, const char* title, SvgNodeType type)
{
- if (!cssStyle) return nullptr;
+ if (!style) return nullptr;
- auto child = cssStyle->child.data;
- for (uint32_t i = 0; i < cssStyle->child.count; ++i, ++child) {
+ auto child = style->child.data;
+ for (uint32_t i = 0; i < style->child.count; ++i, ++child) {
if ((*child)->type == type) {
if ((!title && !(*child)->id) || (title && (*child)->id && !strcmp((*child)->id, title))) return (*child);
}
}
-SvgNode* findCssStyleNode(const SvgNode* cssStyle, const char* title)
+SvgNode* cssFindStyleNode(const SvgNode* style, const char* title)
{
- if (!cssStyle) return nullptr;
+ if (!style) return nullptr;
- auto child = cssStyle->child.data;
- for (uint32_t i = 0; i < cssStyle->child.count; ++i, ++child) {
+ auto child = style->child.data;
+ for (uint32_t i = 0; i < style->child.count; ++i, ++child) {
if ((*child)->type == SvgNodeType::CssStyle) {
if ((title && (*child)->id && !strcmp((*child)->id, title))) return (*child);
}
}
-void updateCssStyle(SvgNode* doc, SvgNode* cssStyle)
+void cssUpdateStyle(SvgNode* doc, SvgNode* style)
{
if (doc->child.count > 0) {
auto child = doc->child.data;
for (uint32_t i = 0; i < doc->child.count; ++i, ++child) {
- if (auto cssNode = findCssStyleNode(cssStyle, nullptr, (*child)->type)) {
- copyCssStyleAttr(*child, cssNode);
+ if (auto cssNode = cssFindStyleNode(style, nullptr, (*child)->type)) {
+ cssCopyStyleAttr(*child, cssNode);
}
- if (auto cssNode = findCssStyleNode(cssStyle, nullptr)) {
- copyCssStyleAttr(*child, cssNode);
+ if (auto cssNode = cssFindStyleNode(style, nullptr)) {
+ cssCopyStyleAttr(*child, cssNode);
}
- updateCssStyle(*child, cssStyle);
+ cssUpdateStyle(*child, style);
}
}
}
-void stylePostponedNodes(Array<SvgNodeIdPair>* nodesToStyle, SvgNode* cssStyle)
+void cssApplyStyleToPostponeds(Array<SvgNodeIdPair>& postponeds, SvgNode* style)
{
- for (uint32_t i = 0; i < nodesToStyle->count; ++i) {
- auto nodeIdPair = nodesToStyle->data[i];
+ for (uint32_t i = 0; i < postponeds.count; ++i) {
+ auto nodeIdPair = postponeds.data[i];
//css styling: tag.name has higher priority than .name
- if (auto cssNode = findCssStyleNode(cssStyle, nodeIdPair.id, nodeIdPair.node->type)) {
- copyCssStyleAttr(nodeIdPair.node, cssNode);
+ if (auto cssNode = cssFindStyleNode(style, nodeIdPair.id, nodeIdPair.node->type)) {
+ cssCopyStyleAttr(nodeIdPair.node, cssNode);
}
- if (auto cssNode = findCssStyleNode(cssStyle, nodeIdPair.id)) {
- copyCssStyleAttr(nodeIdPair.node, cssNode);
+ if (auto cssNode = cssFindStyleNode(style, nodeIdPair.id)) {
+ cssCopyStyleAttr(nodeIdPair.node, cssNode);
}
}
-}
-
+}
\ No newline at end of file
typedef SvgNode* (*FactoryMethod)(SvgLoaderData* loader, SvgNode* parent, const char* buf, unsigned bufLength, parseAttributes func);
typedef SvgStyleGradient* (*GradientFactoryMethod)(SvgLoaderData* loader, const char* buf, unsigned bufLength);
-static void _postponeCloneNode(Array<SvgNodeIdPair>* nodes, SvgNode *node, char* id);
-
-
static char* _skipSpace(const char* str, const char* end)
{
while (((end && str < end) || (!end && *str != '\0')) && isspace(*str)) {
}
+static void _postpone(Array<SvgNodeIdPair>& nodes, SvgNode *node, char* id)
+{
+ nodes.push({node, id});
+}
+
+
/*
// TODO - remove?
static constexpr struct
bool cssClassFound = false;
//css styling: tag.name has higher priority than .name
- if (auto cssNode = findCssStyleNode(loader->cssStyle, *cssClass, node->type)) {
+ if (auto cssNode = cssFindStyleNode(loader->cssStyle, *cssClass, node->type)) {
cssClassFound = true;
- copyCssStyleAttr(node, cssNode);
+ cssCopyStyleAttr(node, cssNode);
}
- if (auto cssNode = findCssStyleNode(loader->cssStyle, *cssClass)) {
+ if (auto cssNode = cssFindStyleNode(loader->cssStyle, *cssClass)) {
cssClassFound = true;
- copyCssStyleAttr(node, cssNode);
+ cssCopyStyleAttr(node, cssNode);
}
- if (!cssClassFound) _postponeCloneNode(&loader->nodesToStyle, node, *cssClass);
+ if (!cssClassFound) _postpone(loader->nodesToStyle, node, *cssClass);
}
}
-static void _postponeCloneNode(Array<SvgNodeIdPair>* nodes, SvgNode *node, char* id)
-{
- nodes->push({node, id});
-}
-
-
static void _clonePostponedNodes(Array<SvgNodeIdPair>* cloneNodes, SvgNode* doc)
{
for (uint32_t i = 0; i < cloneNodes->count; ++i) {
//some svg export software include <defs> element at the end of the file
//if so the 'from' element won't be found now and we have to repeat finding
//after the whole file is parsed
- _postponeCloneNode(&loader->cloneNodes, node, id);
+ _postpone(loader->cloneNodes, node, id);
}
} else {
return _attrParseGNode(data, key, value);
if (loaderData.doc) {
auto defs = loaderData.doc->node.doc.defs;
- if (loaderData.nodesToStyle.count > 0) stylePostponedNodes(&loaderData.nodesToStyle, loaderData.cssStyle);
- if (loaderData.cssStyle) updateCssStyle(loaderData.doc, loaderData.cssStyle);
+ if (loaderData.nodesToStyle.count > 0) cssApplyStyleToPostponeds(loaderData.nodesToStyle, loaderData.cssStyle);
+ if (loaderData.cssStyle) cssUpdateStyle(loaderData.doc, loaderData.cssStyle);
_updateComposite(loaderData.doc, loaderData.doc);
if (defs) _updateComposite(loaderData.doc, defs);