[Libreoffice-commits] core.git: 2 commits - writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Sat Mar 15 09:41:12 PDT 2014


 writerfilter/source/rtftok/rtfcontrolwords.cxx |   59 +++++++++
 writerfilter/source/rtftok/rtfcontrolwords.hxx |  150 +++++++++++++++++++++++++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   71 ++---------
 writerfilter/source/rtftok/rtflistener.hxx     |  135 ----------------------
 writerfilter/source/rtftok/rtftokenizer.cxx    |   18 +++
 writerfilter/source/rtftok/rtftokenizer.hxx    |    5 
 6 files changed, 247 insertions(+), 191 deletions(-)

New commits:
commit fa40f7df971b1aaabccc11668a987336f50e3b0d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sat Mar 15 17:36:49 2014 +0100

    rtftok: OPEN_M_TOKEN -> RTFTokenizer::lookupMathKeyword()
    
    Change-Id: I60d0e65d0e7f37b2d5cded64cee1270c51ed5b3d

diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 7e09482..c50e13e 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -58,11 +58,6 @@
 
 #define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
 #define MM100_TO_EMU(MM100)     (MM100 * 360)
-#define OPEN_M_TOKEN( rtftok, ooxtok ) \
-        case RTF_M##rtftok: \
-            m_aMathBuffer.appendOpeningTag(M_TOKEN(ooxtok)); \
-            m_aStates.top().nDestinationState = DESTINATION_M##rtftok; \
-            break
 
 using std::make_pair;
 
@@ -1827,51 +1822,6 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
         case RTF_MBEGCHR: m_aStates.top().nDestinationState = DESTINATION_MBEGCHR; break;
         case RTF_MSEPCHR: m_aStates.top().nDestinationState = DESTINATION_MSEPCHR; break;
         case RTF_MENDCHR: m_aStates.top().nDestinationState = DESTINATION_MENDCHR; break;
-        OPEN_M_TOKEN(OMATH, oMath);
-        OPEN_M_TOKEN(F, f);
-        OPEN_M_TOKEN(FPR, fPr);
-        OPEN_M_TOKEN(CTRLPR, ctrlPr);
-        OPEN_M_TOKEN(NUM, num);
-        OPEN_M_TOKEN(DEN, den);
-        OPEN_M_TOKEN(ACC, acc);
-        OPEN_M_TOKEN(ACCPR, accPr);
-        OPEN_M_TOKEN(BAR, bar);
-        OPEN_M_TOKEN(BARPR, barPr);
-        OPEN_M_TOKEN(E, e);
-        OPEN_M_TOKEN(D, d);
-        OPEN_M_TOKEN(DPR, dPr);
-        OPEN_M_TOKEN(FUNC, func);
-        OPEN_M_TOKEN(FUNCPR, funcPr);
-        OPEN_M_TOKEN(FNAME, fName);
-        OPEN_M_TOKEN(LIMLOW, limLow);
-        OPEN_M_TOKEN(LIMLOWPR, limLowPr);
-        OPEN_M_TOKEN(LIM, lim);
-        OPEN_M_TOKEN(M, m);
-        OPEN_M_TOKEN(MPR, mPr);
-        OPEN_M_TOKEN(MR, mr);
-        OPEN_M_TOKEN(NARY, nary);
-        OPEN_M_TOKEN(NARYPR, naryPr);
-        OPEN_M_TOKEN(SUB, sub);
-        OPEN_M_TOKEN(SUP, sup);
-        OPEN_M_TOKEN(LIMUPP, limUpp);
-        OPEN_M_TOKEN(LIMUPPPR, limUppPr);
-        OPEN_M_TOKEN(GROUPCHR, groupChr);
-        OPEN_M_TOKEN(GROUPCHRPR, groupChrPr);
-        OPEN_M_TOKEN(BORDERBOX, borderBox);
-        OPEN_M_TOKEN(BORDERBOXPR, borderBoxPr);
-        OPEN_M_TOKEN(RAD, rad);
-        OPEN_M_TOKEN(RADPR, radPr);
-        OPEN_M_TOKEN(DEG, deg);
-        OPEN_M_TOKEN(SSUB, sSub);
-        OPEN_M_TOKEN(SSUBPR, sSubPr);
-        OPEN_M_TOKEN(SSUP, sSup);
-        OPEN_M_TOKEN(SSUPPR, sSupPr);
-        OPEN_M_TOKEN(SSUBSUP, sSubSup);
-        OPEN_M_TOKEN(SSUBSUPPR, sSubSupPr);
-        OPEN_M_TOKEN(SPRE, sPre);
-        OPEN_M_TOKEN(SPREPR, sPrePr);
-        OPEN_M_TOKEN(BOX, box);
-        OPEN_M_TOKEN(EQARR, eqArr);
         case RTF_UPR:
             m_aStates.top().nDestinationState = DESTINATION_UPR;
             break;
