add new shapes to the head due to performance, reverse list of shapes later

This commit is contained in:
tpechot 2017-04-20 14:32:02 +02:00
parent 46c7ae0ef9
commit f76c596d8a

View File

@ -996,17 +996,9 @@ static void nsvg__addShape(NSVGparser* p)
// Set flags // Set flags
shape->flags = (attr->visible ? NSVG_FLAGS_VISIBLE : 0x00); shape->flags = (attr->visible ? NSVG_FLAGS_VISIBLE : 0x00);
// Add to tail // Add to head due to performance, reverse list later
prev = NULL; shape->next = p->image->shapes;
cur = p->image->shapes; p->image->shapes = shape;
while (cur != NULL) {
prev = cur;
cur = cur->next;
}
if (prev == NULL)
p->image->shapes = shape;
else
prev->next = shape;
return; return;
@ -2795,6 +2787,7 @@ NSVGimage* nsvgParse(char* input, const char* units, float dpi)
{ {
NSVGparser* p; NSVGparser* p;
NSVGimage* ret = 0; NSVGimage* ret = 0;
NSVGshape* cur, *tmp;
p = nsvg__createParser(); p = nsvg__createParser();
if (p == NULL) { if (p == NULL) {
@ -2803,6 +2796,16 @@ NSVGimage* nsvgParse(char* input, const char* units, float dpi)
p->dpi = dpi; p->dpi = dpi;
nsvg__parseXML(input, nsvg__startElement, nsvg__endElement, nsvg__content, p); nsvg__parseXML(input, nsvg__startElement, nsvg__endElement, nsvg__content, p);
//reverse the list of shapes to match svg order
cur = p->image->shapes;
while (cur && cur->next != NULL) {
tmp = cur->next;
cur->next = cur->next->next;
tmp->next = p->image->shapes;
p->image->shapes = tmp;
cur = cur->next;
}
// Scale to viewBox // Scale to viewBox
nsvg__scaleToViewbox(p, units); nsvg__scaleToViewbox(p, units);