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 #pragma once
21 
22 #include <oox/helper/refvector.hxx>
23 #include "stylesbuffer.hxx"
24 
25 class EditTextObject;
26 struct ESelection;
28 
29 namespace com::sun::star {
30  namespace text { class XText; }
31 }
32 
33 namespace oox { class SequenceInputStream; }
34 
35 namespace oox::xls {
36 
39 {
40 public:
41  explicit RichStringPortion( const WorkbookHelper& rHelper );
42 
44  void setText( const OUString& rText );
46  FontRef const & createFont();
48  void setFontId( sal_Int32 nFontId );
49 
51  void finalizeImport();
52 
54  const OUString& getText() const { return maText; }
56  bool hasFont() const { return bool(mxFont); }
57 
59  void convert(
60  const css::uno::Reference< css::text::XText >& rxText,
61  bool bReplace );
62  void convert( ScEditEngineDefaulter& rEE, ESelection& rSelection, const oox::xls::Font* pFont );
63 
65  const css::uno::Reference< css::text::XText >& rxText ) const;
66 
67 private:
68  OUString maText;
70  sal_Int32 mnFontId;
71  bool mbConverted;
72 };
73 
74 typedef std::shared_ptr< RichStringPortion > RichStringPortionRef;
75 
83 {
84  sal_Int32 mnPos;
85  sal_Int32 mnFontId;
86 
87  explicit FontPortionModel() : mnPos( 0 ), mnFontId( -1 ) {}
88  explicit FontPortionModel( sal_Int32 nPos ) : mnPos( nPos ), mnFontId( -1 ) {}
89 
90  void read( SequenceInputStream& rStrm );
91 };
92 
95  ::std::vector< FontPortionModel > mvModels;
96 
97 public:
98  explicit FontPortionModelList() : mvModels() {}
99 
100  bool empty() const { return mvModels.empty(); }
101 
102  const FontPortionModel& back() const { return mvModels.back(); }
103  const FontPortionModel& front() const { return mvModels.front(); }
104 
105  void push_back(const FontPortionModel& rModel) { mvModels.push_back(rModel); }
106 
107  void insert(::std::vector< FontPortionModel >::iterator it,
108  const FontPortionModel& rModel)
109  { mvModels.insert(it, rModel); }
110 
111  ::std::vector< FontPortionModel >::iterator begin() { return mvModels.begin(); }
112 
114  void appendPortion( const FontPortionModel& rPortion );
116  void importPortions( SequenceInputStream& rStrm );
117 };
118 
120 {
121  sal_Int32 mnFontId;
122  sal_Int32 mnType;
123  sal_Int32 mnAlignment;
124 
125  explicit PhoneticDataModel();
126 
128  void setBiffData( sal_Int32 nType, sal_Int32 nAlignment );
129 };
130 
132 {
133 public:
134  explicit PhoneticSettings( const WorkbookHelper& rHelper );
135 
137  void importPhoneticPr( const AttributeList& rAttribs );
140 
142  void importStringData( SequenceInputStream& rStrm );
143 
144 private:
146 };
147 
150 {
151 public:
152  explicit RichStringPhonetic( const WorkbookHelper& rHelper );
153 
155  void setText( const OUString& rText );
157  void importPhoneticRun( const AttributeList& rAttribs );
159  void setBaseRange( sal_Int32 nBasePos, sal_Int32 nBaseEnd );
160 
161 private:
162  OUString maText;
163  sal_Int32 mnBasePos;
164  sal_Int32 mnBaseEnd;
165 };
166 
167 typedef std::shared_ptr< RichStringPhonetic > RichStringPhoneticRef;
168 
172 {
173  sal_Int32 mnPos;
174  sal_Int32 mnBasePos;
175  sal_Int32 mnBaseLen;
176 
177  explicit PhoneticPortionModel() : mnPos( -1 ), mnBasePos( -1 ), mnBaseLen( 0 ) {}
178  explicit PhoneticPortionModel( sal_Int32 nPos, sal_Int32 nBasePos, sal_Int32 nBaseLen ) :
179  mnPos( nPos ), mnBasePos( nBasePos ), mnBaseLen( nBaseLen ) {}
180 
181  void read( SequenceInputStream& rStrm );
182 };
183 
186 {
187 public:
189 
190  bool empty() const { return mvModels.empty(); }
191 
192  const PhoneticPortionModel& back() const { return mvModels.back(); }
193 
194  void push_back(const PhoneticPortionModel& rModel) { mvModels.push_back(rModel); }
195 
196  ::std::vector< PhoneticPortionModel >::const_iterator begin() const { return mvModels.begin(); }
197 
199  void appendPortion( const PhoneticPortionModel& rPortion );
201  void importPortions( SequenceInputStream& rStrm );
202 
203 private:
204  ::std::vector< PhoneticPortionModel > mvModels;
205 };
206 
209 {
210 public:
211  explicit RichString( const WorkbookHelper& rHelper );
212 
214  RichStringPortionRef importText();
216  RichStringPortionRef importRun();
218  RichStringPhoneticRef importPhoneticRun( const AttributeList& rAttribs );
220  void importPhoneticPr( const AttributeList& rAttribs );
221 
223  void importString( SequenceInputStream& rStrm, bool bRich );
224 
226  void finalizeImport();
227 
230  bool extractPlainString(
231  OUString& orString,
232  const oox::xls::Font* pFirstPortionFont ) const;
233 
237  void convert( const css::uno::Reference< css::text::XText >& rxText ) const;
238  std::unique_ptr<EditTextObject> convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFont ) const;
239 
240 private:
242  RichStringPortionRef createPortion();
244  RichStringPhoneticRef createPhonetic();
245 
247  void createTextPortions( const OUString& rText, FontPortionModelList& rPortions );
249  void createPhoneticPortions( const OUString& rText, PhoneticPortionModelList& rPortions, sal_Int32 nBaseLen );
250 
251 private:
254 
255  PortionVector maTextPortions;
257  PhoneticVector maPhonPortions;
258 };
259 
260 typedef std::shared_ptr< RichString > RichStringRef;
261 
262 } // namespace oox::xls
263 
264 /* 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:431
void setText(const OUString &rText)
Sets text data for this portion.
Definition: richstring.cxx:170
Represents a position in a rich-string containing current font identifier.
Definition: richstring.hxx:82
sal_Int32 mnAlignment
Phonetic text type.
Definition: richstring.hxx:123
PhoneticPortionModel()
Number of characters in base text.
Definition: richstring.hxx:177
Contains text data and font attributes for a part of a rich formatted string.
Definition: richstring.hxx:38
void push_back(const PhoneticPortionModel &rModel)
Definition: richstring.hxx:194
void importPortions(SequenceInputStream &rStrm)
Reads all phonetic portions from the passed stream.
Definition: richstring.cxx:392
void setBaseRange(sal_Int32 nBasePos, sal_Int32 nBaseEnd)
Sets the associated range in base text for this phonetic portion.
Definition: richstring.cxx:362
RichStringPortion(const WorkbookHelper &rHelper)
Definition: richstring.cxx:163
std::shared_ptr< RichStringPortion > RichStringPortionRef
Definition: richstring.hxx:74
RefVector< RichStringPortion > PortionVector
Definition: richstring.hxx:252
::std::vector< FontPortionModel >::iterator begin()
Definition: richstring.hxx:111
Contains string data and a list of formatting runs for a rich formatted string.
Definition: richstring.hxx:208
RichStringPortionRef importRun()
Appends and returns a portion object for a new formatting run (r element).
Definition: richstring.cxx:419
PhoneticVector maPhonPortions
Phonetic settings for this string.
Definition: richstring.hxx:257
sal_Int32 mnBaseEnd
Start position in base text.
Definition: richstring.hxx:164
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:107
const FontPortionModel & front() const
Definition: richstring.hxx:103
PhoneticPortionModel(sal_Int32 nPos, sal_Int32 nBasePos, sal_Int32 nBaseLen)
Definition: richstring.hxx:178
void importPortions(SequenceInputStream &rStrm)
Reads count and font identifiers from the passed stream.
Definition: richstring.cxx:278
void read(SequenceInputStream &rStrm)
Definition: richstring.cxx:368
void setFontId(sal_Int32 nFontId)
Links this portion to a font object from the global font list.
Definition: richstring.cxx:181
void importPhoneticPr(const AttributeList &rAttribs)
Imports phonetic settings from the phoneticPr element.
Definition: richstring.cxx:317
void createPhoneticPortions(const OUString &rText, PhoneticPortionModelList &rPortions, sal_Int32 nBaseLen)
Create phonetic text portions from the passed string and portion data.
Definition: richstring.cxx:568
void finalizeImport()
Final processing after import of all strings.
Definition: richstring.cxx:462
Contains text data and positioning information for a phonetic text portion.
Definition: richstring.hxx:149
FontRef mxFont
Portion text.
Definition: richstring.hxx:69
sal_Int32 mnBaseLen
First character in base text.
Definition: richstring.hxx:175
std::shared_ptr< RichString > RichStringRef
Definition: richstring.hxx:260
::std::vector< FontPortionModel > mvModels
Definition: richstring.hxx:95
void importString(SequenceInputStream &rStrm, bool bRich)
Imports a Unicode rich-string from the passed record stream.
Definition: richstring.cxx:436
PhoneticSettings(const WorkbookHelper &rHelper)
Definition: richstring.cxx:312
PhoneticDataModel maModel
Definition: richstring.hxx:145
void appendPortion(const PhoneticPortionModel &rPortion)
Appends a rich-string phonetic portion.
Definition: richstring.cxx:375
A vector with all font portions in a rich-string.
Definition: richstring.hxx:94
RichStringPhonetic(const WorkbookHelper &rHelper)
Definition: richstring.cxx:344
const OUString & getText() const
Returns the text data of this portion.
Definition: richstring.hxx:54
void push_back(const FontPortionModel &rModel)
Definition: richstring.hxx:105
void writeFontProperties(const css::uno::Reference< css::text::XText > &rxText) const
Definition: richstring.cxx:254
void setText(const OUString &rText)
Sets text data for this phonetic portion.
Definition: richstring.cxx:351
void importStringData(SequenceInputStream &rStrm)
Imports phonetic settings from a rich string.
Definition: richstring.cxx:335
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:424
void read(SequenceInputStream &rStrm)
Definition: richstring.cxx:262
sal_Int32 mnBasePos
Portion text.
Definition: richstring.hxx:163
PhoneticSettings maPhonSettings
String portions with font data.
Definition: richstring.hxx:256
void importPhoneticRun(const AttributeList &rAttribs)
Imports attributes of a phonetic run (rPh element).
Definition: richstring.cxx:356
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:71
const PhoneticPortionModel & back() const
Definition: richstring.hxx:192
PortionVector maTextPortions
Definition: richstring.hxx:255
::std::vector< PhoneticPortionModel > mvModels
Definition: richstring.hxx:204
RichStringPortionRef createPortion()
Creates, appends, and returns a new empty string portion.
Definition: richstring.cxx:528
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:542
bool hasFont() const
Returns true, if the portion contains font formatting.
Definition: richstring.hxx:56
Represents a phonetic text portion in a rich-string with phonetic text.
Definition: richstring.hxx:171
RichStringPortionRef importText()
Appends and returns a portion object for a plain string (t element).
Definition: richstring.cxx:414
void appendPortion(const FontPortionModel &rPortion)
Appends a rich-string font identifier.
Definition: richstring.cxx:268
void setBiffData(sal_Int32 nType, sal_Int32 nAlignment)
Sets the passed data from binary import.
Definition: richstring.cxx:303
sal_Int32 mnBasePos
First character in phonetic text.
Definition: richstring.hxx:174
A vector with all phonetic portions in a rich-string.
Definition: richstring.hxx:185
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
FontPortionModel(sal_Int32 nPos)
Definition: richstring.hxx:88
void finalizeImport()
Final processing after import of all strings.
Definition: richstring.cxx:186
FontPortionModel()
Font identifier for the next characters.
Definition: richstring.hxx:87
RefVector< RichStringPhonetic > PhoneticVector
Definition: richstring.hxx:253
sal_Int32 mnFontId
First character in the string.
Definition: richstring.hxx:85
sal_Int32 mnType
Font identifier for text formatting.
Definition: richstring.hxx:122
FontRef const & createFont()
Creates and returns a new font formatting object.
Definition: richstring.cxx:175
sal_Int32 mnFontId
Embedded portion font, may be empty.
Definition: richstring.hxx:70
::std::vector< PhoneticPortionModel >::const_iterator begin() const
Definition: richstring.hxx:196
RichString(const WorkbookHelper &rHelper)
Definition: richstring.cxx:408
std::shared_ptr< RichStringPhonetic > RichStringPhoneticRef
Definition: richstring.hxx:167
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:467
RichStringPhoneticRef createPhonetic()
Creates, appends, and returns a new empty phonetic text portion.
Definition: richstring.cxx:535
PhoneticDataModel()
Phonetic portion alignment.
Definition: richstring.cxx:296
const FontPortionModel & back() const
Definition: richstring.hxx:102