LCOV - code coverage report
Current view: top level - svtools/source/svrtf - rtfout.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 79 0.0 %
Date: 2012-08-25 Functions: 0 3 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 73 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <tools/debug.hxx>
      30                 :            : #include <tools/stream.hxx>
      31                 :            : #include <tools/string.hxx>
      32                 :            : #include <rtl/string.hxx>
      33                 :            : #include <rtl/ustrbuf.hxx>
      34                 :            : #include <svtools/rtfkeywd.hxx>
      35                 :            : #include <svtools/rtfout.hxx>
      36                 :            : 
      37                 :            : using ::rtl::OUString;
      38                 :            : using ::rtl::OString;
      39                 :            : 
      40                 :            : #if defined(UNX)
      41                 :            : const sal_Char RTFOutFuncs::sNewLine = '\012';
      42                 :            : #else
      43                 :            : const sal_Char RTFOutFuncs::sNewLine[] = "\015\012";
      44                 :            : #endif
      45                 :            : 
      46                 :            : 
      47                 :          0 : SvStream& RTFOutFuncs::Out_Char(SvStream& rStream, sal_Unicode c,
      48                 :            :     int *pUCMode, rtl_TextEncoding eDestEnc, sal_Bool bWriteHelpFile)
      49                 :            : {
      50                 :          0 :     const sal_Char* pStr = 0;
      51   [ #  #  #  #  :          0 :     switch (c)
                #  #  # ]
      52                 :            :     {
      53                 :            :     case 0x1:
      54                 :            :     case 0x2:
      55                 :            :         // this are control character of our textattributes and will never be
      56                 :            :         // written
      57                 :          0 :         break;
      58                 :            :     case 0xA0:
      59                 :          0 :         rStream << "\\~";
      60                 :          0 :         break;
      61                 :            :     case 0xAD:
      62                 :          0 :         rStream << "\\-";
      63                 :          0 :         break;
      64                 :            :     case 0x2011:
      65                 :          0 :         rStream << "\\_";
      66                 :          0 :         break;
      67                 :            :     case '\n':
      68                 :          0 :         pStr = OOO_STRING_SVTOOLS_RTF_LINE;
      69                 :          0 :         break;
      70                 :            :     case '\t':
      71                 :          0 :         pStr = OOO_STRING_SVTOOLS_RTF_TAB;
      72                 :          0 :         break;
      73                 :            :     default:
      74         [ #  # ]:          0 :         if(!bWriteHelpFile)
      75                 :            :         {
      76   [ #  #  #  #  :          0 :             switch(c)
             #  #  #  # ]
      77                 :            :             {
      78                 :            :                 case 149:
      79                 :          0 :                     pStr = OOO_STRING_SVTOOLS_RTF_BULLET;
      80                 :          0 :                     break;
      81                 :            :                 case 150:
      82                 :          0 :                     pStr = OOO_STRING_SVTOOLS_RTF_ENDASH;
      83                 :          0 :                     break;
      84                 :            :                 case 151:
      85                 :          0 :                     pStr = OOO_STRING_SVTOOLS_RTF_EMDASH;
      86                 :          0 :                     break;
      87                 :            :                 case 145:
      88                 :          0 :                     pStr = OOO_STRING_SVTOOLS_RTF_LQUOTE;
      89                 :          0 :                     break;
      90                 :            :                 case 146:
      91                 :          0 :                     pStr = OOO_STRING_SVTOOLS_RTF_RQUOTE;
      92                 :          0 :                     break;
      93                 :            :                 case 147:
      94                 :          0 :                     pStr = OOO_STRING_SVTOOLS_RTF_LDBLQUOTE;
      95                 :          0 :                     break;
      96                 :            :                 case 148:
      97                 :          0 :                     pStr = OOO_STRING_SVTOOLS_RTF_RDBLQUOTE;
      98                 :          0 :                     break;
      99                 :            :             }
     100                 :            : 
     101         [ #  # ]:          0 :             if (pStr)
     102                 :          0 :                 break;
     103                 :            :         }
     104                 :            : 
     105         [ #  # ]:          0 :         switch (c)
     106                 :            :         {
     107                 :            :             case '\\':
     108                 :            :             case '}':
     109                 :            :             case '{':
     110                 :          0 :                 rStream << '\\' << (sal_Char)c;
     111                 :          0 :                 break;
     112                 :            :             default:
     113 [ #  # ][ #  # ]:          0 :                 if (c >= ' ' && c <= '~')
     114                 :          0 :                     rStream << (sal_Char)c;
     115                 :            :                 else
     116                 :            :                 {
     117                 :            :                     //If we can't convert to the dest encoding, or if
     118                 :            :                     //its an uncommon multibyte sequence which most
     119                 :            :                     //readers won't be able to handle correctly, then
     120                 :            :                     //If we can't convert to the dest encoding, then
     121                 :            :                     //export as unicode
     122                 :          0 :                     OUString sBuf(&c, 1);
     123                 :          0 :                     OString sConverted;
     124                 :            :                     sal_uInt32 nFlags =
     125                 :            :                         RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
     126                 :          0 :                         RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR;
     127                 :            :                     bool bWriteAsUnicode = !(sBuf.convertToString(&sConverted,
     128                 :          0 :                                          eDestEnc, nFlags))
     129 [ #  # ][ #  # ]:          0 :                                             || (RTL_TEXTENCODING_UTF8==eDestEnc); // #i43933# do not export UTF-8 chars in RTF;
     130         [ #  # ]:          0 :                     if (bWriteAsUnicode)
     131                 :            :                     {
     132                 :            :                         sBuf.convertToString(&sConverted,
     133                 :          0 :                             eDestEnc, OUSTRING_TO_OSTRING_CVTFLAGS);
     134                 :            :                     }
     135                 :          0 :                     const sal_Int32 nLen = sConverted.getLength();
     136                 :            : 
     137 [ #  # ][ #  # ]:          0 :                     if (bWriteAsUnicode && pUCMode)
     138                 :            :                     {
     139                 :            :                         // then write as unicode - character
     140         [ #  # ]:          0 :                         if (*pUCMode != nLen)
     141                 :            :                         {
     142                 :            :                             // #i47831# add an additional whitespace, so that
     143                 :            :                             // "document whitespaces" are not ignored.;
     144         [ #  # ]:          0 :                             rStream << "\\uc"
     145 [ #  # ][ #  # ]:          0 :                                 << rtl::OString::valueOf(nLen).getStr() << " ";
     146                 :          0 :                             *pUCMode = nLen;
     147                 :            :                         }
     148         [ #  # ]:          0 :                         rStream << "\\u"
     149                 :            :                             << rtl::OString::valueOf(
     150         [ #  # ]:          0 :                                 static_cast<sal_Int32>(c)).getStr();
     151                 :            :                     }
     152                 :            : 
     153         [ #  # ]:          0 :                     for (sal_Int32 nI = 0; nI < nLen; ++nI)
     154                 :            :                     {
     155         [ #  # ]:          0 :                         rStream << "\\'";
     156         [ #  # ]:          0 :                         Out_Hex(rStream, sConverted.getStr()[nI], 2);
     157                 :          0 :                     }
     158                 :            :                 }
     159                 :          0 :                 break;
     160                 :            :         }
     161                 :          0 :         break;
     162                 :            :     }
     163                 :            : 
     164         [ #  # ]:          0 :     if (pStr)
     165                 :          0 :         rStream << pStr << ' ';
     166                 :            : 
     167                 :          0 :     return rStream;
     168                 :            : }
     169                 :            : 
     170                 :          0 : SvStream& RTFOutFuncs::Out_String( SvStream& rStream, const String& rStr,
     171                 :            :     rtl_TextEncoding eDestEnc, sal_Bool bWriteHelpFile)
     172                 :            : {
     173                 :          0 :     int nUCMode = 1;
     174         [ #  # ]:          0 :     for (xub_StrLen n = 0; n < rStr.Len(); ++n)
     175         [ #  # ]:          0 :         Out_Char(rStream, rStr.GetChar(n), &nUCMode, eDestEnc, bWriteHelpFile);
     176         [ #  # ]:          0 :     if (nUCMode != 1)
     177 [ #  # ][ #  # ]:          0 :       rStream << "\\uc1"<< " "; // #i47831# add an additional whitespace, so that "document whitespaces" are not ignored.;
     178                 :          0 :     return rStream;
     179                 :            : }
     180                 :            : 
     181                 :          0 : SvStream& RTFOutFuncs::Out_Hex( SvStream& rStream, sal_uLong nHex, sal_uInt8 nLen )
     182                 :            : {
     183                 :          0 :     sal_Char aNToABuf[] = "0000000000000000";
     184                 :            : 
     185                 :            :     DBG_ASSERT( nLen < sizeof(aNToABuf), "zu viele Stellen" );
     186         [ #  # ]:          0 :     if( nLen >= sizeof(aNToABuf) )
     187                 :          0 :         nLen = (sizeof(aNToABuf)-1);
     188                 :            : 
     189                 :            :     // Pointer an das Bufferende setzen
     190                 :          0 :     sal_Char* pStr = aNToABuf + (sizeof(aNToABuf)-1);
     191         [ #  # ]:          0 :     for( sal_uInt8 n = 0; n < nLen; ++n )
     192                 :            :     {
     193                 :          0 :         *(--pStr) = (sal_Char)(nHex & 0xf ) + 48;
     194         [ #  # ]:          0 :         if( *pStr > '9' )
     195                 :          0 :             *pStr += 39;
     196                 :          0 :         nHex >>= 4;
     197                 :            :     }
     198         [ #  # ]:          0 :     return rStream << pStr;
     199                 :            : }
     200                 :            : 
     201                 :            : 
     202                 :            : 
     203                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10