[Libreoffice-commits] .: 16 commits - filter/inc starmath/inc starmath/Library_sm.mk starmath/source sw/source

Lubos Lunak llunak at kemper.freedesktop.org
Thu Aug 18 06:34:02 PDT 2011


 filter/inc/filter/msfilter/ooxmlexport.hxx   |   47 ++
 starmath/Library_sm.mk                       |    4 
 starmath/inc/document.hxx                    |    4 
 starmath/inc/node.hxx                        |  122 ++++++
 starmath/inc/unomodel.hxx                    |    7 
 starmath/source/document.cxx                 |   14 
 starmath/source/ooxml.cxx                    |  496 +++++++++++++++++++++++++++
 starmath/source/ooxml.hxx                    |   68 +++
 starmath/source/unomodel.cxx                 |    5 
 sw/source/filter/ww8/docxattributeoutput.cxx |   23 +
 sw/source/filter/ww8/docxattributeoutput.hxx |    2 
 11 files changed, 788 insertions(+), 4 deletions(-)

New commits:
commit 1a4c6931914f0072a2828bf6966606781384d210
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Aug 18 15:01:35 2011 +0200

    implement sub/sup support for ooxml math export

diff --git a/starmath/inc/node.hxx b/starmath/inc/node.hxx
index 93b2521..38793e7 100644
--- a/starmath/inc/node.hxx
+++ b/starmath/inc/node.hxx
@@ -964,6 +964,7 @@ public:
      * @remarks this method may return NULL.
      */
     SmNode * GetSubSup(SmSubSup eSubSup) { return GetSubNode( sal::static_int_cast< sal_uInt16 >(1 + eSubSup) ); };
+    const SmNode * GetSubSup(SmSubSup eSubSup) const { return const_cast< SmSubSupNode* >( this )->GetSubSup( eSubSup ); }
 
     /** Set the body */
     void SetBody(SmNode* pBody) { SetSubNode(0, pBody); }
diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
index 1b0480e..b7c8092 100644
--- a/starmath/source/ooxml.cxx
+++ b/starmath/source/ooxml.cxx
@@ -140,11 +140,9 @@ void SmOoxml::HandleNode( const SmNode* pNode, int nLevel )
         case NMATH:
             HandleMath(pNode,nLevel);
             break;
-#if 0
         case NSUBSUP:
-            HandleSubSupScript(pNode,nLevel);
+            HandleSubSupScript( static_cast< const SmSubSupNode* >( pNode ), nLevel );
             break;
-#endif
         case NEXPRESSION:
             HandleAllSubNodes( pNode, nLevel );
             break;
@@ -423,4 +421,76 @@ void SmOoxml::HandleRoot( const SmRootNode* pNode, int nLevel )
     m_pSerializer->endElementNS( XML_m, XML_rad );
 }
 
+void SmOoxml::HandleSubSupScript( const SmSubSupNode* pNode, int nLevel )
+{
+    // set flags to a bitfield of which sub/sup items exists
+    int flags = ( pNode->GetSubSup( CSUB ) != NULL ? ( 1 << CSUB ) : 0 )
+            | ( pNode->GetSubSup( CSUP ) != NULL ? ( 1 << CSUP ) : 0 )
+            | ( pNode->GetSubSup( RSUB ) != NULL ? ( 1 << RSUB ) : 0 )
+            | ( pNode->GetSubSup( RSUP ) != NULL ? ( 1 << RSUP ) : 0 )
+            | ( pNode->GetSubSup( LSUB ) != NULL ? ( 1 << RSUB ) : 0 )
+            | ( pNode->GetSubSup( LSUP ) != NULL ? ( 1 << LSUP ) : 0 );
+    if( flags == 0 ) // none
+        return;
+    HandleSubSupScriptInternal( pNode, nLevel, flags );
+}
+
+void SmOoxml::HandleSubSupScriptInternal( const SmSubSupNode* pNode, int nLevel, int flags )
+{
+    if( flags == ( 1 << RSUP | 1 << RSUB ))
+    { // m:sSubSup
+        m_pSerializer->startElementNS( XML_m, XML_sSubSup, FSEND );
+        m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
+        HandleNode( pNode->GetBody(), nLevel + 1 );
+        m_pSerializer->endElementNS( XML_m, XML_e );
+        m_pSerializer->startElementNS( XML_m, XML_sub, FSEND );
+        HandleNode( pNode->GetSubSup( RSUB ), nLevel + 1 );
+        m_pSerializer->endElementNS( XML_m, XML_sub );
+        m_pSerializer->startElementNS( XML_m, XML_sup, FSEND );
+        HandleNode( pNode->GetSubSup( RSUP ), nLevel + 1 );
+        m_pSerializer->endElementNS( XML_m, XML_sup );
+        m_pSerializer->endElementNS( XML_m, XML_sSubSup );
+    }
+    else if( flags == 1 << RSUB )
+    { // m:sSub
+        m_pSerializer->startElementNS( XML_m, XML_sSub, FSEND );
+        m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
+        HandleNode( pNode->GetBody(), nLevel + 1 );
+        m_pSerializer->endElementNS( XML_m, XML_e );
+        m_pSerializer->startElementNS( XML_m, XML_sub, FSEND );
+        HandleNode( pNode->GetSubSup( RSUB ), nLevel + 1 );
+        m_pSerializer->endElementNS( XML_m, XML_sub );
+        m_pSerializer->endElementNS( XML_m, XML_sSub );
+    }
+    else if( flags == 1 << RSUP )
+    { // m:sSup
+        m_pSerializer->startElementNS( XML_m, XML_sSup, FSEND );
+        m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
+        HandleNode( pNode->GetBody(), nLevel + 1 );
+        m_pSerializer->endElementNS( XML_m, XML_e );
+        m_pSerializer->startElementNS( XML_m, XML_sup, FSEND );
+        HandleNode( pNode->GetSubSup( RSUP ), nLevel + 1 );
+        m_pSerializer->endElementNS( XML_m, XML_sup );
+        m_pSerializer->endElementNS( XML_m, XML_sSup );
+    }
+    else if( flags == ( 1 << LSUP | 1 << LSUB ))
+    { // m:sPre
+        m_pSerializer->startElementNS( XML_m, XML_sPre, FSEND );
+        m_pSerializer->startElementNS( XML_m, XML_sub, FSEND );
+        HandleNode( pNode->GetSubSup( LSUB ), nLevel + 1 );
+        m_pSerializer->endElementNS( XML_m, XML_sub );
+        m_pSerializer->startElementNS( XML_m, XML_sup, FSEND );
+        HandleNode( pNode->GetSubSup( LSUP ), nLevel + 1 );
+        m_pSerializer->endElementNS( XML_m, XML_sup );
+        m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
+        HandleNode( pNode->GetBody(), nLevel + 1 );
+        m_pSerializer->endElementNS( XML_m, XML_e );
+        m_pSerializer->endElementNS( XML_m, XML_sSubSup );
+    }
+    else
+    {
+        OSL_FAIL( "Unhandled sub/sup combination" );
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/ooxml.hxx b/starmath/source/ooxml.hxx
index c0679d2..7246a8c 100644
--- a/starmath/source/ooxml.hxx
+++ b/starmath/source/ooxml.hxx
@@ -54,6 +54,8 @@ private:
     void HandleBinaryOperation( const SmBinHorNode* pNode, int nLevel );
     void HandleRoot( const SmRootNode* pNode,int nLevel );
     void HandleAttribute( const SmAttributNode* pNode,int nLevel );
+    void HandleSubSupScript( const SmSubSupNode* pNode, int nLevel );
+    void HandleSubSupScriptInternal( const SmSubSupNode* pNode, int nLevel, int flags );
     String str;
     const SmNode* const pTree;
     ::sax_fastparser::FSHelperPtr m_pSerializer;
commit efb9c9000071b9ab2f1757caf810ad43ee259e1d
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Wed Aug 17 17:35:35 2011 +0200

    handle some attributes for ooxml math export

diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
index 998b1bd..1b0480e 100644
--- a/starmath/source/ooxml.cxx
+++ b/starmath/source/ooxml.cxx
@@ -95,11 +95,9 @@ void SmOoxml::HandleNode( const SmNode* pNode, int nLevel )
     fprintf(stderr,"XX %d %d %d\n", nLevel, pNode->GetType(), pNode->GetNumSubNodes());
     switch(pNode->GetType())
     {
-#if 0
         case NATTRIBUT:
-            HandleAttributes(pNode,nLevel);
+            HandleAttribute( static_cast< const SmAttributNode* >( pNode ), nLevel );
             break;
-#endif
         case NTEXT:
             HandleText(pNode,nLevel);
             break;
@@ -114,8 +112,11 @@ void SmOoxml::HandleNode( const SmNode* pNode, int nLevel )
             HandleOperator(pNode,nLevel);
             break;
 #endif
+        case NUNHOR:
+            HandleUnaryOperation( static_cast< const SmUnHorNode* >( pNode ), nLevel );
+            break;
         case NBINHOR:
-            HandleBinaryOperation(pNode,nLevel);
+            HandleBinaryOperation( static_cast< const SmBinHorNode* >( pNode ), nLevel );
             break;
         case NBINVER:
             HandleFractions(pNode,nLevel);
@@ -311,121 +312,6 @@ void SmOoxml::HandleText( const SmNode* pNode, int /*nLevel*/)
     m_pSerializer->endElementNS( XML_m, XML_r );
 }
 
-void SmOoxml::HandleMath( const SmNode* pNode,int nLevel )
-{
-    fprintf(stderr,"MATH %d\n", pNode->GetToken().eType);
-    // these are handled elsewhere, e.g. when handling BINHOR
-    OSL_ASSERT( pNode->GetToken().eType != TDIVIDEBY );
-    HandleText( pNode, nLevel );
-// TODO at least some items (e.g. y/2 need to handled as ooxml and not as plain text symbols)
-#if 0
-    if (pNode->GetToken().eType == TMLINE)
-    {
-        *pS << sal_uInt8(END);
-        *pS << sal_uInt8(LINE);
-        bIsReInterpBrace=1;
-        return;
-    }
-    SmMathSymbolNode* pTemp=(SmMathSymbolNode* )pNode;
-    for(xub_StrLen i=0;i<pTemp->GetText().Len();i++)
-    {
-        sal_Unicode nArse = Convert(pTemp->GetText().GetChar(i));
-        if ((nArse == 0x2224) || (nArse == 0x2288) || (nArse == 0x2285) ||
-            (nArse == 0x2289))
-        {
-            *pS << sal_uInt8(CHAR|0x20);
-        }
-        else if ((nPendingAttributes) &&
-                (i == ((pTemp->GetText().Len()+1)/2)-1))
-            {
-                *pS << sal_uInt8(0x22);
-            }
-        else
-            *pS << sal_uInt8(CHAR); //char without formula recognition
-        //The typeface seems to be MTEXTRA for unicode characters,
-        //though how to determine when mathtype chooses one over
-        //the other is unknown. This should do the trick
-        //nevertheless.
-        sal_uInt8 nBias;
-        if ( (nArse == 0x2213) || (nArse == 0x2218) ||
-            (nArse == 0x210F) || (
-                (nArse >= 0x22EE) && (nArse <= 0x22FF)
-            ))
-        {
-            nBias = 0xB; //typeface
-        }
-        else if ((nArse > 0x2000) || (nArse == 0x00D7))
-            nBias = 0x6; //typeface
-        else if (nArse == 0x3d1)
-            nBias = 0x4;
-        else if ((nArse > 0xFF) && ((nArse < 0x393) || (nArse > 0x3c9)))
-            nBias = 0xB; //typeface
-        else if ((nArse == 0x2F) || (nArse == 0x2225))
-            nBias = 0x2; //typeface
-        else
-            nBias = 0x3; //typeface
-
-        *pS << sal_uInt8(nSpec+nBias+128); //typeface
-
-        if (nArse == 0x2224)
-        {
-            *pS << sal_uInt16(0x7C);
-            *pS << sal_uInt8(EMBEL);
-            *pS << sal_uInt8(0x0A);
-            *pS << sal_uInt8(END); //end embel
-            *pS << sal_uInt8(END); //end embel
-        }
-        else if (nArse == 0x2225)
-            *pS << sal_uInt16(0xEC09);
-        else if (nArse == 0xE421)
-            *pS << sal_uInt16(0x2265);
-        else if (nArse == 0x230A)
-            *pS << sal_uInt16(0xF8F0);
-        else if (nArse == 0x230B)
-            *pS << sal_uInt16(0xF8FB);
-        else if (nArse == 0xE425)
-            *pS << sal_uInt16(0x2264);
-        else if (nArse == 0x226A)
-        {
-            *pS << sal_uInt16(0x3C);
-            *pS << sal_uInt8(CHAR);
-            *pS << sal_uInt8(0x98);
-            *pS << sal_uInt16(0xEB01);
-            *pS << sal_uInt8(CHAR);
-            *pS << sal_uInt8(0x86);
-            *pS << sal_uInt16(0x3c);
-        }
-        else if (nArse == 0x2288)
-        {
-            *pS << sal_uInt16(0x2286);
-            *pS << sal_uInt8(EMBEL);
-            *pS << sal_uInt8(0x0A);
-            *pS << sal_uInt8(END); //end embel
-            *pS << sal_uInt8(END); //end embel
-        }
-        else if (nArse == 0x2289)
-        {
-            *pS << sal_uInt16(0x2287);
-            *pS << sal_uInt8(EMBEL);
-            *pS << sal_uInt8(0x0A);
-            *pS << sal_uInt8(END); //end embel
-            *pS << sal_uInt8(END); //end embel
-        }
-        else if (nArse == 0x2285)
-        {
-            *pS << sal_uInt16(0x2283);
-            *pS << sal_uInt8(EMBEL);
-            *pS << sal_uInt8(0x0A);
-            *pS << sal_uInt8(END); //end embel
-            *pS << sal_uInt8(END); //end embel
-        }
-        else
-            *pS << nArse;
-    }
-    nPendingAttributes = 0;
-#endif
-}
-
 void SmOoxml::HandleFractions( const SmNode* pNode, int nLevel, const char* type )
 {
     m_pSerializer->startElementNS( XML_m, XML_f, FSEND );
@@ -445,10 +331,23 @@ void SmOoxml::HandleFractions( const SmNode* pNode, int nLevel, const char* type
     m_pSerializer->endElementNS( XML_m, XML_f );
 }
 
-void SmOoxml::HandleBinaryOperation( const SmNode* pNode, int nLevel )
+void SmOoxml::HandleUnaryOperation( const SmUnHorNode* pNode, int nLevel )
 {
-    // update OSL_ASSERT in HandleMath() when adding new items
-    switch( pNode->GetToken().eType )
+    // update HandleMath() when adding new items
+    fprintf(stderr,"UNARY %d\n", pNode->Symbol()->GetToken().eType );
+    switch( pNode->Symbol()->GetToken().eType )
+    {
+        default:
+            HandleAllSubNodes( pNode, nLevel );
+            break;
+    }
+}
+
+void SmOoxml::HandleBinaryOperation( const SmBinHorNode* pNode, int nLevel )
+{
+    fprintf(stderr,"BINARY %d\n", pNode->Symbol()->GetToken().eType );
+    // update HandleMath() when adding new items
+    switch( pNode->Symbol()->GetToken().eType )
     {
         case TDIVIDEBY:
             return HandleFractions( pNode, nLevel, "lin" );
@@ -458,13 +357,57 @@ void SmOoxml::HandleBinaryOperation( const SmNode* pNode, int nLevel )
     }
 }
 
+void SmOoxml::HandleAttribute( const SmAttributNode* pNode, int nLevel )
+{
+    switch( pNode->Attribute()->GetToken().eType )
+    {
+        case TCHECK: // TODO check these all are really accents
+        case TACUTE:
+        case TGRAVE:
+        case TCIRCLE:
+        case TWIDETILDE:
+        case TWIDEHAT:
+        {
+            m_pSerializer->startElementNS( XML_m, XML_acc, FSEND );
+            m_pSerializer->startElementNS( XML_m, XML_accPr, FSEND );
+            rtl::OString value = rtl::OUStringToOString(
+                rtl::OUString( pNode->Attribute()->GetToken().cMathChar ), RTL_TEXTENCODING_UTF8 );
+            m_pSerializer->singleElementNS( XML_m, XML_chr, FSNS( XML_m, XML_val ), value.getStr(), FSEND );
+            m_pSerializer->endElementNS( XML_m, XML_accPr );
+            m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
+            HandleNode( pNode->Body(), nLevel + 1 );
+            m_pSerializer->endElementNS( XML_m, XML_e );
+            m_pSerializer->endElementNS( XML_m, XML_acc );
+            break;
+        }
+        default:
+            HandleAllSubNodes( pNode, nLevel );
+            break;
+    }
+}
+
+void SmOoxml::HandleMath( const SmNode* pNode, int nLevel )
+{
+    fprintf(stderr,"MATH %d\n", pNode->GetToken().eType);
+    switch( pNode->GetToken().eType )
+    {
+        case TDIVIDEBY:
+        case TACUTE:
+        // these are handled elsewhere, e.g. when handling BINHOR
+            OSL_ASSERT( false );
+        default:
+            HandleText( pNode, nLevel );
+            break;
+    }
+}
+
 void SmOoxml::HandleRoot( const SmRootNode* pNode, int nLevel )
 {
     m_pSerializer->startElementNS( XML_m, XML_rad, FSEND );
     if( const SmNode* argument = pNode->Argument())
     {
         m_pSerializer->startElementNS( XML_m, XML_deg, FSEND );
-        HandleAllSubNodes( argument, nLevel );
+        HandleNode( argument, nLevel + 1 );
         m_pSerializer->endElementNS( XML_m, XML_deg );
     }
     else
@@ -475,7 +418,7 @@ void SmOoxml::HandleRoot( const SmRootNode* pNode, int nLevel )
         m_pSerializer->singleElementNS( XML_m, XML_deg, FSEND ); // empty but present
     }
     m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
-    HandleAllSubNodes( pNode->Body(), nLevel );
+    HandleNode( pNode->Body(), nLevel + 1 );
     m_pSerializer->endElementNS( XML_m, XML_e );
     m_pSerializer->endElementNS( XML_m, XML_rad );
 }
diff --git a/starmath/source/ooxml.hxx b/starmath/source/ooxml.hxx
index 083c51c..c0679d2 100644
--- a/starmath/source/ooxml.hxx
+++ b/starmath/source/ooxml.hxx
@@ -50,8 +50,10 @@ private:
     void HandleText( const SmNode* pNode, int nLevel );
     void HandleMath( const SmNode* pNode, int nLevel );
     void HandleFractions( const SmNode* pNode, int nLevel, const char* type = NULL );
-    void HandleBinaryOperation( const SmNode* pNode, int nLevel );
+    void HandleUnaryOperation( const SmUnHorNode* pNode, int nLevel );
+    void HandleBinaryOperation( const SmBinHorNode* pNode, int nLevel );
     void HandleRoot( const SmRootNode* pNode,int nLevel );
+    void HandleAttribute( const SmAttributNode* pNode,int nLevel );
     String str;
     const SmNode* const pTree;
     ::sax_fastparser::FSHelperPtr m_pSerializer;
commit 7f4ccc474c8606b58bcbdb888b81a2f0e9aea2aa
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Wed Aug 17 17:34:21 2011 +0200

    add more accessors to Sm*Node classes

diff --git a/starmath/inc/node.hxx b/starmath/inc/node.hxx
index 6098322..93b2521 100644
--- a/starmath/inc/node.hxx
+++ b/starmath/inc/node.hxx
@@ -750,6 +750,11 @@ public:
 
     virtual void Arrange(const OutputDevice &rDev, const SmFormat &rFormat);
     void Accept(SmVisitor* pVisitor);
+
+    SmMathSymbolNode* Symbol();
+    const SmMathSymbolNode* Symbol() const;
+    SmNode* Operand();
+    const SmNode* Operand() const;
 };
 
 
@@ -817,6 +822,13 @@ public:
 
     virtual void Arrange(const OutputDevice &rDev, const SmFormat &rFormat);
     void Accept(SmVisitor* pVisitor);
+
+    SmMathSymbolNode* Symbol();
+    const SmMathSymbolNode* Symbol() const;
+    SmNode* LeftOperand();
+    const SmNode* LeftOperand() const;
+    SmNode* RightOperand();
+    const SmNode* RightOperand() const;
 };
 
 
