Added support for automatic rasterization sizes (leave width or height as 0).

This commit is contained in:
Aloshi 2014-04-06 18:55:57 -05:00
parent cafa1b5b8d
commit 062a004e4a

View file

@ -45,15 +45,25 @@ void SVGResource::initFromMemory(const char* file, size_t length)
if(mLastWidth && mLastHeight) if(mLastWidth && mLastHeight)
rasterizeAt(mLastWidth, mLastHeight); rasterizeAt(mLastWidth, mLastHeight);
else else
rasterizeAt((int)round(mSVGImage->width), (int)round(mSVGImage->height)); rasterizeAt((size_t)round(mSVGImage->width), (size_t)round(mSVGImage->height));
} }
void SVGResource::rasterizeAt(size_t width, size_t height) void SVGResource::rasterizeAt(size_t width, size_t height)
{ {
if(!mSVGImage || width == 0 || height == 0) if(!mSVGImage || (width == 0 && height == 0))
return; return;
if(width != (int)round(mSVGImage->width) && height != (int)round(mSVGImage->height)) if(width == 0)
{
// auto scale width to keep aspect
width = (size_t)round((height / mSVGImage->height) * mSVGImage->width);
}else if(height == 0)
{
// auto scale height to keep aspect
height = (size_t)round((width / mSVGImage->width) * mSVGImage->height);
}
if(width != (size_t)round(mSVGImage->width) && height != (size_t)round(mSVGImage->height))
{ {
mLastWidth = width; mLastWidth = width;
mLastHeight = height; mLastHeight = height;