Bump version to 24.04.3.4
[LibreOffice.git] / xmloff / source / draw / ximpstyl.cxx
blob8e685447641e35e8ef60143aa4fd34cfa25aee65
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ximpstyl.hxx"
21 #include <utility>
22 #include <xmloff/maptype.hxx>
23 #include <xmloff/XMLDrawingPageStyleContext.hxx>
24 #include <xmloff/XMLShapeStyleContext.hxx>
25 #include <xmloff/xmlnamespace.hxx>
26 #include <xmloff/xmlprmap.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <xmloff/xmluconv.hxx>
29 #include "ximpnote.hxx"
30 #include <xmlsdtypes.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 <com/sun/star/util/Color.hpp>
45 #include <comphelper/namecontainer.hxx>
46 #include <xmloff/autolayout.hxx>
47 #include <xmloff/xmlprcon.hxx>
48 #include <xmloff/families.hxx>
49 #include <com/sun/star/container/XNameContainer.hpp>
50 #include <svl/numformat.hxx>
51 #include <svl/zforlist.hxx>
52 #include "layerimp.hxx"
53 #include <xmloff/XMLGraphicsDefaultStyle.hxx>
54 #include <XMLNumberStylesImport.hxx>
55 #include <XMLThemeContext.hxx>
56 #include <unotools/configmgr.hxx>
57 #include <xmloff/xmlerror.hxx>
58 #include <xmloff/table/XMLTableImport.hxx>
59 #include <comphelper/sequenceashashmap.hxx>
60 #include <sax/tools/converter.hxx>
61 #include <comphelper/sequence.hxx>
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::uno;
65 using namespace ::com::sun::star::xml::sax;
66 using namespace ::xmloff::token;
68 namespace {
70 class SdXMLDrawingPagePropertySetContext : public SvXMLPropertySetContext
72 public:
74 SdXMLDrawingPagePropertySetContext( SvXMLImport& rImport, sal_Int32 nElement,
75 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
76 ::std::vector< XMLPropertyState > &rProps,
77 const rtl::Reference < SvXMLImportPropertyMapper > &rMap );
79 using SvXMLPropertySetContext::createFastChildContext;
80 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > createFastChildContext(
81 sal_Int32 nElement,
82 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
83 ::std::vector< XMLPropertyState > &rProperties,
84 const XMLPropertyState& rProp ) override;
86 } // end anonymous namespace
88 SdXMLDrawingPagePropertySetContext::SdXMLDrawingPagePropertySetContext(
89 SvXMLImport& rImport, sal_Int32 nElement,
90 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList,
91 ::std::vector< XMLPropertyState > &rProps,
92 const rtl::Reference < SvXMLImportPropertyMapper > &rMap ) :
93 SvXMLPropertySetContext( rImport, nElement, xAttrList,
94 XML_TYPE_PROP_DRAWING_PAGE, rProps, rMap )
98 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLDrawingPagePropertySetContext::createFastChildContext(
99 sal_Int32 nElement,
100 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
101 ::std::vector< XMLPropertyState > &rProperties,
102 const XMLPropertyState& rProp )
104 switch( mxMapper->getPropertySetMapper()->GetEntryContextId( rProp.mnIndex ) )
106 case CTF_PAGE_SOUND_URL:
108 for (auto &aIter : sax_fastparser::castToFastAttributeList(xAttrList))
110 if( aIter.getToken() == XML_ELEMENT(XLINK, XML_HREF) )
112 uno::Any aAny( GetImport().GetAbsoluteReference( aIter.toString() ) );
113 XMLPropertyState aPropState( rProp.mnIndex, aAny );
114 rProperties.push_back( aPropState );
116 else
117 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
119 break;
123 return SvXMLPropertySetContext::createFastChildContext( nElement,
124 xAttrList,
125 rProperties, rProp );
128 namespace {
131 class SdXMLDrawingPageStyleContext : public XMLDrawingPageStyleContext
133 public:
135 SdXMLDrawingPageStyleContext(
136 SvXMLImport& rImport,
137 SvXMLStylesContext& rStyles);
139 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
140 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
142 virtual void Finish( bool bOverwrite ) override;
145 const sal_uInt16 MAX_SPECIAL_DRAW_STYLES = 7;
146 ContextID_Index_Pair const g_ContextIDs[MAX_SPECIAL_DRAW_STYLES+1] =
148 { CTF_DASHNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE },
149 { CTF_LINESTARTNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE },
150 { CTF_LINEENDNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE },
151 { CTF_FILLGRADIENTNAME, -1, drawing::FillStyle::FillStyle_GRADIENT},
152 { CTF_FILLTRANSNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE },
153 { CTF_FILLHATCHNAME, -1, drawing::FillStyle::FillStyle_HATCH },
154 { CTF_FILLBITMAPNAME, -1, drawing::FillStyle::FillStyle_BITMAP },
155 { -1, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }
157 XmlStyleFamily const g_Families[MAX_SPECIAL_DRAW_STYLES] =
159 XmlStyleFamily::SD_STROKE_DASH_ID,
160 XmlStyleFamily::SD_MARKER_ID,
161 XmlStyleFamily::SD_MARKER_ID,
162 XmlStyleFamily::SD_GRADIENT_ID,
163 XmlStyleFamily::SD_GRADIENT_ID,
164 XmlStyleFamily::SD_HATCH_ID,
165 XmlStyleFamily::SD_FILL_IMAGE_ID
170 XMLDrawingPageStyleContext::XMLDrawingPageStyleContext(
171 SvXMLImport& rImport,
172 SvXMLStylesContext& rStyles,
173 ContextID_Index_Pair const pContextIDs[],
174 XmlStyleFamily const pFamilies[])
175 : XMLPropStyleContext(rImport, rStyles, XmlStyleFamily::SD_DRAWINGPAGE_ID)
176 , m_pFamilies(pFamilies)
178 size_t size(1); // for the -1 entry
179 for (ContextID_Index_Pair const* pTemp(pContextIDs); pTemp->nContextID != -1; ++size, ++pTemp);
180 m_pContextIDs.reset(new ContextID_Index_Pair[size]);
181 std::memcpy(m_pContextIDs.get(), pContextIDs, size * sizeof(ContextID_Index_Pair));
184 SdXMLDrawingPageStyleContext::SdXMLDrawingPageStyleContext(
185 SvXMLImport& rImport,
186 SvXMLStylesContext& rStyles)
187 : XMLDrawingPageStyleContext(rImport, rStyles, g_ContextIDs, g_Families)
191 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLDrawingPageStyleContext::createFastChildContext(
192 sal_Int32 nElement,
193 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
195 if( nElement == XML_ELEMENT(STYLE, XML_DRAWING_PAGE_PROPERTIES) )
197 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
198 GetStyles()->GetImportPropertyMapper( GetFamily() );
199 if( xImpPrMap.is() )
200 return new SdXMLDrawingPagePropertySetContext( GetImport(), nElement,
201 xAttrList,
202 GetProperties(),
203 xImpPrMap );
206 return XMLPropStyleContext::createFastChildContext( nElement, xAttrList );
209 void SdXMLDrawingPageStyleContext::Finish( bool bOverwrite )
211 XMLPropStyleContext::Finish( bOverwrite );
213 ::std::vector< XMLPropertyState > &rProperties = GetProperties();
215 const rtl::Reference< XMLPropertySetMapper >& rImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper();
217 for(auto& property : rProperties)
219 if( property.mnIndex == -1 )
220 continue;
222 sal_Int16 nContextID = rImpPrMap->GetEntryContextId(property.mnIndex);
223 switch( nContextID )
225 case CTF_DATE_TIME_FORMAT:
227 OUString sStyleName;
228 property.maValue >>= sStyleName;
230 sal_Int32 nStyle = 0;
232 const SdXMLNumberFormatImportContext* pSdNumStyle =
233 dynamic_cast< const SdXMLNumberFormatImportContext*> (
234 GetStyles()->FindStyleChildContext( XmlStyleFamily::DATA_STYLE, sStyleName, true ) );
236 if( pSdNumStyle )
237 nStyle = pSdNumStyle->GetDrawKey();
239 property.maValue <<= nStyle;
241 break;
248 // #i35918#
249 void XMLDrawingPageStyleContext::FillPropertySet(
250 const Reference< beans::XPropertySet > & rPropSet )
252 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
253 GetStyles()->GetImportPropertyMapper( GetFamily() );
254 SAL_WARN_IF( !xImpPrMap.is(), "xmloff", "There is the import prop mapper" );
255 if( xImpPrMap.is() )
256 xImpPrMap->FillPropertySet(GetProperties(), rPropSet, m_pContextIDs.get());
258 Reference< beans::XPropertySetInfo > xInfo;
259 for (size_t i=0; m_pContextIDs[i].nContextID != -1; ++i)
261 sal_Int32 nIndex = m_pContextIDs[i].nIndex;
262 if( nIndex != -1 )
264 struct XMLPropertyState& rState = GetProperties()[nIndex];
265 OUString sStyleName;
266 rState.maValue >>= sStyleName;
268 if (::xmloff::IsIgnoreFillStyleNamedItem(rPropSet, m_pContextIDs[i].nExpectedFillStyle))
270 SAL_INFO("xmloff.style", "XMLDrawingPageStyleContext: dropping fill named item: " << sStyleName);
271 break; // ignore it, it's not used
274 sStyleName = GetImport().GetStyleDisplayName( m_pFamilies[i],
275 sStyleName );
276 // get property set mapper
277 rtl::Reference<XMLPropertySetMapper> rPropMapper =
278 xImpPrMap->getPropertySetMapper();
280 // set property
281 const OUString& rPropertyName =
282 rPropMapper->GetEntryAPIName(rState.mnIndex);
283 if( !xInfo.is() )
284 xInfo = rPropSet->getPropertySetInfo();
285 if ( xInfo->hasPropertyByName( rPropertyName ) )
287 rPropSet->setPropertyValue( rPropertyName, Any( sStyleName ) );
294 SdXMLPageMasterStyleContext::SdXMLPageMasterStyleContext(
295 SdXMLImport& rImport,
296 sal_Int32 /*nElement*/,
297 const uno::Reference< xml::sax::XFastAttributeList>& xAttrList)
298 : SvXMLStyleContext(rImport, XmlStyleFamily::SD_PAGEMASTERSTYLECONTEXT_ID),
299 mnBorderBottom( 0 ),
300 mnBorderLeft( 0 ),
301 mnBorderRight( 0 ),
302 mnBorderTop( 0 ),
303 mnWidth( 0 ),
304 mnHeight( 0 ),
305 meOrientation(GetSdImport().IsDraw() ? view::PaperOrientation_PORTRAIT : view::PaperOrientation_LANDSCAPE)
307 // set family to something special at SvXMLStyleContext
308 // for differences in search-methods
310 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
312 switch(aIter.getToken())
314 case XML_ELEMENT(FO, XML_MARGIN_TOP):
315 case XML_ELEMENT(FO_COMPAT, XML_MARGIN_TOP):
317 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
318 mnBorderTop, aIter.toView());
319 break;
321 case XML_ELEMENT(FO, XML_MARGIN_BOTTOM):
322 case XML_ELEMENT(FO_COMPAT, XML_MARGIN_BOTTOM):
324 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
325 mnBorderBottom, aIter.toView());
326 break;
328 case XML_ELEMENT(FO, XML_MARGIN_LEFT):
329 case XML_ELEMENT(FO_COMPAT, XML_MARGIN_LEFT):
331 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
332 mnBorderLeft, aIter.toView());
333 break;
335 case XML_ELEMENT(FO, XML_MARGIN_RIGHT):
336 case XML_ELEMENT(FO_COMPAT, XML_MARGIN_RIGHT):
338 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
339 mnBorderRight, aIter.toView());
340 break;
342 case XML_ELEMENT(FO, XML_PAGE_WIDTH):
343 case XML_ELEMENT(FO_COMPAT, XML_PAGE_WIDTH):
345 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
346 mnWidth, aIter.toView());
347 break;
349 case XML_ELEMENT(FO, XML_PAGE_HEIGHT):
350 case XML_ELEMENT(FO_COMPAT, XML_PAGE_HEIGHT):
352 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
353 mnHeight, aIter.toView());
354 break;
356 case XML_ELEMENT(STYLE, XML_PRINT_ORIENTATION):
358 if( IsXMLToken( aIter, XML_PORTRAIT ) )
359 meOrientation = view::PaperOrientation_PORTRAIT;
360 else
361 meOrientation = view::PaperOrientation_LANDSCAPE;
362 break;
364 default:
365 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
370 SdXMLPageMasterStyleContext::~SdXMLPageMasterStyleContext()
375 SdXMLPageMasterContext::SdXMLPageMasterContext(
376 SdXMLImport& rImport,
377 sal_Int32 /*nElement*/,
378 const uno::Reference< xml::sax::XFastAttributeList>& /*xAttrList*/)
379 : SvXMLStyleContext(rImport, XmlStyleFamily::SD_PAGEMASTERCONTEXT_ID)
381 // set family to something special at SvXMLStyleContext
382 // for differences in search-methods
386 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLPageMasterContext::createFastChildContext(
387 sal_Int32 nElement,
388 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
390 if(nElement == XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_PROPERTIES))
392 DBG_ASSERT(!mxPageMasterStyle.is(), "PageMasterStyle is set, there seem to be two of them (!)");
393 mxPageMasterStyle.set(new SdXMLPageMasterStyleContext(GetSdImport(), nElement, xAttrList));
394 return mxPageMasterStyle;
396 else
397 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
399 return nullptr;
402 SdXMLPresentationPageLayoutContext::SdXMLPresentationPageLayoutContext(
403 SdXMLImport& rImport,
404 sal_Int32 /*nElement*/,
405 const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/)
406 : SvXMLStyleContext(rImport, XmlStyleFamily::SD_PRESENTATIONPAGELAYOUT_ID),
407 mnTypeId( AUTOLAYOUT_NONE )
409 // set family to something special at SvXMLStyleContext
410 // for differences in search-methods
413 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLPresentationPageLayoutContext::createFastChildContext(
414 sal_Int32 nElement,
415 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
417 SvXMLImportContextRef xContext;
419 if(nElement == XML_ELEMENT(PRESENTATION, XML_PLACEHOLDER))
421 const rtl::Reference< SdXMLPresentationPlaceholderContext > xLclContext{
422 new SdXMLPresentationPlaceholderContext(GetSdImport(), nElement, xAttrList)};
423 // presentation:placeholder inside style:presentation-page-layout context
424 xContext = xLclContext.get();
426 // remember SdXMLPresentationPlaceholderContext for later evaluation
427 maList.push_back(xLclContext);
429 else
430 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
432 return xContext;
435 void SdXMLPresentationPageLayoutContext::endFastElement(sal_Int32 )
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 if( maList.empty() )
441 return;
443 SdXMLPresentationPlaceholderContext* pObj0 = maList[ 0 ].get();
444 if( pObj0->GetName() == "handout" )
446 switch( maList.size() )
448 case 1:
449 mnTypeId = AUTOLAYOUT_HANDOUT1;
450 break;
451 case 2:
452 mnTypeId = AUTOLAYOUT_HANDOUT2;
453 break;
454 case 3:
455 mnTypeId = AUTOLAYOUT_HANDOUT3;
456 break;
457 case 4:
458 mnTypeId = AUTOLAYOUT_HANDOUT4;
459 break;
460 case 9:
461 mnTypeId = AUTOLAYOUT_HANDOUT9;
462 break;
463 default:
464 mnTypeId = AUTOLAYOUT_HANDOUT6;
467 else
469 switch( maList.size() )
471 case 1:
473 if( pObj0->GetName() == "title" )
475 mnTypeId = AUTOLAYOUT_TITLE_ONLY;
477 else
479 mnTypeId = AUTOLAYOUT_ONLY_TEXT;
481 break;
483 case 2:
485 SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get();
487 if( pObj1->GetName() == "subtitle" )
489 mnTypeId = AUTOLAYOUT_TITLE;
491 else if( pObj1->GetName() == "outline" )
493 mnTypeId = AUTOLAYOUT_TITLE_CONTENT;
495 else if( pObj1->GetName() == "chart" )
497 mnTypeId = AUTOLAYOUT_CHART;
499 else if( pObj1->GetName() == "table" )
501 mnTypeId = AUTOLAYOUT_TAB;
503 else if( pObj1->GetName() == "object" )
505 mnTypeId = AUTOLAYOUT_OBJ;
507 else if( pObj1->GetName() == "vertical_outline" )
509 if( pObj0->GetName() == "vertical_title" )
511 mnTypeId = AUTOLAYOUT_VTITLE_VCONTENT;
513 else
515 mnTypeId = AUTOLAYOUT_TITLE_VCONTENT;
518 else
520 mnTypeId = AUTOLAYOUT_NOTES;
522 break;
524 case 3:
526 SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get();
527 SdXMLPresentationPlaceholderContext* pObj2 = maList[ 2 ].get();
529 if( pObj1->GetName() == "outline" )
531 if( pObj2->GetName() == "outline" )
533 mnTypeId = AUTOLAYOUT_TITLE_2CONTENT;
535 else if( pObj2->GetName() == "chart" )
537 mnTypeId = AUTOLAYOUT_TEXTCHART;
539 else if( pObj2->GetName() == "graphic" )
541 mnTypeId = AUTOLAYOUT_TEXTCLIP;
543 else
545 if(pObj1->GetX() < pObj2->GetX())
547 mnTypeId = AUTOLAYOUT_TEXTOBJ; // outline left, object right
549 else
551 mnTypeId = AUTOLAYOUT_TEXTOVEROBJ; // outline top, object right
555 else if( pObj1->GetName() == "chart" )
557 mnTypeId = AUTOLAYOUT_CHARTTEXT;
559 else if( pObj1->GetName() == "graphic" )
561 if( pObj2->GetName() == "vertical_outline" )
563 mnTypeId = AUTOLAYOUT_TITLE_2VTEXT;
565 else
567 mnTypeId = AUTOLAYOUT_CLIPTEXT;
570 else if( pObj1->GetName() == "vertical_outline" )
572 mnTypeId = AUTOLAYOUT_VTITLE_VCONTENT_OVER_VCONTENT;
574 else
576 if(pObj1->GetX() < pObj2->GetX())
578 mnTypeId = AUTOLAYOUT_OBJTEXT; // left, right
580 else
582 mnTypeId = AUTOLAYOUT_TITLE_CONTENT_OVER_CONTENT; // top, bottom
585 break;
587 case 4:
589 SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get();
590 SdXMLPresentationPlaceholderContext* pObj2 = maList[ 2 ].get();
592 if( pObj1->GetName() == "object" )
594 if(pObj1->GetX() < pObj2->GetX())
596 mnTypeId = AUTOLAYOUT_TITLE_2CONTENT_OVER_CONTENT;
598 else
600 mnTypeId = AUTOLAYOUT_TITLE_2CONTENT_CONTENT;
603 else
605 mnTypeId = AUTOLAYOUT_TITLE_CONTENT_2CONTENT;
607 break;
609 case 5:
611 SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get();
613 if( pObj1->GetName() == "object" )
615 mnTypeId = AUTOLAYOUT_TITLE_4CONTENT;
617 else
619 mnTypeId = AUTOLAYOUT_4CLIPART;
621 break;
624 case 7:
626 mnTypeId = AUTOLAYOUT_TITLE_6CONTENT; // tdf#141978: Apply 6content layout
627 break;
629 default:
631 mnTypeId = AUTOLAYOUT_NONE;
632 break;
637 // release remembered contexts, they are no longer needed
638 maList.clear();
641 SdXMLPresentationPlaceholderContext::SdXMLPresentationPlaceholderContext(
642 SdXMLImport& rImport,
643 sal_Int32 /*nElement*/,
644 const uno::Reference< xml::sax::XFastAttributeList>& xAttrList)
645 : SvXMLImportContext( rImport ),
646 mnX(0)
648 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
650 switch(aIter.getToken())
652 case XML_ELEMENT(PRESENTATION, XML_OBJECT):
654 msName = aIter.toString();
655 break;
657 case XML_ELEMENT(SVG, XML_X):
658 case XML_ELEMENT(SVG_COMPAT, XML_X):
660 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
661 mnX, aIter.toView());
662 break;
664 case XML_ELEMENT(SVG, XML_Y):
665 case XML_ELEMENT(SVG_COMPAT, XML_Y):
667 break;
669 case XML_ELEMENT(SVG, XML_WIDTH):
670 case XML_ELEMENT(SVG_COMPAT, XML_WIDTH):
672 break;
674 case XML_ELEMENT(SVG, XML_HEIGHT):
675 case XML_ELEMENT(SVG_COMPAT, XML_HEIGHT):
677 break;
679 default:
680 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
685 SdXMLPresentationPlaceholderContext::~SdXMLPresentationPlaceholderContext()
690 SdXMLMasterPageContext::SdXMLMasterPageContext(
691 SdXMLImport& rImport,
692 sal_Int32 nElement,
693 const uno::Reference< xml::sax::XFastAttributeList>& xAttrList,
694 uno::Reference< drawing::XShapes > const & rShapes)
695 : SdXMLGenericPageContext( rImport, xAttrList, rShapes )
697 const bool bHandoutMaster = (nElement & TOKEN_MASK) == XML_HANDOUT_MASTER;
698 OUString sStyleName, sPageMasterName;
700 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
702 const OUString sValue = aIter.toString();
703 switch(aIter.getToken())
705 case XML_ELEMENT(STYLE, XML_NAME):
707 msName = sValue;
708 break;
710 case XML_ELEMENT(STYLE, XML_DISPLAY_NAME):
712 msDisplayName = sValue;
713 break;
715 case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_NAME):
717 sPageMasterName = sValue;
718 break;
720 case XML_ELEMENT(DRAW, XML_STYLE_NAME):
722 sStyleName = sValue;
723 break;
725 case XML_ELEMENT(PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME):
727 maPageLayoutName = sValue;
728 break;
730 case XML_ELEMENT(PRESENTATION, XML_USE_HEADER_NAME):
732 maUseHeaderDeclName = sValue;
733 break;
735 case XML_ELEMENT(PRESENTATION, XML_USE_FOOTER_NAME):
737 maUseFooterDeclName = sValue;
738 break;
740 case XML_ELEMENT(PRESENTATION, XML_USE_DATE_TIME_NAME):
742 maUseDateTimeDeclName = sValue;
743 break;
745 default:
746 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
750 if( msDisplayName.isEmpty() )
751 msDisplayName = msName;
752 else if( msDisplayName != msName )
753 GetImport().AddStyleDisplayName( XmlStyleFamily::MASTER_PAGE, msName, msDisplayName );
755 GetImport().GetShapeImport()->startPage( GetLocalShapesContext() );
757 // set page name?
758 if(!bHandoutMaster && !msDisplayName.isEmpty() && GetLocalShapesContext().is())
760 uno::Reference < container::XNamed > xNamed(GetLocalShapesContext(), uno::UNO_QUERY);
761 if(xNamed.is())
762 xNamed->setName(msDisplayName);
765 // set page-master?
766 if(!sPageMasterName.isEmpty())
768 SetPageMaster( sPageMasterName );
771 SetStyle( sStyleName );
773 SetLayout();
775 DeleteAllShapes();
778 SdXMLMasterPageContext::~SdXMLMasterPageContext()
782 void SdXMLMasterPageContext::endFastElement(sal_Int32 nElement)
784 // set styles on master-page
785 if(!msName.isEmpty() && GetSdImport().GetShapeImport()->GetStylesContext())
787 SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetStylesContext();
788 if (SdXMLStylesContext* pSdContext = dynamic_cast<SdXMLStylesContext*>(pContext))
789 pSdContext->SetMasterPageStyles(*this);
792 SdXMLGenericPageContext::endFastElement(nElement);
793 GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
796 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLMasterPageContext::createFastChildContext(
797 sal_Int32 nElement,
798 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
800 switch (nElement)
802 // some special objects inside style:masterpage context
803 case XML_ELEMENT(STYLE, XML_STYLE):
805 if(GetSdImport().GetShapeImport()->GetStylesContext())
807 // style:style inside master-page context -> presentation style
808 XMLShapeStyleContext* pNew = new XMLShapeStyleContext(
809 GetSdImport(),
810 *GetSdImport().GetShapeImport()->GetStylesContext(),
811 XmlStyleFamily::SD_PRESENTATION_ID);
813 // add this style to the outer StylesContext class for later processing
814 GetSdImport().GetShapeImport()->GetStylesContext()->AddStyle(*pNew);
815 return pNew;
817 break;
819 case XML_ELEMENT(PRESENTATION, XML_NOTES):
821 if( GetSdImport().IsImpress() )
823 // get notes page
824 uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
825 if(xPresPage.is())
827 uno::Reference< drawing::XDrawPage > xNotesDrawPage = xPresPage->getNotesPage();
828 if(xNotesDrawPage.is())
830 // presentation:notes inside master-page context
831 return new SdXMLNotesContext( GetSdImport(), xAttrList, xNotesDrawPage);
835 break;
837 case XML_ELEMENT(LO_EXT, XML_THEME):
839 uno::Reference<drawing::XDrawPage> xMasterPage(GetLocalShapesContext(), uno::UNO_QUERY);
840 return new XMLThemeContext(GetSdImport(), xAttrList, xMasterPage);
841 break;
844 return SdXMLGenericPageContext::createFastChildContext(nElement, xAttrList);
847 SdXMLStylesContext::SdXMLStylesContext(
848 SdXMLImport& rImport,
849 bool bIsAutoStyle)
850 : SvXMLStylesContext(rImport),
851 mbIsAutoStyle(bIsAutoStyle)
853 Reference< uno::XComponentContext > xContext = rImport.GetComponentContext();
854 mpNumFormatter = std::make_unique<SvNumberFormatter>( xContext, LANGUAGE_SYSTEM );
855 mpNumFmtHelper = std::make_unique<SvXMLNumFmtHelper>( mpNumFormatter.get(), xContext );
858 SvXMLStyleContext* SdXMLStylesContext::CreateStyleChildContext(
859 sal_Int32 nElement,
860 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
862 switch (nElement)
864 case XML_ELEMENT(TABLE, XML_TABLE_TEMPLATE):
866 auto pContext = GetImport().GetShapeImport()->GetShapeTableImport()->CreateTableTemplateContext(nElement, xAttrList );
867 if (pContext)
868 return pContext;
869 break;
871 case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT):
872 // style:page-master inside office:styles context
873 return new SdXMLPageMasterContext(GetSdImport(), nElement, xAttrList);
874 case XML_ELEMENT(STYLE, XML_PRESENTATION_PAGE_LAYOUT):
875 // style:presentation-page-layout inside office:styles context
876 return new SdXMLPresentationPageLayoutContext(GetSdImport(), nElement, xAttrList);
877 case XML_ELEMENT(NUMBER, XML_DATE_STYLE):
878 // number:date-style or number:time-style
879 return new SdXMLNumberFormatImportContext( GetSdImport(), nElement, mpNumFmtHelper->getData(), SvXMLStylesTokens::DATE_STYLE, xAttrList, *this );
880 case XML_ELEMENT(NUMBER, XML_TIME_STYLE):
881 // number:date-style or number:time-style
882 return new SdXMLNumberFormatImportContext( GetSdImport(), nElement, mpNumFmtHelper->getData(), SvXMLStylesTokens::TIME_STYLE, xAttrList, *this );
883 case XML_ELEMENT(NUMBER, XML_NUMBER_STYLE):
884 return new SvXMLNumFormatContext( GetSdImport(), nElement,
885 mpNumFmtHelper->getData(), SvXMLStylesTokens::NUMBER_STYLE, xAttrList, *this );
886 case XML_ELEMENT(NUMBER, XML_CURRENCY_STYLE):
887 return new SvXMLNumFormatContext( GetSdImport(), nElement,
888 mpNumFmtHelper->getData(), SvXMLStylesTokens::CURRENCY_STYLE, xAttrList, *this );
889 case XML_ELEMENT(NUMBER, XML_PERCENTAGE_STYLE):
890 return new SvXMLNumFormatContext( GetSdImport(), nElement,
891 mpNumFmtHelper->getData(), SvXMLStylesTokens::PERCENTAGE_STYLE, xAttrList, *this );
892 case XML_ELEMENT(NUMBER, XML_BOOLEAN_STYLE):
893 return new SvXMLNumFormatContext( GetSdImport(), nElement,
894 mpNumFmtHelper->getData(), SvXMLStylesTokens::BOOLEAN_STYLE, xAttrList, *this );
895 case XML_ELEMENT(NUMBER, XML_TEXT_STYLE):
896 return new SvXMLNumFormatContext( GetSdImport(), nElement,
897 mpNumFmtHelper->getData(), SvXMLStylesTokens::TEXT_STYLE, xAttrList, *this );
898 case XML_ELEMENT(PRESENTATION, XML_HEADER_DECL):
899 case XML_ELEMENT(PRESENTATION, XML_FOOTER_DECL):
900 case XML_ELEMENT(PRESENTATION, XML_DATE_TIME_DECL):
901 return new SdXMLHeaderFooterDeclContext( GetImport(), xAttrList );
902 case XML_ELEMENT(STYLE, XML_STYLE):
903 break; // ignore
904 default:
905 XMLOFF_INFO_UNKNOWN_ELEMENT("xmloff", nElement);
908 // call base class
909 return SvXMLStylesContext::CreateStyleChildContext(nElement, xAttrList);
912 SvXMLStyleContext* SdXMLStylesContext::CreateStyleStyleChildContext(
913 XmlStyleFamily nFamily,
914 sal_Int32 nElement,
915 const uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
917 switch( nFamily )
919 case XmlStyleFamily::SD_DRAWINGPAGE_ID:
920 return new SdXMLDrawingPageStyleContext(GetSdImport(), *this );
921 case XmlStyleFamily::TABLE_CELL:
922 case XmlStyleFamily::TABLE_COLUMN:
923 case XmlStyleFamily::TABLE_ROW:
924 return new XMLShapeStyleContext( GetSdImport(), *this, nFamily );
925 default: break;
928 // call base class
929 return SvXMLStylesContext::CreateStyleStyleChildContext(nFamily, nElement, xAttrList);
932 SvXMLStyleContext* SdXMLStylesContext::CreateDefaultStyleStyleChildContext(
933 XmlStyleFamily nFamily,
934 sal_Int32 nElement,
935 const Reference< XFastAttributeList > & xAttrList )
937 switch( nFamily )
939 case XmlStyleFamily::SD_GRAPHICS_ID:
940 return new XMLGraphicsDefaultStyle(GetSdImport(), *this );
941 default: break;
944 // call base class
945 return SvXMLStylesContext::CreateDefaultStyleStyleChildContext(nFamily, nElement, xAttrList);
948 rtl::Reference< SvXMLImportPropertyMapper > SdXMLStylesContext::GetImportPropertyMapper(
949 XmlStyleFamily nFamily) const
951 rtl::Reference < SvXMLImportPropertyMapper > xMapper;
953 switch( nFamily )
955 case XmlStyleFamily::SD_DRAWINGPAGE_ID:
957 if(!xPresImpPropMapper.is())
959 rtl::Reference< XMLShapeImportHelper > aImpHelper = const_cast<SvXMLImport&>(GetImport()).GetShapeImport();
960 const_cast<SdXMLStylesContext*>(this)->xPresImpPropMapper =
961 aImpHelper->GetPresPagePropsMapper();
963 xMapper = xPresImpPropMapper;
964 break;
967 case XmlStyleFamily::TABLE_COLUMN:
968 case XmlStyleFamily::TABLE_ROW:
969 case XmlStyleFamily::TABLE_CELL:
971 const rtl::Reference< XMLTableImport >& xTableImport( const_cast< SvXMLImport& >( GetImport() ).GetShapeImport()->GetShapeTableImport() );
973 switch( nFamily )
975 case XmlStyleFamily::TABLE_COLUMN: xMapper = xTableImport->GetColumnImportPropertySetMapper().get(); break;
976 case XmlStyleFamily::TABLE_ROW: xMapper = xTableImport->GetRowImportPropertySetMapper().get(); break;
977 case XmlStyleFamily::TABLE_CELL: xMapper = xTableImport->GetCellImportPropertySetMapper().get(); break;
978 default: break;
980 break;
982 default: break;
985 // call base class
986 if( !xMapper.is() )
987 xMapper = SvXMLStylesContext::GetImportPropertyMapper(nFamily);
988 return xMapper;
991 // Process all style and object info
993 void SdXMLStylesContext::endFastElement(sal_Int32 )
995 if(mbIsAutoStyle)
997 // AutoStyles for text import
998 GetImport().GetTextImport()->SetAutoStyles( this );
1000 // AutoStyles for chart
1001 GetImport().GetChartImport()->SetAutoStylesContext( this );
1003 // AutoStyles for forms
1004 GetImport().GetFormImport()->setAutoStyleContext( this );
1006 // associate AutoStyles with styles in preparation to setting Styles on shapes
1007 for(sal_uInt32 a(0); a < GetStyleCount(); a++)
1009 const SvXMLStyleContext* pStyle = GetStyle(a);
1010 if (const XMLShapeStyleContext* pDocStyle = dynamic_cast<const XMLShapeStyleContext*>(pStyle))
1012 SvXMLStylesContext* pStylesContext = GetSdImport().GetShapeImport()->GetStylesContext();
1013 if (pStylesContext)
1015 pStyle = pStylesContext->FindStyleChildContext(pStyle->GetFamily(), pStyle->GetParentName());
1017 if (const XMLShapeStyleContext* pParentStyle = dynamic_cast<const XMLShapeStyleContext*>(pStyle))
1019 if(pParentStyle->GetStyle().is())
1021 const_cast<XMLShapeStyleContext*>(pDocStyle)->SetStyle(pParentStyle->GetStyle());
1028 FinishStyles( false );
1030 else
1032 // Process styles list
1033 ImpSetGraphicStyles();
1034 ImpSetCellStyles();
1035 GetImport().GetShapeImport()->GetShapeTableImport()->finishStyles();
1037 // put style infos in the info set for other components ( content import f.e. )
1038 uno::Reference< beans::XPropertySet > xInfoSet( GetImport().getImportInfo() );
1039 if( xInfoSet.is() )
1041 uno::Reference< beans::XPropertySetInfo > xInfoSetInfo( xInfoSet->getPropertySetInfo() );
1043 if( xInfoSetInfo->hasPropertyByName("PageLayouts") )
1044 xInfoSet->setPropertyValue("PageLayouts", uno::Any( getPageLayouts() ) );
1050 // set master-page styles (all with family="presentation" and a special
1051 // prefix) on given master-page.
1053 void SdXMLStylesContext::SetMasterPageStyles(SdXMLMasterPageContext const & rMaster) const
1055 const uno::Reference<container::XNameAccess>& rStyleFamilies =
1056 GetSdImport().GetLocalDocStyleFamilies();
1058 if (!rStyleFamilies.is())
1059 return;
1061 if (!rStyleFamilies->hasByName(rMaster.GetDisplayName()))
1062 return;
1066 uno::Reference< container::XNameAccess > xMasterPageStyles( rStyleFamilies->getByName(rMaster.GetDisplayName()), UNO_QUERY_THROW );
1067 OUString sPrefix(rMaster.GetDisplayName() + "-");
1068 ImpSetGraphicStyles(xMasterPageStyles, XmlStyleFamily::SD_PRESENTATION_ID, sPrefix);
1070 catch (const uno::Exception&)
1072 TOOLS_WARN_EXCEPTION("xmloff.draw", "");
1076 // Process styles list:
1077 // set graphic styles (all with family="graphics"). Remember xStyle at list element.
1079 void SdXMLStylesContext::ImpSetGraphicStyles() const
1081 if(GetSdImport().GetLocalDocStyleFamilies().is()) try
1083 uno::Reference< container::XNameAccess > xGraphicPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName("graphics"), uno::UNO_QUERY_THROW );
1085 ImpSetGraphicStyles(xGraphicPageStyles, XmlStyleFamily::SD_GRAPHICS_ID, u"");
1087 catch( uno::Exception& )
1089 TOOLS_WARN_EXCEPTION("xmloff.draw", "");
1093 void SdXMLStylesContext::ImpSetCellStyles() const
1095 if(GetSdImport().GetLocalDocStyleFamilies().is()) try
1097 uno::Reference< container::XNameAccess > xGraphicPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName("cell"), uno::UNO_QUERY_THROW );
1099 ImpSetGraphicStyles(xGraphicPageStyles, XmlStyleFamily::TABLE_CELL, u"");
1101 catch( uno::Exception& )
1103 TOOLS_WARN_EXCEPTION("xmloff.draw", "");
1107 //Resolves: fdo#34987 if the style's auto height before and after is the same
1108 //then don't reset it back to the underlying default of true for the small
1109 //period before it's going to be reset to false again. Doing this avoids the
1110 //master page shapes from resizing themselves due to autoheight becoming
1111 //enabled before having autoheight turned off again and getting stuck on that
1112 //autosized height
1113 static bool canSkipReset(std::u16string_view rName, const XMLPropStyleContext* pPropStyle,
1114 const uno::Reference< beans::XPropertySet > &rPropSet, const rtl::Reference < XMLPropertySetMapper >& rPrMap)
1116 bool bCanSkipReset = false;
1117 if (pPropStyle && rName == u"TextAutoGrowHeight")
1119 bool bOldStyleTextAutoGrowHeight(false);
1120 rPropSet->getPropertyValue("TextAutoGrowHeight") >>= bOldStyleTextAutoGrowHeight;
1122 sal_Int32 nIndexStyle = rPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, u"auto-grow-height", 0);
1123 if (nIndexStyle != -1)
1125 const ::std::vector< XMLPropertyState > &rProperties = pPropStyle->GetProperties();
1126 auto property = std::find_if(rProperties.cbegin(), rProperties.cend(),
1127 [nIndexStyle](const XMLPropertyState& rProp) { return rProp.mnIndex == nIndexStyle; });
1128 if (property != rProperties.cend())
1130 bool bNewStyleTextAutoGrowHeight(false);
1131 property->maValue >>= bNewStyleTextAutoGrowHeight;
1132 bCanSkipReset = (bNewStyleTextAutoGrowHeight == bOldStyleTextAutoGrowHeight);
1136 return bCanSkipReset;
1139 // help function used by ImpSetGraphicStyles() and ImpSetMasterPageStyles()
1141 void SdXMLStylesContext::ImpSetGraphicStyles( uno::Reference< container::XNameAccess > const & xPageStyles, XmlStyleFamily nFamily, std::u16string_view rPrefix) const
1143 sal_Int32 nPrefLen(rPrefix.size());
1145 sal_uInt32 a;
1147 // set defaults
1148 for( a = 0; a < GetStyleCount(); a++)
1150 const SvXMLStyleContext* pStyle = GetStyle(a);
1152 if(nFamily == pStyle->GetFamily() && pStyle->IsDefaultStyle())
1154 const_cast<SvXMLStyleContext*>(pStyle)->SetDefaults();
1158 // create all styles and set properties
1159 for( a = 0; a < GetStyleCount(); a++)
1163 const SvXMLStyleContext* pStyle = GetStyle(a);
1164 if(nFamily == pStyle->GetFamily() && !pStyle->IsDefaultStyle())
1166 OUString aStyleName(pStyle->GetDisplayName());
1168 if( nPrefLen )
1170 sal_Int32 nStylePrefLen = aStyleName.lastIndexOf( '-' ) + 1;
1171 if( (nPrefLen != nStylePrefLen) || !aStyleName.startsWith(rPrefix) )
1172 continue;
1174 aStyleName = aStyleName.copy( nPrefLen );
1177 XMLPropStyleContext* pPropStyle = dynamic_cast< XMLPropStyleContext* >(const_cast< SvXMLStyleContext* >( pStyle ) );
1179 uno::Reference< style::XStyle > xStyle;
1180 if(xPageStyles->hasByName(aStyleName))
1182 xPageStyles->getByName(aStyleName) >>= xStyle;
1184 // set properties of existing styles to default
1185 uno::Reference< beans::XPropertySet > xPropSet( xStyle, uno::UNO_QUERY );
1186 uno::Reference< beans::XPropertySetInfo > xPropSetInfo;
1187 if( xPropSet.is() )
1188 xPropSetInfo = xPropSet->getPropertySetInfo();
1190 uno::Reference< beans::XPropertyState > xPropState( xStyle, uno::UNO_QUERY );
1192 if( xPropState.is() )
1194 rtl::Reference < XMLPropertySetMapper > xPrMap;
1195 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetImportPropertyMapper( nFamily );
1196 SAL_WARN_IF( !xImpPrMap.is(), "xmloff", "There is the import prop mapper" );
1197 if( xImpPrMap.is() )
1198 xPrMap = xImpPrMap->getPropertySetMapper();
1199 if( xPrMap.is() )
1201 const sal_Int32 nCount = xPrMap->GetEntryCount();
1202 for( sal_Int32 i = 0; i < nCount; i++ )
1204 const OUString& rName = xPrMap->GetEntryAPIName( i );
1205 if( xPropSetInfo->hasPropertyByName( rName ) && beans::PropertyState_DIRECT_VALUE == xPropState->getPropertyState( rName ) )
1207 bool bCanSkipReset = canSkipReset(rName, pPropStyle, xPropSet, xPrMap);
1208 if (bCanSkipReset)
1209 continue;
1210 xPropState->setPropertyToDefault( rName );
1216 else
1218 // graphics style does not exist, create and add it
1219 uno::Reference< lang::XSingleServiceFactory > xServiceFact(xPageStyles, uno::UNO_QUERY);
1220 if(xServiceFact.is())
1222 uno::Reference< style::XStyle > xNewStyle( xServiceFact->createInstance(), uno::UNO_QUERY);
1224 if(xNewStyle.is())
1226 // remember style
1227 xStyle = xNewStyle;
1229 // add new style to graphics style pool
1230 uno::Reference< container::XNameContainer > xInsertContainer(xPageStyles, uno::UNO_QUERY);
1231 if(xInsertContainer.is())
1232 xInsertContainer->insertByName(aStyleName, uno::Any( xStyle ) );
1237 if(xStyle.is())
1239 // set properties at style
1240 uno::Reference< beans::XPropertySet > xPropSet(xStyle, uno::UNO_QUERY);
1241 if(xPropSet.is() && pPropStyle)
1243 pPropStyle->FillPropertySet(xPropSet);
1244 pPropStyle->SetStyle(xStyle);
1249 catch(const Exception& e)
1251 const_cast<SdXMLImport*>(&GetSdImport())->SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, {}, e.Message, nullptr );
1255 // now set parents for all styles (when necessary)
1256 for(a = 0; a < GetStyleCount(); a++)
1258 const SvXMLStyleContext* pStyle = GetStyle(a);
1260 if(pStyle && !pStyle->GetDisplayName().isEmpty() && (nFamily == pStyle->GetFamily())) try
1262 OUString aStyleName(pStyle->GetDisplayName());
1263 if( nPrefLen )
1265 sal_Int32 nStylePrefLen = aStyleName.lastIndexOf( '-' ) + 1;
1266 if( (nPrefLen != nStylePrefLen) || !aStyleName.startsWith( rPrefix ) )
1267 continue;
1269 aStyleName = aStyleName.copy( nPrefLen );
1272 uno::Reference< style::XStyle > xStyle( xPageStyles->getByName(aStyleName), UNO_QUERY );
1273 if(xStyle.is())
1275 // set parent style name
1276 OUString sParentStyleDisplayName( GetImport().GetStyleDisplayName( pStyle->GetFamily(), pStyle->GetParentName() ) );
1277 if( nPrefLen )
1279 sal_Int32 nStylePrefLen = sParentStyleDisplayName.lastIndexOf( '-' ) + 1;
1280 if( (nPrefLen != nStylePrefLen) || !sParentStyleDisplayName.startsWith( rPrefix ) )
1281 continue;
1283 sParentStyleDisplayName = sParentStyleDisplayName.copy( nPrefLen );
1285 xStyle->setParentStyle( sParentStyleDisplayName );
1288 catch( const Exception& e )
1290 const_cast<SdXMLImport*>(&GetSdImport())->SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, {}, e.Message, nullptr );
1295 // helper function to create the uno component that hold the mappings from
1296 // xml auto layout name to internal autolayout id
1298 uno::Reference< container::XNameAccess > SdXMLStylesContext::getPageLayouts() const
1300 uno::Reference< container::XNameContainer > xLayouts( comphelper::NameContainer_createInstance( ::cppu::UnoType<sal_Int32>::get()) );
1302 for(sal_uInt32 a(0); a < GetStyleCount(); a++)
1304 const SvXMLStyleContext* pStyle = GetStyle(a);
1305 if (const SdXMLPresentationPageLayoutContext* pContext = dynamic_cast<const SdXMLPresentationPageLayoutContext*>(pStyle))
1307 xLayouts->insertByName(pStyle->GetName(), uno::Any(static_cast<sal_Int32>(pContext->GetTypeId())));
1311 return xLayouts;
1315 SdXMLMasterStylesContext::SdXMLMasterStylesContext(
1316 SdXMLImport& rImport)
1317 : SvXMLImportContext( rImport )
1321 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLMasterStylesContext::createFastChildContext(
1322 sal_Int32 nElement,
1323 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
1325 if( nElement == XML_ELEMENT(DRAW, XML_LAYER_SET) )
1327 return new SdXMLLayerSetContext( GetImport() );
1329 else if( nElement == XML_ELEMENT(STYLE, XML_MASTER_PAGE) )
1331 // style:masterpage inside office:styles context
1332 uno::Reference< drawing::XDrawPage > xNewMasterPage;
1333 uno::Reference< drawing::XDrawPages > xMasterPages(GetSdImport().GetLocalMasterPages(), uno::UNO_QUERY);
1335 if( xMasterPages.is() )
1337 sal_Int32 nNewMasterPageCount = GetSdImport().GetNewMasterPageCount();
1338 sal_Int32 nMasterPageCount = xMasterPages->getCount();
1339 if (nNewMasterPageCount + 1 > nMasterPageCount)
1341 // arbitrary limit to master pages when fuzzing to avoid deadend timeouts
1342 if (nMasterPageCount >= 64 && utl::ConfigManager::IsFuzzing())
1343 return nullptr;
1345 // new page, create and insert
1346 xNewMasterPage = xMasterPages->insertNewByIndex(nMasterPageCount);
1348 else
1350 // existing page, use it
1351 xMasterPages->getByIndex(nNewMasterPageCount) >>= xNewMasterPage;
1354 // increment global import page counter
1355 GetSdImport().IncrementNewMasterPageCount();
1357 if(xNewMasterPage.is())
1359 if(GetSdImport().GetShapeImport()->GetStylesContext())
1361 const rtl::Reference<SdXMLMasterPageContext> xLclContext{
1362 new SdXMLMasterPageContext(GetSdImport(),
1363 nElement, xAttrList, xNewMasterPage)};
1364 maMasterPageList.push_back(xLclContext);
1365 return xLclContext;
1370 else if( nElement == XML_ELEMENT(STYLE, XML_HANDOUT_MASTER) )
1372 uno::Reference< presentation::XHandoutMasterSupplier > xHandoutSupp( GetSdImport().GetModel(), uno::UNO_QUERY );
1373 if( xHandoutSupp.is() )
1375 uno::Reference< drawing::XShapes > xHandoutPage = xHandoutSupp->getHandoutMasterPage();
1376 if(xHandoutPage.is() && GetSdImport().GetShapeImport()->GetStylesContext())
1378 return new SdXMLMasterPageContext(GetSdImport(),
1379 nElement, xAttrList, xHandoutPage);
1383 else
1384 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
1385 return nullptr;
1388 SdXMLHeaderFooterDeclContext::SdXMLHeaderFooterDeclContext(SvXMLImport& rImport,
1389 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
1390 : SvXMLStyleContext( rImport )
1391 , mbFixed(false)
1393 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
1395 if( aIter.getToken() == XML_ELEMENT(PRESENTATION, XML_NAME) )
1397 maStrName = aIter.toString();
1399 else if( aIter.getToken() == XML_ELEMENT(PRESENTATION, XML_SOURCE) )
1401 mbFixed = IsXMLToken( aIter, XML_FIXED );
1403 else if( aIter.getToken() == XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME) )
1405 maStrDateTimeFormat = aIter.toString();
1407 else
1409 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
1414 bool SdXMLHeaderFooterDeclContext::IsTransient() const
1416 return true;
1419 void SdXMLHeaderFooterDeclContext::endFastElement(sal_Int32 nToken)
1421 SdXMLImport& rImport = dynamic_cast<SdXMLImport&>(GetImport());
1422 auto nElement = nToken & TOKEN_MASK;
1423 if( nElement == XML_HEADER_DECL )
1425 rImport.AddHeaderDecl( maStrName, maStrText );
1427 else if( nElement == XML_FOOTER_DECL )
1429 rImport.AddFooterDecl( maStrName, maStrText );
1431 else if( nElement == XML_DATE_TIME_DECL )
1433 rImport.AddDateTimeDecl( maStrName, maStrText, mbFixed, maStrDateTimeFormat );
1435 else
1437 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nToken);
1441 void SdXMLHeaderFooterDeclContext::characters( const OUString& rChars )
1443 maStrText += rChars;
1446 namespace xmloff {
1448 bool IsIgnoreFillStyleNamedItem(
1449 css::uno::Reference<css::beans::XPropertySet> const& xProps,
1450 drawing::FillStyle const nExpectedFillStyle)
1452 assert(xProps.is());
1453 if (nExpectedFillStyle == drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE)
1455 return false;
1458 // note: the caller must have called FillPropertySet() previously
1459 drawing::FillStyle fillStyle{drawing::FillStyle_NONE};
1460 xProps->getPropertyValue("FillStyle") >>= fillStyle;
1461 return fillStyle != nExpectedFillStyle;
1464 } // namespace xmloff
1466 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */