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:03:46 +0100 |
commit | 5523e04065c0df5de1d9e2ed178463137a1e0bb0 (patch) | |
tree | f0b809553772fa524f0fc69ade2801e2af2a3631 /sfx2 | |
parent | 6ec1253285ec39b31b82ba7bc7a2b0bd0f98ef7a (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; |