summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2014-02-27 23:48:59 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-03-03 10:31:30 -0600
commit153993292cc9f11fed8fcba8de45b0c46d5e0ef2 (patch)
tree772310769244edceee186f784b51230598278472 /sw
parentcb83b334e489a4ec1cc067145c3f64b129475e7f (diff)
RTF import: fix spurious page breaks at doc end (related: rhbz#1065629)cp-4.2-branch-point
When a document ends with \sect it's possible that a spurious page break is created. In fact the spurious page break is always created by the RTF importer, sometimes it is deleted again by DomainMapper_Impl::RemoveLastParagraph() and sometimes not. It is created because on the final \sect RTFDocumentImpl::sectBreak() still calls startSectionGroup(), and the popState() for the \rtf1 group then calls sectBreak() another time. To prevent this, do not call startSectionGroup() from sectBreak() but instead from setNeedSect(), and ensure that it is called as soon as anything after \sect is read. One unit test fails because the \page is not handled properly: the conversion to \skbpage \sect \skbnone is not correct, because the \skb* keywords are an exception and affect the \sect that precedes them, not the following one; sending the \skbpage later unfortunately requires additional cleanup later. (cherry picked from commit e3f254ab8211fbab7541cde2100a35c875b0c240) RTF import: add unit test for page break in continuous section (cherry picked from commit f03218f43e8c25c2e136d364455f3cdaf95362b6) RTF import: fix paragraphs in header/footer (cherry picked from commit 74b3f4f00766d199df3b017d056cf7a00ae52988) Change-Id: I3c1a3bceb2c8b75bbecdc748170562451ce5f5c3 Reviewed-on: https://gerrit.libreoffice.org/8439 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'sw')
-rw-r--r--sw/qa/extras/rtfimport/data/cont-section-pagebreak.rtf16
-rw-r--r--sw/qa/extras/rtfimport/data/footer-para.rtf5
-rw-r--r--sw/qa/extras/rtfimport/rtfimport.cxx42
3 files changed, 63 insertions, 0 deletions
diff --git a/sw/qa/extras/rtfimport/data/cont-section-pagebreak.rtf b/sw/qa/extras/rtfimport/data/cont-section-pagebreak.rtf
new file mode 100644
index 000000000000..888dc2d0293e
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/cont-section-pagebreak.rtf
@@ -0,0 +1,16 @@
+{\rtf1 \ansi
+\fet0 \ftnbj \paperw11905 \paperh16837 \margt2267 \margb1133 \margl1417 \margr1417
+
+\sectd
+\sbknone
+FIRST
+\par
+\sect
+SECOND
+\par
+\page
+\sect
+THIRD
+\par
+\sect
+}
diff --git a/sw/qa/extras/rtfimport/data/footer-para.rtf b/sw/qa/extras/rtfimport/data/footer-para.rtf
new file mode 100644
index 000000000000..28863b202f17
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/footer-para.rtf
@@ -0,0 +1,5 @@
+{\rtf1\fbidis\ansi\ansicpg0\uc0\deff0\deflang0\deflangfe0\paperw11905\paperh16838\margl1200\margr1200\margt1200\margb1200\headery600\footery600\viewscale100\viewzk0\titlepg
+{\fonttbl{\f0\fnil Arial;}}
+{\footerf
+\pard\s0\fi0\li0\qc\ri0\sb0\sa0\itap0 \plain \f0\fs18 All Rights Reserved.\par}
+\pard\par}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index 950402790cd4..73bf74921801 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -17,6 +17,7 @@
#include <com/sun/star/drawing/LineStyle.hpp>
#include <com/sun/star/graphic/GraphicType.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/style/BreakType.hpp>
#include <com/sun/star/style/CaseMap.hpp>
#include <com/sun/star/style/LineSpacing.hpp>
#include <com/sun/star/style/LineSpacingMode.hpp>
@@ -1413,6 +1414,47 @@ DECLARE_RTFIMPORT_TEST(testNestedTable, "rhbz1065629.rtf")
getProperty<table::BorderLine2>(xCell, "RightBorder"));
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0xffffffff),
getProperty<sal_Int32>(xCell, "BackColor"));
+
+ // \sect at the end resulted in spurious page break
+ CPPUNIT_ASSERT_EQUAL(1, getPages());
+}
+
+DECLARE_RTFIMPORT_TEST(testContSectionPageBreak, "cont-section-pagebreak.rtf")
+{
+ uno::Reference<text::XTextRange> xParaSecond = getParagraph(2);
+ CPPUNIT_ASSERT_EQUAL(OUString("SECOND"), xParaSecond->getString());
+ CPPUNIT_ASSERT_EQUAL(style::BreakType_NONE,
+ getProperty<style::BreakType>(xParaSecond, "BreakType"));
+ CPPUNIT_ASSERT_EQUAL(OUString(""),
+ getProperty<OUString>(xParaSecond, "PageDescName"));
+ // actually not sure how many paragraph there should be between
+ // SECOND and THIRD - important is that the page break is on there
+ uno::Reference<text::XTextRange> xParaNext = getParagraph(3);
+ CPPUNIT_ASSERT_EQUAL(OUString(""), xParaNext->getString());
+ CPPUNIT_ASSERT_EQUAL(OUString("Converted1"),
+ getProperty<OUString>(xParaNext, "PageDescName"));
+ uno::Reference<text::XTextRange> xParaThird = getParagraph(4);
+ CPPUNIT_ASSERT_EQUAL(OUString("THIRD"), xParaThird->getString());
+ CPPUNIT_ASSERT_EQUAL(style::BreakType_NONE,
+ getProperty<style::BreakType>(xParaThird, "BreakType"));
+ CPPUNIT_ASSERT_EQUAL(OUString(""),
+ getProperty<OUString>(xParaThird, "PageDescName"));
+
+ CPPUNIT_ASSERT_EQUAL(2, getPages());
+}
+
+DECLARE_RTFIMPORT_TEST(testFooterPara, "footer-para.rtf")
+{
+ // check that paragraph properties in footer are imported
+ uno::Reference<text::XText> xFooterText =
+ getProperty< uno::Reference<text::XText> >(
+ getStyles("PageStyles")->getByName("First Page"), "FooterText");
+ uno::Reference<text::XTextContent> xParagraph =
+ getParagraphOrTable(1, xFooterText);
+ CPPUNIT_ASSERT_EQUAL(OUString("All Rights Reserved."),
+ uno::Reference<text::XTextRange>(xParagraph, uno::UNO_QUERY)->getString());
+ CPPUNIT_ASSERT_EQUAL((sal_Int16)style::ParagraphAdjust_CENTER,
+ getProperty</*style::ParagraphAdjust*/sal_Int16>(xParagraph, "ParaAdjust"));
}
DECLARE_RTFIMPORT_TEST(testCp1000016, "hello.rtf")