diff options
author | Miklos Vajna <vmiklos@suse.cz> | 2012-07-27 11:09:57 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2012-07-27 11:54:57 +0200 |
commit | 2f91b691e523385ff6350ea3524c7f795820612d (patch) | |
tree | bd56a8f0f3ebd812f1aa4fa8fa4b275225f019bb /starmath/source/ooxmlexport.cxx | |
parent | ebacc340796a6a99d363bd3f04c72106db7d6f7a (diff) |
factor out common code of SmOoxmlExport and SmRtfExport to SmWordExportBase
Change-Id: I63ce6c57faf8568776d24ba1e8b13bd11b6c5532
Diffstat (limited to 'starmath/source/ooxmlexport.cxx')
-rw-r--r-- | starmath/source/ooxmlexport.cxx | 188 |
1 files changed, 12 insertions, 176 deletions
diff --git a/starmath/source/ooxmlexport.cxx b/starmath/source/ooxmlexport.cxx index 1eaf6c817c44..9cf7188543a7 100644 --- a/starmath/source/ooxmlexport.cxx +++ b/starmath/source/ooxmlexport.cxx @@ -36,19 +36,19 @@ using namespace oox; using namespace oox::core; SmOoxmlExport::SmOoxmlExport( const SmNode* pIn, OoxmlVersion v ) -: pTree( pIn ) +: SmWordExportBase( pIn ) , version( v ) { } bool SmOoxmlExport::ConvertFromStarMath( ::sax_fastparser::FSHelperPtr serializer ) { - if( pTree == NULL ) + if( m_pTree == NULL ) return false; m_pSerializer = serializer; m_pSerializer->startElementNS( XML_m, XML_oMath, FSNS( XML_xmlns, XML_m ), "http://schemas.openxmlformats.org/officeDocument/2006/math", FSEND ); - HandleNode( pTree, 0 ); + HandleNode( m_pTree, 0 ); m_pSerializer->endElementNS( XML_m, XML_oMath ); return true; } @@ -56,124 +56,6 @@ bool SmOoxmlExport::ConvertFromStarMath( ::sax_fastparser::FSHelperPtr serialize // NOTE: This is still work in progress and unfinished, but it already covers a good // part of the ooxml math stuff. -void SmOoxmlExport::HandleNode( const SmNode* pNode, int nLevel ) -{ - SAL_INFO( "starmath.ooxml", "Node: " << nLevel << " " << int( pNode->GetType()) << " " << pNode->GetNumSubNodes()); - switch(pNode->GetType()) - { - case NATTRIBUT: - HandleAttribute( static_cast< const SmAttributNode* >( pNode ), nLevel ); - break; - 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; - case NOPER: - HandleOperator( static_cast< const SmOperNode* >( pNode ), nLevel ); - break; - case NUNHOR: - HandleUnaryOperation( static_cast< const SmUnHorNode* >( pNode ), nLevel ); - break; - case NBINHOR: - HandleBinaryOperation( static_cast< const SmBinHorNode* >( pNode ), nLevel ); - break; - case NBINVER: - HandleFractions(pNode,nLevel); - break; - case NROOT: - HandleRoot( static_cast< const SmRootNode* >( pNode ), nLevel ); - break; - case NSPECIAL: - { - 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) - HandleText(pText,nLevel); - else - HandleMath(pText,nLevel); - break; - } - case NMATH: - HandleMath(pNode,nLevel); - break; - case NSUBSUP: - HandleSubSupScript( static_cast< const SmSubSupNode* >( pNode ), nLevel ); - break; - case NEXPRESSION: - HandleAllSubNodes( pNode, nLevel ); - break; - case NTABLE: - //Root Node, PILE equivalent, i.e. vertical stack - HandleTable(pNode,nLevel); - break; - case NMATRIX: - HandleMatrix( static_cast< const SmMatrixNode* >( pNode ), nLevel ); - break; - case NLINE: - { -// TODO - HandleAllSubNodes( pNode, nLevel ); - } - break; -#if 0 - case NALIGN: - HandleMAlign(pNode,nLevel); - break; -#endif - case NPLACE: - // explicitly do nothing, MSOffice treats that as a placeholder if item is missing - break; - case NBLANK: - m_pSerializer->startElementNS( XML_m, XML_r, FSEND ); - m_pSerializer->startElementNS( XML_m, XML_t, FSNS( XML_xml, XML_space ), "preserve", FSEND ); - m_pSerializer->write( " " ); - m_pSerializer->endElementNS( XML_m, XML_t ); - m_pSerializer->endElementNS( XML_m, XML_r ); - break; - default: - HandleAllSubNodes( pNode, nLevel ); - break; - } -} - -//Root Node, PILE equivalent, i.e. vertical stack -void SmOoxmlExport::HandleTable( const SmNode* pNode, int nLevel ) -{ - //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 || pNode->GetNumSubNodes() > 1 ) - HandleVerticalStack( pNode, nLevel ); - else - HandleAllSubNodes( pNode, nLevel ); -} - -void SmOoxmlExport::HandleAllSubNodes( const SmNode* pNode, int nLevel ) -{ - int size = pNode->GetNumSubNodes(); - 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 ); - } -} - void SmOoxmlExport::HandleVerticalStack( const SmNode* pNode, int nLevel ) { m_pSerializer->startElementNS( XML_m, XML_eqArr, FSEND ); @@ -278,34 +160,6 @@ void SmOoxmlExport::HandleFractions( const SmNode* pNode, int nLevel, const char m_pSerializer->endElementNS( XML_m, XML_f ); } -void SmOoxmlExport::HandleUnaryOperation( const SmUnHorNode* pNode, int nLevel ) -{ - // update HandleMath() when adding new items - SAL_INFO( "starmath.ooxml", "Unary: " << int( pNode->GetToken().eType )); - -// Avoid MSVC warning C4065: switch statement contains 'default' but no 'case' labels -// switch( pNode->GetToken().eType ) -// { -// default: - HandleAllSubNodes( pNode, nLevel ); -// break; -// } -} - -void SmOoxmlExport::HandleBinaryOperation( const SmBinHorNode* pNode, int nLevel ) -{ - SAL_INFO( "starmath.ooxml", "Binary: " << int( pNode->Symbol()->GetToken().eType )); - // update HandleMath() when adding new items - switch( pNode->Symbol()->GetToken().eType ) - { - case TDIVIDEBY: - return HandleFractions( pNode, nLevel, "lin" ); - default: - HandleAllSubNodes( pNode, nLevel ); - break; - } -} - void SmOoxmlExport::HandleAttribute( const SmAttributNode* pNode, int nLevel ) { switch( pNode->Attribute()->GetToken().eType ) @@ -370,21 +224,6 @@ void SmOoxmlExport::HandleAttribute( const SmAttributNode* pNode, int nLevel ) } } -void SmOoxmlExport::HandleMath( const SmNode* pNode, int nLevel ) -{ - SAL_INFO( "starmath.ooxml", "Math: " << int( 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 SmOoxmlExport::HandleRoot( const SmRootNode* pNode, int nLevel ) { m_pSerializer->startElementNS( XML_m, XML_rad, FSEND ); @@ -494,18 +333,6 @@ void SmOoxmlExport::HandleOperator( const SmOperNode* pNode, int nLevel ) } } -void SmOoxmlExport::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 << LSUB ) : 0 ) - | ( pNode->GetSubSup( LSUP ) != NULL ? ( 1 << LSUP ) : 0 ); - HandleSubSupScriptInternal( pNode, nLevel, flags ); -} - void SmOoxmlExport::HandleSubSupScriptInternal( const SmSubSupNode* pNode, int nLevel, int flags ) { // docx supports only a certain combination of sub/super scripts, but LO can have any, @@ -714,4 +541,13 @@ void SmOoxmlExport::HandleVerticalBrace( const SmVerticalBraceNode* pNode, int n } } +void SmOoxmlExport::HandleBlank() +{ + m_pSerializer->startElementNS( XML_m, XML_r, FSEND ); + m_pSerializer->startElementNS( XML_m, XML_t, FSNS( XML_xml, XML_space ), "preserve", FSEND ); + m_pSerializer->write( " " ); + m_pSerializer->endElementNS( XML_m, XML_t ); + m_pSerializer->endElementNS( XML_m, XML_r ); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |