diff options
Diffstat (limited to 'writerfilter/source/rtftok/rtfdocumentimpl.cxx')
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index cb54d38208ab..3ebb8da59f0c 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -278,7 +278,9 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x m_bIsInFrame(false), m_aUnicodeBuffer(), m_aHexBuffer(), - m_bDeferredContSectBreak(false) + m_bIgnoreNextContSectBreak(false), + m_bNeedSect(true), + m_bWasInFrame(false) { OSL_ASSERT(xInputStream.is()); m_pInStream.reset(utl::UcbStreamHelper::CreateStream(xInputStream, sal_True)); @@ -395,6 +397,11 @@ void RTFDocumentImpl::setNeedPar(bool bNeedPar) m_bNeedPar = bNeedPar; } +void RTFDocumentImpl::setNeedSect(bool bNeedSect) +{ + m_bNeedSect = bNeedSect; +} + void RTFDocumentImpl::checkNeedPap() { if (m_bNeedPap) @@ -479,6 +486,8 @@ void RTFDocumentImpl::parBreak() void RTFDocumentImpl::sectBreak(bool bFinal = false) { + SAL_INFO("writerfilter", OSL_THIS_FUNC << ": final? " << bFinal << ", needed? " << m_bNeedSect); + bool bNeedSect = m_bNeedSect; // If there is no paragraph in this section, then insert a dummy one, as required by Writer if (m_bNeedPar) dispatchSymbol(RTF_PAR); @@ -495,10 +504,15 @@ void RTFDocumentImpl::sectBreak(bool bFinal = false) resolveSubstream(aPair.second, aPair.first); } - RTFValue::Pointer_t pBreak = m_aStates.top().aSectionSprms.find(NS_sprm::LN_SBkc); - // In case the last section is a continous one, we don't need to output a section break. - if (bFinal && pBreak.get() && !pBreak->getInt()) - m_aStates.top().aSectionSprms.erase(NS_sprm::LN_SBkc); + // Normally a section break at the end of the doc is necessary. Unless the + // last control word in the document is a section break itself. + if (!bNeedSect) + { + RTFValue::Pointer_t pBreak = m_aStates.top().aSectionSprms.find(NS_sprm::LN_SBkc); + // In case the last section is a continous one, we don't need to output a section break. + if (bFinal && pBreak.get() && !pBreak->getInt()) + m_aStates.top().aSectionSprms.erase(NS_sprm::LN_SBkc); + } // Section properties are a paragraph sprm. RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aSectionAttributes, m_aStates.top().aSectionSprms)); @@ -519,6 +533,7 @@ void RTFDocumentImpl::sectBreak(bool bFinal = false) Mapper().startParagraphGroup(); } m_bNeedPar = true; + m_bNeedSect = false; } void RTFDocumentImpl::seek(sal_uInt32 nPos) @@ -1092,7 +1107,7 @@ void RTFDocumentImpl::replayBuffer(RTFBuffer_t& rBuffer) int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) { checkUnicode(); - checkDeferredContSectBreak(); + setNeedSect(); RTFSkipDestination aSkip(*this); switch (nKeyword) { @@ -1422,7 +1437,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) { if (nKeyword != RTF_HEXCHAR) checkUnicode(); - checkDeferredContSectBreak(); + setNeedSect(); RTFSkipDestination aSkip(*this); sal_uInt8 cCh = 0; @@ -1480,13 +1495,8 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) break; case RTF_SECT: { - 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; - } + if (m_bIgnoreNextContSectBreak) + m_bIgnoreNextContSectBreak = false; else sectBreak(); } @@ -1630,9 +1640,17 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) RTFValue::Pointer_t pBreak = m_aStates.top().aSectionSprms.find(NS_sprm::LN_SBkc); if (pBreak.get() && !pBreak->getInt()) { + if (m_bWasInFrame) + { + dispatchSymbol(RTF_PAR); + m_bWasInFrame = false; + } dispatchFlag(RTF_SBKPAGE); sectBreak(); dispatchFlag(RTF_SBKNONE); + if (m_bNeedPar) + dispatchSymbol(RTF_PAR); + m_bIgnoreNextContSectBreak = true; } else { @@ -1663,7 +1681,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) { checkUnicode(); - checkDeferredContSectBreak(); + setNeedSect(); RTFSkipDestination aSkip(*this); int nParam = -1; int nSprm = -1; @@ -2282,7 +2300,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) { checkUnicode(nKeyword != RTF_U, true); - checkDeferredContSectBreak(); + setNeedSect(); RTFSkipDestination aSkip(*this); int nSprm = 0; RTFValue::Pointer_t pIntValue(new RTFValue(nParam)); @@ -3002,7 +3020,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) int RTFDocumentImpl::dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) { checkUnicode(); - checkDeferredContSectBreak(); + setNeedSect(); RTFSkipDestination aSkip(*this); int nSprm = -1; RTFValue::Pointer_t pBoolValue(new RTFValue(!bParam || nParam != 0)); @@ -3191,6 +3209,7 @@ int RTFDocumentImpl::popState() bool bFaltEnd = false; bool bPopFrame = false; RTFParserState aState(m_aStates.top()); + m_bWasInFrame = aState.aFrame.inFrame(); if (m_aStates.top().nDestinationState == DESTINATION_FONTTABLE) { @@ -3538,7 +3557,6 @@ int RTFDocumentImpl::popState() { if (m_bNeedCr) dispatchSymbol(RTF_PAR); - m_bDeferredContSectBreak = false; sectBreak(true); } @@ -3758,15 +3776,6 @@ 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), |