@@ -1907,10 +1857,22 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
             m_aStates.top().aCharacterAttributes.set(NS_ooxml::LN_CT_FtnEdn_type, RTFValue::Pointer_t(new RTFValue(NS_ooxml::LN_Value_wordprocessingml_ST_FtnEdn_separator)));
             break;
         default:
-            SAL_INFO("writerfilter", "TODO handle destination '" << lcl_RtfToString(nKeyword) << "'");
-            // Make sure we skip destinations (even without \*) till we don't handle them
-            m_aStates.top().nDestinationState = DESTINATION_SKIP;
-            aSkip.setParsed(false);
+            {
+                // Check if it's a math token.
+                RTFMathSymbol aSymbol;
+                aSymbol.eKeyword = nKeyword;
+                if (RTFTokenizer::lookupMathKeyword(aSymbol))
+                {
+                    m_aMathBuffer.appendOpeningTag(aSymbol.nToken);
+                    m_aStates.top().nDestinationState = aSymbol.eDestination;
+                    return 0;
+                }
+
+                SAL_INFO("writerfilter", "TODO handle destination '" << lcl_RtfToString(nKeyword) << "'");
+                // Make sure we skip destinations (even without \*) till we don't handle them
+                m_aStates.top().nDestinationState = DESTINATION_SKIP;
+                aSkip.setParsed(false);
+            }
             break;
     }
 
commit 6f09a77cda886f2efefd97766366f277b17ca984
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Sat Mar 15 17:32:02 2014 +0100

    rtftok: add static array that maps between rtf and ooxml math tokens
    
    Change-Id: I7e27115ec35ce4209b7c92951919312267754742

diff --git a/writerfilter/source/rtftok/rtfcontrolwords.cxx b/writerfilter/source/rtftok/rtfcontrolwords.cxx
index 2890c4e..1076f9d 100644
--- a/writerfilter/source/rtftok/rtfcontrolwords.cxx
+++ b/writerfilter/source/rtftok/rtfcontrolwords.cxx
@@ -7,7 +7,9 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#include <rtfcontrolwords.hxx>
+#include <rtflistener.hxx>
+#include <oox/token/namespaces.hxx>
+#include <oox/token/tokens.hxx>
 #include <sal/macros.h>
 #include <string.h>
 
@@ -1849,6 +1851,61 @@ bool RTFSymbol::operator<(const RTFSymbol& rOther) const
     return strcmp(sKeyword, rOther.sKeyword) < 0;
 }
 
+RTFMathSymbol aRTFMathControlWords[] = {
+    // eKeyword nToken eDestination
+    {RTF_MOMATH, M_TOKEN(oMath), DESTINATION_MOMATH},
+    {RTF_MF, M_TOKEN(f), DESTINATION_MF},
+    {RTF_MFPR, M_TOKEN(fPr), DESTINATION_MFPR},
+    {RTF_MCTRLPR, M_TOKEN(ctrlPr), DESTINATION_MCTRLPR},
+    {RTF_MNUM, M_TOKEN(num), DESTINATION_MNUM},
+    {RTF_MDEN, M_TOKEN(den), DESTINATION_MDEN},
+    {RTF_MACC, M_TOKEN(acc), DESTINATION_MACC},
+    {RTF_MACCPR, M_TOKEN(accPr), DESTINATION_MACCPR},
+    {RTF_MBAR, M_TOKEN(bar), DESTINATION_MBAR},
+    {RTF_MBARPR, M_TOKEN(barPr), DESTINATION_MBARPR},
+    {RTF_ME, M_TOKEN(e), DESTINATION_ME},
+    {RTF_MD, M_TOKEN(d), DESTINATION_MD},
+    {RTF_MDPR, M_TOKEN(dPr), DESTINATION_MDPR},
+    {RTF_MFUNC, M_TOKEN(func), DESTINATION_MFUNC},
+    {RTF_MFUNCPR, M_TOKEN(funcPr), DESTINATION_MFUNCPR},
+    {RTF_MFNAME, M_TOKEN(fName), DESTINATION_MFNAME},
+    {RTF_MLIMLOW, M_TOKEN(limLow), DESTINATION_MLIMLOW},
+    {RTF_MLIMLOWPR, M_TOKEN(limLowPr), DESTINATION_MLIMLOWPR},
+    {RTF_MLIM, M_TOKEN(lim), DESTINATION_MLIM},
+    {RTF_MM, M_TOKEN(m), DESTINATION_MM},
+    {RTF_MMPR, M_TOKEN(mPr), DESTINATION_MMPR},
+    {RTF_MMR, M_TOKEN(mr), DESTINATION_MMR},
+    {RTF_MNARY, M_TOKEN(nary), DESTINATION_MNARY},
+    {RTF_MNARYPR, M_TOKEN(naryPr), DESTINATION_MNARYPR},
+    {RTF_MSUB, M_TOKEN(sub), DESTINATION_MSUB},
+    {RTF_MSUP, M_TOKEN(sup), DESTINATION_MSUP},
+    {RTF_MLIMUPP, M_TOKEN(limUpp), DESTINATION_MLIMUPP},
+    {RTF_MLIMUPPPR, M_TOKEN(limUppPr), DESTINATION_MLIMUPPPR},
+    {RTF_MGROUPCHR, M_TOKEN(groupChr), DESTINATION_MGROUPCHR},
+    {RTF_MGROUPCHRPR, M_TOKEN(groupChrPr), DESTINATION_MGROUPCHRPR},
+    {RTF_MBORDERBOX, M_TOKEN(borderBox), DESTINATION_MBORDERBOX},
+    {RTF_MBORDERBOXPR, M_TOKEN(borderBoxPr), DESTINATION_MBORDERBOXPR},
+    {RTF_MRAD, M_TOKEN(rad), DESTINATION_MRAD},
+    {RTF_MRADPR, M_TOKEN(radPr), DESTINATION_MRADPR},
+    {RTF_MDEG, M_TOKEN(deg), DESTINATION_MDEG},
+    {RTF_MSSUB, M_TOKEN(sSub), DESTINATION_MSSUB},
+    {RTF_MSSUBPR, M_TOKEN(sSubPr), DESTINATION_MSSUBPR},
+    {RTF_MSSUP, M_TOKEN(sSup), DESTINATION_MSSUP},
+    {RTF_MSSUPPR, M_TOKEN(sSupPr), DESTINATION_MSSUPPR},
+    {RTF_MSSUBSUP, M_TOKEN(sSubSup), DESTINATION_MSSUBSUP},
+    {RTF_MSSUBSUPPR, M_TOKEN(sSubSupPr), DESTINATION_MSSUBSUPPR},
+    {RTF_MSPRE, M_TOKEN(sPre), DESTINATION_MSPRE},
+    {RTF_MSPREPR, M_TOKEN(sPrePr), DESTINATION_MSPREPR},
+    {RTF_MBOX, M_TOKEN(box), DESTINATION_MBOX},
+    {RTF_MEQARR, M_TOKEN(eqArr), DESTINATION_MEQARR},
+};
+int nRTFMathControlWords = SAL_N_ELEMENTS(aRTFMathControlWords);
+
+bool RTFMathSymbol::operator<(const RTFMathSymbol& rOther) const
+{
+    return eKeyword < rOther.eKeyword;
+}
+
 } // namespace rtftok
 } // namespace writerfilter
 
