summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2014-12-18 19:17:25 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-12-18 19:28:19 +0100
commit20f8006e21943b08f1f152e4a0359c9ebe4786f2 (patch)
tree1a28cc7eea83652d912cbe35ec1266a6e55ca3ca
parent4423637d4e9c949b22109f7db029c9afaccc7d7e (diff)
fdo#87448 EnhancedCustomShape2d: fix handling of scaled ARCANGLETO commands
Change-Id: I7daf52a60e3fac8d9f86b464e86af60e0495fcb1
-rw-r--r--svx/source/customshapes/EnhancedCustomShape2d.cxx12
-rw-r--r--sw/qa/extras/uiwriter/data/fdo87448.odtbin0 -> 9989 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx44
3 files changed, 52 insertions, 4 deletions
diff --git a/svx/source/customshapes/EnhancedCustomShape2d.cxx b/svx/source/customshapes/EnhancedCustomShape2d.cxx
index 225ec2650c89..9a669213ef7f 100644
--- a/svx/source/customshapes/EnhancedCustomShape2d.cxx
+++ b/svx/source/customshapes/EnhancedCustomShape2d.cxx
@@ -52,6 +52,7 @@
#include <basegfx/color/bcolortools.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
+#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <rtl/strbuf.hxx>
#include <math.h>
@@ -1770,8 +1771,7 @@ void EnhancedCustomShape2d::CreateSubPath( sal_uInt16& rSrcPt, sal_uInt16& rSegm
GetParameter ( fStartAngle, seqCoordinates[ (sal_uInt16)( rSrcPt + 1) ].First, false, false );
GetParameter ( fSwingAngle, seqCoordinates[ (sal_uInt16)( rSrcPt + 1 ) ].Second, false, false );
- fWR *= fXScale;
- fHR *= fYScale;
+ // Convert angles to radians, but don't do any scaling / translation yet.
fStartAngle *= F_PI180;
fSwingAngle *= F_PI180;
@@ -1783,7 +1783,7 @@ void EnhancedCustomShape2d::CreateSubPath( sal_uInt16& rSrcPt, sal_uInt16& rSegm
if (aNewB2DPolygon.count() > 0)
{
basegfx::B2DPoint aStartPointB2D( aNewB2DPolygon.getB2DPoint(aNewB2DPolygon.count() - 1 ) );
- Point aStartPoint( aStartPointB2D.getX(), aStartPointB2D.getY() );
+ Point aStartPoint( 0, 0 );
double fT = atan2((fWR*sin(fStartAngle)), (fHR*cos(fStartAngle)));
double fTE = atan2((fWR*sin(fStartAngle + fSwingAngle)), fHR*cos(fStartAngle + fSwingAngle));
@@ -1798,7 +1798,11 @@ void EnhancedCustomShape2d::CreateSubPath( sal_uInt16& rSrcPt, sal_uInt16& rSegm
OSL_TRACE("ARCANGLETO rect: %d, %d x %d, %d start: %d, %d end: %d, %d clockwise: %d",
aRect.Left(), aRect.Top(), aRect.Right(), aRect.Bottom(),
aStartPoint.X(), aStartPoint.Y(), aEndPoint.X(), aEndPoint.Y(), bClockwise);
- aNewB2DPolygon.append(CreateArc( aRect, bClockwise ? aEndPoint : aStartPoint, bClockwise ? aStartPoint : aEndPoint, bClockwise, aStartPoint == aEndPoint && fSwingAngle > F_PI));
+ basegfx::B2DPolygon aArc = CreateArc( aRect, bClockwise ? aEndPoint : aStartPoint, bClockwise ? aStartPoint : aEndPoint, bClockwise, aStartPoint == aEndPoint && fSwingAngle > F_PI);
+ // Now that we have the arc, move it to aStartPointB2D and also scale it.
+ basegfx::B2DHomMatrix aMatrix = basegfx::tools::createScaleTranslateB2DHomMatrix(fXScale, fYScale, aStartPointB2D.getX(), aStartPointB2D.getY());
+ aArc.transform(aMatrix);
+ aNewB2DPolygon.append(aArc);
}
rSrcPt += 2;
diff --git a/sw/qa/extras/uiwriter/data/fdo87448.odt b/sw/qa/extras/uiwriter/data/fdo87448.odt
new file mode 100644
index 000000000000..3618dcd9634f
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/fdo87448.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index c840b44c8ec0..8073a4317b6f 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -8,6 +8,7 @@
*/
#include <com/sun/star/awt/FontWeight.hpp>
+#include <com/sun/star/drawing/GraphicExportFilter.hpp>
#include <com/sun/star/i18n/TextConversionOption.hpp>
#include <swmodeltestbase.hxx>
#include <ndtxt.hxx>
@@ -26,6 +27,8 @@
#include <hhcwrp.hxx>
#include <swacorr.hxx>
#include <editeng/acorrcfg.hxx>
+#include <unotools/streamwrap.hxx>
+#include <test/mtfxmldump.hxx>
#include <svx/svdpage.hxx>
#include <svx/svdview.hxx>
@@ -72,6 +75,7 @@ public:
void testCreatePortions();
void testBookmarkUndo();
void testFdo85876();
+ void testFdo87448();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
@@ -101,6 +105,7 @@ public:
CPPUNIT_TEST(testCreatePortions);
CPPUNIT_TEST(testBookmarkUndo);
CPPUNIT_TEST(testFdo85876);
+ CPPUNIT_TEST(testFdo87448);
CPPUNIT_TEST_SUITE_END();
@@ -760,6 +765,45 @@ void SwUiWriterTest::testFdo85876()
}
}
+void SwUiWriterTest::testFdo87448()
+{
+ createDoc("fdo87448.odt");
+
+ // Save the first shape to a metafile.
+ uno::Reference<drawing::XGraphicExportFilter> xGraphicExporter = drawing::GraphicExportFilter::create(comphelper::getProcessComponentContext());
+ uno::Reference<lang::XComponent> xSourceDoc(getShape(1), uno::UNO_QUERY);
+ xGraphicExporter->setSourceDocument(xSourceDoc);
+
+ SvMemoryStream aStream;
+ uno::Reference<io::XOutputStream> xOutputStream(new utl::OStreamWrapper(aStream));
+ uno::Sequence<beans::PropertyValue> aDescriptor =
+ {
+ beans::PropertyValue("OutputStream", sal_Int32(0), uno::makeAny(xOutputStream), beans::PropertyState_DIRECT_VALUE),
+ beans::PropertyValue("FilterName", sal_Int32(0), uno::makeAny(OUString("SVM")), beans::PropertyState_DIRECT_VALUE)
+ };
+ xGraphicExporter->filter(aDescriptor);
+ aStream.Seek(STREAM_SEEK_TO_BEGIN);
+
+ // Read it back and dump it as an XML file.
+ Graphic aGraphic;
+ ReadGraphic(aStream, aGraphic);
+ const GDIMetaFile& rMetaFile = aGraphic.GetGDIMetaFile();
+ MetafileXmlDump dumper;
+ xmlDocPtr pXmlDoc = dumper.dumpAndParse(const_cast<GDIMetaFile&>(rMetaFile));
+
+ // The first polyline in the document has a number of points to draw arcs,
+ // the last one jumps back to the start, so we call "end" the last but one.
+ sal_Int32 nFirstEnd = getXPath(pXmlDoc, "/metafile/polyline[1]/point[last()-1]", "x").toInt32();
+ // The second polyline has a different start point, but the arc it draws
+ // should end at the ~same position as the first polyline.
+ sal_Int32 nSecondEnd = getXPath(pXmlDoc, "/metafile/polyline[2]/point[last()]", "x").toInt32();
+
+ // nFirstEnd was 6023 and nSecondEnd was 6648, now they should be much closer, e.g. nFirstEnd = 6550, nSecondEnd = 6548
+ OString aMsg = "nFirstEnd is " + OString::number(nFirstEnd) + ", nSecondEnd is " + OString::number(nSecondEnd);
+ // Assert that the difference is less than half point.
+ CPPUNIT_ASSERT_MESSAGE(aMsg.getStr(), abs(nFirstEnd - nSecondEnd) < 10);
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();