/src/libreoffice/xmloff/source/style/styleexp.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 <sal/config.h> |
21 | | |
22 | | #include <o3tl/any.hxx> |
23 | | #include <xmloff/xmlnamespace.hxx> |
24 | | #include <xmloff/xmltoken.hxx> |
25 | | #include <xmloff/xmlexppr.hxx> |
26 | | #include <com/sun/star/frame/XModel.hpp> |
27 | | #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> |
28 | | #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> |
29 | | #include <com/sun/star/style/XStyle.hpp> |
30 | | #include <com/sun/star/beans/NamedValue.hpp> |
31 | | #include <com/sun/star/beans/XPropertySet.hpp> |
32 | | #include <com/sun/star/beans/XPropertyState.hpp> |
33 | | #include <com/sun/star/document/XEventsSupplier.hpp> |
34 | | #include <com/sun/star/text/XChapterNumberingSupplier.hpp> |
35 | | #include <xmloff/xmlaustp.hxx> |
36 | | #include <xmloff/styleexp.hxx> |
37 | | #include <xmloff/xmlexp.hxx> |
38 | | #include <xmloff/XMLEventExport.hxx> |
39 | | #include <xmloff/maptype.hxx> |
40 | | #include <set> |
41 | | #include <prstylecond.hxx> |
42 | | #include <sal/log.hxx> |
43 | | |
44 | | using namespace ::com::sun::star; |
45 | | using namespace ::com::sun::star::uno; |
46 | | using namespace ::com::sun::star::style; |
47 | | using namespace ::com::sun::star::container; |
48 | | using namespace ::com::sun::star::beans; |
49 | | using namespace ::com::sun::star::text; |
50 | | using namespace ::xmloff::token; |
51 | | |
52 | | using ::com::sun::star::document::XEventsSupplier; |
53 | | |
54 | | constexpr OUString gsIsPhysical( u"IsPhysical"_ustr ); |
55 | | constexpr OUString gsIsAutoUpdate( u"IsAutoUpdate"_ustr ); |
56 | | constexpr OUString gsFollowStyle( u"FollowStyle"_ustr ); |
57 | | constexpr OUString gsNumberingStyleName( u"NumberingStyleName"_ustr ); |
58 | | constexpr OUString gsOutlineLevel( u"OutlineLevel"_ustr ); |
59 | | |
60 | | XMLStyleExport::XMLStyleExport( |
61 | | SvXMLExport& rExp, |
62 | | SvXMLAutoStylePoolP *pAutoStyleP ) : |
63 | 5 | m_rExport( rExp ), |
64 | 5 | m_pAutoStylePool( pAutoStyleP ) |
65 | 5 | { |
66 | 5 | } |
67 | | |
68 | | XMLStyleExport::~XMLStyleExport() |
69 | 5 | { |
70 | 5 | } |
71 | | |
72 | | void XMLStyleExport::exportStyleAttributes( const Reference< XStyle >& ) |
73 | 27 | { |
74 | 27 | } |
75 | | |
76 | | void XMLStyleExport::exportStyleContent( const Reference< XStyle >& rStyle ) |
77 | 27 | { |
78 | 27 | Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY ); |
79 | 27 | assert(xPropSet.is()); |
80 | | |
81 | 27 | try |
82 | 27 | { |
83 | 27 | uno::Any aProperty = xPropSet->getPropertyValue( u"ParaStyleConditions"_ustr ); |
84 | 27 | uno::Sequence< beans::NamedValue > aSeq; |
85 | | |
86 | 27 | aProperty >>= aSeq; |
87 | | |
88 | 27 | for (beans::NamedValue const& rNamedCond : aSeq) |
89 | 0 | { |
90 | 0 | OUString aStyleName; |
91 | |
|
92 | 0 | if (rNamedCond.Value >>= aStyleName) |
93 | 0 | { |
94 | 0 | if (!aStyleName.isEmpty()) |
95 | 0 | { |
96 | 0 | OUString aExternal = GetParaStyleCondExternal(rNamedCond.Name); |
97 | |
|
98 | 0 | if (!aExternal.isEmpty()) |
99 | 0 | { |
100 | 0 | bool bEncoded; |
101 | |
|
102 | 0 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, |
103 | 0 | XML_CONDITION, |
104 | 0 | aExternal); |
105 | 0 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, |
106 | 0 | XML_APPLY_STYLE_NAME, |
107 | 0 | GetExport().EncodeStyleName( aStyleName, |
108 | 0 | &bEncoded ) ); |
109 | 0 | SvXMLElementExport aElem( GetExport(), |
110 | 0 | XML_NAMESPACE_STYLE, |
111 | 0 | XML_MAP, |
112 | 0 | true, |
113 | 0 | true ); |
114 | 0 | } |
115 | 0 | } |
116 | 0 | } |
117 | 0 | } |
118 | 27 | } |
119 | 27 | catch( const beans::UnknownPropertyException& ) |
120 | 27 | { |
121 | 27 | } |
122 | 27 | } |
123 | | |
124 | | namespace |
125 | | { |
126 | | /// Writes <style:style style:list-level="..."> for Writer paragraph styles. |
127 | | void ExportStyleListlevel(const uno::Reference<beans::XPropertySetInfo>& xPropSetInfo, |
128 | | const uno::Reference<beans::XPropertyState>& xPropState, |
129 | | const uno::Reference<beans::XPropertySet>& xPropSet, SvXMLExport& rExport) |
130 | 0 | { |
131 | 0 | if (!xPropSetInfo->hasPropertyByName(u"NumberingLevel"_ustr)) |
132 | 0 | { |
133 | 0 | SAL_WARN("xmloff", "ExportStyleListlevel: no NumberingLevel for a Writer paragraph style"); |
134 | 0 | return; |
135 | 0 | } |
136 | | |
137 | 0 | if (xPropState->getPropertyState(u"NumberingLevel"_ustr) != beans::PropertyState_DIRECT_VALUE) |
138 | 0 | { |
139 | 0 | return; |
140 | 0 | } |
141 | | |
142 | 0 | sal_Int16 nNumberingLevel{}; |
143 | 0 | if (!(xPropSet->getPropertyValue(u"NumberingLevel"_ustr) >>= nNumberingLevel)) |
144 | 0 | { |
145 | 0 | return; |
146 | 0 | } |
147 | | |
148 | | // The spec is positiveInteger (1-based), but the implementation is 0-based. |
149 | 0 | rExport.AddAttribute(XML_NAMESPACE_STYLE, XML_LIST_LEVEL, OUString::number(++nNumberingLevel)); |
150 | 0 | } |
151 | | } |
152 | | |
153 | | bool XMLStyleExport::exportStyle( |
154 | | const Reference< XStyle >& rStyle, |
155 | | const OUString& rXMLFamily, |
156 | | const rtl::Reference < SvXMLExportPropertyMapper >& rPropMapper, |
157 | | const Reference< XNameAccess >& xStyles, |
158 | | const OUString* pPrefix ) |
159 | 27 | { |
160 | 27 | Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY ); |
161 | 27 | if (!xPropSet) |
162 | 0 | return false; |
163 | | |
164 | 27 | Reference< XPropertySetInfo > xPropSetInfo = |
165 | 27 | xPropSet->getPropertySetInfo(); |
166 | 27 | Any aAny; |
167 | | |
168 | | // Don't export styles that aren't existing really. This may be the |
169 | | // case for StarOffice Writer's pool styles. |
170 | 27 | if( xPropSetInfo->hasPropertyByName( gsIsPhysical ) ) |
171 | 0 | { |
172 | 0 | aAny = xPropSet->getPropertyValue( gsIsPhysical ); |
173 | 0 | if( !*o3tl::doAccess<bool>(aAny) ) |
174 | 0 | return false; |
175 | 0 | } |
176 | | |
177 | | // <style:style ...> |
178 | 27 | GetExport().CheckAttrList(); |
179 | | |
180 | | // style:name="..." |
181 | 27 | OUString sName; |
182 | | |
183 | 27 | if(pPrefix) |
184 | 0 | sName = *pPrefix; |
185 | 27 | sName += rStyle->getName(); |
186 | | |
187 | 27 | bool bEncoded = false; |
188 | 27 | const OUString sEncodedStyleName(GetExport().EncodeStyleName( sName, &bEncoded )); |
189 | 27 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NAME, sEncodedStyleName ); |
190 | | |
191 | 27 | if( bEncoded ) |
192 | 17 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_DISPLAY_NAME, |
193 | 17 | sName); |
194 | | |
195 | | // style:family="..." |
196 | 27 | if( !rXMLFamily.isEmpty() ) |
197 | 27 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, rXMLFamily); |
198 | | |
199 | 27 | if ( xPropSetInfo->hasPropertyByName( u"Hidden"_ustr ) ) |
200 | 27 | { |
201 | 27 | aAny = xPropSet->getPropertyValue( u"Hidden"_ustr ); |
202 | 27 | bool bHidden = false; |
203 | 27 | if ((aAny >>= bHidden) && bHidden |
204 | 0 | && GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) |
205 | 0 | { |
206 | 0 | GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_HIDDEN, u"true"_ustr); |
207 | 0 | GetExport().AddAttribute(XML_NAMESPACE_STYLE, XML_HIDDEN, u"true"_ustr); // FIXME for compatibility |
208 | 0 | } |
209 | 27 | } |
210 | | |
211 | | // style:parent-style-name="..." |
212 | 27 | OUString sParentString(rStyle->getParentStyle()); |
213 | 27 | OUString sParent; |
214 | | |
215 | 27 | if(!sParentString.isEmpty()) |
216 | 24 | { |
217 | 24 | if(pPrefix) |
218 | 0 | sParent = *pPrefix; |
219 | 24 | sParent += sParentString; |
220 | 24 | } |
221 | | |
222 | 27 | if( !sParent.isEmpty() ) |
223 | 24 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_PARENT_STYLE_NAME, |
224 | 24 | GetExport().EncodeStyleName( sParent ) ); |
225 | | |
226 | | // style:next-style-name="..." (paragraph styles only) |
227 | 27 | if( xPropSetInfo->hasPropertyByName( gsFollowStyle ) ) |
228 | 0 | { |
229 | 0 | aAny = xPropSet->getPropertyValue( gsFollowStyle ); |
230 | 0 | OUString sNextName; |
231 | 0 | aAny >>= sNextName; |
232 | 0 | if( sName != sNextName ) |
233 | 0 | { |
234 | 0 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_NEXT_STYLE_NAME, |
235 | 0 | GetExport().EncodeStyleName( sNextName ) ); |
236 | 0 | } |
237 | 0 | } |
238 | | |
239 | | // style:linked-style-name="..." (SW paragraph and character styles only) |
240 | 27 | if (xPropSetInfo->hasPropertyByName(u"LinkStyle"_ustr)) |
241 | 0 | { |
242 | 0 | aAny = xPropSet->getPropertyValue(u"LinkStyle"_ustr); |
243 | 0 | OUString sLinkName; |
244 | 0 | aAny >>= sLinkName; |
245 | 0 | if (!sLinkName.isEmpty() |
246 | 0 | && (GetExport().getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED)) |
247 | 0 | { |
248 | 0 | GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_LINKED_STYLE_NAME, |
249 | 0 | GetExport().EncodeStyleName(sLinkName)); |
250 | 0 | } |
251 | 0 | } |
252 | | |
253 | | // style:auto-update="..." (SW only) |
254 | 27 | if( xPropSetInfo->hasPropertyByName( gsIsAutoUpdate ) ) |
255 | 0 | { |
256 | 0 | aAny = xPropSet->getPropertyValue( gsIsAutoUpdate ); |
257 | 0 | if( *o3tl::doAccess<bool>(aAny) ) |
258 | 0 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_AUTO_UPDATE, |
259 | 0 | XML_TRUE ); |
260 | 0 | } |
261 | | |
262 | | // style:default-outline-level"..." |
263 | 27 | sal_Int32 nOutlineLevel = 0; |
264 | 27 | if( xPropSetInfo->hasPropertyByName( gsOutlineLevel ) ) |
265 | 0 | { |
266 | 0 | Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY ); |
267 | 0 | if( PropertyState_DIRECT_VALUE == xPropState->getPropertyState( gsOutlineLevel ) ) |
268 | 0 | { |
269 | 0 | aAny = xPropSet->getPropertyValue( gsOutlineLevel ); |
270 | 0 | aAny >>= nOutlineLevel; |
271 | 0 | if( nOutlineLevel > 0 ) |
272 | 0 | { |
273 | 0 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, |
274 | 0 | XML_DEFAULT_OUTLINE_LEVEL, |
275 | 0 | OUString::number(nOutlineLevel) ); |
276 | 0 | } |
277 | 0 | else |
278 | 0 | { |
279 | | /* Empty value for style:default-outline-level does exist |
280 | | since ODF 1.2. Thus, suppress its export for former versions. (#i104889#) |
281 | | */ |
282 | 0 | if ( ( GetExport().getExportFlags() & SvXMLExportFlags::OASIS ) && |
283 | 0 | GetExport().getSaneDefaultVersion() >= SvtSaveOptions::ODFSVER_012) |
284 | 0 | { |
285 | 0 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, |
286 | 0 | XML_DEFAULT_OUTLINE_LEVEL, |
287 | 0 | u""_ustr); |
288 | 0 | } |
289 | 0 | } |
290 | 0 | } |
291 | 0 | } |
292 | | |
293 | | // style:list-style-name="..." (SW paragraph styles only) |
294 | 27 | if( xPropSetInfo->hasPropertyByName( gsNumberingStyleName ) ) |
295 | 0 | { |
296 | 0 | Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY ); |
297 | 0 | if( PropertyState_DIRECT_VALUE == |
298 | 0 | xPropState->getPropertyState( gsNumberingStyleName ) ) |
299 | 0 | { |
300 | 0 | aAny = xPropSet->getPropertyValue( gsNumberingStyleName ); |
301 | 0 | if( aAny.hasValue() ) |
302 | 0 | { |
303 | 0 | OUString sListName; |
304 | 0 | aAny >>= sListName; |
305 | | |
306 | | /* A direct set empty list style has to be written. Otherwise, |
307 | | this information is lost and causes an error, if the parent |
308 | | style has a list style set. (#i69523#) |
309 | | */ |
310 | 0 | if ( sListName.isEmpty() ) |
311 | 0 | { |
312 | 0 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, |
313 | 0 | XML_LIST_STYLE_NAME, |
314 | 0 | sListName /* empty string */); |
315 | 0 | } |
316 | 0 | else |
317 | 0 | { |
318 | | // Written OpenDocument file format doesn't fit to the created text document (#i69627#) |
319 | 0 | bool bSuppressListStyle( false ); |
320 | |
|
321 | 0 | if ( !GetExport().writeOutlineStyleAsNormalListStyle() ) |
322 | 0 | { |
323 | 0 | Reference< XChapterNumberingSupplier > xCNSupplier |
324 | 0 | (GetExport().GetModel(), UNO_QUERY); |
325 | |
|
326 | 0 | if (xCNSupplier.is()) |
327 | 0 | { |
328 | 0 | Reference< XIndexReplace > xNumRule |
329 | 0 | ( xCNSupplier->getChapterNumberingRules() ); |
330 | 0 | assert(xNumRule.is()); |
331 | |
|
332 | 0 | Reference< XPropertySet > xNumRulePropSet |
333 | 0 | (xNumRule, UNO_QUERY); |
334 | 0 | OUString sOutlineName; |
335 | 0 | xNumRulePropSet->getPropertyValue(u"Name"_ustr) |
336 | 0 | >>= sOutlineName; |
337 | 0 | bSuppressListStyle = sListName == sOutlineName; |
338 | 0 | } |
339 | 0 | } |
340 | |
|
341 | 0 | if ( !sListName.isEmpty() && !bSuppressListStyle ) |
342 | 0 | { |
343 | 0 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, |
344 | 0 | XML_LIST_STYLE_NAME, |
345 | 0 | GetExport().EncodeStyleName( sListName ) ); |
346 | |
|
347 | 0 | ExportStyleListlevel(xPropSetInfo, xPropState, xPropSet, GetExport()); |
348 | 0 | } |
349 | 0 | } |
350 | 0 | } |
351 | 0 | } |
352 | 0 | else if( nOutlineLevel > 0 ) |
353 | 0 | { |
354 | |
|
355 | 0 | bool bNoInheritedListStyle( true ); |
356 | |
|
357 | 0 | Reference<XStyle> xStyle( xPropState, UNO_QUERY ); |
358 | 0 | while ( xStyle.is() ) |
359 | 0 | { |
360 | 0 | OUString aParentStyle( xStyle->getParentStyle() ); |
361 | 0 | if ( aParentStyle.isEmpty() || !xStyles->hasByName( aParentStyle ) ) |
362 | 0 | { |
363 | 0 | break; |
364 | 0 | } |
365 | 0 | else |
366 | 0 | { |
367 | 0 | xPropState.set( xStyles->getByName( aParentStyle ), UNO_QUERY ); |
368 | 0 | if ( !xPropState.is() ) |
369 | 0 | { |
370 | 0 | break; |
371 | 0 | } |
372 | 0 | if ( xPropState->getPropertyState( gsNumberingStyleName ) == PropertyState_DIRECT_VALUE ) |
373 | 0 | { |
374 | 0 | bNoInheritedListStyle = false; |
375 | 0 | break; |
376 | 0 | } |
377 | 0 | else |
378 | 0 | { |
379 | 0 | xStyle.set( xPropState, UNO_QUERY ); |
380 | 0 | } |
381 | 0 | } |
382 | 0 | } |
383 | 0 | if ( bNoInheritedListStyle ) |
384 | 0 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, |
385 | 0 | XML_LIST_STYLE_NAME, |
386 | 0 | u""_ustr); |
387 | 0 | } |
388 | 0 | } |
389 | | |
390 | | // style:pool-id="..." is not required any longer since we use |
391 | | // english style names only |
392 | 27 | exportStyleAttributes( rStyle ); |
393 | | |
394 | | // TODO: style:help-file-name="..." and style:help-id="..." can neither |
395 | | // be modified by UI nor by API and that for, have not to be exported |
396 | | // currently. |
397 | | |
398 | 27 | { |
399 | | // <style:style> |
400 | 27 | SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, XML_STYLE, |
401 | 27 | true, true ); |
402 | | |
403 | 27 | rPropMapper->SetStyleName( sName ); |
404 | | |
405 | | // <style:properties> |
406 | 27 | ::std::vector< XMLPropertyState > aPropStates = |
407 | 27 | rPropMapper->Filter(GetExport(), xPropSet, true); |
408 | 27 | bool const bUseExtensionNamespaceForGraphicProperties( |
409 | 27 | rXMLFamily != "drawing-page" && |
410 | 27 | rXMLFamily != "graphic" && |
411 | 0 | rXMLFamily != "presentation" && |
412 | 0 | rXMLFamily != "chart"); |
413 | 27 | rPropMapper->exportXML( GetExport(), aPropStates, |
414 | 27 | SvXmlExportFlags::IGN_WS, |
415 | 27 | bUseExtensionNamespaceForGraphicProperties ); |
416 | | |
417 | 27 | rPropMapper->SetStyleName( OUString() ); |
418 | | |
419 | 27 | exportStyleContent( rStyle ); |
420 | | |
421 | | // <script:events>, if they are supported by this style |
422 | 27 | Reference<XEventsSupplier> xEventsSupp(rStyle, UNO_QUERY); |
423 | 27 | GetExport().GetEventExport().Export(xEventsSupp); |
424 | 27 | } |
425 | 27 | return true; |
426 | 27 | } |
427 | | |
428 | | void XMLStyleExport::exportDefaultStyle( |
429 | | const Reference< XPropertySet >& xPropSet, |
430 | | const OUString& rXMLFamily, |
431 | | const rtl::Reference < SvXMLExportPropertyMapper >& rPropMapper ) |
432 | 1 | { |
433 | | // <style:default-style ...> |
434 | 1 | GetExport().CheckAttrList(); |
435 | | |
436 | 1 | { |
437 | | // style:family="..." |
438 | 1 | if( !rXMLFamily.isEmpty() ) |
439 | 1 | GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FAMILY, |
440 | 1 | rXMLFamily ); |
441 | | // <style:style> |
442 | 1 | SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_STYLE, |
443 | 1 | XML_DEFAULT_STYLE, |
444 | 1 | true, true ); |
445 | | // <style:properties> |
446 | 1 | ::std::vector< XMLPropertyState > aPropStates = |
447 | 1 | rPropMapper->FilterDefaults(GetExport(), xPropSet); |
448 | 1 | rPropMapper->exportXML( GetExport(), aPropStates, |
449 | 1 | SvXmlExportFlags::IGN_WS ); |
450 | 1 | } |
451 | 1 | } |
452 | | |
453 | | void XMLStyleExport::exportStyleFamily( |
454 | | const OUString& rFamily, const OUString& rXMLFamily, |
455 | | const rtl::Reference < SvXMLExportPropertyMapper >& rPropMapper, |
456 | | bool bUsed, XmlStyleFamily nFamily, const OUString* pPrefix) |
457 | 3 | { |
458 | 3 | assert(GetExport().GetModel().is()); |
459 | 3 | Reference< XStyleFamiliesSupplier > xFamiliesSupp( GetExport().GetModel(), UNO_QUERY ); |
460 | 3 | if( !xFamiliesSupp.is() ) |
461 | 0 | return; // family not available in current model |
462 | | |
463 | 3 | Reference< XNameAccess > xStyleCont; |
464 | | |
465 | 3 | Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() ); |
466 | 3 | if( xFamilies->hasByName( rFamily ) ) |
467 | 2 | xFamilies->getByName( rFamily ) >>= xStyleCont; |
468 | | |
469 | 3 | if( !xStyleCont.is() ) |
470 | 1 | return; |
471 | | |
472 | | // If next styles are supported and used styles should be exported only, |
473 | | // the next style may be unused but has to be exported, too. In this case |
474 | | // the names of all exported styles are remembered. |
475 | 2 | std::optional<std::set<OUString> > xExportedStyles; |
476 | 2 | bool bFirstStyle = true; |
477 | | |
478 | 2 | const uno::Sequence< OUString> aSeq = xStyleCont->getElementNames(); |
479 | 2 | for(const auto& rName : aSeq) |
480 | 27 | { |
481 | 27 | Reference< XStyle > xStyle; |
482 | 27 | try |
483 | 27 | { |
484 | 27 | xStyleCont->getByName( rName ) >>= xStyle; |
485 | 27 | } |
486 | 27 | catch(const lang::IndexOutOfBoundsException&) |
487 | 27 | { |
488 | | // due to bugs in prior versions it is possible that |
489 | | // a binary file is missing some critical styles. |
490 | | // The only possible way to deal with this is to |
491 | | // not export them here and remain silent. |
492 | 0 | continue; |
493 | 0 | } |
494 | 27 | catch(css::container::NoSuchElementException&) |
495 | 27 | { |
496 | 0 | continue; |
497 | 0 | } |
498 | | |
499 | 27 | assert(xStyle.is()); |
500 | 27 | if (!bUsed || xStyle->isInUse()) |
501 | 27 | { |
502 | 27 | bool bExported = exportStyle( xStyle, rXMLFamily, rPropMapper, |
503 | 27 | xStyleCont,pPrefix ); |
504 | 27 | if (bUsed && bFirstStyle && bExported) |
505 | 0 | { |
506 | | // If this is the first style, find out whether next styles |
507 | | // are supported. |
508 | 0 | Reference< XPropertySet > xPropSet( xStyle, UNO_QUERY ); |
509 | 0 | Reference< XPropertySetInfo > xPropSetInfo = |
510 | 0 | xPropSet->getPropertySetInfo(); |
511 | |
|
512 | 0 | if (xPropSetInfo->hasPropertyByName( gsFollowStyle )) |
513 | 0 | xExportedStyles.emplace(); |
514 | 0 | bFirstStyle = false; |
515 | 0 | } |
516 | | |
517 | 27 | if (xExportedStyles && bExported) |
518 | 0 | { |
519 | | // If next styles are supported, remember this style's name. |
520 | 0 | xExportedStyles->insert( xStyle->getName() ); |
521 | 0 | } |
522 | 27 | } |
523 | | |
524 | | // if an auto style pool is given, remember this style's name as a |
525 | | // style name that must not be used by automatic styles. |
526 | 27 | if (m_pAutoStylePool) |
527 | 27 | m_pAutoStylePool->RegisterName( nFamily, xStyle->getName() ); |
528 | 27 | } |
529 | | |
530 | 2 | if( !xExportedStyles ) |
531 | 2 | return; |
532 | | |
533 | | // if next styles are supported, export all next styles that are |
534 | | // unused and that for, haven't been exported in the first loop. |
535 | 0 | for(const auto& rName : aSeq) |
536 | 0 | { |
537 | 0 | Reference< XStyle > xStyle; |
538 | 0 | xStyleCont->getByName( rName ) >>= xStyle; |
539 | |
|
540 | 0 | assert(xStyle.is()); |
541 | |
|
542 | 0 | Reference< XPropertySet > xPropSet( xStyle, UNO_QUERY ); |
543 | 0 | Reference< XPropertySetInfo > xPropSetInfo( xPropSet->getPropertySetInfo() ); |
544 | | |
545 | | // styles that aren't existing really are ignored. |
546 | 0 | if (xPropSetInfo->hasPropertyByName( gsIsPhysical )) |
547 | 0 | { |
548 | 0 | Any aAny( xPropSet->getPropertyValue( gsIsPhysical ) ); |
549 | 0 | if (!*o3tl::doAccess<bool>(aAny)) |
550 | 0 | continue; |
551 | 0 | } |
552 | | |
553 | 0 | if (!xStyle->isInUse()) |
554 | 0 | continue; |
555 | | |
556 | 0 | if (!xPropSetInfo->hasPropertyByName( gsFollowStyle )) |
557 | 0 | { |
558 | 0 | continue; |
559 | 0 | } |
560 | | |
561 | 0 | OUString sNextName; |
562 | 0 | xPropSet->getPropertyValue( gsFollowStyle ) >>= sNextName; |
563 | 0 | OUString sTmp( sNextName ); |
564 | | // if the next style hasn't been exported by now, export it now |
565 | | // and remember its name. |
566 | 0 | if (xStyle->getName() != sNextName && |
567 | 0 | 0 == xExportedStyles->count( sTmp )) |
568 | 0 | { |
569 | 0 | xStyleCont->getByName( sNextName ) >>= xStyle; |
570 | 0 | assert(xStyle.is()); |
571 | |
|
572 | 0 | if (exportStyle(xStyle, rXMLFamily, rPropMapper, xStyleCont, pPrefix)) |
573 | 0 | xExportedStyles->insert( sTmp ); |
574 | 0 | } |
575 | 0 | } |
576 | 0 | } |
577 | | |
578 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |