summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Bakos (NISZ) <bakos.attilakaroly@nisz.hu>2020-09-30 11:24:14 +0200
committerGabor Kelemen <kelemen.gabor2@nisz.hu>2021-04-20 17:17:22 +0200
commitf97331f691588aa42c004fe19d7874092ab45e4f (patch)
tree6318b6b82530bef2bf85e3c7a02da323ed7da68a
parent986aca62157c828687ad6401a332ead233cbbf14 (diff)
tdf#137025 sw: apply textbox padding set in Text
dialog window using Spacing to Borders in Format->Text Box and Shape->Text attributes... on the selected text box. There are two types of text boxes in sw, the older editeng one, what worked fine, and the newer one, the shape + text frame one, where modifying Spacing to Borders had no effect. This has been fixed by copying the modified shape attributes to the associated text frame. Change-Id: I8da0b414fd4771fa86851d9a6affbd9502894ebf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103674 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org> (cherry picked from commit 726c911b90b9a3170fa6b3a34bb952a8d2dbe148) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114352 Tested-by: Gabor Kelemen <kelemen.gabor2@nisz.hu> Reviewed-by: Gabor Kelemen <kelemen.gabor2@nisz.hu>
-rw-r--r--sw/inc/textboxhelper.hxx6
-rwxr-xr-xsw/qa/extras/layout/data/tdf137025.docxbin0 -> 14726 bytes
-rw-r--r--sw/qa/extras/layout/layout.cxx69
-rw-r--r--sw/source/core/doc/textboxhelper.cxx34
-rw-r--r--sw/source/uibase/shells/drawdlg.cxx8
5 files changed, 117 insertions, 0 deletions
diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx
index e6c991d8acfa..58f5deba8485 100644
--- a/sw/inc/textboxhelper.hxx
+++ b/sw/inc/textboxhelper.hxx
@@ -79,6 +79,9 @@ public:
/// Similar to syncProperty(), but used by the internal API (e.g. for UI purposes).
static void syncFlyFrameAttr(SwFrameFormat& rShape, SfxItemSet const& rSet);
+ /// Copy shape attributes to the text frame
+ static void updateTextBoxMargin(SdrObject* pObj);
+
/**
* If we have an associated TextFrame, then return that.
*
@@ -105,6 +108,9 @@ public:
*/
static bool isTextBox(const SwFrameFormat* pFormat, sal_uInt16 nType);
+ /// Returns true if the SdrObject has a SwTextFrame otherwise false
+ static bool hasTextFrame(const SdrObject* pObj);
+
/// Count number of shapes in the document, excluding TextBoxes.
static sal_Int32 getCount(const SwDoc* pDoc);
/// Count number of shapes on the page, excluding TextBoxes.
diff --git a/sw/qa/extras/layout/data/tdf137025.docx b/sw/qa/extras/layout/data/tdf137025.docx
new file mode 100755
index 000000000000..89f33a911ebe
--- /dev/null
+++ b/sw/qa/extras/layout/data/tdf137025.docx
Binary files differ
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index 02c754b8404c..b45474ac4245 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -44,6 +44,10 @@
#include <svx/svdpage.hxx>
#include <svx/svdotext.hxx>
#include <dcontact.hxx>
+#include <unotxdoc.hxx>
+#include <rootfrm.hxx>
+#include <docsh.hxx>
+#include <IDocumentLayoutAccess.hxx>
#include <config_features.h>
@@ -796,6 +800,71 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testRedlineFlysInHeader)
}
}
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter, TestTdf137025)
+{
+ // Check the padding of the textbox
+ SwDoc* pDoc = createDoc("tdf137025.docx");
+ CPPUNIT_ASSERT(pDoc);
+ xmlDocUniquePtr pXmlDoc = parseLayoutDump();
+ CPPUNIT_ASSERT(pXmlDoc);
+
+ // Check the layout xml
+ assertXPath(pXmlDoc,
+ "/root/page/body/txt/anchored/SwAnchoredDrawObject/SdrObject"
+ "/DefaultProperties/SfxItemSet/SfxInt32Item[3]",
+ "value", "567");
+ assertXPath(pXmlDoc,
+ "/root/page/body/txt/anchored/SwAnchoredDrawObject/SdrObject"
+ "/DefaultProperties/SfxItemSet/SfxInt32Item[4]",
+ "value", "1134");
+ assertXPath(pXmlDoc,
+ "/root/page/body/txt/anchored/SwAnchoredDrawObject/SdrObject"
+ "/DefaultProperties/SfxItemSet/SfxInt32Item[5]",
+ "value", "1701");
+ assertXPath(pXmlDoc,
+ "/root/page/body/txt/anchored/SwAnchoredDrawObject/SdrObject"
+ "/DefaultProperties/SfxItemSet/SfxInt32Item[6]",
+ "value", "2268");
+
+ // Check the textbox-shape import too
+ auto xShp = getShape(1);
+ CPPUNIT_ASSERT(xShp);
+
+ uno::Reference<beans::XPropertySet> xShapeProps(xShp, uno::UNO_QUERY);
+
+ SwFrameFormat* pFrameFormat = SwTextBoxHelper::getOtherTextBoxFormat(xShp);
+ CPPUNIT_ASSERT(pFrameFormat);
+
+ // The shape has these values to copy to the associated text frame after modification::
+ const long nLPaddng = xShapeProps->getPropertyValue("TextLeftDistance").get<long>();
+ const long nRPaddng = xShapeProps->getPropertyValue("TextRightDistance").get<long>();
+ const long nTPaddng = xShapeProps->getPropertyValue("TextUpperDistance").get<long>();
+ const long nBPaddng = xShapeProps->getPropertyValue("TextLowerDistance").get<long>();
+
+ CPPUNIT_ASSERT_EQUAL(long(1000), nLPaddng);
+ CPPUNIT_ASSERT_EQUAL(long(2000), nRPaddng);
+ CPPUNIT_ASSERT_EQUAL(long(3000), nTPaddng);
+ CPPUNIT_ASSERT_EQUAL(long(4001), nBPaddng);
+
+ // TODO: modify shape distance via UNO with text frame synchronization
+ // Check the textbox as well:
+ auto xTxFrm = SwXTextFrame::CreateXTextFrame(*pFrameFormat->GetDoc(), pFrameFormat);
+ CPPUNIT_ASSERT(xTxFrm);
+ uno::Reference<beans::XPropertySet> xFrameProps(xTxFrm, uno::UNO_QUERY);
+
+ const long nFrameLeftPaddng = xFrameProps->getPropertyValue("LeftBorderDistance").get<long>();
+ const long nFrameRightPaddng = xFrameProps->getPropertyValue("RightBorderDistance").get<long>();
+ const long nFrameTopPaddng = xFrameProps->getPropertyValue("TopBorderDistance").get<long>();
+ const long nFrameBottomPaddng
+ = xFrameProps->getPropertyValue("BottomBorderDistance").get<long>();
+
+ // Check if the shape and frame have different setting
+ CPPUNIT_ASSERT_EQUAL(nLPaddng, nFrameLeftPaddng);
+ CPPUNIT_ASSERT_EQUAL(nRPaddng, nFrameRightPaddng);
+ CPPUNIT_ASSERT_EQUAL(nTPaddng, nFrameTopPaddng);
+ CPPUNIT_ASSERT_EQUAL(nBPaddng, nFrameBottomPaddng);
+}
+
CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testRedlineFlysInFootnote)
{
loadURL("private:factory/swriter", nullptr);
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index c900255a1a7e..98debf9b59d4 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -244,6 +244,17 @@ bool SwTextBoxHelper::isTextBox(const SwFrameFormat* pFormat, sal_uInt16 nType)
return pOtherFormat->GetAttrSet().HasItem(RES_CNTNT) && pOtherFormat->GetContent() == rContent;
}
+bool SwTextBoxHelper::hasTextFrame(const SdrObject* pObj)
+{
+ if (!pObj)
+ return false;
+
+ uno::Reference<drawing::XShape> xShape(pObj->getWeakUnoShape(), uno::UNO_QUERY);
+ if (!xShape)
+ return false;
+ return SwTextBoxHelper::getOtherTextBoxFormat(xShape);
+}
+
sal_Int32 SwTextBoxHelper::getCount(SdrPage const* pPage)
{
sal_Int32 nRet = 0;
@@ -841,4 +852,27 @@ void SwTextBoxHelper::syncFlyFrameAttr(SwFrameFormat& rShape, SfxItemSet const&
}
}
+void SwTextBoxHelper::updateTextBoxMargin(SdrObject* pObj)
+{
+ if (!pObj)
+ return;
+ uno::Reference<drawing::XShape> xShape(pObj->getUnoShape(), uno::UNO_QUERY);
+ if (!xShape)
+ return;
+ uno::Reference<beans::XPropertySet> const xPropertySet(xShape, uno::UNO_QUERY);
+
+ auto pParentFormat = getOtherTextBoxFormat(getOtherTextBoxFormat(xShape), RES_FLYFRMFMT);
+ if (!pParentFormat)
+ return;
+
+ syncProperty(pParentFormat, UNO_NAME_TEXT_LEFTDIST,
+ xPropertySet->getPropertyValue(UNO_NAME_TEXT_LEFTDIST));
+ syncProperty(pParentFormat, UNO_NAME_TEXT_RIGHTDIST,
+ xPropertySet->getPropertyValue(UNO_NAME_TEXT_RIGHTDIST));
+ syncProperty(pParentFormat, UNO_NAME_TEXT_UPPERDIST,
+ xPropertySet->getPropertyValue(UNO_NAME_TEXT_UPPERDIST));
+ syncProperty(pParentFormat, UNO_NAME_TEXT_LOWERDIST,
+ xPropertySet->getPropertyValue(UNO_NAME_TEXT_LOWERDIST));
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/shells/drawdlg.cxx b/sw/source/uibase/shells/drawdlg.cxx
index 36d231bc4dde..e71391b46789 100644
--- a/sw/source/uibase/shells/drawdlg.cxx
+++ b/sw/source/uibase/shells/drawdlg.cxx
@@ -39,6 +39,7 @@
#include <svx/xflftrit.hxx>
#include <svx/xfltrit.hxx>
#include <comphelper/lok.hxx>
+#include <textboxhelper.hxx>
using namespace com::sun::star::drawing;
@@ -69,6 +70,13 @@ void SwDrawShell::ExecDrawDlg(SfxRequest& rReq)
{
pSh->StartAction();
pView->SetAttributes(*pDlg->GetOutputItemSet());
+ auto vMarkedObjs = pView->GetMarkedObjects();
+ for (auto pObj : vMarkedObjs)
+ {
+ // If the shape has textframe, set its params as well.
+ if (SwTextBoxHelper::hasTextFrame(pObj))
+ SwTextBoxHelper::updateTextBoxMargin(pObj);
+ }
rReq.Done(*(pDlg->GetOutputItemSet()));
pSh->EndAction();
}