diff options
author | Attila Bakos (NISZ) <bakos.attilakaroly@nisz.hu> | 2020-09-30 11:24:14 +0200 |
---|---|---|
committer | László Németh <nemeth@numbertext.org> | 2020-10-14 08:56:02 +0200 |
commit | 726c911b90b9a3170fa6b3a34bb952a8d2dbe148 (patch) | |
tree | 91543b2ec8d32767485cfe15e0aac2d8895e1abd | |
parent | 16e88bd68c523117fee9070c986151a781c0e7bf (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>
-rw-r--r-- | sw/inc/textboxhelper.hxx | 6 | ||||
-rwxr-xr-x | sw/qa/extras/layout/data/tdf137025.docx | bin | 0 -> 14726 bytes | |||
-rw-r--r-- | sw/qa/extras/layout/layout.cxx | 67 | ||||
-rw-r--r-- | sw/source/core/doc/textboxhelper.cxx | 34 | ||||
-rw-r--r-- | sw/source/uibase/shells/drawdlg.cxx | 8 |
5 files changed, 115 insertions, 0 deletions
diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx index 5d58305406c2..1c4a723cc07b 100644 --- a/sw/inc/textboxhelper.hxx +++ b/sw/inc/textboxhelper.hxx @@ -69,6 +69,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. * @@ -95,6 +98,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& rDoc); /// 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 Binary files differnew file mode 100755 index 000000000000..89f33a911ebe --- /dev/null +++ b/sw/qa/extras/layout/data/tdf137025.docx diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx index 98ee25b5a134..428878d8e85b 100644 --- a/sw/qa/extras/layout/layout.cxx +++ b/sw/qa/extras/layout/layout.cxx @@ -42,6 +42,8 @@ #include <rootfrm.hxx> #include <docsh.hxx> #include <IDocumentLayoutAccess.hxx> +#include <textboxhelper.hxx> +#include <unoframe.hxx> char const DATA_DIRECTORY[] = "/sw/qa/extras/layout/data/"; @@ -813,6 +815,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 15d80ea1ca93..94f43c61af02 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -210,6 +210,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; @@ -809,4 +820,27 @@ void SwTextBoxHelper::syncFlyFrameAttr(SwFrameFormat& rShape, SfxItemSet const& pFormat->GetDoc()->SetFlyFrameAttr(*pFormat, aTextBoxSet); } +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 b08cde80068d..114b7f33b055 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(); } |