/src/libreoffice/xmloff/source/draw/ximpstyl.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 "ximpstyl.hxx" |
21 | | #include <xmloff/maptype.hxx> |
22 | | #include <xmloff/XMLDrawingPageStyleContext.hxx> |
23 | | #include <xmloff/XMLShapeStyleContext.hxx> |
24 | | #include <xmloff/xmlnamespace.hxx> |
25 | | #include <xmloff/xmlprmap.hxx> |
26 | | #include <xmloff/xmltoken.hxx> |
27 | | #include <xmloff/xmluconv.hxx> |
28 | | #include "ximpnote.hxx" |
29 | | #include <xmlsdtypes.hxx> |
30 | | #include <tools/gen.hxx> |
31 | | #include <tools/debug.hxx> |
32 | | #include <sal/log.hxx> |
33 | | #include <comphelper/diagnose_ex.hxx> |
34 | | #include <com/sun/star/frame/XModel.hpp> |
35 | | #include <com/sun/star/style/XStyle.hpp> |
36 | | #include <com/sun/star/lang/XSingleServiceFactory.hpp> |
37 | | #include <com/sun/star/presentation/XPresentationPage.hpp> |
38 | | #include <com/sun/star/drawing/FillStyle.hpp> |
39 | | #include <com/sun/star/drawing/XDrawPages.hpp> |
40 | | #include <com/sun/star/container/XNamed.hpp> |
41 | | #include <com/sun/star/beans/XPropertySet.hpp> |
42 | | #include <com/sun/star/beans/XPropertyState.hpp> |
43 | | #include <com/sun/star/presentation/XHandoutMasterSupplier.hpp> |
44 | | #include <comphelper/namecontainer.hxx> |
45 | | #include <xmloff/autolayout.hxx> |
46 | | #include <xmloff/xmlprcon.hxx> |
47 | | #include <xmloff/families.hxx> |
48 | | #include <com/sun/star/container/XNameContainer.hpp> |
49 | | #include <svl/numformat.hxx> |
50 | | #include "layerimp.hxx" |
51 | | #include <xmloff/XMLGraphicsDefaultStyle.hxx> |
52 | | #include <XMLNumberStylesImport.hxx> |
53 | | #include <XMLThemeContext.hxx> |
54 | | #include <comphelper/configuration.hxx> |
55 | | #include <xmloff/xmlerror.hxx> |
56 | | #include <xmloff/table/XMLTableImport.hxx> |
57 | | |
58 | | using namespace ::com::sun::star; |
59 | | using namespace ::com::sun::star::uno; |
60 | | using namespace ::com::sun::star::xml::sax; |
61 | | using namespace ::xmloff::token; |
62 | | |
63 | | namespace { |
64 | | |
65 | | class SdXMLDrawingPagePropertySetContext : public SvXMLPropertySetContext |
66 | | { |
67 | | public: |
68 | | |
69 | | SdXMLDrawingPagePropertySetContext( SvXMLImport& rImport, sal_Int32 nElement, |
70 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, |
71 | | ::std::vector< XMLPropertyState > &rProps, |
72 | | SvXMLImportPropertyMapper* pMap ); |
73 | | |
74 | | using SvXMLPropertySetContext::createFastChildContext; |
75 | | virtual css::uno::Reference< css::xml::sax::XFastContextHandler > createFastChildContext( |
76 | | sal_Int32 nElement, |
77 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, |
78 | | ::std::vector< XMLPropertyState > &rProperties, |
79 | | const XMLPropertyState& rProp ) override; |
80 | | }; |
81 | | } // end anonymous namespace |
82 | | |
83 | | SdXMLDrawingPagePropertySetContext::SdXMLDrawingPagePropertySetContext( |
84 | | SvXMLImport& rImport, sal_Int32 nElement, |
85 | | const uno::Reference< xml::sax::XFastAttributeList > & xAttrList, |
86 | | ::std::vector< XMLPropertyState > &rProps, |
87 | | SvXMLImportPropertyMapper* pMap ) : |
88 | 1.06k | SvXMLPropertySetContext( rImport, nElement, xAttrList, |
89 | 1.06k | XML_TYPE_PROP_DRAWING_PAGE, rProps, pMap ) |
90 | 1.06k | { |
91 | 1.06k | } |
92 | | |
93 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLDrawingPagePropertySetContext::createFastChildContext( |
94 | | sal_Int32 nElement, |
95 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, |
96 | | ::std::vector< XMLPropertyState > &rProperties, |
97 | | const XMLPropertyState& rProp ) |
98 | 0 | { |
99 | 0 | switch( mpMapper->getPropertySetMapper()->GetEntryContextId( rProp.mnIndex ) ) |
100 | 0 | { |
101 | 0 | case CTF_PAGE_SOUND_URL: |
102 | 0 | { |
103 | 0 | for (auto &aIter : sax_fastparser::castToFastAttributeList(xAttrList)) |
104 | 0 | { |
105 | 0 | if( aIter.getToken() == XML_ELEMENT(XLINK, XML_HREF) ) |
106 | 0 | { |
107 | 0 | uno::Any aAny( GetImport().GetAbsoluteReference( aIter.toString() ) ); |
108 | 0 | XMLPropertyState aPropState( rProp.mnIndex, aAny ); |
109 | 0 | rProperties.push_back( aPropState ); |
110 | 0 | } |
111 | 0 | else |
112 | 0 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
113 | 0 | } |
114 | 0 | break; |
115 | 0 | } |
116 | 0 | } |
117 | | |
118 | 0 | return SvXMLPropertySetContext::createFastChildContext( nElement, |
119 | 0 | xAttrList, |
120 | 0 | rProperties, rProp ); |
121 | 0 | } |
122 | | |
123 | | namespace { |
124 | | |
125 | | |
126 | | class SdXMLDrawingPageStyleContext : public XMLDrawingPageStyleContext |
127 | | { |
128 | | public: |
129 | | |
130 | | SdXMLDrawingPageStyleContext( |
131 | | SvXMLImport& rImport, |
132 | | SvXMLStylesContext& rStyles); |
133 | | |
134 | | virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( |
135 | | sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; |
136 | | |
137 | | virtual void Finish( bool bOverwrite ) override; |
138 | | }; |
139 | | |
140 | | const sal_uInt16 MAX_SPECIAL_DRAW_STYLES = 7; |
141 | | ContextID_Index_Pair const g_ContextIDs[MAX_SPECIAL_DRAW_STYLES+1] = |
142 | | { |
143 | | { CTF_DASHNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, |
144 | | { CTF_LINESTARTNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, |
145 | | { CTF_LINEENDNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, |
146 | | { CTF_FILLGRADIENTNAME, -1, drawing::FillStyle::FillStyle_GRADIENT}, |
147 | | { CTF_FILLTRANSNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, |
148 | | { CTF_FILLHATCHNAME, -1, drawing::FillStyle::FillStyle_HATCH }, |
149 | | { CTF_FILLBITMAPNAME, -1, drawing::FillStyle::FillStyle_BITMAP }, |
150 | | { -1, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE } |
151 | | }; |
152 | | XmlStyleFamily const g_Families[MAX_SPECIAL_DRAW_STYLES] = |
153 | | { |
154 | | XmlStyleFamily::SD_STROKE_DASH_ID, |
155 | | XmlStyleFamily::SD_MARKER_ID, |
156 | | XmlStyleFamily::SD_MARKER_ID, |
157 | | XmlStyleFamily::SD_GRADIENT_ID, |
158 | | XmlStyleFamily::SD_GRADIENT_ID, |
159 | | XmlStyleFamily::SD_HATCH_ID, |
160 | | XmlStyleFamily::SD_FILL_IMAGE_ID |
161 | | }; |
162 | | |
163 | | } |
164 | | |
165 | | XMLDrawingPageStyleContext::XMLDrawingPageStyleContext( |
166 | | SvXMLImport& rImport, |
167 | | SvXMLStylesContext& rStyles, |
168 | | ContextID_Index_Pair const pContextIDs[], |
169 | | XmlStyleFamily const pFamilies[]) |
170 | 1.48k | : XMLPropStyleContext(rImport, rStyles, XmlStyleFamily::SD_DRAWINGPAGE_ID) |
171 | 1.48k | , m_pFamilies(pFamilies) |
172 | 1.48k | { |
173 | 1.48k | size_t size(1); // for the -1 entry |
174 | 11.0k | for (ContextID_Index_Pair const* pTemp(pContextIDs); pTemp->nContextID != -1; ++size, ++pTemp); |
175 | 1.48k | m_pContextIDs.reset(new ContextID_Index_Pair[size]); |
176 | 1.48k | std::copy(pContextIDs, pContextIDs + size, m_pContextIDs.get()); |
177 | 1.48k | } |
178 | | |
179 | | SdXMLDrawingPageStyleContext::SdXMLDrawingPageStyleContext( |
180 | | SvXMLImport& rImport, |
181 | | SvXMLStylesContext& rStyles) |
182 | 1.21k | : XMLDrawingPageStyleContext(rImport, rStyles, g_ContextIDs, g_Families) |
183 | 1.21k | { |
184 | 1.21k | } |
185 | | |
186 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLDrawingPageStyleContext::createFastChildContext( |
187 | | sal_Int32 nElement, |
188 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
189 | 1.26k | { |
190 | 1.26k | if( nElement == XML_ELEMENT(STYLE, XML_DRAWING_PAGE_PROPERTIES) ) |
191 | 1.06k | { |
192 | 1.06k | SvXMLImportPropertyMapper* pImpPrMap = |
193 | 1.06k | GetStyles()->GetImportPropertyMapper( GetFamily() ); |
194 | 1.06k | if( pImpPrMap ) |
195 | 1.06k | return new SdXMLDrawingPagePropertySetContext( GetImport(), nElement, |
196 | 1.06k | xAttrList, |
197 | 1.06k | GetProperties(), |
198 | 1.06k | pImpPrMap ); |
199 | 1.06k | } |
200 | | |
201 | 202 | return XMLPropStyleContext::createFastChildContext( nElement, xAttrList ); |
202 | 1.26k | } |
203 | | |
204 | | void SdXMLDrawingPageStyleContext::Finish( bool bOverwrite ) |
205 | 1.09k | { |
206 | 1.09k | XMLPropStyleContext::Finish( bOverwrite ); |
207 | | |
208 | 1.09k | ::std::vector< XMLPropertyState > &rProperties = GetProperties(); |
209 | | |
210 | 1.09k | const rtl::Reference< XMLPropertySetMapper >& rImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper(); |
211 | | |
212 | 1.09k | for(auto& property : rProperties) |
213 | 2.00k | { |
214 | 2.00k | if( property.mnIndex == -1 ) |
215 | 0 | continue; |
216 | | |
217 | 2.00k | sal_Int16 nContextID = rImpPrMap->GetEntryContextId(property.mnIndex); |
218 | 2.00k | switch( nContextID ) |
219 | 2.00k | { |
220 | 0 | case CTF_DATE_TIME_FORMAT: |
221 | 0 | { |
222 | 0 | OUString sStyleName; |
223 | 0 | property.maValue >>= sStyleName; |
224 | |
|
225 | 0 | sal_Int32 nStyle = 0; |
226 | |
|
227 | 0 | const SdXMLNumberFormatImportContext* pSdNumStyle = |
228 | 0 | dynamic_cast< const SdXMLNumberFormatImportContext*> ( |
229 | 0 | GetStyles()->FindStyleChildContext( XmlStyleFamily::DATA_STYLE, sStyleName, true ) ); |
230 | |
|
231 | 0 | if( pSdNumStyle ) |
232 | 0 | nStyle = pSdNumStyle->GetDrawKey(); |
233 | |
|
234 | 0 | property.maValue <<= nStyle; |
235 | 0 | } |
236 | 0 | break; |
237 | 2.00k | } |
238 | 2.00k | } |
239 | | |
240 | 1.09k | } |
241 | | |
242 | | |
243 | | // #i35918# |
244 | | void XMLDrawingPageStyleContext::FillPropertySet( |
245 | | const Reference< beans::XPropertySet > & rPropSet ) |
246 | 8.61k | { |
247 | 8.61k | SvXMLImportPropertyMapper* pImpPrMap = |
248 | 8.61k | GetStyles()->GetImportPropertyMapper( GetFamily() ); |
249 | 8.61k | assert( pImpPrMap ); |
250 | 8.61k | pImpPrMap->FillPropertySet(GetProperties(), rPropSet, m_pContextIDs.get()); |
251 | | |
252 | 8.61k | Reference< beans::XPropertySetInfo > xInfo; |
253 | 54.8k | for (size_t i=0; m_pContextIDs[i].nContextID != -1; ++i) |
254 | 46.1k | { |
255 | 46.1k | sal_Int32 nIndex = m_pContextIDs[i].nIndex; |
256 | 46.1k | if( nIndex != -1 ) |
257 | 0 | { |
258 | 0 | struct XMLPropertyState& rState = GetProperties()[nIndex]; |
259 | 0 | OUString sStyleName; |
260 | 0 | rState.maValue >>= sStyleName; |
261 | |
|
262 | 0 | if (::xmloff::IsIgnoreFillStyleNamedItem(rPropSet, m_pContextIDs[i].nExpectedFillStyle)) |
263 | 0 | { |
264 | 0 | SAL_INFO("xmloff.style", "XMLDrawingPageStyleContext: dropping fill named item: " << sStyleName); |
265 | 0 | break; // ignore it, it's not used |
266 | 0 | } |
267 | | |
268 | 0 | sStyleName = GetImport().GetStyleDisplayName( m_pFamilies[i], |
269 | 0 | sStyleName ); |
270 | | // get property set mapper |
271 | 0 | rtl::Reference<XMLPropertySetMapper> rPropMapper = |
272 | 0 | pImpPrMap->getPropertySetMapper(); |
273 | | |
274 | | // set property |
275 | 0 | const OUString& rPropertyName = |
276 | 0 | rPropMapper->GetEntryAPIName(rState.mnIndex); |
277 | 0 | if( !xInfo.is() ) |
278 | 0 | xInfo = rPropSet->getPropertySetInfo(); |
279 | 0 | if ( xInfo->hasPropertyByName( rPropertyName ) ) |
280 | 0 | { |
281 | 0 | rPropSet->setPropertyValue( rPropertyName, Any( sStyleName ) ); |
282 | 0 | } |
283 | 0 | } |
284 | 46.1k | } |
285 | 8.61k | } |
286 | | |
287 | | |
288 | | SdXMLPageMasterStyleContext::SdXMLPageMasterStyleContext( |
289 | | SdXMLImport& rImport, |
290 | | sal_Int32 /*nElement*/, |
291 | | const uno::Reference< xml::sax::XFastAttributeList>& xAttrList) |
292 | 970 | : SvXMLStyleContext(rImport, XmlStyleFamily::SD_PAGEMASTERSTYLECONTEXT_ID), |
293 | 970 | mnBorderBottom( 0 ), |
294 | 970 | mnBorderLeft( 0 ), |
295 | 970 | mnBorderRight( 0 ), |
296 | 970 | mnBorderTop( 0 ), |
297 | 970 | mnWidth( 0 ), |
298 | 970 | mnHeight( 0 ), |
299 | 970 | meOrientation(GetSdImport().IsDraw() ? view::PaperOrientation_PORTRAIT : view::PaperOrientation_LANDSCAPE) |
300 | 970 | { |
301 | | // set family to something special at SvXMLStyleContext |
302 | | // for differences in search-methods |
303 | | |
304 | 970 | for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) |
305 | 4.09k | { |
306 | 4.09k | switch(aIter.getToken()) |
307 | 4.09k | { |
308 | 0 | case XML_ELEMENT(FO, XML_MARGIN_TOP): |
309 | 609 | case XML_ELEMENT(FO_COMPAT, XML_MARGIN_TOP): |
310 | 609 | { |
311 | 609 | GetSdImport().GetMM100UnitConverter().convertMeasureToCore( |
312 | 609 | mnBorderTop, aIter.toView()); |
313 | 609 | break; |
314 | 0 | } |
315 | 0 | case XML_ELEMENT(FO, XML_MARGIN_BOTTOM): |
316 | 609 | case XML_ELEMENT(FO_COMPAT, XML_MARGIN_BOTTOM): |
317 | 609 | { |
318 | 609 | GetSdImport().GetMM100UnitConverter().convertMeasureToCore( |
319 | 609 | mnBorderBottom, aIter.toView()); |
320 | 609 | break; |
321 | 0 | } |
322 | 0 | case XML_ELEMENT(FO, XML_MARGIN_LEFT): |
323 | 512 | case XML_ELEMENT(FO_COMPAT, XML_MARGIN_LEFT): |
324 | 512 | { |
325 | 512 | GetSdImport().GetMM100UnitConverter().convertMeasureToCore( |
326 | 512 | mnBorderLeft, aIter.toView()); |
327 | 512 | break; |
328 | 0 | } |
329 | 0 | case XML_ELEMENT(FO, XML_MARGIN_RIGHT): |
330 | 403 | case XML_ELEMENT(FO_COMPAT, XML_MARGIN_RIGHT): |
331 | 403 | { |
332 | 403 | GetSdImport().GetMM100UnitConverter().convertMeasureToCore( |
333 | 403 | mnBorderRight, aIter.toView()); |
334 | 403 | break; |
335 | 0 | } |
336 | 0 | case XML_ELEMENT(FO, XML_PAGE_WIDTH): |
337 | 467 | case XML_ELEMENT(FO_COMPAT, XML_PAGE_WIDTH): |
338 | 467 | { |
339 | 467 | GetSdImport().GetMM100UnitConverter().convertMeasureToCore( |
340 | 467 | mnWidth, aIter.toView()); |
341 | 467 | break; |
342 | 0 | } |
343 | 0 | case XML_ELEMENT(FO, XML_PAGE_HEIGHT): |
344 | 523 | case XML_ELEMENT(FO_COMPAT, XML_PAGE_HEIGHT): |
345 | 523 | { |
346 | 523 | GetSdImport().GetMM100UnitConverter().convertMeasureToCore( |
347 | 523 | mnHeight, aIter.toView()); |
348 | 523 | break; |
349 | 0 | } |
350 | 955 | case XML_ELEMENT(STYLE, XML_PRINT_ORIENTATION): |
351 | 955 | { |
352 | 955 | if( IsXMLToken( aIter, XML_PORTRAIT ) ) |
353 | 563 | meOrientation = view::PaperOrientation_PORTRAIT; |
354 | 392 | else |
355 | 392 | meOrientation = view::PaperOrientation_LANDSCAPE; |
356 | 955 | break; |
357 | 0 | } |
358 | 18 | default: |
359 | 18 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
360 | 4.09k | } |
361 | 4.09k | } |
362 | | // Set size to useful default value, same as in SdDrawDocument::CreateFirstPages |
363 | | // except we cannot call SvxPaperInfo::GetDefaultPaperSize from here. |
364 | 970 | if (mnWidth == 0) |
365 | 578 | mnWidth = 21000; |
366 | 970 | if (mnHeight == 0) |
367 | 451 | mnHeight = 29700; |
368 | 970 | } |
369 | | |
370 | | SdXMLPageMasterStyleContext::~SdXMLPageMasterStyleContext() |
371 | 970 | { |
372 | 970 | } |
373 | | |
374 | | |
375 | | SdXMLPageMasterContext::SdXMLPageMasterContext( |
376 | | SdXMLImport& rImport, |
377 | | sal_Int32 /*nElement*/, |
378 | | const uno::Reference< xml::sax::XFastAttributeList>& /*xAttrList*/) |
379 | 1.06k | : SvXMLStyleContext(rImport, XmlStyleFamily::SD_PAGEMASTERCONTEXT_ID) |
380 | 1.06k | { |
381 | | // set family to something special at SvXMLStyleContext |
382 | | // for differences in search-methods |
383 | | |
384 | 1.06k | } |
385 | | |
386 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLPageMasterContext::createFastChildContext( |
387 | | sal_Int32 nElement, |
388 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
389 | 1.18k | { |
390 | 1.18k | if(nElement == XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_PROPERTIES)) |
391 | 970 | { |
392 | 970 | DBG_ASSERT(!mxPageMasterStyle.is(), "PageMasterStyle is set, there seem to be two of them (!)"); |
393 | 970 | mxPageMasterStyle.set(new SdXMLPageMasterStyleContext(GetSdImport(), nElement, xAttrList)); |
394 | 970 | return mxPageMasterStyle; |
395 | 970 | } |
396 | 215 | else |
397 | 1.18k | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
398 | | |
399 | 215 | return nullptr; |
400 | 1.18k | } |
401 | | |
402 | | SdXMLPresentationPageLayoutContext::SdXMLPresentationPageLayoutContext( |
403 | | SdXMLImport& rImport, |
404 | | sal_Int32 /*nElement*/, |
405 | | const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/) |
406 | 606 | : SvXMLStyleContext(rImport, XmlStyleFamily::SD_PRESENTATIONPAGELAYOUT_ID), |
407 | 606 | mnTypeId( AUTOLAYOUT_NONE ) |
408 | 606 | { |
409 | | // set family to something special at SvXMLStyleContext |
410 | | // for differences in search-methods |
411 | 606 | } |
412 | | |
413 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLPresentationPageLayoutContext::createFastChildContext( |
414 | | sal_Int32 nElement, |
415 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
416 | 2.31k | { |
417 | 2.31k | SvXMLImportContextRef xContext; |
418 | | |
419 | 2.31k | if(nElement == XML_ELEMENT(PRESENTATION, XML_PLACEHOLDER)) |
420 | 2.28k | { |
421 | 2.28k | const rtl::Reference< SdXMLPresentationPlaceholderContext > xLclContext{ |
422 | 2.28k | new SdXMLPresentationPlaceholderContext(GetSdImport(), nElement, xAttrList)}; |
423 | | // presentation:placeholder inside style:presentation-page-layout context |
424 | 2.28k | xContext = xLclContext.get(); |
425 | | |
426 | | // remember SdXMLPresentationPlaceholderContext for later evaluation |
427 | 2.28k | maList.push_back(xLclContext); |
428 | 2.28k | } |
429 | 37 | else |
430 | 2.31k | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
431 | | |
432 | 2.31k | return xContext; |
433 | 2.31k | } |
434 | | |
435 | | void SdXMLPresentationPageLayoutContext::endFastElement(sal_Int32 ) |
436 | 579 | { |
437 | | // build presentation page layout type here |
438 | | // calc mnTpeId due to content of maList |
439 | | // at the moment only use number of types used there |
440 | 579 | if( maList.empty() ) |
441 | 60 | return; |
442 | | |
443 | 519 | SdXMLPresentationPlaceholderContext* pObj0 = maList[ 0 ].get(); |
444 | 519 | if( pObj0->GetName() == "handout" ) |
445 | 258 | { |
446 | 258 | switch( maList.size() ) |
447 | 258 | { |
448 | 0 | case 1: |
449 | 0 | mnTypeId = AUTOLAYOUT_HANDOUT1; |
450 | 0 | break; |
451 | 2 | case 2: |
452 | 2 | mnTypeId = AUTOLAYOUT_HANDOUT2; |
453 | 2 | break; |
454 | 3 | case 3: |
455 | 3 | mnTypeId = AUTOLAYOUT_HANDOUT3; |
456 | 3 | break; |
457 | 1 | case 4: |
458 | 1 | mnTypeId = AUTOLAYOUT_HANDOUT4; |
459 | 1 | break; |
460 | 0 | case 9: |
461 | 0 | mnTypeId = AUTOLAYOUT_HANDOUT9; |
462 | 0 | break; |
463 | 252 | default: |
464 | 252 | mnTypeId = AUTOLAYOUT_HANDOUT6; |
465 | 258 | } |
466 | 258 | } |
467 | 261 | else |
468 | 261 | { |
469 | 261 | switch( maList.size() ) |
470 | 261 | { |
471 | 32 | case 1: |
472 | 32 | { |
473 | 32 | if( pObj0->GetName() == "title" ) |
474 | 3 | { |
475 | 3 | mnTypeId = AUTOLAYOUT_TITLE_ONLY; |
476 | 3 | } |
477 | 29 | else |
478 | 29 | { |
479 | 29 | mnTypeId = AUTOLAYOUT_ONLY_TEXT; |
480 | 29 | } |
481 | 32 | break; |
482 | 0 | } |
483 | 49 | case 2: |
484 | 49 | { |
485 | 49 | SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get(); |
486 | | |
487 | 49 | if( pObj1->GetName() == "subtitle" ) |
488 | 0 | { |
489 | 0 | mnTypeId = AUTOLAYOUT_TITLE; |
490 | 0 | } |
491 | 49 | else if( pObj1->GetName() == "outline" ) |
492 | 48 | { |
493 | 48 | mnTypeId = AUTOLAYOUT_TITLE_CONTENT; |
494 | 48 | } |
495 | 1 | else if( pObj1->GetName() == "chart" ) |
496 | 0 | { |
497 | 0 | mnTypeId = AUTOLAYOUT_CHART; |
498 | 0 | } |
499 | 1 | else if( pObj1->GetName() == "table" ) |
500 | 0 | { |
501 | 0 | mnTypeId = AUTOLAYOUT_TAB; |
502 | 0 | } |
503 | 1 | else if( pObj1->GetName() == "object" ) |
504 | 0 | { |
505 | 0 | mnTypeId = AUTOLAYOUT_OBJ; |
506 | 0 | } |
507 | 1 | else if( pObj1->GetName() == "vertical_outline" ) |
508 | 0 | { |
509 | 0 | if( pObj0->GetName() == "vertical_title" ) |
510 | 0 | { |
511 | 0 | mnTypeId = AUTOLAYOUT_VTITLE_VCONTENT; |
512 | 0 | } |
513 | 0 | else |
514 | 0 | { |
515 | 0 | mnTypeId = AUTOLAYOUT_TITLE_VCONTENT; |
516 | 0 | } |
517 | 0 | } |
518 | 1 | else |
519 | 1 | { |
520 | 1 | mnTypeId = AUTOLAYOUT_NOTES; |
521 | 1 | } |
522 | 49 | break; |
523 | 0 | } |
524 | 174 | case 3: |
525 | 174 | { |
526 | 174 | SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get(); |
527 | 174 | SdXMLPresentationPlaceholderContext* pObj2 = maList[ 2 ].get(); |
528 | | |
529 | 174 | if( pObj1->GetName() == "outline" ) |
530 | 172 | { |
531 | 172 | if( pObj2->GetName() == "outline" ) |
532 | 169 | { |
533 | 169 | mnTypeId = AUTOLAYOUT_TITLE_2CONTENT; |
534 | 169 | } |
535 | 3 | else if( pObj2->GetName() == "chart" ) |
536 | 0 | { |
537 | 0 | mnTypeId = AUTOLAYOUT_TEXTCHART; |
538 | 0 | } |
539 | 3 | else if( pObj2->GetName() == "graphic" ) |
540 | 0 | { |
541 | 0 | mnTypeId = AUTOLAYOUT_TEXTCLIP; |
542 | 0 | } |
543 | 3 | else |
544 | 3 | { |
545 | 3 | if(pObj1->GetX() < pObj2->GetX()) |
546 | 3 | { |
547 | 3 | mnTypeId = AUTOLAYOUT_TEXTOBJ; // outline left, object right |
548 | 3 | } |
549 | 0 | else |
550 | 0 | { |
551 | 0 | mnTypeId = AUTOLAYOUT_TEXTOVEROBJ; // outline top, object right |
552 | 0 | } |
553 | 3 | } |
554 | 172 | } |
555 | 2 | else if( pObj1->GetName() == "chart" ) |
556 | 0 | { |
557 | 0 | mnTypeId = AUTOLAYOUT_CHARTTEXT; |
558 | 0 | } |
559 | 2 | else if( pObj1->GetName() == "graphic" ) |
560 | 0 | { |
561 | 0 | if( pObj2->GetName() == "vertical_outline" ) |
562 | 0 | { |
563 | 0 | mnTypeId = AUTOLAYOUT_TITLE_2VTEXT; |
564 | 0 | } |
565 | 0 | else |
566 | 0 | { |
567 | 0 | mnTypeId = AUTOLAYOUT_CLIPTEXT; |
568 | 0 | } |
569 | 0 | } |
570 | 2 | else if( pObj1->GetName() == "vertical_outline" ) |
571 | 0 | { |
572 | 0 | mnTypeId = AUTOLAYOUT_VTITLE_VCONTENT_OVER_VCONTENT; |
573 | 0 | } |
574 | 2 | else |
575 | 2 | { |
576 | 2 | if(pObj1->GetX() < pObj2->GetX()) |
577 | 2 | { |
578 | 2 | mnTypeId = AUTOLAYOUT_OBJTEXT; // left, right |
579 | 2 | } |
580 | 0 | else |
581 | 0 | { |
582 | 0 | mnTypeId = AUTOLAYOUT_TITLE_CONTENT_OVER_CONTENT; // top, bottom |
583 | 0 | } |
584 | 2 | } |
585 | 174 | break; |
586 | 0 | } |
587 | 0 | case 4: |
588 | 0 | { |
589 | 0 | SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get(); |
590 | 0 | SdXMLPresentationPlaceholderContext* pObj2 = maList[ 2 ].get(); |
591 | |
|
592 | 0 | if( pObj1->GetName() == "object" ) |
593 | 0 | { |
594 | 0 | if(pObj1->GetX() < pObj2->GetX()) |
595 | 0 | { |
596 | 0 | mnTypeId = AUTOLAYOUT_TITLE_2CONTENT_OVER_CONTENT; |
597 | 0 | } |
598 | 0 | else |
599 | 0 | { |
600 | 0 | mnTypeId = AUTOLAYOUT_TITLE_2CONTENT_CONTENT; |
601 | 0 | } |
602 | 0 | } |
603 | 0 | else |
604 | 0 | { |
605 | 0 | mnTypeId = AUTOLAYOUT_TITLE_CONTENT_2CONTENT; |
606 | 0 | } |
607 | 0 | break; |
608 | 0 | } |
609 | 0 | case 5: |
610 | 0 | { |
611 | 0 | SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get(); |
612 | |
|
613 | 0 | if( pObj1->GetName() == "object" ) |
614 | 0 | { |
615 | 0 | mnTypeId = AUTOLAYOUT_TITLE_4CONTENT; |
616 | 0 | } |
617 | 0 | else |
618 | 0 | { |
619 | 0 | mnTypeId = AUTOLAYOUT_4CLIPART; |
620 | 0 | } |
621 | 0 | break; |
622 | | |
623 | 0 | } |
624 | 0 | case 7: |
625 | 0 | { |
626 | 0 | mnTypeId = AUTOLAYOUT_TITLE_6CONTENT; // tdf#141978: Apply 6content layout |
627 | 0 | break; |
628 | 0 | } |
629 | 6 | default: |
630 | 6 | { |
631 | 6 | mnTypeId = AUTOLAYOUT_NONE; |
632 | 6 | break; |
633 | 0 | } |
634 | 261 | } |
635 | 261 | } |
636 | | |
637 | | // release remembered contexts, they are no longer needed |
638 | 519 | maList.clear(); |
639 | 519 | } |
640 | | |
641 | | SdXMLPresentationPlaceholderContext::SdXMLPresentationPlaceholderContext( |
642 | | SdXMLImport& rImport, |
643 | | sal_Int32 /*nElement*/, |
644 | | const uno::Reference< xml::sax::XFastAttributeList>& xAttrList) |
645 | 2.28k | : SvXMLImportContext( rImport ), |
646 | 2.28k | mnX(0) |
647 | 2.28k | { |
648 | 2.28k | for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) |
649 | 9.73k | { |
650 | 9.73k | switch(aIter.getToken()) |
651 | 9.73k | { |
652 | 2.26k | case XML_ELEMENT(PRESENTATION, XML_OBJECT): |
653 | 2.26k | { |
654 | 2.26k | msName = aIter.toString(); |
655 | 2.26k | break; |
656 | 0 | } |
657 | 0 | case XML_ELEMENT(SVG, XML_X): |
658 | 1.86k | case XML_ELEMENT(SVG_COMPAT, XML_X): |
659 | 1.86k | { |
660 | 1.86k | GetSdImport().GetMM100UnitConverter().convertMeasureToCore( |
661 | 1.86k | mnX, aIter.toView()); |
662 | 1.86k | break; |
663 | 0 | } |
664 | 0 | case XML_ELEMENT(SVG, XML_Y): |
665 | 1.86k | case XML_ELEMENT(SVG_COMPAT, XML_Y): |
666 | 1.86k | { |
667 | 1.86k | break; |
668 | 0 | } |
669 | 0 | case XML_ELEMENT(SVG, XML_WIDTH): |
670 | 1.86k | case XML_ELEMENT(SVG_COMPAT, XML_WIDTH): |
671 | 1.86k | { |
672 | 1.86k | break; |
673 | 0 | } |
674 | 0 | case XML_ELEMENT(SVG, XML_HEIGHT): |
675 | 1.86k | case XML_ELEMENT(SVG_COMPAT, XML_HEIGHT): |
676 | 1.86k | { |
677 | 1.86k | break; |
678 | 0 | } |
679 | 3 | default: |
680 | 3 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
681 | 9.73k | } |
682 | 9.73k | } |
683 | 2.28k | } |
684 | | |
685 | | SdXMLPresentationPlaceholderContext::~SdXMLPresentationPlaceholderContext() |
686 | 2.28k | { |
687 | 2.28k | } |
688 | | |
689 | | |
690 | | // Only called for handout master |
691 | | SdXMLMasterPageContext::SdXMLMasterPageContext( |
692 | | SdXMLImport& rImport, |
693 | | sal_Int32 nElement, |
694 | | const uno::Reference< xml::sax::XFastAttributeList>& xAttrList, |
695 | | uno::Reference< drawing::XShapes > const & rShapes) |
696 | 288 | : SdXMLGenericPageContext( rImport, xAttrList, rShapes ) |
697 | 288 | { |
698 | 288 | assert((nElement & TOKEN_MASK) == XML_HANDOUT_MASTER); (void)nElement; |
699 | 288 | OUString sStyleName, sPageMasterName; |
700 | | |
701 | 288 | for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) |
702 | 756 | { |
703 | 756 | const OUString sValue = aIter.toString(); |
704 | 756 | switch(aIter.getToken()) |
705 | 756 | { |
706 | 0 | case XML_ELEMENT(STYLE, XML_NAME): |
707 | 0 | { |
708 | 0 | msName = sValue; |
709 | 0 | break; |
710 | 0 | } |
711 | 0 | case XML_ELEMENT(STYLE, XML_DISPLAY_NAME): |
712 | 0 | { |
713 | 0 | msDisplayName = sValue; |
714 | 0 | break; |
715 | 0 | } |
716 | 287 | case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_NAME): |
717 | 287 | { |
718 | 287 | sPageMasterName = sValue; |
719 | 287 | break; |
720 | 0 | } |
721 | 282 | case XML_ELEMENT(DRAW, XML_STYLE_NAME): |
722 | 282 | { |
723 | 282 | sStyleName = sValue; |
724 | 282 | break; |
725 | 0 | } |
726 | 186 | case XML_ELEMENT(PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME): |
727 | 186 | { |
728 | 186 | maPageLayoutName = sValue; |
729 | 186 | break; |
730 | 0 | } |
731 | 0 | case XML_ELEMENT(PRESENTATION, XML_USE_HEADER_NAME): |
732 | 0 | { |
733 | 0 | maUseHeaderDeclName = sValue; |
734 | 0 | break; |
735 | 0 | } |
736 | 0 | case XML_ELEMENT(PRESENTATION, XML_USE_FOOTER_NAME): |
737 | 0 | { |
738 | 0 | maUseFooterDeclName = sValue; |
739 | 0 | break; |
740 | 0 | } |
741 | 0 | case XML_ELEMENT(PRESENTATION, XML_USE_DATE_TIME_NAME): |
742 | 0 | { |
743 | 0 | maUseDateTimeDeclName = sValue; |
744 | 0 | break; |
745 | 0 | } |
746 | 1 | default: |
747 | 1 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
748 | 756 | } |
749 | 756 | } |
750 | | |
751 | 288 | if( msDisplayName.isEmpty() ) |
752 | 288 | msDisplayName = msName; |
753 | 0 | else if( msDisplayName != msName ) |
754 | 0 | GetImport().AddStyleDisplayName( XmlStyleFamily::MASTER_PAGE, msName, msDisplayName ); |
755 | | |
756 | 288 | GetImport().GetShapeImport()->startPage( GetLocalShapesContext() ); |
757 | | |
758 | | // set page-master? |
759 | 288 | if(!sPageMasterName.isEmpty()) |
760 | 287 | { |
761 | 287 | SetPageMaster( sPageMasterName ); |
762 | 287 | } |
763 | | |
764 | 288 | SetStyle( sStyleName ); |
765 | | |
766 | 288 | SetLayout(); |
767 | | |
768 | 288 | DeleteAllShapes(); |
769 | 288 | } |
770 | | |
771 | | // only called for normal master pages |
772 | | SdXMLMasterPageContext::SdXMLMasterPageContext( |
773 | | SdXMLImport& rImport, |
774 | | sal_Int32 nElement, |
775 | | const uno::Reference< xml::sax::XFastAttributeList>& xAttrList, |
776 | | uno::Reference< drawing::XDrawPages2 > const & xMasterPages) |
777 | 12.7k | : SdXMLGenericPageContext( rImport, xAttrList ) |
778 | 12.7k | { |
779 | 12.7k | assert((nElement & TOKEN_MASK) != XML_HANDOUT_MASTER); (void)nElement; |
780 | 12.7k | OUString sStyleName, sPageMasterName; |
781 | | |
782 | 12.7k | for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) |
783 | 13.0k | { |
784 | 13.0k | const OUString sValue = aIter.toString(); |
785 | 13.0k | switch(aIter.getToken()) |
786 | 13.0k | { |
787 | 4.93k | case XML_ELEMENT(STYLE, XML_NAME): |
788 | 4.93k | { |
789 | 4.93k | msName = sValue; |
790 | 4.93k | break; |
791 | 0 | } |
792 | 0 | case XML_ELEMENT(STYLE, XML_DISPLAY_NAME): |
793 | 0 | { |
794 | 0 | msDisplayName = sValue; |
795 | 0 | break; |
796 | 0 | } |
797 | 2.65k | case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_NAME): |
798 | 2.65k | { |
799 | 2.65k | sPageMasterName = sValue; |
800 | 2.65k | break; |
801 | 0 | } |
802 | 5.38k | case XML_ELEMENT(DRAW, XML_STYLE_NAME): |
803 | 5.38k | { |
804 | 5.38k | sStyleName = sValue; |
805 | 5.38k | break; |
806 | 0 | } |
807 | 0 | case XML_ELEMENT(PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME): |
808 | 0 | { |
809 | 0 | maPageLayoutName = sValue; |
810 | 0 | break; |
811 | 0 | } |
812 | 0 | case XML_ELEMENT(PRESENTATION, XML_USE_HEADER_NAME): |
813 | 0 | { |
814 | 0 | maUseHeaderDeclName = sValue; |
815 | 0 | break; |
816 | 0 | } |
817 | 0 | case XML_ELEMENT(PRESENTATION, XML_USE_FOOTER_NAME): |
818 | 0 | { |
819 | 0 | maUseFooterDeclName = sValue; |
820 | 0 | break; |
821 | 0 | } |
822 | 0 | case XML_ELEMENT(PRESENTATION, XML_USE_DATE_TIME_NAME): |
823 | 0 | { |
824 | 0 | maUseDateTimeDeclName = sValue; |
825 | 0 | break; |
826 | 0 | } |
827 | 110 | default: |
828 | 110 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
829 | 13.0k | } |
830 | 13.0k | } |
831 | | |
832 | 12.7k | if( msDisplayName.isEmpty() ) |
833 | 12.7k | msDisplayName = msName; |
834 | 0 | else if( msDisplayName != msName ) |
835 | 0 | GetImport().AddStyleDisplayName( XmlStyleFamily::MASTER_PAGE, msName, msDisplayName ); |
836 | | |
837 | 12.7k | sal_Int32 nNewMasterPageCount = GetSdImport().GetNewMasterPageCount(); |
838 | 12.7k | sal_Int32 nMasterPageCount = xMasterPages->getCount(); |
839 | 12.7k | uno::Reference< drawing::XDrawPage > xNewMasterPage; |
840 | 12.7k | if (nNewMasterPageCount + 1 > nMasterPageCount) |
841 | 11.4k | { |
842 | | // new page, create and insert |
843 | 11.4k | xNewMasterPage = xMasterPages->insertNamedNewByIndex(nMasterPageCount, msDisplayName); |
844 | 11.4k | SetShapes(xNewMasterPage); |
845 | 11.4k | } |
846 | 1.27k | else |
847 | 1.27k | { |
848 | | // existing page, use it |
849 | 1.27k | xMasterPages->getByIndex(nNewMasterPageCount) >>= xNewMasterPage; |
850 | 1.27k | SetShapes(xNewMasterPage); |
851 | 1.27k | if(!msDisplayName.isEmpty()) |
852 | 935 | { |
853 | 935 | uno::Reference < container::XNamed > xNamed(xNewMasterPage, uno::UNO_QUERY); |
854 | 935 | if(xNamed.is()) |
855 | 935 | xNamed->setName(msDisplayName); |
856 | 935 | } |
857 | 1.27k | } |
858 | | // increment global import page counter |
859 | 12.7k | GetSdImport().IncrementNewMasterPageCount(); |
860 | | |
861 | 12.7k | GetImport().GetShapeImport()->startPage( GetLocalShapesContext() ); |
862 | | |
863 | | // set page-master? |
864 | 12.7k | if(!sPageMasterName.isEmpty()) |
865 | 2.65k | { |
866 | 2.65k | SetPageMaster( sPageMasterName ); |
867 | 2.65k | } |
868 | | |
869 | 12.7k | SetStyle( sStyleName ); |
870 | | |
871 | 12.7k | SetLayout(); |
872 | | |
873 | 12.7k | DeleteAllShapes(); |
874 | 12.7k | } |
875 | | |
876 | | SdXMLMasterPageContext::~SdXMLMasterPageContext() |
877 | 13.0k | { |
878 | 13.0k | } |
879 | | |
880 | | void SdXMLMasterPageContext::endFastElement(sal_Int32 nElement) |
881 | 12.8k | { |
882 | | // set styles on master-page |
883 | 12.8k | if(!msName.isEmpty() && GetSdImport().GetShapeImport()->GetStylesContext()) |
884 | 4.81k | { |
885 | 4.81k | SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetStylesContext(); |
886 | 4.81k | if (SdXMLStylesContext* pSdContext = dynamic_cast<SdXMLStylesContext*>(pContext)) |
887 | 4.81k | pSdContext->SetMasterPageStyles(*this); |
888 | 4.81k | } |
889 | | |
890 | 12.8k | SdXMLGenericPageContext::endFastElement(nElement); |
891 | 12.8k | GetImport().GetShapeImport()->endPage(GetLocalShapesContext()); |
892 | 12.8k | } |
893 | | |
894 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLMasterPageContext::createFastChildContext( |
895 | | sal_Int32 nElement, |
896 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
897 | 3.42k | { |
898 | 3.42k | switch (nElement) |
899 | 3.42k | { |
900 | | // some special objects inside style:masterpage context |
901 | 0 | case XML_ELEMENT(STYLE, XML_STYLE): |
902 | 0 | { |
903 | 0 | if(GetSdImport().GetShapeImport()->GetStylesContext()) |
904 | 0 | { |
905 | | // style:style inside master-page context -> presentation style |
906 | 0 | XMLShapeStyleContext* pNew = new XMLShapeStyleContext( |
907 | 0 | GetSdImport(), |
908 | 0 | *GetSdImport().GetShapeImport()->GetStylesContext(), |
909 | 0 | XmlStyleFamily::SD_PRESENTATION_ID); |
910 | | |
911 | | // add this style to the outer StylesContext class for later processing |
912 | 0 | GetSdImport().GetShapeImport()->GetStylesContext()->AddStyle(*pNew); |
913 | 0 | return pNew; |
914 | 0 | } |
915 | 0 | break; |
916 | 0 | } |
917 | 115 | case XML_ELEMENT(PRESENTATION, XML_NOTES): |
918 | 115 | { |
919 | 115 | if( GetSdImport().IsImpress() ) |
920 | 115 | { |
921 | | // get notes page |
922 | 115 | uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY); |
923 | 115 | if(xPresPage.is()) |
924 | 115 | { |
925 | 115 | uno::Reference< drawing::XDrawPage > xNotesDrawPage = xPresPage->getNotesPage(); |
926 | 115 | if(xNotesDrawPage.is()) |
927 | 115 | { |
928 | | // presentation:notes inside master-page context |
929 | 115 | return new SdXMLNotesContext( GetSdImport(), xAttrList, xNotesDrawPage); |
930 | 115 | } |
931 | 115 | } |
932 | 115 | } |
933 | 0 | break; |
934 | 115 | } |
935 | 0 | case XML_ELEMENT(LO_EXT, XML_THEME): |
936 | 0 | { |
937 | 0 | uno::Reference<drawing::XDrawPage> xMasterPage(GetLocalShapesContext(), uno::UNO_QUERY); |
938 | 0 | return new XMLThemeContext(GetSdImport(), xAttrList, xMasterPage); |
939 | 0 | break; |
940 | 115 | } |
941 | 3.42k | } |
942 | 3.31k | return SdXMLGenericPageContext::createFastChildContext(nElement, xAttrList); |
943 | 3.42k | } |
944 | | |
945 | | SdXMLStylesContext::SdXMLStylesContext( |
946 | | SdXMLImport& rImport, |
947 | | bool bIsAutoStyle) |
948 | 4.40k | : SvXMLStylesContext(rImport), |
949 | 4.40k | mbIsAutoStyle(bIsAutoStyle) |
950 | 4.40k | { |
951 | 4.40k | Reference< uno::XComponentContext > xContext = rImport.GetComponentContext(); |
952 | 4.40k | mpNumFormatter = std::make_unique<SvNumberFormatter>( xContext, LANGUAGE_SYSTEM ); |
953 | 4.40k | mpNumFmtHelper = std::make_unique<SvXMLNumFmtHelper>( mpNumFormatter.get() ); |
954 | 4.40k | } |
955 | | |
956 | | SvXMLStyleContext* SdXMLStylesContext::CreateStyleChildContext( |
957 | | sal_Int32 nElement, |
958 | | const uno::Reference< xml::sax::XFastAttributeList >& xAttrList) |
959 | 55.7k | { |
960 | 55.7k | switch (nElement) |
961 | 55.7k | { |
962 | 0 | case XML_ELEMENT(TABLE, XML_TABLE_TEMPLATE): |
963 | 0 | { |
964 | 0 | auto pContext = GetImport().GetShapeImport()->GetShapeTableImport()->CreateTableTemplateContext(nElement, xAttrList ); |
965 | 0 | if (pContext) |
966 | 0 | return pContext; |
967 | 0 | break; |
968 | 0 | } |
969 | 1.06k | case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT): |
970 | | // style:page-master inside office:styles context |
971 | 1.06k | return new SdXMLPageMasterContext(GetSdImport(), nElement, xAttrList); |
972 | 606 | case XML_ELEMENT(STYLE, XML_PRESENTATION_PAGE_LAYOUT): |
973 | | // style:presentation-page-layout inside office:styles context |
974 | 606 | return new SdXMLPresentationPageLayoutContext(GetSdImport(), nElement, xAttrList); |
975 | 0 | case XML_ELEMENT(NUMBER, XML_DATE_STYLE): |
976 | | // number:date-style or number:time-style |
977 | 0 | return new SdXMLNumberFormatImportContext( GetSdImport(), nElement, mpNumFmtHelper->getData(), SvXMLStylesTokens::DATE_STYLE, xAttrList, *this ); |
978 | 17 | case XML_ELEMENT(NUMBER, XML_TIME_STYLE): |
979 | | // number:date-style or number:time-style |
980 | 17 | return new SdXMLNumberFormatImportContext( GetSdImport(), nElement, mpNumFmtHelper->getData(), SvXMLStylesTokens::TIME_STYLE, xAttrList, *this ); |
981 | 39 | case XML_ELEMENT(NUMBER, XML_NUMBER_STYLE): |
982 | 39 | return new SvXMLNumFormatContext( GetSdImport(), nElement, |
983 | 39 | mpNumFmtHelper->getData(), SvXMLStylesTokens::NUMBER_STYLE, xAttrList, *this ); |
984 | 33 | case XML_ELEMENT(NUMBER, XML_CURRENCY_STYLE): |
985 | 33 | return new SvXMLNumFormatContext( GetSdImport(), nElement, |
986 | 33 | mpNumFmtHelper->getData(), SvXMLStylesTokens::CURRENCY_STYLE, xAttrList, *this ); |
987 | 0 | case XML_ELEMENT(NUMBER, XML_PERCENTAGE_STYLE): |
988 | 0 | return new SvXMLNumFormatContext( GetSdImport(), nElement, |
989 | 0 | mpNumFmtHelper->getData(), SvXMLStylesTokens::PERCENTAGE_STYLE, xAttrList, *this ); |
990 | 0 | case XML_ELEMENT(NUMBER, XML_BOOLEAN_STYLE): |
991 | 0 | return new SvXMLNumFormatContext( GetSdImport(), nElement, |
992 | 0 | mpNumFmtHelper->getData(), SvXMLStylesTokens::BOOLEAN_STYLE, xAttrList, *this ); |
993 | 0 | case XML_ELEMENT(NUMBER, XML_TEXT_STYLE): |
994 | 0 | return new SvXMLNumFormatContext( GetSdImport(), nElement, |
995 | 0 | mpNumFmtHelper->getData(), SvXMLStylesTokens::TEXT_STYLE, xAttrList, *this ); |
996 | 0 | case XML_ELEMENT(PRESENTATION, XML_HEADER_DECL): |
997 | 0 | case XML_ELEMENT(PRESENTATION, XML_FOOTER_DECL): |
998 | 0 | case XML_ELEMENT(PRESENTATION, XML_DATE_TIME_DECL): |
999 | 0 | return new SdXMLHeaderFooterDeclContext( GetImport(), xAttrList ); |
1000 | 31.0k | case XML_ELEMENT(STYLE, XML_STYLE): |
1001 | 31.0k | break; // ignore |
1002 | 23.0k | default: |
1003 | 23.0k | XMLOFF_INFO_UNKNOWN_ELEMENT("xmloff", nElement); |
1004 | 55.7k | } |
1005 | | |
1006 | | // call base class |
1007 | 54.0k | return SvXMLStylesContext::CreateStyleChildContext(nElement, xAttrList); |
1008 | 55.7k | } |
1009 | | |
1010 | | SvXMLStyleContext* SdXMLStylesContext::CreateStyleStyleChildContext( |
1011 | | XmlStyleFamily nFamily, |
1012 | | sal_Int32 nElement, |
1013 | | const uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList) |
1014 | 31.0k | { |
1015 | 31.0k | switch( nFamily ) |
1016 | 31.0k | { |
1017 | 1.21k | case XmlStyleFamily::SD_DRAWINGPAGE_ID: |
1018 | 1.21k | return new SdXMLDrawingPageStyleContext(GetSdImport(), *this ); |
1019 | 11.5k | case XmlStyleFamily::TABLE_CELL: |
1020 | 13.0k | case XmlStyleFamily::TABLE_COLUMN: |
1021 | 13.7k | case XmlStyleFamily::TABLE_ROW: |
1022 | 13.7k | return new XMLShapeStyleContext( GetSdImport(), *this, nFamily ); |
1023 | 16.0k | default: break; |
1024 | 31.0k | } |
1025 | | |
1026 | | // call base class |
1027 | 16.0k | return SvXMLStylesContext::CreateStyleStyleChildContext(nFamily, nElement, xAttrList); |
1028 | 31.0k | } |
1029 | | |
1030 | | SvXMLStyleContext* SdXMLStylesContext::CreateDefaultStyleStyleChildContext( |
1031 | | XmlStyleFamily nFamily, |
1032 | | sal_Int32 nElement, |
1033 | | const Reference< XFastAttributeList > & xAttrList ) |
1034 | 592 | { |
1035 | 592 | switch( nFamily ) |
1036 | 592 | { |
1037 | 497 | case XmlStyleFamily::SD_GRAPHICS_ID: |
1038 | 497 | return new XMLGraphicsDefaultStyle(GetSdImport(), *this ); |
1039 | 95 | default: break; |
1040 | 592 | } |
1041 | | |
1042 | | // call base class |
1043 | 95 | return SvXMLStylesContext::CreateDefaultStyleStyleChildContext(nFamily, nElement, xAttrList); |
1044 | 592 | } |
1045 | | |
1046 | | SvXMLImportPropertyMapper* SdXMLStylesContext::GetImportPropertyMapper( |
1047 | | XmlStyleFamily nFamily) const |
1048 | 196k | { |
1049 | 196k | SvXMLImportPropertyMapper* pMapper = nullptr; |
1050 | | |
1051 | 196k | switch( nFamily ) |
1052 | 196k | { |
1053 | 6.10k | case XmlStyleFamily::SD_DRAWINGPAGE_ID: |
1054 | 6.10k | { |
1055 | 6.10k | pMapper = const_cast<SvXMLImport&>(GetImport()).GetShapeImport()->GetPresPagePropsMapper(); |
1056 | 6.10k | break; |
1057 | 0 | } |
1058 | | |
1059 | 1.97k | case XmlStyleFamily::TABLE_COLUMN: |
1060 | 4.35k | case XmlStyleFamily::TABLE_ROW: |
1061 | 161k | case XmlStyleFamily::TABLE_CELL: |
1062 | 161k | { |
1063 | 161k | const rtl::Reference< XMLTableImport >& xTableImport( const_cast< SvXMLImport& >( GetImport() ).GetShapeImport()->GetShapeTableImport() ); |
1064 | | |
1065 | 161k | switch( nFamily ) |
1066 | 161k | { |
1067 | 1.97k | case XmlStyleFamily::TABLE_COLUMN: pMapper = xTableImport->GetColumnImportPropertySetMapper(); break; |
1068 | 2.38k | case XmlStyleFamily::TABLE_ROW: pMapper = xTableImport->GetRowImportPropertySetMapper(); break; |
1069 | 157k | case XmlStyleFamily::TABLE_CELL: pMapper = xTableImport->GetCellImportPropertySetMapper(); break; |
1070 | 0 | default: break; |
1071 | 161k | } |
1072 | 161k | break; |
1073 | 161k | } |
1074 | 161k | default: break; |
1075 | 196k | } |
1076 | | |
1077 | | // call base class |
1078 | 196k | if( !pMapper ) |
1079 | 28.5k | pMapper = SvXMLStylesContext::GetImportPropertyMapper(nFamily); |
1080 | 196k | return pMapper; |
1081 | 196k | } |
1082 | | |
1083 | | // Process all style and object info |
1084 | | |
1085 | | void SdXMLStylesContext::endFastElement(sal_Int32 ) |
1086 | 7.81k | { |
1087 | 7.81k | if(mbIsAutoStyle) |
1088 | 2.66k | { |
1089 | | // AutoStyles for text import |
1090 | 2.66k | GetImport().GetTextImport()->SetAutoStyles( this ); |
1091 | | |
1092 | | // AutoStyles for chart |
1093 | 2.66k | GetImport().GetChartImport()->SetAutoStylesContext( this ); |
1094 | | |
1095 | | // AutoStyles for forms |
1096 | 2.66k | GetImport().GetFormImport()->setAutoStyleContext( this ); |
1097 | | |
1098 | | // associate AutoStyles with styles in preparation to setting Styles on shapes |
1099 | 12.0k | for(sal_uInt32 a(0); a < GetStyleCount(); a++) |
1100 | 9.39k | { |
1101 | 9.39k | const SvXMLStyleContext* pStyle = GetStyle(a); |
1102 | 9.39k | if (const XMLShapeStyleContext* pDocStyle = dynamic_cast<const XMLShapeStyleContext*>(pStyle)) |
1103 | 5.87k | { |
1104 | 5.87k | SvXMLStylesContext* pStylesContext = GetSdImport().GetShapeImport()->GetStylesContext(); |
1105 | 5.87k | if (pStylesContext) |
1106 | 5.82k | { |
1107 | 5.82k | pStyle = pStylesContext->FindStyleChildContext(pStyle->GetFamily(), pStyle->GetParentName()); |
1108 | | |
1109 | 5.82k | if (const XMLShapeStyleContext* pParentStyle = dynamic_cast<const XMLShapeStyleContext*>(pStyle)) |
1110 | 598 | { |
1111 | 598 | if(pParentStyle->GetStyle().is()) |
1112 | 299 | { |
1113 | 299 | const_cast<XMLShapeStyleContext*>(pDocStyle)->SetStyle(pParentStyle->GetStyle()); |
1114 | 299 | } |
1115 | 598 | } |
1116 | 5.82k | } |
1117 | 5.87k | } |
1118 | 9.39k | } |
1119 | | |
1120 | 2.66k | FinishStyles( false ); |
1121 | 2.66k | } |
1122 | 5.15k | else |
1123 | 5.15k | { |
1124 | | // Process styles list |
1125 | 5.15k | ImpSetGraphicStyles(); |
1126 | 5.15k | ImpSetCellStyles(); |
1127 | 5.15k | GetImport().GetShapeImport()->GetShapeTableImport()->finishStyles(); |
1128 | | |
1129 | | // put style infos in the info set for other components ( content import f.e. ) |
1130 | 5.15k | uno::Reference< beans::XPropertySet > xInfoSet( GetImport().getImportInfo() ); |
1131 | 5.15k | if( xInfoSet.is() ) |
1132 | 5.15k | { |
1133 | 5.15k | uno::Reference< beans::XPropertySetInfo > xInfoSetInfo( xInfoSet->getPropertySetInfo() ); |
1134 | | |
1135 | 5.15k | if( xInfoSetInfo->hasPropertyByName(u"PageLayouts"_ustr) ) |
1136 | 0 | xInfoSet->setPropertyValue(u"PageLayouts"_ustr, uno::Any( getPageLayouts() ) ); |
1137 | 5.15k | } |
1138 | | |
1139 | 5.15k | } |
1140 | 7.81k | } |
1141 | | |
1142 | | // set master-page styles (all with family="presentation" and a special |
1143 | | // prefix) on given master-page. |
1144 | | |
1145 | | void SdXMLStylesContext::SetMasterPageStyles(SdXMLMasterPageContext const & rMaster) const |
1146 | 4.81k | { |
1147 | 4.81k | const uno::Reference<container::XNameAccess>& rStyleFamilies = |
1148 | 4.81k | GetSdImport().GetLocalDocStyleFamilies(); |
1149 | | |
1150 | 4.81k | if (!rStyleFamilies.is()) |
1151 | 0 | return; |
1152 | | |
1153 | 4.81k | if (!rStyleFamilies->hasByName(rMaster.GetDisplayName())) |
1154 | 0 | return; |
1155 | | |
1156 | 4.81k | try |
1157 | 4.81k | { |
1158 | 4.81k | uno::Reference< container::XNameAccess > xMasterPageStyles( rStyleFamilies->getByName(rMaster.GetDisplayName()), UNO_QUERY_THROW ); |
1159 | 4.81k | OUString sPrefix(rMaster.GetDisplayName() + "-"); |
1160 | 4.81k | ImpSetGraphicStyles(xMasterPageStyles, XmlStyleFamily::SD_PRESENTATION_ID, sPrefix); |
1161 | 4.81k | } |
1162 | 4.81k | catch (const uno::Exception&) |
1163 | 4.81k | { |
1164 | 0 | TOOLS_WARN_EXCEPTION("xmloff.draw", ""); |
1165 | 0 | } |
1166 | 4.81k | } |
1167 | | |
1168 | | // Process styles list: |
1169 | | // set graphic styles (all with family="graphics"). Remember xStyle at list element. |
1170 | | |
1171 | | void SdXMLStylesContext::ImpSetGraphicStyles() const |
1172 | 5.15k | { |
1173 | 5.15k | if(GetSdImport().GetLocalDocStyleFamilies().is()) try |
1174 | 5.15k | { |
1175 | 5.15k | uno::Reference< container::XNameAccess > xGraphicPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName(u"graphics"_ustr), uno::UNO_QUERY_THROW ); |
1176 | | |
1177 | 5.15k | ImpSetGraphicStyles(xGraphicPageStyles, XmlStyleFamily::SD_GRAPHICS_ID, u""_ustr); |
1178 | 5.15k | } |
1179 | 5.15k | catch( uno::Exception& ) |
1180 | 5.15k | { |
1181 | 0 | TOOLS_WARN_EXCEPTION("xmloff.draw", ""); |
1182 | 0 | } |
1183 | 5.15k | } |
1184 | | |
1185 | | void SdXMLStylesContext::ImpSetCellStyles() const |
1186 | 5.15k | { |
1187 | 5.15k | if(GetSdImport().GetLocalDocStyleFamilies().is()) try |
1188 | 5.15k | { |
1189 | 5.15k | uno::Reference< container::XNameAccess > xGraphicPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName(u"cell"_ustr), uno::UNO_QUERY_THROW ); |
1190 | | |
1191 | 5.15k | ImpSetGraphicStyles(xGraphicPageStyles, XmlStyleFamily::TABLE_CELL, u""_ustr); |
1192 | 5.15k | } |
1193 | 5.15k | catch( uno::Exception& ) |
1194 | 5.15k | { |
1195 | 0 | TOOLS_WARN_EXCEPTION("xmloff.draw", ""); |
1196 | 0 | } |
1197 | 5.15k | } |
1198 | | |
1199 | | //Resolves: fdo#34987 if the style's auto height before and after is the same |
1200 | | //then don't reset it back to the underlying default of true for the small |
1201 | | //period before it's going to be reset to false again. Doing this avoids the |
1202 | | //master page shapes from resizing themselves due to autoheight becoming |
1203 | | //enabled before having autoheight turned off again and getting stuck on that |
1204 | | //autosized height |
1205 | | static bool canSkipReset(std::u16string_view rName, const XMLPropStyleContext* pPropStyle, |
1206 | | const uno::Reference< beans::XPropertySet > &rPropSet, const rtl::Reference < XMLPropertySetMapper >& rPrMap) |
1207 | 49.6k | { |
1208 | 49.6k | bool bCanSkipReset = false; |
1209 | 49.6k | if (pPropStyle && rName == u"TextAutoGrowHeight") |
1210 | 37 | { |
1211 | 37 | bool bOldStyleTextAutoGrowHeight(false); |
1212 | 37 | rPropSet->getPropertyValue(u"TextAutoGrowHeight"_ustr) >>= bOldStyleTextAutoGrowHeight; |
1213 | | |
1214 | 37 | sal_Int32 nIndexStyle = rPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, u"auto-grow-height", 0); |
1215 | 37 | if (nIndexStyle != -1) |
1216 | 37 | { |
1217 | 37 | const ::std::vector< XMLPropertyState > &rProperties = pPropStyle->GetProperties(); |
1218 | 37 | auto property = std::find_if(rProperties.cbegin(), rProperties.cend(), |
1219 | 312 | [nIndexStyle](const XMLPropertyState& rProp) { return rProp.mnIndex == nIndexStyle; }); |
1220 | 37 | if (property != rProperties.cend()) |
1221 | 24 | { |
1222 | 24 | bool bNewStyleTextAutoGrowHeight(false); |
1223 | 24 | property->maValue >>= bNewStyleTextAutoGrowHeight; |
1224 | 24 | bCanSkipReset = (bNewStyleTextAutoGrowHeight == bOldStyleTextAutoGrowHeight); |
1225 | 24 | } |
1226 | 37 | } |
1227 | 37 | } |
1228 | 49.6k | return bCanSkipReset; |
1229 | 49.6k | } |
1230 | | |
1231 | | // help function used by ImpSetGraphicStyles() and ImpSetMasterPageStyles() |
1232 | | |
1233 | | void SdXMLStylesContext::ImpSetGraphicStyles( uno::Reference< container::XNameAccess > const & xPageStyles, XmlStyleFamily nFamily, const OUString& rPrefix) const |
1234 | 15.1k | { |
1235 | 15.1k | sal_Int32 nPrefLen(rPrefix.getLength()); |
1236 | | |
1237 | | // set defaults |
1238 | 15.1k | auto [itStart1, itEnd1] = FindStyleChildContextByDisplayNamePrefix(nFamily, u""_ustr); |
1239 | 87.3k | for (auto it = itStart1; it != itEnd1; ++it) |
1240 | 72.2k | { |
1241 | 72.2k | const SvXMLStyleContext* pStyle = *it; |
1242 | 72.2k | if(pStyle->IsDefaultStyle()) |
1243 | 286 | { |
1244 | 286 | const_cast<SvXMLStyleContext*>(pStyle)->SetDefaults(); |
1245 | 286 | } |
1246 | 72.2k | } |
1247 | | |
1248 | | // create all styles and set properties |
1249 | 15.1k | auto [itStart, itEnd] = FindStyleChildContextByDisplayNamePrefix(nFamily, rPrefix); |
1250 | 87.3k | for (auto it = itStart; it != itEnd; ++it) |
1251 | 72.2k | { |
1252 | 72.2k | const SvXMLStyleContext* pStyle = *it; |
1253 | 72.2k | try |
1254 | 72.2k | { |
1255 | 72.2k | if(!pStyle->IsDefaultStyle()) |
1256 | 71.9k | { |
1257 | 71.9k | OUString aStyleName(pStyle->GetDisplayName()); |
1258 | 71.9k | if( nPrefLen ) |
1259 | 502 | aStyleName = aStyleName.copy( nPrefLen ); |
1260 | | |
1261 | 71.9k | XMLPropStyleContext* pPropStyle = dynamic_cast< XMLPropStyleContext* >(const_cast< SvXMLStyleContext* >( pStyle ) ); |
1262 | | |
1263 | 71.9k | uno::Reference< style::XStyle > xStyle; |
1264 | 71.9k | if(xPageStyles->hasByName(aStyleName)) |
1265 | 54.8k | { |
1266 | 54.8k | xPageStyles->getByName(aStyleName) >>= xStyle; |
1267 | | |
1268 | | // set properties of existing styles to default |
1269 | 54.8k | uno::Reference< beans::XPropertySet > xPropSet( xStyle, uno::UNO_QUERY ); |
1270 | 54.8k | uno::Reference< beans::XPropertySetInfo > xPropSetInfo; |
1271 | 54.8k | if( xPropSet.is() ) |
1272 | 54.8k | xPropSetInfo = xPropSet->getPropertySetInfo(); |
1273 | | |
1274 | 54.8k | uno::Reference< beans::XPropertyState > xPropState( xStyle, uno::UNO_QUERY ); |
1275 | | |
1276 | 54.8k | if( xPropState.is() ) |
1277 | 54.8k | { |
1278 | 54.8k | rtl::Reference < XMLPropertySetMapper > xPrMap; |
1279 | 54.8k | SvXMLImportPropertyMapper* pImpPrMap = GetImportPropertyMapper( nFamily ); |
1280 | 54.8k | SAL_WARN_IF( !pImpPrMap, "xmloff", "There is the import prop mapper" ); |
1281 | 54.8k | if( pImpPrMap ) |
1282 | 54.8k | xPrMap = pImpPrMap->getPropertySetMapper(); |
1283 | 54.8k | if( xPrMap.is() ) |
1284 | 54.8k | { |
1285 | 54.8k | const sal_Int32 nCount = xPrMap->GetEntryCount(); |
1286 | 23.9M | for( sal_Int32 i = 0; i < nCount; i++ ) |
1287 | 23.9M | { |
1288 | 23.9M | const OUString& rName = xPrMap->GetEntryAPIName( i ); |
1289 | 23.9M | if( xPropSetInfo->hasPropertyByName( rName ) && beans::PropertyState_DIRECT_VALUE == xPropState->getPropertyState( rName ) ) |
1290 | 49.6k | { |
1291 | 49.6k | bool bCanSkipReset = canSkipReset(rName, pPropStyle, xPropSet, xPrMap); |
1292 | 49.6k | if (bCanSkipReset) |
1293 | 24 | continue; |
1294 | 49.6k | xPropState->setPropertyToDefault( rName ); |
1295 | 49.6k | } |
1296 | 23.9M | } |
1297 | 54.8k | } |
1298 | 54.8k | } |
1299 | 54.8k | } |
1300 | 17.0k | else |
1301 | 17.0k | { |
1302 | | // graphics style does not exist, create and add it |
1303 | 17.0k | uno::Reference< lang::XSingleServiceFactory > xServiceFact(xPageStyles, uno::UNO_QUERY); |
1304 | 17.0k | if(xServiceFact.is()) |
1305 | 17.0k | { |
1306 | 17.0k | uno::Reference< style::XStyle > xNewStyle( xServiceFact->createInstance(), uno::UNO_QUERY); |
1307 | | |
1308 | 17.0k | if(xNewStyle.is()) |
1309 | 17.0k | { |
1310 | | // remember style |
1311 | 17.0k | xStyle = std::move(xNewStyle); |
1312 | | |
1313 | | // add new style to graphics style pool |
1314 | 17.0k | uno::Reference< container::XNameContainer > xInsertContainer(xPageStyles, uno::UNO_QUERY); |
1315 | 17.0k | if(xInsertContainer.is()) |
1316 | 17.0k | xInsertContainer->insertByName(aStyleName, uno::Any( xStyle ) ); |
1317 | 17.0k | } |
1318 | 17.0k | } |
1319 | 17.0k | } |
1320 | | |
1321 | 71.9k | if(xStyle.is()) |
1322 | 57.4k | { |
1323 | | // set properties at style |
1324 | 57.4k | uno::Reference< beans::XPropertySet > xPropSet(xStyle, uno::UNO_QUERY); |
1325 | 57.4k | if(xPropSet.is() && pPropStyle) |
1326 | 57.4k | { |
1327 | 57.4k | pPropStyle->FillPropertySet(xPropSet); |
1328 | 57.4k | pPropStyle->SetStyle(xStyle); |
1329 | 57.4k | } |
1330 | 57.4k | } |
1331 | 71.9k | } |
1332 | 72.2k | } |
1333 | 72.2k | catch(const Exception& e) |
1334 | 72.2k | { |
1335 | 14.4k | const_cast<SdXMLImport*>(&GetSdImport())->SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, {}, e.Message, nullptr ); |
1336 | 14.4k | } |
1337 | 72.2k | } |
1338 | | |
1339 | | // now set parents for all styles (when necessary) |
1340 | 87.3k | for (auto it = itStart; it != itEnd; ++it) |
1341 | 72.2k | { |
1342 | 72.2k | const SvXMLStyleContext* pStyle = *it; |
1343 | | |
1344 | 72.2k | if(pStyle->GetDisplayName().isEmpty()) |
1345 | 14.7k | continue; |
1346 | 57.4k | try |
1347 | 57.4k | { |
1348 | 57.4k | OUString aStyleName(pStyle->GetDisplayName()); |
1349 | 57.4k | if( nPrefLen ) |
1350 | 502 | aStyleName = aStyleName.copy( nPrefLen ); |
1351 | | |
1352 | 57.4k | uno::Reference< style::XStyle > xStyle( xPageStyles->getByName(aStyleName), UNO_QUERY ); |
1353 | 57.4k | if(xStyle.is()) |
1354 | 57.4k | { |
1355 | | // set parent style name |
1356 | 57.4k | OUString sParentStyleDisplayName( GetImport().GetStyleDisplayName( pStyle->GetFamily(), pStyle->GetParentName() ) ); |
1357 | 57.4k | if( nPrefLen ) |
1358 | 501 | { |
1359 | 501 | sal_Int32 nStylePrefLen = sParentStyleDisplayName.lastIndexOf( '-' ) + 1; |
1360 | 501 | if( (nPrefLen != nStylePrefLen) || !sParentStyleDisplayName.startsWith( rPrefix ) ) |
1361 | 234 | continue; |
1362 | | |
1363 | 267 | sParentStyleDisplayName = sParentStyleDisplayName.copy( nPrefLen ); |
1364 | 267 | } |
1365 | 57.2k | if (xStyle->getParentStyle() != sParentStyleDisplayName) |
1366 | 41.9k | xStyle->setParentStyle( sParentStyleDisplayName ); |
1367 | 57.2k | } |
1368 | 57.4k | } |
1369 | 57.4k | catch( const Exception& e ) |
1370 | 57.4k | { |
1371 | 34.0k | const_cast<SdXMLImport*>(&GetSdImport())->SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, {}, e.Message, nullptr ); |
1372 | 34.0k | } |
1373 | 57.4k | } |
1374 | 15.1k | } |
1375 | | |
1376 | | // helper function to create the uno component that hold the mappings from |
1377 | | // xml auto layout name to internal autolayout id |
1378 | | |
1379 | | uno::Reference< container::XNameAccess > SdXMLStylesContext::getPageLayouts() const |
1380 | 0 | { |
1381 | 0 | uno::Reference< container::XNameContainer > xLayouts( comphelper::NameContainer_createInstance( ::cppu::UnoType<sal_Int32>::get()) ); |
1382 | |
|
1383 | 0 | for(sal_uInt32 a(0); a < GetStyleCount(); a++) |
1384 | 0 | { |
1385 | 0 | const SvXMLStyleContext* pStyle = GetStyle(a); |
1386 | 0 | if (const SdXMLPresentationPageLayoutContext* pContext = dynamic_cast<const SdXMLPresentationPageLayoutContext*>(pStyle)) |
1387 | 0 | { |
1388 | 0 | xLayouts->insertByName(pStyle->GetName(), uno::Any(static_cast<sal_Int32>(pContext->GetTypeId()))); |
1389 | 0 | } |
1390 | 0 | } |
1391 | |
|
1392 | 0 | return xLayouts; |
1393 | 0 | } |
1394 | | |
1395 | | |
1396 | | SdXMLMasterStylesContext::SdXMLMasterStylesContext( |
1397 | | SdXMLImport& rImport) |
1398 | 1.61k | : SvXMLImportContext( rImport ) |
1399 | 1.61k | { |
1400 | 1.61k | } |
1401 | | |
1402 | | css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLMasterStylesContext::createFastChildContext( |
1403 | | sal_Int32 nElement, |
1404 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) |
1405 | 18.3k | { |
1406 | 18.3k | if( nElement == XML_ELEMENT(DRAW, XML_LAYER_SET) ) |
1407 | 303 | { |
1408 | 303 | return new SdXMLLayerSetContext( GetImport() ); |
1409 | 303 | } |
1410 | 18.0k | else if( nElement == XML_ELEMENT(STYLE, XML_MASTER_PAGE) ) |
1411 | 17.5k | { |
1412 | | // style:masterpage inside office:styles context |
1413 | 17.5k | uno::Reference< drawing::XDrawPages2 > xMasterPages(GetSdImport().GetLocalMasterPages()); |
1414 | | |
1415 | 17.5k | if( xMasterPages.is() ) |
1416 | 17.5k | { |
1417 | 17.5k | sal_Int32 nMasterPageCount = xMasterPages->getCount(); |
1418 | | // arbitrary limit to master pages when fuzzing to avoid deadend timeouts |
1419 | 17.5k | if (nMasterPageCount >= 64 && comphelper::IsFuzzing()) |
1420 | 110 | return nullptr; |
1421 | | |
1422 | | // new page, create and insert |
1423 | | |
1424 | 17.4k | if(GetSdImport().GetShapeImport()->GetStylesContext()) |
1425 | 12.7k | { |
1426 | 12.7k | const rtl::Reference<SdXMLMasterPageContext> xLclContext{ |
1427 | 12.7k | new SdXMLMasterPageContext(GetSdImport(), |
1428 | 12.7k | nElement, xAttrList, xMasterPages)}; |
1429 | 12.7k | maMasterPageList.push_back(xLclContext); |
1430 | 12.7k | return xLclContext; |
1431 | 12.7k | } |
1432 | 17.4k | } |
1433 | 17.5k | } |
1434 | 425 | else if( nElement == XML_ELEMENT(STYLE, XML_HANDOUT_MASTER) ) |
1435 | 289 | { |
1436 | 289 | uno::Reference< presentation::XHandoutMasterSupplier > xHandoutSupp( GetSdImport().GetModel(), uno::UNO_QUERY ); |
1437 | 289 | if( xHandoutSupp.is() ) |
1438 | 289 | { |
1439 | 289 | uno::Reference< drawing::XShapes > xHandoutPage = xHandoutSupp->getHandoutMasterPage(); |
1440 | 289 | if(xHandoutPage.is() && GetSdImport().GetShapeImport()->GetStylesContext()) |
1441 | 288 | { |
1442 | 288 | return new SdXMLMasterPageContext(GetSdImport(), |
1443 | 288 | nElement, xAttrList, xHandoutPage); |
1444 | 288 | } |
1445 | 289 | } |
1446 | 289 | } |
1447 | 136 | else |
1448 | 4.87k | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); |
1449 | 4.87k | return nullptr; |
1450 | 18.3k | } |
1451 | | |
1452 | | SdXMLHeaderFooterDeclContext::SdXMLHeaderFooterDeclContext(SvXMLImport& rImport, |
1453 | | const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList) |
1454 | 124 | : SvXMLStyleContext( rImport ) |
1455 | 124 | , mbFixed(false) |
1456 | 124 | { |
1457 | 124 | for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) |
1458 | 179 | { |
1459 | 179 | if( aIter.getToken() == XML_ELEMENT(PRESENTATION, XML_NAME) ) |
1460 | 118 | { |
1461 | 118 | maStrName = aIter.toString(); |
1462 | 118 | } |
1463 | 61 | else if( aIter.getToken() == XML_ELEMENT(PRESENTATION, XML_SOURCE) ) |
1464 | 61 | { |
1465 | 61 | mbFixed = IsXMLToken( aIter, XML_FIXED ); |
1466 | 61 | } |
1467 | 0 | else if( aIter.getToken() == XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME) ) |
1468 | 0 | { |
1469 | 0 | maStrDateTimeFormat = aIter.toString(); |
1470 | 0 | } |
1471 | 0 | else |
1472 | 0 | { |
1473 | 0 | XMLOFF_WARN_UNKNOWN("xmloff", aIter); |
1474 | 0 | } |
1475 | 179 | } |
1476 | 124 | } |
1477 | | |
1478 | | bool SdXMLHeaderFooterDeclContext::IsTransient() const |
1479 | 0 | { |
1480 | 0 | return true; |
1481 | 0 | } |
1482 | | |
1483 | | void SdXMLHeaderFooterDeclContext::endFastElement(sal_Int32 nToken) |
1484 | 122 | { |
1485 | 122 | SdXMLImport& rImport = dynamic_cast<SdXMLImport&>(GetImport()); |
1486 | 122 | auto nElement = nToken & TOKEN_MASK; |
1487 | 122 | if( nElement == XML_HEADER_DECL ) |
1488 | 0 | { |
1489 | 0 | rImport.AddHeaderDecl( maStrName, maStrText ); |
1490 | 0 | } |
1491 | 122 | else if( nElement == XML_FOOTER_DECL ) |
1492 | 63 | { |
1493 | 63 | rImport.AddFooterDecl( maStrName, maStrText ); |
1494 | 63 | } |
1495 | 59 | else if( nElement == XML_DATE_TIME_DECL ) |
1496 | 59 | { |
1497 | 59 | rImport.AddDateTimeDecl( maStrName, maStrText, mbFixed, maStrDateTimeFormat ); |
1498 | 59 | } |
1499 | 0 | else |
1500 | 0 | { |
1501 | 0 | XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nToken); |
1502 | 0 | } |
1503 | 122 | } |
1504 | | |
1505 | | void SdXMLHeaderFooterDeclContext::characters( const OUString& rChars ) |
1506 | 121 | { |
1507 | 121 | maStrText += rChars; |
1508 | 121 | } |
1509 | | |
1510 | | namespace xmloff { |
1511 | | |
1512 | | bool IsIgnoreFillStyleNamedItem( |
1513 | | css::uno::Reference<css::beans::XPropertySet> const& xProps, |
1514 | | drawing::FillStyle const nExpectedFillStyle) |
1515 | 400 | { |
1516 | 400 | assert(xProps.is()); |
1517 | 400 | if (nExpectedFillStyle == drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE) |
1518 | 400 | { |
1519 | 400 | return false; |
1520 | 400 | } |
1521 | | |
1522 | | // note: the caller must have called FillPropertySet() previously |
1523 | 0 | drawing::FillStyle fillStyle{drawing::FillStyle_NONE}; |
1524 | 0 | xProps->getPropertyValue(u"FillStyle"_ustr) >>= fillStyle; |
1525 | 0 | return fillStyle != nExpectedFillStyle; |
1526 | 400 | } |
1527 | | |
1528 | | } // namespace xmloff |
1529 | | |
1530 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |