NanoSVG: update image size to the actual size after scaling.
(cherry picked from commit 2c07866fff
)
This commit is contained in:
parent
b0e09327db
commit
bdbd7f0c9c
|
@ -3642,6 +3642,8 @@ static void nsvg__scaleToViewbox( NSVGparser* p, const char* units )
|
||||||
float tx, ty, sx, sy, us, bounds[4], t[6], avgs;
|
float tx, ty, sx, sy, us, bounds[4], t[6], avgs;
|
||||||
int i;
|
int i;
|
||||||
float* pt;
|
float* pt;
|
||||||
|
bool updw = false;
|
||||||
|
bool updh = false;
|
||||||
|
|
||||||
// Guess image size if not set completely.
|
// Guess image size if not set completely.
|
||||||
nsvg__imageBounds( p, bounds );
|
nsvg__imageBounds( p, bounds );
|
||||||
|
@ -3673,10 +3675,16 @@ static void nsvg__scaleToViewbox( NSVGparser* p, const char* units )
|
||||||
}
|
}
|
||||||
|
|
||||||
if( p->image->width == 0 )
|
if( p->image->width == 0 )
|
||||||
|
{
|
||||||
p->image->width = p->viewWidth;
|
p->image->width = p->viewWidth;
|
||||||
|
updw = true;
|
||||||
|
}
|
||||||
|
|
||||||
if( p->image->height == 0 )
|
if( p->image->height == 0 )
|
||||||
|
{
|
||||||
p->image->height = p->viewHeight;
|
p->image->height = p->viewHeight;
|
||||||
|
updh = true;
|
||||||
|
}
|
||||||
|
|
||||||
tx = -p->viewMinx;
|
tx = -p->viewMinx;
|
||||||
ty = -p->viewMiny;
|
ty = -p->viewMiny;
|
||||||
|
@ -3691,6 +3699,13 @@ static void nsvg__scaleToViewbox( NSVGparser* p, const char* units )
|
||||||
{
|
{
|
||||||
// fit whole image into viewbox
|
// fit whole image into viewbox
|
||||||
sx = sy = nsvg__minf( sx, sy );
|
sx = sy = nsvg__minf( sx, sy );
|
||||||
|
|
||||||
|
if( updw )
|
||||||
|
p->image->width = p->viewWidth * sx;
|
||||||
|
|
||||||
|
if( updh )
|
||||||
|
p->image->height = p->viewHeight * sy;
|
||||||
|
|
||||||
tx += nsvg__viewAlign( p->viewWidth * sx, p->image->width, p->alignX ) / sx;
|
tx += nsvg__viewAlign( p->viewWidth * sx, p->image->width, p->alignX ) / sx;
|
||||||
ty += nsvg__viewAlign( p->viewHeight * sy, p->image->height, p->alignY ) / sy;
|
ty += nsvg__viewAlign( p->viewHeight * sy, p->image->height, p->alignY ) / sy;
|
||||||
}
|
}
|
||||||
|
@ -3698,6 +3713,13 @@ static void nsvg__scaleToViewbox( NSVGparser* p, const char* units )
|
||||||
{
|
{
|
||||||
// fill whole viewbox with image
|
// fill whole viewbox with image
|
||||||
sx = sy = nsvg__maxf( sx, sy );
|
sx = sy = nsvg__maxf( sx, sy );
|
||||||
|
|
||||||
|
if( updw )
|
||||||
|
p->image->width = p->viewWidth * sx;
|
||||||
|
|
||||||
|
if( updh )
|
||||||
|
p->image->height = p->viewHeight * sy;
|
||||||
|
|
||||||
tx += nsvg__viewAlign( p->viewWidth * sx, p->image->width, p->alignX ) / sx;
|
tx += nsvg__viewAlign( p->viewWidth * sx, p->image->width, p->alignX ) / sx;
|
||||||
ty += nsvg__viewAlign( p->viewHeight * sy, p->image->height, p->alignY ) / sy;
|
ty += nsvg__viewAlign( p->viewHeight * sy, p->image->height, p->alignY ) / sy;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue