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 OOX_XLS_RICHSTRING_HXX
21 : #define OOX_XLS_RICHSTRING_HXX
22 :
23 : #include "oox/helper/refvector.hxx"
24 : #include "stylesbuffer.hxx"
25 :
26 : namespace com { namespace sun { namespace star {
27 : namespace text { class XText; }
28 : } } }
29 :
30 : namespace oox {
31 : namespace xls {
32 :
33 : // ============================================================================
34 :
35 : /** Flags used to specify import/export mode of strings. */
36 : typedef sal_Int32 BiffStringFlags;
37 :
38 : const BiffStringFlags BIFF_STR_DEFAULT = 0x0000; /// Default string settings.
39 : const BiffStringFlags BIFF_STR_FORCEUNICODE = 0x0001; /// Always use UCS-2 characters (default: try to compress). BIFF8 export only.
40 : const BiffStringFlags BIFF_STR_8BITLENGTH = 0x0002; /// 8-bit string length field (default: 16-bit).
41 : const BiffStringFlags BIFF_STR_SMARTFLAGS = 0x0004; /// Omit flags on empty string (default: read/write always). BIFF8 only.
42 : const BiffStringFlags BIFF_STR_KEEPFONTS = 0x0008; /// Keep old fonts when reading unformatted string (default: clear fonts). Import only.
43 : const BiffStringFlags BIFF_STR_EXTRAFONTS = 0x0010; /// Read trailing rich-string font array (default: nothing). BIFF2-BIFF5 import only.
44 :
45 : // ============================================================================
46 :
47 : /** Contains text data and font attributes for a part of a rich formatted string. */
48 148 : 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 ::rtl::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 79 : inline const ::rtl::OUString& getText() const { return maText; }
65 : /** Returns true, if the portion fontains font formatting. */
66 77 : 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 Font* pFont, bool bReplace );
72 :
73 : void writeFontProperties(
74 : const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
75 : const Font* pFont ) const;
76 :
77 : private:
78 : ::rtl::OUString maText; /// Portion text.
79 : FontRef mxFont; /// Embedded portion font, may be empty.
80 : sal_Int32 mnFontId; /// Link to global font list.
81 : };
82 :
83 : typedef ::boost::shared_ptr< RichStringPortion > RichStringPortionRef;
84 :
85 : // ----------------------------------------------------------------------------
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 : // ----------------------------------------------------------------------------
95 :
96 : /** Represents a position in a rich-string containing current font identifier.
97 :
98 : This object stores the position of a formatted character in a rich-string
99 : and the identifier of a font from the global font list used to format this
100 : and the following characters. Used in binary filters only.
101 : */
102 : struct FontPortionModel
103 : {
104 : sal_Int32 mnPos; /// First character in the string.
105 : sal_Int32 mnFontId; /// Font identifier for the next characters.
106 :
107 0 : explicit inline FontPortionModel() : mnPos( 0 ), mnFontId( -1 ) {}
108 0 : explicit inline FontPortionModel( sal_Int32 nPos, sal_Int32 nFontId ) :
109 0 : mnPos( nPos ), mnFontId( nFontId ) {}
110 :
111 : void read( SequenceInputStream& rStrm );
112 : };
113 :
114 : // ----------------------------------------------------------------------------
115 :
116 : /** A vector with all font portions in a rich-string. */
117 0 : class FontPortionModelList : public ::std::vector< FontPortionModel >
118 : {
119 : public:
120 0 : inline explicit FontPortionModelList() {}
121 :
122 : /** Appends a rich-string font identifier. */
123 : void appendPortion( const FontPortionModel& rPortion );
124 : /** Reads count and font identifiers from the passed stream. */
125 : void importPortions( SequenceInputStream& rStrm );
126 : };
127 :
128 : // ============================================================================
129 :
130 : struct PhoneticDataModel
131 : {
132 : sal_Int32 mnFontId; /// Font identifier for text formatting.
133 : sal_Int32 mnType; /// Phonetic text type.
134 : sal_Int32 mnAlignment; /// Phonetic portion alignment.
135 :
136 : explicit PhoneticDataModel();
137 :
138 : /** Sets the passed data from binary import. */
139 : void setBiffData( sal_Int32 nType, sal_Int32 nAlignment );
140 : };
141 :
142 : // ----------------------------------------------------------------------------
143 :
144 98 : class PhoneticSettings : public WorkbookHelper
145 : {
146 : public:
147 : explicit PhoneticSettings( const WorkbookHelper& rHelper );
148 :
149 : /** Imports phonetic settings from the phoneticPr element. */
150 : void importPhoneticPr( const AttributeList& rAttribs );
151 : /** Imports phonetic settings from the PHONETICPR record. */
152 : void importPhoneticPr( SequenceInputStream& rStrm );
153 :
154 : /** Imports phonetic settings from a rich string. */
155 : void importStringData( SequenceInputStream& rStrm );
156 :
157 : private:
158 : PhoneticDataModel maModel;
159 : };
160 :
161 : // ============================================================================
162 :
163 : /** Contains text data and positioning information for a phonetic text portion. */
164 0 : class RichStringPhonetic : public WorkbookHelper
165 : {
166 : public:
167 : explicit RichStringPhonetic( const WorkbookHelper& rHelper );
168 :
169 : /** Sets text data for this phonetic portion. */
170 : void setText( const ::rtl::OUString& rText );
171 : /** Imports attributes of a phonetic run (rPh element). */
172 : void importPhoneticRun( const AttributeList& rAttribs );
173 : /** Sets the associated range in base text for this phonetic portion. */
174 : void setBaseRange( sal_Int32 nBasePos, sal_Int32 nBaseEnd );
175 :
176 : private:
177 : ::rtl::OUString maText; /// Portion text.
178 : sal_Int32 mnBasePos; /// Start position in base text.
179 : sal_Int32 mnBaseEnd; /// One-past-end position in base text.
180 : };
181 :
182 : typedef ::boost::shared_ptr< RichStringPhonetic > RichStringPhoneticRef;
183 :
184 : // ----------------------------------------------------------------------------
185 :
186 : /** Represents a phonetic text portion in a rich-string with phonetic text.
187 : Used in binary filters only. */
188 : struct PhoneticPortionModel
189 : {
190 : sal_Int32 mnPos; /// First character in phonetic text.
191 : sal_Int32 mnBasePos; /// First character in base text.
192 : sal_Int32 mnBaseLen; /// Number of characters in base text.
193 :
194 0 : explicit inline PhoneticPortionModel() : mnPos( -1 ), mnBasePos( -1 ), mnBaseLen( 0 ) {}
195 0 : explicit inline PhoneticPortionModel( sal_Int32 nPos, sal_Int32 nBasePos, sal_Int32 nBaseLen ) :
196 0 : mnPos( nPos ), mnBasePos( nBasePos ), mnBaseLen( nBaseLen ) {}
197 :
198 : void read( SequenceInputStream& rStrm );
199 : };
200 :
201 : // ----------------------------------------------------------------------------
202 :
203 : /** A vector with all phonetic portions in a rich-string. */
204 0 : class PhoneticPortionModelList : public ::std::vector< PhoneticPortionModel >
205 : {
206 : public:
207 0 : inline explicit PhoneticPortionModelList() {}
208 :
209 : /** Appends a rich-string phonetic portion. */
210 : void appendPortion( const PhoneticPortionModel& rPortion );
211 : /** Reads all phonetic portions from the passed stream. */
212 : void importPortions( SequenceInputStream& rStrm );
213 : };
214 :
215 : // ============================================================================
216 :
217 : /** Contains string data and a list of formatting runs for a rich formatted string. */
218 146 : class RichString : public WorkbookHelper
219 : {
220 : public:
221 : explicit RichString( const WorkbookHelper& rHelper );
222 :
223 : /** Appends and returns a portion object for a plain string (t element). */
224 : RichStringPortionRef importText( const AttributeList& rAttribs );
225 : /** Appends and returns a portion object for a new formatting run (r element). */
226 : RichStringPortionRef importRun( const AttributeList& rAttribs );
227 : /** Appends and returns a phonetic text object for a new phonetic run (rPh element). */
228 : RichStringPhoneticRef importPhoneticRun( const AttributeList& rAttribs );
229 : /** Imports phonetic settings from the rPhoneticPr element. */
230 : void importPhoneticPr( const AttributeList& rAttribs );
231 :
232 : /** Imports a Unicode rich-string from the passed record stream. */
233 : void importString( SequenceInputStream& rStrm, bool bRich );
234 :
235 : /** Final processing after import of all strings. */
236 : void finalizeImport();
237 :
238 : /** Tries to extract a plain string from this object. Returns the string,
239 : if there is only one unformatted portion. */
240 : bool extractPlainString(
241 : ::rtl::OUString& orString,
242 : const Font* pFirstPortionFont = 0 ) const;
243 :
244 : /** Converts the string and writes it into the passed XText.
245 : @param rxText The XText interface of the target object.
246 : @param bReplaceOld True = replace old contents of the text object.
247 : @param pFirstPortionFont Optional font providing additional rich-text
248 : formatting for the first text portion, e.g. font escapement. */
249 : void convert(
250 : const ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >& rxText,
251 : bool bReplaceOld,
252 : const Font* pFirstPortionFont = 0 ) const;
253 :
254 : private:
255 : /** Creates, appends, and returns a new empty string portion. */
256 : RichStringPortionRef createPortion();
257 : /** Creates, appends, and returns a new empty phonetic text portion. */
258 : RichStringPhoneticRef createPhonetic();
259 :
260 : /** Create base text portions from the passed string and character formatting. */
261 : void createTextPortions( const ::rtl::OUString& rText, FontPortionModelList& rPortions );
262 : /** Create phonetic text portions from the passed string and portion data. */
263 : void createPhoneticPortions( const ::rtl::OUString& rText, PhoneticPortionModelList& rPortions, sal_Int32 nBaseLen );
264 :
265 : private:
266 : typedef RefVector< RichStringPortion > PortionVector;
267 : typedef RefVector< RichStringPhonetic > PhoneticVector;
268 :
269 : PortionVector maTextPortions; /// String portions with font data.
270 : PhoneticSettings maPhonSettings; /// Phonetic settings for this string.
271 : PhoneticVector maPhonPortions; /// Phonetic text portions.
272 : };
273 :
274 : typedef ::boost::shared_ptr< RichString > RichStringRef;
275 :
276 : // ============================================================================
277 :
278 : } // namespace xls
279 : } // namespace oox
280 :
281 : #endif
282 :
283 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|