summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drawinglayer/source/tools/emfphelperdata.cxx44
-rw-r--r--emfio/qa/cppunit/emf/EmfImportTest.cxx34
-rw-r--r--emfio/qa/cppunit/emf/data/TestDrawImagePointsTypeBitmap.emfbin0 -> 8600 bytes
3 files changed, 73 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;
}
diff --git a/emfio/qa/cppunit/emf/EmfImportTest.cxx b/emfio/qa/cppunit/emf/EmfImportTest.cxx
index 63e1d575803b..c60a4870f6f1 100644
--- a/emfio/qa/cppunit/emf/EmfImportTest.cxx
+++ b/emfio/qa/cppunit/emf/EmfImportTest.cxx
@@ -46,6 +46,7 @@ class Test : public test::BootstrapFixture, public XmlTestTools, public unotest:
uno::Reference<lang::XComponent> mxComponent;
void testPolyPolygon();
+ void TestDrawImagePointsTypeBitmap();
void TestDrawString();
void TestDrawStringAlign();
void TestDrawStringTransparent();
@@ -87,6 +88,7 @@ public:
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testPolyPolygon);
+ CPPUNIT_TEST(TestDrawImagePointsTypeBitmap);
CPPUNIT_TEST(TestDrawString);
CPPUNIT_TEST(TestDrawStringAlign);
CPPUNIT_TEST(TestDrawStringTransparent);
@@ -190,6 +192,38 @@ void Test::testPolyPolygon()
}
+void Test::TestDrawImagePointsTypeBitmap()
+{
+ // tdf#142941 EMF+ file with ObjectTypeImage, FillRects, DrawImagePoints ,records
+ // The test is checking the position of displaying bitmap with too large SrcRect
+
+ Primitive2DSequence aSequence
+ = parseEmf(u"/emfio/qa/cppunit/emf/data/TestDrawImagePointsTypeBitmap.emf");
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(aSequence.getLength()));
+ drawinglayer::Primitive2dXmlDump dumper;
+ xmlDocUniquePtr pDocument
+ = dumper.dumpAndParse(comphelper::sequenceToContainer<Primitive2DContainer>(aSequence));
+ CPPUNIT_ASSERT(pDocument);
+
+ assertXPath(pDocument, "/primitive2D/metafile/transform/polypolygoncolor", "color", "#0080ff");
+ assertXPath(pDocument, "/primitive2D/metafile/transform/bitmap", "xy11", "5346");
+ assertXPath(pDocument, "/primitive2D/metafile/transform/bitmap", "xy12", "0");
+ assertXPath(pDocument, "/primitive2D/metafile/transform/bitmap", "xy13", "5558");
+ assertXPath(pDocument, "/primitive2D/metafile/transform/bitmap", "xy21", "0");
+ assertXPath(pDocument, "/primitive2D/metafile/transform/bitmap", "xy22", "4716");
+ assertXPath(pDocument, "/primitive2D/metafile/transform/bitmap", "xy23", "5564");
+ assertXPath(
+ pDocument, "/primitive2D/metafile/transform/bitmap/data[2]", "row",
+ "020202,ffffff,ffffff,ffffff,fefefe,ffffff,ffffff,fefefe,ffffff,ffffff,f8f8f8,ffffff,"
+ "fdfdfd,ffffff,ffffff,fdfdfd,ffffff,ffffff,ffffff,fbfbfb,010101,ffffff,fefefe,ffffff,"
+ "ffffff,fbfbfb,ffffff,fdfdfd,fcfcfc,fdfdfd,ffffff,ffffff,ffffff,ffffff,ffffff,ffffff,"
+ "ffffff,ffffff,ffffff,ffffff,020202,fdfdfd,ffffff,ffffff,fefefe,ffffff,ffffff,ffffff,"
+ "ffffff,fbfbfb,fefefe,ffffff,fcfcfc,ffffff,fdfdfd,ffffff,ffffff,ffffff,ffffff,fbfbfb,"
+ "010101,ffffff,fefefe,ffffff,ffffff,ffffff,fcfcfc,ffffff,fafafa,ffffff,ffffff,fefefe,"
+ "ffffff,fdfdfd,fefefe,fefefe,ffffff,ffffff,fdfdfd,fffbfb,1e0000,8f4347,b13a3e,b82d32,"
+ "bb3438,b73237,b63338,b33035,b63338");
+}
+
void Test::TestDrawString()
{
#if HAVE_MORE_FONTS
diff --git a/emfio/qa/cppunit/emf/data/TestDrawImagePointsTypeBitmap.emf b/emfio/qa/cppunit/emf/data/TestDrawImagePointsTypeBitmap.emf
new file mode 100644
index 000000000000..291052a165a8
--- /dev/null
+++ b/emfio/qa/cppunit/emf/data/TestDrawImagePointsTypeBitmap.emf
Binary files differ