@@ -1133,6 +1145,11 @@ public:
     virtual void Arrange(const OutputDevice &rDev, const SmFormat &rFormat);
     void CreateTextFromNode(String &rText);
     void Accept(SmVisitor* pVisitor);
+
+    SmNode* Attribute();
+    const SmNode* Attribute() const;
+    SmNode* Body();
+    const SmNode* Body() const;
 };
 
 
@@ -1240,7 +1257,7 @@ inline const SmNode* SmRootNode::Argument() const
 }
 inline SmRootSymbolNode* SmRootNode::Symbol()
 {
-    OSL_ASSERT( GetSubNode( 0 )->GetType() == NROOTSYMBOL );
+    OSL_ASSERT( GetNumSubNodes() > 1 && GetSubNode( 1 )->GetType() == NROOTSYMBOL );
     return static_cast< SmRootSymbolNode* >( GetSubNode( 1 ));
 }
 inline const SmRootSymbolNode* SmRootNode::Symbol() const
@@ -1257,6 +1274,71 @@ inline const SmNode* SmRootNode::Body() const
     return const_cast< SmRootNode* >( this )->Body();
 }
 
+inline SmMathSymbolNode* SmUnHorNode::Symbol()
+{
+    OSL_ASSERT( GetNumSubNodes() > 0 && GetSubNode( 0 )->GetType() == NMATH );
+    return static_cast< SmMathSymbolNode* >( GetSubNode( 0 ));
+}
+inline const SmMathSymbolNode* SmUnHorNode::Symbol() const
+{
+    return const_cast< SmUnHorNode* >( this )->Symbol();
+}
+inline SmNode* SmUnHorNode::Operand()
+{
+    OSL_ASSERT( GetNumSubNodes() > 1 );
+    return GetSubNode( 1 );
+}
+inline const SmNode* SmUnHorNode::Operand() const
+{
+    return const_cast< SmUnHorNode* >( this )->Operand();
+}
+
+inline SmMathSymbolNode* SmBinHorNode::Symbol()
+{
+    OSL_ASSERT( GetNumSubNodes() > 1 && GetSubNode( 1 )->GetType() == NMATH );
+    return static_cast< SmMathSymbolNode* >( GetSubNode( 1 ));
+}
+inline const SmMathSymbolNode* SmBinHorNode::Symbol() const
+{
+    return const_cast< SmBinHorNode* >( this )->Symbol();
+}
+inline SmNode* SmBinHorNode::LeftOperand()
+{
+    OSL_ASSERT( GetNumSubNodes() > 0 );
+    return GetSubNode( 0 );
+}
+inline const SmNode* SmBinHorNode::LeftOperand() const
+{
+    return const_cast< SmBinHorNode* >( this )->LeftOperand();
+}
+inline SmNode* SmBinHorNode::RightOperand()
+{
+    OSL_ASSERT( GetNumSubNodes() > 2 );
+    return GetSubNode( 2 );
+}
+inline const SmNode* SmBinHorNode::RightOperand() const
+{
+    return const_cast< SmBinHorNode* >( this )->RightOperand();
+}
+
+inline SmNode* SmAttributNode::Attribute()
+{
+    OSL_ASSERT( GetNumSubNodes() > 0 );
+    return GetSubNode( 0 );
+}
+inline const SmNode* SmAttributNode::Attribute() const
+{
+    return const_cast< SmAttributNode* >( this )->Attribute();
+}
+inline SmNode* SmAttributNode::Body()
+{
+    OSL_ASSERT( GetNumSubNodes() > 1 );
+    return GetSubNode( 1 );
+}
+inline const SmNode* SmAttributNode::Body() const
+{
+    return const_cast< SmAttributNode* >( this )->Body();
+}
 
 #endif
 
