summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorAttila Bakos (NISZ) <bakos.attilakaroly@nisz.hu>2022-01-24 10:57:34 +0100
committerLászló Németh <nemeth@numbertext.org>2022-02-03 09:28:52 +0100
commit65b09ef1c5e24651579eb11900cf2ddbbb7b0971 (patch)
treec738c6d5d485038bd9f6478c534e530a88893ece /oox
parent4a38ca4035ac03571925e72cb47e0beb8da2003a (diff)
tdf#146803 tdf#146805 OOXML import: fix bodyPr at grouped shapes
Grouped text boxes (WPG) lost their alignment and spacing, because the bodyPr tag what has the information for this, processed after the textbox content, and applied to the XShape which in case of group shape is not ready. To solve this, the mentioned properties read for the shape member after copied to the XShape when its ready, and than synced to the textbox. Regression from commit 121cbc250b36290f0f8c7265fea57256dad69553 "tdf#66039 DOCX: import textboxes (with tables, images etc.) in group shapes". Change-Id: Ifb5e8bde58613137441bec2e2b51bc67118dab40 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128854 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/drawingml/shape.cxx42
-rw-r--r--oox/source/shape/WpgContext.hxx2
-rw-r--r--oox/source/shape/WpsContext.cxx43
-rw-r--r--oox/source/shape/WpsContext.hxx1
4 files changed, 87 insertions, 1 deletions
diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx
index f7161e01291f..b13000035add 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -134,6 +134,7 @@ Shape::Shape( const char* pServiceName, bool bDefaultHeight )
, mbHidden( false )
, mbHiddenMasterShape( false )
, mbLocked( false )
+, mbWPGChild(false)
, mbLockedCanvas( false )
, mbWps( false )
, mbTextBox( false )
@@ -176,6 +177,7 @@ Shape::Shape( const ShapePtr& pSourceShape )
, mbHidden( pSourceShape->mbHidden )
, mbHiddenMasterShape( pSourceShape->mbHiddenMasterShape )
, mbLocked( pSourceShape->mbLocked )
+, mbWPGChild( pSourceShape->mbWPGChild )
, mbLockedCanvas( pSourceShape->mbLockedCanvas )
, mbWps( pSourceShape->mbWps )
, mbTextBox( pSourceShape->mbTextBox )
@@ -292,6 +294,41 @@ void Shape::addShape(
if ( xShapes.is() )
addChildren( rFilterBase, *this, pTheme, xShapes, pShapeMap, aMatrix );
+ if (isWPGChild() && xShape)
+ {
+ // This is a wps shape and it is the child of the WPG, now copy the
+ // the text body properties to the xshape.
+ Reference<XPropertySet> xChildWPSProperties(xShape, uno::UNO_QUERY);
+
+ if (getTextBody() && xChildWPSProperties)
+ {
+ xChildWPSProperties->setPropertyValue(
+ UNO_NAME_TEXT_VERTADJUST,
+ uno::Any(getTextBody()->getTextProperties().meVA));
+
+ xChildWPSProperties->setPropertyValue(
+ UNO_NAME_TEXT_LEFTDIST,
+ uno::Any(getTextBody()->getTextProperties().moInsets[0].has_value()
+ ? *getTextBody()->getTextProperties().moInsets[0]
+ : 0));
+ xChildWPSProperties->setPropertyValue(
+ UNO_NAME_TEXT_UPPERDIST,
+ uno::Any(getTextBody()->getTextProperties().moInsets[1].has_value()
+ ? *getTextBody()->getTextProperties().moInsets[1]
+ : 0));
+ xChildWPSProperties->setPropertyValue(
+ UNO_NAME_TEXT_RIGHTDIST,
+ uno::Any(getTextBody()->getTextProperties().moInsets[2].has_value()
+ ? *getTextBody()->getTextProperties().moInsets[2]
+ : 0));
+ xChildWPSProperties->setPropertyValue(
+ UNO_NAME_TEXT_LOWERDIST,
+ uno::Any(getTextBody()->getTextProperties().moInsets[3].has_value()
+ ? *getTextBody()->getTextProperties().moInsets[3]
+ : 0));
+ }
+ }
+
if( meFrameType == FRAMETYPE_DIAGRAM )
{
keepDiagramCompatibilityInfo();
@@ -332,6 +369,11 @@ void Shape::setLockedCanvas(bool bLockedCanvas)
mbLockedCanvas = bLockedCanvas;
}
+void Shape::setWPGChild(bool bWPG)
+{
+ mbWPGChild = bWPG;
+}
+
void Shape::setWps(bool bWps)
{
mbWps = bWps;
diff --git a/oox/source/shape/WpgContext.hxx b/oox/source/shape/WpgContext.hxx
index 6da13d9663be..414e5f819bfe 100644
--- a/oox/source/shape/WpgContext.hxx
+++ b/oox/source/shape/WpgContext.hxx
@@ -28,7 +28,7 @@ public:
const oox::drawingml::ShapePtr& getShape() const { return mpShape; }
- const bool& isFullWPGSupport() { return m_bFullWPGSupport; };
+ const bool& isFullWPGSupport() const { return m_bFullWPGSupport; };
void setFullWPGSupport(const bool& rbUse) { m_bFullWPGSupport = rbUse; };
private:
diff --git a/oox/source/shape/WpsContext.cxx b/oox/source/shape/WpsContext.cxx
index 5eaff0abe6e0..d39f93fc8402 100644
--- a/oox/source/shape/WpsContext.cxx
+++ b/oox/source/shape/WpsContext.cxx
@@ -8,6 +8,7 @@
*/
#include "WpsContext.hxx"
+#include "WpgContext.hxx"
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/tuple/b2dtuple.hxx>
#include <comphelper/sequenceashashmap.hxx>
@@ -24,6 +25,9 @@
#include <oox/token/namespaces.hxx>
#include <oox/token/tokens.hxx>
#include <oox/drawingml/shape.hxx>
+#include <oox/drawingml/drawingmltypes.hxx>
+#include <drawingml/textbody.hxx>
+#include <drawingml/textbodyproperties.hxx>
#include <optional>
@@ -39,6 +43,11 @@ WpsContext::WpsContext(ContextHandler2Helper const& rParent, uno::Reference<draw
{
if (mpShapePtr)
mpShapePtr->setWps(true);
+
+ if (const auto pParent = dynamic_cast<const WpgContext*>(&rParent))
+ m_bHasWPGParent = pParent->isFullWPGSupport();
+ else
+ m_bHasWPGParent = false;
}
WpsContext::~WpsContext() = default;
@@ -169,6 +178,40 @@ oox::core::ContextHandlerRef WpsContext::onCreateContext(sal_Int32 nElementToken
return this;
}
+ else if (m_bHasWPGParent && mpShapePtr)
+ {
+ // this WPS context has to be inside a WPG shape, so the <BodyPr> element
+ // cannot be applied to mxShape member, use mpShape instead, and after the
+ // the parent shape finished, apply it for its children.
+ mpShapePtr->setWPGChild(true);
+ oox::drawingml::TextBodyPtr pTextBody;
+ pTextBody.reset(new oox::drawingml::TextBody());
+
+ if (rAttribs.hasAttribute(XML_anchor))
+ {
+ drawing::TextVerticalAdjust eAdjust
+ = drawingml::GetTextVerticalAdjust(rAttribs.getToken(XML_anchor, XML_t));
+ pTextBody->getTextProperties().meVA = eAdjust;
+ }
+
+ sal_Int32 aInsets[] = { XML_lIns, XML_tIns, XML_rIns, XML_bIns };
+ for (int i = 0; i < 4; ++i)
+ {
+ if (rAttribs.hasAttribute(XML_lIns))
+ {
+ OptValue<OUString> oValue = rAttribs.getString(aInsets[i]);
+ if (oValue.has())
+ pTextBody->getTextProperties().moInsets[i]
+ = oox::drawingml::GetCoordinate(oValue.get());
+ else
+ // Defaults from the spec: left/right: 91440 EMU, top/bottom: 45720 EMU
+ pTextBody->getTextProperties().moInsets[i]
+ = (aInsets[i] == XML_lIns || aInsets[i] == XML_rIns) ? 254 : 127;
+ }
+ }
+
+ mpShapePtr->setTextBody(pTextBody);
+ }
break;
case XML_noAutofit:
case XML_spAutoFit:
diff --git a/oox/source/shape/WpsContext.hxx b/oox/source/shape/WpsContext.hxx
index 1cb6106324da..29110b6fbf8e 100644
--- a/oox/source/shape/WpsContext.hxx
+++ b/oox/source/shape/WpsContext.hxx
@@ -36,6 +36,7 @@ public:
private:
css::uno::Reference<css::drawing::XShape> mxShape;
+ bool m_bHasWPGParent;
};
}