Issue #20: fixed stroke scaling handling

- better handling of getting stroke scaling from matrix
This commit is contained in:
Mikko Mononen 2014-11-05 11:12:59 +02:00
parent 205d5197d2
commit 4101587c9a

View File

@ -767,6 +767,13 @@ static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const f
return grad;
}
static float nsvg__getAverageScale(float* t)
{
float sx = sqrtf(t[0]*t[0] + t[2]*t[2]);
float sy = sqrtf(t[1]*t[1] + t[3]*t[3]);
return (sx + sy) * 0.5f;
}
static void nsvg__addShape(NSVGparser* p)
{
NSVGattrib* attr = nsvg__getAttr(p);
@ -781,7 +788,7 @@ static void nsvg__addShape(NSVGparser* p)
if (shape == NULL) goto error;
memset(shape, 0, sizeof(NSVGshape));
scale = nsvg__maxf(fabsf(attr->xform[0]), fabsf(attr->xform[3]));
scale = nsvg__getAverageScale(attr->xform);
shape->strokeWidth = attr->strokeWidth * scale;
shape->strokeLineJoin = attr->strokeLineJoin;
shape->strokeLineCap = attr->strokeLineCap;