LCOV - code coverage report
Current view: top level - starmath/source - ooxmlexport.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 312 0.0 %
Date: 2014-04-14 Functions: 0 16 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : 
      11             : #include "ooxmlexport.hxx"
      12             : 
      13             : #include <oox/token/tokens.hxx>
      14             : #include <rtl/ustring.hxx>
      15             : 
      16             : using namespace oox;
      17             : using namespace oox::core;
      18             : 
      19           0 : SmOoxmlExport::SmOoxmlExport( const SmNode* pIn, OoxmlVersion v )
      20             : : SmWordExportBase( pIn )
      21           0 : , version( v )
      22             : {
      23           0 : }
      24             : 
      25           0 : bool SmOoxmlExport::ConvertFromStarMath( ::sax_fastparser::FSHelperPtr serializer )
      26             : {
      27           0 :     if( m_pTree == NULL )
      28           0 :         return false;
      29           0 :     m_pSerializer = serializer;
      30             :     m_pSerializer->startElementNS( XML_m, XML_oMath,
      31           0 :         FSNS( XML_xmlns, XML_m ), "http://schemas.openxmlformats.org/officeDocument/2006/math", FSEND );
      32           0 :     HandleNode( m_pTree, 0 );
      33           0 :     m_pSerializer->endElementNS( XML_m, XML_oMath );
      34           0 :     return true;
      35             : }
      36             : 
      37             : // NOTE: This is still work in progress and unfinished, but it already covers a good
      38             : // part of the ooxml math stuff.
      39             : 
      40           0 : void SmOoxmlExport::HandleVerticalStack( const SmNode* pNode, int nLevel )
      41             : {
      42           0 :     m_pSerializer->startElementNS( XML_m, XML_eqArr, FSEND );
      43           0 :     int size = pNode->GetNumSubNodes();
      44           0 :     for( int i = 0;
      45             :          i < size;
      46             :          ++i )
      47             :     {
      48           0 :         m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
      49           0 :         HandleNode( pNode->GetSubNode( i ), nLevel + 1 );
      50           0 :         m_pSerializer->endElementNS( XML_m, XML_e );
      51             :     }
      52           0 :     m_pSerializer->endElementNS( XML_m, XML_eqArr );
      53           0 : }
      54             : 
      55           0 : void SmOoxmlExport::HandleText( const SmNode* pNode, int /*nLevel*/)
      56             : {
      57           0 :     m_pSerializer->startElementNS( XML_m, XML_r, FSEND );
      58             : 
      59           0 :     if( pNode->GetToken().eType == TTEXT ) // literal text (in quotes)
      60             :     {
      61           0 :         m_pSerializer->startElementNS( XML_m, XML_rPr, FSEND );
      62           0 :         m_pSerializer->singleElementNS( XML_m, XML_lit, FSEND );
      63           0 :         m_pSerializer->singleElementNS( XML_m, XML_nor, FSEND );
      64           0 :         m_pSerializer->endElementNS( XML_m, XML_rPr );
      65             :     }
      66           0 :     if( version == ECMA_DIALECT )
      67             :     { // HACK: MSOffice2007 does not import characters properly unless this font is explicitly given
      68           0 :         m_pSerializer->startElementNS( XML_w, XML_rPr, FSEND );
      69             :         m_pSerializer->singleElementNS( XML_w, XML_rFonts, FSNS( XML_w, XML_ascii ), "Cambria Math",
      70           0 :             FSNS( XML_w, XML_hAnsi ), "Cambria Math", FSEND );
      71           0 :         m_pSerializer->endElementNS( XML_w, XML_rPr );
      72             :     }
      73           0 :     m_pSerializer->startElementNS( XML_m, XML_t, FSNS( XML_xml, XML_space ), "preserve", FSEND );
      74           0 :     SmTextNode* pTemp=(SmTextNode* )pNode;
      75             :     SAL_INFO( "starmath.ooxml", "Text:" << OUStringToOString( pTemp->GetText(), RTL_TEXTENCODING_UTF8 ).getStr());
      76           0 :     for(sal_Int32 i=0;i<pTemp->GetText().getLength();i++)
      77             :     {
      78             : #if 0
      79             :         if ((nPendingAttributes) &&
      80             :             (i == ((pTemp->GetText().getLength()+1)/2)-1))
      81             :         {
      82             :             *pS << sal_uInt8(0x22);     //char, with attributes right
      83             :                                 //after the character
      84             :         }
      85             :         else
      86             :             *pS << sal_uInt8(CHAR);
      87             : 
      88             :         sal_uInt8 nFace = 0x1;
      89             :         if (pNode->GetFont().GetItalic() == ITALIC_NORMAL)
      90             :             nFace = 0x3;
      91             :         else if (pNode->GetFont().GetWeight() == WEIGHT_BOLD)
      92             :             nFace = 0x7;
      93             :         *pS << sal_uInt8(nFace+128); //typeface
      94             : #endif
      95           0 :         sal_uInt16 nChar = pTemp->GetText()[i];
      96           0 :         m_pSerializer->writeEscaped( OUString( SmTextNode::ConvertSymbolToUnicode(nChar)));
      97             : 
      98             : #if 0
      99             :         //Mathtype can only have these sort of character
     100             :         //attributes on a single character, starmath can put them
     101             :         //anywhere, when the entity involved is a text run this is
     102             :         //a large effort to place the character attribute on the
     103             :         //central mathtype character so that it does pretty much
     104             :         //what the user probably has in mind. The attributes
     105             :         //filled in here are dummy ones which are replaced in the
     106             :         //ATTRIBUT handler if a suitable location for the
     107             :         //attributes was found here. Unfortunately it is
     108             :         //possible for starmath to place character attributes on
     109             :         //entities which cannot occur in mathtype e.g. a Summation
     110             :         //symbol so these attributes may be lost
     111             :         if ((nPendingAttributes) &&
     112             :             (i == ((pTemp->GetText().getLength()+1)/2)-1))
     113             :         {
     114             :             *pS << sal_uInt8(EMBEL);
     115             :             while (nPendingAttributes)
     116             :             {
     117             :                 *pS << sal_uInt8(2);
     118             :                 //wedge the attributes in here and clear
     119             :                 //the pending stack
     120             :                 nPendingAttributes--;
     121             :             }
     122             :             nInsertion=pS->Tell();
     123             :             *pS << sal_uInt8(END); //end embel
     124             :             *pS << sal_uInt8(END); //end embel
     125             :         }
     126             : #endif
     127             :     }
     128           0 :     m_pSerializer->endElementNS( XML_m, XML_t );
     129           0 :     m_pSerializer->endElementNS( XML_m, XML_r );
     130           0 : }
     131             : 
     132           0 : void SmOoxmlExport::HandleFractions( const SmNode* pNode, int nLevel, const char* type )
     133             : {
     134           0 :     m_pSerializer->startElementNS( XML_m, XML_f, FSEND );
     135           0 :     if( type != NULL )
     136             :     {
     137           0 :         m_pSerializer->startElementNS( XML_m, XML_fPr, FSEND );
     138           0 :         m_pSerializer->singleElementNS( XML_m, XML_type, FSNS( XML_m, XML_val ), type, FSEND );
     139           0 :         m_pSerializer->endElementNS( XML_m, XML_fPr );
     140             :     }
     141             :     OSL_ASSERT( pNode->GetNumSubNodes() == 3 );
     142           0 :     m_pSerializer->startElementNS( XML_m, XML_num, FSEND );
     143           0 :     HandleNode( pNode->GetSubNode( 0 ), nLevel + 1 );
     144           0 :     m_pSerializer->endElementNS( XML_m, XML_num );
     145           0 :     m_pSerializer->startElementNS( XML_m, XML_den, FSEND );
     146           0 :     HandleNode( pNode->GetSubNode( 2 ), nLevel + 1 );
     147           0 :     m_pSerializer->endElementNS( XML_m, XML_den );
     148           0 :     m_pSerializer->endElementNS( XML_m, XML_f );
     149           0 : }
     150             : 
     151           0 : void SmOoxmlExport::HandleAttribute( const SmAttributNode* pNode, int nLevel )
     152             : {
     153           0 :     switch( pNode->Attribute()->GetToken().eType )
     154             :     {
     155             :         case TCHECK:
     156             :         case TACUTE:
     157             :         case TGRAVE:
     158             :         case TBREVE:
     159             :         case TCIRCLE:
     160             :         case TVEC:
     161             :         case TTILDE:
     162             :         case THAT:
     163             :         case TDOT:
     164             :         case TDDOT:
     165             :         case TDDDOT:
     166             :         case TWIDETILDE:
     167             :         case TWIDEHAT:
     168             :         case TWIDEVEC:
     169             :         case TBAR:
     170             :         {
     171           0 :             m_pSerializer->startElementNS( XML_m, XML_acc, FSEND );
     172           0 :             m_pSerializer->startElementNS( XML_m, XML_accPr, FSEND );
     173             :             OString value = OUStringToOString(
     174           0 :                 OUString( pNode->Attribute()->GetToken().cMathChar ), RTL_TEXTENCODING_UTF8 );
     175           0 :             m_pSerializer->singleElementNS( XML_m, XML_chr, FSNS( XML_m, XML_val ), value.getStr(), FSEND );
     176           0 :             m_pSerializer->endElementNS( XML_m, XML_accPr );
     177           0 :             m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     178           0 :             HandleNode( pNode->Body(), nLevel + 1 );
     179           0 :             m_pSerializer->endElementNS( XML_m, XML_e );
     180           0 :             m_pSerializer->endElementNS( XML_m, XML_acc );
     181           0 :             break;
     182             :         }
     183             :         case TOVERLINE:
     184             :         case TUNDERLINE:
     185           0 :             m_pSerializer->startElementNS( XML_m, XML_bar, FSEND );
     186           0 :             m_pSerializer->startElementNS( XML_m, XML_barPr, FSEND );
     187             :             m_pSerializer->singleElementNS( XML_m, XML_pos, FSNS( XML_m, XML_val ),
     188           0 :                 ( pNode->Attribute()->GetToken().eType == TUNDERLINE ) ? "bot" : "top", FSEND );
     189           0 :             m_pSerializer->endElementNS( XML_m, XML_barPr );
     190           0 :             m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     191           0 :             HandleNode( pNode->Body(), nLevel + 1 );
     192           0 :             m_pSerializer->endElementNS( XML_m, XML_e );
     193           0 :             m_pSerializer->endElementNS( XML_m, XML_bar );
     194           0 :             break;
     195             :         case TOVERSTRIKE:
     196           0 :             m_pSerializer->startElementNS( XML_m, XML_borderBox, FSEND );
     197           0 :             m_pSerializer->startElementNS( XML_m, XML_borderBoxPr, FSEND );
     198           0 :             m_pSerializer->singleElementNS( XML_m, XML_hideTop, FSNS( XML_m, XML_val ), "1", FSEND );
     199           0 :             m_pSerializer->singleElementNS( XML_m, XML_hideBot, FSNS( XML_m, XML_val ), "1", FSEND );
     200           0 :             m_pSerializer->singleElementNS( XML_m, XML_hideLeft, FSNS( XML_m, XML_val ), "1", FSEND );
     201           0 :             m_pSerializer->singleElementNS( XML_m, XML_hideRight, FSNS( XML_m, XML_val ), "1", FSEND );
     202           0 :             m_pSerializer->singleElementNS( XML_m, XML_strikeH, FSNS( XML_m, XML_val ), "1", FSEND );
     203           0 :             m_pSerializer->endElementNS( XML_m, XML_borderBoxPr );
     204           0 :             m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     205           0 :             HandleNode( pNode->Body(), nLevel + 1 );
     206           0 :             m_pSerializer->endElementNS( XML_m, XML_e );
     207           0 :             m_pSerializer->endElementNS( XML_m, XML_borderBox );
     208           0 :             break;
     209             :         default:
     210           0 :             HandleAllSubNodes( pNode, nLevel );
     211           0 :             break;
     212             :     }
     213           0 : }
     214             : 
     215           0 : void SmOoxmlExport::HandleRoot( const SmRootNode* pNode, int nLevel )
     216             : {
     217           0 :     m_pSerializer->startElementNS( XML_m, XML_rad, FSEND );
     218           0 :     if( const SmNode* argument = pNode->Argument())
     219             :     {
     220           0 :         m_pSerializer->startElementNS( XML_m, XML_deg, FSEND );
     221           0 :         HandleNode( argument, nLevel + 1 );
     222           0 :         m_pSerializer->endElementNS( XML_m, XML_deg );
     223             :     }
     224             :     else
     225             :     {
     226           0 :         m_pSerializer->startElementNS( XML_m, XML_radPr, FSEND );
     227           0 :         m_pSerializer->singleElementNS( XML_m, XML_degHide, FSNS( XML_m, XML_val ), "1", FSEND );
     228           0 :         m_pSerializer->endElementNS( XML_m, XML_radPr );
     229           0 :         m_pSerializer->singleElementNS( XML_m, XML_deg, FSEND ); // empty but present
     230             :     }
     231           0 :     m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     232           0 :     HandleNode( pNode->Body(), nLevel + 1 );
     233           0 :     m_pSerializer->endElementNS( XML_m, XML_e );
     234           0 :     m_pSerializer->endElementNS( XML_m, XML_rad );
     235           0 : }
     236             : 
     237           0 : static OString mathSymbolToString( const SmNode* node )
     238             : {
     239             :     assert( node->GetType() == NMATH || node->GetType() == NMATHIDENT );
     240           0 :     const SmTextNode* txtnode = static_cast< const SmTextNode* >( node );
     241             :     assert( txtnode->GetText().getLength() == 1 );
     242           0 :     sal_Unicode chr = SmTextNode::ConvertSymbolToUnicode( txtnode->GetText()[0] );
     243           0 :     return OUStringToOString( OUString( chr ), RTL_TEXTENCODING_UTF8 );
     244             : }
     245             : 
     246           0 : void SmOoxmlExport::HandleOperator( const SmOperNode* pNode, int nLevel )
     247             : {
     248             :     SAL_INFO( "starmath.ooxml", "Operator: " << int( pNode->GetToken().eType ));
     249           0 :     switch( pNode->GetToken().eType )
     250             :     {
     251             :         case TINT:
     252             :         case TINTD:
     253             :         case TIINT:
     254             :         case TIIINT:
     255             :         case TLINT:
     256             :         case TLLINT:
     257             :         case TLLLINT:
     258             :         case TPROD:
     259             :         case TCOPROD:
     260             :         case TSUM:
     261             :         {
     262           0 :             const SmSubSupNode* subsup = pNode->GetSubNode( 0 )->GetType() == NSUBSUP
     263           0 :                 ? static_cast< const SmSubSupNode* >( pNode->GetSubNode( 0 )) : NULL;
     264           0 :             const SmNode* operation = subsup != NULL ? subsup->GetBody() : pNode->GetSubNode( 0 );
     265           0 :             m_pSerializer->startElementNS( XML_m, XML_nary, FSEND );
     266           0 :             m_pSerializer->startElementNS( XML_m, XML_naryPr, FSEND );
     267             :             m_pSerializer->singleElementNS( XML_m, XML_chr,
     268           0 :                 FSNS( XML_m, XML_val ), mathSymbolToString( operation ).getStr(), FSEND );
     269           0 :             if( subsup == NULL || subsup->GetSubSup( CSUB ) == NULL )
     270           0 :                 m_pSerializer->singleElementNS( XML_m, XML_subHide, FSNS( XML_m, XML_val ), "1", FSEND );
     271           0 :             if( subsup == NULL || subsup->GetSubSup( CSUP ) == NULL )
     272           0 :                 m_pSerializer->singleElementNS( XML_m, XML_supHide, FSNS( XML_m, XML_val ), "1", FSEND );
     273           0 :             m_pSerializer->endElementNS( XML_m, XML_naryPr );
     274           0 :             if( subsup == NULL || subsup->GetSubSup( CSUB ) == NULL )
     275           0 :                 m_pSerializer->singleElementNS( XML_m, XML_sub, FSEND );
     276             :             else
     277             :             {
     278           0 :                 m_pSerializer->startElementNS( XML_m, XML_sub, FSEND );
     279           0 :                 HandleNode( subsup->GetSubSup( CSUB ), nLevel + 1 );
     280           0 :                 m_pSerializer->endElementNS( XML_m, XML_sub );
     281             :             }
     282           0 :             if( subsup == NULL || subsup->GetSubSup( CSUP ) == NULL )
     283           0 :                 m_pSerializer->singleElementNS( XML_m, XML_sup, FSEND );
     284             :             else
     285             :             {
     286           0 :                 m_pSerializer->startElementNS( XML_m, XML_sup, FSEND );
     287           0 :                 HandleNode( subsup->GetSubSup( CSUP ), nLevel + 1 );
     288           0 :                 m_pSerializer->endElementNS( XML_m, XML_sup );
     289             :             }
     290           0 :             m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     291           0 :             HandleNode( pNode->GetSubNode( 1 ), nLevel + 1 ); // body
     292           0 :             m_pSerializer->endElementNS( XML_m, XML_e );
     293           0 :             m_pSerializer->endElementNS( XML_m, XML_nary );
     294           0 :             break;
     295             :         }
     296             :         case TLIM:
     297           0 :             m_pSerializer->startElementNS( XML_m, XML_func, FSEND );
     298           0 :             m_pSerializer->startElementNS( XML_m, XML_fName, FSEND );
     299           0 :             m_pSerializer->startElementNS( XML_m, XML_limLow, FSEND );
     300           0 :             m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     301           0 :             HandleNode( pNode->GetSymbol(), nLevel + 1 );
     302           0 :             m_pSerializer->endElementNS( XML_m, XML_e );
     303           0 :             m_pSerializer->startElementNS( XML_m, XML_lim, FSEND );
     304           0 :             if( const SmSubSupNode* subsup = pNode->GetSubNode( 0 )->GetType() == NSUBSUP
     305           0 :                 ? static_cast< const SmSubSupNode* >( pNode->GetSubNode( 0 )) : NULL )
     306             :             {
     307           0 :                 if( subsup->GetSubSup( CSUB ) != NULL )
     308           0 :                     HandleNode( subsup->GetSubSup( CSUB ), nLevel + 1 );
     309             :             }
     310           0 :             m_pSerializer->endElementNS( XML_m, XML_lim );
     311           0 :             m_pSerializer->endElementNS( XML_m, XML_limLow );
     312           0 :             m_pSerializer->endElementNS( XML_m, XML_fName );
     313           0 :             m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     314           0 :             HandleNode( pNode->GetSubNode( 1 ), nLevel + 1 ); // body
     315           0 :             m_pSerializer->endElementNS( XML_m, XML_e );
     316           0 :             m_pSerializer->endElementNS( XML_m, XML_func );
     317           0 :             break;
     318             :         default:
     319             :             SAL_WARN("starmath.ooxml", "Unhandled operation");
     320           0 :             HandleAllSubNodes( pNode, nLevel );
     321           0 :             break;
     322             :     }
     323           0 : }
     324             : 
     325           0 : void SmOoxmlExport::HandleSubSupScriptInternal( const SmSubSupNode* pNode, int nLevel, int flags )
     326             : {
     327             : // docx supports only a certain combination of sub/super scripts, but LO can have any,
     328             : // so try to merge it using several tags if necessary
     329           0 :     if( flags == 0 ) // none
     330           0 :         return;
     331           0 :     if(( flags & ( 1 << RSUP | 1 << RSUB )) == ( 1 << RSUP | 1 << RSUB ))
     332             :     { // m:sSubSup
     333           0 :         m_pSerializer->startElementNS( XML_m, XML_sSubSup, FSEND );
     334           0 :         m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     335           0 :         flags &= ~( 1 << RSUP | 1 << RSUB );
     336           0 :         if( flags == 0 )
     337           0 :             HandleNode( pNode->GetBody(), nLevel + 1 );
     338             :         else
     339           0 :             HandleSubSupScriptInternal( pNode, nLevel, flags );
     340           0 :         m_pSerializer->endElementNS( XML_m, XML_e );
     341           0 :         m_pSerializer->startElementNS( XML_m, XML_sub, FSEND );
     342           0 :         HandleNode( pNode->GetSubSup( RSUB ), nLevel + 1 );
     343           0 :         m_pSerializer->endElementNS( XML_m, XML_sub );
     344           0 :         m_pSerializer->startElementNS( XML_m, XML_sup, FSEND );
     345           0 :         HandleNode( pNode->GetSubSup( RSUP ), nLevel + 1 );
     346           0 :         m_pSerializer->endElementNS( XML_m, XML_sup );
     347           0 :         m_pSerializer->endElementNS( XML_m, XML_sSubSup );
     348             :     }
     349           0 :     else if(( flags & ( 1 << RSUB )) == 1 << RSUB )
     350             :     { // m:sSub
     351           0 :         m_pSerializer->startElementNS( XML_m, XML_sSub, FSEND );
     352           0 :         m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     353           0 :         flags &= ~( 1 << RSUB );
     354           0 :         if( flags == 0 )
     355           0 :             HandleNode( pNode->GetBody(), nLevel + 1 );
     356             :         else
     357           0 :             HandleSubSupScriptInternal( pNode, nLevel, flags );
     358           0 :         m_pSerializer->endElementNS( XML_m, XML_e );
     359           0 :         m_pSerializer->startElementNS( XML_m, XML_sub, FSEND );
     360           0 :         HandleNode( pNode->GetSubSup( RSUB ), nLevel + 1 );
     361           0 :         m_pSerializer->endElementNS( XML_m, XML_sub );
     362           0 :         m_pSerializer->endElementNS( XML_m, XML_sSub );
     363             :     }
     364           0 :     else if(( flags & ( 1 << RSUP )) == 1 << RSUP )
     365             :     { // m:sSup
     366           0 :         m_pSerializer->startElementNS( XML_m, XML_sSup, FSEND );
     367           0 :         m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     368           0 :         flags &= ~( 1 << RSUP );
     369           0 :         if( flags == 0 )
     370           0 :             HandleNode( pNode->GetBody(), nLevel + 1 );
     371             :         else
     372           0 :             HandleSubSupScriptInternal( pNode, nLevel, flags );
     373           0 :         m_pSerializer->endElementNS( XML_m, XML_e );
     374           0 :         m_pSerializer->startElementNS( XML_m, XML_sup, FSEND );
     375           0 :         HandleNode( pNode->GetSubSup( RSUP ), nLevel + 1 );
     376           0 :         m_pSerializer->endElementNS( XML_m, XML_sup );
     377           0 :         m_pSerializer->endElementNS( XML_m, XML_sSup );
     378             :     }
     379           0 :     else if(( flags & ( 1 << LSUP | 1 << LSUB )) == ( 1 << LSUP | 1 << LSUB ))
     380             :     { // m:sPre
     381           0 :         m_pSerializer->startElementNS( XML_m, XML_sPre, FSEND );
     382           0 :         m_pSerializer->startElementNS( XML_m, XML_sub, FSEND );
     383           0 :         HandleNode( pNode->GetSubSup( LSUB ), nLevel + 1 );
     384           0 :         m_pSerializer->endElementNS( XML_m, XML_sub );
     385           0 :         m_pSerializer->startElementNS( XML_m, XML_sup, FSEND );
     386           0 :         HandleNode( pNode->GetSubSup( LSUP ), nLevel + 1 );
     387           0 :         m_pSerializer->endElementNS( XML_m, XML_sup );
     388           0 :         m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     389           0 :         flags &= ~( 1 << LSUP | 1 << LSUB );
     390           0 :         if( flags == 0 )
     391           0 :             HandleNode( pNode->GetBody(), nLevel + 1 );
     392             :         else
     393           0 :             HandleSubSupScriptInternal( pNode, nLevel, flags );
     394           0 :         m_pSerializer->endElementNS( XML_m, XML_e );
     395           0 :         m_pSerializer->endElementNS( XML_m, XML_sPre );
     396             :     }
     397           0 :     else if(( flags & ( 1 << CSUB )) == ( 1 << CSUB ))
     398             :     { // m:limLow looks like a good element for central superscript
     399           0 :         m_pSerializer->startElementNS( XML_m, XML_limLow, FSEND );
     400           0 :         m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     401           0 :         flags &= ~( 1 << CSUB );
     402           0 :         if( flags == 0 )
     403           0 :             HandleNode( pNode->GetBody(), nLevel + 1 );
     404             :         else
     405           0 :             HandleSubSupScriptInternal( pNode, nLevel, flags );
     406           0 :         m_pSerializer->endElementNS( XML_m, XML_e );
     407           0 :         m_pSerializer->startElementNS( XML_m, XML_lim, FSEND );
     408           0 :         HandleNode( pNode->GetSubSup( CSUB ), nLevel + 1 );
     409           0 :         m_pSerializer->endElementNS( XML_m, XML_lim );
     410           0 :         m_pSerializer->endElementNS( XML_m, XML_limLow );
     411             :     }
     412           0 :     else if(( flags & ( 1 << CSUP )) == ( 1 << CSUP ))
     413             :     { // m:limUpp looks like a good element for central superscript
     414           0 :         m_pSerializer->startElementNS( XML_m, XML_limUpp, FSEND );
     415           0 :         m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     416           0 :         flags &= ~( 1 << CSUP );
     417           0 :         if( flags == 0 )
     418           0 :             HandleNode( pNode->GetBody(), nLevel + 1 );
     419             :         else
     420           0 :             HandleSubSupScriptInternal( pNode, nLevel, flags );
     421           0 :         m_pSerializer->endElementNS( XML_m, XML_e );
     422           0 :         m_pSerializer->startElementNS( XML_m, XML_lim, FSEND );
     423           0 :         HandleNode( pNode->GetSubSup( CSUP ), nLevel + 1 );
     424           0 :         m_pSerializer->endElementNS( XML_m, XML_lim );
     425           0 :         m_pSerializer->endElementNS( XML_m, XML_limUpp );
     426             :     }
     427             :     else
     428             :     {
     429             :         SAL_WARN("starmath.ooxml", "Unhandled sub/sup combination");
     430             :         // TODO do not do anything, this should be probably an assert()
     431             :         // HandleAllSubNodes( pNode, nLevel );
     432             :     }
     433             : }
     434             : 
     435           0 : void SmOoxmlExport::HandleMatrix( const SmMatrixNode* pNode, int nLevel )
     436             : {
     437           0 :     m_pSerializer->startElementNS( XML_m, XML_m, FSEND );
     438           0 :     for( int row = 0; row < pNode->GetNumRows(); ++row )
     439             :     {
     440           0 :         m_pSerializer->startElementNS( XML_m, XML_mr, FSEND );
     441           0 :         for( int col = 0; col < pNode->GetNumCols(); ++col )
     442             :         {
     443           0 :             m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     444           0 :             if( const SmNode* node = pNode->GetSubNode( row * pNode->GetNumCols() + col ))
     445           0 :                 HandleNode( node, nLevel + 1 );
     446           0 :             m_pSerializer->endElementNS( XML_m, XML_e );
     447             :         }
     448           0 :         m_pSerializer->endElementNS( XML_m, XML_mr );
     449             :     }
     450           0 :     m_pSerializer->endElementNS( XML_m, XML_m );
     451           0 : }
     452             : 
     453           0 : void SmOoxmlExport::HandleBrace( const SmBraceNode* pNode, int nLevel )
     454             : {
     455           0 :     m_pSerializer->startElementNS( XML_m, XML_d, FSEND );
     456           0 :     m_pSerializer->startElementNS( XML_m, XML_dPr, FSEND );
     457             : 
     458             :     //check if the node has an opening brace
     459           0 :     if( TNONE == pNode->GetSubNode(0)->GetToken().eType )
     460             :         m_pSerializer->singleElementNS( XML_m, XML_begChr,
     461           0 :             FSNS( XML_m, XML_val ), "", FSEND );
     462             :     else
     463             :         m_pSerializer->singleElementNS( XML_m, XML_begChr,
     464           0 :             FSNS( XML_m, XML_val ), mathSymbolToString( pNode->OpeningBrace()).getStr(), FSEND );
     465             : 
     466           0 :     std::vector< const SmNode* > subnodes;
     467           0 :     if( pNode->Body()->GetType() == NBRACEBODY )
     468             :     {
     469           0 :         const SmBracebodyNode* body = static_cast< const SmBracebodyNode* >( pNode->Body());
     470           0 :         bool separatorWritten = false; // assume all separators are the same
     471           0 :         for( int i = 0; i < body->GetNumSubNodes(); ++i )
     472             :         {
     473           0 :             const SmNode* subnode = body->GetSubNode( i );
     474           0 :             if (subnode->GetType() == NMATH || subnode->GetType() == NMATHIDENT)
     475             :             { // do not write, but write what separator it is
     476           0 :                 const SmMathSymbolNode* math = static_cast< const SmMathSymbolNode* >( subnode );
     477           0 :                 if( !separatorWritten )
     478             :                 {
     479             :                     m_pSerializer->singleElementNS( XML_m, XML_sepChr,
     480           0 :                         FSNS( XML_m, XML_val ), mathSymbolToString( math ).getStr(), FSEND );
     481           0 :                     separatorWritten = true;
     482             :                 }
     483             :             }
     484             :             else
     485           0 :                 subnodes.push_back( subnode );
     486             :         }
     487             :     }
     488             :     else
     489           0 :         subnodes.push_back( pNode->Body());
     490             : 
     491           0 :     if( TNONE == pNode->GetSubNode(2)->GetToken().eType )
     492             :         m_pSerializer->singleElementNS( XML_m, XML_endChr,
     493           0 :             FSNS( XML_m, XML_val ), "", FSEND );
     494             :     else
     495             :         m_pSerializer->singleElementNS( XML_m, XML_endChr,
     496           0 :             FSNS( XML_m, XML_val ), mathSymbolToString( pNode->ClosingBrace()).getStr(), FSEND );
     497             : 
     498           0 :     m_pSerializer->endElementNS( XML_m, XML_dPr );
     499           0 :     for( unsigned int i = 0; i < subnodes.size(); ++i )
     500             :     {
     501           0 :         m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     502           0 :         HandleNode( subnodes[ i ], nLevel + 1 );
     503           0 :         m_pSerializer->endElementNS( XML_m, XML_e );
     504             :     }
     505           0 :     m_pSerializer->endElementNS( XML_m, XML_d );
     506           0 : }
     507             : 
     508           0 : void SmOoxmlExport::HandleVerticalBrace( const SmVerticalBraceNode* pNode, int nLevel )
     509             : {
     510             :     SAL_INFO( "starmath.ooxml", "Vertical: " << int( pNode->GetToken().eType ));
     511           0 :     switch( pNode->GetToken().eType )
     512             :     {
     513             :         case TOVERBRACE:
     514             :         case TUNDERBRACE:
     515             :         {
     516           0 :             bool top = ( pNode->GetToken().eType == TOVERBRACE );
     517           0 :             m_pSerializer->startElementNS( XML_m, top ? XML_limUpp : XML_limLow, FSEND );
     518           0 :             m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     519           0 :             m_pSerializer->startElementNS( XML_m, XML_groupChr, FSEND );
     520           0 :             m_pSerializer->startElementNS( XML_m, XML_groupChrPr, FSEND );
     521             :             m_pSerializer->singleElementNS( XML_m, XML_chr,
     522           0 :                 FSNS( XML_m, XML_val ), mathSymbolToString( pNode->Brace()).getStr(), FSEND );
     523             :             // TODO not sure if pos and vertJc are correct
     524             :             m_pSerializer->singleElementNS( XML_m, XML_pos,
     525           0 :                 FSNS( XML_m, XML_val ), top ? "top" : "bot", FSEND );
     526           0 :             m_pSerializer->singleElementNS( XML_m, XML_vertJc, FSNS( XML_m, XML_val ), top ? "bot" : "top", FSEND );
     527           0 :             m_pSerializer->endElementNS( XML_m, XML_groupChrPr );
     528           0 :             m_pSerializer->startElementNS( XML_m, XML_e, FSEND );
     529           0 :             HandleNode( pNode->Body(), nLevel + 1 );
     530           0 :             m_pSerializer->endElementNS( XML_m, XML_e );
     531           0 :             m_pSerializer->endElementNS( XML_m, XML_groupChr );
     532           0 :             m_pSerializer->endElementNS( XML_m, XML_e );
     533           0 :             m_pSerializer->startElementNS( XML_m, XML_lim, FSEND );
     534           0 :             HandleNode( pNode->Script(), nLevel + 1 );
     535           0 :             m_pSerializer->endElementNS( XML_m, XML_lim );
     536           0 :             m_pSerializer->endElementNS( XML_m, top ? XML_limUpp : XML_limLow );
     537           0 :             break;
     538             :         }
     539             :         default:
     540             :             SAL_WARN("starmath.ooxml", "Unhandled vertical brace");
     541           0 :             HandleAllSubNodes( pNode, nLevel );
     542           0 :             break;
     543             :     }
     544           0 : }
     545             : 
     546           0 : void SmOoxmlExport::HandleBlank()
     547             : {
     548           0 :     m_pSerializer->startElementNS( XML_m, XML_r, FSEND );
     549           0 :     m_pSerializer->startElementNS( XML_m, XML_t, FSNS( XML_xml, XML_space ), "preserve", FSEND );
     550           0 :     m_pSerializer->write( " " );
     551           0 :     m_pSerializer->endElementNS( XML_m, XML_t );
     552           0 :     m_pSerializer->endElementNS( XML_m, XML_r );
     553           0 : }
     554             : 
     555             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10