[Libreoffice-commits] .: 5 commits - starmath/source writerfilter/qa

Miklos Vajna vmiklos at kemper.freedesktop.org
Thu Jul 26 00:44:46 PDT 2012


 starmath/source/rtfexport.cxx                      |  208 +++++++++++++++++++--
 writerfilter/qa/cppunittests/rtftok/testrtftok.cxx |   14 -
 2 files changed, 204 insertions(+), 18 deletions(-)

New commits:
commit 4f08fcb8e337f79f1282966bf726f82ddadf24a3
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Jul 25 18:20:17 2012 +0200

    export RTF_MSSU{B,P} and related keywords
    
    Change-Id: Ida24beda4d961db068279e81711e10c3d87b0ac1

diff --git a/starmath/source/rtfexport.cxx b/starmath/source/rtfexport.cxx
index 32c441a..2031fe0 100644
--- a/starmath/source/rtfexport.cxx
+++ b/starmath/source/rtfexport.cxx
@@ -86,6 +86,9 @@ void SmRtfExport::HandleNode(const SmNode* pNode, int nLevel)
         case NMATH:
             HandleMath(pNode, nLevel);
             break;
+        case NSUBSUP:
+            HandleSubSupScript(static_cast<const SmSubSupNode*>(pNode), nLevel);
+            break;
         case NEXPRESSION:
             HandleAllSubNodes(pNode, nLevel);
             break;
@@ -381,14 +384,122 @@ void SmRtfExport::HandleOperator(const SmOperNode* pNode, int nLevel)
     }
 }
 
-void SmRtfExport::HandleSubSupScript(const SmSubSupNode* /*pNode*/, int /*nLevel*/)
+void SmRtfExport::HandleSubSupScript(const SmSubSupNode* pNode, int nLevel)
 {
-    SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
+    // set flags to a bitfield of which sub/sup items exists
+    int flags = (pNode->GetSubSup(CSUB) ? (1 << CSUB) : 0)
+            | (pNode->GetSubSup(CSUP) ? (1 << CSUP) : 0)
+            | (pNode->GetSubSup(RSUB) ? (1 << RSUB) : 0)
+            | (pNode->GetSubSup(RSUP) ? (1 << RSUP) : 0)
+            | (pNode->GetSubSup(LSUB) ? (1 << LSUB) : 0)
+            | (pNode->GetSubSup(LSUP) ? (1 << LSUP) : 0);
+    HandleSubSupScriptInternal(pNode, nLevel, flags);
 }
 
