summaryrefslogtreecommitdiff
path: root/oox/source
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2021-04-19 20:27:32 +0200
committerMichael Stahl <michael.stahl@allotropia.de>2021-04-21 11:58:37 +0200
commit7b3ea547bddd08e483c49ed5b3ff822f782a0aae (patch)
treeae5582c99189b8f702f7046cea8666847d99500a /oox/source
parent054d0f8f5e6791d03081be7be19abeaad8aab918 (diff)
tdf#122962 DOCX drawingML export: fix polygon shape in group shape
Regression from commit cfb5b20cdc230320ff9f864d1cfd81aaea221da0 (DocxAttributeOutput::OutputFlyFrame_Impl: enable DML export by default, 2013-12-18), there were two problems here. First, <a:chOff> and <a:chExt> was not written for docx group shapes. This can be done for toplevel shapes just by writing what would be the shape position and size (but for docx, we don't write the size). Second, (poly)polygon shapes used the bounding rectangle of their points as size, which doesn't necessarily match the shape size. Given that the group shape is meant to simply contain its children in LibreOffice (and not have an own size), switch to using the UNO API for polygon shapes as well, that way the two sizes will always match. Change-Id: I4406ddefe5f6105aa2fc74d805359add452936bb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114305 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> (cherry picked from commit 4cb71fefc61d9015a0142f3a4fdafc5250913f2c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114279 Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'oox/source')
-rw-r--r--oox/source/export/drawingml.cxx29
-rw-r--r--oox/source/export/shapes.cxx8
2 files changed, 28 insertions, 9 deletions
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 94b67cb379f2..8cfd4a6dabc5 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -1686,7 +1686,22 @@ void DrawingML::WriteXGraphicStretch(uno::Reference<beans::XPropertySet> const &
mpFS->endElementNS(XML_a, XML_stretch);
}
-void DrawingML::WriteTransformation(const tools::Rectangle& rRect,
+namespace
+{
+bool IsTopGroupObj(const uno::Reference<drawing::XShape>& xShape)
+{
+ SdrObject* pObject = GetSdrObjectFromXShape(xShape);
+ if (!pObject)
+ return false;
+
+ if (pObject->getParentSdrObjectFromSdrObject())
+ return false;
+
+ return pObject->IsGroupObject();
+}
+}
+
+void DrawingML::WriteTransformation(const Reference< XShape >& xShape, const tools::Rectangle& rRect,
sal_Int32 nXmlNamespace, bool bFlipH, bool bFlipV, sal_Int32 nRotation, bool bIsGroupShape)
{
@@ -1696,7 +1711,9 @@ void DrawingML::WriteTransformation(const tools::Rectangle& rRect,
XML_rot, sax_fastparser::UseIf(OString::number(nRotation), nRotation % 21600000 != 0));
sal_Int32 nLeft = rRect.Left();
+ sal_Int32 nChildLeft = nLeft;
sal_Int32 nTop = rRect.Top();
+ sal_Int32 nChildTop = nTop;
if (GetDocumentType() == DOCUMENT_DOCX && !m_xParent.is())
{
nLeft = 0;
@@ -1710,11 +1727,11 @@ void DrawingML::WriteTransformation(const tools::Rectangle& rRect,
XML_cx, OString::number(oox::drawingml::convertHmmToEmu(rRect.GetWidth())),
XML_cy, OString::number(oox::drawingml::convertHmmToEmu(rRect.GetHeight())));
- if (GetDocumentType() != DOCUMENT_DOCX && bIsGroupShape)
+ if (bIsGroupShape && (GetDocumentType() != DOCUMENT_DOCX || IsTopGroupObj(xShape)))
{
mpFS->singleElementNS(XML_a, XML_chOff,
- XML_x, OString::number(oox::drawingml::convertHmmToEmu(nLeft)),
- XML_y, OString::number(oox::drawingml::convertHmmToEmu(nTop)));
+ XML_x, OString::number(oox::drawingml::convertHmmToEmu(nChildLeft)),
+ XML_y, OString::number(oox::drawingml::convertHmmToEmu(nChildTop)));
mpFS->singleElementNS(XML_a, XML_chExt,
XML_cx, OString::number(oox::drawingml::convertHmmToEmu(rRect.GetWidth())),
XML_cy, OString::number(oox::drawingml::convertHmmToEmu(rRect.GetHeight())));
@@ -1798,7 +1815,7 @@ void DrawingML::WriteShapeTransformation( const Reference< XShape >& rXShape, sa
if(bFlipH != bFlipV)
nRotation = nRotation * -1 + 36000;
- WriteTransformation(tools::Rectangle(Point(aPos.X, aPos.Y), Size(aSize.Width, aSize.Height)), nXmlNamespace,
+ WriteTransformation(rXShape, tools::Rectangle(Point(aPos.X, aPos.Y), Size(aSize.Width, aSize.Height)), nXmlNamespace,
bFlipHWrite, bFlipVWrite, ExportRotateClockwisify(nRotation + nCameraRotation), IsGroupShape( rXShape ));
}
@@ -4809,7 +4826,7 @@ void DrawingML::WriteDiagram(const css::uno::Reference<css::drawing::XShape>& rX
awt::Point aPos = xShapeBg->getPosition();
awt::Size aSize = xShapeBg->getSize();
WriteTransformation(
- tools::Rectangle(Point(aPos.X, aPos.Y), Size(aSize.Width, aSize.Height)),
+ xShapeBg, tools::Rectangle(Point(aPos.X, aPos.Y), Size(aSize.Width, aSize.Height)),
XML_p, false, false, 0, false);
}
diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx
index aae5ed633d85..b217358b6197 100644
--- a/oox/source/export/shapes.cxx
+++ b/oox/source/export/shapes.cxx
@@ -400,7 +400,9 @@ ShapeExport& ShapeExport::WritePolyPolygonShape( const Reference< XShape >& xSha
pFS->startElementNS(mnXmlNamespace, (GetDocumentType() != DOCUMENT_DOCX ? XML_sp : XML_wsp));
tools::PolyPolygon aPolyPolygon = EscherPropertyContainer::GetPolyPolygon( xShape );
- tools::Rectangle aRect( aPolyPolygon.GetBoundRect() );
+ awt::Point aPos = xShape->getPosition();
+ awt::Size aSize = xShape->getSize();
+ tools::Rectangle aRect(Point(aPos.X, aPos.Y), Size(aSize.Width, aSize.Height));
#if OSL_DEBUG_LEVEL > 0
awt::Size size = MapSize( awt::Size( aRect.GetWidth(), aRect.GetHeight() ) );
@@ -425,7 +427,7 @@ ShapeExport& ShapeExport::WritePolyPolygonShape( const Reference< XShape >& xSha
// visual shape properties
pFS->startElementNS(mnXmlNamespace, XML_spPr);
- WriteTransformation( aRect, XML_a );
+ WriteTransformation( xShape, aRect, XML_a );
WritePolyPolygon(xShape, aPolyPolygon, bClosed);
Reference< XPropertySet > xProps( xShape, UNO_QUERY );
if( xProps.is() ) {
@@ -1344,7 +1346,7 @@ ShapeExport& ShapeExport::WriteConnectorShape( const Reference< XShape >& xShape
// visual shape properties
pFS->startElementNS(mnXmlNamespace, XML_spPr);
- WriteTransformation( aRect, XML_a, bFlipH, bFlipV );
+ WriteTransformation( xShape, aRect, XML_a, bFlipH, bFlipV );
// TODO: write adjustments (ppt export doesn't work well there either)
WritePresetShape( sGeometry );
Reference< XPropertySet > xShapeProps( xShape, UNO_QUERY );