fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / svrtf / rtfout.cxx
blob64a9a8b48c9fe1aa04987460ba59f32fd29b4c53
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/debug.hxx>
21 #include <tools/stream.hxx>
22 #include <tools/string.hxx>
23 #include <rtl/string.hxx>
24 #include <rtl/ustrbuf.hxx>
25 #include <svtools/rtfkeywd.hxx>
26 #include <svtools/rtfout.hxx>
29 #if defined(UNX)
30 const sal_Char RTFOutFuncs::sNewLine = '\012';
31 #else
32 const sal_Char RTFOutFuncs::sNewLine[] = "\015\012";
33 #endif
36 SvStream& RTFOutFuncs::Out_Char(SvStream& rStream, sal_Unicode c,
37 int *pUCMode, rtl_TextEncoding eDestEnc, sal_Bool bWriteHelpFile)
39 const sal_Char* pStr = 0;
40 switch (c)
42 case 0x1:
43 case 0x2:
44 // this are control character of our textattributes and will never be
45 // written
46 break;
47 case 0xA0:
48 rStream << "\\~";
49 break;
50 case 0xAD:
51 rStream << "\\-";
52 break;
53 case 0x2011:
54 rStream << "\\_";
55 break;
56 case '\n':
57 pStr = OOO_STRING_SVTOOLS_RTF_LINE;
58 break;
59 case '\t':
60 pStr = OOO_STRING_SVTOOLS_RTF_TAB;
61 break;
62 default:
63 if(!bWriteHelpFile)
65 switch(c)
67 case 149:
68 pStr = OOO_STRING_SVTOOLS_RTF_BULLET;
69 break;
70 case 150:
71 pStr = OOO_STRING_SVTOOLS_RTF_ENDASH;
72 break;
73 case 151:
74 pStr = OOO_STRING_SVTOOLS_RTF_EMDASH;
75 break;
76 case 145:
77 pStr = OOO_STRING_SVTOOLS_RTF_LQUOTE;
78 break;
79 case 146:
80 pStr = OOO_STRING_SVTOOLS_RTF_RQUOTE;
81 break;
82 case 147:
83 pStr = OOO_STRING_SVTOOLS_RTF_LDBLQUOTE;
84 break;
85 case 148:
86 pStr = OOO_STRING_SVTOOLS_RTF_RDBLQUOTE;
87 break;
90 if (pStr)
91 break;
94 switch (c)
96 case '\\':
97 case '}':
98 case '{':
99 rStream << '\\' << (sal_Char)c;
100 break;
101 default:
102 if (c >= ' ' && c <= '~')
103 rStream << (sal_Char)c;
104 else
106 //If we can't convert to the dest encoding, or if
107 //its an uncommon multibyte sequence which most
108 //readers won't be able to handle correctly, then
109 //If we can't convert to the dest encoding, then
110 //export as unicode
111 OUString sBuf(&c, 1);
112 OString sConverted;
113 sal_uInt32 nFlags =
114 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
115 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR;
116 bool bWriteAsUnicode = !(sBuf.convertToString(&sConverted,
117 eDestEnc, nFlags))
118 || (RTL_TEXTENCODING_UTF8==eDestEnc); // #i43933# do not export UTF-8 chars in RTF;
119 if (bWriteAsUnicode)
121 sBuf.convertToString(&sConverted,
122 eDestEnc, OUSTRING_TO_OSTRING_CVTFLAGS);
124 const sal_Int32 nLen = sConverted.getLength();
126 if (bWriteAsUnicode && pUCMode)
128 // then write as unicode - character
129 if (*pUCMode != nLen)
131 // #i47831# add an additional whitespace, so that
132 // "document whitespaces" are not ignored.;
133 rStream << "\\uc"
134 << OString::valueOf(nLen).getStr() << " ";
135 *pUCMode = nLen;
137 rStream << "\\u"
138 << OString::valueOf(
139 static_cast<sal_Int32>(c)).getStr();
142 for (sal_Int32 nI = 0; nI < nLen; ++nI)
144 rStream << "\\'";
145 Out_Hex(rStream, sConverted.getStr()[nI], 2);
148 break;
150 break;
153 if (pStr)
154 rStream << pStr << ' ';
156 return rStream;
159 SvStream& RTFOutFuncs::Out_String( SvStream& rStream, const String& rStr,
160 rtl_TextEncoding eDestEnc, sal_Bool bWriteHelpFile)
162 int nUCMode = 1;
163 for (xub_StrLen n = 0; n < rStr.Len(); ++n)
164 Out_Char(rStream, rStr.GetChar(n), &nUCMode, eDestEnc, bWriteHelpFile);
165 if (nUCMode != 1)
166 rStream << "\\uc1"<< " "; // #i47831# add an additional whitespace, so that "document whitespaces" are not ignored.;
167 return rStream;
170 SvStream& RTFOutFuncs::Out_Hex( SvStream& rStream, sal_uLong nHex, sal_uInt8 nLen )
172 sal_Char aNToABuf[] = "0000000000000000";
174 DBG_ASSERT( nLen < sizeof(aNToABuf), "zu viele Stellen" );
175 if( nLen >= sizeof(aNToABuf) )
176 nLen = (sizeof(aNToABuf)-1);
178 // Pointer an das Bufferende setzen
179 sal_Char* pStr = aNToABuf + (sizeof(aNToABuf)-1);
180 for( sal_uInt8 n = 0; n < nLen; ++n )
182 *(--pStr) = (sal_Char)(nHex & 0xf ) + 48;
183 if( *pStr > '9' )
184 *pStr += 39;
185 nHex >>= 4;
187 return rStream << pStr;
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */