summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorParis Oplopoios <paris.oplopoios@collabora.com>2023-07-12 16:56:25 +0300
committerParis Oplopoios <parisoplop@gmail.com>2023-07-19 14:19:28 +0200
commitb33e485b1dc9aec04a8899671abf5397face30cd (patch)
treed8095bd0a6821e59b740e5ee6da30681fb7b1b19
parent3bc3ba51d25ff1fd0fbdf1b09863cf90b20c8950 (diff)
Fix inline page breaks not imported correctly from .doc files
The way we handle page breaks is by creating new paragraphs. This visually looks fine until the imported file has stuff like first line indentation. Change-Id: I26d5bbc1ce8b0ff4492b099305f0ff22de41e4cf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/154358 Tested-by: Jenkins Reviewed-by: Paris Oplopoios <parisoplop@gmail.com>
-rw-r--r--sw/qa/extras/ww8export/data/inlinePageBreakFirstLine.docbin0 -> 26624 bytes
-rw-r--r--sw/qa/extras/ww8export/data/nonInlinePageBreakFirstLine.docbin0 -> 26624 bytes
-rw-r--r--sw/qa/extras/ww8export/ww8export4.cxx61
-rw-r--r--sw/source/filter/ww8/ww8par.cxx5
4 files changed, 65 insertions, 1 deletions
diff --git a/sw/qa/extras/ww8export/data/inlinePageBreakFirstLine.doc b/sw/qa/extras/ww8export/data/inlinePageBreakFirstLine.doc
new file mode 100644
index 000000000000..4f339511d664
--- /dev/null
+++ b/sw/qa/extras/ww8export/data/inlinePageBreakFirstLine.doc
Binary files differ
diff --git a/sw/qa/extras/ww8export/data/nonInlinePageBreakFirstLine.doc b/sw/qa/extras/ww8export/data/nonInlinePageBreakFirstLine.doc
new file mode 100644
index 000000000000..5351a9edecc7
--- /dev/null
+++ b/sw/qa/extras/ww8export/data/nonInlinePageBreakFirstLine.doc
Binary files differ
diff --git a/sw/qa/extras/ww8export/ww8export4.cxx b/sw/qa/extras/ww8export/ww8export4.cxx
index 7e3042aefab2..459daa69ec81 100644
--- a/sw/qa/extras/ww8export/ww8export4.cxx
+++ b/sw/qa/extras/ww8export/ww8export4.cxx
@@ -25,6 +25,8 @@
#include <IDocumentMarkAccess.hxx>
#include <IDocumentSettingAccess.hxx>
#include <unotxdoc.hxx>
+#include <ndtxt.hxx>
+#include <editeng/lrspitem.hxx>
class Test : public SwModelTestBase
{
@@ -142,6 +144,65 @@ CPPUNIT_TEST_FIXTURE(Test, testDontBreakWrappedTables)
CPPUNIT_ASSERT(bDontBreakWrappedTables);
}
+static bool IsFirstLine(const SwTextNode* pTextNode)
+{
+ const SfxPoolItem* pItem = pTextNode->GetNoCondAttr(RES_MARGIN_FIRSTLINE, false);
+ return !!pItem;
+}
+
+DECLARE_WW8EXPORT_TEST(testInlinePageBreakFirstLine, "inlinePageBreakFirstLine.doc")
+{
+ SwDoc* pDoc = getSwDoc();
+ const SwNodes& rNodes = pDoc->GetNodes();
+
+ std::vector<SwTextNode*> aTextNodes;
+
+ for (SwNodeOffset nNode(0); nNode < rNodes.Count(); ++nNode)
+ {
+ SwNode* pNode = pDoc->GetNodes()[nNode];
+ SwTextNode* pTextNode = pNode->GetTextNode();
+ if (!pTextNode)
+ continue;
+ aTextNodes.push_back(pTextNode);
+ }
+
+ CPPUNIT_ASSERT_EQUAL(size_t(3), aTextNodes.size());
+ CPPUNIT_ASSERT_EQUAL(OUString("First line"), aTextNodes[0]->GetText());
+ CPPUNIT_ASSERT(IsFirstLine(aTextNodes[0]));
+ // Here exists an inline pagebreak (a pagebreak without a paragraph before it)
+ // This text node is not indented because it is not the first line of the paragraph
+ CPPUNIT_ASSERT_EQUAL(OUString("Should not be indented"), aTextNodes[1]->GetText());
+ CPPUNIT_ASSERT(!IsFirstLine(aTextNodes[1]));
+ // Here is the actual second paragraph
+ CPPUNIT_ASSERT_EQUAL(OUString("Should be indented"), aTextNodes[2]->GetText());
+ CPPUNIT_ASSERT(IsFirstLine(aTextNodes[2]));
+}
+
+DECLARE_WW8EXPORT_TEST(testNonInlinePageBreakFirstLine, "nonInlinePageBreakFirstLine.doc")
+{
+ SwDoc* pDoc = getSwDoc();
+ const SwNodes& rNodes = pDoc->GetNodes();
+
+ std::vector<SwTextNode*> aTextNodes;
+
+ for (SwNodeOffset nNode(0); nNode < rNodes.Count(); ++nNode)
+ {
+ SwNode* pNode = pDoc->GetNodes()[nNode];
+ SwTextNode* pTextNode = pNode->GetTextNode();
+ if (!pTextNode)
+ continue;
+ aTextNodes.push_back(pTextNode);
+ }
+
+ CPPUNIT_ASSERT_EQUAL(size_t(2), aTextNodes.size());
+ CPPUNIT_ASSERT_EQUAL(OUString("First line"), aTextNodes[0]->GetText());
+ CPPUNIT_ASSERT(IsFirstLine(aTextNodes[0]));
+ // Here exists a pagebreak after a paragraph
+ // This text node is indented because it is the first line of a paragraph
+ CPPUNIT_ASSERT_EQUAL(OUString("Should be indented"), aTextNodes[1]->GetText());
+ CPPUNIT_ASSERT(IsFirstLine(aTextNodes[1]));
+}
+
DECLARE_WW8EXPORT_TEST(testTdf104704_mangledFooter, "tdf104704_mangledFooter.odt")
{
CPPUNIT_ASSERT_EQUAL(2, getPages());
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 04c00b90b78e..e2d6b35e7345 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -1418,7 +1418,10 @@ void SwWW8FltControlStack::SetAttrInDoc(const SwPosition& rTmpPos,
if (firstLineNew != firstLineOld)
{
- pNd->SetAttr(firstLineNew);
+ if (nStart == aRegion.Start()->GetNodeIndex())
+ {
+ pNd->SetAttr(firstLineNew);
+ }
}
if (leftMarginNew != leftMarginOld)
{