commit b9aa0c02d998c412431784acd99f30a38c71d43e
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Wed Aug 17 16:03:03 2011 +0200

    const

diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
index b5cb6c8..998b1bd 100644
--- a/starmath/source/ooxml.cxx
+++ b/starmath/source/ooxml.cxx
@@ -71,7 +71,7 @@ static sal_Unicode Convert(sal_Unicode nIn)
     return nIn;
 }
 
-SmOoxml::SmOoxml(String &rIn,SmNode *pIn,OoxmlVersion v)
+SmOoxml::SmOoxml( const String &rIn, const SmNode* pIn, OoxmlVersion v )
 : str( rIn )
 , pTree( pIn )
 , version( v )
@@ -90,7 +90,7 @@ bool SmOoxml::ConvertFromStarMath( ::sax_fastparser::FSHelperPtr serializer )
     return true;
 }
 
-void SmOoxml::HandleNode(SmNode *pNode,int nLevel)
+void SmOoxml::HandleNode( const SmNode* pNode, int nLevel )
 {
     fprintf(stderr,"XX %d %d %d\n", nLevel, pNode->GetType(), pNode->GetNumSubNodes());
     switch(pNode->GetType())
@@ -121,12 +121,12 @@ void SmOoxml::HandleNode(SmNode *pNode,int nLevel)
             HandleFractions(pNode,nLevel);
             break;
         case NROOT:
-            HandleRoot( static_cast< SmRootNode* >( pNode ),nLevel);
+            HandleRoot( static_cast< const SmRootNode* >( pNode ), nLevel );
             break;
 #if 0
         case NSPECIAL:
             {
-            SmTextNode *pText=(SmTextNode *)pNode;
+            const SmTextNode* pText= static_cast< const SmTextNode* >( pNode );
             //if the token str and the result text are the same then this
             //is to be seen as text, else assume its a mathchar
             if (pText->GetText() == pText->GetToken().aText)
@@ -153,7 +153,7 @@ void SmOoxml::HandleNode(SmNode *pNode,int nLevel)
             break;
 #if 0
         case NMATRIX:
-            HandleSmMatrix((SmMatrixNode *)pNode,nLevel);
+            HandleSmMatrix( static_cast< const SmMatrixNode* >( pNode ), nLevel );
             break;
 #endif
         case NLINE:
@@ -185,7 +185,7 @@ void SmOoxml::HandleNode(SmNode *pNode,int nLevel)
 }
 
 //Root Node, PILE equivalent, i.e. vertical stack
-void SmOoxml::HandleTable(SmNode *pNode,int nLevel)
+void SmOoxml::HandleTable( const SmNode* pNode, int nLevel )
 {
     //The root of the starmath is a table, if
     //we convert this them each iteration of
@@ -199,7 +199,7 @@ void SmOoxml::HandleTable(SmNode *pNode,int nLevel)
         HandleAllSubNodes( pNode, nLevel );
 }
 
-void SmOoxml::HandleAllSubNodes( SmNode* pNode, int nLevel )
+void SmOoxml::HandleAllSubNodes( const SmNode* pNode, int nLevel )
 {
     int size = pNode->GetNumSubNodes();
     for( int i = 0;
@@ -219,7 +219,7 @@ void SmOoxml::HandleAllSubNodes( SmNode* pNode, int nLevel )
 // output vertical stack, firstItem says which child to use as first (if there
 // are more than two children, OOXML can have only a vertical stack of two items,
 // so create a bigger vertical stack recursively)
-void SmOoxml::HandleVerticalStack( SmNode* pNode, int nLevel, int firstItem )
+void SmOoxml::HandleVerticalStack( const SmNode* pNode, int nLevel, int firstItem )
 {
     if( firstItem == pNode->GetNumSubNodes() - 1 ) // only one item, just output the item
     {
@@ -241,7 +241,7 @@ void SmOoxml::HandleVerticalStack( SmNode* pNode, int nLevel, int firstItem )
     m_pSerializer->endElementNS( XML_m, XML_f );
 }
 
-void SmOoxml::HandleText(SmNode *pNode, int /*nLevel*/)
+void SmOoxml::HandleText( const SmNode* pNode, int /*nLevel*/)
 {
     m_pSerializer->startElementNS( XML_m, XML_r, FSEND );
 
@@ -253,7 +253,7 @@ void SmOoxml::HandleText(SmNode *pNode, int /*nLevel*/)
         m_pSerializer->endElementNS( XML_w, XML_rPr );
     }
     m_pSerializer->startElementNS( XML_m, XML_t, FSEND );
-    SmTextNode *pTemp=(SmTextNode *)pNode;
+    SmTextNode* pTemp=(SmTextNode* )pNode;
     fprintf(stderr, "T %s\n", rtl::OUStringToOString( pTemp->GetText(), RTL_TEXTENCODING_UTF8 ).getStr());
     for(xub_StrLen i=0;i<pTemp->GetText().Len();i++)
     {
@@ -311,7 +311,7 @@ void SmOoxml::HandleText(SmNode *pNode, int /*nLevel*/)
     m_pSerializer->endElementNS( XML_m, XML_r );
 }
 
-void SmOoxml::HandleMath(SmNode *pNode,int nLevel)
+void SmOoxml::HandleMath( const SmNode* pNode,int nLevel )
 {
     fprintf(stderr,"MATH %d\n", pNode->GetToken().eType);
     // these are handled elsewhere, e.g. when handling BINHOR
@@ -326,7 +326,7 @@ void SmOoxml::HandleMath(SmNode *pNode,int nLevel)
         bIsReInterpBrace=1;
         return;
     }
-    SmMathSymbolNode *pTemp=(SmMathSymbolNode *)pNode;
+    SmMathSymbolNode* pTemp=(SmMathSymbolNode* )pNode;
     for(xub_StrLen i=0;i<pTemp->GetText().Len();i++)
     {
         sal_Unicode nArse = Convert(pTemp->GetText().GetChar(i));
@@ -426,7 +426,7 @@ void SmOoxml::HandleMath(SmNode *pNode,int nLevel)
 #endif
 }
 
-void SmOoxml::HandleFractions(SmNode *pNode,int nLevel, const char* type)
+void SmOoxml::HandleFractions( const SmNode* pNode, int nLevel, const char* type )
 {
     m_pSerializer->startElementNS( XML_m, XML_f, FSEND );
     if( type != NULL )
@@ -445,7 +445,7 @@ void SmOoxml::HandleFractions(SmNode *pNode,int nLevel, const char* type)
     m_pSerializer->endElementNS( XML_m, XML_f );
 }
 
-void SmOoxml::HandleBinaryOperation(SmNode *pNode,int nLevel)
+void SmOoxml::HandleBinaryOperation( const SmNode* pNode, int nLevel )
 {
     // update OSL_ASSERT in HandleMath() when adding new items
     switch( pNode->GetToken().eType )
@@ -458,10 +458,10 @@ void SmOoxml::HandleBinaryOperation(SmNode *pNode,int nLevel)
     }
 }
 
-void SmOoxml::HandleRoot(SmRootNode *pNode,int nLevel)
+void SmOoxml::HandleRoot( const SmRootNode* pNode, int nLevel )
 {
     m_pSerializer->startElementNS( XML_m, XML_rad, FSEND );
-    if( SmNode* argument = pNode->Argument())
+    if( const SmNode* argument = pNode->Argument())
     {
         m_pSerializer->startElementNS( XML_m, XML_deg, FSEND );
         HandleAllSubNodes( argument, nLevel );
diff --git a/starmath/source/ooxml.hxx b/starmath/source/ooxml.hxx
index d6a9876..083c51c 100644
--- a/starmath/source/ooxml.hxx
+++ b/starmath/source/ooxml.hxx
@@ -40,20 +40,20 @@
 class SmOoxml
 {
 public:
-    SmOoxml(String &rIn,SmNode *pIn, oox::core::OoxmlVersion version);
+    SmOoxml( const String &rIn,const SmNode* pIn, oox::core::OoxmlVersion version );
     bool ConvertFromStarMath( ::sax_fastparser::FSHelperPtr m_pSerializer );
 private:
-    void HandleNode(SmNode *pNode,int nLevel);
-    void HandleAllSubNodes(SmNode *pNode,int nLevel);
-    void HandleTable(SmNode *pNode,int nLevel);
-    void HandleVerticalStack( SmNode* pNode, int nLevel, int firstItem );
-    void HandleText(SmNode *pNode,int nLevel);
-    void HandleMath(SmNode *pNode,int nLevel);
-    void HandleFractions( SmNode *pNode,int nLevel, const char* type = NULL );
-    void HandleBinaryOperation(SmNode *pNode,int nLevel);
-    void HandleRoot(SmRootNode *pNode,int nLevel);
+    void HandleNode( const SmNode* pNode, int nLevel );
+    void HandleAllSubNodes( const SmNode* pNode, int nLevel );
+    void HandleTable( const SmNode* pNode, int nLevel );
+    void HandleVerticalStack( const SmNode* pNode, int nLevel, int firstItem );
+    void HandleText( const SmNode* pNode, int nLevel );
+    void HandleMath( const SmNode* pNode, int nLevel );
+    void HandleFractions( const SmNode* pNode, int nLevel, const char* type = NULL );
+    void HandleBinaryOperation( const SmNode* pNode, int nLevel );
+    void HandleRoot( const SmRootNode* pNode,int nLevel );
     String str;
-    SmNode *pTree;
+    const SmNode* const pTree;
     ::sax_fastparser::FSHelperPtr m_pSerializer;
     oox::core::OoxmlVersion version;
 };
commit 4ded3c11bb25368f92aaee623d3e8ca004719d9d
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Wed Aug 17 15:56:07 2011 +0200

    implement root support for ooxml math export

diff --git a/starmath/inc/node.hxx b/starmath/inc/node.hxx
index 202cf2e..6098322 100644
--- a/starmath/inc/node.hxx
+++ b/starmath/inc/node.hxx
@@ -764,7 +764,7 @@ public:
  * 0: Argument (optional)<BR>
  * 1: Symbol (instance of SmRootSymbolNode)<BR>
  * 2: Body<BR>
- * Where argument is optinal and may be NULL.
+ * Where argument is optional and may be NULL.
  */
 class SmRootNode : public SmStructureNode
 {
@@ -783,6 +783,13 @@ public:
     virtual void Arrange(const OutputDevice &rDev, const SmFormat &rFormat);
     void CreateTextFromNode(String &rText);
     void Accept(SmVisitor* pVisitor);
+
+    SmNode* Argument();
+    const SmNode* Argument() const;
+    SmRootSymbolNode* Symbol();
+    const SmRootSymbolNode* Symbol() const;
+    SmNode* Body();
+    const SmNode* Body() const;
 };
 
 
@@ -1221,6 +1228,36 @@ public:
 
 ////////////////////////////////////////////////////////////////////////////////
 
+
+inline SmNode* SmRootNode::Argument()
+{
+    OSL_ASSERT( GetNumSubNodes() > 0 );
+    return GetSubNode( 0 );
+}
+inline const SmNode* SmRootNode::Argument() const
+{
+    return const_cast< SmRootNode* >( this )->Argument();
+}
+inline SmRootSymbolNode* SmRootNode::Symbol()
+{
+    OSL_ASSERT( GetSubNode( 0 )->GetType() == NROOTSYMBOL );
+    return static_cast< SmRootSymbolNode* >( GetSubNode( 1 ));
+}
+inline const SmRootSymbolNode* SmRootNode::Symbol() const
+{
+    return const_cast< SmRootNode* >( this )->Symbol();
+}
+inline SmNode* SmRootNode::Body()
+{
+    OSL_ASSERT( GetNumSubNodes() > 2 );
+    return GetSubNode( 2 );
+}
+inline const SmNode* SmRootNode::Body() const
+{
+    return const_cast< SmRootNode* >( this )->Body();
+}
+
+
 #endif
 
 
diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
index ae5d2f2..b5cb6c8 100644
--- a/starmath/source/ooxml.cxx
+++ b/starmath/source/ooxml.cxx
@@ -120,10 +120,10 @@ void SmOoxml::HandleNode(SmNode *pNode,int nLevel)
         case NBINVER:
             HandleFractions(pNode,nLevel);
             break;
-#if 0
         case NROOT:
-            HandleRoot(pNode,nLevel);
+            HandleRoot( static_cast< SmRootNode* >( pNode ),nLevel);
             break;
+#if 0
         case NSPECIAL:
             {
             SmTextNode *pText=(SmTextNode *)pNode;
@@ -458,4 +458,26 @@ void SmOoxml::HandleBinaryOperation(SmNode *pNode,int nLevel)
     }
 }
 
+void SmOoxml::HandleRoot(SmRootNode *pNode,int nLevel)
+{
+    m_pSerializer->startElementNS( XML_m, XML_rad, FSEND );
+    if( SmNode* argument = pNode->Argument())
+    {
+        m_pSerializer->startElementNS( XML_m, XML_deg, FSEND );
+        HandleAllSubNodes( argument, nLevel );
+        m_pSerializer->endElementNS( XML_m, XML_deg );
+    }
+    else
+    {
+        m_pSerializer->startElementNS( XML_m, XML_radPr, FSEND );
+        m_pSerializer->singleElementNS( XML_m, XML_degHide, FSNS( XML_m, XML_val ), "1", FSEND );
+        m_pSerializer->endElementNS( XML_m, XML_radPr );
+        m_pSerializer->singleElementNS( XML_m, XML_deg, FSEND ); // empty but present
+    }
+    m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
+    HandleAllSubNodes( pNode->Body(), nLevel );
+    m_pSerializer->endElementNS( XML_m, XML_e );
+    m_pSerializer->endElementNS( XML_m, XML_rad );
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/ooxml.hxx b/starmath/source/ooxml.hxx
index 5b9aaff..d6a9876 100644
--- a/starmath/source/ooxml.hxx
+++ b/starmath/source/ooxml.hxx
@@ -51,6 +51,7 @@ private:
     void HandleMath(SmNode *pNode,int nLevel);
     void HandleFractions( SmNode *pNode,int nLevel, const char* type = NULL );
     void HandleBinaryOperation(SmNode *pNode,int nLevel);
+    void HandleRoot(SmRootNode *pNode,int nLevel);
     String str;
     SmNode *pTree;
     ::sax_fastparser::FSHelperPtr m_pSerializer;
commit c070a4d86a43984152ce44ff1d39a21ee5f9818f
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Wed Aug 17 15:13:35 2011 +0200

    certain SmNode children actually can be NULL
    
    but such (optional) sub-nodes should be handled explicitly when
    handling the node (e.g. optional subscript)

diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
index df1b717..ae5d2f2 100644
--- a/starmath/source/ooxml.cxx
+++ b/starmath/source/ooxml.cxx
@@ -205,7 +205,15 @@ void SmOoxml::HandleAllSubNodes( SmNode* pNode, int nLevel )
     for( int i = 0;
          i < size;
          ++i )
+    {
+// TODO remove when all types of nodes are handled properly
+        if( pNode->GetSubNode( i ) == NULL )
+        {
+            OSL_FAIL( "Subnode is NULL, parent node not handled properly" );
+            continue;
+        }
         HandleNode( pNode->GetSubNode( i ), nLevel + 1 );
+    }
 }
 
 // output vertical stack, firstItem says which child to use as first (if there
commit 283fba09952bcbca74f879ad94371c09ff92907a
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Wed Aug 17 14:43:18 2011 +0200

    explicitly do nothing about formula placeholders for ooxml export

diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
index 84f6574..df1b717 100644
--- a/starmath/source/ooxml.cxx
+++ b/starmath/source/ooxml.cxx
@@ -166,6 +166,9 @@ void SmOoxml::HandleNode(SmNode *pNode,int nLevel)
         case NALIGN:
             HandleMAlign(pNode,nLevel);
             break;
+        case NPLACE:
+            // explicitly do nothing, MSOffice treats that as a placeholder if item is missing
+            break;
         case NBLANK:
             *pS << sal_uInt8(CHAR);
             *pS << sal_uInt8(0x98);
commit a169d1cec171977fa446622ac1c3beb28d32fd05
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Wed Aug 17 14:41:15 2011 +0200

    cleanups for ooxml math export
    
    HandleNodes() -> HandleNode(), as it just handle the one node
     (and children recursively)
    add HandleAllSubNodes() to handle all children of a node
    there seem to be no point in checking GetSubNode() for NULL, as it
     seems it can't be so

diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
index 740a50c..84f6574 100644
--- a/starmath/source/ooxml.cxx
+++ b/starmath/source/ooxml.cxx
@@ -85,12 +85,12 @@ bool SmOoxml::ConvertFromStarMath( ::sax_fastparser::FSHelperPtr serializer )
     m_pSerializer = serializer;
     m_pSerializer->startElementNS( XML_m, XML_oMath,
         FSNS( XML_xmlns, XML_m ), "http://schemas.openxmlformats.org/officeDocument/2006/math", FSEND );
-    HandleNodes( pTree, 0 );
+    HandleNode( pTree, 0 );
     m_pSerializer->endElementNS( XML_m, XML_oMath );
     return true;
 }
 
-void SmOoxml::HandleNodes(SmNode *pNode,int nLevel)
+void SmOoxml::HandleNode(SmNode *pNode,int nLevel)
 {
     fprintf(stderr,"XX %d %d %d\n", nLevel, pNode->GetType(), pNode->GetNumSubNodes());
     switch(pNode->GetType())
@@ -145,12 +145,7 @@ void SmOoxml::HandleNodes(SmNode *pNode,int nLevel)
             break;
 #endif
         case NEXPRESSION:
-            {
-            sal_uInt16  nSize = pNode->GetNumSubNodes();
-            for (sal_uInt16 i = 0; i < nSize; i++)
-                if (SmNode *pTemp = pNode->GetSubNode(i))
-                    HandleNodes(pTemp,nLevel+1);
-            }
+            HandleAllSubNodes( pNode, nLevel );
             break;
         case NTABLE:
             //Root Node, PILE equivalent, i.e. vertical stack
@@ -164,12 +159,7 @@ void SmOoxml::HandleNodes(SmNode *pNode,int nLevel)
         case NLINE:
             {
 // TODO
-//            *pS << sal_uInt8(LINE);
-            sal_uInt16  nSize = pNode->GetNumSubNodes();
-            for (sal_uInt16 i = 0; i < nSize; i++)
-                if (SmNode *pTemp = pNode->GetSubNode(i))
-                    HandleNodes(pTemp,nLevel+1);
-//            *pS << sal_uInt8(END);
+            HandleAllSubNodes( pNode, nLevel );
             }
             break;
 #if 0
@@ -186,12 +176,7 @@ void SmOoxml::HandleNodes(SmNode *pNode,int nLevel)
             break;
 #endif
         default:
-            {
-            sal_uInt16  nSize = pNode->GetNumSubNodes();
-            for (sal_uInt16 i = 0; i < nSize; i++)
-                if (SmNode *pTemp = pNode->GetSubNode(i))
-                    HandleNodes(pTemp,nLevel+1);
-            }
+            HandleAllSubNodes( pNode, nLevel );
             break;
     }
 }
@@ -199,18 +184,25 @@ void SmOoxml::HandleNodes(SmNode *pNode,int nLevel)
 //Root Node, PILE equivalent, i.e. vertical stack
 void SmOoxml::HandleTable(SmNode *pNode,int nLevel)
 {
-    sal_uInt16  nSize = pNode->GetNumSubNodes();
     //The root of the starmath is a table, if
     //we convert this them each iteration of
     //conversion from starmath to OOXML will
     //add an extra unnecessary level to the
     //OOXML output stack which would grow
     //without bound in a multi step conversion
-    if( nLevel || nSize > 1 )
-        return HandleVerticalStack( pNode, nLevel, 0 );
-    for (sal_uInt16 i = 0; i < nSize; i++)
-        if (SmNode *pTemp = pNode->GetSubNode(i))
-            HandleNodes(pTemp,nLevel+1);
+    if( nLevel || pNode->GetNumSubNodes() > 1 )
+        HandleVerticalStack( pNode, nLevel, 0 );
+    else
+        HandleAllSubNodes( pNode, nLevel );
+}
+
+void SmOoxml::HandleAllSubNodes( SmNode* pNode, int nLevel )
+{
+    int size = pNode->GetNumSubNodes();
+    for( int i = 0;
+         i < size;
+         ++i )
+        HandleNode( pNode->GetSubNode( i ), nLevel + 1 );
 }
 
 // output vertical stack, firstItem says which child to use as first (if there
@@ -220,8 +212,7 @@ void SmOoxml::HandleVerticalStack( SmNode* pNode, int nLevel, int firstItem )
 {
     if( firstItem == pNode->GetNumSubNodes() - 1 ) // only one item, just output the item
     {
-        if( SmNode *pTemp = pNode->GetSubNode( firstItem ))
-            HandleNodes( pTemp, nLevel + 1 );
+        HandleNode( pNode->GetSubNode( firstItem ), nLevel + 1 );
         return;
     }
     m_pSerializer->startElementNS( XML_m, XML_f, FSEND );
@@ -229,8 +220,7 @@ void SmOoxml::HandleVerticalStack( SmNode* pNode, int nLevel, int firstItem )
     m_pSerializer->singleElementNS( XML_m, XML_type, FSNS( XML_m, XML_val ), "noBar", FSEND );
     m_pSerializer->endElementNS( XML_m, XML_fPr );
     m_pSerializer->startElementNS( XML_m, XML_num, FSEND );
-    if( SmNode* num = pNode->GetSubNode( firstItem ))
-        HandleNodes( num, nLevel + 1 );
+    HandleNode( pNode->GetSubNode( firstItem ), nLevel + 1 );
     m_pSerializer->endElementNS( XML_m, XML_num );
     // TODO this nesting means MSOffice will use smaller fonts for nested items,
     // not sure if there's another way to represent a bigger stack than 2 items
@@ -434,13 +424,12 @@ void SmOoxml::HandleFractions(SmNode *pNode,int nLevel, const char* type)
         m_pSerializer->singleElementNS( XML_m, XML_type, FSNS( XML_m, XML_val ), type, FSEND );
         m_pSerializer->endElementNS( XML_m, XML_fPr );
     }
+    OSL_ASSERT( pNode->GetNumSubNodes() == 3 );
     m_pSerializer->startElementNS( XML_m, XML_num, FSEND );
-    if( SmNode* num = pNode->GetSubNode( 0 ))
-        HandleNodes( num, nLevel + 1 );
+    HandleNode( pNode->GetSubNode( 0 ), nLevel + 1 );
     m_pSerializer->endElementNS( XML_m, XML_num );
     m_pSerializer->startElementNS( XML_m, XML_den, FSEND );
-    if( SmNode* num = pNode->GetSubNode( 2 ))
-        HandleNodes( num, nLevel + 1 );
+    HandleNode( pNode->GetSubNode( 2 ), nLevel + 1 );
     m_pSerializer->endElementNS( XML_m, XML_den );
     m_pSerializer->endElementNS( XML_m, XML_f );
 }
@@ -453,14 +442,8 @@ void SmOoxml::HandleBinaryOperation(SmNode *pNode,int nLevel)
         case TDIVIDEBY:
             return HandleFractions( pNode, nLevel, "lin" );
         default:
-        {
-            for( int i = 0;
-                 i < pNode->GetNumSubNodes();
-                 ++i )
-                if( SmNode *pTemp = pNode->GetSubNode( i ))
-                    HandleNodes( pTemp, nLevel + 1 );
+            HandleAllSubNodes( pNode, nLevel );
             break;
-        }
     }
 }
 
diff --git a/starmath/source/ooxml.hxx b/starmath/source/ooxml.hxx
index e6e6d08..5b9aaff 100644
--- a/starmath/source/ooxml.hxx
+++ b/starmath/source/ooxml.hxx
@@ -43,7 +43,8 @@ public:
     SmOoxml(String &rIn,SmNode *pIn, oox::core::OoxmlVersion version);
     bool ConvertFromStarMath( ::sax_fastparser::FSHelperPtr m_pSerializer );
 private:
-    void HandleNodes(SmNode *pNode,int nLevel);
+    void HandleNode(SmNode *pNode,int nLevel);
+    void HandleAllSubNodes(SmNode *pNode,int nLevel);
     void HandleTable(SmNode *pNode,int nLevel);
     void HandleVerticalStack( SmNode* pNode, int nLevel, int firstItem );
     void HandleText(SmNode *pNode,int nLevel);
commit b80005b21226f1b01761a427be31d89dc49e2e02
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Wed Aug 17 14:31:42 2011 +0200

    ooxml math export for vertical stack

diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
index 395d84d..740a50c 100644
--- a/starmath/source/ooxml.cxx
+++ b/starmath/source/ooxml.cxx
@@ -92,7 +92,7 @@ bool SmOoxml::ConvertFromStarMath( ::sax_fastparser::FSHelperPtr serializer )
 
 void SmOoxml::HandleNodes(SmNode *pNode,int nLevel)
 {
-    fprintf(stderr,"XX %d %d\n", nLevel, pNode->GetType());
+    fprintf(stderr,"XX %d %d %d\n", nLevel, pNode->GetType(), pNode->GetNumSubNodes());
     switch(pNode->GetType())
     {
 #if 0
@@ -202,28 +202,42 @@ void SmOoxml::HandleTable(SmNode *pNode,int nLevel)
     sal_uInt16  nSize = pNode->GetNumSubNodes();
     //The root of the starmath is a table, if
     //we convert this them each iteration of
-    //conversion from starmath to mathtype will
+    //conversion from starmath to OOXML will
     //add an extra unnecessary level to the
-    //mathtype output stack which would grow
+    //OOXML output stack which would grow
     //without bound in a multi step conversion
-
-// TODO
-//    if ( nLevel || (nSize >1))
-//    {
-//        *pS << sal_uInt8(PILE);
-//        *pS << sal_uInt8(nHAlign); //vAlign ?
-//        *pS << sal_uInt8(0x01); //hAlign
-//    }
-
+    if( nLevel || nSize > 1 )
+        return HandleVerticalStack( pNode, nLevel, 0 );
     for (sal_uInt16 i = 0; i < nSize; i++)
         if (SmNode *pTemp = pNode->GetSubNode(i))
-        {
-//            *pS << sal_uInt8(LINE);
             HandleNodes(pTemp,nLevel+1);
-//            *pS << sal_uInt8(END);
-        }
-//    if (nLevel || (nSize>1))
-//        *pS << sal_uInt8(END);
+}
+
+// output vertical stack, firstItem says which child to use as first (if there
+// are more than two children, OOXML can have only a vertical stack of two items,
+// so create a bigger vertical stack recursively)
+void SmOoxml::HandleVerticalStack( SmNode* pNode, int nLevel, int firstItem )
+{
+    if( firstItem == pNode->GetNumSubNodes() - 1 ) // only one item, just output the item
+    {
+        if( SmNode *pTemp = pNode->GetSubNode( firstItem ))
+            HandleNodes( pTemp, nLevel + 1 );
+        return;
+    }
+    m_pSerializer->startElementNS( XML_m, XML_f, FSEND );
+    m_pSerializer->startElementNS( XML_m, XML_fPr, FSEND );
+    m_pSerializer->singleElementNS( XML_m, XML_type, FSNS( XML_m, XML_val ), "noBar", FSEND );
+    m_pSerializer->endElementNS( XML_m, XML_fPr );
+    m_pSerializer->startElementNS( XML_m, XML_num, FSEND );
+    if( SmNode* num = pNode->GetSubNode( firstItem ))
+        HandleNodes( num, nLevel + 1 );
+    m_pSerializer->endElementNS( XML_m, XML_num );
+    // TODO this nesting means MSOffice will use smaller fonts for nested items,
+    // not sure if there's another way to represent a bigger stack than 2 items
+    m_pSerializer->startElementNS( XML_m, XML_den, FSEND );
+    HandleVerticalStack( pNode, nLevel, firstItem + 1 );
+    m_pSerializer->endElementNS( XML_m, XML_den );
+    m_pSerializer->endElementNS( XML_m, XML_f );
 }
 
 void SmOoxml::HandleText(SmNode *pNode, int /*nLevel*/)
diff --git a/starmath/source/ooxml.hxx b/starmath/source/ooxml.hxx
index ba659ff..e6e6d08 100644
--- a/starmath/source/ooxml.hxx
+++ b/starmath/source/ooxml.hxx
@@ -45,6 +45,7 @@ public:
 private:
     void HandleNodes(SmNode *pNode,int nLevel);
     void HandleTable(SmNode *pNode,int nLevel);
+    void HandleVerticalStack( SmNode* pNode, int nLevel, int firstItem );
     void HandleText(SmNode *pNode,int nLevel);
     void HandleMath(SmNode *pNode,int nLevel);
     void HandleFractions( SmNode *pNode,int nLevel, const char* type = NULL );
commit ce5626277bc55c17db8322b81be1c5f2d1ad02f6
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue Aug 16 17:53:37 2011 +0200

    implement x/y properly for ooxml math

diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
index 4e0198e..395d84d 100644
--- a/starmath/source/ooxml.cxx
+++ b/starmath/source/ooxml.cxx
@@ -114,6 +114,9 @@ void SmOoxml::HandleNodes(SmNode *pNode,int nLevel)
             HandleOperator(pNode,nLevel);
             break;
 #endif
+        case NBINHOR:
+            HandleBinaryOperation(pNode,nLevel);
+            break;
         case NBINVER:
             HandleFractions(pNode,nLevel);
             break;
@@ -295,6 +298,9 @@ void SmOoxml::HandleText(SmNode *pNode, int /*nLevel*/)
 
 void SmOoxml::HandleMath(SmNode *pNode,int nLevel)
 {
+    fprintf(stderr,"MATH %d\n", pNode->GetToken().eType);
+    // these are handled elsewhere, e.g. when handling BINHOR
+    OSL_ASSERT( pNode->GetToken().eType != TDIVIDEBY );
     HandleText( pNode, nLevel );
 // TODO at least some items (e.g. y/2 need to handled as ooxml and not as plain text symbols)
 #if 0
@@ -405,9 +411,15 @@ void SmOoxml::HandleMath(SmNode *pNode,int nLevel)
 #endif
 }
 
-void SmOoxml::HandleFractions(SmNode *pNode,int nLevel)
+void SmOoxml::HandleFractions(SmNode *pNode,int nLevel, const char* type)
 {
     m_pSerializer->startElementNS( XML_m, XML_f, FSEND );
+    if( type != NULL )
+    {
+        m_pSerializer->startElementNS( XML_m, XML_fPr, FSEND );
+        m_pSerializer->singleElementNS( XML_m, XML_type, FSNS( XML_m, XML_val ), type, FSEND );
+        m_pSerializer->endElementNS( XML_m, XML_fPr );
+    }
     m_pSerializer->startElementNS( XML_m, XML_num, FSEND );
     if( SmNode* num = pNode->GetSubNode( 0 ))
         HandleNodes( num, nLevel + 1 );
@@ -419,4 +431,23 @@ void SmOoxml::HandleFractions(SmNode *pNode,int nLevel)
     m_pSerializer->endElementNS( XML_m, XML_f );
 }
 
+void SmOoxml::HandleBinaryOperation(SmNode *pNode,int nLevel)
+{
+    // update OSL_ASSERT in HandleMath() when adding new items
+    switch( pNode->GetToken().eType )
+    {
+        case TDIVIDEBY:
+            return HandleFractions( pNode, nLevel, "lin" );
+        default:
+        {
+            for( int i = 0;
+                 i < pNode->GetNumSubNodes();
+                 ++i )
+                if( SmNode *pTemp = pNode->GetSubNode( i ))
+                    HandleNodes( pTemp, nLevel + 1 );
+            break;
+        }
+    }
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/ooxml.hxx b/starmath/source/ooxml.hxx
index 1cdf55d..ba659ff 100644
--- a/starmath/source/ooxml.hxx
+++ b/starmath/source/ooxml.hxx
@@ -47,7 +47,8 @@ private:
     void HandleTable(SmNode *pNode,int nLevel);
     void HandleText(SmNode *pNode,int nLevel);
     void HandleMath(SmNode *pNode,int nLevel);
-    void HandleFractions(SmNode *pNode,int nLevel);
+    void HandleFractions( SmNode *pNode,int nLevel, const char* type = NULL );
+    void HandleBinaryOperation(SmNode *pNode,int nLevel);
     String str;
     SmNode *pTree;
     ::sax_fastparser::FSHelperPtr m_pSerializer;
commit 438b5717ab783d13ba8249c0c11d87896a5ee49b
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue Aug 16 17:31:20 2011 +0200

    implement ooxml math (basic) fractions

diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
index 5bf6426..4e0198e 100644
--- a/starmath/source/ooxml.cxx
+++ b/starmath/source/ooxml.cxx
@@ -113,9 +113,11 @@ void SmOoxml::HandleNodes(SmNode *pNode,int nLevel)
         case NOPER:
             HandleOperator(pNode,nLevel);
             break;
+#endif
         case NBINVER:
             HandleFractions(pNode,nLevel);
             break;
+#if 0
         case NROOT:
             HandleRoot(pNode,nLevel);
             break;
@@ -294,6 +296,7 @@ void SmOoxml::HandleText(SmNode *pNode, int /*nLevel*/)
 void SmOoxml::HandleMath(SmNode *pNode,int nLevel)
 {
     HandleText( pNode, nLevel );
+// TODO at least some items (e.g. y/2 need to handled as ooxml and not as plain text symbols)
 #if 0
     if (pNode->GetToken().eType == TMLINE)
     {
@@ -402,4 +405,18 @@ void SmOoxml::HandleMath(SmNode *pNode,int nLevel)
 #endif
 }
 
+void SmOoxml::HandleFractions(SmNode *pNode,int nLevel)
+{
+    m_pSerializer->startElementNS( XML_m, XML_f, FSEND );
+    m_pSerializer->startElementNS( XML_m, XML_num, FSEND );
+    if( SmNode* num = pNode->GetSubNode( 0 ))
+        HandleNodes( num, nLevel + 1 );
+    m_pSerializer->endElementNS( XML_m, XML_num );
+    m_pSerializer->startElementNS( XML_m, XML_den, FSEND );
+    if( SmNode* num = pNode->GetSubNode( 2 ))
+        HandleNodes( num, nLevel + 1 );
+    m_pSerializer->endElementNS( XML_m, XML_den );
+    m_pSerializer->endElementNS( XML_m, XML_f );
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/ooxml.hxx b/starmath/source/ooxml.hxx
index 22aa91f..1cdf55d 100644
--- a/starmath/source/ooxml.hxx
+++ b/starmath/source/ooxml.hxx
@@ -47,6 +47,7 @@ private:
     void HandleTable(SmNode *pNode,int nLevel);
     void HandleText(SmNode *pNode,int nLevel);
     void HandleMath(SmNode *pNode,int nLevel);
+    void HandleFractions(SmNode *pNode,int nLevel);
     String str;
     SmNode *pTree;
     ::sax_fastparser::FSHelperPtr m_pSerializer;
commit c0bcff297b9282baa6de998804e451d66e2863b7
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue Aug 16 16:58:37 2011 +0200

    hack: make msoffice 2k7 be able to read ooxml formulas
    
    It seems that it doesn't read characters unless the font is explicitly
    specified as "Cambria Math"

diff --git a/filter/inc/filter/msfilter/ooxmlexport.hxx b/filter/inc/filter/msfilter/ooxmlexport.hxx
index b8a59e7..c9de21a 100644
--- a/filter/inc/filter/msfilter/ooxmlexport.hxx
+++ b/filter/inc/filter/msfilter/ooxmlexport.hxx
@@ -29,6 +29,7 @@
 #define _OOXMLEXPORT_HXX
 
 #include <sax/fshelper.hxx>
+#include <oox/core/filterbase.hxx>
 #include "filter/msfilter/msfilterdllapi.h"
 
 /**
@@ -38,7 +39,7 @@
 class MSFILTER_DLLPUBLIC OoxmlFormulaExportBase
 {
 public:
-    virtual void writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer ) = 0;
+    virtual void writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version ) = 0;
 };
 
 #endif
diff --git a/starmath/Library_sm.mk b/starmath/Library_sm.mk
index 98d792d..6c60337 100644
--- a/starmath/Library_sm.mk
+++ b/starmath/Library_sm.mk
@@ -48,6 +48,7 @@ $(eval $(call gb_Library_add_linked_libs,sm,\
         editeng \
 	i18npaper \
         msfilter \
+        oox \
         sal \
         sax \
         sfx \
diff --git a/starmath/inc/document.hxx b/starmath/inc/document.hxx
index d8e042c..99f0d8b 100644
--- a/starmath/inc/document.hxx
+++ b/starmath/inc/document.hxx
@@ -40,6 +40,7 @@
 #include <vcl/jobset.hxx>
 #include <vcl/virdev.hxx>
 #include <sax/fshelper.hxx>
+#include <oox/core/filterbase.hxx>
 
 #include <set>
 
@@ -173,7 +174,7 @@ class SmDocShell : public SfxObjectShell, public SfxListener
      */
     void                InvalidateCursor();
 
-    bool writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer );
+    bool writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version );
 
 public:
     TYPEINFO();
diff --git a/starmath/inc/unomodel.hxx b/starmath/inc/unomodel.hxx
index 15ada7b..a55cac8 100644
--- a/starmath/inc/unomodel.hxx
+++ b/starmath/inc/unomodel.hxx
@@ -103,7 +103,7 @@ public:
     virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xParent ) throw( ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException );
 
     // OoxmlFormulaExportBase
-    virtual void writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer );
+    virtual void writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version );
 
     static ::com::sun::star::uno::Sequence< rtl::OUString > getSupportedServiceNames_Static();
     static ::rtl::OUString getImplementationName_Static();
diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx
index b9db1f5..90da132 100644
--- a/starmath/source/document.cxx
+++ b/starmath/source/document.cxx
@@ -991,7 +991,7 @@ sal_Bool SmDocShell::ConvertTo( SfxMedium &rMedium )
     return bRet;
 }
 
-bool SmDocShell::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer )
+bool SmDocShell::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version )
 {
     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::writeFormulaOoxml" );
 
@@ -999,7 +999,7 @@ bool SmDocShell::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer
         Parse();
     if( pTree && !IsFormulaArranged() )
         ArrangeFormula();
-    SmOoxml aEquation( aText, pTree );
+    SmOoxml aEquation( aText, pTree, version );
     return aEquation.ConvertFromStarMath( m_pSerializer );
 }
 
diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
index 10b576d..5bf6426 100644
--- a/starmath/source/ooxml.cxx
+++ b/starmath/source/ooxml.cxx
@@ -34,6 +34,7 @@
 #include <oox/token/tokens.hxx>
 
 using namespace oox;
+using namespace oox::core;
 
 // TODO duped from MathType
 
@@ -70,9 +71,10 @@ static sal_Unicode Convert(sal_Unicode nIn)
     return nIn;
 }
 
-SmOoxml::SmOoxml(String &rIn,SmNode *pIn)
+SmOoxml::SmOoxml(String &rIn,SmNode *pIn,OoxmlVersion v)
 : str( rIn )
 , pTree( pIn )