-void SmRtfExport::HandleSubSupScriptInternal(const SmSubSupNode* /*pNode*/, int /*nLevel*/, int /*flags*/)
+void SmRtfExport::HandleSubSupScriptInternal(const SmSubSupNode* pNode, int nLevel, int flags)
 {
-    SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
+// rtf supports only a certain combination of sub/super scripts, but LO can have any,
+// so try to merge it using several tags if necessary
+    if (flags == 0) // none
+        return;
+    if ((flags & (1 << RSUP | 1 << RSUB)) == (1 << RSUP | 1 << RSUB))
+    { // m:sSubSup
+        m_pBuffer->append("{\\msSubSup ");
+        m_pBuffer->append("{\\me ");
+        flags &= ~(1 << RSUP | 1 << RSUB);
+        if (flags == 0)
+            HandleNode(pNode->GetBody(), nLevel + 1);
+        else
+            HandleSubSupScriptInternal(pNode, nLevel, flags);
+        m_pBuffer->append("}"); // me
+        m_pBuffer->append("{\\msub ");
+        HandleNode(pNode->GetSubSup(RSUB), nLevel + 1);
+        m_pBuffer->append("}"); // msub
+        m_pBuffer->append("{\\msup ");
+        HandleNode(pNode->GetSubSup(RSUP ), nLevel + 1);
+        m_pBuffer->append("}"); // msup
+        m_pBuffer->append("}"); // msubSup
+    }
+    else if ((flags & (1 << RSUB)) == 1 << RSUB)
+    { // m:sSub
+        m_pBuffer->append("{\\msSub ");
+        m_pBuffer->append("{\\me ");
+        flags &= ~(1 << RSUB);
+        if (flags == 0)
+            HandleNode(pNode->GetBody(), nLevel + 1);
+        else
+            HandleSubSupScriptInternal(pNode, nLevel, flags);
+        m_pBuffer->append("}"); // me
+        m_pBuffer->append("{\\msub ");
+        HandleNode(pNode->GetSubSup(RSUB), nLevel + 1);
+        m_pBuffer->append("}"); // msub
+        m_pBuffer->append("}"); // msSub
+    }
+    else if ((flags & (1 << RSUP)) == 1 << RSUP)
+    { // m:sSup
+        m_pBuffer->append("{\\msSup ");
+        m_pBuffer->append("{\\me ");
+        flags &= ~(1 << RSUP);
+        if (flags == 0)
+            HandleNode(pNode->GetBody(), nLevel + 1);
+        else
+            HandleSubSupScriptInternal(pNode, nLevel, flags);
+        m_pBuffer->append("}"); // me
+        m_pBuffer->append("{\\msup ");
+        HandleNode(pNode->GetSubSup(RSUP), nLevel + 1);
+        m_pBuffer->append("}"); // msup
+        m_pBuffer->append("}"); // msSup
+    }
+    else if ((flags & (1 << LSUP | 1 << LSUB)) == (1 << LSUP | 1 << LSUB))
+    { // m:sPre
+        m_pBuffer->append("{\\msPre ");
+        m_pBuffer->append("{\\msub ");
+        HandleNode(pNode->GetSubSup(LSUB ), nLevel + 1);
+        m_pBuffer->append("}"); // msub
+        m_pBuffer->append("{\\msup ");
+        HandleNode(pNode->GetSubSup(LSUP), nLevel + 1);
+        m_pBuffer->append("}"); // msup
+        m_pBuffer->append("{\\me ");
+        flags &= ~(1 << LSUP | 1 << LSUB);
+        if (flags == 0)
+            HandleNode(pNode->GetBody(), nLevel + 1);
+        else
+            HandleSubSupScriptInternal(pNode, nLevel, flags);
+        m_pBuffer->append("}"); // me
+        m_pBuffer->append("}"); // msPre
+    }
+    else if ((flags & (1 << CSUB)) == (1 << CSUB))
+    { // m:limLow looks like a good element for central superscript
+        m_pBuffer->append("{\\mlimLow ");
+        m_pBuffer->append("{\\me ");
+        flags &= ~(1 << CSUB);
+        if (flags == 0)
+            HandleNode(pNode->GetBody(), nLevel + 1);
+        else
+            HandleSubSupScriptInternal(pNode, nLevel, flags);
+        m_pBuffer->append("}"); // me
+        m_pBuffer->append("{\\mlim ");
+        HandleNode(pNode->GetSubSup(CSUB), nLevel + 1);
+        m_pBuffer->append("}"); // mlim
+        m_pBuffer->append("}"); // mlimLow
+    }
+    else if ((flags & (1 << CSUP)) == (1 << CSUP))
+    { // m:limUpp looks like a good element for central superscript
+        m_pBuffer->append("{\\mlimUpp ");
+        m_pBuffer->append("{\\me ");
+        flags &= ~(1 << CSUP);
+        if (flags == 0)
+            HandleNode(pNode->GetBody(), nLevel + 1);
+        else
+            HandleSubSupScriptInternal(pNode, nLevel, flags);
+        m_pBuffer->append("}"); // me
+        m_pBuffer->append("{\\mlim ");
+        HandleNode(pNode->GetSubSup(CSUP), nLevel + 1);
+        m_pBuffer->append("}"); // mlim
+        m_pBuffer->append("}"); // mlimUpp
+    }
+    else
+        SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC << " unhandled subsup type");
 }
 
 void SmRtfExport::HandleMatrix(const SmMatrixNode* pNode, int nLevel)
commit 189ad9186cb905ff9830319fd86be4e183a30be4
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Jul 25 17:48:50 2012 +0200

    export RTF_MRAD
    
    Change-Id: I1b5802dfba24b45358842189d8ae05c3f9de319f

diff --git a/starmath/source/rtfexport.cxx b/starmath/source/rtfexport.cxx
index 32b62ff..32c441a 100644
--- a/starmath/source/rtfexport.cxx
+++ b/starmath/source/rtfexport.cxx
@@ -80,6 +80,9 @@ void SmRtfExport::HandleNode(const SmNode* pNode, int nLevel)
         case NBINVER:
             HandleFractions(pNode, nLevel);
             break;
+        case NROOT:
+            HandleRoot(static_cast<const SmRootNode*>(pNode), nLevel);
+            break;
         case NMATH:
             HandleMath(pNode, nLevel);
             break;
@@ -96,6 +99,9 @@ void SmRtfExport::HandleNode(const SmNode* pNode, int nLevel)
         case NLINE:
             HandleAllSubNodes(pNode, nLevel);
             break;
+        case NPLACE:
+            // explicitly do nothing, MSOffice treats that as a placeholder if item is missing
+            break;
         default:
             SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC << " unhandled node type");
             break;
@@ -267,9 +273,26 @@ void SmRtfExport::HandleMath(const SmNode* pNode, int nLevel)
     }
 }
 
-void SmRtfExport::HandleRoot(const SmRootNode* /*pNode*/, int /*nLevel*/)
+void SmRtfExport::HandleRoot(const SmRootNode* pNode, int nLevel)
 {
-    SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
+    m_pBuffer->append("{\\mrad ");
+    if (const SmNode* argument = pNode->Argument())
+    {
+        m_pBuffer->append("{\\mdeg ");
+        HandleNode(argument, nLevel + 1);
+        m_pBuffer->append("}"); // mdeg
+    }
+    else
+    {
+        m_pBuffer->append("{\\mradPr ");
+        m_pBuffer->append("{\\mdegHide 1}");
+        m_pBuffer->append("}"); // mradPr
+        m_pBuffer->append("{\\mdeg }"); // empty but present
+    }
+    m_pBuffer->append("{\\me ");
+    HandleNode(pNode->Body(), nLevel + 1);
+    m_pBuffer->append("}"); // me
+    m_pBuffer->append("}"); // mrad
 }
 
 namespace {
commit cc22622f379a5dc59a00625cdace561e4ba14c14
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Jul 25 17:36:33 2012 +0200

    export RTF_MLIM{UPP,LOW}
    
    Change-Id: Ic47868daa3e9bd7defbc76a1ab1bfc717c48bee7

diff --git a/starmath/source/rtfexport.cxx b/starmath/source/rtfexport.cxx
index 9a0a68c..32b62ff 100644
--- a/starmath/source/rtfexport.cxx
+++ b/starmath/source/rtfexport.cxx
@@ -65,6 +65,9 @@ void SmRtfExport::HandleNode(const SmNode* pNode, int nLevel)
         case NTEXT:
             HandleText(pNode,nLevel);
             break;
+        case NVERTICAL_BRACE:
+            HandleVerticalBrace(static_cast<const SmVerticalBraceNode*>(pNode), nLevel);
+            break;
         case NBRACE:
             HandleBrace( static_cast< const SmBraceNode* >( pNode ), nLevel );
             break;
@@ -428,9 +431,44 @@ void SmRtfExport::HandleBrace(const SmBraceNode* pNode, int nLevel)
     m_pBuffer->append("}"); // md
 }
 
