LCOV - code coverage report
Current view: top level - libreoffice/starmath/source - rtfexport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 298 315 94.6 %
Date: 2012-12-27 Functions: 13 14 92.9 %
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             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License or as specified alternatively below. You may obtain a copy of
       8             :  * the License at http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * Major Contributor(s):
      16             :  * Copyright (C) 2012 Miklos Vajna <vmiklos@suse.cz> (SUSE, Inc.)
      17             :  *
      18             :  * All Rights Reserved.
      19             :  *
      20             :  * For minor contributions see the git repository.
      21             :  *
      22             :  * Alternatively, the contents of this file may be used under the terms of
      23             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26             :  * instead of those above.
      27             :  */
      28             : 
      29             : 
      30             : #include "rtfexport.hxx"
      31             : 
      32             : #include <rtl/ustring.hxx>
      33             : #include <svtools/rtfkeywd.hxx>
      34             : #include <filter/msfilter/rtfutil.hxx>
      35             : 
      36          29 : SmRtfExport::SmRtfExport(const SmNode* pIn)
      37             :     : SmWordExportBase(pIn)
      38          29 :       , m_pBuffer(0)
      39             : {
      40          29 : }
      41             : 
      42          29 : bool SmRtfExport::ConvertFromStarMath(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding)
      43             : {
      44          29 :     if (!m_pTree)
      45           0 :         return false;
      46          29 :     m_pBuffer = &rBuffer;
      47          29 :     m_nEncoding = nEncoding;
      48          29 :     m_pBuffer->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE LO_STRING_SVTOOLS_RTF_MOMATH " ");
      49          29 :     HandleNode(m_pTree, 0);
      50          29 :     m_pBuffer->append("}"); // moMath
      51          29 :     return true;
      52             : }
      53             : 
      54             : // NOTE: This is still work in progress and unfinished, but it already covers a good
      55             : // part of the rtf math stuff.
      56             : 
      57           5 : void SmRtfExport::HandleVerticalStack(const SmNode* pNode, int nLevel)
      58             : {
      59           5 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MEQARR " ");
      60           5 :     int size = pNode->GetNumSubNodes();
      61          16 :     for (int i = 0; i < size; ++i)
      62             :     {
      63          11 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
      64          11 :         HandleNode(pNode->GetSubNode( i ), nLevel + 1);
      65          11 :         m_pBuffer->append("}"); // me
      66             :     }
      67           5 :     m_pBuffer->append("}"); // meqArr
      68           5 : }
      69             : 
      70         256 : void SmRtfExport::HandleText(const SmNode* pNode, int /*nLevel*/)
      71             : {
      72         256 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MR " ");
      73             : 
      74         256 :     SmTextNode* pTemp=(SmTextNode* )pNode;
      75             :     SAL_INFO("starmath.rtf", "Text: " << pTemp->GetText());
      76         555 :     for (sal_Int32 i = 0; i < pTemp->GetText().getLength(); i++)
      77             :     {
      78         299 :         sal_uInt16 nChar = pTemp->GetText()[i];
      79         299 :         OUString aValue(SmTextNode::ConvertSymbolToUnicode(nChar));
      80         299 :         m_pBuffer->append(msfilter::rtfutil::OutString(aValue, m_nEncoding));
      81         299 :     }
      82             : 
      83         256 :     m_pBuffer->append("}"); // mr
      84         256 : }
      85             : 
      86          15 : void SmRtfExport::HandleFractions(const SmNode* pNode, int nLevel, const char* type)
      87             : {
      88          15 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MF " ");
      89          15 :     if (type)
      90             :     {
      91           1 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MFPR " ");
      92           1 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MTYPE " ");
      93           1 :         m_pBuffer->append(type);
      94           1 :         m_pBuffer->append("}"); // mtype
      95           1 :         m_pBuffer->append("}"); // mfPr
      96             :     }
      97             :     OSL_ASSERT(pNode->GetNumSubNodes() == 3);
      98          15 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MNUM " ");
      99          15 :     HandleNode(pNode->GetSubNode(0), nLevel + 1);
     100          15 :     m_pBuffer->append("}"); // mnum
     101          15 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MDEN " ");
     102          15 :     HandleNode(pNode->GetSubNode(2), nLevel + 1);
     103          15 :     m_pBuffer->append("}"); // mden
     104          15 :     m_pBuffer->append("}"); // mf
     105          15 : }
     106             : 
     107          14 : void SmRtfExport::HandleAttribute(const SmAttributNode* pNode, int nLevel)
     108             : {
     109          14 :     switch (pNode->Attribute()->GetToken().eType)
     110             :     {
     111             :         case TCHECK:
     112             :         case TACUTE:
     113             :         case TGRAVE:
     114             :         case TBREVE:
     115             :         case TCIRCLE:
     116             :         case TVEC:
     117             :         case TTILDE:
     118             :         case THAT:
     119             :         case TDOT:
     120             :         case TDDOT:
     121             :         case TDDDOT:
     122             :         case TWIDETILDE:
     123             :         case TWIDEHAT:
     124             :         case TWIDEVEC:
     125             :         case TBAR:
     126             :         {
     127          12 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MACC " ");
     128          12 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MACCPR " ");
     129          12 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MCHR " ");
     130          12 :             OUString aValue(pNode->Attribute()->GetToken().cMathChar);
     131          12 :             m_pBuffer->append(msfilter::rtfutil::OutString(aValue, m_nEncoding));
     132          12 :             m_pBuffer->append("}"); // mchr
     133          12 :             m_pBuffer->append("}"); // maccPr
     134          12 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     135          12 :             HandleNode( pNode->Body(), nLevel + 1 );
     136          12 :             m_pBuffer->append("}"); // me
     137          12 :             m_pBuffer->append("}"); // macc
     138          12 :             break;
     139             :         }
     140             :         case TOVERLINE:
     141             :         case TUNDERLINE:
     142           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MBAR " ");
     143           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MBARPR " ");
     144           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MPOS " ");
     145           1 :             m_pBuffer->append((pNode->Attribute()->GetToken().eType == TUNDERLINE ) ? "bot" : "top");
     146           1 :             m_pBuffer->append("}"); // mpos
     147           1 :             m_pBuffer->append("}"); // mbarPr
     148           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     149           1 :             HandleNode( pNode->Body(), nLevel + 1 );
     150           1 :             m_pBuffer->append("}"); // me
     151           1 :             m_pBuffer->append("}"); // mbar
     152           1 :             break;
     153             :         case TOVERSTRIKE:
     154           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MBORDERBOX " ");
     155           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MBORDERBOXPR " ");
     156           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MHIDETOP " 1}");
     157           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MHIDEBOT " 1}");
     158           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MHIDELEFT " 1}");
     159           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MHIDERIGHT " 1}");
     160           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSTRIKEH " 1}");
     161           1 :             m_pBuffer->append("}"); // mborderBoxPr
     162           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     163           1 :             HandleNode( pNode->Body(), nLevel + 1 );
     164           1 :             m_pBuffer->append("}"); // me
     165           1 :             m_pBuffer->append("}"); // mborderBox
     166           1 :             break;
     167             :         default:
     168           0 :             HandleAllSubNodes( pNode, nLevel );
     169           0 :             break;
     170             :     }
     171          14 : }
     172             : 
     173           3 : void SmRtfExport::HandleRoot(const SmRootNode* pNode, int nLevel)
     174             : {
     175           3 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MRAD " ");
     176           3 :     if (const SmNode* argument = pNode->Argument())
     177             :     {
     178           1 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MDEG " ");
     179           1 :         HandleNode(argument, nLevel + 1);
     180           1 :         m_pBuffer->append("}"); // mdeg
     181             :     }
     182             :     else
     183             :     {
     184           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MRADPR " ");
     185           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MDEGHIDE " 1}");
     186           2 :         m_pBuffer->append("}"); // mradPr
     187           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MDEG " }"); // empty but present
     188             :     }
     189           3 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     190           3 :     HandleNode(pNode->Body(), nLevel + 1);
     191           3 :     m_pBuffer->append("}"); // me
     192           3 :     m_pBuffer->append("}"); // mrad
     193           3 : }
     194             : 
     195             : namespace {
     196          56 : OString mathSymbolToString(const SmNode* node, rtl_TextEncoding nEncoding)
     197             : {
     198             :     assert(node->GetType() == NMATH);
     199          56 :     const SmTextNode* txtnode = static_cast<const SmTextNode*>(node);
     200          56 :     if (txtnode->GetText().isEmpty())
     201           1 :         return OString();
     202             :     assert(txtnode->GetText().getLength() == 1);
     203          55 :     sal_Unicode chr = SmTextNode::ConvertSymbolToUnicode(txtnode->GetText()[0]);
     204          55 :     OUString aValue(chr);
     205          55 :     return msfilter::rtfutil::OutString(aValue, nEncoding);
     206             : }
     207             : }
     208             : 
     209           7 : void SmRtfExport::HandleOperator(const SmOperNode* pNode, int nLevel)
     210             : {
     211             :     SAL_INFO("starmath.rtf", "Operator: " << int(pNode->GetToken().eType));
     212           7 :     switch (pNode->GetToken().eType)
     213             :     {
     214             :         case TINT:
     215             :         case TIINT:
     216             :         case TIIINT:
     217             :         case TLINT:
     218             :         case TLLINT:
     219             :         case TLLLINT:
     220             :         case TPROD:
     221             :         case TCOPROD:
     222             :         case TSUM:
     223             :         {
     224           6 :             const SmSubSupNode* subsup = pNode->GetSubNode(0)->GetType() == NSUBSUP ? static_cast<const SmSubSupNode*>(pNode->GetSubNode(0)) : 0;
     225           6 :             const SmNode* operation = subsup ? subsup->GetBody() : pNode->GetSubNode(0);
     226           6 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MNARY " ");
     227           6 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MNARYPR " ");
     228           6 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MCHR " ");
     229           6 :             m_pBuffer->append(mathSymbolToString(operation, m_nEncoding));
     230           6 :             m_pBuffer->append("}"); // mchr
     231           6 :             if (!subsup || !subsup->GetSubSup(CSUB))
     232           1 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUBHIDE " 1}");
     233           6 :             if (!subsup || !subsup->GetSubSup(CSUP))
     234           1 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUPHIDE " 1}");
     235           6 :             m_pBuffer->append("}"); // mnaryPr
     236           6 :             if (!subsup || !subsup->GetSubSup(CSUB))
     237           1 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUB " }");
     238             :             else
     239             :             {
     240           5 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUB " ");
     241           5 :                 HandleNode(subsup->GetSubSup(CSUB), nLevel + 1);
     242           5 :                 m_pBuffer->append("}"); // msub
     243             :             }
     244           6 :             if (!subsup || !subsup->GetSubSup( CSUP ))
     245           1 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUP " }");
     246             :             else
     247             :             {
     248           5 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUP " ");
     249           5 :                 HandleNode(subsup->GetSubSup(CSUP), nLevel + 1);
     250           5 :                 m_pBuffer->append("}"); // msup
     251             :             }
     252           6 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     253           6 :             HandleNode(pNode->GetSubNode(1), nLevel + 1); // body
     254           6 :             m_pBuffer->append("}"); // me
     255           6 :             m_pBuffer->append("}"); // mnary
     256           6 :             break;
     257             :         }
     258             :         case TLIM:
     259           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MFUNC " ");
     260           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MFNAME " ");
     261           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIMLOW " ");
     262           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     263           1 :             HandleNode(pNode->GetSymbol(), nLevel + 1);
     264           1 :             m_pBuffer->append("}"); // me
     265           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIM " ");
     266           1 :             if (const SmSubSupNode* subsup = pNode->GetSubNode(0)->GetType() == NSUBSUP ? static_cast<const SmSubSupNode*>( pNode->GetSubNode(0)) : 0)
     267           1 :                 if (subsup->GetSubSup(CSUB))
     268           1 :                     HandleNode(subsup->GetSubSup(CSUB), nLevel + 1);
     269           1 :             m_pBuffer->append("}"); // mlim
     270           1 :             m_pBuffer->append("}"); // mlimLow
     271           1 :             m_pBuffer->append("}"); // mfName
     272           1 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     273           1 :             HandleNode(pNode->GetSubNode(1), nLevel + 1); // body
     274           1 :             m_pBuffer->append("}"); // me
     275           1 :             m_pBuffer->append("}"); // mfunc
     276           1 :             break;
     277             :         default:
     278             :             SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC << " unhandled oper type");
     279           0 :             break;
     280             :     }
     281           7 : }
     282             : 
     283          27 : void SmRtfExport::HandleSubSupScriptInternal(const SmSubSupNode* pNode, int nLevel, int flags)
     284             : {
     285             : // rtf supports only a certain combination of sub/super scripts, but LO can have any,
     286             : // so try to merge it using several tags if necessary
     287          27 :     if (flags == 0) // none
     288          27 :         return;
     289          27 :     if ((flags & (1 << RSUP | 1 << RSUB)) == (1 << RSUP | 1 << RSUB))
     290             :     { // m:sSubSup
     291           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSSUBSUP " ");
     292           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     293           2 :         flags &= ~(1 << RSUP | 1 << RSUB);
     294           2 :         if (flags == 0)
     295           2 :             HandleNode(pNode->GetBody(), nLevel + 1);
     296             :         else
     297           0 :             HandleSubSupScriptInternal(pNode, nLevel, flags);
     298           2 :         m_pBuffer->append("}"); // me
     299           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUB " ");
     300           2 :         HandleNode(pNode->GetSubSup(RSUB), nLevel + 1);
     301           2 :         m_pBuffer->append("}"); // msub
     302           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUP " ");
     303           2 :         HandleNode(pNode->GetSubSup(RSUP ), nLevel + 1);
     304           2 :         m_pBuffer->append("}"); // msup
     305           2 :         m_pBuffer->append("}"); // msubSup
     306             :     }
     307          25 :     else if ((flags & (1 << RSUB)) == 1 << RSUB)
     308             :     { // m:sSub
     309           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSSUB " ");
     310           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     311           4 :         flags &= ~(1 << RSUB);
     312           4 :         if (flags == 0)
     313           4 :             HandleNode(pNode->GetBody(), nLevel + 1);
     314             :         else
     315           0 :             HandleSubSupScriptInternal(pNode, nLevel, flags);
     316           4 :         m_pBuffer->append("}"); // me
     317           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUB " ");
     318           4 :         HandleNode(pNode->GetSubSup(RSUB), nLevel + 1);
     319           4 :         m_pBuffer->append("}"); // msub
     320           4 :         m_pBuffer->append("}"); // msSub
     321             :     }
     322          21 :     else if ((flags & (1 << RSUP)) == 1 << RSUP)
     323             :     { // m:sSup
     324          17 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSSUP " ");
     325          17 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     326          17 :         flags &= ~(1 << RSUP);
     327          17 :         if (flags == 0)
     328          17 :             HandleNode(pNode->GetBody(), nLevel + 1);
     329             :         else
     330           0 :             HandleSubSupScriptInternal(pNode, nLevel, flags);
     331          17 :         m_pBuffer->append("}"); // me
     332          17 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUP " ");
     333          17 :         HandleNode(pNode->GetSubSup(RSUP), nLevel + 1);
     334          17 :         m_pBuffer->append("}"); // msup
     335          17 :         m_pBuffer->append("}"); // msSup
     336             :     }
     337           4 :     else if ((flags & (1 << LSUP | 1 << LSUB)) == (1 << LSUP | 1 << LSUB))
     338             :     { // m:sPre
     339           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSPRE " ");
     340           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUB " ");
     341           2 :         HandleNode(pNode->GetSubSup(LSUB ), nLevel + 1);
     342           2 :         m_pBuffer->append("}"); // msub
     343           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUP " ");
     344           2 :         HandleNode(pNode->GetSubSup(LSUP), nLevel + 1);
     345           2 :         m_pBuffer->append("}"); // msup
     346           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     347           2 :         flags &= ~(1 << LSUP | 1 << LSUB);
     348           2 :         if (flags == 0)
     349           2 :             HandleNode(pNode->GetBody(), nLevel + 1);
     350             :         else
     351           0 :             HandleSubSupScriptInternal(pNode, nLevel, flags);
     352           2 :         m_pBuffer->append("}"); // me
     353           2 :         m_pBuffer->append("}"); // msPre
     354             :     }
     355           2 :     else if ((flags & (1 << CSUB)) == (1 << CSUB))
     356             :     { // m:limLow looks like a good element for central superscript
     357           1 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIMLOW " ");
     358           1 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     359           1 :         flags &= ~(1 << CSUB);
     360           1 :         if (flags == 0)
     361           0 :             HandleNode(pNode->GetBody(), nLevel + 1);
     362             :         else
     363           1 :             HandleSubSupScriptInternal(pNode, nLevel, flags);
     364           1 :         m_pBuffer->append("}"); // me
     365           1 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIM " ");
     366           1 :         HandleNode(pNode->GetSubSup(CSUB), nLevel + 1);
     367           1 :         m_pBuffer->append("}"); // mlim
     368           1 :         m_pBuffer->append("}"); // mlimLow
     369             :     }
     370           1 :     else if ((flags & (1 << CSUP)) == (1 << CSUP))
     371             :     { // m:limUpp looks like a good element for central superscript
     372           1 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIMUPP " ");
     373           1 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     374           1 :         flags &= ~(1 << CSUP);
     375           1 :         if (flags == 0)
     376           1 :             HandleNode(pNode->GetBody(), nLevel + 1);
     377             :         else
     378           0 :             HandleSubSupScriptInternal(pNode, nLevel, flags);
     379           1 :         m_pBuffer->append("}"); // me
     380           1 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIM " ");
     381           1 :         HandleNode(pNode->GetSubSup(CSUP), nLevel + 1);
     382           1 :         m_pBuffer->append("}"); // mlim
     383           1 :         m_pBuffer->append("}"); // mlimUpp
     384             :     }
     385             :     else
     386             :         SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC << " unhandled subsup type");
     387             : }
     388             : 
     389           1 : void SmRtfExport::HandleMatrix(const SmMatrixNode* pNode, int nLevel)
     390             : {
     391           1 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MM " ");
     392           3 :     for (int row = 0; row < pNode->GetNumRows(); ++row )
     393             :     {
     394           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MMR " ");
     395           6 :         for (int col = 0; col < pNode->GetNumCols(); ++col )
     396             :         {
     397           4 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     398           4 :             if (const SmNode* node = pNode->GetSubNode(row * pNode->GetNumCols() + col))
     399           4 :                 HandleNode(node, nLevel + 1);
     400           4 :             m_pBuffer->append("}"); // me
     401             :         }
     402           2 :         m_pBuffer->append("}"); // mmr
     403             :     }
     404           1 :     m_pBuffer->append("}"); // mm
     405           1 : }
     406             : 
     407          23 : void SmRtfExport::HandleBrace(const SmBraceNode* pNode, int nLevel)
     408             : {
     409          23 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MD " ");
     410          23 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MDPR " ");
     411          23 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MBEGCHR " ");
     412          23 :     m_pBuffer->append(mathSymbolToString(pNode->OpeningBrace(), m_nEncoding));
     413          23 :     m_pBuffer->append("}"); // mbegChr
     414          23 :     std::vector< const SmNode* > subnodes;
     415          23 :     if (pNode->Body()->GetType() == NBRACEBODY)
     416             :     {
     417          23 :         const SmBracebodyNode* body = static_cast<const SmBracebodyNode*>( pNode->Body());
     418          23 :         bool separatorWritten = false; // assume all separators are the same
     419          50 :         for (int i = 0; i < body->GetNumSubNodes(); ++i)
     420             :         {
     421          27 :             const SmNode* subnode = body->GetSubNode(i);
     422          27 :             if (subnode->GetType() == NMATH)
     423             :             { // do not write, but write what separator it is
     424           3 :                 const SmMathSymbolNode* math = static_cast<const SmMathSymbolNode*>(subnode);
     425           3 :                 if(!separatorWritten)
     426             :                 {
     427           2 :                     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSEPCHR " ");
     428           2 :                     m_pBuffer->append(mathSymbolToString(math, m_nEncoding));
     429           2 :                     m_pBuffer->append("}"); // msepChr
     430           2 :                     separatorWritten = true;
     431             :                 }
     432             :             }
     433             :             else
     434          24 :                 subnodes.push_back(subnode);
     435             :         }
     436             :     }
     437             :     else
     438           0 :         subnodes.push_back(pNode->Body());
     439          23 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MENDCHR " ");
     440          23 :     m_pBuffer->append(mathSymbolToString(pNode->ClosingBrace(), m_nEncoding));
     441          23 :     m_pBuffer->append("}"); // mendChr
     442          23 :     m_pBuffer->append("}"); // mdPr
     443          47 :     for (unsigned int i = 0; i < subnodes.size(); ++i)
     444             :     {
     445          24 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     446          24 :         HandleNode(subnodes[ i ], nLevel + 1);
     447          24 :         m_pBuffer->append("}"); // me
     448             :     }
     449          23 :     m_pBuffer->append("}"); // md
     450          23 : }
     451             : 
     452           2 : void SmRtfExport::HandleVerticalBrace(const SmVerticalBraceNode* pNode, int nLevel)
     453             : {
     454             :     SAL_INFO("starmath.rtf", "Vertical: " << int(pNode->GetToken().eType));
     455           2 :     switch (pNode->GetToken().eType)
     456             :     {
     457             :         case TOVERBRACE:
     458             :         case TUNDERBRACE:
     459             :         {
     460           2 :             bool top = (pNode->GetToken().eType == TOVERBRACE);
     461           2 :             if (top)
     462           1 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIMUPP " ");
     463             :             else
     464           1 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIMLOW " ");
     465           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     466           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MGROUPCHR " ");
     467           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MGROUPCHRPR " ");
     468           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MCHR " ");
     469           2 :             m_pBuffer->append(mathSymbolToString(pNode->Brace(), m_nEncoding));
     470           2 :             m_pBuffer->append("}"); // mchr
     471             :             // TODO not sure if pos and vertJc are correct
     472           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MPOS " ").append(top ? "top" : "bot").append("}");
     473           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MVERTJC " ").append(top ? "bot" : "top").append("}");
     474           2 :             m_pBuffer->append("}"); // mgroupChrPr
     475           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     476           2 :             HandleNode(pNode->Body(), nLevel + 1);
     477           2 :             m_pBuffer->append("}"); // me
     478           2 :             m_pBuffer->append("}"); // mgroupChr
     479           2 :             m_pBuffer->append("}"); // me
     480           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIM " ");
     481           2 :             HandleNode(pNode->Script(), nLevel + 1);
     482           2 :             m_pBuffer->append("}"); // mlim
     483           2 :             m_pBuffer->append("}"); // mlimUpp or mlimLow
     484           2 :             break;
     485             :         }
     486             :         default:
     487             :             SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC << " unhandled vertical brace type");
     488           0 :             break;
     489             :     }
     490           2 : }
     491             : 
     492           0 : void SmRtfExport::HandleBlank()
     493             : {
     494           0 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MR " ");
     495           0 :     m_pBuffer->append(" ");
     496           0 :     m_pBuffer->append("}"); // mr
     497           0 : }
     498             : 
     499             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10