1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
30 const sal_Char
RTFOutFuncs::sNewLine
= '\012';
32 const sal_Char
RTFOutFuncs::sNewLine
[] = "\015\012";
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;
44 // this are control character of our textattributes and will never be
57 pStr
= OOO_STRING_SVTOOLS_RTF_LINE
;
60 pStr
= OOO_STRING_SVTOOLS_RTF_TAB
;
68 pStr
= OOO_STRING_SVTOOLS_RTF_BULLET
;
71 pStr
= OOO_STRING_SVTOOLS_RTF_ENDASH
;
74 pStr
= OOO_STRING_SVTOOLS_RTF_EMDASH
;
77 pStr
= OOO_STRING_SVTOOLS_RTF_LQUOTE
;
80 pStr
= OOO_STRING_SVTOOLS_RTF_RQUOTE
;
83 pStr
= OOO_STRING_SVTOOLS_RTF_LDBLQUOTE
;
86 pStr
= OOO_STRING_SVTOOLS_RTF_RDBLQUOTE
;
99 rStream
<< '\\' << (sal_Char
)c
;
102 if (c
>= ' ' && c
<= '~')
103 rStream
<< (sal_Char
)c
;
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
111 OUString
sBuf(&c
, 1);
114 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
|
115 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
;
116 bool bWriteAsUnicode
= !(sBuf
.convertToString(&sConverted
,
118 || (RTL_TEXTENCODING_UTF8
==eDestEnc
); // #i43933# do not export UTF-8 chars in RTF;
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.;
134 << OString::valueOf(nLen
).getStr() << " ";
139 static_cast<sal_Int32
>(c
)).getStr();
142 for (sal_Int32 nI
= 0; nI
< nLen
; ++nI
)
145 Out_Hex(rStream
, sConverted
.getStr()[nI
], 2);
154 rStream
<< pStr
<< ' ';
159 SvStream
& RTFOutFuncs::Out_String( SvStream
& rStream
, const String
& rStr
,
160 rtl_TextEncoding eDestEnc
, sal_Bool bWriteHelpFile
)
163 for (xub_StrLen n
= 0; n
< rStr
.Len(); ++n
)
164 Out_Char(rStream
, rStr
.GetChar(n
), &nUCMode
, eDestEnc
, bWriteHelpFile
);
166 rStream
<< "\\uc1"<< " "; // #i47831# add an additional whitespace, so that "document whitespaces" are not ignored.;
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;
187 return rStream
<< pStr
;
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */