fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / inc / richstring.hxx
blob7dc2eb6302b07ce3f8f47232d3cc25325be4bfbc
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_RICHSTRING_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_RICHSTRING_HXX
23 #include <oox/helper/refvector.hxx>
24 #include "stylesbuffer.hxx"
26 class EditTextObject;
27 struct ESelection;
28 class ScEditEngineDefaulter;
30 namespace com { namespace sun { namespace star {
31 namespace text { class XText; }
32 } } }
34 namespace oox {
35 namespace xls {
37 /** Flags used to specify import/export mode of strings. */
38 typedef sal_Int32 BiffStringFlags;
40 const BiffStringFlags BIFF_STR_DEFAULT = 0x0000; /// Default string settings.
41 const BiffStringFlags BIFF_STR_FORCEUNICODE = 0x0001; /// Always use UCS-2 characters (default: try to compress). BIFF8 export only.
42 const BiffStringFlags BIFF_STR_8BITLENGTH = 0x0002; /// 8-bit string length field (default: 16-bit).
43 const BiffStringFlags BIFF_STR_SMARTFLAGS = 0x0004; /// Omit flags on empty string (default: read/write always). BIFF8 only.
44 const BiffStringFlags BIFF_STR_KEEPFONTS = 0x0008; /// Keep old fonts when reading unformatted string (default: clear fonts). Import only.
45 const BiffStringFlags BIFF_STR_EXTRAFONTS = 0x0010; /// Read trailing rich-string font array (default: nothing). BIFF2-BIFF5 import only.
47 /** Contains text data and font attributes for a part of a rich formatted string. */
48 class RichStringPortion : public WorkbookHelper
50 public:
51 explicit RichStringPortion( const WorkbookHelper& rHelper );
53 /** Sets text data for this portion. */
54 void setText( const OUString& rText );
55 /** Creates and returns a new font formatting object. */
56 FontRef createFont();
57 /** Links this portion to a font object from the global font list. */
58 void setFontId( sal_Int32 nFontId );
60 /** Final processing after import of all strings. */
61 void finalizeImport();
63 /** Returns the text data of this portion. */
64 inline const OUString& getText() const { return maText; }
65 /** Returns true, if the portion fontains font formatting. */
66 inline bool hasFont() const { return mxFont.get() != 0; }
68 /** Converts the portion and replaces or appends to the passed XText. */
69 void convert(
70 const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
71 const oox::xls::Font* pFont, bool bReplace );
72 void convert( ScEditEngineDefaulter& rEE, ESelection& rSelection, const oox::xls::Font* pFont );
74 void writeFontProperties(
75 const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
76 const oox::xls::Font* pFont ) const;
78 private:
79 OUString maText; /// Portion text.
80 FontRef mxFont; /// Embedded portion font, may be empty.
81 sal_Int32 mnFontId; /// Link to global font list.
82 bool mbConverted; /// Without repeatly convert
85 typedef std::shared_ptr< RichStringPortion > RichStringPortionRef;
87 enum BiffFontPortionMode
89 BIFF_FONTPORTION_8BIT, /// Font portion with 8-bit values.
90 BIFF_FONTPORTION_16BIT, /// Font portion with 16-bit values.
91 BIFF_FONTPORTION_OBJ /// Font portion in OBJ or TXO record.
94 /** Represents a position in a rich-string containing current font identifier.
96 This object stores the position of a formatted character in a rich-string
97 and the identifier of a font from the global font list used to format this
98 and the following characters. Used in binary filters only.
100 struct FontPortionModel
102 sal_Int32 mnPos; /// First character in the string.
103 sal_Int32 mnFontId; /// Font identifier for the next characters.
105 explicit inline FontPortionModel() : mnPos( 0 ), mnFontId( -1 ) {}
106 explicit inline FontPortionModel( sal_Int32 nPos, sal_Int32 nFontId ) :
107 mnPos( nPos ), mnFontId( nFontId ) {}
109 void read( SequenceInputStream& rStrm );
112 /** A vector with all font portions in a rich-string. */
113 class FontPortionModelList {
114 ::std::vector< FontPortionModel > mvModels;
116 public:
117 inline explicit FontPortionModelList() : mvModels() {}
119 bool empty() const { return mvModels.empty(); }
121 const FontPortionModel& back() const { return mvModels.back(); }
122 const FontPortionModel& front() const { return mvModels.front(); }
124 void push_back(const FontPortionModel& rModel) { mvModels.push_back(rModel); }
126 void insert(::std::vector< FontPortionModel >::iterator it,
127 const FontPortionModel& rModel)
128 { mvModels.insert(it, rModel); }
130 ::std::vector< FontPortionModel >::const_iterator begin() const { return mvModels.begin(); }
131 ::std::vector< FontPortionModel >::iterator begin() { return mvModels.begin(); }
133 /** Appends a rich-string font identifier. */
134 void appendPortion( const FontPortionModel& rPortion );
135 /** Reads count and font identifiers from the passed stream. */
136 void importPortions( SequenceInputStream& rStrm );
139 struct PhoneticDataModel
141 sal_Int32 mnFontId; /// Font identifier for text formatting.
142 sal_Int32 mnType; /// Phonetic text type.
143 sal_Int32 mnAlignment; /// Phonetic portion alignment.
145 explicit PhoneticDataModel();
147 /** Sets the passed data from binary import. */
148 void setBiffData( sal_Int32 nType, sal_Int32 nAlignment );
151 class PhoneticSettings : public WorkbookHelper
153 public:
154 explicit PhoneticSettings( const WorkbookHelper& rHelper );
156 /** Imports phonetic settings from the phoneticPr element. */
157 void importPhoneticPr( const AttributeList& rAttribs );
158 /** Imports phonetic settings from the PHONETICPR record. */
159 void importPhoneticPr( SequenceInputStream& rStrm );
161 /** Imports phonetic settings from a rich string. */
162 void importStringData( SequenceInputStream& rStrm );
164 private:
165 PhoneticDataModel maModel;
168 /** Contains text data and positioning information for a phonetic text portion. */
169 class RichStringPhonetic : public WorkbookHelper
171 public:
172 explicit RichStringPhonetic( const WorkbookHelper& rHelper );
174 /** Sets text data for this phonetic portion. */
175 void setText( const OUString& rText );
176 /** Imports attributes of a phonetic run (rPh element). */
177 void importPhoneticRun( const AttributeList& rAttribs );
178 /** Sets the associated range in base text for this phonetic portion. */
179 void setBaseRange( sal_Int32 nBasePos, sal_Int32 nBaseEnd );
181 private:
182 OUString maText; /// Portion text.
183 sal_Int32 mnBasePos; /// Start position in base text.
184 sal_Int32 mnBaseEnd; /// One-past-end position in base text.
187 typedef std::shared_ptr< RichStringPhonetic > RichStringPhoneticRef;
189 /** Represents a phonetic text portion in a rich-string with phonetic text.
190 Used in binary filters only. */
191 struct PhoneticPortionModel
193 sal_Int32 mnPos; /// First character in phonetic text.
194 sal_Int32 mnBasePos; /// First character in base text.
195 sal_Int32 mnBaseLen; /// Number of characters in base text.
197 explicit inline PhoneticPortionModel() : mnPos( -1 ), mnBasePos( -1 ), mnBaseLen( 0 ) {}
198 explicit inline PhoneticPortionModel( sal_Int32 nPos, sal_Int32 nBasePos, sal_Int32 nBaseLen ) :
199 mnPos( nPos ), mnBasePos( nBasePos ), mnBaseLen( nBaseLen ) {}
201 void read( SequenceInputStream& rStrm );
204 /** A vector with all phonetic portions in a rich-string. */
205 class PhoneticPortionModelList
207 public:
208 inline explicit PhoneticPortionModelList() : mvModels() {}
210 bool empty() const { return mvModels.empty(); }
212 const PhoneticPortionModel& back() const { return mvModels.back(); }
214 void push_back(const PhoneticPortionModel& rModel) { mvModels.push_back(rModel); }
216 ::std::vector< PhoneticPortionModel >::const_iterator begin() const { return mvModels.begin(); }
218 /** Appends a rich-string phonetic portion. */
219 void appendPortion( const PhoneticPortionModel& rPortion );
220 /** Reads all phonetic portions from the passed stream. */
221 void importPortions( SequenceInputStream& rStrm );
223 private:
224 ::std::vector< PhoneticPortionModel > mvModels;
227 /** Contains string data and a list of formatting runs for a rich formatted string. */
228 class RichString : public WorkbookHelper
230 public:
231 explicit RichString( const WorkbookHelper& rHelper );
233 /** Appends and returns a portion object for a plain string (t element). */
234 RichStringPortionRef importText( const AttributeList& rAttribs );
235 /** Appends and returns a portion object for a new formatting run (r element). */
236 RichStringPortionRef importRun( const AttributeList& rAttribs );
237 /** Appends and returns a phonetic text object for a new phonetic run (rPh element). */
238 RichStringPhoneticRef importPhoneticRun( const AttributeList& rAttribs );
239 /** Imports phonetic settings from the rPhoneticPr element. */
240 void importPhoneticPr( const AttributeList& rAttribs );
242 /** Imports a Unicode rich-string from the passed record stream. */
243 void importString( SequenceInputStream& rStrm, bool bRich );
245 /** Final processing after import of all strings. */
246 void finalizeImport();
248 /** Tries to extract a plain string from this object. Returns the string,
249 if there is only one unformatted portion. */
250 bool extractPlainString(
251 OUString& orString,
252 const oox::xls::Font* pFirstPortionFont = 0 ) const;
254 /** Converts the string and writes it into the passed XText.
255 @param rxText The XText interface of the target object.
256 @param bReplaceOld True = replace old contents of the text object.
257 @param pFirstPortionFont Optional font providing additional rich-text
258 formatting for the first text portion, e.g. font escapement. */
259 void convert(
260 const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
261 bool bReplaceOld,
262 const oox::xls::Font* pFirstPortionFont = 0 ) const;
263 ::EditTextObject* convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFont ) const;
265 private:
266 /** Creates, appends, and returns a new empty string portion. */
267 RichStringPortionRef createPortion();
268 /** Creates, appends, and returns a new empty phonetic text portion. */
269 RichStringPhoneticRef createPhonetic();
271 /** Create base text portions from the passed string and character formatting. */
272 void createTextPortions( const OUString& rText, FontPortionModelList& rPortions );
273 /** Create phonetic text portions from the passed string and portion data. */
274 void createPhoneticPortions( const OUString& rText, PhoneticPortionModelList& rPortions, sal_Int32 nBaseLen );
276 private:
277 typedef RefVector< RichStringPortion > PortionVector;
278 typedef RefVector< RichStringPhonetic > PhoneticVector;
280 PortionVector maTextPortions; /// String portions with font data.
281 PhoneticSettings maPhonSettings; /// Phonetic settings for this string.
282 PhoneticVector maPhonPortions; /// Phonetic text portions.
285 typedef std::shared_ptr< RichString > RichStringRef;
287 } // namespace xls
288 } // namespace oox
290 #endif
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */