/src/libreoffice/xmloff/source/style/xmlstyle.cxx
Line | Count | Source |
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 | | #include <config_wasm_strip.h> |
21 | | |
22 | | #include <sal/config.h> |
23 | | |
24 | | #include <com/sun/star/beans/XPropertySet.hpp> |
25 | | #include <com/sun/star/frame/XModel.hpp> |
26 | | #include <com/sun/star/container/XNameContainer.hpp> |
27 | | #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> |
28 | | #include <com/sun/star/style/XAutoStylesSupplier.hpp> |
29 | | #include <com/sun/star/style/XAutoStyleFamily.hpp> |
30 | | #include <com/sun/star/drawing/XDrawPageSupplier.hpp> |
31 | | #include <PageMasterPropMapper.hxx> |
32 | | |
33 | | #include <comphelper/diagnose_ex.hxx> |
34 | | #include <sal/log.hxx> |
35 | | #include <svl/style.hxx> |
36 | | #include <utility> |
37 | | #include <xmloff/xmlnamespace.hxx> |
38 | | #include <xmloff/xmltoken.hxx> |
39 | | |
40 | | #include <xmloff/families.hxx> |
41 | | #include <xmloff/xmlimp.hxx> |
42 | | #include <xmloff/xmlnumi.hxx> |
43 | | #include <xmloff/xmlimppr.hxx> |
44 | | #include <xmloff/xmlstyle.hxx> |
45 | | #include <xmloff/txtstyli.hxx> |
46 | | #include <xmloff/xmlnumfi.hxx> |
47 | | #include <XMLChartStyleContext.hxx> |
48 | | #include <XMLChartPropertySetMapper.hxx> |
49 | | #include <XMLThemeContext.hxx> |
50 | | #include <xmloff/XMLShapeStyleContext.hxx> |
51 | | #include "FillStyleContext.hxx" |
52 | | #include <XMLFootnoteConfigurationImportContext.hxx> |
53 | | #include <XMLIndexBibliographyConfigurationContext.hxx> |
54 | | #include <XMLLineNumberingImportContext.hxx> |
55 | | #include <PageMasterImportContext.hxx> |
56 | | #include "PageMasterImportPropMapper.hxx" |
57 | | |
58 | | #include <memory> |
59 | | #include <set> |
60 | | #include <string_view> |
61 | | #include <vector> |
62 | | |
63 | | using namespace ::com::sun::star; |
64 | | using namespace ::com::sun::star::uno; |
65 | | using namespace ::com::sun::star::container; |
66 | | using namespace ::com::sun::star::style; |
67 | | using namespace ::xmloff::token; |
68 | | |
69 | | constexpr OUStringLiteral gsParaStyleServiceName( u"com.sun.star.style.ParagraphStyle" ); |
70 | | constexpr OUStringLiteral gsTextStyleServiceName( u"com.sun.star.style.CharacterStyle" ); |
71 | | constexpr OUString gsParagraphStyles(u"ParagraphStyles"_ustr); |
72 | | constexpr OUString gsCharacterStyles(u"CharacterStyles"_ustr); |
73 | | |
74 | | void SvXMLStyleContext::SetAttribute( sal_Int32 nElement, |
75 | | const OUString& rValue ) |
76 | 471k | { |
77 | 471k | switch (nElement) |
78 | 471k | { |
79 | 14.2k | case XML_ELEMENT(STYLE, XML_FAMILY): |
80 | 14.2k | { |
81 | 14.2k | if( IsXMLToken( rValue, XML_PARAGRAPH ) ) |
82 | 27 | mnFamily = XmlStyleFamily(SfxStyleFamily::Para); |
83 | 14.2k | else if( IsXMLToken( rValue, XML_TEXT ) ) |
84 | 1 | mnFamily = XmlStyleFamily(SfxStyleFamily::Char); |
85 | 14.2k | break; |
86 | 0 | } |
87 | 233k | case XML_ELEMENT(STYLE, XML_NAME): |
88 | 233k | maName = rValue; |
89 | 233k | break; |
90 | 28.9k | case XML_ELEMENT(STYLE, XML_DISPLAY_NAME): |
91 | 28.9k | maDisplayName = rValue; |
92 | 28.9k | break; |
93 | 68.0k | case XML_ELEMENT(STYLE, XML_PARENT_STYLE_NAME): |
94 | 68.0k | maParentName = rValue; |
95 | 68.0k | break; |
96 | 6.40k | case XML_ELEMENT(STYLE, XML_NEXT_STYLE_NAME): |
97 | 6.40k | maFollow = rValue; |
98 | 6.40k | break; |
99 | 0 | case XML_ELEMENT(LO_EXT, XML_LINKED_STYLE_NAME): |
100 | 0 | maLinked = rValue; |
101 | 0 | break; |
102 | 0 | case XML_ELEMENT(STYLE, XML_HIDDEN): |
103 | 0 | case XML_ELEMENT(LO_EXT, XML_HIDDEN): |
104 | 0 | mbHidden = rValue.toBoolean(); |
105 | 0 | break; |
106 | 471k | } |
107 | 471k | } |
108 | | |
109 | | |
110 | | SvXMLStyleContext::SvXMLStyleContext( |
111 | | SvXMLImport& rImp, |
112 | | XmlStyleFamily nFam, bool bDefault ) : |
113 | 284k | SvXMLImportContext( rImp ), |
114 | 284k | mbHidden( false ), |
115 | 284k | mnFamily( nFam ), |
116 | 284k | mbValid( true ), |
117 | 284k | mbNew( true ), |
118 | 284k | mbDefaultStyle( bDefault ) |
119 | 284k | { |
120 | 284k | } |
121 | | |
122 | | SvXMLStyleContext::~SvXMLStyleContext() |
123 | 284k | { |
124 | 284k | } |
125 | | |
126 | | void SvXMLStyleContext::startFastElement( |
127 | | sal_Int32 /*nElement*/, |
128 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
129 | 278k | { |
130 | 278k | for( auto &it : sax_fastparser::castToFastAttributeList( xAttrList ) ) |
131 | 745k | SetAttribute( it.getToken(), it.toString() ); |
132 | 278k | } |
133 | | |
134 | | void SvXMLStyleContext::SetDefaults() |
135 | 0 | { |
136 | 0 | } |
137 | | |
138 | | void SvXMLStyleContext::CreateAndInsert( bool /*bOverwrite*/ ) |
139 | 5.25k | { |
140 | 5.25k | } |
141 | | |
142 | | void SvXMLStyleContext::CreateAndInsertLate( bool /*bOverwrite*/ ) |
143 | 65.5k | { |
144 | 65.5k | } |
145 | | |
146 | | void SvXMLStyleContext::Finish( bool /*bOverwrite*/ ) |
147 | 12.9k | { |
148 | 12.9k | } |
149 | | |
150 | | bool SvXMLStyleContext::IsTransient() const |
151 | 256k | { |
152 | 256k | return false; |
153 | 256k | } |
154 | | |
155 | | namespace { |
156 | | struct StyleIndexCompareByName |
157 | | { |
158 | | bool operator()(const SvXMLStyleContext* r1, const SvXMLStyleContext* r2) const |
159 | 502k | { |
160 | 502k | if( r1->GetFamily() < r2->GetFamily() ) |
161 | 103k | return true; |
162 | 398k | if( r1->GetFamily() > r2->GetFamily() ) |
163 | 25.1k | return false; |
164 | 373k | return r1->GetName() < r2->GetName(); |
165 | 398k | } |
166 | | }; |
167 | | struct StyleIndexCompareByDisplayName |
168 | | { |
169 | | bool operator()(const SvXMLStyleContext* r1, const SvXMLStyleContext* r2) const |
170 | 469k | { |
171 | 469k | if( r1->GetFamily() < r2->GetFamily() ) |
172 | 92.3k | return true; |
173 | 376k | if( r1->GetFamily() > r2->GetFamily() ) |
174 | 23.9k | return false; |
175 | 352k | return r1->GetDisplayName() < r2->GetDisplayName(); |
176 | 376k | } |
177 | | }; |
178 | | } |
179 | | |
180 | | class SvXMLStylesContext_Impl |
181 | | { |
182 | | std::vector<rtl::Reference<SvXMLStyleContext>> aStyles; |
183 | | // it would be better if we could share one vector for the styles and the index, but some code in calc |
184 | | // is sensitive to having styles re-ordered |
185 | | mutable SvXMLStylesContext::StyleIndex maStylesIndexByName; |
186 | | mutable SvXMLStylesContext::StyleIndex maStylesIndexByDisplayName; |
187 | | bool bAutomaticStyle; |
188 | | |
189 | | #if OSL_DEBUG_LEVEL > 0 |
190 | | mutable sal_uInt32 m_nIndexCreated; |
191 | | #endif |
192 | | |
193 | | public: |
194 | | explicit SvXMLStylesContext_Impl( bool bAuto ); |
195 | | |
196 | 42.8k | size_t GetStyleCount() const { return aStyles.size(); } |
197 | | |
198 | | SvXMLStyleContext *GetStyle( size_t i ) |
199 | 289k | { |
200 | 289k | return i < aStyles.size() ? aStyles[ i ].get() : nullptr; |
201 | 289k | } |
202 | | |
203 | | inline void AddStyle( SvXMLStyleContext *pStyle ); |
204 | | void dispose(); |
205 | | |
206 | | const SvXMLStyleContext *FindStyleChildContext( XmlStyleFamily nFamily, |
207 | | const OUString& rName, |
208 | | bool bCreateIndex ) const; |
209 | | |
210 | | std::pair<SvXMLStylesContext::StyleIndex::const_iterator, SvXMLStylesContext::StyleIndex::const_iterator> |
211 | | FindStyleChildContextByDisplayNamePrefix( XmlStyleFamily nFamily, |
212 | | const OUString& rPrefix ) const; |
213 | | |
214 | 169k | bool IsAutomaticStyle() const { return bAutomaticStyle; } |
215 | | |
216 | | private: |
217 | | void BuildNameIndex() const; |
218 | | void BuildDisplayNameIndex() const; |
219 | | }; |
220 | | |
221 | | SvXMLStylesContext_Impl::SvXMLStylesContext_Impl( bool bAuto ) : |
222 | 54.5k | bAutomaticStyle( bAuto ) |
223 | | #if OSL_DEBUG_LEVEL > 0 |
224 | | , m_nIndexCreated( 0 ) |
225 | | #endif |
226 | 54.5k | {} |
227 | | |
228 | | inline void SvXMLStylesContext_Impl::AddStyle( SvXMLStyleContext *pStyle ) |
229 | 262k | { |
230 | | #if OSL_DEBUG_LEVEL > 0 |
231 | | // for (auto const & xStyle : aStyles) |
232 | | // if (xStyle->GetFamily() == pStyle->GetFamily() && xStyle->GetName() == pStyle->GetName()) |
233 | | // assert(false && "duplicate style"); |
234 | | #endif |
235 | 262k | aStyles.emplace_back(pStyle ); |
236 | | |
237 | 262k | maStylesIndexByName.clear(); |
238 | 262k | maStylesIndexByDisplayName.clear(); |
239 | 262k | } |
240 | | |
241 | | void SvXMLStylesContext_Impl::dispose() |
242 | 116k | { |
243 | 116k | aStyles.clear(); |
244 | 116k | } |
245 | | |
246 | | const SvXMLStyleContext *SvXMLStylesContext_Impl::FindStyleChildContext( XmlStyleFamily nFamily, |
247 | | const OUString& rName, |
248 | | bool bCreateIndex ) const |
249 | 305k | { |
250 | 305k | const SvXMLStyleContext *pStyle = nullptr; |
251 | | |
252 | 305k | if( maStylesIndexByName.empty() && bCreateIndex && !aStyles.empty() ) |
253 | 13.4k | BuildNameIndex(); |
254 | | |
255 | 305k | if( !maStylesIndexByName.empty() ) |
256 | 191k | { |
257 | 191k | auto it = std::lower_bound(maStylesIndexByName.begin(), maStylesIndexByName.end(), true, |
258 | 191k | [&nFamily, &rName](const SvXMLStyleContext* lhs, bool /*rhs*/) |
259 | 499k | { |
260 | 499k | if (lhs->GetFamily() < nFamily) |
261 | 74.0k | return true; |
262 | 425k | if (lhs->GetFamily() > nFamily) |
263 | 157k | return false; |
264 | 267k | return lhs->GetName() < rName; |
265 | 425k | }); |
266 | 191k | if (it != maStylesIndexByName.end() && (*it)->GetFamily() == nFamily && (*it)->GetName() == rName) |
267 | 101k | pStyle = *it; |
268 | 191k | } |
269 | 113k | else |
270 | 113k | { |
271 | 415k | for( size_t i = 0; !pStyle && i < aStyles.size(); i++ ) |
272 | 301k | { |
273 | 301k | const SvXMLStyleContext *pS = aStyles[ i ].get(); |
274 | 301k | if( pS->GetFamily() == nFamily && |
275 | 149k | pS->GetName() == rName ) |
276 | 39.3k | pStyle = pS; |
277 | 301k | } |
278 | 113k | } |
279 | 305k | return pStyle; |
280 | 305k | } |
281 | | |
282 | | namespace |
283 | | { |
284 | | struct PrefixProbeLowerBound |
285 | | { |
286 | | XmlStyleFamily nFamily; |
287 | | const OUString& rPrefix; |
288 | | |
289 | | bool operator()(const SvXMLStyleContext* lhs, bool /*rhs*/) |
290 | 57.2k | { |
291 | 57.2k | if (lhs->GetFamily() < nFamily) |
292 | 35.2k | return true; |
293 | 21.9k | if (lhs->GetFamily() > nFamily) |
294 | 2.74k | return false; |
295 | 19.2k | return lhs->GetDisplayName() < rPrefix; |
296 | 21.9k | } |
297 | | }; |
298 | | struct PrefixProbeUpperBound |
299 | | { |
300 | | XmlStyleFamily nFamily; |
301 | | const OUString& rPrefix; |
302 | | |
303 | | bool operator()(bool /*lhs*/, const SvXMLStyleContext* rhs) |
304 | 26.1k | { |
305 | 26.1k | if (nFamily < rhs->GetFamily()) |
306 | 3.32k | return true; |
307 | 22.7k | if (nFamily > rhs->GetFamily()) |
308 | 0 | return false; |
309 | 22.7k | std::u16string_view rhsName = rhs->GetDisplayName(); |
310 | | // For the upper bound we want to view the vector's data as if |
311 | | // every element was truncated to the size of the prefix. |
312 | | // Then perform a normal match. |
313 | 22.7k | rhsName = rhsName.substr(0, rPrefix.getLength()); |
314 | | // compare UP TO the length of the prefix and no farther |
315 | 22.7k | if (int cmp = rPrefix.compareTo(rhsName)) |
316 | 2 | return cmp < 0; |
317 | | // The strings are equal to the length of the prefix so |
318 | | // behave as if they are equal. That means s1 < s2 == false |
319 | 22.7k | return false; |
320 | 22.7k | } |
321 | | }; |
322 | | } |
323 | | |
324 | | std::pair<SvXMLStylesContext::StyleIndex::const_iterator, SvXMLStylesContext::StyleIndex::const_iterator> |
325 | | SvXMLStylesContext_Impl::FindStyleChildContextByDisplayNamePrefix( XmlStyleFamily nFamily, |
326 | | const OUString& rPrefix ) const |
327 | 29.6k | { |
328 | 29.6k | if( maStylesIndexByDisplayName.empty() ) |
329 | 19.1k | BuildDisplayNameIndex(); |
330 | 29.6k | auto itStart = std::lower_bound(maStylesIndexByDisplayName.begin(), maStylesIndexByDisplayName.end(), true, PrefixProbeLowerBound{nFamily,rPrefix}); |
331 | 29.6k | auto itEnd = std::upper_bound(itStart, maStylesIndexByDisplayName.end(), true, PrefixProbeUpperBound{nFamily,rPrefix}); |
332 | 29.6k | return {itStart, itEnd}; |
333 | 29.6k | } |
334 | | |
335 | | void SvXMLStylesContext_Impl::BuildNameIndex() const |
336 | 13.4k | { |
337 | 13.4k | maStylesIndexByName.reserve(aStyles.size()); |
338 | | |
339 | 13.4k | for (const auto & i : aStyles) |
340 | 125k | maStylesIndexByName.push_back(i.get()); |
341 | 13.4k | std::sort(maStylesIndexByName.begin(), maStylesIndexByName.end(), StyleIndexCompareByName()); |
342 | | |
343 | | #if OSL_DEBUG_LEVEL > 0 |
344 | | SAL_WARN_IF(0 != m_nIndexCreated, "xmloff.style", |
345 | | "Performance warning: sdbcx::Index created multiple times"); |
346 | | ++m_nIndexCreated; |
347 | | #endif |
348 | 13.4k | } |
349 | | |
350 | | void SvXMLStylesContext_Impl::BuildDisplayNameIndex() const |
351 | 19.1k | { |
352 | 19.1k | maStylesIndexByDisplayName.reserve(aStyles.size()); |
353 | 19.1k | for (const auto & i : aStyles) |
354 | 94.9k | maStylesIndexByDisplayName.push_back(i.get()); |
355 | 19.1k | std::sort(maStylesIndexByDisplayName.begin(), maStylesIndexByDisplayName.end(), StyleIndexCompareByDisplayName()); |
356 | 19.1k | } |
357 | | |
358 | | sal_uInt32 SvXMLStylesContext::GetStyleCount() const |
359 | 42.8k | { |
360 | 42.8k | return mpImpl->GetStyleCount(); |
361 | 42.8k | } |
362 | | |
363 | | SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) |
364 | 289k | { |
365 | 289k | return mpImpl->GetStyle( i ); |
366 | 289k | } |
367 | | |
368 | | const SvXMLStyleContext *SvXMLStylesContext::GetStyle( sal_uInt32 i ) const |
369 | 0 | { |
370 | 0 | return mpImpl->GetStyle( i ); |
371 | 0 | } |
372 | | |
373 | | bool SvXMLStylesContext::IsAutomaticStyle() const |
374 | 169k | { |
375 | 169k | return mpImpl->IsAutomaticStyle(); |
376 | 169k | } |
377 | | |
378 | | SvXMLStyleContext *SvXMLStylesContext::CreateStyleChildContext( |
379 | | sal_Int32 nElement, |
380 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList) |
381 | 216k | { |
382 | 216k | SvXMLStyleContext *pStyle = nullptr; |
383 | | |
384 | 216k | if(GetImport().GetDataStylesImport()) |
385 | 158k | { |
386 | 158k | pStyle = GetImport().GetDataStylesImport()->CreateChildContext(GetImport(), nElement, |
387 | 158k | xAttrList, *this); |
388 | 158k | if (pStyle) |
389 | 15.4k | return pStyle; |
390 | 158k | } |
391 | | |
392 | 200k | switch (nElement) |
393 | 200k | { |
394 | 140k | case XML_ELEMENT(STYLE, XML_STYLE): |
395 | 155k | case XML_ELEMENT(STYLE, XML_DEFAULT_STYLE): |
396 | 155k | { |
397 | 155k | XmlStyleFamily nFamily = XmlStyleFamily::DATA_STYLE; |
398 | 155k | for( auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ) ) |
399 | 289k | { |
400 | 289k | if( aIter.getToken() == XML_ELEMENT(STYLE, XML_FAMILY) ) |
401 | 146k | { |
402 | 146k | nFamily = GetFamily( aIter.toString() ); |
403 | 146k | break; |
404 | 146k | } |
405 | 289k | } |
406 | 155k | pStyle = XML_ELEMENT(STYLE, XML_STYLE)==nElement |
407 | 155k | ? CreateStyleStyleChildContext( nFamily, nElement, xAttrList ) |
408 | 155k | : CreateDefaultStyleStyleChildContext( nFamily, nElement, xAttrList ); |
409 | 155k | break; |
410 | 140k | } |
411 | 129 | case XML_ELEMENT(TEXT, XML_BIBLIOGRAPHY_CONFIGURATION): |
412 | 129 | pStyle = new XMLIndexBibliographyConfigurationContext(GetImport()); |
413 | 129 | break; |
414 | 4.16k | case XML_ELEMENT(TEXT, XML_NOTES_CONFIGURATION): |
415 | 4.16k | pStyle = new XMLFootnoteConfigurationImportContext( |
416 | 4.16k | GetImport(), nElement, xAttrList); |
417 | 4.16k | break; |
418 | 1.45k | case XML_ELEMENT(TEXT, XML_LINENUMBERING_CONFIGURATION): |
419 | 1.45k | pStyle = new XMLLineNumberingImportContext(GetImport()); |
420 | 1.45k | break; |
421 | 6.15k | case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT): |
422 | 6.24k | case XML_ELEMENT(STYLE, XML_DEFAULT_PAGE_LAYOUT): |
423 | 6.24k | { |
424 | | //there is not page family in ODF now, so I specify one for it |
425 | 6.24k | bool bDefaultStyle = XML_ELEMENT(STYLE, XML_DEFAULT_PAGE_LAYOUT) == nElement; |
426 | 6.24k | pStyle = new PageStyleContext( GetImport(), *this, bDefaultStyle ); |
427 | 6.24k | } |
428 | 6.24k | break; |
429 | 2.68k | case XML_ELEMENT(TEXT, XML_LIST_STYLE): |
430 | 2.68k | pStyle = new SvxXMLListStyleContext( GetImport() ); |
431 | 2.68k | break; |
432 | 978 | case XML_ELEMENT(TEXT, XML_OUTLINE_STYLE): |
433 | 978 | pStyle = new SvxXMLListStyleContext( GetImport(), true ); |
434 | 978 | break; |
435 | | |
436 | | // FillStyles |
437 | | |
438 | 227 | case XML_ELEMENT(DRAW, XML_GRADIENT): |
439 | 227 | { |
440 | 227 | pStyle = new XMLGradientStyleContext( GetImport(), nElement, xAttrList ); |
441 | 227 | break; |
442 | 6.15k | } |
443 | 0 | case XML_ELEMENT(DRAW, XML_HATCH): |
444 | 0 | { |
445 | 0 | pStyle = new XMLHatchStyleContext( GetImport(), nElement, xAttrList ); |
446 | 0 | break; |
447 | 6.15k | } |
448 | 0 | case XML_ELEMENT(DRAW, XML_FILL_IMAGE): |
449 | 0 | { |
450 | 0 | pStyle = new XMLBitmapStyleContext( GetImport(), nElement, xAttrList ); |
451 | 0 | break; |
452 | 6.15k | } |
453 | 6 | case XML_ELEMENT(DRAW, XML_OPACITY): |
454 | 6 | { |
455 | 6 | pStyle = new XMLTransGradientStyleContext( GetImport(), nElement, xAttrList ); |
456 | 6 | break; |
457 | 6.15k | } |
458 | 18.9k | case XML_ELEMENT(DRAW, XML_MARKER): |
459 | 18.9k | { |
460 | 18.9k | pStyle = new XMLMarkerStyleContext( GetImport(), nElement, xAttrList ); |
461 | 18.9k | break; |
462 | 6.15k | } |
463 | 434 | case XML_ELEMENT(DRAW, XML_STROKE_DASH): |
464 | 434 | { |
465 | 434 | pStyle = new XMLDashStyleContext( GetImport(), nElement, xAttrList ); |
466 | 434 | break; |
467 | 6.15k | } |
468 | 200k | } |
469 | | |
470 | 200k | if (!pStyle) |
471 | 200k | SAL_WARN("xmloff", "Unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); |
472 | | |
473 | 200k | return pStyle; |
474 | 200k | } |
475 | | |
476 | | SvXMLStyleContext *SvXMLStylesContext::CreateStyleStyleChildContext( |
477 | | XmlStyleFamily nFamily, sal_Int32 /*nElement*/, |
478 | | const uno::Reference< xml::sax::XFastAttributeList > & /*xAttrList*/ ) |
479 | 57.7k | { |
480 | 57.7k | SvXMLStyleContext *pStyle = nullptr; |
481 | | |
482 | 57.7k | switch( nFamily ) |
483 | 57.7k | { |
484 | 7.88k | case XmlStyleFamily::TEXT_PARAGRAPH: |
485 | 18.6k | case XmlStyleFamily::TEXT_TEXT: |
486 | 18.8k | case XmlStyleFamily::TEXT_SECTION: |
487 | 18.8k | pStyle = new XMLTextStyleContext( GetImport(), *this, nFamily ); |
488 | 18.8k | break; |
489 | | |
490 | 465 | case XmlStyleFamily::TEXT_RUBY: |
491 | 465 | pStyle = new XMLPropStyleContext( GetImport(), *this, nFamily ); |
492 | 465 | break; |
493 | 0 | #if !ENABLE_WASM_STRIP_CHART |
494 | | // WASM_CHART change |
495 | 485 | case XmlStyleFamily::SCH_CHART_ID: |
496 | 485 | pStyle = new XMLChartStyleContext( GetImport(), *this, nFamily ); |
497 | 485 | break; |
498 | 0 | #endif |
499 | 4.20k | case XmlStyleFamily::SD_GRAPHICS_ID: |
500 | 7.38k | case XmlStyleFamily::SD_PRESENTATION_ID: |
501 | 7.38k | case XmlStyleFamily::SD_POOL_ID: |
502 | 7.38k | pStyle = new XMLShapeStyleContext( GetImport(), *this, nFamily ); |
503 | 7.38k | break; |
504 | 30.5k | default: break; |
505 | 57.7k | } |
506 | | |
507 | 57.7k | return pStyle; |
508 | 57.7k | } |
509 | | |
510 | | SvXMLStyleContext *SvXMLStylesContext::CreateDefaultStyleStyleChildContext( |
511 | | XmlStyleFamily /*nFamily*/, sal_Int32 /*nElement*/, |
512 | | const uno::Reference< xml::sax::XFastAttributeList > & ) |
513 | 4.13k | { |
514 | 4.13k | return nullptr; |
515 | 4.13k | } |
516 | | |
517 | | bool SvXMLStylesContext::InsertStyleFamily( XmlStyleFamily ) const |
518 | 89.2k | { |
519 | 89.2k | return true; |
520 | 89.2k | } |
521 | | |
522 | | XmlStyleFamily SvXMLStylesContext::GetFamily( std::u16string_view rValue ) |
523 | 146k | { |
524 | 146k | XmlStyleFamily nFamily = XmlStyleFamily::DATA_STYLE; |
525 | 146k | if( IsXMLToken( rValue, XML_PARAGRAPH ) ) |
526 | 53.1k | { |
527 | 53.1k | nFamily = XmlStyleFamily::TEXT_PARAGRAPH; |
528 | 53.1k | } |
529 | 93.5k | else if( IsXMLToken( rValue, XML_TEXT ) ) |
530 | 11.4k | { |
531 | 11.4k | nFamily = XmlStyleFamily::TEXT_TEXT; |
532 | 11.4k | } |
533 | 82.0k | else if( IsXMLToken( rValue, XML_DATA_STYLE ) ) |
534 | 0 | { |
535 | 0 | nFamily = XmlStyleFamily::DATA_STYLE; |
536 | 0 | } |
537 | 82.0k | else if ( IsXMLToken( rValue, XML_SECTION ) ) |
538 | 188 | { |
539 | 188 | nFamily = XmlStyleFamily::TEXT_SECTION; |
540 | 188 | } |
541 | 81.8k | else if( IsXMLToken( rValue, XML_TABLE ) ) |
542 | 6.60k | { |
543 | 6.60k | nFamily = XmlStyleFamily::TABLE_TABLE; |
544 | 6.60k | } |
545 | 75.2k | else if( IsXMLToken( rValue, XML_TABLE_COLUMN ) ) |
546 | 13.3k | nFamily = XmlStyleFamily::TABLE_COLUMN; |
547 | 61.8k | else if( IsXMLToken( rValue, XML_TABLE_ROW ) ) |
548 | 4.73k | nFamily = XmlStyleFamily::TABLE_ROW; |
549 | 57.1k | else if( IsXMLToken( rValue, XML_TABLE_CELL ) ) |
550 | 35.6k | nFamily = XmlStyleFamily::TABLE_CELL; |
551 | 21.5k | else if ( rValue == XML_STYLE_FAMILY_SD_GRAPHICS_NAME ) |
552 | 12.5k | { |
553 | 12.5k | nFamily = XmlStyleFamily::SD_GRAPHICS_ID; |
554 | 12.5k | } |
555 | 8.97k | else if ( rValue == XML_STYLE_FAMILY_SD_PRESENTATION_NAME ) |
556 | 3.17k | { |
557 | 3.17k | nFamily = XmlStyleFamily::SD_PRESENTATION_ID; |
558 | 3.17k | } |
559 | 5.80k | else if ( rValue == XML_STYLE_FAMILY_SD_POOL_NAME ) |
560 | 0 | { |
561 | 0 | nFamily = XmlStyleFamily::SD_POOL_ID; |
562 | 0 | } |
563 | 5.80k | else if ( rValue == XML_STYLE_FAMILY_SD_DRAWINGPAGE_NAME ) |
564 | 1.72k | { |
565 | 1.72k | nFamily = XmlStyleFamily::SD_DRAWINGPAGE_ID; |
566 | 1.72k | } |
567 | 4.08k | else if ( rValue == XML_STYLE_FAMILY_SCH_CHART_NAME ) |
568 | 485 | { |
569 | 485 | nFamily = XmlStyleFamily::SCH_CHART_ID; |
570 | 485 | } |
571 | 3.59k | else if ( IsXMLToken( rValue, XML_RUBY ) ) |
572 | 465 | { |
573 | 465 | nFamily = XmlStyleFamily::TEXT_RUBY; |
574 | 465 | } |
575 | | |
576 | 146k | return nFamily; |
577 | 146k | } |
578 | | |
579 | | SvXMLImportPropertyMapper* SvXMLStylesContext::GetImportPropertyMapper( |
580 | | XmlStyleFamily nFamily ) const |
581 | 416k | { |
582 | 416k | SvXMLImportPropertyMapper* pMapper = nullptr; |
583 | | |
584 | 416k | SvXMLStylesContext * pThis = const_cast<SvXMLStylesContext *>(this); |
585 | 416k | switch( nFamily ) |
586 | 416k | { |
587 | 206k | case XmlStyleFamily::TEXT_PARAGRAPH: |
588 | 206k | pMapper = |
589 | 206k | pThis->GetImport().GetTextImport() |
590 | 206k | ->GetParaImportPropertySetMapper(); |
591 | 206k | break; |
592 | 27.3k | case XmlStyleFamily::TEXT_TEXT: |
593 | 27.3k | pMapper = |
594 | 27.3k | pThis->GetImport().GetTextImport() |
595 | 27.3k | ->GetTextImportPropertySetMapper(); |
596 | 27.3k | break; |
597 | | |
598 | 306 | case XmlStyleFamily::TEXT_SECTION: |
599 | | // *sigh*, cast to non-const, because this is a const method, |
600 | | // but SvXMLImport::GetTextImport() isn't. |
601 | 306 | pMapper = pThis->GetImport().GetTextImport()-> |
602 | 306 | GetSectionImportPropertySetMapper(); |
603 | 306 | break; |
604 | | |
605 | 547 | case XmlStyleFamily::TEXT_RUBY: |
606 | | // *sigh*, cast to non-const, because this is a const method, |
607 | | // but SvXMLImport::GetTextImport() isn't. |
608 | 547 | pMapper = pThis->GetImport().GetTextImport()-> |
609 | 547 | GetRubyImportPropertySetMapper(); |
610 | 547 | break; |
611 | | |
612 | 38.2k | case XmlStyleFamily::SD_GRAPHICS_ID: |
613 | 46.1k | case XmlStyleFamily::SD_PRESENTATION_ID: |
614 | 46.1k | case XmlStyleFamily::SD_POOL_ID: |
615 | 46.1k | pMapper = const_cast<SvXMLImport&>(GetImport()).GetShapeImport()->GetPropertySetMapper(); |
616 | 46.1k | break; |
617 | 0 | #if !ENABLE_WASM_STRIP_CHART |
618 | | // WASM_CHART change |
619 | 961 | case XmlStyleFamily::SCH_CHART_ID: |
620 | 961 | if( ! mxChartImpPropMapper ) |
621 | 64 | { |
622 | 64 | XMLPropertySetMapper *const pPropMapper = new XMLChartPropertySetMapper(nullptr); |
623 | 64 | mxChartImpPropMapper = std::make_unique<XMLChartImportPropertyMapper>( pPropMapper, GetImport() ); |
624 | 64 | } |
625 | 961 | pMapper = mxChartImpPropMapper.get(); |
626 | 961 | break; |
627 | 0 | #endif |
628 | 56.7k | case XmlStyleFamily::PAGE_MASTER: |
629 | 56.7k | if( ! mxPageImpPropMapper ) |
630 | 3.72k | { |
631 | 3.72k | XMLPropertySetMapper *pPropMapper = |
632 | 3.72k | new XMLPageMasterPropSetMapper(); |
633 | 3.72k | mxPageImpPropMapper = |
634 | 3.72k | std::make_unique<PageMasterImportPropertyMapper>( pPropMapper, |
635 | 3.72k | const_cast<SvXMLStylesContext*>(this)->GetImport() ); |
636 | 3.72k | } |
637 | 56.7k | pMapper = mxPageImpPropMapper.get(); |
638 | 56.7k | break; |
639 | 77.5k | default: break; |
640 | 416k | } |
641 | | |
642 | 416k | return pMapper; |
643 | 416k | } |
644 | | |
645 | | Reference < XAutoStyleFamily > SvXMLStylesContext::GetAutoStyles( XmlStyleFamily nFamily ) const |
646 | 10.6k | { |
647 | 10.6k | Reference < XAutoStyleFamily > xAutoStyles; |
648 | 10.6k | if( XmlStyleFamily::TEXT_TEXT == nFamily || XmlStyleFamily::TEXT_PARAGRAPH == nFamily) |
649 | 10.6k | { |
650 | 10.6k | bool bPara = XmlStyleFamily::TEXT_PARAGRAPH == nFamily; |
651 | 10.6k | const Reference<XAutoStyleFamily>& rxAutoStyles = bPara ? mxParaAutoStyles : mxTextAutoStyles; |
652 | 10.6k | if (!rxAutoStyles) |
653 | 3.59k | { |
654 | 3.59k | OUString sName(bPara ? gsParagraphStyles : gsCharacterStyles); |
655 | 3.59k | Reference< XAutoStylesSupplier > xAutoStylesSupp( GetImport().GetModel(), UNO_QUERY ); |
656 | 3.59k | Reference< XAutoStyles > xAutoStyleFamilies = xAutoStylesSupp->getAutoStyles(); |
657 | 3.59k | if (xAutoStyleFamilies->hasByName(sName)) |
658 | 3.59k | { |
659 | 3.59k | Any aAny = xAutoStyleFamilies->getByName( sName ); |
660 | 3.59k | aAny >>= const_cast<Reference<XAutoStyleFamily>&>(rxAutoStyles); |
661 | 3.59k | } |
662 | 3.59k | } |
663 | 10.6k | xAutoStyles = rxAutoStyles; |
664 | 10.6k | } |
665 | 10.6k | return xAutoStyles; |
666 | 10.6k | } |
667 | | |
668 | | Reference < XNameContainer > SvXMLStylesContext::GetStylesContainer( |
669 | | XmlStyleFamily nFamily ) const |
670 | 76.0k | { |
671 | 76.0k | Reference < XNameContainer > xStyles; |
672 | 76.0k | if (XmlStyleFamily::TEXT_TEXT == nFamily || XmlStyleFamily::TEXT_PARAGRAPH == nFamily) |
673 | 56.3k | { |
674 | 56.3k | bool bPara = XmlStyleFamily::TEXT_PARAGRAPH == nFamily; |
675 | 56.3k | const Reference<XNameContainer>& rxStyles = bPara ? mxParaStyles : mxTextStyles; |
676 | 56.3k | if (!rxStyles) |
677 | 8.34k | { |
678 | 8.34k | OUString sName(bPara ? gsParagraphStyles : gsCharacterStyles); |
679 | 8.34k | Reference<XStyleFamiliesSupplier> xFamiliesSupp(GetImport().GetModel(), UNO_QUERY); |
680 | 8.34k | if (xFamiliesSupp.is()) |
681 | 8.34k | { |
682 | 8.34k | Reference<XNameAccess> xFamilies = xFamiliesSupp->getStyleFamilies(); |
683 | 8.34k | if (xFamilies->hasByName(sName)) |
684 | 7.01k | { |
685 | 7.01k | Any aAny = xFamilies->getByName(sName); |
686 | 7.01k | aAny >>= const_cast<Reference<XNameContainer>&>(rxStyles); |
687 | 7.01k | } |
688 | 8.34k | } |
689 | 8.34k | } |
690 | 56.3k | xStyles = rxStyles; |
691 | 56.3k | } |
692 | | |
693 | 76.0k | return xStyles; |
694 | 76.0k | } |
695 | | |
696 | | OUString SvXMLStylesContext::GetServiceName( XmlStyleFamily nFamily ) const |
697 | 18.0k | { |
698 | 18.0k | OUString sServiceName; |
699 | 18.0k | switch( nFamily ) |
700 | 18.0k | { |
701 | 8.83k | case XmlStyleFamily::TEXT_PARAGRAPH: |
702 | 8.83k | sServiceName = gsParaStyleServiceName; |
703 | 8.83k | break; |
704 | 3.87k | case XmlStyleFamily::TEXT_TEXT: |
705 | 3.87k | sServiceName = gsTextStyleServiceName; |
706 | 3.87k | break; |
707 | 5.31k | default: break; |
708 | 18.0k | } |
709 | | |
710 | 18.0k | return sServiceName; |
711 | 18.0k | } |
712 | | |
713 | | SvXMLStylesContext::SvXMLStylesContext( SvXMLImport& rImport, bool bAuto ) : |
714 | 54.5k | SvXMLImportContext( rImport ), |
715 | 54.5k | mpImpl( new SvXMLStylesContext_Impl( bAuto ) ) |
716 | 54.5k | { |
717 | 54.5k | } |
718 | | |
719 | | SvXMLStylesContext::~SvXMLStylesContext() |
720 | 54.5k | { |
721 | 54.5k | } |
722 | | |
723 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SvXMLStylesContext::createFastChildContext( |
724 | | sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
725 | 302k | { |
726 | 302k | if (nElement == XML_ELEMENT(LO_EXT, XML_THEME)) |
727 | 0 | { |
728 | 0 | if (auto xImportInfo = GetImport().getImportInfo()) |
729 | 0 | { |
730 | 0 | try |
731 | 0 | { |
732 | 0 | if (auto xPropertySetInfo = xImportInfo->getPropertySetInfo()) |
733 | 0 | { |
734 | 0 | if (xPropertySetInfo->hasPropertyByName(u"IsInPaste"_ustr)) |
735 | 0 | { |
736 | 0 | css::uno::Any value = xImportInfo->getPropertyValue(u"IsInPaste"_ustr); |
737 | 0 | if (bool b; (value >>= b) && b) |
738 | 0 | return nullptr; // do not import themes in paste mode |
739 | 0 | } |
740 | 0 | } |
741 | 0 | } |
742 | 0 | catch (const css::uno::Exception&) |
743 | 0 | { |
744 | 0 | DBG_UNHANDLED_EXCEPTION("xmloff"); |
745 | 0 | } |
746 | 0 | } |
747 | | |
748 | 0 | uno::Reference<uno::XInterface> xObject(GetImport().GetModel(), uno::UNO_QUERY); |
749 | 0 | uno::Reference<drawing::XDrawPageSupplier> const xDrawPageSupplier(GetImport().GetModel(), uno::UNO_QUERY); |
750 | 0 | if (xDrawPageSupplier.is()) |
751 | 0 | { |
752 | 0 | uno::Reference<drawing::XDrawPage> xPage = xDrawPageSupplier->getDrawPage(); |
753 | 0 | if (xPage.is()) |
754 | 0 | xObject = xPage; |
755 | 0 | } |
756 | |
|
757 | 0 | return new XMLThemeContext(GetImport(), xAttrList, xObject); |
758 | 0 | } |
759 | | |
760 | 302k | SvXMLStyleContext* pStyle = CreateStyleChildContext( nElement, xAttrList ); |
761 | 302k | if (pStyle) |
762 | 276k | { |
763 | 276k | if (!pStyle->IsTransient()) |
764 | 256k | mpImpl->AddStyle(pStyle); |
765 | 276k | return pStyle; |
766 | 276k | } |
767 | | |
768 | 26.5k | return nullptr; |
769 | 302k | } |
770 | | |
771 | | void SvXMLStylesContext::AddStyle(SvXMLStyleContext& rNew) |
772 | 6.42k | { |
773 | 6.42k | mpImpl->AddStyle( &rNew ); |
774 | 6.42k | } |
775 | | |
776 | | void SvXMLStylesContext::dispose() |
777 | 116k | { |
778 | 116k | mpImpl->dispose(); |
779 | 116k | } |
780 | | |
781 | | void SvXMLStylesContext::CopyAutoStylesToDoc() |
782 | 6.55k | { |
783 | 6.55k | sal_uInt32 nCount = GetStyleCount(); |
784 | 6.55k | sal_uInt32 i; |
785 | 36.9k | for( i = 0; i < nCount; i++ ) |
786 | 30.3k | { |
787 | 30.3k | SvXMLStyleContext *pStyle = GetStyle( i ); |
788 | 30.3k | if( !pStyle || ( pStyle->GetFamily() != XmlStyleFamily::TEXT_TEXT && |
789 | 27.5k | pStyle->GetFamily() != XmlStyleFamily::TEXT_PARAGRAPH && |
790 | 19.8k | pStyle->GetFamily() != XmlStyleFamily::TABLE_CELL ) ) |
791 | 17.1k | continue; |
792 | 13.1k | pStyle->CreateAndInsert( false ); |
793 | 13.1k | } |
794 | 6.55k | } |
795 | | |
796 | | void SvXMLStylesContext::CopyStylesToDoc( bool bOverwrite, |
797 | | bool bFinish ) |
798 | 9.12k | { |
799 | | // pass 1: create text, paragraph and frame styles |
800 | 9.12k | sal_uInt32 nCount = GetStyleCount(); |
801 | 9.12k | sal_uInt32 i; |
802 | | |
803 | 86.4k | for( i = 0; i < nCount; i++ ) |
804 | 77.3k | { |
805 | 77.3k | SvXMLStyleContext *pStyle = GetStyle( i ); |
806 | 77.3k | if( !pStyle ) |
807 | 0 | continue; |
808 | | |
809 | 77.3k | if (pStyle->IsDefaultStyle()) |
810 | 10.2k | { |
811 | 10.2k | if (bOverwrite) pStyle->SetDefaults(); |
812 | 10.2k | } |
813 | 67.0k | else if( InsertStyleFamily( pStyle->GetFamily() ) ) |
814 | 67.0k | pStyle->CreateAndInsert( bOverwrite ); |
815 | 77.3k | } |
816 | | |
817 | | // pass 2: create list styles (they require char styles) |
818 | 86.3k | for( i=0; i<nCount; i++ ) |
819 | 77.2k | { |
820 | 77.2k | SvXMLStyleContext *pStyle = GetStyle( i ); |
821 | 77.2k | if( !pStyle || pStyle->IsDefaultStyle()) |
822 | 10.2k | continue; |
823 | | |
824 | 67.0k | if( InsertStyleFamily( pStyle->GetFamily() ) ) |
825 | 67.0k | pStyle->CreateAndInsertLate( bOverwrite ); |
826 | 67.0k | } |
827 | | |
828 | | // pass3: finish creation of styles |
829 | 9.12k | if( bFinish ) |
830 | 2.70k | FinishStyles( bOverwrite ); |
831 | 9.12k | } |
832 | | |
833 | | void SvXMLStylesContext::FinishStyles( bool bOverwrite ) |
834 | 14.8k | { |
835 | 14.8k | sal_uInt32 nCount = GetStyleCount(); |
836 | 109k | for( sal_uInt32 i=0; i<nCount; i++ ) |
837 | 95.0k | { |
838 | 95.0k | SvXMLStyleContext *pStyle = GetStyle( i ); |
839 | 95.0k | if( !pStyle || !pStyle->IsValid() || pStyle->IsDefaultStyle() ) |
840 | 6.76k | continue; |
841 | | |
842 | 88.3k | if( InsertStyleFamily( pStyle->GetFamily() ) ) |
843 | 88.3k | pStyle->Finish( bOverwrite ); |
844 | 88.3k | } |
845 | 14.8k | } |
846 | | |
847 | | const SvXMLStyleContext *SvXMLStylesContext::FindStyleChildContext( |
848 | | XmlStyleFamily nFamily, |
849 | | const OUString& rName, |
850 | | bool bCreateIndex ) const |
851 | 305k | { |
852 | 305k | return mpImpl->FindStyleChildContext( nFamily, rName, bCreateIndex ); |
853 | 305k | } |
854 | | |
855 | | std::pair<SvXMLStylesContext::StyleIndex::const_iterator, SvXMLStylesContext::StyleIndex::const_iterator> |
856 | | SvXMLStylesContext::FindStyleChildContextByDisplayNamePrefix( |
857 | | XmlStyleFamily nFamily, |
858 | | const OUString& rNamePrefix ) const |
859 | 29.6k | { |
860 | 29.6k | return mpImpl->FindStyleChildContextByDisplayNamePrefix( nFamily, rNamePrefix ); |
861 | 29.6k | } |
862 | | |
863 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |