diff options
author | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2012-12-05 18:40:16 +0100 |
---|---|---|
committer | Cédric Bosdonnat <cedric.bosdonnat@free.fr> | 2012-12-05 18:40:32 +0100 |
commit | e2a35977ca056d7bf1dae3a9c41ae135a85892fd (patch) | |
tree | 06347251cf4bbe7ed010eb25809c0547f8cef1e2 /sfx2 | |
parent | Template manager: pickup non-empty thumbnails for folders (diff) | |
download | core-e2a35977ca056d7bf1dae3a9c41ae135a85892fd.tar.gz core-e2a35977ca056d7bf1dae3a9c41ae135a85892fd.zip |
Template manager: keep thumbnails ratio when scaling down
Change-Id: Ic597dd9fd12895c0d21f678cba44feba9f6fcd47
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/control/templateabstractview.cxx | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx index 8cbf60fcea4c..0baed64e28d5 100644 --- a/sfx2/source/control/templateabstractview.cxx +++ b/sfx2/source/control/templateabstractview.cxx @@ -137,10 +137,33 @@ BitmapEx TemplateAbstractView::scaleImg (const BitmapEx &rImg, long width, long { BitmapEx aImg = rImg; - int sWidth = std::min(aImg.GetSizePixel().getWidth(),width); - int sHeight = std::min(aImg.GetSizePixel().getHeight(),height); + if ( !rImg.IsEmpty() ) + { + + const Size& aImgSize = aImg.GetSizePixel(); + double nRatio = double(aImgSize.getWidth()) / double(aImgSize.getHeight()); + + long nDestWidth = aImgSize.getWidth(); + long nDestHeight = aImgSize.getHeight(); + + // Which one side is the overflowing most? + long nDistW = aImgSize.getWidth() - width; + long nDistH = aImgSize.getHeight() - height; + + // Use the biggest overflow side to make it fit the destination + if ( nDistW >= nDistH && nDistW > 0 ) + { + nDestWidth = width; + nDestHeight = width / nRatio; + } + else if ( nDistW < nDistH && nDistH > 0 ) + { + nDestHeight = height; + nDestWidth = height * nRatio; + } - aImg.Scale(Size(sWidth,sHeight),BMP_SCALE_INTERPOLATE); + aImg.Scale(Size(nDestWidth,nDestHeight)); + } return aImg; } |