+, version( v )
 {
 }
 
@@ -222,6 +224,14 @@ void SmOoxml::HandleTable(SmNode *pNode,int nLevel)
 void SmOoxml::HandleText(SmNode *pNode, int /*nLevel*/)
 {
     m_pSerializer->startElementNS( XML_m, XML_r, FSEND );
+
+    if( version == ECMA_DIALECT )
+    { // HACK: MSOffice2007 does not import characters properly unless this font is explicitly given
+        m_pSerializer->startElementNS( XML_w, XML_rPr, FSEND );
+        m_pSerializer->singleElementNS( XML_w, XML_rFonts, FSNS( XML_w, XML_ascii ), "Cambria Math",
+            FSNS( XML_w, XML_hAnsi ), "Cambria Math", FSEND );
+        m_pSerializer->endElementNS( XML_w, XML_rPr );
+    }
     m_pSerializer->startElementNS( XML_m, XML_t, FSEND );
     SmTextNode *pTemp=(SmTextNode *)pNode;
     fprintf(stderr, "T %s\n", rtl::OUStringToOString( pTemp->GetText(), RTL_TEXTENCODING_UTF8 ).getStr());
diff --git a/starmath/source/ooxml.hxx b/starmath/source/ooxml.hxx
index 70de500..22aa91f 100644
--- a/starmath/source/ooxml.hxx
+++ b/starmath/source/ooxml.hxx
@@ -32,6 +32,7 @@
 #include "node.hxx"
 
 #include <sax/fshelper.hxx>
+#include <oox/core/filterbase.hxx>
 
 /**
  Class implementing writing of formulas to OOXML.
@@ -39,7 +40,7 @@
 class SmOoxml
 {
 public:
-    SmOoxml(String &rIn,SmNode *pIn);
+    SmOoxml(String &rIn,SmNode *pIn, oox::core::OoxmlVersion version);
     bool ConvertFromStarMath( ::sax_fastparser::FSHelperPtr m_pSerializer );
 private:
     void HandleNodes(SmNode *pNode,int nLevel);
@@ -49,6 +50,7 @@ private:
     String str;
     SmNode *pTree;
     ::sax_fastparser::FSHelperPtr m_pSerializer;
+    oox::core::OoxmlVersion version;
 };
 
 
diff --git a/starmath/source/unomodel.cxx b/starmath/source/unomodel.cxx
index d44485a..4ac9297 100644
--- a/starmath/source/unomodel.cxx
+++ b/starmath/source/unomodel.cxx
@@ -1132,9 +1132,9 @@ void SAL_CALL SmModel::setParent( const uno::Reference< uno::XInterface >& xPare
     }
 }
 
-void SmModel::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer )
+void SmModel::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version )
 {
-    static_cast< SmDocShell* >( GetObjectShell())->writeFormulaOoxml( m_pSerializer );
+    static_cast< SmDocShell* >( GetObjectShell())->writeFormulaOoxml( m_pSerializer, version );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index f080ea9..41c585a 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2319,7 +2319,7 @@ void DocxAttributeOutput::WritePostponedMath()
 
     uno::Reference< uno::XInterface > xInterface( aObjRef->getComponent(), uno::UNO_QUERY );
     if( OoxmlFormulaExportBase* formulaexport = dynamic_cast< OoxmlFormulaExportBase* >( xInterface.get()))
-        formulaexport->writeFormulaOoxml( m_pSerializer );
+        formulaexport->writeFormulaOoxml( m_pSerializer, GetExport().GetFilter().getVersion());
     else
         OSL_FAIL( "Math OLE object cannot write out OOXML" );
     m_postponedMath = NULL;
commit 1ea4a6658517d27e7d5e26fc33fca9e49af6ddf7
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue Aug 16 14:45:42 2011 +0200

    write formula to the proper place inside ooxml document

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index fcd303a..f080ea9 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -585,6 +585,8 @@ void DocxAttributeOutput::EndRun()
     // append the actual run end
     m_pSerializer->endElementNS( XML_w, XML_r );
 
+    WritePostponedMath();
+
     while ( m_Fields.begin() != m_Fields.end() )
     {
         EndField_Impl( m_Fields.front( ) );
@@ -2302,14 +2304,27 @@ bool DocxAttributeOutput::WriteOLEMath( const SdrObject*, const SwOLENode& rOLEN
 
     if( !SotExchange::IsMath(aObjName) )
         return false;
-    uno::Reference< uno::XInterface > xInterface( aObjRef->getComponent(), uno::UNO_QUERY );
-    OoxmlFormulaExportBase* formulaexport = dynamic_cast< OoxmlFormulaExportBase* >( xInterface.get());
-    if( formulaexport == NULL )
-        return false;
-    formulaexport->writeFormulaOoxml( m_pSerializer );
+    assert( m_postponedMath == NULL ); // make it a list if there can be more inside one run
+    m_postponedMath = &rOLENode;
     return true;
 }
 
+void DocxAttributeOutput::WritePostponedMath()
+{
+    if( m_postponedMath == NULL )
+        return;
+    uno::Reference < embed::XEmbeddedObject > xObj(const_cast<SwOLENode*>(m_postponedMath)->GetOLEObj().GetOleRef());
+    sal_Int64 nAspect = m_postponedMath->GetAspect();
+    svt::EmbeddedObjectRef aObjRef( xObj, nAspect );
+
+    uno::Reference< uno::XInterface > xInterface( aObjRef->getComponent(), uno::UNO_QUERY );
+    if( OoxmlFormulaExportBase* formulaexport = dynamic_cast< OoxmlFormulaExportBase* >( xInterface.get()))
+        formulaexport->writeFormulaOoxml( m_pSerializer );
+    else
+        OSL_FAIL( "Math OLE object cannot write out OOXML" );
+    m_postponedMath = NULL;
+}
+
 void DocxAttributeOutput::OutputFlyFrame_Impl( const sw::Frame &rFrame, const Point& /*rNdTopLeft*/ )
 {
     m_pSerializer->mark();
@@ -4341,6 +4356,7 @@ DocxAttributeOutput::DocxAttributeOutput( DocxExport &rExport, FSHelperPtr pSeri
       m_pParentFrame( NULL ),
       m_nCloseHyperlinkStatus( Undetected ),
       m_postponedGraphic( NULL ),
+      m_postponedMath( NULL ),
       m_postitFieldsMaxId( 0 )
 {
 }
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index 550ba9f..10ee7cd 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -530,6 +530,7 @@ private:
 
     void DoWriteBookmarks( );
     void WritePostponedGraphic();
+    void WritePostponedMath();
 
     void StartField_Impl( FieldInfos& rInfos, sal_Bool bWriteRun = sal_False );
     void DoWriteCmd( String& rCmd );
@@ -603,6 +604,7 @@ private:
         Size size;
     };
     std::list< PostponedGraphic >* m_postponedGraphic;
+    const SwOLENode* m_postponedMath;
     std::vector< const SwPostItField* > m_postitFields;
     unsigned int m_postitFieldsMaxId;
 
commit 046677539e002698425b11428488a1229fc3be20
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue Aug 16 14:44:58 2011 +0200

    proper namespace for ooxml math stuff

diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
index e702b4c..10b576d 100644
--- a/starmath/source/ooxml.cxx
+++ b/starmath/source/ooxml.cxx
@@ -81,9 +81,8 @@ bool SmOoxml::ConvertFromStarMath( ::sax_fastparser::FSHelperPtr serializer )
     if( pTree == NULL )
         return false;
     m_pSerializer = serializer;
-// TODO check that the document includes the m namespace
     m_pSerializer->startElementNS( XML_m, XML_oMath,
-        FSNS( XML_xmlns, XML_m ), "http://schemas.openxmlformats.org/wordprocessingml/2006/math", FSEND );
+        FSNS( XML_xmlns, XML_m ), "http://schemas.openxmlformats.org/officeDocument/2006/math", FSEND );
     HandleNodes( pTree, 0 );
     m_pSerializer->endElementNS( XML_m, XML_oMath );
     return true;
