From 062a004e4a9b85edac5c921bf62fc8eea435e413 Mon Sep 17 00:00:00 2001 From: Aloshi Date: Sun, 6 Apr 2014 18:55:57 -0500 Subject: [PATCH] Added support for automatic rasterization sizes (leave width or height as 0). --- src/resources/SVGResource.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/resources/SVGResource.cpp b/src/resources/SVGResource.cpp index 8a2138100..6dc773a47 100644 --- a/src/resources/SVGResource.cpp +++ b/src/resources/SVGResource.cpp @@ -45,15 +45,25 @@ void SVGResource::initFromMemory(const char* file, size_t length) if(mLastWidth && mLastHeight) rasterizeAt(mLastWidth, mLastHeight); 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) { - if(!mSVGImage || width == 0 || height == 0) + if(!mSVGImage || (width == 0 && height == 0)) 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; mLastHeight = height;