sd/qa/uitest/data/tdf155863.odp |binary sd/qa/uitest/impress_tests/tdf155863.py | 34 ++++++++++++++++++++++++++++++++ svx/source/svdraw/svdograf.cxx | 24 ++++++++++------------ 3 files changed, 45 insertions(+), 13 deletions(-)
New commits: commit 755d2a8e30c6f6fd0508697dcd8037e3ce560d3b Author: Tibor Nagy <[email protected]> AuthorDate: Fri Jun 16 09:34:29 2023 +0200 Commit: László Németh <[email protected]> CommitDate: Wed Jun 21 19:57:19 2023 +0200 tdf#155863 sd: fix resizing of cropped images to original size Resizing with the function "Original Size" (e.g. in the context menu) resulted distortion in case of cropped images, if the original image and its cropping have different aspect ratios. Now zoom the cropped image to the original resolution instead of stretching it to the same size. Change-Id: I5e59f8b48dc03844a739c3eb803e3195a12d9c6d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153170 Tested-by: László Németh <[email protected]> Reviewed-by: László Németh <[email protected]> (cherry picked from commit a3401a5acb300baa0be9a5e3bd8fa817c4b01c88) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153340 Tested-by: Jenkins diff --git a/sd/qa/uitest/data/tdf155863.odp b/sd/qa/uitest/data/tdf155863.odp new file mode 100644 index 000000000000..2ae286c05d31 Binary files /dev/null and b/sd/qa/uitest/data/tdf155863.odp differ diff --git a/sd/qa/uitest/impress_tests/tdf155863.py b/sd/qa/uitest/impress_tests/tdf155863.py new file mode 100644 index 000000000000..bce8936a3d40 --- /dev/null +++ b/sd/qa/uitest/impress_tests/tdf155863.py @@ -0,0 +1,34 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +from uitest.framework import UITestCase +from libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.uihelper.common import get_state_as_dict, get_url_for_data_file + +class tdf155863(UITestCase): + def test_tdf155863(self): + # This document contains an image with an original size of 7.99cm x 5.74cm. + # The image has been cropped 0.8cm on the left, 3.59cm on the right, 0.99cm at the top, + # and 0.75cm at the bottom. + # Also, it has been resized to a width of 2.1cm and a height of 2.33cm. + with self.ui_test.load_file(get_url_for_data_file("tdf155863.odp")) as document: + xImpressDoc = self.xUITest.getTopFocusWindow() + xEditWin = xImpressDoc.getChild("impress_win") + + # select the image on the first slide + xEditWin.executeAction("SELECT", mkPropertyValues({"OBJECT":"Image"})) + + # click "Original Size" + self.xUITest.executeCommand(".uno:OriginalSize") + + # tdf#155863: Without the fix in place, the image will be distorted due to the wrong size. + self.assertEqual(3597, document.DrawPages[0].getByIndex(0).Size.Width) + self.assertEqual(3998, document.DrawPages[0].getByIndex(0).Size.Height) + +# vim: set shiftwidth=4 softtabstop=4 expandtab: diff --git a/svx/source/svdraw/svdograf.cxx b/svx/source/svdraw/svdograf.cxx index cdb1b0e8301c..b36daff54745 100644 --- a/svx/source/svdraw/svdograf.cxx +++ b/svx/source/svdraw/svdograf.cxx @@ -476,23 +476,21 @@ Size SdrGrafObj::getOriginalSize() const { Size aSize = GetGrafPrefSize(); - if (aGrafInfo.IsCropped()) - { - const tools::Long aCroppedTop(OutputDevice::LogicToLogic(aGrafInfo.GetTopCrop(), getSdrModelFromSdrObject().GetScaleUnit(), GetGrafPrefMapMode().GetMapUnit())); - const tools::Long aCroppedBottom(OutputDevice::LogicToLogic(aGrafInfo.GetBottomCrop(), getSdrModelFromSdrObject().GetScaleUnit(), GetGrafPrefMapMode().GetMapUnit())); - const tools::Long aCroppedLeft(OutputDevice::LogicToLogic(aGrafInfo.GetLeftCrop(), getSdrModelFromSdrObject().GetScaleUnit(), GetGrafPrefMapMode().GetMapUnit())); - const tools::Long aCroppedRight(OutputDevice::LogicToLogic(aGrafInfo.GetRightCrop(), getSdrModelFromSdrObject().GetScaleUnit(), GetGrafPrefMapMode().GetMapUnit())); - const tools::Long aCroppedWidth(aSize.getWidth() - aCroppedLeft + aCroppedRight); - const tools::Long aCroppedHeight(aSize.getHeight() - aCroppedTop + aCroppedBottom); - - aSize = Size ( aCroppedWidth, aCroppedHeight); - } - - if ( GetGrafPrefMapMode().GetMapUnit() == MapUnit::MapPixel ) + if (GetGrafPrefMapMode().GetMapUnit() == MapUnit::MapPixel) aSize = Application::GetDefaultDevice()->PixelToLogic(aSize, MapMode(getSdrModelFromSdrObject().GetScaleUnit())); else aSize = OutputDevice::LogicToLogic(aSize, GetGrafPrefMapMode(), MapMode(getSdrModelFromSdrObject().GetScaleUnit())); + if (aGrafInfo.IsCropped()) + { + const tools::Long aCroppedWidth(aSize.getWidth() - aGrafInfo.GetLeftCrop() + - aGrafInfo.GetRightCrop()); + const tools::Long aCroppedHeight(aSize.getHeight() - aGrafInfo.GetTopCrop() + - aGrafInfo.GetBottomCrop()); + + aSize = Size(aCroppedWidth, aCroppedHeight); + } + return aSize; }
