diff options
author | Bartosz Kosiorek <gang65@poczta.onet.pl> | 2021-06-22 14:36:15 +0200 |
---|---|---|
committer | Bartosz Kosiorek <gang65@poczta.onet.pl> | 2021-07-03 14:59:06 +0200 |
commit | 4992780d2bc996c111b333549314d72f6891308d (patch) | |
tree | 23a018e12dd22452c63b5314a44639a77219614c /drawinglayer | |
parent | ded2452a52d21131347a0dc2e25c8161f20fcfad (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>
Diffstat (limited to 'drawinglayer')
-rw-r--r-- | drawinglayer/source/tools/emfphelperdata.cxx | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/drawinglayer/source/tools/emfphelperdata.cxx b/drawinglayer/source/tools/emfphelperdata.cxx index dff19563002d..2568cedb453a 100644 --- a/drawinglayer/source/tools/emfphelperdata.cxx +++ b/drawinglayer/source/tools/emfphelperdata.cxx @@ -1441,7 +1441,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; @@ -1462,10 +1463,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; } |