[PATCH libreoffice-4-0] solve fdo#62805

Maxime de Roucy (via Code Review) gerrit at gerrit.libreoffice.org
Wed Mar 27 12:10:36 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3096

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/96/3096/1

solve fdo#62805

move m_pCurrentBuffer to RTFParserState

Change-Id: Ied16ee1704d35c6bd0368b26a210131b60bc91a3
Reviewed-on: https://gerrit.libreoffice.org/3082
Reviewed-by: Miklos Vajna <vmiklos at suse.cz>
Tested-by: Miklos Vajna <vmiklos at suse.cz>
---
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 3f18695..7e9c8b0 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -254,7 +254,6 @@
     m_aTableBuffer(),
     m_aSuperBuffer(),
     m_aShapetextBuffer(),
-    m_pCurrentBuffer(0),
     m_bHasFootnote(false),
     m_pSuperstream(0),
     m_nHeaderFooterPositions(),
@@ -437,7 +436,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)
@@ -465,14 +464,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);
@@ -480,7 +479,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));
     }
 }
 
@@ -839,7 +838,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.
@@ -848,7 +847,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;
 }
@@ -948,7 +947,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?
@@ -959,10 +958,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()));
     }
 }
 
@@ -1109,31 +1108,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));
     }
 }
 
@@ -1289,7 +1288,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;
@@ -1343,8 +1342,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())
@@ -1415,7 +1414,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)
@@ -1463,7 +1462,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).
@@ -1475,7 +1474,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,
@@ -1695,7 +1694,7 @@
                 checkNeedPap();
                 if (bNeedPap)
                     runProps();
-                if (!m_pCurrentBuffer)
+                if (!m_aStates.top().pCurrentBuffer)
                 {
                     parBreak();
                     // Not in table? Reset max width.
@@ -1704,7 +1703,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;
@@ -2128,9 +2127,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;
             }
             else
             {
@@ -2378,8 +2377,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);
             }
@@ -2391,10 +2390,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;
@@ -2720,7 +2719,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;
     }
@@ -3761,9 +3760,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()));
@@ -4288,11 +4284,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())
@@ -4405,7 +4403,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/3096
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ied16ee1704d35c6bd0368b26a210131b60bc91a3
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Maxime de Roucy <mderoucy at linagora.com>
Gerrit-Reviewer: Miklos Vajna <vmiklos at suse.cz>



More information about the LibreOffice mailing list