From 2cb703067b827b0ebb562845c82dae5e35161e72 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Thu, 12 Dec 2013 21:54:58 +0100 Subject: template view: Simplify code. Change-Id: I48fc6fa86a9953db87e59a83714d4d7b0ff8d64a --- sfx2/source/control/templateabstractview.cxx | 31 ++++++++++------------------ 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'sfx2') diff --git a/sfx2/source/control/templateabstractview.cxx b/sfx2/source/control/templateabstractview.cxx index 5de8a8ee1994..f80908438c6c 100644 --- a/sfx2/source/control/templateabstractview.cxx +++ b/sfx2/source/control/templateabstractview.cxx @@ -248,32 +248,23 @@ BitmapEx TemplateAbstractView::scaleImg (const BitmapEx &rImg, long width, long { BitmapEx aImg = rImg; - if ( !rImg.IsEmpty() ) + if (!rImg.IsEmpty()) { + Size aSize = rImg.GetSizePixel(); - const Size& aImgSize = aImg.GetSizePixel(); - double nRatio = double(aImgSize.getWidth()) / double(aImgSize.getHeight()); + if (aSize.Width() == 0) + aSize.Width() = 1; - long nDestWidth = aImgSize.getWidth(); - long nDestHeight = aImgSize.getHeight(); + if (aSize.Height() == 0) + aSize.Height() = 1; - // Which one side is the overflowing most? - long nDistW = aImgSize.getWidth() - width; - long nDistH = aImgSize.getHeight() - height; + // make the picture fit the given width/height constraints + double nRatio = std::min(double(width)/double(aSize.Width()), double(height)/double(aSize.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; - } + // don't up-scale + nRatio = std::min(nRatio, 1.0); - aImg.Scale(Size(nDestWidth,nDestHeight)); + aImg.Scale(Size(aSize.Width() * nRatio, aSize.Height() * nRatio)); } return aImg; -- cgit