From 59aed1d334de21270628c784920c61f2b8eb1da0 Mon Sep 17 00:00:00 2001 From: Bayram Çiçek Date: Mon, 7 Jun 2021 07:24:05 +0300 Subject: tdf#104995: Fix opposite cropping issue on flipped images in Writer In Writer, cropping an flipped image crops the opposite side of the image instead of the selected side. Fix: update crop values after the flipping(mirroring). Change-Id: I55cfed086bbf63b0c516e1cb6b2624c02b04a6da Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116770 Tested-by: Jenkins Reviewed-by: Muhammet Kara --- sw/source/core/graphic/ndgrf.cxx | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/sw/source/core/graphic/ndgrf.cxx b/sw/source/core/graphic/ndgrf.cxx index 83e8a33a3527..680f142ef1d6 100644 --- a/sw/source/core/graphic/ndgrf.cxx +++ b/sw/source/core/graphic/ndgrf.cxx @@ -775,10 +775,31 @@ GraphicAttr& SwGrfNode::GetGraphicAttr( GraphicAttr& rGA, rGA.SetMirrorFlags( nMirror ); const SwCropGrf& rCrop = rSet.GetCropGrf(); - rGA.SetCrop( convertTwipToMm100( rCrop.GetLeft() ), - convertTwipToMm100( rCrop.GetTop() ), - convertTwipToMm100( rCrop.GetRight() ), - convertTwipToMm100( rCrop.GetBottom() )); + + tools::Long nCropLeft = rCrop.GetLeft(); + tools::Long nCropTop = rCrop.GetTop(); + tools::Long nCropRight = rCrop.GetRight(); + tools::Long nCropBottom = rCrop.GetBottom(); + + // take mirroring of crop values into consideration + // while cropping a flipped image. otherwise, + // cropping will crop the opposite side of the image. + if (rGA.GetMirrorFlags() & BmpMirrorFlags::Vertical) + { + nCropTop = rCrop.GetBottom(); + nCropBottom = rCrop.GetTop(); + } + + if (rGA.GetMirrorFlags() & BmpMirrorFlags::Horizontal) + { + nCropLeft = rCrop.GetRight(); + nCropRight = rCrop.GetLeft(); + } + + rGA.SetCrop( convertTwipToMm100( nCropLeft ), + convertTwipToMm100( nCropTop ), + convertTwipToMm100( nCropRight ), + convertTwipToMm100( nCropBottom )); const SwRotationGrf& rRotation = rSet.GetRotationGrf(); rGA.SetRotation( rRotation.GetValue() ); -- cgit v1.2.3