diff --git a/writerfilter/source/rtftok/rtfcontrolwords.hxx b/writerfilter/source/rtftok/rtfcontrolwords.hxx
index d38a0b4..6283a08 100644
--- a/writerfilter/source/rtftok/rtfcontrolwords.hxx
+++ b/writerfilter/source/rtftok/rtfcontrolwords.hxx
@@ -13,6 +13,141 @@
 namespace writerfilter {
 namespace rtftok {
 
+// Note that this is not a 1:1 mapping between destination control
+// words, e.g. RTF_PICT gets mapped to DESTINATION_PICT or
+// DESTINATION_SHAPEPROPERTYVALUEPICT, etc.
+enum RTFDestinationState
+{
+    DESTINATION_NORMAL,
+    DESTINATION_SKIP,
+    DESTINATION_FONTTABLE,
+    DESTINATION_FONTENTRY,
+    DESTINATION_COLORTABLE,
+    DESTINATION_STYLESHEET,
+    DESTINATION_STYLEENTRY,
+    DESTINATION_FIELD,
+    DESTINATION_FIELDINSTRUCTION,
+    DESTINATION_FIELDRESULT,
+    DESTINATION_LISTTABLE,
+    DESTINATION_LISTPICTURE,
+    DESTINATION_LISTENTRY,
+    DESTINATION_LISTOVERRIDETABLE,
+    DESTINATION_LISTOVERRIDEENTRY,
+    DESTINATION_LISTLEVEL,
+    DESTINATION_LEVELTEXT,
+    DESTINATION_LEVELNUMBERS,
+    DESTINATION_SHPPICT,
+    DESTINATION_PICT,
+    DESTINATION_PICPROP,
+    DESTINATION_SHAPEPROPERTY,
+    DESTINATION_SHAPEPROPERTYNAME,
+    DESTINATION_SHAPEPROPERTYVALUE,
+    DESTINATION_SHAPE,
+    DESTINATION_SHAPEINSTRUCTION,
+    DESTINATION_SHAPEPROPERTYVALUEPICT,
+    DESTINATION_NESTEDTABLEPROPERTIES,
+    DESTINATION_FOOTNOTE,
+    DESTINATION_BOOKMARKSTART,
+    DESTINATION_BOOKMARKEND,
+    DESTINATION_REVISIONTABLE,
+    DESTINATION_REVISIONENTRY,
+    DESTINATION_SHAPETEXT,
+    DESTINATION_FORMFIELD,
+    DESTINATION_FORMFIELDNAME,
+    DESTINATION_FORMFIELDLIST,
+    DESTINATION_DATAFIELD,
+    DESTINATION_INFO,
+    DESTINATION_CREATIONTIME,
+    DESTINATION_REVISIONTIME,
+    DESTINATION_PRINTTIME,
+    DESTINATION_AUTHOR,
+    DESTINATION_KEYWORDS,
+    DESTINATION_OPERATOR,
+    DESTINATION_COMPANY,
+    DESTINATION_COMMENT,
+    DESTINATION_OBJECT,
+    DESTINATION_OBJDATA,
+    DESTINATION_RESULT,
+    DESTINATION_ANNOTATIONDATE,
+    DESTINATION_ANNOTATIONAUTHOR,
+    DESTINATION_ANNOTATIONREFERENCE,
+    DESTINATION_FALT,
+    DESTINATION_FLYMAINCONTENT,
+    DESTINATION_DRAWINGOBJECT,
+    DESTINATION_PARAGRAPHNUMBERING,
+    DESTINATION_PARAGRAPHNUMBERING_TEXTBEFORE,
+    DESTINATION_PARAGRAPHNUMBERING_TEXTAFTER,
+    DESTINATION_TITLE,
+    DESTINATION_SUBJECT,
+    DESTINATION_DOCCOMM,
+    DESTINATION_ATNID,
+    DESTINATION_ANNOTATIONREFERENCESTART,
+    DESTINATION_ANNOTATIONREFERENCEEND,
+    DESTINATION_MOMATH,
+    DESTINATION_MR,
+    DESTINATION_MF,
+    DESTINATION_MFPR,
+    DESTINATION_MCTRLPR,
+    DESTINATION_MNUM,
+    DESTINATION_MDEN,
+    DESTINATION_MACC,
+    DESTINATION_MACCPR,
+    DESTINATION_MCHR,
+    DESTINATION_MPOS,
+    DESTINATION_MVERTJC,
+    DESTINATION_MSTRIKEH,
+    DESTINATION_MDEGHIDE,
+    DESTINATION_ME,
+    DESTINATION_MBAR,
+    DESTINATION_MBARPR,
+    DESTINATION_MD,
+    DESTINATION_MDPR,
+    DESTINATION_MBEGCHR,
+    DESTINATION_MSEPCHR,
+    DESTINATION_MENDCHR,
+    DESTINATION_MFUNC,
+    DESTINATION_MFUNCPR,
+    DESTINATION_MFNAME,
+    DESTINATION_MLIMLOW,
+    DESTINATION_MLIMLOWPR,
+    DESTINATION_MLIM,
+    DESTINATION_MM,
+    DESTINATION_MMPR,
+    DESTINATION_MMR,
+    DESTINATION_MNARY,
+    DESTINATION_MNARYPR,
+    DESTINATION_MSUB,
+    DESTINATION_MSUP,
+    DESTINATION_MSUBHIDE,
+    DESTINATION_MSUPHIDE,
+    DESTINATION_MLIMUPP,
+    DESTINATION_MLIMUPPPR,
+    DESTINATION_MGROUPCHR,
+    DESTINATION_MGROUPCHRPR,
+    DESTINATION_MBORDERBOX,
+    DESTINATION_MBORDERBOXPR,
+    DESTINATION_MRAD,
+    DESTINATION_MRADPR,
+    DESTINATION_MDEG,
+    DESTINATION_MSSUB,
+    DESTINATION_MSSUBPR,
+    DESTINATION_MSSUP,
+    DESTINATION_MSSUPPR,
+    DESTINATION_MSSUBSUP,
+    DESTINATION_MSSUBSUPPR,
+    DESTINATION_MSPRE,
+    DESTINATION_MSPREPR,
+    DESTINATION_MTYPE,
+    DESTINATION_MGROW,
+    DESTINATION_MBOX,
+    DESTINATION_MEQARR,
+    DESTINATION_UPR,
+    DESTINATION_LFOLEVEL,
+    DESTINATION_BACKGROUND,
+    DESTINATION_SHAPEGROUP,
+    DESTINATION_FOOTNOTESEPARATOR,
+};
+
 enum RTFKeyword
 {
     RTF_invalid = -1,
@@ -1855,6 +1990,21 @@ struct RTFSymbol
 
 extern RTFSymbol aRTFControlWords[];
 extern int nRTFControlWords;
+
+/// Respresents an RTF Math Control Word
+struct RTFMathSymbol
+{
+    RTFKeyword eKeyword;
+    int nToken; ///< This is the OOXML token equivalent.
+    RTFDestinationState eDestination;
+    bool operator<(const RTFMathSymbol& rOther) const;
+};
+
+#define M_TOKEN(token) OOX_TOKEN(officeMath, token)
+
+extern RTFMathSymbol aRTFMathControlWords[];
+extern int nRTFMathControlWords;
+
 } // namespace rtftok
 } // namespace writerfilter
 
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 0e21515..7e09482 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -58,7 +58,6 @@
 
 #define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
 #define MM100_TO_EMU(MM100)     (MM100 * 360)
-#define M_TOKEN(token) OOX_TOKEN(officeMath, token)
 #define OPEN_M_TOKEN( rtftok, ooxtok ) \
         case RTF_M##rtftok: \
             m_aMathBuffer.appendOpeningTag(M_TOKEN(ooxtok)); \
diff --git a/writerfilter/source/rtftok/rtflistener.hxx b/writerfilter/source/rtftok/rtflistener.hxx
index b345275..fd76282 100644
--- a/writerfilter/source/rtftok/rtflistener.hxx
+++ b/writerfilter/source/rtftok/rtflistener.hxx
@@ -21,141 +21,6 @@ namespace writerfilter {
             INTERNAL_HEX
         };
 
-        // Note that this is not a 1:1 mapping between destination control
-        // words, e.g. RTF_PICT gets mapped to DESTINATION_PICT or
-        // DESTINATION_SHAPEPROPERTYVALUEPICT, etc.
-        enum RTFDestinationState
-        {
-            DESTINATION_NORMAL,
-            DESTINATION_SKIP,
-            DESTINATION_FONTTABLE,
-            DESTINATION_FONTENTRY,
-            DESTINATION_COLORTABLE,
-            DESTINATION_STYLESHEET,
-            DESTINATION_STYLEENTRY,
-            DESTINATION_FIELD,
-            DESTINATION_FIELDINSTRUCTION,
-            DESTINATION_FIELDRESULT,
-            DESTINATION_LISTTABLE,
-            DESTINATION_LISTPICTURE,
-            DESTINATION_LISTENTRY,
-            DESTINATION_LISTOVERRIDETABLE,
-            DESTINATION_LISTOVERRIDEENTRY,
-            DESTINATION_LISTLEVEL,
-            DESTINATION_LEVELTEXT,
-            DESTINATION_LEVELNUMBERS,
-            DESTINATION_SHPPICT,
-            DESTINATION_PICT,
-            DESTINATION_PICPROP,
-            DESTINATION_SHAPEPROPERTY,
-            DESTINATION_SHAPEPROPERTYNAME,
-            DESTINATION_SHAPEPROPERTYVALUE,
-            DESTINATION_SHAPE,
-            DESTINATION_SHAPEINSTRUCTION,
-            DESTINATION_SHAPEPROPERTYVALUEPICT,
-            DESTINATION_NESTEDTABLEPROPERTIES,
-            DESTINATION_FOOTNOTE,
-            DESTINATION_BOOKMARKSTART,
-            DESTINATION_BOOKMARKEND,
-            DESTINATION_REVISIONTABLE,
-            DESTINATION_REVISIONENTRY,
-            DESTINATION_SHAPETEXT,
-            DESTINATION_FORMFIELD,
-            DESTINATION_FORMFIELDNAME,
-            DESTINATION_FORMFIELDLIST,
-            DESTINATION_DATAFIELD,
-            DESTINATION_INFO,
-            DESTINATION_CREATIONTIME,
-            DESTINATION_REVISIONTIME,
-            DESTINATION_PRINTTIME,
-            DESTINATION_AUTHOR,
-            DESTINATION_KEYWORDS,
-            DESTINATION_OPERATOR,
-            DESTINATION_COMPANY,
-            DESTINATION_COMMENT,
-            DESTINATION_OBJECT,
-            DESTINATION_OBJDATA,
-            DESTINATION_RESULT,
-            DESTINATION_ANNOTATIONDATE,
-            DESTINATION_ANNOTATIONAUTHOR,
-            DESTINATION_ANNOTATIONREFERENCE,
-            DESTINATION_FALT,
-            DESTINATION_FLYMAINCONTENT,
-            DESTINATION_DRAWINGOBJECT,
-            DESTINATION_PARAGRAPHNUMBERING,
-            DESTINATION_PARAGRAPHNUMBERING_TEXTBEFORE,
-            DESTINATION_PARAGRAPHNUMBERING_TEXTAFTER,
-            DESTINATION_TITLE,
-            DESTINATION_SUBJECT,
-            DESTINATION_DOCCOMM,
-            DESTINATION_ATNID,
-            DESTINATION_ANNOTATIONREFERENCESTART,
-            DESTINATION_ANNOTATIONREFERENCEEND,
-            DESTINATION_MOMATH,
-            DESTINATION_MR,
-            DESTINATION_MF,
-            DESTINATION_MFPR,
-            DESTINATION_MCTRLPR,
-            DESTINATION_MNUM,
-            DESTINATION_MDEN,
-            DESTINATION_MACC,
-            DESTINATION_MACCPR,
-            DESTINATION_MCHR,
-            DESTINATION_MPOS,
-            DESTINATION_MVERTJC,
-            DESTINATION_MSTRIKEH,
-            DESTINATION_MDEGHIDE,
-            DESTINATION_ME,
-            DESTINATION_MBAR,
-            DESTINATION_MBARPR,
-            DESTINATION_MD,
-            DESTINATION_MDPR,
-            DESTINATION_MBEGCHR,
-            DESTINATION_MSEPCHR,
-            DESTINATION_MENDCHR,
-            DESTINATION_MFUNC,
-            DESTINATION_MFUNCPR,
-            DESTINATION_MFNAME,
-            DESTINATION_MLIMLOW,
-            DESTINATION_MLIMLOWPR,
-            DESTINATION_MLIM,
-            DESTINATION_MM,
-            DESTINATION_MMPR,
-            DESTINATION_MMR,
-            DESTINATION_MNARY,
-            DESTINATION_MNARYPR,
-            DESTINATION_MSUB,
-            DESTINATION_MSUP,
-            DESTINATION_MSUBHIDE,
-            DESTINATION_MSUPHIDE,
-            DESTINATION_MLIMUPP,
-            DESTINATION_MLIMUPPPR,
-            DESTINATION_MGROUPCHR,
-            DESTINATION_MGROUPCHRPR,
-            DESTINATION_MBORDERBOX,
-            DESTINATION_MBORDERBOXPR,
-            DESTINATION_MRAD,
-            DESTINATION_MRADPR,
-            DESTINATION_MDEG,
-            DESTINATION_MSSUB,
-            DESTINATION_MSSUBPR,
-            DESTINATION_MSSUP,
-            DESTINATION_MSSUPPR,
-            DESTINATION_MSSUBSUP,
-            DESTINATION_MSSUBSUPPR,
-            DESTINATION_MSPRE,
-            DESTINATION_MSPREPR,
-            DESTINATION_MTYPE,
-            DESTINATION_MGROW,
-            DESTINATION_MBOX,
-            DESTINATION_MEQARR,
-            DESTINATION_UPR,
-            DESTINATION_LFOLEVEL,
-            DESTINATION_BACKGROUND,
-            DESTINATION_SHAPEGROUP,
-            DESTINATION_FOOTNOTESEPARATOR,
-        };
-
         enum RTFErrors
         {
             ERROR_OK,
diff --git a/writerfilter/source/rtftok/rtftokenizer.cxx b/writerfilter/source/rtftok/rtftokenizer.cxx
index 497c551..a5a00fb 100644
--- a/writerfilter/source/rtftok/rtftokenizer.cxx
+++ b/writerfilter/source/rtftok/rtftokenizer.cxx
@@ -25,6 +25,8 @@ namespace rtftok {
 
 std::vector<RTFSymbol> RTFTokenizer::m_aRTFControlWords;
 bool RTFTokenizer::m_bControlWordsSorted;
+std::vector<RTFMathSymbol> RTFTokenizer::m_aRTFMathControlWords;
+bool RTFTokenizer::m_bMathControlWordsSorted;
 
 RTFTokenizer::RTFTokenizer(RTFListener& rImport, SvStream* pInStream, uno::Reference<task::XStatusIndicator> const& xStatusIndicator)
     : m_rImport(rImport),
@@ -41,6 +43,12 @@ RTFTokenizer::RTFTokenizer(RTFListener& rImport, SvStream* pInStream, uno::Refer
         m_aRTFControlWords = std::vector<RTFSymbol>(aRTFControlWords, aRTFControlWords + nRTFControlWords);
         std::sort(m_aRTFControlWords.begin(), m_aRTFControlWords.end());
     }
+    if (!RTFTokenizer::m_bMathControlWordsSorted)
+    {
+        RTFTokenizer::m_bMathControlWordsSorted = true;
+        m_aRTFMathControlWords = std::vector<RTFMathSymbol>(aRTFMathControlWords, aRTFMathControlWords + nRTFMathControlWords);
+        std::sort(m_aRTFMathControlWords.begin(), m_aRTFMathControlWords.end());
+    }
 }
 
 RTFTokenizer::~RTFTokenizer()
@@ -273,6 +281,16 @@ int RTFTokenizer::resolveKeyword()
     return dispatchKeyword(aKeyword, bParam, nParam);
 }
 
+bool RTFTokenizer::lookupMathKeyword(RTFMathSymbol& rSymbol)
+{
+    std::vector<RTFMathSymbol>::iterator low = std::lower_bound(m_aRTFMathControlWords.begin(), m_aRTFMathControlWords.end(), rSymbol);
+    int i = low - m_aRTFMathControlWords.begin();
+    if (low == m_aRTFMathControlWords.end() || rSymbol < *low)
+        return false;
+    rSymbol = m_aRTFMathControlWords[i];
+    return true;
+}
+
 int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam)
 {
     if (m_rImport.getDestinationState() == DESTINATION_SKIP)
diff --git a/writerfilter/source/rtftok/rtftokenizer.hxx b/writerfilter/source/rtftok/rtftokenizer.hxx
index 7eb6fdd..48414ce 100644
--- a/writerfilter/source/rtftok/rtftokenizer.hxx
+++ b/writerfilter/source/rtftok/rtftokenizer.hxx
@@ -34,6 +34,8 @@ namespace writerfilter {
                 void popGroup();
                 OUString getPosition();
                 sal_Size getGroupStart();
+                /// To look up additional properties of a math symbol.
+                static bool lookupMathKeyword(RTFMathSymbol& rSymbol);
             private:
                 SvStream& Strm();
                 int resolveKeyword();
@@ -45,6 +47,9 @@ namespace writerfilter {
                 // This is the same as aRTFControlWords, but sorted
                 static std::vector<RTFSymbol> m_aRTFControlWords;
                 static bool m_bControlWordsSorted;
+                // This is the same as aRTFMathControlWords, but sorted
+                static std::vector<RTFMathSymbol> m_aRTFMathControlWords;
+                static bool m_bMathControlWordsSorted;
                 /// Same as the size of the importer's states, except that this can be negative for invalid input.
                 int m_nGroup;
                 sal_Int32 m_nLineNumber;


More information about the Libreoffice-commits mailing list