[PATCH] solve fdo#62805

Maxime de Roucy (via Code Review) gerrit at gerrit.libreoffice.org
Wed Mar 27 04:15:09 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3082

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/82/3082/1

solve fdo#62805

move m_pCurrentBuffer to RTFParserState

Change-Id: Ied16ee1704d35c6bd0368b26a210131b60bc91a3
---
M writerfilter/source/rtftok/rtfdocumentimpl.cxx
M writerfilter/source/rtftok/rtfdocumentimpl.hxx
2 files changed, 44 insertions(+), 44 deletions(-)



diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 4fbb6cc..d2fb17f 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -255,7 +255,6 @@
     m_aTableBuffer(),
     m_aSuperBuffer(),
     m_aShapetextBuffer(),
-    m_pCurrentBuffer(0),
     m_bHasFootnote(false),
     m_pSuperstream(0),
     m_nHeaderFooterPositions(),
@@ -438,7 +437,7 @@
     if (m_bNeedPap)
     {
         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(
                     getProperties(m_aStates.top().aParagraphAttributes, m_aStates.top().aParagraphSprms)
@@ -466,14 +465,14 @@
         else
         {
             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()
 {
-    if (!m_pCurrentBuffer)
+    if (!m_aStates.top().pCurrentBuffer)
     {
         writerfilter::Reference<Properties>::Pointer_t const pProperties = getProperties(m_aStates.top().aCharacterAttributes, m_aStates.top().aCharacterSprms);
         Mapper().props(pProperties);
@@ -481,7 +480,7 @@
     else
     {
         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 @@
     }
     writerfilter::Reference<Properties>::Pointer_t const pProperties(new RTFReferenceProperties(aAttributes, aSprms));
     checkFirstRun();
-    if (!m_pCurrentBuffer)
+    if (!m_aStates.top().pCurrentBuffer)
     {
         Mapper().props(pProperties);
         // Make sure we don't loose these properties with a too early reset.
@@ -849,7 +848,7 @@
     else
     {
         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;
 }
@@ -949,7 +948,7 @@
 void RTFDocumentImpl::singleChar(sal_uInt8 nValue, bool bRunProps)
 {
     sal_uInt8 sValue[] = { nValue };
-    if (!m_pCurrentBuffer)
+    if (!m_aStates.top().pCurrentBuffer)
     {
         Mapper().startCharacterGroup();
         // Should we send run properties?
@@ -960,10 +959,10 @@
     }
     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));
-        m_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_TEXT, pValue));
+        m_aStates.top().pCurrentBuffer->push_back(make_pair(BUFFER_ENDRUN, RTFValue::Pointer_t()));
     }
 }
 
@@ -1110,31 +1109,31 @@
         return;
     }
 
-    if (!m_pCurrentBuffer && m_aStates.top().nDestinationState != DESTINATION_FOOTNOTE)
+    if (!m_aStates.top().pCurrentBuffer && m_aStates.top().nDestinationState != DESTINATION_FOOTNOTE)
         Mapper().startCharacterGroup();
-    else if (m_pCurrentBuffer)
+    else if (m_aStates.top().pCurrentBuffer)
     {
         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
             || m_aStates.top().nDestinationState == DESTINATION_FIELDRESULT
             || m_aStates.top().nDestinationState == DESTINATION_SHAPETEXT)
         runProps();
