diff options
author | Jan Holesovsky <kendy@collabora.com> | 2013-12-12 21:54:58 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2013-12-13 13:01:27 +0100 |
commit | 2cb703067b827b0ebb562845c82dae5e35161e72 (patch) | |
tree | 70b42fc502c13550c2d89da5fec6e920554b764f /sfx2 | |
parent | f57be7e4c16556f515241f80e81ec4d6eaeb3ca2 (diff) |
template view: Simplify code.
Change-Id: I48fc6fa86a9953db87e59a83714d4d7b0ff8d64a
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/control/templateabstractview.cxx | 31 |
1 files changed, 11 insertions, 20 deletions
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; |