fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / inc / xestring.hxx
blob0109972305c708d90b413f2363819a97c4417081
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 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_XESTRING_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_XESTRING_HXX
23 #include "xlstring.hxx"
25 class XclExpStream;
26 class XclExpXmlStream;
28 /** This class stores an unformatted or formatted string for Excel export.
30 The class supports two completely different types of Excel strings:
31 1) BIFF2-BIFF7 byte strings: The text is encoded as a 8-bit character
32 array. The strings cannot contain any character formatting.
33 2) BIFF8 Unicode strings: The text may be stored as UCS-2 character array,
34 or compressed to an 8-bit array, if all characters are less than
35 U+0100. Unicode strings may contain a formatting array, that specifies
36 the used FONT record for different ranges of characters.
38 The class provides full support for NUL characters in strings. On
39 construction or assignment the passed flags specify the behaviour of the
40 string while it is written to a stream (the 'Write' functions and
41 'operator<<').
43 class XclExpString
45 public:
46 // constructors -----------------------------------------------------------
48 /** Constructs an empty BIFF8 Unicode string.
49 @param nFlags Modifiers for string export.
50 @param nMaxLen The maximum number of characters to store in this string. */
51 explicit XclExpString(
52 XclStrFlags nFlags = EXC_STR_DEFAULT,
53 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
55 /** Constructs an unformatted BIFF8 Unicode string.
56 @param nFlags Modifiers for string export.
57 @param nMaxLen The maximum number of characters to store in this string. */
58 explicit XclExpString(
59 const OUString& rString,
60 XclStrFlags nFlags = EXC_STR_DEFAULT,
61 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
63 // assign -----------------------------------------------------------------
65 /** Assigns an unformatted string, converts this object to a BIFF8 Unicode string.
66 @param nFlags Modifiers for string export.
67 @param nMaxLen The maximum number of characters to store in this string. */
68 void Assign(
69 const OUString& rString,
70 XclStrFlags nFlags = EXC_STR_DEFAULT,
71 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
73 /** Assigns a Unicode character, converts this object to a BIFF8 Unicode string.
74 @param nFlags Modifiers for string export.
75 @param nMaxLen The maximum number of characters to store in this string (for appending). */
76 void Assign(
77 sal_Unicode cChar,
78 XclStrFlags nFlags = EXC_STR_DEFAULT,
79 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
81 /** Assigns an unformatted string, converts this object to a BIFF2-BIFF7 byte string.
82 @param nFlags Modifiers for string export.
83 @param nMaxLen The maximum number of characters to store in this string. */
84 void AssignByte(
85 const OUString& rString,
86 rtl_TextEncoding eTextEnc,
87 XclStrFlags nFlags = EXC_STR_DEFAULT,
88 sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
90 // append -----------------------------------------------------------------
92 /** Appends a string. Uses the string flags used in constructor or last Assign().
93 @descr This object must be a BIFF8 Unicode string. */
94 void Append( const OUString& rString );
96 /** Appends a string. Uses the string flags used in constructor or last Assign().
97 @descr This object must be a BIFF2-BIFF7 byte string. */
98 void AppendByte( const OUString& rString, rtl_TextEncoding eTextEnc );
99 /** Appends a character. Uses the string flags used in constructor or last Assign().
100 @descr This object must be a BIFF2-BIFF7 byte string. */
101 void AppendByte( sal_Unicode cChar, rtl_TextEncoding eTextEnc );
103 // formatting runs --------------------------------------------------------
105 /** Appends a formatting run. nChar must be greater than last contained character index. */
106 void AppendFormat( sal_uInt16 nChar, sal_uInt16 nFontIdx, bool bDropDuplicate = true );
107 /** Appends a trailing formatting run with the passed font index. */
108 void AppendTrailingFormat( sal_uInt16 nFontIdx );
109 /** Removes formatting runs at the end, if the string contains too much. */
110 void LimitFormatCount( sal_uInt16 nMaxCount );
111 /** Removes and returns the font index for the first char from the formatting runs, otherwise EXC_FONT_NOTFOUND. */
112 sal_uInt16 RemoveLeadingFont();
114 // get data ---------------------------------------------------------------
116 /** Returns the character count of the string. */
117 inline sal_uInt16 Len() const { return mnLen; }
118 /** Returns true, if the string is empty. */
119 inline bool IsEmpty() const { return mnLen == 0; }
120 /** Returns true, if the string contains line breaks. */
121 inline bool IsWrapped() const { return mbWrapped; }
122 /** Returns true, if this string is equal to the passed string. */
123 bool IsEqual( const XclExpString& rCmp ) const;
124 /** Returns true, if this string is less than the passed string. */
125 bool IsLessThan( const XclExpString& rCmp ) const;
127 /** Returns true, if the string contains formatting information. */
128 inline bool IsRich() const { return !maFormats.empty(); }
129 /** Returns the current count of formatting runs for rich strings. */
130 sal_uInt16 GetFormatsCount() const;
131 /** Returns the vector with all formatting runs. */
132 inline const XclFormatRunVec& GetFormats() const { return maFormats; }
134 /** Returns the current string flags field to export. */
135 sal_uInt8 GetFlagField() const;
136 /** Returns the byte count the header will take on export. */
137 sal_uInt16 GetHeaderSize() const;
138 /** Returns the byte count the character buffer will take on export. */
139 sal_Size GetBufferSize() const;
140 /** Returns the byte count the whole string will take on export. */
141 sal_Size GetSize() const;
143 /** Returns the specified character from the (already encoded) string. */
144 sal_uInt16 GetChar( sal_uInt16 nCharIdx ) const;
145 /** Returns a hash value for the string. */
146 sal_uInt16 GetHash() const;
148 const ScfUInt16Vec& GetUnicodeBuffer() const { return maUniBuffer; }
150 // streaming --------------------------------------------------------------
152 /** Writes the string length field (1 byte or 2 bytes). */
153 void WriteLenField( XclExpStream& rStrm ) const;
154 /** Writes the string flags field (1 byte). */
155 void WriteFlagField( XclExpStream& rStrm ) const;
156 /** Writes 8-bit or 16-bit length field and string flags field. */
157 void WriteHeader( XclExpStream& rStrm ) const;
158 /** Writes the raw character buffer. */
159 void WriteBuffer( XclExpStream& rStrm ) const;
160 /** Writes the raw formatting run buffer. */
161 void WriteFormats( XclExpStream& rStrm, bool bWriteSize = false ) const;
162 /** Writes the complete Unicode string. */
163 void Write( XclExpStream& rStrm ) const;
165 /** Writes the string header to memory. */
166 void WriteHeaderToMem( sal_uInt8* pnMem ) const;
167 /** Writes the raw character buffer to memory (8-bit or 16-bit little-endian). */
168 void WriteBufferToMem( sal_uInt8* pnMem ) const;
169 /** Writes the entire string to memory. */
170 void WriteToMem( sal_uInt8* pnMem ) const;
172 void WriteXml( XclExpXmlStream& rStrm ) const;
174 private:
175 /** Returns true, if the flag field should be written. */
176 bool IsWriteFlags() const;
177 /** Returns true, if the formatting run vector should be written. */
178 bool IsWriteFormats() const;
180 /** Sets the string length but regards the limit given in mnMaxLen. */
181 void SetStrLen( sal_Int32 nNewLen );
182 /** Inserts the passed character array into the internal character buffer.
183 @param nBegin First index in internal buffer to fill.
184 @param nLen Number of characters to insert. */
185 void CharsToBuffer( const sal_Unicode* pcSource, sal_Int32 nBegin, sal_Int32 nLen );
186 /** Inserts the passed character array into the internal character buffer.
187 @param nBegin First index in internal buffer to fill.
188 @param nLen Number of characters to insert. */
189 void CharsToBuffer( const sal_Char* pcSource, sal_Int32 nBegin, sal_Int32 nLen );
191 /** Initializes flags, string length, and resizes character buffer.
192 @param nFlags Modifiers for string export.
193 @param nCurrLen The requested number of characters for the string.
194 @param nMaxLen The maximum length allowed of the resulting string.
195 @param bBiff8 true = BIFF8 Unicode string; false = BIFF2-BIFF7 byte string. */
196 void Init( sal_Int32 nCurrLen, XclStrFlags nFlags, sal_uInt16 nMaxLen, bool bBiff8 );
197 /** Creates the character buffer from the given Unicode array.
198 @param pcSource The source character buffer. Trailing NUL character is not necessary.
199 @param nFlags Modifiers for string export.
200 @param nCurrLen The real count of characters contained in the passed buffer.
201 @param nMaxLen The maximum length allowed of the resulting string. */
202 void Build(
203 const sal_Unicode* pcSource, sal_Int32 nCurrLen,
204 XclStrFlags nFlags, sal_uInt16 nMaxLen );
205 /** Creates the character buffer from the given character array.
206 @param pcSource The source character buffer. Trailing NUL character is not necessary.
207 @param nFlags Modifiers for string export.
208 @param nCurrLen The real count of characters contained in the passed buffer.
209 @param nMaxLen The maximum length allowed of the resulting string. */
210 void Build(
211 const sal_Char* pcSource, sal_Int32 nCurrLen,
212 XclStrFlags nFlags, sal_uInt16 nMaxLen );
214 /** Initializes string length and resizes character buffers for appending operation.
215 @param nAddLen The number of characters to be appended. */
216 void InitAppend( sal_Int32 nAddLen );
217 /** Appends the given Unicode array to the character buffer.
218 @param pcSource The source character buffer. Trailing NUL character is not necessary.
219 @param nAddLen The real count of characters contained in the passed buffer. */
220 void BuildAppend( const sal_Unicode* pcSource, sal_Int32 nAddLen );
221 /** Appends the given character array to the character buffer.
222 @param pcSource The source character buffer. Trailing NUL character is not necessary.
223 @param nAddLen The real count of characters contained in the passed buffer. */
224 void BuildAppend( const sal_Char* pcSource, sal_Int32 nAddLen );
226 /** Initializes write process on stream. */
227 void PrepareWrite( XclExpStream& rStrm, sal_uInt16 nBytes ) const;
229 private:
230 ScfUInt16Vec maUniBuffer; /// The Unicode character buffer.
231 ScfUInt8Vec maCharBuffer; /// The byte character buffer.
232 XclFormatRunVec maFormats; /// All formatting runs.
233 sal_uInt16 mnLen; /// Character count to export.
234 sal_uInt16 mnMaxLen; /// Maximum allowed number of characters.
235 bool mbIsBiff8; /// true = BIFF8 Unicode string, false = BIFF2-7 bytestring.
236 bool mbIsUnicode; /// true, if at least one character is >0xFF.
237 bool mb8BitLen; /// true = write 8-bit string length; false = 16-bit.
238 bool mbSmartFlags; /// true = omit flags on empty string; false = always write flags.
239 bool mbSkipFormats; /// true = skip formats on export; false = write complete formatted string.
240 bool mbWrapped; /// true = text contains several paragraphs.
241 bool mbSkipHeader; /// true = skip length and flags when writing string bytes.
244 inline bool operator==( const XclExpString& rLeft, const XclExpString& rRight )
246 return rLeft.IsEqual( rRight );
249 inline bool operator!=( const XclExpString& rLeft, const XclExpString& rRight )
251 return !(rLeft == rRight);
254 inline bool operator<( const XclExpString& rLeft, const XclExpString& rRight )
256 return rLeft.IsLessThan( rRight );
259 inline XclExpStream& operator<<( XclExpStream& rStrm, const XclExpString& rString )
261 rString.Write( rStrm );
262 return rStrm;
265 #endif
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */