node->parent = parent;
node->type = type;
- if (parent) parent->child.push_back(node);
+ if (parent) parent->child.push(node);
return node;
}
static SvgNode* _findChildById(SvgNode* node, const char* id)
{
-
if (!node) return nullptr;
- for (vector<SvgNode*>::iterator itrChild = node->child.begin(); itrChild != node->child.end(); itrChild++) {
- if (((*itrChild)->id != nullptr) && !strcmp((*itrChild)->id->c_str(), id)) return *itrChild;
+ auto child = node->child.list;
+ for (uint32_t i = 0; i < node->child.cnt; ++i, ++child) {
+ if (((*child)->id != nullptr) && !strcmp((*child)->id->c_str(), id)) return (*child);
}
return nullptr;
}
-static void _cloneGradStops(vector<Fill::ColorStop*> *dst, vector<Fill::ColorStop*> src)
+static void _cloneGradStops(SvgVector<Fill::ColorStop*>* dst, SvgVector<Fill::ColorStop*>* src)
{
- for (auto colorStop : src) {
- auto stop = static_cast<Fill::ColorStop *>(malloc(sizeof(Fill::ColorStop)));
- *stop = *colorStop;
- dst->push_back(stop);
+ for (uint32_t i = 0; i < src->cnt; ++i) {
+ auto stop = static_cast<Fill::ColorStop *>(malloc(sizeof(Fill::ColorStop)));
+ *stop = *src->list[i];
+ dst->push(stop);
}
}
memcpy(grad->radial, from->radial, sizeof(SvgRadialGradient));
}
- _cloneGradStops(&(grad->stops), from->stops);
+ _cloneGradStops(&grad->stops, &from->stops);
return grad;
}
newNode = _createNode(parent, from->type);
_copyAttr(newNode, from);
- for (auto child : from->child) {
- _cloneNode(child, newNode);
+ auto child = from->child.list;
+ for (uint32_t i = 0; i < from->child.cnt; ++i, ++child) {
+ _cloneNode(*child, newNode);
}
_freeNode(newNode);
for (i = 0; i < sizeof(popArray) / sizeof(popArray[0]); i++) {
if (!strncmp(content, popArray[i].tag, popArray[i].sz - 1)) {
- loader->stack.pop_back();
+ loader->stack.pop();
break;
}
}
loader->doc = node;
} else {
if (!strcmp(tagName, "svg")) return; //Already loadded <svg>(SvgNodeType::Doc) tag
- if (loader->stack.size() > 0) parent = loader->stack.at(loader->stack.size() - 1);
+ if (loader->stack.cnt > 0) parent = loader->stack.list[loader->stack.cnt - 1];
node = method(loader, parent, attrs, attrsLength);
}
- loader->stack.push_back(node);
+ loader->stack.push(node);
if (node->type == SvgNodeType::Defs) {
loader->doc->node.doc.defs = node;
loader->def = node;
}
} else if ((method = _findGraphicsFactory(tagName))) {
- parent = loader->stack.at(loader->stack.size() - 1);
+ parent = loader->stack.list[loader->stack.cnt - 1];
node = method(loader, parent, attrs, attrsLength);
} else if ((gradientMethod = _findGradientFactory(tagName))) {
SvgStyleGradient* gradient;
// This is only to support this when multiple gradients are declared, even if no defs are declared.
// refer to: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/defs
if (loader->doc->node.doc.defs) {
- loader->def->node.defs.gradients.push_back(gradient);
+ loader->def->node.defs.gradients.push(gradient);
} else {
- loader->gradients.push_back(gradient);
+ loader->gradients.push(gradient);
}
loader->latestGradient = gradient;
} else if (!strcmp(tagName, "stop")) {
stop->a = 255;
simpleXmlParseAttributes(attrs, attrsLength, _attrParseStops, loader);
if (loader->latestGradient) {
- loader->latestGradient->stops.push_back(stop);
+ loader->latestGradient->stops.push(stop);
}
}
}
{
_styleInherit(node->style, parentStyle);
- for (vector<SvgNode*>::iterator itrChild = node->child.begin(); itrChild != node->child.end(); itrChild++) {
- _updateStyle(*itrChild, node->style);
+ auto child = node->child.list;
+ for (uint32_t i = 0; i < node->child.cnt; ++i, ++child) {
+ _updateStyle(*child, node->style);
}
}
-static SvgStyleGradient* _gradientDup(vector<SvgStyleGradient*> gradList, string* id)
+static SvgStyleGradient* _gradientDup(SvgVector<SvgStyleGradient*>* gradients, string* id)
{
SvgStyleGradient* result = nullptr;
- for (vector<SvgStyleGradient*>::iterator itrGrad = gradList.begin(); itrGrad != gradList.end(); itrGrad++) {
- if (!((*itrGrad)->id->compare(*id))) {
- result = _cloneGradient(*itrGrad);
+ auto gradList = gradients->list;
+
+ for (uint32_t i = 0; i < gradients->cnt; ++i) {
+ if (!((*gradList)->id->compare(*id))) {
+ result = _cloneGradient(*gradList);
break;
}
+ ++gradList;
}
if (result && result->ref) {
- for (vector<SvgStyleGradient*>::iterator itrGrad = gradList.begin(); itrGrad != gradList.end(); itrGrad++) {
- if (!((*itrGrad)->id->compare(*result->ref))) {
- if (!result->stops.empty()) {
- _cloneGradStops(&(result->stops), (*itrGrad)->stops);
+ gradList = gradients->list;
+ for (uint32_t i = 0; i < gradients->cnt; ++i) {
+ if (!((*gradList)->id->compare(*result->ref))) {
+ if (result->stops.cnt > 0) {
+ _cloneGradStops(&result->stops, &(*gradList)->stops);
}
//TODO: Properly inherit other property
break;
}
+ ++gradList;
}
}
}
-static void _updateGradient(SvgNode* node, vector<SvgStyleGradient*> gradList)
+static void _updateGradient(SvgNode* node, SvgVector<SvgStyleGradient*>* gradidents)
{
- if (!node->child.empty()) {
- for (vector<SvgNode*>::iterator itrChild = node->child.begin(); itrChild != node->child.end(); itrChild++) {
- _updateGradient(*itrChild, gradList);
+ if (node->child.cnt > 0) {
+ auto child = node->child.list;
+ for (uint32_t i = 0; i < node->child.cnt; ++i, ++child) {
+ _updateGradient(*child, gradidents);
}
} else {
if (node->style->fill.paint.url) {
- node->style->fill.paint.gradient = _gradientDup(gradList, node->style->fill.paint.url);
+ node->style->fill.paint.gradient = _gradientDup(gradidents, node->style->fill.paint.url);
} else if (node->style->stroke.paint.url) {
//node->style->stroke.paint.gradient = _gradientDup(gradList, node->style->stroke.paint.url);
}
free(grad->linear);
if (grad->transform) free(grad->transform);
- for (auto colorStop : grad->stops) free(colorStop);
-
+ for (uint32_t i = 0; i < grad->stops.cnt; ++i) {
+ auto colorStop = grad->stops.list[i];
+ free(colorStop);
+ }
+ grad->stops.clear();
free(grad);
}
{
if (!node) return;
- for(auto child : node->child) {
- _freeNode(child);
+ auto child = node->child.list;
+ for (uint32_t i = 0; i < node->child.cnt; ++i, ++child) {
+ _freeNode(*child);
}
node->child.clear();
break;
}
case SvgNodeType::Defs: {
- for(vector<SvgStyleGradient*>::iterator itrGrad = node->node.defs.gradients.begin(); itrGrad != node->node.defs.gradients.end(); itrGrad++) {
- _freeGradientStyle(*itrGrad);
+ auto gradients = node->node.defs.gradients.list;
+ for (size_t i = 0; i < node->node.defs.gradients.cnt; ++i) {
+ _freeGradientStyle(*gradients);
+ ++gradients;
}
+ node->node.defs.gradients.clear();
break;
}
default: {
if (strcmp(tagName, "svg")) return true; //Not a valid svg document
node = method(loader, nullptr, attrs, attrsLength);
loader->doc = node;
- loader->stack.push_back(node);
+ loader->stack.push(node);
return false;
}
}
if (loader->loaderData.doc) {
_updateStyle(loader->loaderData.doc, nullptr);
auto defs = loader->loaderData.doc->node.doc.defs;
- if (defs) _updateGradient(loader->loaderData.doc, defs->node.defs.gradients);
+ if (defs) _updateGradient(loader->loaderData.doc, &defs->node.defs.gradients);
else {
- if (!loader->loaderData.gradients.empty()) {
- vector<SvgStyleGradient*> gradientList;
- for (auto gradient : loader->loaderData.gradients) {
- gradientList.push_back(gradient);
- }
- _updateGradient(loader->loaderData.doc, gradientList);
- gradientList.clear();
+ if (loader->loaderData.gradients.cnt > 0) {
+ _updateGradient(loader->loaderData.doc, &loader->loaderData.gradients);
}
}
}
}
_freeNode(loaderData.doc);
loaderData.doc = nullptr;
+ loaderData.stack.clear();
return true;
}
fillGrad->spread(g->spread);
//Update the stops
- stopCount = g->stops.size();
+ stopCount = g->stops.cnt;
if (stopCount > 0) {
float opacity;
float fopacity = fillOpacity / 255.0f; //fill opacity if any exists.
- int i = 0;
stops = (Fill::ColorStop*)calloc(stopCount, sizeof(Fill::ColorStop));
- for (auto colorStop : g->stops) {
+ for (uint32_t i = 0; i < g->stops.cnt; ++i) {
+ auto colorStop = g->stops.list[i];
//Use premultiplied color
opacity = ((float)colorStop->a / 255.0f) * fopacity;
stops[i].r = colorStop->r * opacity;
stops[i].b = colorStop->b * opacity;
stops[i].a = colorStop->a * fopacity;
stops[i].offset = colorStop->offset;
- i++;
}
fillGrad->colorStops(stops, stopCount);
free(stops);
fillGrad->spread(g->spread);
//Update the stops
- stopCount = g->stops.size();
+ stopCount = g->stops.cnt;
if (stopCount > 0) {
float opacity;
float fopacity = fillOpacity / 255.0f; //fill opacity if any exists.
- int i = 0;
stops = (Fill::ColorStop*)calloc(stopCount, sizeof(Fill::ColorStop));
- for (auto colorStop : g->stops) {
+ for (uint32_t i = 0; i < g->stops.cnt; ++i) {
+ auto colorStop = g->stops.list[i];
//Use premultiplied color
opacity = ((float)colorStop->a / 255.0f) * fopacity;
stops[i].r = colorStop->r * opacity;
stops[i].b = colorStop->b * opacity;
stops[i].a = colorStop->a * fopacity;
stops[i].offset = colorStop->offset;
- i++;
}
fillGrad->colorStops(stops, stopCount);
free(stops);
if (node->transform) scene->transform(*node->transform);
node->style->opacity = (node->style->opacity * parentOpacity) / 255.0f;
if (node->display) {
- for (auto child : node->child) {
- if (child->type == SvgNodeType::Doc || child->type == SvgNodeType::G) scene->push(_sceneBuildHelper(child, vx, vy, vw, vh, node->style->opacity));
- else {
- child->style->opacity = (child->style->opacity * node->style->opacity) / 255.0f;
- scene->push(_shapeBuildHelper(child, vx, vy, vw, vh));
+ auto child = node->child.list;
+ for (uint32_t i = 0; i < node->child.cnt; ++i, ++child) {
+ if ((*child)->type == SvgNodeType::Doc || (*child)->type == SvgNodeType::G) {
+ scene->push(_sceneBuildHelper(*child, vx, vy, vw, vh, node->style->opacity));
+ } else {
+ (*child)->style->opacity = ((*child)->style->opacity * node->style->opacity) / 255.0f;
+ scene->push(_shapeBuildHelper(*child, vx, vy, vw, vh));
}
}
}