Kaydet (Commit) 7f9b2423 authored tarafından Miklos Vajna's avatar Miklos Vajna

DOCX drawingML import: fix remaining rotation / flip combinations

With this, each rotation = 0 / 90 / 180 / 270 and flip = none /
horizontal / vertical / horizontal+vertical combination (16 cases) are
imported perfectly.

Also adjust a few testcases -- now that in many cases we only set the
position in oox, some rounding errors went away.

Change-Id: I5567a7d6964775f2caf10a0e539f3eb84d10461e
üst ef58e108
...@@ -418,7 +418,9 @@ Reference< XShape > Shape::createAndInsert( ...@@ -418,7 +418,9 @@ Reference< XShape > Shape::createAndInsert(
aServiceName == "com.sun.star.drawing.ConnectorShape" ); aServiceName == "com.sun.star.drawing.ConnectorShape" );
bool bUseRotationTransform = ( !mbWps || bool bUseRotationTransform = ( !mbWps ||
aServiceName == "com.sun.star.drawing.LineShape" || aServiceName == "com.sun.star.drawing.LineShape" ||
aServiceName == "com.sun.star.drawing.GroupShape" ); aServiceName == "com.sun.star.drawing.GroupShape" ||
mbFlipH ||
mbFlipV );
basegfx::B2DHomMatrix aTransformation; basegfx::B2DHomMatrix aTransformation;
...@@ -458,6 +460,9 @@ Reference< XShape > Shape::createAndInsert( ...@@ -458,6 +460,9 @@ Reference< XShape > Shape::createAndInsert(
if( maPosition.X != 0 || maPosition.Y != 0) if( maPosition.X != 0 || maPosition.Y != 0)
{ {
// if global position is used, add it to transformation // if global position is used, add it to transformation
if (mbWps && aParentTransformation.isIdentity())
aTransformation.translate( maPosition.X * 360, maPosition.Y * 360);
else
aTransformation.translate( maPosition.X, maPosition.Y ); aTransformation.translate( maPosition.X, maPosition.Y );
} }
...@@ -986,7 +991,7 @@ Reference< XShape > Shape::createAndInsert( ...@@ -986,7 +991,7 @@ Reference< XShape > Shape::createAndInsert(
// These can have a custom geometry, so position should be set here, // These can have a custom geometry, so position should be set here,
// after creation but before custom shape handling, using the position // after creation but before custom shape handling, using the position
// we got from the caller. // we got from the caller.
if (mbWps && aServiceName != "com.sun.star.text.TextFrame") if (mbWps && aServiceName == "com.sun.star.drawing.LineShape")
mxShape->setPosition(maPosition); mxShape->setPosition(maPosition);
if( bIsCustomShape ) if( bIsCustomShape )
......
...@@ -1169,7 +1169,13 @@ void DrawingML::WriteShapeTransformation( Reference< XShape > rXShape, sal_Int32 ...@@ -1169,7 +1169,13 @@ void DrawingML::WriteShapeTransformation( Reference< XShape > rXShape, sal_Int32
} }
if (!bSuppressRotation) if (!bSuppressRotation)
{ {
// See SdrObjCustomShape::NbcRotate().
int nSwap = 0;
if (bFlipH)
nSwap ^= 1;
if (bFlipV) if (bFlipV)
nSwap ^= 1;
if (nSwap)
{ {
nRotation=(nRotation+18000)%36000; nRotation=(nRotation+18000)%36000;
} }
......
...@@ -315,6 +315,17 @@ DECLARE_OOXMLEXPORT_TEST(testRot90Fliph, "rot90-fliph.docx") ...@@ -315,6 +315,17 @@ DECLARE_OOXMLEXPORT_TEST(testRot90Fliph, "rot90-fliph.docx")
} }
} }
DECLARE_OOXMLEXPORT_TEST(testRot180Flipv, "rot180-flipv.docx")
{
// 180° rotation got lost after roundtrip.
if (xmlDocPtr pXmlDoc = parseExport("word/document.xml"))
{
assertXPath(pXmlDoc, "//a:xfrm", "flipV", "1");
// This attribute was completely missing.
assertXPath(pXmlDoc, "//a:xfrm", "rot", "10800000");
}
}
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -1048,7 +1048,7 @@ DECLARE_OOXMLEXPORT_TEST(testTableFloating, "table-floating.docx") ...@@ -1048,7 +1048,7 @@ DECLARE_OOXMLEXPORT_TEST(testTableFloating, "table-floating.docx")
// After import, table is inside a TextFrame. // After import, table is inside a TextFrame.
uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY); uno::Reference<beans::XPropertySet> xShape(getShape(1), uno::UNO_QUERY);
// This was 0, should be the the opposite of (left margin + half of the border width). // This was 0, should be the the opposite of (left margin + half of the border width).
CPPUNIT_ASSERT_EQUAL(sal_Int32(-198), getProperty<sal_Int32>(xShape, "HoriOrientPosition")); CPPUNIT_ASSERT_EQUAL(sal_Int32(-199), getProperty<sal_Int32>(xShape, "HoriOrientPosition"));
// Was 0 as well, should be the right margin. // Was 0 as well, should be the right margin.
CPPUNIT_ASSERT_EQUAL(sal_Int32(250), getProperty<sal_Int32>(xShape, "RightMargin")); CPPUNIT_ASSERT_EQUAL(sal_Int32(250), getProperty<sal_Int32>(xShape, "RightMargin"));
} }
......
...@@ -319,17 +319,17 @@ DECLARE_OOXMLEXPORT_TEST(testDMLGroupShapeChildPosition, "dml-groupshape-childpo ...@@ -319,17 +319,17 @@ DECLARE_OOXMLEXPORT_TEST(testDMLGroupShapeChildPosition, "dml-groupshape-childpo
uno::Reference<drawing::XShapes> xGroup(getShape(1), uno::UNO_QUERY); uno::Reference<drawing::XShapes> xGroup(getShape(1), uno::UNO_QUERY);
uno::Reference<drawing::XShape> xChildGroup(xGroup->getByIndex(1), uno::UNO_QUERY); uno::Reference<drawing::XShape> xChildGroup(xGroup->getByIndex(1), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? -2119 : -2121), xChildGroup->getPosition().X); CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? -2119 : -2122), xChildGroup->getPosition().X);
CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? 11338 : 11335), xChildGroup->getPosition().Y); CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? 11336 : 11333), xChildGroup->getPosition().Y);
xGroup.set(xChildGroup, uno::UNO_QUERY); xGroup.set(xChildGroup, uno::UNO_QUERY);
xChildGroup.set(xGroup->getByIndex(0), uno::UNO_QUERY); xChildGroup.set(xGroup->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? -1856 : -1858), xChildGroup->getPosition().X); CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? -1856 : -1858), xChildGroup->getPosition().X);
CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? 11338 : 11335), xChildGroup->getPosition().Y); CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? 11336 : 11333), xChildGroup->getPosition().Y);
xChildGroup.set(xGroup->getByIndex(1), uno::UNO_QUERY); xChildGroup.set(xGroup->getByIndex(1), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? -2119 : -2121), xChildGroup->getPosition().X); CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? -2119 : -2122), xChildGroup->getPosition().X);
CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? 14028 : 14025), xChildGroup->getPosition().Y); CPPUNIT_ASSERT_EQUAL(sal_Int32(mbExported ? 14026 : 14023), xChildGroup->getPosition().Y);
} }
DECLARE_OOXMLEXPORT_TEST(testDMLGradientFillTheme, "dml-gradientfill-theme.docx") DECLARE_OOXMLEXPORT_TEST(testDMLGradientFillTheme, "dml-gradientfill-theme.docx")
......
...@@ -363,15 +363,17 @@ public: ...@@ -363,15 +363,17 @@ public:
uno::makeAny(nVertOrient)); uno::makeAny(nVertOrient));
} }
void applyRelativePosition(uno::Reference< beans::XPropertySet > xGraphicObjectProperties) const void applyRelativePosition(uno::Reference< beans::XPropertySet > xGraphicObjectProperties, bool bRelativeOnly = false) const
{ {
PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier(); PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
if (!bRelativeOnly)
xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_ORIENT_POSITION), xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_ORIENT_POSITION),
uno::makeAny(nLeftPosition)); uno::makeAny(nLeftPosition));
xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_ORIENT_RELATION ), xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_HORI_ORIENT_RELATION ),
uno::makeAny(nHoriRelation)); uno::makeAny(nHoriRelation));
xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_PAGE_TOGGLE ), xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_PAGE_TOGGLE ),
uno::makeAny(bPageToggle)); uno::makeAny(bPageToggle));
if (!bRelativeOnly)
xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_ORIENT_POSITION), xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_ORIENT_POSITION),
uno::makeAny(nTopPosition)); uno::makeAny(nTopPosition));
xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_ORIENT_RELATION ), xGraphicObjectProperties->setPropertyValue(rPropNameSupplier.GetName( PROP_VERT_ORIENT_RELATION ),
...@@ -805,7 +807,7 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue) ...@@ -805,7 +807,7 @@ void GraphicImport::lcl_attribute(Id nName, Value& rValue)
if (nRotation) if (nRotation)
xShapeProps->setPropertyValue("RotateAngle", uno::makeAny(nRotation)); xShapeProps->setPropertyValue("RotateAngle", uno::makeAny(nRotation));
} }
m_pImpl->applyRelativePosition(xShapeProps); m_pImpl->applyRelativePosition(xShapeProps, /*bRelativeOnly=*/true);
xShapeProps->setPropertyValue("SurroundContour", uno::makeAny(m_pImpl->bContour)); xShapeProps->setPropertyValue("SurroundContour", uno::makeAny(m_pImpl->bContour));
m_pImpl->applyMargins(xShapeProps); m_pImpl->applyMargins(xShapeProps);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment