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 <rtl/string.hxx>
23 #include <rtl/ustrbuf.hxx>
24 #include <svtools/rtfkeywd.hxx>
25 #include <svtools/rtfout.hxx>
27 SvStream
& RTFOutFuncs::Out_Char(SvStream
& rStream
, sal_Unicode c
,
28 int *pUCMode
, rtl_TextEncoding eDestEnc
, bool bWriteHelpFile
)
30 const sal_Char
* pStr
= 0;
35 // this are control character of our textattributes and will never be
39 rStream
.WriteCharPtr( "\\~" );
42 rStream
.WriteCharPtr( "\\-" );
45 rStream
.WriteCharPtr( "\\_" );
48 pStr
= OOO_STRING_SVTOOLS_RTF_LINE
;
51 pStr
= OOO_STRING_SVTOOLS_RTF_TAB
;
59 pStr
= OOO_STRING_SVTOOLS_RTF_BULLET
;
62 pStr
= OOO_STRING_SVTOOLS_RTF_ENDASH
;
65 pStr
= OOO_STRING_SVTOOLS_RTF_EMDASH
;
68 pStr
= OOO_STRING_SVTOOLS_RTF_LQUOTE
;
71 pStr
= OOO_STRING_SVTOOLS_RTF_RQUOTE
;
74 pStr
= OOO_STRING_SVTOOLS_RTF_LDBLQUOTE
;
77 pStr
= OOO_STRING_SVTOOLS_RTF_RDBLQUOTE
;
90 rStream
.WriteChar( '\\' ).WriteChar( c
);
93 if (c
>= ' ' && c
<= '~')
94 rStream
.WriteChar( c
);
97 //If we can't convert to the dest encoding, or if
98 //its an uncommon multibyte sequence which most
99 //readers won't be able to handle correctly, then
100 //If we can't convert to the dest encoding, then
102 OUString
sBuf(&c
, 1);
105 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
|
106 RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
;
107 bool bWriteAsUnicode
= !(sBuf
.convertToString(&sConverted
,
109 || (RTL_TEXTENCODING_UTF8
==eDestEnc
); // #i43933# do not export UTF-8 chars in RTF;
112 sBuf
.convertToString(&sConverted
,
113 eDestEnc
, OUSTRING_TO_OSTRING_CVTFLAGS
);
115 const sal_Int32 nLen
= sConverted
.getLength();
117 if (bWriteAsUnicode
&& pUCMode
)
119 // then write as unicode - character
120 if (*pUCMode
!= nLen
)
122 // #i47831# add an additional whitespace, so that
123 // "document whitespaces" are not ignored.;
124 rStream
.WriteCharPtr( "\\uc" )
125 .WriteCharPtr( OString::number(nLen
).getStr() ).WriteCharPtr( " " );
128 rStream
.WriteCharPtr( "\\u" )
129 .WriteCharPtr( OString::number(
130 static_cast<sal_Int32
>(c
)).getStr() );
133 for (sal_Int32 nI
= 0; nI
< nLen
; ++nI
)
135 rStream
.WriteCharPtr( "\\'" );
136 Out_Hex(rStream
, sConverted
[nI
], 2);
145 rStream
.WriteCharPtr( pStr
).WriteChar( ' ' );
150 SvStream
& RTFOutFuncs::Out_String( SvStream
& rStream
, const OUString
& rStr
,
151 rtl_TextEncoding eDestEnc
, bool bWriteHelpFile
)
154 for (sal_Int32 n
= 0; n
< rStr
.getLength(); ++n
)
155 Out_Char(rStream
, rStr
[n
], &nUCMode
, eDestEnc
, bWriteHelpFile
);
157 rStream
.WriteCharPtr( "\\uc1" ).WriteCharPtr( " " ); // #i47831# add an additional whitespace, so that "document whitespaces" are not ignored.;
161 SvStream
& RTFOutFuncs::Out_Hex( SvStream
& rStream
, sal_uLong nHex
, sal_uInt8 nLen
)
163 sal_Char aNToABuf
[] = "0000000000000000";
165 DBG_ASSERT( nLen
< sizeof(aNToABuf
), "zu viele Stellen" );
166 if( nLen
>= sizeof(aNToABuf
) )
167 nLen
= (sizeof(aNToABuf
)-1);
169 // set pointer to end of buffer
170 sal_Char
* pStr
= aNToABuf
+ (sizeof(aNToABuf
)-1);
171 for( sal_uInt8 n
= 0; n
< nLen
; ++n
)
173 *(--pStr
) = (sal_Char
)(nHex
& 0xf ) + 48;
178 return rStream
.WriteCharPtr( pStr
);
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */