LibreOffice Module sc (master)  1
richstring.hxx
Go to the documentation of this file.
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;
29 
30 namespace com::sun::star {
31  namespace text { class XText; }
32 }
33 
34 namespace oox { class SequenceInputStream; }
35 
36 namespace oox::xls {
37 
40 {
41 public:
42  explicit RichStringPortion( const WorkbookHelper& rHelper );
43 
45  void setText( const OUString& rText );
47  FontRef const & createFont();
49  void setFontId( sal_Int32 nFontId );
50 
52  void finalizeImport();
53 
55  const OUString& getText() const { return maText; }
57  bool hasFont() const { return bool(mxFont); }
58 
60  void convert(
61  const css::uno::Reference< css::text::XText >& rxText,
62  bool bReplace );
63  void convert( ScEditEngineDefaulter& rEE, ESelection& rSelection, const oox::xls::Font* pFont );
64 
66  const css::uno::Reference< css::text::XText >& rxText ) const;
67 
68 private:
69  OUString maText;
71  sal_Int32 mnFontId;
72  bool mbConverted;
73 };
74 
75 typedef std::shared_ptr< RichStringPortion > RichStringPortionRef;
76 
84 {
85  sal_Int32 mnPos;
86  sal_Int32 mnFontId;
87 
88  explicit FontPortionModel() : mnPos( 0 ), mnFontId( -1 ) {}
89  explicit FontPortionModel( sal_Int32 nPos ) : mnPos( nPos ), mnFontId( -1 ) {}
90 
91  void read( SequenceInputStream& rStrm );
92 };
93 
96  ::std::vector< FontPortionModel > mvModels;
97 
98 public:
99  explicit FontPortionModelList() : mvModels() {}
100 
101  bool empty() const { return mvModels.empty(); }
102 
103  const FontPortionModel& back() const { return mvModels.back(); }
104  const FontPortionModel& front() const { return mvModels.front(); }
105 
106  void push_back(const FontPortionModel& rModel) { mvModels.push_back(rModel); }
107 
108  void insert(::std::vector< FontPortionModel >::iterator it,
109  const FontPortionModel& rModel)
110  { mvModels.insert(it, rModel); }
111 
112  ::std::vector< FontPortionModel >::iterator begin() { return mvModels.begin(); }
113 
115  void appendPortion( const FontPortionModel& rPortion );
117  void importPortions( SequenceInputStream& rStrm );
118 };
119 
121 {
122  sal_Int32 mnFontId;
123  sal_Int32 mnType;
124  sal_Int32 mnAlignment;
125 
126  explicit PhoneticDataModel();
127 
129  void setBiffData( sal_Int32 nType, sal_Int32 nAlignment );
130 };
131 
133 {
134 public:
135  explicit PhoneticSettings( const WorkbookHelper& rHelper );
136 
138  void importPhoneticPr( const AttributeList& rAttribs );
141 
143  void importStringData( SequenceInputStream& rStrm );
144 
145 private:
147 };
148 
151 {
152 public:
153  explicit RichStringPhonetic( const WorkbookHelper& rHelper );
154 
156  void setText( const OUString& rText );
158  void importPhoneticRun( const AttributeList& rAttribs );
160  void setBaseRange( sal_Int32 nBasePos, sal_Int32 nBaseEnd );
161 
162 private:
163  OUString maText;
164  sal_Int32 mnBasePos;
165  sal_Int32 mnBaseEnd;
166 };
167 
168 typedef std::shared_ptr< RichStringPhonetic > RichStringPhoneticRef;
169 
173 {
174  sal_Int32 mnPos;
175  sal_Int32 mnBasePos;
176  sal_Int32 mnBaseLen;
177 
178  explicit PhoneticPortionModel() : mnPos( -1 ), mnBasePos( -1 ), mnBaseLen( 0 ) {}
179  explicit PhoneticPortionModel( sal_Int32 nPos, sal_Int32 nBasePos, sal_Int32 nBaseLen ) :
180  mnPos( nPos ), mnBasePos( nBasePos ), mnBaseLen( nBaseLen ) {}
181 
182  void read( SequenceInputStream& rStrm );
183 };
184 
187 {
188 public:
190 
191  bool empty() const { return mvModels.empty(); }
192 
193  const PhoneticPortionModel& back() const { return mvModels.back(); }
194 
195  void push_back(const PhoneticPortionModel& rModel) { mvModels.push_back(rModel); }
196 
197  ::std::vector< PhoneticPortionModel >::const_iterator begin() const { return mvModels.begin(); }
198 
200  void appendPortion( const PhoneticPortionModel& rPortion );
202  void importPortions( SequenceInputStream& rStrm );
203 
204 private:
205  ::std::vector< PhoneticPortionModel > mvModels;
206 };
207 
210 {
211 public:
212  explicit RichString( const WorkbookHelper& rHelper );
213 
215  RichStringPortionRef importText();
217  RichStringPortionRef importRun();
219  RichStringPhoneticRef importPhoneticRun( const AttributeList& rAttribs );
221  void importPhoneticPr( const AttributeList& rAttribs );
222 
224  void importString( SequenceInputStream& rStrm, bool bRich );
225 
227  void finalizeImport();
228 
231  bool extractPlainString(
232  OUString& orString,
233  const oox::xls::Font* pFirstPortionFont ) const;
234 
238  void convert( const css::uno::Reference< css::text::XText >& rxText ) const;
239  std::unique_ptr<EditTextObject> convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFont ) const;
240 
241 private:
243  RichStringPortionRef createPortion();
245  RichStringPhoneticRef createPhonetic();
246 
248  void createTextPortions( const OUString& rText, FontPortionModelList& rPortions );
250  void createPhoneticPortions( const OUString& rText, PhoneticPortionModelList& rPortions, sal_Int32 nBaseLen );
251 
252 private:
255 
256  PortionVector maTextPortions;
258  PhoneticVector maPhonPortions;
259 };
260 
261 typedef std::shared_ptr< RichString > RichStringRef;
262 
263 } // namespace oox::xls
264 
265 #endif
266 
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper class to provide access to global workbook data.
void importPhoneticPr(const AttributeList &rAttribs)
Imports phonetic settings from the rPhoneticPr element.
Definition: richstring.cxx:321
void setText(const OUString &rText)
Sets text data for this portion.
Definition: richstring.cxx:60
Represents a position in a rich-string containing current font identifier.
Definition: richstring.hxx:83
sal_Int32 mnAlignment
Phonetic text type.
Definition: richstring.hxx:124
PhoneticPortionModel()
Number of characters in base text.
Definition: richstring.hxx:178
Contains text data and font attributes for a part of a rich formatted string.
Definition: richstring.hxx:39
void push_back(const PhoneticPortionModel &rModel)
Definition: richstring.hxx:195
void importPortions(SequenceInputStream &rStrm)
Reads all phonetic portions from the passed stream.
Definition: richstring.cxx:282
void setBaseRange(sal_Int32 nBasePos, sal_Int32 nBaseEnd)
Sets the associated range in base text for this phonetic portion.
Definition: richstring.cxx:252
RichStringPortion(const WorkbookHelper &rHelper)
Definition: richstring.cxx:53
std::shared_ptr< RichStringPortion > RichStringPortionRef
Definition: richstring.hxx:75
RefVector< RichStringPortion > PortionVector
Definition: richstring.hxx:253
::std::vector< FontPortionModel >::iterator begin()
Definition: richstring.hxx:112
Contains string data and a list of formatting runs for a rich formatted string.
Definition: richstring.hxx:209
RichStringPortionRef importRun()
Appends and returns a portion object for a new formatting run (r element).
Definition: richstring.cxx:309
PhoneticVector maPhonPortions
Phonetic settings for this string.
Definition: richstring.hxx:258
sal_Int32 mnBaseEnd
Start position in base text.
Definition: richstring.hxx:165
void convert(const css::uno::Reference< css::text::XText > &rxText, bool bReplace)
Converts the portion and replaces or appends to the passed XText.
void insert(::std::vector< FontPortionModel >::iterator it, const FontPortionModel &rModel)
Definition: richstring.hxx:108
const FontPortionModel & front() const
Definition: richstring.hxx:104
PhoneticPortionModel(sal_Int32 nPos, sal_Int32 nBasePos, sal_Int32 nBaseLen)
Definition: richstring.hxx:179
void importPortions(SequenceInputStream &rStrm)
Reads count and font identifiers from the passed stream.
Definition: richstring.cxx:168
void read(SequenceInputStream &rStrm)
Definition: richstring.cxx:258
void setFontId(sal_Int32 nFontId)
Links this portion to a font object from the global font list.
Definition: richstring.cxx:71
void importPhoneticPr(const AttributeList &rAttribs)
Imports phonetic settings from the phoneticPr element.
Definition: richstring.cxx:207
void createPhoneticPortions(const OUString &rText, PhoneticPortionModelList &rPortions, sal_Int32 nBaseLen)
Create phonetic text portions from the passed string and portion data.
Definition: richstring.cxx:458
void finalizeImport()
Final processing after import of all strings.
Definition: richstring.cxx:352
Contains text data and positioning information for a phonetic text portion.
Definition: richstring.hxx:150
FontRef mxFont
Portion text.
Definition: richstring.hxx:70
sal_Int32 mnBaseLen
First character in base text.
Definition: richstring.hxx:176
std::shared_ptr< RichString > RichStringRef
Definition: richstring.hxx:261
::std::vector< FontPortionModel > mvModels
Definition: richstring.hxx:96
void importString(SequenceInputStream &rStrm, bool bRich)
Imports a Unicode rich-string from the passed record stream.
Definition: richstring.cxx:326
PhoneticSettings(const WorkbookHelper &rHelper)
Definition: richstring.cxx:202
PhoneticDataModel maModel
Definition: richstring.hxx:146
void appendPortion(const PhoneticPortionModel &rPortion)
Appends a rich-string phonetic portion.
Definition: richstring.cxx:265
A vector with all font portions in a rich-string.
Definition: richstring.hxx:95
RichStringPhonetic(const WorkbookHelper &rHelper)
Definition: richstring.cxx:234
const OUString & getText() const
Returns the text data of this portion.
Definition: richstring.hxx:55
void push_back(const FontPortionModel &rModel)
Definition: richstring.hxx:106
void writeFontProperties(const css::uno::Reference< css::text::XText > &rxText) const
Definition: richstring.cxx:144
void setText(const OUString &rText)
Sets text data for this phonetic portion.
Definition: richstring.cxx:241
void importStringData(SequenceInputStream &rStrm)
Imports phonetic settings from a rich string.
Definition: richstring.cxx:225
exports com.sun.star. text
RichStringPhoneticRef importPhoneticRun(const AttributeList &rAttribs)
Appends and returns a phonetic text object for a new phonetic run (rPh element).
Definition: richstring.cxx:314
void read(SequenceInputStream &rStrm)
Definition: richstring.cxx:152
sal_Int32 mnBasePos
Portion text.
Definition: richstring.hxx:164
PhoneticSettings maPhonSettings
String portions with font data.
Definition: richstring.hxx:257
void importPhoneticRun(const AttributeList &rAttribs)
Imports attributes of a phonetic run (rPh element).
Definition: richstring.cxx:246
void convert(const css::uno::Reference< css::text::XText > &rxText) const
Converts the string and writes it into the passed XText, replace old contents of the text object...
bool mbConverted
Link to global font list.
Definition: richstring.hxx:72
const PhoneticPortionModel & back() const
Definition: richstring.hxx:193
PortionVector maTextPortions
Definition: richstring.hxx:256
::std::vector< PhoneticPortionModel > mvModels
Definition: richstring.hxx:205
RichStringPortionRef createPortion()
Creates, appends, and returns a new empty string portion.
Definition: richstring.cxx:418
std::shared_ptr< Font > FontRef
void createTextPortions(const OUString &rText, FontPortionModelList &rPortions)
Create base text portions from the passed string and character formatting.
Definition: richstring.cxx:432
bool hasFont() const
Returns true, if the portion contains font formatting.
Definition: richstring.hxx:57
Represents a phonetic text portion in a rich-string with phonetic text.
Definition: richstring.hxx:172
RichStringPortionRef importText()
Appends and returns a portion object for a plain string (t element).
Definition: richstring.cxx:304
void appendPortion(const FontPortionModel &rPortion)
Appends a rich-string font identifier.
Definition: richstring.cxx:158
void setBiffData(sal_Int32 nType, sal_Int32 nAlignment)
Sets the passed data from binary import.
Definition: richstring.cxx:193
sal_Int32 mnBasePos
First character in phonetic text.
Definition: richstring.hxx:175
A vector with all phonetic portions in a rich-string.
Definition: richstring.hxx:186
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:401
FontPortionModel(sal_Int32 nPos)
Definition: richstring.hxx:89
void finalizeImport()
Final processing after import of all strings.
Definition: richstring.cxx:76
FontPortionModel()
Font identifier for the next characters.
Definition: richstring.hxx:88
RefVector< RichStringPhonetic > PhoneticVector
Definition: richstring.hxx:254
sal_Int32 mnFontId
First character in the string.
Definition: richstring.hxx:86
sal_Int32 mnType
Font identifier for text formatting.
Definition: richstring.hxx:123
FontRef const & createFont()
Creates and returns a new font formatting object.
Definition: richstring.cxx:65
sal_Int32 mnFontId
Embedded portion font, may be empty.
Definition: richstring.hxx:71
::std::vector< PhoneticPortionModel >::const_iterator begin() const
Definition: richstring.hxx:197
RichString(const WorkbookHelper &rHelper)
Definition: richstring.cxx:298
std::shared_ptr< RichStringPhonetic > RichStringPhoneticRef
Definition: richstring.hxx:168
void SvStream & rStrm
bool extractPlainString(OUString &orString, const oox::xls::Font *pFirstPortionFont) const
Tries to extract a plain string from this object.
Definition: richstring.cxx:357
RichStringPhoneticRef createPhonetic()
Creates, appends, and returns a new empty phonetic text portion.
Definition: richstring.cxx:425
PhoneticDataModel()
Phonetic portion alignment.
Definition: richstring.cxx:186
const FontPortionModel & back() const
Definition: richstring.hxx:103