summaryrefslogtreecommitdiff
path: root/drawinglayer
diff options
context:
space:
mode:
authorBartosz Kosiorek <gang65@poczta.onet.pl>2021-06-22 14:36:15 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2021-07-07 22:00:24 +0200
commit032b00382f654962ec787029b3a887f9efbd2a3d (patch)
treeb97b74aff9daf9fb060bb0e7910c7d1e0d3afd5b /drawinglayer
parent70e86db58bd04d919b3f67efad6c94dc967fd900 (diff)
EMF+ tdf#142941 Fixes for SrcRect in DrawImagePoints
The SrcRect could be specified outside of source bitmap. In such cases the Destination bitmap should be displayed as shifted (eg. if position is negative), and scaled properly. Change-Id: Ied6d339703999faaae061802ef6a28e190d5a176 Change-Id: Ia9772ced282684c2c94a261d97d30b53921d6171 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118345 Tested-by: Jenkins Reviewed-by: Bartosz Kosiorek <gang65@poczta.onet.pl> (cherry picked from commit 4992780d2bc996c111b333549314d72f6891308d) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118304 Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'drawinglayer')
-rw-r--r--drawinglayer/source/tools/emfphelperdata.cxx44
1 files changed, 39 insertions, 5 deletions
diff --git a/drawinglayer/source/tools/emfphelperdata.cxx b/drawinglayer/source/tools/emfphelperdata.cxx
index 23ceb6487d66..7a2007da07ba 100644
--- a/drawinglayer/source/tools/emfphelperdata.cxx
+++ b/drawinglayer/source/tools/emfphelperdata.cxx
@@ -1443,7 +1443,8 @@ namespace emfplushelper
EMFPImage& image = *static_cast<EMFPImage *>(maEMFPObjects[flags & 0xff].get());
float sx, sy, sw, sh;
ReadRectangle(rMS, sx, sy, sw, sh);
- ::tools::Rectangle aSource(Point(sx, sy), Size(sw, sh));
+
+ ::tools::Rectangle aSource(Point(sx, sy), Size(sw + 1, sh + 1));
SAL_INFO("drawinglayer.emf", "EMF+\t " << (type == EmfPlusRecordTypeDrawImagePoints ? "DrawImagePoints" : "DrawImage") << " source rectangle: " << sx << "," << sy << " " << sw << "x" << sh);
::basegfx::B2DPoint aDstPoint;
::basegfx::B2DSize aDstSize;
@@ -1464,10 +1465,43 @@ namespace emfplushelper
ReadPoint(rMS, x2, y2, flags); // upper-right
ReadPoint(rMS, x3, y3, flags); // lower-left
- SAL_INFO("drawinglayer.emf", "EMF+\t destination points: P1:" << x1 << "," << y1 << " P2:" << x2 << "," << y2 << " P3:" << x3 << "," << y3);
-
- aDstPoint = ::basegfx::B2DPoint(x1, y1);
- aDstSize = ::basegfx::B2DSize(x2 - x1, y3 - y1);
+ SAL_INFO("drawinglayer.emf",
+ "EMF+\t destination points: " << x1 << "," << y1 << " "
+ << x2 << "," << y2 << " "
+ << x3 << "," << y3);
+ float xDstShift = x1;
+ float yDstShift = y2;
+ float xDstSize = x2 - x1;
+ float yDstSize = y3 - y1;
+ if (image.type == ImageDataTypeBitmap)
+ {
+ const Size aSize(image.graphic.GetBitmapEx().GetSizePixel());
+ if (sx < 0)
+ {
+ // If src position is negative then we need shift image to right
+ xDstShift = xDstShift + ((-sx) / sw) * (x2 - x1);
+ if (sx + sw <= aSize.Width())
+ xDstSize = ((sw + sx) / sw) * xDstSize;
+ else
+ xDstSize = (aSize.Width() / sw) * xDstSize;
+ }
+ else if (sx + sw > aSize.Width())
+ // If the src image is smaller that what we want to cut, then we need to scale down
+ xDstSize = ((aSize.Width() - sx) / sw) * xDstSize;
+
+ if (sy < 0)
+ {
+ yDstShift = yDstShift + ((-sy) / sh) * (y3 - y1);
+ if (sy + sh <= aSize.Height())
+ yDstSize = ((sh + sy) / sh) * yDstSize;
+ else
+ yDstSize = (aSize.Height() / sh) * yDstSize;
+ }
+ else if (sy + sh > aSize.Height())
+ yDstSize = ((aSize.Height() - sy) / sh) * yDstSize;
+ }
+ aDstPoint = ::basegfx::B2DPoint(xDstShift, yDstShift);
+ aDstSize = ::basegfx::B2DSize(xDstSize, yDstSize);
fShearX = x3 - x1;
fShearY = y2 - y1;
}