Changed reverse shape list to tail cached variant
This commit is contained in:
parent
3f40cbc53e
commit
096f60a5c5
@ -145,7 +145,7 @@ typedef struct NSVGshape
|
|||||||
char strokeDashCount; // Number of dash values in dash array.
|
char strokeDashCount; // Number of dash values in dash array.
|
||||||
char strokeLineJoin; // Stroke join type.
|
char strokeLineJoin; // Stroke join type.
|
||||||
char strokeLineCap; // Stroke cap type.
|
char strokeLineCap; // Stroke cap type.
|
||||||
float miterLimit; // Miter limit
|
float miterLimit; // Miter limit
|
||||||
char fillRule; // Fill rule, see NSVGfillRule.
|
char fillRule; // Fill rule, see NSVGfillRule.
|
||||||
unsigned char flags; // Logical or of NSVG_FLAGS_* flags
|
unsigned char flags; // Logical or of NSVG_FLAGS_* flags
|
||||||
float bounds[4]; // Tight bounding box of the shape [minx,miny,maxx,maxy].
|
float bounds[4]; // Tight bounding box of the shape [minx,miny,maxx,maxy].
|
||||||
@ -414,7 +414,7 @@ typedef struct NSVGattrib
|
|||||||
int strokeDashCount;
|
int strokeDashCount;
|
||||||
char strokeLineJoin;
|
char strokeLineJoin;
|
||||||
char strokeLineCap;
|
char strokeLineCap;
|
||||||
float miterLimit;
|
float miterLimit;
|
||||||
char fillRule;
|
char fillRule;
|
||||||
float fontSize;
|
float fontSize;
|
||||||
unsigned int stopColor;
|
unsigned int stopColor;
|
||||||
@ -435,6 +435,7 @@ typedef struct NSVGparser
|
|||||||
NSVGpath* plist;
|
NSVGpath* plist;
|
||||||
NSVGimage* image;
|
NSVGimage* image;
|
||||||
NSVGgradientData* gradients;
|
NSVGgradientData* gradients;
|
||||||
|
NSVGshape* shapesTail;
|
||||||
float viewMinx, viewMiny, viewWidth, viewHeight;
|
float viewMinx, viewMiny, viewWidth, viewHeight;
|
||||||
int alignX, alignY, alignType;
|
int alignX, alignY, alignType;
|
||||||
float dpi;
|
float dpi;
|
||||||
@ -921,7 +922,7 @@ static void nsvg__addShape(NSVGparser* p)
|
|||||||
{
|
{
|
||||||
NSVGattrib* attr = nsvg__getAttr(p);
|
NSVGattrib* attr = nsvg__getAttr(p);
|
||||||
float scale = 1.0f;
|
float scale = 1.0f;
|
||||||
NSVGshape *shape;
|
NSVGshape* shape;
|
||||||
NSVGpath* path;
|
NSVGpath* path;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -996,9 +997,12 @@ 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 head due to performance, reverse list later
|
// Add to tail
|
||||||
shape->next = p->image->shapes;
|
if (p->image->shapes == NULL)
|
||||||
p->image->shapes = shape;
|
p->image->shapes = shape;
|
||||||
|
else
|
||||||
|
p->shapesTail->next = shape;
|
||||||
|
p->shapesTail = shape;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -2151,23 +2155,23 @@ static void nsvg__parsePath(NSVGparser* p, const char** attr)
|
|||||||
// Moveto can be followed by multiple coordinate pairs,
|
// Moveto can be followed by multiple coordinate pairs,
|
||||||
// which should be treated as linetos.
|
// which should be treated as linetos.
|
||||||
cmd = (cmd == 'm') ? 'l' : 'L';
|
cmd = (cmd == 'm') ? 'l' : 'L';
|
||||||
rargs = nsvg__getArgsPerElement(cmd);
|
rargs = nsvg__getArgsPerElement(cmd);
|
||||||
cpx2 = cpx; cpy2 = cpy;
|
cpx2 = cpx; cpy2 = cpy;
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
case 'L':
|
case 'L':
|
||||||
nsvg__pathLineTo(p, &cpx, &cpy, args, cmd == 'l' ? 1 : 0);
|
nsvg__pathLineTo(p, &cpx, &cpy, args, cmd == 'l' ? 1 : 0);
|
||||||
cpx2 = cpx; cpy2 = cpy;
|
cpx2 = cpx; cpy2 = cpy;
|
||||||
break;
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
case 'h':
|
case 'h':
|
||||||
nsvg__pathHLineTo(p, &cpx, &cpy, args, cmd == 'h' ? 1 : 0);
|
nsvg__pathHLineTo(p, &cpx, &cpy, args, cmd == 'h' ? 1 : 0);
|
||||||
cpx2 = cpx; cpy2 = cpy;
|
cpx2 = cpx; cpy2 = cpy;
|
||||||
break;
|
break;
|
||||||
case 'V':
|
case 'V':
|
||||||
case 'v':
|
case 'v':
|
||||||
nsvg__pathVLineTo(p, &cpx, &cpy, args, cmd == 'v' ? 1 : 0);
|
nsvg__pathVLineTo(p, &cpx, &cpy, args, cmd == 'v' ? 1 : 0);
|
||||||
cpx2 = cpx; cpy2 = cpy;
|
cpx2 = cpx; cpy2 = cpy;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
case 'c':
|
case 'c':
|
||||||
@ -2188,13 +2192,13 @@ static void nsvg__parsePath(NSVGparser* p, const char** attr)
|
|||||||
case 'A':
|
case 'A':
|
||||||
case 'a':
|
case 'a':
|
||||||
nsvg__pathArcTo(p, &cpx, &cpy, args, cmd == 'a' ? 1 : 0);
|
nsvg__pathArcTo(p, &cpx, &cpy, args, cmd == 'a' ? 1 : 0);
|
||||||
cpx2 = cpx; cpy2 = cpy;
|
cpx2 = cpx; cpy2 = cpy;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (nargs >= 2) {
|
if (nargs >= 2) {
|
||||||
cpx = args[nargs-2];
|
cpx = args[nargs-2];
|
||||||
cpy = args[nargs-1];
|
cpy = args[nargs-1];
|
||||||
cpx2 = cpx; cpy2 = cpy;
|
cpx2 = cpx; cpy2 = cpy;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -2787,7 +2791,6 @@ NSVGimage* nsvgParse(char* input, const char* units, float dpi)
|
|||||||
{
|
{
|
||||||
NSVGparser* p;
|
NSVGparser* p;
|
||||||
NSVGimage* ret = 0;
|
NSVGimage* ret = 0;
|
||||||
NSVGshape* cur, *prev, *tmp;
|
|
||||||
|
|
||||||
p = nsvg__createParser();
|
p = nsvg__createParser();
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
@ -2797,17 +2800,6 @@ NSVGimage* nsvgParse(char* input, const char* units, float 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;
|
|
||||||
prev = NULL;
|
|
||||||
while (cur != NULL) {
|
|
||||||
tmp = cur;
|
|
||||||
cur = cur->next;
|
|
||||||
tmp->next = prev;
|
|
||||||
prev = tmp;
|
|
||||||
}
|
|
||||||
if (prev != NULL) p->image->shapes = prev;
|
|
||||||
|
|
||||||
// Scale to viewBox
|
// Scale to viewBox
|
||||||
nsvg__scaleToViewbox(p, units);
|
nsvg__scaleToViewbox(p, units);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user