1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  */
9 
10 #ifndef INCLUDED_FILTER_MSFILTER_RTFUTIL_HXX
11 #define INCLUDED_FILTER_MSFILTER_RTFUTIL_HXX
12 
13 #include <filter/msfilter/msfilterdllapi.h>
14 #include <rtl/string.hxx>
15 #include <rtl/ustring.hxx>
16 #include <rtl/textenc.h>
17 #include <sal/types.h>
18 #include <tools/solar.h>
19 
20 // RTF values are often multiplied by 2^16
21 #define RTF_MULTIPLIER 65536
22 
23 class SvStream;
24 
25 namespace msfilter
26 {
27 namespace rtfutil
28 {
29 /// Outputs a single character in hex form.
30 MSFILTER_DLLPUBLIC OString OutHex(sal_uLong nHex, sal_uInt8 nLen);
31 
32 /// Handles correct unicode and legacy export of a single character.
33 MSFILTER_DLLPUBLIC OString OutChar(sal_Unicode c, int* pUCMode, rtl_TextEncoding eDestEnc,
34                                    bool* pSuccess, bool bUnicode = true);
35 
36 /**
37  * Handles correct unicode and legacy export of a string.
38  *
39  * @param rStr the string to export
40  * @param eDestEnc the legacy encoding to use
41  * @param bUnicode if unicode output is wanted as well, or just legacy
42  */
43 MSFILTER_DLLPUBLIC OString OutString(const OUString& rStr, rtl_TextEncoding eDestEnc,
44                                      bool bUnicode = true);
45 
46 /**
47  * Handles correct unicode and legacy export of a string, when a
48  * '{' \upr '{' keyword ansi_text '}{\*' \ud '{' keyword Unicode_text '}}}'
49  * construct should be used.
50  *
51  * @param pToken the keyword
52  * @param rStr the text to export
53  * @param eDestEnc the legacy encoding to use
54  */
55 MSFILTER_DLLPUBLIC OString OutStringUpr(const sal_Char* pToken, const OUString& rStr,
56                                         rtl_TextEncoding eDestEnc);
57 
58 /**
59  * Get the numeric value of a single character, representing a hex value.
60  *
61  * @return -1 on failure
62  */
63 MSFILTER_DLLPUBLIC int AsHex(char ch);
64 
65 /// Writes binary data as a hex dump.
66 MSFILTER_DLLPUBLIC OString WriteHex(const sal_uInt8* pData, sal_uInt32 nSize,
67                                     SvStream* pStream = nullptr, sal_uInt32 nLimit = 64);
68 
69 /**
70  * Extract OLE2 data from an \objdata hex dump.
71  */
72 MSFILTER_DLLPUBLIC bool ExtractOLE2FromObjdata(const OString& rObjdata, SvStream& rOle2);
73 
74 /// Strips the header of a WMF file.
75 MSFILTER_DLLPUBLIC bool StripMetafileHeader(const sal_uInt8*& rpGraphicAry, sal_uInt64& rSize);
76 }
77 }
78 
79 #endif
80 
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
82