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-17 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          58 : SmRtfExport::SmRtfExport(const SmNode* pIn)
      37             :     : SmWordExportBase(pIn)
      38          58 :       , m_pBuffer(0)
      39             : {
      40          58 : }
      41             : 
      42          58 : bool SmRtfExport::ConvertFromStarMath(OStringBuffer& rBuffer, rtl_TextEncoding nEncoding)
      43             : {
      44          58 :     if (!m_pTree)
      45           0 :         return false;
      46          58 :     m_pBuffer = &rBuffer;
      47          58 :     m_nEncoding = nEncoding;
      48          58 :     m_pBuffer->append("{" OOO_STRING_SVTOOLS_RTF_IGNORE LO_STRING_SVTOOLS_RTF_MOMATH " ");
      49          58 :     HandleNode(m_pTree, 0);
      50          58 :     m_pBuffer->append("}"); // moMath
      51          58 :     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          10 : void SmRtfExport::HandleVerticalStack(const SmNode* pNode, int nLevel)
      58             : {
      59          10 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MEQARR " ");
      60          10 :     int size = pNode->GetNumSubNodes();
      61          32 :     for (int i = 0; i < size; ++i)
      62             :     {
      63          22 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
      64          22 :         HandleNode(pNode->GetSubNode( i ), nLevel + 1);
      65          22 :         m_pBuffer->append("}"); // me
      66             :     }
      67          10 :     m_pBuffer->append("}"); // meqArr
      68          10 : }
      69             : 
      70         512 : void SmRtfExport::HandleText(const SmNode* pNode, int /*nLevel*/)
      71             : {
      72         512 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MR " ");
      73             : 
      74         512 :     SmTextNode* pTemp=(SmTextNode* )pNode;
      75             :     SAL_INFO("starmath.rtf", "Text: " << pTemp->GetText());
      76        1110 :     for (sal_Int32 i = 0; i < pTemp->GetText().getLength(); i++)
      77             :     {
      78         598 :         sal_uInt16 nChar = pTemp->GetText()[i];
      79         598 :         OUString aValue(SmTextNode::ConvertSymbolToUnicode(nChar));
      80         598 :         m_pBuffer->append(msfilter::rtfutil::OutString(aValue, m_nEncoding));
      81         598 :     }
      82             : 
      83         512 :     m_pBuffer->append("}"); // mr
      84         512 : }
      85             : 
      86          30 : void SmRtfExport::HandleFractions(const SmNode* pNode, int nLevel, const char* type)
      87             : {
      88          30 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MF " ");
      89          30 :     if (type)
      90             :     {
      91           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MFPR " ");
      92           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MTYPE " ");
      93           2 :         m_pBuffer->append(type);
      94           2 :         m_pBuffer->append("}"); // mtype
      95           2 :         m_pBuffer->append("}"); // mfPr
      96             :     }
      97             :     OSL_ASSERT(pNode->GetNumSubNodes() == 3);
      98          30 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MNUM " ");
      99          30 :     HandleNode(pNode->GetSubNode(0), nLevel + 1);
     100          30 :     m_pBuffer->append("}"); // mnum
     101          30 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MDEN " ");
     102          30 :     HandleNode(pNode->GetSubNode(2), nLevel + 1);
     103          30 :     m_pBuffer->append("}"); // mden
     104          30 :     m_pBuffer->append("}"); // mf
     105          30 : }
     106             : 
     107          28 : void SmRtfExport::HandleAttribute(const SmAttributNode* pNode, int nLevel)
     108             : {
     109          28 :     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          24 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MACC " ");
     128          24 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MACCPR " ");
     129          24 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MCHR " ");
     130          24 :             OUString aValue(pNode->Attribute()->GetToken().cMathChar);
     131          24 :             m_pBuffer->append(msfilter::rtfutil::OutString(aValue, m_nEncoding));
     132          24 :             m_pBuffer->append("}"); // mchr
     133          24 :             m_pBuffer->append("}"); // maccPr
     134          24 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     135          24 :             HandleNode( pNode->Body(), nLevel + 1 );
     136          24 :             m_pBuffer->append("}"); // me
     137          24 :             m_pBuffer->append("}"); // macc
     138          24 :             break;
     139             :         }
     140             :         case TOVERLINE:
     141             :         case TUNDERLINE:
     142           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MBAR " ");
     143           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MBARPR " ");
     144           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MPOS " ");
     145           2 :             m_pBuffer->append((pNode->Attribute()->GetToken().eType == TUNDERLINE ) ? "bot" : "top");
     146           2 :             m_pBuffer->append("}"); // mpos
     147           2 :             m_pBuffer->append("}"); // mbarPr
     148           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     149           2 :             HandleNode( pNode->Body(), nLevel + 1 );
     150           2 :             m_pBuffer->append("}"); // me
     151           2 :             m_pBuffer->append("}"); // mbar
     152           2 :             break;
     153             :         case TOVERSTRIKE:
     154           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MBORDERBOX " ");
     155           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MBORDERBOXPR " ");
     156           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MHIDETOP " 1}");
     157           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MHIDEBOT " 1}");
     158           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MHIDELEFT " 1}");
     159           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MHIDERIGHT " 1}");
     160           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSTRIKEH " 1}");
     161           2 :             m_pBuffer->append("}"); // mborderBoxPr
     162           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     163           2 :             HandleNode( pNode->Body(), nLevel + 1 );
     164           2 :             m_pBuffer->append("}"); // me
     165           2 :             m_pBuffer->append("}"); // mborderBox
     166           2 :             break;
     167             :         default:
     168           0 :             HandleAllSubNodes( pNode, nLevel );
     169           0 :             break;
     170             :     }
     171          28 : }
     172             : 
     173           6 : void SmRtfExport::HandleRoot(const SmRootNode* pNode, int nLevel)
     174             : {
     175           6 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MRAD " ");
     176           6 :     if (const SmNode* argument = pNode->Argument())
     177             :     {
     178           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MDEG " ");
     179           2 :         HandleNode(argument, nLevel + 1);
     180           2 :         m_pBuffer->append("}"); // mdeg
     181             :     }
     182             :     else
     183             :     {
     184           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MRADPR " ");
     185           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MDEGHIDE " 1}");
     186           4 :         m_pBuffer->append("}"); // mradPr
     187           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MDEG " }"); // empty but present
     188             :     }
     189           6 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     190           6 :     HandleNode(pNode->Body(), nLevel + 1);
     191           6 :     m_pBuffer->append("}"); // me
     192           6 :     m_pBuffer->append("}"); // mrad
     193           6 : }
     194             : 
     195             : namespace {
     196         112 : OString mathSymbolToString(const SmNode* node, rtl_TextEncoding nEncoding)
     197             : {
     198             :     assert(node->GetType() == NMATH);
     199         112 :     const SmTextNode* txtnode = static_cast<const SmTextNode*>(node);
     200         112 :     if (txtnode->GetText().isEmpty())
     201           2 :         return OString();
     202             :     assert(txtnode->GetText().getLength() == 1);
     203         110 :     sal_Unicode chr = SmTextNode::ConvertSymbolToUnicode(txtnode->GetText()[0]);
     204         110 :     OUString aValue(chr);
     205         110 :     return msfilter::rtfutil::OutString(aValue, nEncoding);
     206             : }
     207             : }
     208             : 
     209          14 : void SmRtfExport::HandleOperator(const SmOperNode* pNode, int nLevel)
     210             : {
     211             :     SAL_INFO("starmath.rtf", "Operator: " << int(pNode->GetToken().eType));
     212          14 :     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          12 :             const SmSubSupNode* subsup = pNode->GetSubNode(0)->GetType() == NSUBSUP ? static_cast<const SmSubSupNode*>(pNode->GetSubNode(0)) : 0;
     225          12 :             const SmNode* operation = subsup ? subsup->GetBody() : pNode->GetSubNode(0);
     226          12 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MNARY " ");
     227          12 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MNARYPR " ");
     228          12 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MCHR " ");
     229          12 :             m_pBuffer->append(mathSymbolToString(operation, m_nEncoding));
     230          12 :             m_pBuffer->append("}"); // mchr
     231          12 :             if (!subsup || !subsup->GetSubSup(CSUB))
     232           2 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUBHIDE " 1}");
     233          12 :             if (!subsup || !subsup->GetSubSup(CSUP))
     234           2 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUPHIDE " 1}");
     235          12 :             m_pBuffer->append("}"); // mnaryPr
     236          12 :             if (!subsup || !subsup->GetSubSup(CSUB))
     237           2 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUB " }");
     238             :             else
     239             :             {
     240          10 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUB " ");
     241          10 :                 HandleNode(subsup->GetSubSup(CSUB), nLevel + 1);
     242          10 :                 m_pBuffer->append("}"); // msub
     243             :             }
     244          12 :             if (!subsup || !subsup->GetSubSup( CSUP ))
     245           2 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUP " }");
     246             :             else
     247             :             {
     248          10 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUP " ");
     249          10 :                 HandleNode(subsup->GetSubSup(CSUP), nLevel + 1);
     250          10 :                 m_pBuffer->append("}"); // msup
     251             :             }
     252          12 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     253          12 :             HandleNode(pNode->GetSubNode(1), nLevel + 1); // body
     254          12 :             m_pBuffer->append("}"); // me
     255          12 :             m_pBuffer->append("}"); // mnary
     256          12 :             break;
     257             :         }
     258             :         case TLIM:
     259           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MFUNC " ");
     260           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MFNAME " ");
     261           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIMLOW " ");
     262           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     263           2 :             HandleNode(pNode->GetSymbol(), nLevel + 1);
     264           2 :             m_pBuffer->append("}"); // me
     265           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIM " ");
     266           2 :             if (const SmSubSupNode* subsup = pNode->GetSubNode(0)->GetType() == NSUBSUP ? static_cast<const SmSubSupNode*>( pNode->GetSubNode(0)) : 0)
     267           2 :                 if (subsup->GetSubSup(CSUB))
     268           2 :                     HandleNode(subsup->GetSubSup(CSUB), nLevel + 1);
     269           2 :             m_pBuffer->append("}"); // mlim
     270           2 :             m_pBuffer->append("}"); // mlimLow
     271           2 :             m_pBuffer->append("}"); // mfName
     272           2 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     273           2 :             HandleNode(pNode->GetSubNode(1), nLevel + 1); // body
     274           2 :             m_pBuffer->append("}"); // me
     275           2 :             m_pBuffer->append("}"); // mfunc
     276           2 :             break;
     277             :         default:
     278             :             SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC << " unhandled oper type");
     279           0 :             break;
     280             :     }
     281          14 : }
     282             : 
     283          54 : 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          54 :     if (flags == 0) // none
     288          54 :         return;
     289          54 :     if ((flags & (1 << RSUP | 1 << RSUB)) == (1 << RSUP | 1 << RSUB))
     290             :     { // m:sSubSup
     291           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSSUBSUP " ");
     292           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     293           4 :         flags &= ~(1 << RSUP | 1 << RSUB);
     294           4 :         if (flags == 0)
     295           4 :             HandleNode(pNode->GetBody(), nLevel + 1);
     296             :         else
     297           0 :             HandleSubSupScriptInternal(pNode, nLevel, flags);
     298           4 :         m_pBuffer->append("}"); // me
     299           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUB " ");
     300           4 :         HandleNode(pNode->GetSubSup(RSUB), nLevel + 1);
     301           4 :         m_pBuffer->append("}"); // msub
     302           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUP " ");
     303           4 :         HandleNode(pNode->GetSubSup(RSUP ), nLevel + 1);
     304           4 :         m_pBuffer->append("}"); // msup
     305           4 :         m_pBuffer->append("}"); // msubSup
     306             :     }
     307          50 :     else if ((flags & (1 << RSUB)) == 1 << RSUB)
     308             :     { // m:sSub
     309           8 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSSUB " ");
     310           8 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     311           8 :         flags &= ~(1 << RSUB);
     312           8 :         if (flags == 0)
     313           8 :             HandleNode(pNode->GetBody(), nLevel + 1);
     314             :         else
     315           0 :             HandleSubSupScriptInternal(pNode, nLevel, flags);
     316           8 :         m_pBuffer->append("}"); // me
     317           8 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUB " ");
     318           8 :         HandleNode(pNode->GetSubSup(RSUB), nLevel + 1);
     319           8 :         m_pBuffer->append("}"); // msub
     320           8 :         m_pBuffer->append("}"); // msSub
     321             :     }
     322          42 :     else if ((flags & (1 << RSUP)) == 1 << RSUP)
     323             :     { // m:sSup
     324          34 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSSUP " ");
     325          34 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     326          34 :         flags &= ~(1 << RSUP);
     327          34 :         if (flags == 0)
     328          34 :             HandleNode(pNode->GetBody(), nLevel + 1);
     329             :         else
     330           0 :             HandleSubSupScriptInternal(pNode, nLevel, flags);
     331          34 :         m_pBuffer->append("}"); // me
     332          34 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUP " ");
     333          34 :         HandleNode(pNode->GetSubSup(RSUP), nLevel + 1);
     334          34 :         m_pBuffer->append("}"); // msup
     335          34 :         m_pBuffer->append("}"); // msSup
     336             :     }
     337           8 :     else if ((flags & (1 << LSUP | 1 << LSUB)) == (1 << LSUP | 1 << LSUB))
     338             :     { // m:sPre
     339           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSPRE " ");
     340           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUB " ");
     341           4 :         HandleNode(pNode->GetSubSup(LSUB ), nLevel + 1);
     342           4 :         m_pBuffer->append("}"); // msub
     343           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSUP " ");
     344           4 :         HandleNode(pNode->GetSubSup(LSUP), nLevel + 1);
     345           4 :         m_pBuffer->append("}"); // msup
     346           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     347           4 :         flags &= ~(1 << LSUP | 1 << LSUB);
     348           4 :         if (flags == 0)
     349           4 :             HandleNode(pNode->GetBody(), nLevel + 1);
     350             :         else
     351           0 :             HandleSubSupScriptInternal(pNode, nLevel, flags);
     352           4 :         m_pBuffer->append("}"); // me
     353           4 :         m_pBuffer->append("}"); // msPre
     354             :     }
     355           4 :     else if ((flags & (1 << CSUB)) == (1 << CSUB))
     356             :     { // m:limLow looks like a good element for central superscript
     357           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIMLOW " ");
     358           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     359           2 :         flags &= ~(1 << CSUB);
     360           2 :         if (flags == 0)
     361           0 :             HandleNode(pNode->GetBody(), nLevel + 1);
     362             :         else
     363           2 :             HandleSubSupScriptInternal(pNode, nLevel, flags);
     364           2 :         m_pBuffer->append("}"); // me
     365           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIM " ");
     366           2 :         HandleNode(pNode->GetSubSup(CSUB), nLevel + 1);
     367           2 :         m_pBuffer->append("}"); // mlim
     368           2 :         m_pBuffer->append("}"); // mlimLow
     369             :     }
     370           2 :     else if ((flags & (1 << CSUP)) == (1 << CSUP))
     371             :     { // m:limUpp looks like a good element for central superscript
     372           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIMUPP " ");
     373           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     374           2 :         flags &= ~(1 << CSUP);
     375           2 :         if (flags == 0)
     376           2 :             HandleNode(pNode->GetBody(), nLevel + 1);
     377             :         else
     378           0 :             HandleSubSupScriptInternal(pNode, nLevel, flags);
     379           2 :         m_pBuffer->append("}"); // me
     380           2 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIM " ");
     381           2 :         HandleNode(pNode->GetSubSup(CSUP), nLevel + 1);
     382           2 :         m_pBuffer->append("}"); // mlim
     383           2 :         m_pBuffer->append("}"); // mlimUpp
     384             :     }
     385             :     else
     386             :         SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC << " unhandled subsup type");
     387             : }
     388             : 
     389           2 : void SmRtfExport::HandleMatrix(const SmMatrixNode* pNode, int nLevel)
     390             : {
     391           2 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MM " ");
     392           6 :     for (int row = 0; row < pNode->GetNumRows(); ++row )
     393             :     {
     394           4 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MMR " ");
     395          12 :         for (int col = 0; col < pNode->GetNumCols(); ++col )
     396             :         {
     397           8 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     398           8 :             if (const SmNode* node = pNode->GetSubNode(row * pNode->GetNumCols() + col))
     399           8 :                 HandleNode(node, nLevel + 1);
     400           8 :             m_pBuffer->append("}"); // me
     401             :         }
     402           4 :         m_pBuffer->append("}"); // mmr
     403             :     }
     404           2 :     m_pBuffer->append("}"); // mm
     405           2 : }
     406             : 
     407          46 : void SmRtfExport::HandleBrace(const SmBraceNode* pNode, int nLevel)
     408             : {
     409          46 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MD " ");
     410          46 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MDPR " ");
     411          46 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MBEGCHR " ");
     412          46 :     m_pBuffer->append(mathSymbolToString(pNode->OpeningBrace(), m_nEncoding));
     413          46 :     m_pBuffer->append("}"); // mbegChr
     414          46 :     std::vector< const SmNode* > subnodes;
     415          46 :     if (pNode->Body()->GetType() == NBRACEBODY)
     416             :     {
     417          46 :         const SmBracebodyNode* body = static_cast<const SmBracebodyNode*>( pNode->Body());
     418          46 :         bool separatorWritten = false; // assume all separators are the same
     419         100 :         for (int i = 0; i < body->GetNumSubNodes(); ++i)
     420             :         {
     421          54 :             const SmNode* subnode = body->GetSubNode(i);
     422          54 :             if (subnode->GetType() == NMATH)
     423             :             { // do not write, but write what separator it is
     424           6 :                 const SmMathSymbolNode* math = static_cast<const SmMathSymbolNode*>(subnode);
     425           6 :                 if(!separatorWritten)
     426             :                 {
     427           4 :                     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MSEPCHR " ");
     428           4 :                     m_pBuffer->append(mathSymbolToString(math, m_nEncoding));
     429           4 :                     m_pBuffer->append("}"); // msepChr
     430           4 :                     separatorWritten = true;
     431             :                 }
     432             :             }
     433             :             else
     434          48 :                 subnodes.push_back(subnode);
     435             :         }
     436             :     }
     437             :     else
     438           0 :         subnodes.push_back(pNode->Body());
     439          46 :     m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MENDCHR " ");
     440          46 :     m_pBuffer->append(mathSymbolToString(pNode->ClosingBrace(), m_nEncoding));
     441          46 :     m_pBuffer->append("}"); // mendChr
     442          46 :     m_pBuffer->append("}"); // mdPr
     443          94 :     for (unsigned int i = 0; i < subnodes.size(); ++i)
     444             :     {
     445          48 :         m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     446          48 :         HandleNode(subnodes[ i ], nLevel + 1);
     447          48 :         m_pBuffer->append("}"); // me
     448             :     }
     449          46 :     m_pBuffer->append("}"); // md
     450          46 : }
     451             : 
     452           4 : void SmRtfExport::HandleVerticalBrace(const SmVerticalBraceNode* pNode, int nLevel)
     453             : {
     454             :     SAL_INFO("starmath.rtf", "Vertical: " << int(pNode->GetToken().eType));
     455           4 :     switch (pNode->GetToken().eType)
     456             :     {
     457             :         case TOVERBRACE:
     458             :         case TUNDERBRACE:
     459             :         {
     460           4 :             bool top = (pNode->GetToken().eType == TOVERBRACE);
     461           4 :             if (top)
     462           2 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIMUPP " ");
     463             :             else
     464           2 :                 m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIMLOW " ");
     465           4 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     466           4 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MGROUPCHR " ");
     467           4 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MGROUPCHRPR " ");
     468           4 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MCHR " ");
     469           4 :             m_pBuffer->append(mathSymbolToString(pNode->Brace(), m_nEncoding));
     470           4 :             m_pBuffer->append("}"); // mchr
     471             :             // TODO not sure if pos and vertJc are correct
     472           4 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MPOS " ").append(top ? "top" : "bot").append("}");
     473           4 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MVERTJC " ").append(top ? "bot" : "top").append("}");
     474           4 :             m_pBuffer->append("}"); // mgroupChrPr
     475           4 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_ME " ");
     476           4 :             HandleNode(pNode->Body(), nLevel + 1);
     477           4 :             m_pBuffer->append("}"); // me
     478           4 :             m_pBuffer->append("}"); // mgroupChr
     479           4 :             m_pBuffer->append("}"); // me
     480           4 :             m_pBuffer->append("{" LO_STRING_SVTOOLS_RTF_MLIM " ");
     481           4 :             HandleNode(pNode->Script(), nLevel + 1);
     482           4 :             m_pBuffer->append("}"); // mlim
     483           4 :             m_pBuffer->append("}"); // mlimUpp or mlimLow
     484           4 :             break;
     485             :         }
     486             :         default:
     487             :             SAL_INFO("starmath.rtf", "TODO: " << OSL_THIS_FUNC << " unhandled vertical brace type");
     488           0 :             break;
     489             :     }
     490           4 : }
     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