diff options
author | Miklos Vajna <vmiklos@suse.cz> | 2012-08-28 11:21:50 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2012-08-28 11:54:37 +0200 |
commit | 1efa576ef88141c4deb5da9818537e053dc6517b (patch) | |
tree | 1d2ff3dbbe1fa82b67d021acdfd9811782893e9a | |
parent | ea4b668d4aea664d4d7fb27ff0d3b001581ff779 (diff) |
fdo#52052 fix RTF import of page breaks on landscape pages
The problem was that we tried to insert a page break before reaching the
first section break, where section properties are sent.
Additionally, the continuous section break at the end of the doc caused
trouble, so ignore it explicitly.
Change-Id: I22bc355994991beeadb41d26b44ce3e2beedbdb2
-rw-r--r-- | sw/qa/extras/rtfimport/data/fdo52052.rtf | 23 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 9 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 51 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 3 |
4 files changed, 80 insertions, 6 deletions
diff --git a/sw/qa/extras/rtfimport/data/fdo52052.rtf b/sw/qa/extras/rtfimport/data/fdo52052.rtf new file mode 100644 index 000000000000..329762e2d147 --- /dev/null +++ b/sw/qa/extras/rtfimport/data/fdo52052.rtf @@ -0,0 +1,23 @@ +{\rtf1\ansi\ansicpg1251\deff0\deflang1033
+{\fonttbl
+{\f0\fswiss\fcharset204 Arial;}
+}
+{\colortbl;\red0\green0\blue0;}
+{\info
+{\title }
+{\author Crystal Reports}
+{\doccomm Powered By Crystal}
+{\company Crystal Decisions}
+}
+\landscape\paperw16836\paperh11904\margl567\margr397\margt567\margb284\gutter0\windowctrl\ftnbj\viewkind1\viewscale100\sectd\linex0\sbknone
+{\pard first
+\par }
+\page\sect
+{\pard \pvpg\phpg\posx13152\posy612\absw2984\absh-210\fi0 \ltrpar\qr\tx360\tx720\tx1080\tx1440\tx1800\tx2160\tx2520\tx2880
+{\ltrch\f0 \b\i0\ul0\strike0\fs15 \cf1 second}
+\par }
+\page\sect
+{\pard \pvpg\phpg\posx13152\posy612\absw2984\absh-210\fi0 \ltrpar\qr\tx360\tx720\tx1080\tx1440\tx1800\tx2160\tx2520\tx2880
+{\ltrch\f0 \b\i0\ul0\strike0\fs15 \cf1 third}
+\par }
+\sect }
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 219acbe3a3e1..918e7a54815a 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -106,6 +106,7 @@ public: void testFdo48446(); void testFdo47495(); void testAllGapsWord(); + void testFdo52052(); CPPUNIT_TEST_SUITE(Test); #if !defined(MACOSX) && !defined(WNT) @@ -153,6 +154,7 @@ public: CPPUNIT_TEST(testFdo48446); CPPUNIT_TEST(testFdo47495); CPPUNIT_TEST(testAllGapsWord); + CPPUNIT_TEST(testFdo52052); #endif CPPUNIT_TEST_SUITE_END(); @@ -915,6 +917,13 @@ void Test::testAllGapsWord() borderTest.testTheBorders(mxComponent); } +void Test::testFdo52052() +{ + load("fdo52052.rtf"); + // Make sure the textframe containing the text "third" appears on the 3rd page. + CPPUNIT_ASSERT_EQUAL(OUString("third"), parseDump("/root/page[3]/body/txt/anchored/fly/txt/text()")); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 812054003135..330c34d6ec6e 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -270,7 +270,8 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x m_bFormField(false), m_bIsInFrame(false), m_aUnicodeBuffer(), - m_aHexBuffer() + m_aHexBuffer(), + m_bDeferredContSectBreak(false) { OSL_ASSERT(xInputStream.is()); m_pInStream.reset(utl::UcbStreamHelper::CreateStream(xInputStream, sal_True)); @@ -1093,6 +1094,7 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer) int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) { checkUnicode(); + checkDeferredContSectBreak(); RTFSkipDestination aSkip(*this); switch (nKeyword) { @@ -1516,6 +1518,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) { if (nKeyword != RTF_HEXCHAR) checkUnicode(); + checkDeferredContSectBreak(); RTFSkipDestination aSkip(*this); sal_uInt8 cCh = 0; @@ -1572,7 +1575,17 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) } break; case RTF_SECT: - sectBreak(); + { + RTFValue::Pointer_t pBreak = m_aStates.top().aSectionSprms.find(NS_sprm::LN_SBkc); + if (pBreak.get() && !pBreak->getInt()) + { + // This is a continous section break, don't send it yet. + // It's possible that we'll have nothing after this token, and then we should ignore it. + m_bDeferredContSectBreak = true; + } + else + sectBreak(); + } break; case RTF_NOBREAK: { @@ -1693,10 +1706,21 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) break; case RTF_PAGE: { - sal_uInt8 sBreak[] = { 0xc }; - Mapper().text(sBreak, 1); - if (!m_bNeedPap) - parBreak(); + // If we're inside a continous section, we should send a section break, not a page one. + RTFValue::Pointer_t pBreak = m_aStates.top().aSectionSprms.find(NS_sprm::LN_SBkc); + if (pBreak.get() && !pBreak->getInt()) + { + dispatchFlag(RTF_SBKPAGE); + sectBreak(); + dispatchFlag(RTF_SBKNONE); + } + else + { + sal_uInt8 sBreak[] = { 0xc }; + Mapper().text(sBreak, 1); + if (!m_bNeedPap) + parBreak(); + } } break; case RTF_CHPGN: @@ -1719,6 +1743,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) { checkUnicode(); + checkDeferredContSectBreak(); RTFSkipDestination aSkip(*this); int nParam = -1; int nSprm = -1; @@ -2342,6 +2367,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) { checkUnicode(nKeyword != RTF_U, true); + checkDeferredContSectBreak(); RTFSkipDestination aSkip(*this); int nSprm = 0; RTFValue::Pointer_t pIntValue(new RTFValue(nParam)); @@ -3081,6 +3107,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) int RTFDocumentImpl::dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) { checkUnicode(); + checkDeferredContSectBreak(); RTFSkipDestination aSkip(*this); int nSprm = -1; RTFValue::Pointer_t pBoolValue(new RTFValue(!bParam || nParam != 0)); @@ -3730,7 +3757,10 @@ int RTFDocumentImpl::popState() // This is the end of the doc, see if we need to close the last section. if (m_nGroup == 1 && !m_bFirstRun) + { + m_bDeferredContSectBreak = false; sectBreak(true); + } m_aStates.pop(); @@ -3947,6 +3977,15 @@ void RTFDocumentImpl::checkUnicode(bool bUnicode, bool bHex) } } +void RTFDocumentImpl::checkDeferredContSectBreak() +{ + if (m_bDeferredContSectBreak) + { + m_bDeferredContSectBreak = false; + sectBreak(); + } +} + RTFParserState::RTFParserState(RTFDocumentImpl *pDocumentImpl) : m_pDocumentImpl(pDocumentImpl), nInternalState(INTERNAL_NORMAL), diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 0759a4c30b90..e3120b7aacdf 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -479,6 +479,8 @@ namespace writerfilter { void replayBuffer(RTFBuffer_t& rBuffer); /// If we have some unicode or hex characters to send. void checkUnicode(bool bUnicode = true, bool bHex = true); + /// If we have a pending continous section break. + void checkDeferredContSectBreak(); uno::Reference<uno::XComponentContext> const& m_xContext; uno::Reference<io::XInputStream> const& m_xInputStream; @@ -573,6 +575,7 @@ namespace writerfilter { rtl::OStringBuffer m_aHexBuffer; /// Formula import. oox::formulaimport::XmlStreamBuilder m_aMathBuffer; + bool m_bDeferredContSectBreak; }; } // namespace rtftok } // namespace writerfilter |