-    if (!m_pCurrentBuffer)
+    if (!m_aStates.top().pCurrentBuffer)
         Mapper().utext(reinterpret_cast<sal_uInt8 const*>(rString.getStr()), rString.getLength());
     else
     {
         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;
-    if (!m_pCurrentBuffer && m_aStates.top().nDestinationState != DESTINATION_FOOTNOTE)
+    if (!m_aStates.top().pCurrentBuffer && m_aStates.top().nDestinationState != DESTINATION_FOOTNOTE)
         Mapper().endCharacterGroup();
-    else if(m_pCurrentBuffer)
+    else if(m_aStates.top().pCurrentBuffer)
     {
         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 @@
             break;
         case RTF_SHPINST:
             // 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;
             else
                 m_aStates.top().nDestinationState = DESTINATION_SKIP;
@@ -1344,8 +1343,8 @@
                     nId = NS_rtf::LN_endnote;
 
                 m_bHasFootnote = true;
-                if (m_pCurrentBuffer == &m_aSuperBuffer)
-                    m_pCurrentBuffer = 0;
+                if (m_aStates.top().pCurrentBuffer == &m_aSuperBuffer)
+                    m_aStates.top().pCurrentBuffer = 0;
                 bool bCustomMark = false;
                 OUString aCustomMark;
                 while (m_aSuperBuffer.size())
@@ -1416,7 +1415,7 @@
             dispatchFlag(RTF_PARD);
             m_bNeedPap = true;
             OSL_ENSURE(!m_aShapetextBuffer.size(), "shapetext buffer is not empty");
-            m_pCurrentBuffer = &m_aShapetextBuffer;
+            m_aStates.top().pCurrentBuffer = &m_aShapetextBuffer;
             break;
         case RTF_FORMFIELD:
             if (m_aStates.top().nDestinationState == DESTINATION_FIELDINSTRUCTION)
@@ -1464,7 +1463,7 @@
                 m_aStates.top().nDestinationState = DESTINATION_OBJECT;
 
                 // 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.
                     // Don't try to treate it as an OLE object (fdo#53594).
@@ -1476,7 +1475,7 @@
             break;
         case RTF_OBJDATA:
             // 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.
                 // Use the \result (RTF_RESULT) element of the object instead,
@@ -1696,7 +1695,7 @@
                 checkNeedPap();
                 if (bNeedPap)
                     runProps();
-                if (!m_pCurrentBuffer)
+                if (!m_aStates.top().pCurrentBuffer)
                 {
                     parBreak();
                     // Not in table? Reset max width.
@@ -1705,7 +1704,7 @@
                 else if (m_aStates.top().nDestinationState != DESTINATION_SHAPETEXT)
                 {
                     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
                 m_bNeedPap = true;
@@ -2129,9 +2128,9 @@
     // Trivial paragraph flags
     switch (nKeyword)
     {
-        case RTF_KEEP: if (m_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_INTBL: m_pCurrentBuffer = &m_aTableBuffer; nParam = NS_sprm::LN_PFInTable; break;
+        case RTF_KEEP: if (m_aStates.top().pCurrentBuffer != &m_aTableBuffer) nParam = NS_sprm::LN_PFKeep; break;
+        case RTF_KEEPN: if (m_aStates.top().pCurrentBuffer != &m_aTableBuffer) nParam = NS_sprm::LN_PFKeepFollow; 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;
         default: break;
     }
@@ -2176,7 +2175,7 @@
                 m_aStates.top().aParagraphSprms = m_aDefaultState.aParagraphSprms;
                 m_aStates.top().aParagraphAttributes = m_aDefaultState.aParagraphAttributes;
                 if (m_aStates.top().nDestinationState != DESTINATION_SHAPETEXT)
-                    m_pCurrentBuffer = 0;
+                    m_aStates.top().pCurrentBuffer = 0;
             }
             m_aStates.top().resetFrame();
             break;
@@ -2370,8 +2369,8 @@
             break;
         case RTF_SUPER:
             {
-                if (!m_pCurrentBuffer)
-                    m_pCurrentBuffer = &m_aSuperBuffer;
+                if (!m_aStates.top().pCurrentBuffer)
+                    m_aStates.top().pCurrentBuffer = &m_aSuperBuffer;
                 RTFValue::Pointer_t pValue(new RTFValue("superscript"));
                 m_aStates.top().aCharacterSprms.set(NS_ooxml::LN_EG_RPrBase_vertAlign, pValue);
             }
@@ -2383,10 +2382,10 @@
             }
             break;
         case RTF_NOSUPERSUB:
-            if (m_pCurrentBuffer == &m_aSuperBuffer)
+            if (m_aStates.top().pCurrentBuffer == &m_aSuperBuffer)
             {
                 replayBuffer(m_aSuperBuffer);
-                m_pCurrentBuffer = 0;
+                m_aStates.top().pCurrentBuffer = 0;
             }
             m_aStates.top().aCharacterSprms.erase(NS_ooxml::LN_EG_RPrBase_vertAlign);
             break;
@@ -2712,7 +2711,7 @@
     {
         m_bNeedPap = true;
         // 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);
         return 0;
     }
@@ -3753,9 +3752,6 @@
     case DESTINATION_PICT:
         resolvePict(true);
     break;
-    case DESTINATION_SHAPETEXT:
-        m_pCurrentBuffer = 0; // Just disable buffering, don't empty it yet.
-    break;
     case DESTINATION_FORMFIELDNAME:
     {
         RTFValue::Pointer_t pValue(new RTFValue(m_aStates.top().aDestinationText.makeStringAndClear()));
@@ -4280,11 +4276,13 @@
         else if (m_xDocumentProperties.is())
             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)
             replayBuffer(m_aSuperBuffer);
-        m_pCurrentBuffer = 0;
+
         m_bHasFootnote = false;
     }
     if (m_aStates.size())
@@ -4397,7 +4395,8 @@
     nDay(0),
     nHour(0),
     nMinute(0),
-    nCurrentStyleIndex(-1)
+    nCurrentStyleIndex(-1),
+    pCurrentBuffer(0)
 {
 }
 
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 5ced019..a96ad9a 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -407,6 +407,9 @@
 
                 /// Same as the int value of NS_rtf::LN_ISTD in aParagraphAttributes, for performance reasons.
                 int nCurrentStyleIndex;
+
+                /// Points to the active buffer, if there is one.
+                RTFBuffer_t* pCurrentBuffer;
         };
 
         class RTFTokenizer;
@@ -540,8 +543,6 @@
                 RTFBuffer_t m_aSuperBuffer;
                 /// Buffered shape text.
                 RTFBuffer_t m_aShapetextBuffer;
-                /// Points to the active buffer, if there is one.
-                RTFBuffer_t* m_pCurrentBuffer;
 
                 bool m_bHasFootnote;
                 /// Superstream of this substream.

-- 
To view, visit https://gerrit.libreoffice.org/3082
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ied16ee1704d35c6bd0368b26a210131b60bc91a3
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Maxime de Roucy <mderoucy at linagora.com>



More information about the LibreOffice mailing list