commit 047a5de1fe8fdc60ffb07c68125c6d0a08353e0d
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue Aug 16 13:56:29 2011 +0200

    starting work on OOXML export of formulas

diff --git a/starmath/Library_sm.mk b/starmath/Library_sm.mk
index 2056424..98d792d 100644
--- a/starmath/Library_sm.mk
+++ b/starmath/Library_sm.mk
@@ -78,6 +78,7 @@ $(eval $(call gb_Library_add_exception_objects,sm,\
         starmath/source/mathmlimport \
         starmath/source/mathtype \
         starmath/source/node \
+        starmath/source/ooxml \
         starmath/source/parse \
         starmath/source/rect \
 		starmath/source/register \
diff --git a/starmath/inc/document.hxx b/starmath/inc/document.hxx
index 562763e..d8e042c 100644
--- a/starmath/inc/document.hxx
+++ b/starmath/inc/document.hxx
@@ -39,6 +39,7 @@
 #include <svl/lstner.hxx>
 #include <vcl/jobset.hxx>
 #include <vcl/virdev.hxx>
+#include <sax/fshelper.hxx>
 
 #include <set>
 
@@ -172,6 +173,8 @@ class SmDocShell : public SfxObjectShell, public SfxListener
      */
     void                InvalidateCursor();
 
+    bool writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer );
+
 public:
     TYPEINFO();
     SFX_DECL_INTERFACE(SFX_INTERFACE_SMA_START+1)
diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx
index b0ec43e..b9db1f5 100644
--- a/starmath/source/document.cxx
+++ b/starmath/source/document.cxx
@@ -95,6 +95,7 @@
 #include <utility.hxx>
 #include <view.hxx>
 #include "mathtype.hxx"
+#include "ooxml.hxx"
 #include "mathmlimport.hxx"
 #include "mathmlexport.hxx"
 #include <sfx2/sfxsids.hrc>
@@ -990,6 +991,18 @@ sal_Bool SmDocShell::ConvertTo( SfxMedium &rMedium )
     return bRet;
 }
 
+bool SmDocShell::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer )
+{
+    RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::writeFormulaOoxml" );
+
+    if( !pTree )
+        Parse();
+    if( pTree && !IsFormulaArranged() )
+        ArrangeFormula();
+    SmOoxml aEquation( aText, pTree );
+    return aEquation.ConvertFromStarMath( m_pSerializer );
+}
+
 sal_Bool SmDocShell::SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
 {
     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SaveCompleted" );
@@ -1433,5 +1446,4 @@ bool SmDocShell::WriteAsMathType3( SfxMedium& rMedium )
     return bRet;
 }
 
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/ooxml.cxx b/starmath/source/ooxml.cxx
new file mode 100644
index 0000000..e702b4c
--- /dev/null
+++ b/starmath/source/ooxml.cxx
@@ -0,0 +1,396 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Lubos Lunak <l.lunak at suse.cz> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_starmath.hxx"
+
+#include "ooxml.hxx"
+
+#include <oox/token/tokens.hxx>
+
+using namespace oox;
+
+// TODO duped from MathType
+
+static sal_Unicode Convert(sal_Unicode nIn)
+{
+    //Find the best match in accepted unicode for our private area symbols
+    static sal_Unicode aStarMathPrivateToUnicode[] =
+    {
+        0x2030, 0xF613, 0xF612, 0x002B, 0x003C, 0x003E, 0xE425, 0xE421, 0xE088, 0x2208,
+        0x0192, 0x2026, 0x2192, 0x221A, 0x221A, 0x221A, 0xE090, 0x005E, 0x02C7, 0x02D8,
+        0x00B4, 0x0060, 0x02DC, 0x00AF, 0x0362, 0xE099, 0xE09A, 0x20DB, 0xE09C, 0xE09D,
+        0x0028, 0x0029, 0x2220, 0x22AF, 0xE0A2, 0xE0A3, 0xE0A4, 0xE0A5, 0xE0A6, 0xE0A7,
+        0x002F, 0x005C, 0x274F, 0xE0AB, 0x0393, 0x0394, 0x0398, 0x039b, 0x039e, 0x03A0,
+        0x03a3, 0x03a5, 0x03a6, 0x03a8, 0x03A9, 0x03B1, 0x03B2, 0x03b3, 0x03b4, 0x03b5,
+        0x03b6, 0x03b7, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bc, 0x03bd, 0x03be, 0x03bf,
+        0x03c0, 0x03c1, 0x03c3, 0x03c4, 0x03c5, 0x03c6, 0x03c7, 0x03c8, 0x03c9, 0x03b5,
+        0x03d1, 0x03d6, 0xE0D2, 0x03db, 0x2118, 0x2202, 0x2129, 0xE0D7, 0xE0D8, 0x22A4,
+        0xE0DA, 0x2190, 0x2191, 0x2193
+    };
+    if ((nIn >= 0xE080) && (nIn <= 0xE0DD))
+        nIn = aStarMathPrivateToUnicode[nIn-0xE080];
+
+    //For whatever unicode glyph that equation editor doesn't ship with that
+    //we have a possible match we can munge it to.
+    switch (nIn)
+    {
+        case 0x2223:
+            nIn = '|';
+            break;
+        default:
+            break;
+    }
+
+    return nIn;
+}
+
+SmOoxml::SmOoxml(String &rIn,SmNode *pIn)
+: str( rIn )
+, pTree( pIn )
+{
+}
+
+bool SmOoxml::ConvertFromStarMath( ::sax_fastparser::FSHelperPtr serializer )
+{
+    if( pTree == NULL )
+        return false;
+    m_pSerializer = serializer;
+// TODO check that the document includes the m namespace
+    m_pSerializer->startElementNS( XML_m, XML_oMath,
+        FSNS( XML_xmlns, XML_m ), "http://schemas.openxmlformats.org/wordprocessingml/2006/math", FSEND );
+    HandleNodes( pTree, 0 );
+    m_pSerializer->endElementNS( XML_m, XML_oMath );
+    return true;
+}
+
+void SmOoxml::HandleNodes(SmNode *pNode,int nLevel)
+{
+    fprintf(stderr,"XX %d %d\n", nLevel, pNode->GetType());
+    switch(pNode->GetType())
+    {
+#if 0
+        case NATTRIBUT:
+            HandleAttributes(pNode,nLevel);
+            break;
+#endif
+        case NTEXT:
+            HandleText(pNode,nLevel);
+            break;
+#if 0
+        case NVERTICAL_BRACE:
+            HandleVerticalBrace(pNode,nLevel);
+            break;
+        case NBRACE:
+            HandleBrace(pNode,nLevel);
+            break;
+        case NOPER:
+            HandleOperator(pNode,nLevel);
+            break;
+        case NBINVER:
+            HandleFractions(pNode,nLevel);
+            break;
+        case NROOT:
+            HandleRoot(pNode,nLevel);
+            break;
+        case NSPECIAL:
+            {
+            SmTextNode *pText=(SmTextNode *)pNode;
+            //if the token str and the result text are the same then this
+            //is to be seen as text, else assume its a mathchar
+            if (pText->GetText() == pText->GetToken().aText)
+                HandleText(pText,nLevel);
+            else
+                HandleMath(pText,nLevel);
+            }
+            break;
+#endif
+        case NMATH:
+            HandleMath(pNode,nLevel);
+            break;
+#if 0
+        case NSUBSUP:
+            HandleSubSupScript(pNode,nLevel);
+            break;
+#endif
+        case NEXPRESSION:
+            {
+            sal_uInt16  nSize = pNode->GetNumSubNodes();
+            for (sal_uInt16 i = 0; i < nSize; i++)
+                if (SmNode *pTemp = pNode->GetSubNode(i))
+                    HandleNodes(pTemp,nLevel+1);
+            }
+            break;
+        case NTABLE:
+            //Root Node, PILE equivalent, i.e. vertical stack
+            HandleTable(pNode,nLevel);
+            break;
+#if 0
+        case NMATRIX:
+            HandleSmMatrix((SmMatrixNode *)pNode,nLevel);
+            break;
+#endif
+        case NLINE:
+            {
+// TODO
+//            *pS << sal_uInt8(LINE);
+            sal_uInt16  nSize = pNode->GetNumSubNodes();
+            for (sal_uInt16 i = 0; i < nSize; i++)
+                if (SmNode *pTemp = pNode->GetSubNode(i))
+                    HandleNodes(pTemp,nLevel+1);
+//            *pS << sal_uInt8(END);
+            }
+            break;
+#if 0
+        case NALIGN:
+            HandleMAlign(pNode,nLevel);
+            break;
+        case NBLANK:
+            *pS << sal_uInt8(CHAR);
+            *pS << sal_uInt8(0x98);
+            if (pNode->GetToken().eType == TSBLANK)
+                *pS << sal_uInt16(0xEB04);
+            else
+                *pS << sal_uInt16(0xEB05);
+            break;
+#endif
+        default:
+            {
+            sal_uInt16  nSize = pNode->GetNumSubNodes();
+            for (sal_uInt16 i = 0; i < nSize; i++)
+                if (SmNode *pTemp = pNode->GetSubNode(i))
+                    HandleNodes(pTemp,nLevel+1);
+            }
+            break;
+    }
+}
+
+//Root Node, PILE equivalent, i.e. vertical stack
+void SmOoxml::HandleTable(SmNode *pNode,int nLevel)
+{
+    sal_uInt16  nSize = pNode->GetNumSubNodes();
+    //The root of the starmath is a table, if
+    //we convert this them each iteration of
+    //conversion from starmath to mathtype will
+    //add an extra unnecessary level to the
+    //mathtype output stack which would grow
+    //without bound in a multi step conversion
+
+// TODO
+//    if ( nLevel || (nSize >1))
+//    {
+//        *pS << sal_uInt8(PILE);
+//        *pS << sal_uInt8(nHAlign); //vAlign ?
+//        *pS << sal_uInt8(0x01); //hAlign
+//    }
+
+    for (sal_uInt16 i = 0; i < nSize; i++)
+        if (SmNode *pTemp = pNode->GetSubNode(i))
+        {
+//            *pS << sal_uInt8(LINE);
+            HandleNodes(pTemp,nLevel+1);
+//            *pS << sal_uInt8(END);
+        }
+//    if (nLevel || (nSize>1))
+//        *pS << sal_uInt8(END);
+}
+
+void SmOoxml::HandleText(SmNode *pNode, int /*nLevel*/)
+{
+    m_pSerializer->startElementNS( XML_m, XML_r, FSEND );
+    m_pSerializer->startElementNS( XML_m, XML_t, FSEND );
+    SmTextNode *pTemp=(SmTextNode *)pNode;
+    fprintf(stderr, "T %s\n", rtl::OUStringToOString( pTemp->GetText(), RTL_TEXTENCODING_UTF8 ).getStr());
+    for(xub_StrLen i=0;i<pTemp->GetText().Len();i++)
+    {
+#if 0
+        if ((nPendingAttributes) &&
+            (i == ((pTemp->GetText().Len()+1)/2)-1))
+        {
+            *pS << sal_uInt8(0x22);     //char, with attributes right
+                                //after the character
+        }
+        else
+            *pS << sal_uInt8(CHAR);
+
+        sal_uInt8 nFace = 0x1;
+        if (pNode->GetFont().GetItalic() == ITALIC_NORMAL)
+            nFace = 0x3;
+        else if (pNode->GetFont().GetWeight() == WEIGHT_BOLD)
+            nFace = 0x7;
+        *pS << sal_uInt8(nFace+128); //typeface
+#endif
+        sal_uInt16 nChar = pTemp->GetText().GetChar(i);
+        m_pSerializer->write( rtl::OUString( Convert(nChar)));
+
+#if 0
+        //Mathtype can only have these sort of character
+        //attributes on a single character, starmath can put them
+        //anywhere, when the entity involved is a text run this is
+        //a large effort to place the character attribute on the
+        //central mathtype character so that it does pretty much
+        //what the user probably has in mind. The attributes
+        //filled in here are dummy ones which are replaced in the
+        //ATTRIBUT handler if a suitable location for the
+        //attributes was found here. Unfortunately it is
+        //possible for starmath to place character attributes on
+        //entities which cannot occur in mathtype e.g. a Summation
+        //symbol so these attributes may be lost
+        if ((nPendingAttributes) &&
+            (i == ((pTemp->GetText().Len()+1)/2)-1))
+        {
+            *pS << sal_uInt8(EMBEL);
+            while (nPendingAttributes)
+            {
+                *pS << sal_uInt8(2);
+                //wedge the attributes in here and clear
+                //the pending stack
+                nPendingAttributes--;
+            }
+            nInsertion=pS->Tell();
+            *pS << sal_uInt8(END); //end embel
+            *pS << sal_uInt8(END); //end embel
+        }
+#endif
+    }
+    m_pSerializer->endElementNS( XML_m, XML_t );
+    m_pSerializer->endElementNS( XML_m, XML_r );
+}
+
+void SmOoxml::HandleMath(SmNode *pNode,int nLevel)
+{
+    HandleText( pNode, nLevel );
+#if 0
+    if (pNode->GetToken().eType == TMLINE)
+    {
+        *pS << sal_uInt8(END);
+        *pS << sal_uInt8(LINE);
+        bIsReInterpBrace=1;
+        return;
+    }
+    SmMathSymbolNode *pTemp=(SmMathSymbolNode *)pNode;
+    for(xub_StrLen i=0;i<pTemp->GetText().Len();i++)
+    {
+        sal_Unicode nArse = Convert(pTemp->GetText().GetChar(i));
+        if ((nArse == 0x2224) || (nArse == 0x2288) || (nArse == 0x2285) ||
+            (nArse == 0x2289))
+        {
+            *pS << sal_uInt8(CHAR|0x20);
+        }
+        else if ((nPendingAttributes) &&
+                (i == ((pTemp->GetText().Len()+1)/2)-1))
+            {
+                *pS << sal_uInt8(0x22);
+            }
+        else
+            *pS << sal_uInt8(CHAR); //char without formula recognition
+        //The typeface seems to be MTEXTRA for unicode characters,
+        //though how to determine when mathtype chooses one over
+        //the other is unknown. This should do the trick
+        //nevertheless.
+        sal_uInt8 nBias;
+        if ( (nArse == 0x2213) || (nArse == 0x2218) ||
+            (nArse == 0x210F) || (
+                (nArse >= 0x22EE) && (nArse <= 0x22FF)
+            ))
+        {
+            nBias = 0xB; //typeface
+        }
+        else if ((nArse > 0x2000) || (nArse == 0x00D7))
+            nBias = 0x6; //typeface
+        else if (nArse == 0x3d1)
+            nBias = 0x4;
+        else if ((nArse > 0xFF) && ((nArse < 0x393) || (nArse > 0x3c9)))
+            nBias = 0xB; //typeface
+        else if ((nArse == 0x2F) || (nArse == 0x2225))
+            nBias = 0x2; //typeface
+        else
+            nBias = 0x3; //typeface
+
+        *pS << sal_uInt8(nSpec+nBias+128); //typeface
+
+        if (nArse == 0x2224)
+        {
+            *pS << sal_uInt16(0x7C);
+            *pS << sal_uInt8(EMBEL);
+            *pS << sal_uInt8(0x0A);
+            *pS << sal_uInt8(END); //end embel
+            *pS << sal_uInt8(END); //end embel
+        }
+        else if (nArse == 0x2225)
+            *pS << sal_uInt16(0xEC09);
+        else if (nArse == 0xE421)
+            *pS << sal_uInt16(0x2265);
+        else if (nArse == 0x230A)
+            *pS << sal_uInt16(0xF8F0);
+        else if (nArse == 0x230B)
+            *pS << sal_uInt16(0xF8FB);
+        else if (nArse == 0xE425)
+            *pS << sal_uInt16(0x2264);
+        else if (nArse == 0x226A)
+        {
+            *pS << sal_uInt16(0x3C);
+            *pS << sal_uInt8(CHAR);
+            *pS << sal_uInt8(0x98);
+            *pS << sal_uInt16(0xEB01);
+            *pS << sal_uInt8(CHAR);
+            *pS << sal_uInt8(0x86);
+            *pS << sal_uInt16(0x3c);
+        }
+        else if (nArse == 0x2288)
+        {
+            *pS << sal_uInt16(0x2286);
+            *pS << sal_uInt8(EMBEL);
+            *pS << sal_uInt8(0x0A);
+            *pS << sal_uInt8(END); //end embel
+            *pS << sal_uInt8(END); //end embel
+        }
+        else if (nArse == 0x2289)
+        {
+            *pS << sal_uInt16(0x2287);
+            *pS << sal_uInt8(EMBEL);
+            *pS << sal_uInt8(0x0A);
+            *pS << sal_uInt8(END); //end embel
+            *pS << sal_uInt8(END); //end embel
+        }
+        else if (nArse == 0x2285)
+        {
+            *pS << sal_uInt16(0x2283);
+            *pS << sal_uInt8(EMBEL);
+            *pS << sal_uInt8(0x0A);
+            *pS << sal_uInt8(END); //end embel
+            *pS << sal_uInt8(END); //end embel
+        }
+        else
+            *pS << nArse;
+    }
+    nPendingAttributes = 0;
+#endif
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/ooxml.hxx b/starmath/source/ooxml.hxx
new file mode 100644
index 0000000..70de500
--- /dev/null
+++ b/starmath/source/ooxml.hxx
@@ -0,0 +1,57 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Lubos Lunak <l.lunak at suse.cz> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#ifndef SM_OOXML_HXX
+#define SM_OOXML_HXX
+
+#include "node.hxx"
+
+#include <sax/fshelper.hxx>
+
+/**
+ Class implementing writing of formulas to OOXML.
+ */
+class SmOoxml
+{
+public:
+    SmOoxml(String &rIn,SmNode *pIn);
+    bool ConvertFromStarMath( ::sax_fastparser::FSHelperPtr m_pSerializer );
+private:
+    void HandleNodes(SmNode *pNode,int nLevel);
+    void HandleTable(SmNode *pNode,int nLevel);
+    void HandleText(SmNode *pNode,int nLevel);
+    void HandleMath(SmNode *pNode,int nLevel);
+    String str;
+    SmNode *pTree;
+    ::sax_fastparser::FSHelperPtr m_pSerializer;
+};
+
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/unomodel.cxx b/starmath/source/unomodel.cxx
index 1820420..d44485a 100644
--- a/starmath/source/unomodel.cxx
+++ b/starmath/source/unomodel.cxx
@@ -1134,7 +1134,7 @@ void SAL_CALL SmModel::setParent( const uno::Reference< uno::XInterface >& xPare
 
 void SmModel::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer )
 {
-//    static_cast< SmDocShell* >( GetObjectShell())->writeFormulaOoxml( m_pSerializer );
+    static_cast< SmDocShell* >( GetObjectShell())->writeFormulaOoxml( m_pSerializer );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit 2e5e29471f9ac61ec454bf90a985525a0ad5cb1c
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue Aug 16 13:52:43 2011 +0200

    hook for calling from .docx filter to starmath for writting formulas

diff --git a/filter/inc/filter/msfilter/ooxmlexport.hxx b/filter/inc/filter/msfilter/ooxmlexport.hxx
new file mode 100644
index 0000000..b8a59e7
--- /dev/null
+++ b/filter/inc/filter/msfilter/ooxmlexport.hxx
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Lubos Lunak <l.lunak at suse.cz> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+#ifndef _OOXMLEXPORT_HXX
+#define _OOXMLEXPORT_HXX
+
+#include <sax/fshelper.hxx>
+#include "filter/msfilter/msfilterdllapi.h"
+
+/**
+ Interface class, StarMath will implement writeFormulaOoxml() to write out OOXML
+ representing the formula.
+ */
+class MSFILTER_DLLPUBLIC OoxmlFormulaExportBase
+{
+public:
+    virtual void writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer ) = 0;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/Library_sm.mk b/starmath/Library_sm.mk
index 86e833f..2056424 100644
--- a/starmath/Library_sm.mk
+++ b/starmath/Library_sm.mk
@@ -47,7 +47,9 @@ $(eval $(call gb_Library_add_linked_libs,sm,\
         cppuhelper \
         editeng \
 	i18npaper \
+        msfilter \
         sal \
+        sax \
         sfx \
         sot \
         svl \
diff --git a/starmath/inc/unomodel.hxx b/starmath/inc/unomodel.hxx
index 693ea3b..15ada7b 100644
--- a/starmath/inc/unomodel.hxx
+++ b/starmath/inc/unomodel.hxx
@@ -37,6 +37,7 @@
 #include <sfx2/sfxbasemodel.hxx>
 #include <comphelper/propertysethelper.hxx>
 #include <vcl/print.hxx>
+#include <filter/msfilter/ooxmlexport.hxx>
 
 class SmFormat;
 
@@ -63,7 +64,8 @@ public:
 class SmModel : public SfxBaseModel,
                 public comphelper::PropertySetHelper,
                 public com::sun::star::lang::XServiceInfo,
-                public com::sun::star::view::XRenderable
+                public com::sun::star::view::XRenderable,
+                public OoxmlFormulaExportBase
 {
     SmPrintUIOptions* m_pPrintUIOptions;
 protected:
@@ -100,6 +102,9 @@ public:
 
     virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xParent ) throw( ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException );
 
+    // OoxmlFormulaExportBase
+    virtual void writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer );
+
     static ::com::sun::star::uno::Sequence< rtl::OUString > getSupportedServiceNames_Static();
     static ::rtl::OUString getImplementationName_Static();
 };
diff --git a/starmath/source/unomodel.cxx b/starmath/source/unomodel.cxx
index 8ee267e..1820420 100644
--- a/starmath/source/unomodel.cxx
+++ b/starmath/source/unomodel.cxx
@@ -1132,4 +1132,9 @@ void SAL_CALL SmModel::setParent( const uno::Reference< uno::XInterface >& xPare
     }
 }
 
+void SmModel::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer )
+{
+//    static_cast< SmDocShell* >( GetObjectShell())->writeFormulaOoxml( m_pSerializer );
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index b2c4391..fcd303a 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -45,6 +45,7 @@
 #include <oox/export/drawingml.hxx>
 #include <oox/export/utils.hxx>
 #include <oox/export/vmlexport.hxx>
+#include <filter/msfilter/ooxmlexport.hxx>
 
 #include <i18npool/mslangid.hxx>
 
@@ -2301,7 +2302,11 @@ bool DocxAttributeOutput::WriteOLEMath( const SdrObject*, const SwOLENode& rOLEN
 
     if( !SotExchange::IsMath(aObjName) )
         return false;
-    // TODO
+    uno::Reference< uno::XInterface > xInterface( aObjRef->getComponent(), uno::UNO_QUERY );
+    OoxmlFormulaExportBase* formulaexport = dynamic_cast< OoxmlFormulaExportBase* >( xInterface.get());
+    if( formulaexport == NULL )
+        return false;
+    formulaexport->writeFormulaOoxml( m_pSerializer );
     return true;
 }
 


More information about the Libreoffice-commits mailing list