-void SmRtfExport::HandleVerticalBrace(const SmVerticalBraceNode* /*pNode*/, int /*nLevel*/)
+void SmRtfExport::HandleVerticalBrace(const SmVerticalBraceNode* pNode, int nLevel)
 {
-    SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
+    SAL_INFO("starmath.rtf", "Vertical: " << int(pNode->GetToken().eType));
+    switch (pNode->GetToken().eType)
+    {
+        case TOVERBRACE:
+        case TUNDERBRACE:
+        {
+            bool top = (pNode->GetToken().eType == TOVERBRACE);
+            if (top)
+                m_pBuffer->append("{\\mlimUpp ");
+            else
+                m_pBuffer->append("{\\mlimLow ");
+            m_pBuffer->append("{\\me ");
+            m_pBuffer->append("{\\mgroupChr ");
+            m_pBuffer->append("{\\mgroupChrPr ");
+            m_pBuffer->append("{\\mchr ");
+            m_pBuffer->append(mathSymbolToString(pNode->Brace()));
+            m_pBuffer->append("}"); // mchr
+            // TODO not sure if pos and vertJc are correct
+            m_pBuffer->append("{\\mpos ").append(top ? "top" : "bot").append("}");
+            m_pBuffer->append("{\\mvertJc ").append(top ? "bot" : "top").append("}");
+            m_pBuffer->append("}"); // mgroupChrPr
+            m_pBuffer->append("{\\me ");
+            HandleNode(pNode->Body(), nLevel + 1);
+            m_pBuffer->append("}"); // me
+            m_pBuffer->append("}"); // mgroupChr
+            m_pBuffer->append("}"); // me
+            m_pBuffer->append("{\\mlim ");
+            HandleNode(pNode->Script(), nLevel + 1);
+            m_pBuffer->append("}"); // mlim
+            m_pBuffer->append("}"); // mlimUpp or mlimLow
+            break;
+        }
+        default:
+            SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC << " unhandled vertical brace type");
+            break;
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit a079bacad186337feb9b7d89ac5a60deb25d02dd
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Jul 25 17:21:37 2012 +0200

    writerfilter/qa: clean up rtl:: and RTL_CONSTASCII_* usage
    
    Change-Id: I729e5a6dcc9ca3a291c5f28c8b7eed7e3ca03bfd

diff --git a/writerfilter/qa/cppunittests/rtftok/testrtftok.cxx b/writerfilter/qa/cppunittests/rtftok/testrtftok.cxx
index 986c67f..b416d78 100644
--- a/writerfilter/qa/cppunittests/rtftok/testrtftok.cxx
+++ b/writerfilter/qa/cppunittests/rtftok/testrtftok.cxx
@@ -43,7 +43,7 @@ public:
 
     virtual void setUp();
 
-    virtual bool load(const rtl::OUString &, const rtl::OUString &rURL, const rtl::OUString &);
+    virtual bool load(const OUString &, const OUString &rURL, const OUString &);
     void test();
 
     CPPUNIT_TEST_SUITE(RtfTest);
@@ -57,24 +57,22 @@ void RtfTest::setUp()
 {
     test::BootstrapFixture::setUp();
 
-    m_xFilter = uno::Reference< document::XFilter >(m_xSFactory->createInstance(
-        ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.RtfFilter"))),
-        uno::UNO_QUERY_THROW);
+    m_xFilter = uno::Reference< document::XFilter >(m_xSFactory->createInstance("com.sun.star.comp.Writer.RtfFilter"), uno::UNO_QUERY_THROW);
 }
 
-bool RtfTest::load(const rtl::OUString &, const rtl::OUString &rURL, const rtl::OUString &)
+bool RtfTest::load(const OUString &, const OUString &rURL, const OUString &)
 {
     uno::Sequence< beans::PropertyValue > aDescriptor(1);
-    aDescriptor[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL"));
+    aDescriptor[0].Name = "URL";
     aDescriptor[0].Value <<= rURL;
     return m_xFilter->filter(aDescriptor);
 }
 
 void RtfTest::test()
 {
-    testDir(rtl::OUString(),
+    testDir(OUString(),
         getURLFromSrc("/writerfilter/qa/cppunittests/rtftok/data/"),
-        rtl::OUString());
+        OUString());
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(RtfTest);
commit 3a4026843835f9f73521d4e6cf150c17d86d6ed5
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Wed Jul 25 17:14:18 2012 +0200

    export RTF_MM
    
    Change-Id: Ia3b2dd3de464d9be1fd496cc81ed903047f7542b

diff --git a/starmath/source/rtfexport.cxx b/starmath/source/rtfexport.cxx
index 493a483..9a0a68c 100644
--- a/starmath/source/rtfexport.cxx
+++ b/starmath/source/rtfexport.cxx
@@ -87,6 +87,9 @@ void SmRtfExport::HandleNode(const SmNode* pNode, int nLevel)
             //Root Node, PILE equivalent, i.e. vertical stack
             HandleTable(pNode,nLevel);
             break;
+        case NMATRIX:
+            HandleMatrix(static_cast<const SmMatrixNode*>(pNode), nLevel);
+            break;
         case NLINE:
             HandleAllSubNodes(pNode, nLevel);
             break;
@@ -362,9 +365,22 @@ void SmRtfExport::HandleSubSupScriptInternal(const SmSubSupNode* /*pNode*/, int
     SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
 }
 
-void SmRtfExport::HandleMatrix(const SmMatrixNode* /*pNode*/, int /*nLevel*/)
+void SmRtfExport::HandleMatrix(const SmMatrixNode* pNode, int nLevel)
 {
-    SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC);
+    m_pBuffer->append("{\\mm ");
+    for (int row = 0; row < pNode->GetNumRows(); ++row )
+    {
+        m_pBuffer->append("{\\mmr ");
+        for (int col = 0; col < pNode->GetNumCols(); ++col )
+        {
+            m_pBuffer->append("{\\me ");
+            if (const SmNode* node = pNode->GetSubNode(row * pNode->GetNumCols() + col))
+                HandleNode(node, nLevel + 1);
+            m_pBuffer->append("}"); // me
+        }
+        m_pBuffer->append("}"); // mmr
+    }
+    m_pBuffer->append("}"); // mm
 }
 
 void SmRtfExport::HandleBrace(const SmBraceNode* pNode, int nLevel)


More information about the Libreoffice-commits mailing list