tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / sc / source / filter / inc / richstring.hxx
blob3969de6b7974dfa210777ea977a95a02eea12637
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 #pragma once
22 #include <oox/helper/refvector.hxx>
23 #include "stylesbuffer.hxx"
25 class EditTextObject;
26 struct ESelection;
27 class ScEditEngineDefaulter;
29 namespace com::sun::star {
30 namespace text { class XText; }
33 namespace oox { class SequenceInputStream; }
35 namespace oox::xls {
37 /** Contains text data and font attributes for a part of a rich formatted string. */
38 class RichStringPortion
40 public:
41 RichStringPortion();
43 /** Sets text data for this portion. */
44 void setText( const OUString& rText );
45 /** Creates and returns a new font formatting object. */
46 FontRef const & createFont(const WorkbookHelper& rHelper);
47 /** Links this portion to a font object from the global font list. */
48 void setFontId( sal_Int32 nFontId );
50 /** Final processing after import of all strings. */
51 void finalizeImport(const WorkbookHelper& rHelper);
53 /** Returns the text data of this portion. */
54 const OUString& getText() const { return maText; }
55 /** Returns true, if the portion contains font formatting. */
56 bool hasFont() const { return bool(mxFont); }
58 /** Converts the portion and replaces or appends to the passed XText. */
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 );
64 void writeFontProperties(
65 const css::uno::Reference< css::text::XText >& rxText ) const;
67 private:
68 OUString maText; /// Portion text.
69 FontRef mxFont; /// Embedded portion font, may be empty.
70 sal_Int32 mnFontId; /// Link to global font list.
71 bool mbConverted; /// Without repeatedly convert
74 /** Represents a position in a rich-string containing current font identifier.
76 This object stores the position of a formatted character in a rich-string
77 and the identifier of a font from the global font list used to format this
78 and the following characters. Used in binary filters only.
80 struct FontPortionModel
82 sal_Int32 mnPos; /// First character in the string.
83 sal_Int32 mnFontId; /// Font identifier for the next characters.
85 explicit FontPortionModel() : mnPos( 0 ), mnFontId( -1 ) {}
86 explicit FontPortionModel( sal_Int32 nPos ) : mnPos( nPos ), mnFontId( -1 ) {}
88 void read( SequenceInputStream& rStrm );
91 /** A vector with all font portions in a rich-string. */
92 class FontPortionModelList {
93 ::std::vector< FontPortionModel > mvModels;
95 public:
96 explicit FontPortionModelList() : mvModels() {}
98 bool empty() const { return mvModels.empty(); }
100 const FontPortionModel& back() const { return mvModels.back(); }
101 const FontPortionModel& front() const { return mvModels.front(); }
103 void push_back(const FontPortionModel& rModel) { mvModels.push_back(rModel); }
105 void insert(::std::vector< FontPortionModel >::iterator it,
106 const FontPortionModel& rModel)
107 { mvModels.insert(it, rModel); }
109 ::std::vector< FontPortionModel >::iterator begin() { return mvModels.begin(); }
111 /** Appends a rich-string font identifier. */
112 void appendPortion( const FontPortionModel& rPortion );
113 /** Reads count and font identifiers from the passed stream. */
114 void importPortions( SequenceInputStream& rStrm );
117 struct PhoneticDataModel
119 sal_Int32 mnFontId; /// Font identifier for text formatting.
120 sal_Int32 mnType; /// Phonetic text type.
121 sal_Int32 mnAlignment; /// Phonetic portion alignment.
123 explicit PhoneticDataModel();
125 /** Sets the passed data from binary import. */
126 void setBiffData( sal_Int32 nType, sal_Int32 nAlignment );
129 class PhoneticSettings : public WorkbookHelper
131 public:
132 explicit PhoneticSettings( const WorkbookHelper& rHelper );
134 /** Imports phonetic settings from the phoneticPr element. */
135 void importPhoneticPr( const AttributeList& rAttribs );
136 /** Imports phonetic settings from the PHONETICPR record. */
137 void importPhoneticPr( SequenceInputStream& rStrm );
139 /** Imports phonetic settings from a rich string. */
140 void importStringData( SequenceInputStream& rStrm );
142 private:
143 PhoneticDataModel maModel;
146 /** Contains text data and positioning information for a phonetic text portion. */
147 class RichStringPhonetic
149 public:
150 RichStringPhonetic();
152 /** Sets text data for this phonetic portion. */
153 void setText( const OUString& rText );
154 /** Imports attributes of a phonetic run (rPh element). */
155 void importPhoneticRun( const AttributeList& rAttribs );
156 /** Sets the associated range in base text for this phonetic portion. */
157 void setBaseRange( sal_Int32 nBasePos, sal_Int32 nBaseEnd );
159 private:
160 OUString maText; /// Portion text.
161 sal_Int32 mnBasePos; /// Start position in base text.
162 sal_Int32 mnBaseEnd; /// One-past-end position in base text.
165 typedef std::shared_ptr< RichStringPhonetic > RichStringPhoneticRef;
167 /** Represents a phonetic text portion in a rich-string with phonetic text.
168 Used in binary filters only. */
169 struct PhoneticPortionModel
171 sal_Int32 mnPos; /// First character in phonetic text.
172 sal_Int32 mnBasePos; /// First character in base text.
173 sal_Int32 mnBaseLen; /// Number of characters in base text.
175 explicit PhoneticPortionModel() : mnPos( -1 ), mnBasePos( -1 ), mnBaseLen( 0 ) {}
176 explicit PhoneticPortionModel( sal_Int32 nPos, sal_Int32 nBasePos, sal_Int32 nBaseLen ) :
177 mnPos( nPos ), mnBasePos( nBasePos ), mnBaseLen( nBaseLen ) {}
179 void read( SequenceInputStream& rStrm );
182 /** A vector with all phonetic portions in a rich-string. */
183 class PhoneticPortionModelList
185 public:
186 explicit PhoneticPortionModelList() : mvModels() {}
188 bool empty() const { return mvModels.empty(); }
190 const PhoneticPortionModel& back() const { return mvModels.back(); }
192 void push_back(const PhoneticPortionModel& rModel) { mvModels.push_back(rModel); }
194 ::std::vector< PhoneticPortionModel >::const_iterator begin() const { return mvModels.begin(); }
196 /** Appends a rich-string phonetic portion. */
197 void appendPortion( const PhoneticPortionModel& rPortion );
198 /** Reads all phonetic portions from the passed stream. */
199 void importPortions( SequenceInputStream& rStrm );
201 private:
202 ::std::vector< PhoneticPortionModel > mvModels;
205 /** Contains string data and a list of formatting runs for a rich formatted string. */
206 class RichString
208 public:
210 /** Appends and returns an index of a portion object for a plain string (t element). */
211 sal_Int32 importText(const AttributeList& rAttribs);
212 /** Appends and returns an index of a portion object for a new formatting run (r element). */
213 sal_Int32 importRun();
214 /** Appends and returns a phonetic text object for a new phonetic run (rPh element). */
215 RichStringPhoneticRef importPhoneticRun( const AttributeList& rAttribs );
216 /** Imports phonetic settings from the rPhoneticPr element. */
217 void importPhoneticPr( const AttributeList& rAttribs, const WorkbookHelper& rHelper );
219 /** Imports a Unicode rich-string from the passed record stream. */
220 void importString( SequenceInputStream& rStrm, bool bRich, const WorkbookHelper& rHelper );
222 /** Final processing after import of all strings. */
223 void finalizeImport(const WorkbookHelper& rHelper);
225 /** Tries to extract a plain string from this object. Returns the string,
226 if there is only one unformatted portion. */
227 bool extractPlainString(
228 OUString& orString,
229 const oox::xls::Font* pFirstPortionFont ) const;
231 /** Get the text of all portions as a single string regardless of formatted or not */
232 OUString getStringContent() const;
234 /** Converts the string and writes it into the passed XText, replace old contents of the text object,.
235 @param rxText The XText interface of the target object.
237 void convert( const css::uno::Reference< css::text::XText >& rxText );
238 std::unique_ptr<EditTextObject> convert( ScEditEngineDefaulter& rEE, const oox::xls::Font* pFont );
240 RichStringPortion& getPortion(sal_Int32 nPortionIdx) { return maTextPortions[nPortionIdx]; }
242 void setAttributes(const AttributeList& rAttribs);
244 bool isPreserveSpace() const { return mbPreserveSpace; }
246 private:
247 /** Creates, appends, and returns a new empty string portion. */
248 sal_Int32 createPortion();
249 /** Creates, appends, and returns a new empty phonetic text portion. */
250 RichStringPhoneticRef createPhonetic();
252 /** Create base text portions from the passed string and character formatting. */
253 void createTextPortions( std::u16string_view aText, FontPortionModelList& rPortions );
254 /** Create phonetic text portions from the passed string and portion data. */
255 void createPhoneticPortions( std::u16string_view aText, PhoneticPortionModelList& rPortions, sal_Int32 nBaseLen );
257 private:
258 typedef RefVector< RichStringPhonetic > PhoneticVector;
260 std::vector<RichStringPortion> maTextPortions; /// String portions with font data.
261 std::unique_ptr<PhoneticSettings> mxPhonSettings; /// Phonetic settings for this string.
262 PhoneticVector maPhonPortions; /// Phonetic text portions.
263 bool mbPreserveSpace = false;
266 typedef std::shared_ptr< RichString > RichStringRef;
268 } // namespace oox::xls
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */