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_UTIL_HXX
11 #define INCLUDED_FILTER_MSFILTER_UTIL_HXX
12 
13 #include <filter/msfilter/msfilterdllapi.h>
14 #include <svx/msdffdef.hxx>
15 #include <rtl/string.hxx>
16 #include <rtl/textenc.h>
17 #include <rtl/ustring.hxx>
18 #include <sal/types.h>
19 #include <tools/datetime.hxx>
20 #include <tools/long.hxx>
21 
22 class Color;
23 
24 namespace com::sun::star {
25     namespace awt { struct Size; }
26     namespace lang { struct Locale; }
27 }
28 
29 namespace msfilter::util {
30 
31 /// Returns the best-fit default 8bit encoding for a given locale
32 /// i.e. useful when dealing with legacy formats which use legacy text encodings without recording
33 /// what the encoding is, but you know or can guess the language
34 MSFILTER_DLLPUBLIC rtl_TextEncoding getBestTextEncodingFromLocale(const css::lang::Locale &rLocale);
35 
36 /// Convert a color in BGR format to RGB.
37 MSFILTER_DLLPUBLIC ::Color BGRToRGB(sal_uInt32 nColour);
38 
39 /** Convert from DTTM to Writer's DateTime
40   */
41 MSFILTER_DLLPUBLIC DateTime DTTM2DateTime( tools::Long lDTTM );
42 
43 /** Convert DateTime to xsd::dateTime string.
44 
45 I guess there must be an implementation of this somewhere in LO, but I failed
46 to find it, unfortunately :-(
47 */
48 
49 /// Given a cBullet in encoding r_ioChrSet and fontname r_ioFontName return a
50 /// suitable new Bullet and change r_ioChrSet and r_ioFontName to form the
51 /// best-fit replacement in terms of default available MSOffice symbol
52 /// fonts.
53 ///
54 /// Used to map from [Open|Star]Symbol to some Windows font or other.
55 MSFILTER_DLLPUBLIC sal_Unicode bestFitOpenSymbolToMSFont(sal_Unicode cBullet,
56     rtl_TextEncoding& r_ioChrSet, OUString& r_ioFontName);
57 
58 
59 /**
60  * Converts tools Color to HTML color (without leading hashmark).
61  *
62  * @param rColor color to convert
63  */
64 MSFILTER_DLLPUBLIC OString ConvertColor( const Color &rColor );
65 
66 
67 /** Paper size in 1/100 millimeters. */
68 struct MSFILTER_DLLPUBLIC ApiPaperSize
69 {
70     sal_Int32           mnWidth;
71     sal_Int32           mnHeight;
72 };
73 
74 class MSFILTER_DLLPUBLIC PaperSizeConv
75 {
76 public:
77     static sal_Int32 getMSPaperSizeIndex( const css::awt::Size& rSize );
78     static const ApiPaperSize& getApiSizeForMSPaperSizeIndex( sal_Int32 nMSOPaperIndex );
79 };
80 
81 /**
82  * Finds the quoted text in a field instruction text.
83  *
84  * Example: SEQ "Figure" \someoption -> "Figure"
85  */
86 MSFILTER_DLLPUBLIC OUString findQuotedText( const OUString& rCommand, const char* cStartQuote, const sal_Unicode uEndQuote );
87 
88 class MSFILTER_DLLPUBLIC WW8ReadFieldParams
89 {
90 private:
91     const OUString aData;
92     sal_Int32 nFnd;
93     sal_Int32 nNext;
94     sal_Int32 nSavPtr;
95 public:
96     WW8ReadFieldParams( const OUString& rData );
97 
98     bool GoToTokenParam();
99     sal_Int32 SkipToNextToken();
GetTokenSttPtr() const100     sal_Int32 GetTokenSttPtr() const   { return nFnd;  }
101 
102     sal_Int32 FindNextStringPiece( sal_Int32 _nStart = -1 );
103     bool GetTokenSttFromTo(sal_Int32* _pFrom, sal_Int32* _pTo, sal_Int32 _nMax);
104 
105     OUString GetResult() const;
106 };
107 
108 struct MSFILTER_DLLPUBLIC EquationResult
109 {
110     OUString sResult;
111     OUString sType;
112 };
113 
114 MSFILTER_DLLPUBLIC EquationResult ParseCombinedChars(const OUString& rStr);
115 
116 /// Similar to EnhancedCustomShapeTypeNames::Get(), but it also supports OOXML types and returns a drawingML string.
117 MSFILTER_DLLPUBLIC const char* GetOOXMLPresetGeometry( const char* sShapeType );
118 
119 /// Similar to EnhancedCustomShapeTypeNames::Get(), but returns an MSO_SPT (binary / VML type).
120 MSFILTER_DLLPUBLIC MSO_SPT GETVMLShapeType(const OString& aType);
121 
122 /**
123  * The following function checks if a MSO shapetype is allowed to have textboxcontent.
124  *
125  * @param nShapeType shape to check
126  */
127 MSFILTER_DLLPUBLIC bool HasTextBoxContent(sal_uInt32 nShapeType);
128 
129 /**
130  * Convert the input color value to an ico value (0..16)
131  *
132  * @param[in]   rCol       input color for conversion
133  *
134  * @return                 ico value [0..16]
135 **/
136 MSFILTER_DLLPUBLIC sal_uInt8 TransColToIco( const Color& rCol );
137 
138 }
139 
140 
141 
142 #endif
143 
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
145