[Libreoffice-commits] .: Branch 'libreoffice-3-6' - writerfilter/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Wed Aug 29 13:23:36 PDT 2012


 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   51 ++++++++++++++++++++++---
 writerfilter/source/rtftok/rtfdocumentimpl.hxx |    3 +
 2 files changed, 48 insertions(+), 6 deletions(-)

New commits:
commit 8c32e8758a2244174a533e045ff9e8113581ee7d
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Tue Aug 28 11:21:50 2012 +0200

    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.
    
    (cherry picked from commit 1efa576ef88141c4deb5da9818537e053dc6517b)
    
    Change-Id: I22bc355994991beeadb41d26b44ce3e2beedbdb2
    Reviewed-on: https://gerrit.libreoffice.org/497
    Reviewed-by: Norbert Thiebaud <nthiebaud at gmail.com>
    Tested-by: Norbert Thiebaud <nthiebaud at gmail.com>

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index c814b91..fb18553 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -277,7 +277,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));
@@ -1077,6 +1078,7 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer)
 int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
 {
     checkUnicode();
+    checkDeferredContSectBreak();
     RTFSkipDestination aSkip(*this);
     switch (nKeyword)
     {
@@ -1406,6 +1408,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
 {
     if (nKeyword != RTF_HEXCHAR)
         checkUnicode();
+    checkDeferredContSectBreak();
     RTFSkipDestination aSkip(*this);
     sal_uInt8 cCh = 0;
 
@@ -1462,7 +1465,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:
             {
@@ -1583,10 +1596,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:
@@ -1609,6 +1633,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
 int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
 {
     checkUnicode();
+    checkDeferredContSectBreak();
     RTFSkipDestination aSkip(*this);
     int nParam = -1;
     int nSprm = -1;
@@ -2224,6 +2249,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));
@@ -2923,6 +2949,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));
@@ -3455,7 +3482,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();
 
@@ -3673,6 +3703,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 c43ca29..6d34e8b 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -420,6 +420,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;
@@ -511,6 +513,7 @@ namespace writerfilter {
                 rtl::OUStringBuffer m_aUnicodeBuffer;
                 /// Same for hex characters.
                 rtl::OStringBuffer m_aHexBuffer;
+                bool m_bDeferredContSectBreak;
         };
     } // namespace rtftok
 } // namespace writerfilter


More information about the Libreoffice-commits mailing list