Line data Source code
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 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SC_SOURCE_FILTER_INC_RICHSTRING_HXX
21 : #define INCLUDED_SC_SOURCE_FILTER_INC_RICHSTRING_HXX
22 :
23 : #include <oox/helper/refvector.hxx>
24 : #include "stylesbuffer.hxx"
25 :
26 : class EditTextObject;
27 : struct ESelection;
28 : class ScEditEngineDefaulter;
29 :
30 : namespace com { namespace sun { namespace star {
31 : namespace text { class XText; }
32 : } } }
33 :
34 : namespace oox {
35 : namespace xls {
36 :
37 : /** Flags used to specify import/export mode of strings. */
38 : typedef sal_Int32 BiffStringFlags;
39 :
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.
46 :
47 : /** Contains text data and font attributes for a part of a rich formatted string. */
48 1632 : class RichStringPortion : public WorkbookHelper
49 : {
50 : public:
51 : explicit RichStringPortion( const WorkbookHelper& rHelper );
52 :
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 );
59 :
60 : /** Final processing after import of all strings. */
61 : void finalizeImport();
62 :
63 : /** Returns the text data of this portion. */
64 940 : inline const OUString& getText() const { return maText; }
65 : /** Returns true, if the portion fontains font formatting. */
66 926 : inline bool hasFont() const { return mxFont.get() != 0; }
67 :
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 );
73 :
74 : void writeFontProperties(
75 : const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
76 : const oox::xls::Font* pFont ) const;
77 :
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
83 : };
84 :
85 : typedef std::shared_ptr< RichStringPortion > RichStringPortionRef;
86 :
87 : enum BiffFontPortionMode
88 : {
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.
92 : };
93 :
94 : /** Represents a position in a rich-string containing current font identifier.
95 :
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.
99 : */
100 : struct FontPortionModel
101 : {
102 : sal_Int32 mnPos; /// First character in the string.
103 : sal_Int32 mnFontId; /// Font identifier for the next characters.
104 :
105 1 : explicit inline FontPortionModel() : mnPos( 0 ), mnFontId( -1 ) {}
106 1 : explicit inline FontPortionModel( sal_Int32 nPos, sal_Int32 nFontId ) :
107 1 : mnPos( nPos ), mnFontId( nFontId ) {}
108 :
109 : void read( SequenceInputStream& rStrm );
110 : };
111 :
112 : /** A vector with all font portions in a rich-string. */
113 1 : class FontPortionModelList {
114 : ::std::vector< FontPortionModel > mvModels;
115 :
116 : public:
117 1 : inline explicit FontPortionModelList() : mvModels() {}
118 :
119 1 : bool empty() const { return mvModels.empty(); }
120 :
121 1 : const FontPortionModel& back() const { return mvModels.back(); }
122 1 : const FontPortionModel& front() const { return mvModels.front(); }
123 :
124 1 : void push_back(const FontPortionModel& rModel) { mvModels.push_back(rModel); }
125 :
126 0 : void insert(::std::vector< FontPortionModel >::iterator it,
127 : const FontPortionModel& rModel)
128 0 : { mvModels.insert(it, rModel); }
129 :
130 : ::std::vector< FontPortionModel >::const_iterator begin() const { return mvModels.begin(); }
131 1 : ::std::vector< FontPortionModel >::iterator begin() { return mvModels.begin(); }
132 :
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 );
137 : };
138 :
139 : struct PhoneticDataModel
140 : {
141 : sal_Int32 mnFontId; /// Font identifier for text formatting.
142 : sal_Int32 mnType; /// Phonetic text type.
143 : sal_Int32 mnAlignment; /// Phonetic portion alignment.
144 :
145 : explicit PhoneticDataModel();
146 :
147 : /** Sets the passed data from binary import. */
148 : void setBiffData( sal_Int32 nType, sal_Int32 nAlignment );
149 : };
150 :
151 1080 : class PhoneticSettings : public WorkbookHelper
152 : {
153 : public:
154 : explicit PhoneticSettings( const WorkbookHelper& rHelper );
155 :
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 );
160 :
161 : /** Imports phonetic settings from a rich string. */
162 : void importStringData( SequenceInputStream& rStrm );
163 :
164 : private:
165 : PhoneticDataModel maModel;
166 : };
167 :
168 : /** Contains text data and positioning information for a phonetic text portion. */
169 0 : class RichStringPhonetic : public WorkbookHelper
170 : {
171 : public:
172 : explicit RichStringPhonetic( const WorkbookHelper& rHelper );
173 :
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 );
180 :
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.
185 : };
186 :
187 : typedef std::shared_ptr< RichStringPhonetic > RichStringPhoneticRef;
188 :
189 : /** Represents a phonetic text portion in a rich-string with phonetic text.
190 : Used in binary filters only. */
191 : struct PhoneticPortionModel
192 : {
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.
196 :
197 0 : explicit inline PhoneticPortionModel() : mnPos( -1 ), mnBasePos( -1 ), mnBaseLen( 0 ) {}
198 0 : explicit inline PhoneticPortionModel( sal_Int32 nPos, sal_Int32 nBasePos, sal_Int32 nBaseLen ) :
199 0 : mnPos( nPos ), mnBasePos( nBasePos ), mnBaseLen( nBaseLen ) {}
200 :
201 : void read( SequenceInputStream& rStrm );
202 : };
203 :
204 : /** A vector with all phonetic portions in a rich-string. */
205 0 : class PhoneticPortionModelList
206 : {
207 : public:
208 0 : inline explicit PhoneticPortionModelList() : mvModels() {}
209 :
210 0 : bool empty() const { return mvModels.empty(); }
211 :
212 0 : const PhoneticPortionModel& back() const { return mvModels.back(); }
213 :
214 0 : void push_back(const PhoneticPortionModel& rModel) { mvModels.push_back(rModel); }
215 :
216 0 : ::std::vector< PhoneticPortionModel >::const_iterator begin() const { return mvModels.begin(); }
217 :
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 );
222 :
223 : private:
224 : ::std::vector< PhoneticPortionModel > mvModels;
225 : };
226 :
227 : /** Contains string data and a list of formatting runs for a rich formatted string. */
228 1622 : class RichString : public WorkbookHelper
229 : {
230 : public:
231 : explicit RichString( const WorkbookHelper& rHelper );
232 :
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 );
241 :
242 : /** Imports a Unicode rich-string from the passed record stream. */
243 : void importString( SequenceInputStream& rStrm, bool bRich );
244 :
245 : /** Final processing after import of all strings. */
246 : void finalizeImport();
247 :
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;
253 :
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;
264 :
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();
270 :
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 );
275 :
276 : private:
277 : typedef RefVector< RichStringPortion > PortionVector;
278 : typedef RefVector< RichStringPhonetic > PhoneticVector;
279 :
280 : PortionVector maTextPortions; /// String portions with font data.
281 : PhoneticSettings maPhonSettings; /// Phonetic settings for this string.
282 : PhoneticVector maPhonPortions; /// Phonetic text portions.
283 : };
284 :
285 : typedef std::shared_ptr< RichString > RichStringRef;
286 :
287 : } // namespace xls
288 : } // namespace oox
289 :
290 : #endif
291 :
292 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|