diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2011-08-18 15:01:35 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2011-08-18 15:33:50 +0200 |
commit | 1a4c6931914f0072a2828bf6966606781384d210 (patch) | |
tree | 2be72bca6b9a2e50ec2dcfc80bb5e300ece83f45 /starmath | |
parent | efb9c9000071b9ab2f1757caf810ad43ee259e1d (diff) |
implement sub/sup support for ooxml math export
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/inc/node.hxx | 1 | ||||
-rw-r--r-- | starmath/source/ooxml.cxx | 76 | ||||
-rw-r--r-- | starmath/source/ooxml.hxx | 2 |
3 files changed, 76 insertions, 3 deletions
diff --git a/starmath/inc/node.hxx b/starmath/inc/node.hxx index 93b2521450b3..38793e7c5148 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 1b0480ea34a2..b7c8092c5991 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 c0679d2e6adf..7246a8c78fa3 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; |