LCOV - code coverage report
Current view: top level - starmath/source - rtfexport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 298 315 94.6 %
Date: 2012-08-25 Functions: 13 14 92.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 134 215 62.3 %

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