Kaydet (Commit) ea8602bd authored tarafından Maxime de Roucy's avatar Maxime de Roucy Kaydeden (comit) Miklos Vajna

solve fdo#62805

move m_pCurrentBuffer to RTFParserState

Change-Id: Ied16ee1704d35c6bd0368b26a210131b60bc91a3
Reviewed-on: https://gerrit.libreoffice.org/3082Reviewed-by: 's avatarMiklos Vajna <vmiklos@suse.cz>
Tested-by: 's avatarMiklos Vajna <vmiklos@suse.cz>
üst cdf0f6cf
...@@ -255,7 +255,6 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x ...@@ -255,7 +255,6 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
m_aTableBuffer(), m_aTableBuffer(),
m_aSuperBuffer(), m_aSuperBuffer(),
m_aShapetextBuffer(), m_aShapetextBuffer(),
m_pCurrentBuffer(0),
m_bHasFootnote(false), m_bHasFootnote(false),
m_pSuperstream(0), m_pSuperstream(0),
m_nHeaderFooterPositions(), m_nHeaderFooterPositions(),
...@@ -438,7 +437,7 @@ void RTFDocumentImpl::checkNeedPap() ...@@ -438,7 +437,7 @@ void RTFDocumentImpl::checkNeedPap()
if (m_bNeedPap) if (m_bNeedPap)
{ {
m_bNeedPap = false; // reset early, so we can avoid recursion when calling ourselves m_bNeedPap = false; // reset early, so we can avoid recursion when calling ourselves
if (!m_pCurrentBuffer) if (!m_aStates.top().pCurrentBuffer)
{ {
writerfilter::Reference<Properties>::Pointer_t const pParagraphProperties( writerfilter::Reference<Properties>::Pointer_t const pParagraphProperties(
getProperties(m_aStates.top().aParagraphAttributes, m_aStates.top().aParagraphSprms) getProperties(m_aStates.top().aParagraphAttributes, m_aStates.top().aParagraphSprms)
...@@ -466,14 +465,14 @@ void RTFDocumentImpl::checkNeedPap() ...@@ -466,14 +465,14 @@ void RTFDocumentImpl::checkNeedPap()
else else
{ {
RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aParagraphAttributes, m_aStates.top().aParagraphSprms)); RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aParagraphAttributes, m_aStates.top().aParagraphSprms));
m_pCurrentBuffer->push_back(make_pair(BUFFER_PROPS, pValue)); m_aStates.top().pCurrentBuffer->push_back(make_pair(BUFFER_PROPS, pValue));
} }
} }
} }
void RTFDocumentImpl::runProps() void RTFDocumentImpl::runProps()
{ {
if (!m_pCurrentBuffer) if (!m_aStates.top().pCurrentBuffer)
{ {
writerfilter::Reference<Properties>::Pointer_t const pProperties = getProperties(m_aStates.top().aCharacterAttributes, m_aStates.top().aCharacterSprms); writerfilter::Reference<Properties>::Pointer_t const pProperties = getProperties(m_aStates.top().aCharacterAttributes, m_aStates.top().aCharacterSprms);
Mapper().props(pProperties); Mapper().props(pProperties);
...@@ -481,7 +480,7 @@ void RTFDocumentImpl::runProps() ...@@ -481,7 +480,7 @@ void RTFDocumentImpl::runProps()
else else
{ {
RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aCharacterAttributes, m_aStates.top().aCharacterSprms)); RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aCharacterAttributes, m_aStates.top().aCharacterSprms));
m_pCurrentBuffer->push_back(make_pair(BUFFER_PROPS, pValue)); m_aStates.top().pCurrentBuffer->push_back(make_pair(BUFFER_PROPS, pValue));
} }
} }
...@@ -840,7 +839,7 @@ int RTFDocumentImpl::resolvePict(bool bInline) ...@@ -840,7 +839,7 @@ int RTFDocumentImpl::resolvePict(bool bInline)
} }
writerfilter::Reference<Properties>::Pointer_t const pProperties(new RTFReferenceProperties(aAttributes, aSprms)); writerfilter::Reference<Properties>::Pointer_t const pProperties(new RTFReferenceProperties(aAttributes, aSprms));
checkFirstRun(); checkFirstRun();
if (!m_pCurrentBuffer) if (!m_aStates.top().pCurrentBuffer)
{ {
Mapper().props(pProperties); Mapper().props(pProperties);
// Make sure we don't loose these properties with a too early reset. // Make sure we don't loose these properties with a too early reset.
...@@ -849,7 +848,7 @@ int RTFDocumentImpl::resolvePict(bool bInline) ...@@ -849,7 +848,7 @@ int RTFDocumentImpl::resolvePict(bool bInline)
else else
{ {
RTFValue::Pointer_t pValue(new RTFValue(aAttributes, aSprms)); RTFValue::Pointer_t pValue(new RTFValue(aAttributes, aSprms));
m_pCurrentBuffer->push_back(make_pair(BUFFER_PROPS, pValue)); m_aStates.top().pCurrentBuffer->push_back(make_pair(BUFFER_PROPS, pValue));
} }
return 0; return 0;
} }
...@@ -949,7 +948,7 @@ bool RTFFrame::inFrame() ...@@ -949,7 +948,7 @@ bool RTFFrame::inFrame()
void RTFDocumentImpl::singleChar(sal_uInt8 nValue, bool bRunProps) void RTFDocumentImpl::singleChar(sal_uInt8 nValue, bool bRunProps)
{ {
sal_uInt8 sValue[] = { nValue }; sal_uInt8 sValue[] = { nValue };
if (!m_pCurrentBuffer) if (!m_aStates.top().pCurrentBuffer)
{ {
Mapper().startCharacterGroup(); Mapper().startCharacterGroup();
// Should we send run properties? // Should we send run properties?
...@@ -960,10 +959,10 @@ void RTFDocumentImpl::singleChar(sal_uInt8 nValue, bool bRunProps) ...@@ -960,10 +959,10 @@ void RTFDocumentImpl::singleChar(sal_uInt8 nValue, bool bRunProps)
} }
else else
{ {
m_pCurrentBuffer->push_back(make_pair(BUFFER_STARTRUN, RTFValue::Pointer_t())); m_aStates.top().pCurrentBuffer->push_back(make_pair(BUFFER_STARTRUN, RTFValue::Pointer_t()));
RTFValue::Pointer_t pValue(new RTFValue(*sValue)); RTFValue::Pointer_t pValue(new RTFValue(*sValue));
m_pCurrentBuffer->push_back(make_pair(BUFFER_TEXT, pValue)); m_aStates.top().pCurrentBuffer->push_back(make_pair(BUFFER_TEXT, pValue));
m_pCurrentBuffer->push_back(make_pair(BUFFER_ENDRUN, RTFValue::Pointer_t())); m_aStates.top().pCurrentBuffer->push_back(make_pair(BUFFER_ENDRUN, RTFValue::Pointer_t()));
} }
} }
...@@ -1110,31 +1109,31 @@ void RTFDocumentImpl::text(OUString& rString) ...@@ -1110,31 +1109,31 @@ void RTFDocumentImpl::text(OUString& rString)
return; return;
} }
if (!m_pCurrentBuffer && m_aStates.top().nDestinationState != DESTINATION_FOOTNOTE) if (!m_aStates.top().pCurrentBuffer && m_aStates.top().nDestinationState != DESTINATION_FOOTNOTE)
Mapper().startCharacterGroup(); Mapper().startCharacterGroup();
else if (m_pCurrentBuffer) else if (m_aStates.top().pCurrentBuffer)
{ {
RTFValue::Pointer_t pValue; RTFValue::Pointer_t pValue;
m_pCurrentBuffer->push_back(make_pair(BUFFER_STARTRUN, pValue)); m_aStates.top().pCurrentBuffer->push_back(make_pair(BUFFER_STARTRUN, pValue));
} }
if (m_aStates.top().nDestinationState == DESTINATION_NORMAL if (m_aStates.top().nDestinationState == DESTINATION_NORMAL
|| m_aStates.top().nDestinationState == DESTINATION_FIELDRESULT || m_aStates.top().nDestinationState == DESTINATION_FIELDRESULT
|| m_aStates.top().nDestinationState == DESTINATION_SHAPETEXT) || m_aStates.top().nDestinationState == DESTINATION_SHAPETEXT)
runProps(); runProps();
if (!m_pCurrentBuffer) if (!m_aStates.top().pCurrentBuffer)
Mapper().utext(reinterpret_cast<sal_uInt8 const*>(rString.getStr()), rString.getLength()); Mapper().utext(reinterpret_cast<sal_uInt8 const*>(rString.getStr()), rString.getLength());
else else
{ {
RTFValue::Pointer_t pValue(new RTFValue(rString)); RTFValue::Pointer_t pValue(new RTFValue(rString));
m_pCurrentBuffer->push_back(make_pair(BUFFER_UTEXT, pValue)); m_aStates.top().pCurrentBuffer->push_back(make_pair(BUFFER_UTEXT, pValue));
} }
m_bNeedCr = true; m_bNeedCr = true;
if (!m_pCurrentBuffer && m_aStates.top().nDestinationState != DESTINATION_FOOTNOTE) if (!m_aStates.top().pCurrentBuffer && m_aStates.top().nDestinationState != DESTINATION_FOOTNOTE)
Mapper().endCharacterGroup(); Mapper().endCharacterGroup();
else if(m_pCurrentBuffer) else if(m_aStates.top().pCurrentBuffer)
{ {
RTFValue::Pointer_t pValue; RTFValue::Pointer_t pValue;
m_pCurrentBuffer->push_back(make_pair(BUFFER_ENDRUN, pValue)); m_aStates.top().pCurrentBuffer->push_back(make_pair(BUFFER_ENDRUN, pValue));
} }
} }
...@@ -1290,7 +1289,7 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) ...@@ -1290,7 +1289,7 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
break; break;
case RTF_SHPINST: case RTF_SHPINST:
// Don't try to support shapes inside tables for now. // Don't try to support shapes inside tables for now.
if (m_pCurrentBuffer != &m_aTableBuffer) if (m_aStates.top().pCurrentBuffer != &m_aTableBuffer)
m_aStates.top().nDestinationState = DESTINATION_SHAPEINSTRUCTION; m_aStates.top().nDestinationState = DESTINATION_SHAPEINSTRUCTION;
else else
m_aStates.top().nDestinationState = DESTINATION_SKIP; m_aStates.top().nDestinationState = DESTINATION_SKIP;
...@@ -1344,8 +1343,8 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) ...@@ -1344,8 +1343,8 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
nId = NS_rtf::LN_endnote; nId = NS_rtf::LN_endnote;
m_bHasFootnote = true; m_bHasFootnote = true;
if (m_pCurrentBuffer == &m_aSuperBuffer) if (m_aStates.top().pCurrentBuffer == &m_aSuperBuffer)
m_pCurrentBuffer = 0; m_aStates.top().pCurrentBuffer = 0;
bool bCustomMark = false; bool bCustomMark = false;
OUString aCustomMark; OUString aCustomMark;
while (m_aSuperBuffer.size()) while (m_aSuperBuffer.size())
...@@ -1416,7 +1415,7 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) ...@@ -1416,7 +1415,7 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
dispatchFlag(RTF_PARD); dispatchFlag(RTF_PARD);
m_bNeedPap = true; m_bNeedPap = true;
OSL_ENSURE(!m_aShapetextBuffer.size(), "shapetext buffer is not empty"); OSL_ENSURE(!m_aShapetextBuffer.size(), "shapetext buffer is not empty");
m_pCurrentBuffer = &m_aShapetextBuffer; m_aStates.top().pCurrentBuffer = &m_aShapetextBuffer;
break; break;
case RTF_FORMFIELD: case RTF_FORMFIELD:
if (m_aStates.top().nDestinationState == DESTINATION_FIELDINSTRUCTION) if (m_aStates.top().nDestinationState == DESTINATION_FIELDINSTRUCTION)
...@@ -1464,7 +1463,7 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) ...@@ -1464,7 +1463,7 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
m_aStates.top().nDestinationState = DESTINATION_OBJECT; m_aStates.top().nDestinationState = DESTINATION_OBJECT;
// check if the object is in a special container (e.g. a table) // check if the object is in a special container (e.g. a table)
if (!m_pCurrentBuffer) if (!m_aStates.top().pCurrentBuffer)
{ {
// the object is in a table or another container. // the object is in a table or another container.
// Don't try to treate it as an OLE object (fdo#53594). // Don't try to treate it as an OLE object (fdo#53594).
...@@ -1476,7 +1475,7 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword) ...@@ -1476,7 +1475,7 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
break; break;
case RTF_OBJDATA: case RTF_OBJDATA:
// check if the object is in a special container (e.g. a table) // check if the object is in a special container (e.g. a table)
if (m_pCurrentBuffer) if (m_aStates.top().pCurrentBuffer)
{ {
// the object is in a table or another container. // the object is in a table or another container.
// Use the \result (RTF_RESULT) element of the object instead, // Use the \result (RTF_RESULT) element of the object instead,
...@@ -1696,7 +1695,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) ...@@ -1696,7 +1695,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
checkNeedPap(); checkNeedPap();
if (bNeedPap) if (bNeedPap)
runProps(); runProps();
if (!m_pCurrentBuffer) if (!m_aStates.top().pCurrentBuffer)
{ {
parBreak(); parBreak();
// Not in table? Reset max width. // Not in table? Reset max width.
...@@ -1705,7 +1704,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) ...@@ -1705,7 +1704,7 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword)
else if (m_aStates.top().nDestinationState != DESTINATION_SHAPETEXT) else if (m_aStates.top().nDestinationState != DESTINATION_SHAPETEXT)
{ {
RTFValue::Pointer_t pValue; RTFValue::Pointer_t pValue;
m_pCurrentBuffer->push_back(make_pair(BUFFER_PAR, pValue)); m_aStates.top().pCurrentBuffer->push_back(make_pair(BUFFER_PAR, pValue));
} }
// but don't emit properties yet, since they may change till the first text token arrives // but don't emit properties yet, since they may change till the first text token arrives
m_bNeedPap = true; m_bNeedPap = true;
...@@ -2129,9 +2128,9 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) ...@@ -2129,9 +2128,9 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
// Trivial paragraph flags // Trivial paragraph flags
switch (nKeyword) switch (nKeyword)
{ {
case RTF_KEEP: if (m_pCurrentBuffer != &m_aTableBuffer) nParam = NS_sprm::LN_PFKeep; break; case RTF_KEEP: if (m_aStates.top().pCurrentBuffer != &m_aTableBuffer) nParam = NS_sprm::LN_PFKeep; break;
case RTF_KEEPN: if (m_pCurrentBuffer != &m_aTableBuffer) nParam = NS_sprm::LN_PFKeepFollow; break; case RTF_KEEPN: if (m_aStates.top().pCurrentBuffer != &m_aTableBuffer) nParam = NS_sprm::LN_PFKeepFollow; break;
case RTF_INTBL: m_pCurrentBuffer = &m_aTableBuffer; nParam = NS_sprm::LN_PFInTable; break; case RTF_INTBL: m_aStates.top().pCurrentBuffer = &m_aTableBuffer; nParam = NS_sprm::LN_PFInTable; break;
case RTF_PAGEBB: nParam = NS_sprm::LN_PFPageBreakBefore; break; case RTF_PAGEBB: nParam = NS_sprm::LN_PFPageBreakBefore; break;
default: break; default: break;
} }
...@@ -2177,7 +2176,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) ...@@ -2177,7 +2176,7 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
m_aStates.top().aParagraphSprms = m_aDefaultState.aParagraphSprms; m_aStates.top().aParagraphSprms = m_aDefaultState.aParagraphSprms;
m_aStates.top().aParagraphAttributes = m_aDefaultState.aParagraphAttributes; m_aStates.top().aParagraphAttributes = m_aDefaultState.aParagraphAttributes;
if (m_aStates.top().nDestinationState != DESTINATION_SHAPETEXT) if (m_aStates.top().nDestinationState != DESTINATION_SHAPETEXT)
m_pCurrentBuffer = 0; m_aStates.top().pCurrentBuffer = 0;
} }
else else
{ {
...@@ -2379,8 +2378,8 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) ...@@ -2379,8 +2378,8 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
break; break;
case RTF_SUPER: case RTF_SUPER:
{ {
if (!m_pCurrentBuffer) if (!m_aStates.top().pCurrentBuffer)
m_pCurrentBuffer = &m_aSuperBuffer; m_aStates.top().pCurrentBuffer = &m_aSuperBuffer;
RTFValue::Pointer_t pValue(new RTFValue("superscript")); RTFValue::Pointer_t pValue(new RTFValue("superscript"));
m_aStates.top().aCharacterSprms.set(NS_ooxml::LN_EG_RPrBase_vertAlign, pValue); m_aStates.top().aCharacterSprms.set(NS_ooxml::LN_EG_RPrBase_vertAlign, pValue);
} }
...@@ -2392,10 +2391,10 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) ...@@ -2392,10 +2391,10 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword)
} }
break; break;
case RTF_NOSUPERSUB: case RTF_NOSUPERSUB:
if (m_pCurrentBuffer == &m_aSuperBuffer) if (m_aStates.top().pCurrentBuffer == &m_aSuperBuffer)
{ {
replayBuffer(m_aSuperBuffer); replayBuffer(m_aSuperBuffer);
m_pCurrentBuffer = 0; m_aStates.top().pCurrentBuffer = 0;
} }
m_aStates.top().aCharacterSprms.erase(NS_ooxml::LN_EG_RPrBase_vertAlign); m_aStates.top().aCharacterSprms.erase(NS_ooxml::LN_EG_RPrBase_vertAlign);
break; break;
...@@ -2721,7 +2720,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) ...@@ -2721,7 +2720,7 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam)
{ {
m_bNeedPap = true; m_bNeedPap = true;
// Don't try to support text frames inside tables for now. // Don't try to support text frames inside tables for now.
if (m_pCurrentBuffer != &m_aTableBuffer) if (m_aStates.top().pCurrentBuffer != &m_aTableBuffer)
m_aStates.top().aFrame.setSprm(nId, nParam); m_aStates.top().aFrame.setSprm(nId, nParam);
return 0; return 0;
} }
...@@ -3762,9 +3761,6 @@ int RTFDocumentImpl::popState() ...@@ -3762,9 +3761,6 @@ int RTFDocumentImpl::popState()
case DESTINATION_PICT: case DESTINATION_PICT:
resolvePict(true); resolvePict(true);
break; break;
case DESTINATION_SHAPETEXT:
m_pCurrentBuffer = 0; // Just disable buffering, don't empty it yet.
break;
case DESTINATION_FORMFIELDNAME: case DESTINATION_FORMFIELDNAME:
{ {
RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aDestinationText.makeStringAndClear())); RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aDestinationText.makeStringAndClear()));
...@@ -4289,11 +4285,13 @@ int RTFDocumentImpl::popState() ...@@ -4289,11 +4285,13 @@ int RTFDocumentImpl::popState()
else if (m_xDocumentProperties.is()) else if (m_xDocumentProperties.is())
m_xDocumentProperties->setTitle(aState.aDestinationText.makeStringAndClear()); m_xDocumentProperties->setTitle(aState.aDestinationText.makeStringAndClear());
} }
if (m_pCurrentBuffer == &m_aSuperBuffer) if (aState.pCurrentBuffer == &m_aSuperBuffer)
{ {
OSL_ASSERT(m_aStates.top().pCurrentBuffer == 0);
if (!m_bHasFootnote) if (!m_bHasFootnote)
replayBuffer(m_aSuperBuffer); replayBuffer(m_aSuperBuffer);
m_pCurrentBuffer = 0;
m_bHasFootnote = false; m_bHasFootnote = false;
} }
if (m_aStates.size()) if (m_aStates.size())
...@@ -4406,7 +4404,8 @@ RTFParserState::RTFParserState(RTFDocumentImpl *pDocumentImpl) ...@@ -4406,7 +4404,8 @@ RTFParserState::RTFParserState(RTFDocumentImpl *pDocumentImpl)
nDay(0), nDay(0),
nHour(0), nHour(0),
nMinute(0), nMinute(0),
nCurrentStyleIndex(-1) nCurrentStyleIndex(-1),
pCurrentBuffer(0)
{ {
} }
......
...@@ -407,6 +407,9 @@ namespace writerfilter { ...@@ -407,6 +407,9 @@ namespace writerfilter {
/// Same as the int value of NS_rtf::LN_ISTD in aParagraphAttributes, for performance reasons. /// Same as the int value of NS_rtf::LN_ISTD in aParagraphAttributes, for performance reasons.
int nCurrentStyleIndex; int nCurrentStyleIndex;
/// Points to the active buffer, if there is one.
RTFBuffer_t* pCurrentBuffer;
}; };
class RTFTokenizer; class RTFTokenizer;
...@@ -540,8 +543,6 @@ namespace writerfilter { ...@@ -540,8 +543,6 @@ namespace writerfilter {
RTFBuffer_t m_aSuperBuffer; RTFBuffer_t m_aSuperBuffer;
/// Buffered shape text. /// Buffered shape text.
RTFBuffer_t m_aShapetextBuffer; RTFBuffer_t m_aShapetextBuffer;
/// Points to the active buffer, if there is one.
RTFBuffer_t* m_pCurrentBuffer;
bool m_bHasFootnote; bool m_bHasFootnote;
/// Superstream of this substream. /// Superstream of this substream.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment