summaryrefslogtreecommitdiff
path: root/sw/qa/extras/layout
diff options
context:
space:
mode:
authorAttila Bakos (NISZ) <bakos.attilakaroly@nisz.hu>2021-06-14 15:24:06 +0200
committerLászló Németh <nemeth@numbertext.org>2021-07-01 12:47:35 +0200
commit35732c84b05e4f6e50349796636beb01f2a09907 (patch)
treee5d6bca329748c626b74e6bfa7db4a0e8c1c2795 /sw/qa/extras/layout
parent5827376349b01447280ee4391b03a0f149f88ce4 (diff)
tdf#121509 DOCX export: fix corrupt shape anchoring in textbox
MSO doesn't support shapes anchored to character in a textbox. Convert these shapes by re-anchoring them to the anchor point of the textbox (also recalculating their positions in simple cases), so Word can now open the exported document. Change-Id: I28b244975981d69c50e5d4a46249918af089bae5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117163 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/qa/extras/layout')
-rw-r--r--sw/qa/extras/layout/data/Tdf121509.odtbin0 -> 9984 bytes
-rw-r--r--sw/qa/extras/layout/layout2.cxx58
2 files changed, 58 insertions, 0 deletions
diff --git a/sw/qa/extras/layout/data/Tdf121509.odt b/sw/qa/extras/layout/data/Tdf121509.odt
new file mode 100644
index 000000000000..856f60c88764
--- /dev/null
+++ b/sw/qa/extras/layout/data/Tdf121509.odt
Binary files differ
diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx
index 72cdc908b6ca..1db5f1e69214 100644
--- a/sw/qa/extras/layout/layout2.cxx
+++ b/sw/qa/extras/layout/layout2.cxx
@@ -49,6 +49,9 @@
#include <svx/svdpage.hxx>
#include <svx/svdotext.hxx>
#include <dcontact.hxx>
+#include <frameformats.hxx>
+#include <fmtcntnt.hxx>
+#include <unotextrange.hxx>
constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/extras/layout/data/";
@@ -1442,6 +1445,61 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf127118)
assertXPath(pXmlDoc, "/root/page[2]/body/tab/row[1]/cell[1]/txt[1]", "WritingMode", "VertBTLR");
}
+CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf121509)
+{
+ auto pDoc = createSwDoc(DATA_DIRECTORY, "Tdf121509.odt");
+ CPPUNIT_ASSERT(pDoc);
+
+ // Get all shape/frame formats
+ auto vFrameFormats = pDoc->GetSpzFrameFormats();
+ // Get the textbox
+ auto xTextFrame = SwTextBoxHelper::getUnoTextFrame(getShape(1));
+ // Get The triangle
+ auto pTriangleShapeFormat = vFrameFormats->GetFormat(2);
+ CPPUNIT_ASSERT(xTextFrame);
+ CPPUNIT_ASSERT(pTriangleShapeFormat);
+
+ // Get the position inside the textbox
+ auto xTextContentStart = xTextFrame->getText()->getStart();
+ SwUnoInternalPaM aCursor(*pDoc);
+ CPPUNIT_ASSERT(sw::XTextRangeToSwPaM(aCursor, xTextContentStart));
+
+ // Put the triangle into the textbox
+ SwFormatAnchor aNewAnch(pTriangleShapeFormat->GetAnchor());
+ aNewAnch.SetAnchor(aCursor.Start());
+ CPPUNIT_ASSERT(pTriangleShapeFormat->SetFormatAttr(aNewAnch));
+
+ // Reload (docx)
+ auto aTemp = utl::TempFile();
+ save("Office Open XML Text", aTemp);
+
+ // The second part: check if the reloaded doc has flys inside a fly
+ uno::Reference<lang::XComponent> xComponent
+ = loadFromDesktop(aTemp.GetURL(), "com.sun.star.text.TextDocument");
+ uno::Reference<text::XTextDocument> xTextDoc(xComponent, uno::UNO_QUERY);
+ auto pTextDoc = dynamic_cast<SwXTextDocument*>(xTextDoc.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ auto pSecondDoc = pTextDoc->GetDocShell()->GetDoc();
+ auto pSecondFormats = pSecondDoc->GetSpzFrameFormats();
+
+ bool bFlyInFlyFound = false;
+ for (auto secondformat : *pSecondFormats)
+ {
+ auto& pNd = secondformat->GetAnchor().GetContentAnchor()->nNode.GetNode();
+ if (pNd.FindFlyStartNode())
+ {
+ // So there is a fly inside another -> problem.
+ bFlyInFlyFound = true;
+ break;
+ }
+ }
+ // Drop the tempfile
+ aTemp.CloseStream();
+
+ // With the fix this cannot be true, if it is, that means Word unable to read the file..
+ CPPUNIT_ASSERT_MESSAGE("Corrupt exported docx file!", !bFlyInFlyFound);
+}
+
CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf134685)
{
createSwDoc(DATA_DIRECTORY, "tdf134685.docx");