tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / draw / ximpstyl.cxx
blob28beb4dff118f715445e1840f8e8a988632202af
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 <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/debug.hxx>
31 #include <sal/log.hxx>
32 #include <comphelper/diagnose_ex.hxx>
33 #include <com/sun/star/frame/XModel.hpp>
34 #include <com/sun/star/style/XStyle.hpp>
35 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
36 #include <com/sun/star/presentation/XPresentationPage.hpp>
37 #include <com/sun/star/drawing/FillStyle.hpp>
38 #include <com/sun/star/drawing/XDrawPages.hpp>
39 #include <com/sun/star/container/XNamed.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/beans/XPropertyState.hpp>
42 #include <com/sun/star/presentation/XHandoutMasterSupplier.hpp>
43 #include <comphelper/namecontainer.hxx>
44 #include <xmloff/autolayout.hxx>
45 #include <xmloff/xmlprcon.hxx>
46 #include <xmloff/families.hxx>
47 #include <com/sun/star/container/XNameContainer.hpp>
48 #include <svl/numformat.hxx>
49 #include "layerimp.hxx"
50 #include <xmloff/XMLGraphicsDefaultStyle.hxx>
51 #include <XMLNumberStylesImport.hxx>
52 #include <XMLThemeContext.hxx>
53 #include <comphelper/configuration.hxx>
54 #include <xmloff/xmlerror.hxx>
55 #include <xmloff/table/XMLTableImport.hxx>
57 using namespace ::com::sun::star;
58 using namespace ::com::sun::star::uno;
59 using namespace ::com::sun::star::xml::sax;
60 using namespace ::xmloff::token;
62 namespace {
64 class SdXMLDrawingPagePropertySetContext : public SvXMLPropertySetContext
66 public:
68 SdXMLDrawingPagePropertySetContext( SvXMLImport& rImport, sal_Int32 nElement,
69 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
70 ::std::vector< XMLPropertyState > &rProps,
71 const rtl::Reference < SvXMLImportPropertyMapper > &rMap );
73 using SvXMLPropertySetContext::createFastChildContext;
74 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > createFastChildContext(
75 sal_Int32 nElement,
76 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
77 ::std::vector< XMLPropertyState > &rProperties,
78 const XMLPropertyState& rProp ) override;
80 } // end anonymous namespace
82 SdXMLDrawingPagePropertySetContext::SdXMLDrawingPagePropertySetContext(
83 SvXMLImport& rImport, sal_Int32 nElement,
84 const uno::Reference< xml::sax::XFastAttributeList > & xAttrList,
85 ::std::vector< XMLPropertyState > &rProps,
86 const rtl::Reference < SvXMLImportPropertyMapper > &rMap ) :
87 SvXMLPropertySetContext( rImport, nElement, xAttrList,
88 XML_TYPE_PROP_DRAWING_PAGE, rProps, rMap )
92 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLDrawingPagePropertySetContext::createFastChildContext(
93 sal_Int32 nElement,
94 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList,
95 ::std::vector< XMLPropertyState > &rProperties,
96 const XMLPropertyState& rProp )
98 switch( mxMapper->getPropertySetMapper()->GetEntryContextId( rProp.mnIndex ) )
100 case CTF_PAGE_SOUND_URL:
102 for (auto &aIter : sax_fastparser::castToFastAttributeList(xAttrList))
104 if( aIter.getToken() == XML_ELEMENT(XLINK, XML_HREF) )
106 uno::Any aAny( GetImport().GetAbsoluteReference( aIter.toString() ) );
107 XMLPropertyState aPropState( rProp.mnIndex, aAny );
108 rProperties.push_back( aPropState );
110 else
111 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
113 break;
117 return SvXMLPropertySetContext::createFastChildContext( nElement,
118 xAttrList,
119 rProperties, rProp );
122 namespace {
125 class SdXMLDrawingPageStyleContext : public XMLDrawingPageStyleContext
127 public:
129 SdXMLDrawingPageStyleContext(
130 SvXMLImport& rImport,
131 SvXMLStylesContext& rStyles);
133 virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(
134 sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override;
136 virtual void Finish( bool bOverwrite ) override;
139 const sal_uInt16 MAX_SPECIAL_DRAW_STYLES = 7;
140 ContextID_Index_Pair const g_ContextIDs[MAX_SPECIAL_DRAW_STYLES+1] =
142 { CTF_DASHNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE },
143 { CTF_LINESTARTNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE },
144 { CTF_LINEENDNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE },
145 { CTF_FILLGRADIENTNAME, -1, drawing::FillStyle::FillStyle_GRADIENT},
146 { CTF_FILLTRANSNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE },
147 { CTF_FILLHATCHNAME, -1, drawing::FillStyle::FillStyle_HATCH },
148 { CTF_FILLBITMAPNAME, -1, drawing::FillStyle::FillStyle_BITMAP },
149 { -1, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }
151 XmlStyleFamily const g_Families[MAX_SPECIAL_DRAW_STYLES] =
153 XmlStyleFamily::SD_STROKE_DASH_ID,
154 XmlStyleFamily::SD_MARKER_ID,
155 XmlStyleFamily::SD_MARKER_ID,
156 XmlStyleFamily::SD_GRADIENT_ID,
157 XmlStyleFamily::SD_GRADIENT_ID,
158 XmlStyleFamily::SD_HATCH_ID,
159 XmlStyleFamily::SD_FILL_IMAGE_ID
164 XMLDrawingPageStyleContext::XMLDrawingPageStyleContext(
165 SvXMLImport& rImport,
166 SvXMLStylesContext& rStyles,
167 ContextID_Index_Pair const pContextIDs[],
168 XmlStyleFamily const pFamilies[])
169 : XMLPropStyleContext(rImport, rStyles, XmlStyleFamily::SD_DRAWINGPAGE_ID)
170 , m_pFamilies(pFamilies)
172 size_t size(1); // for the -1 entry
173 for (ContextID_Index_Pair const* pTemp(pContextIDs); pTemp->nContextID != -1; ++size, ++pTemp);
174 m_pContextIDs.reset(new ContextID_Index_Pair[size]);
175 std::memcpy(m_pContextIDs.get(), pContextIDs, size * sizeof(ContextID_Index_Pair));
178 SdXMLDrawingPageStyleContext::SdXMLDrawingPageStyleContext(
179 SvXMLImport& rImport,
180 SvXMLStylesContext& rStyles)
181 : XMLDrawingPageStyleContext(rImport, rStyles, g_ContextIDs, g_Families)
185 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLDrawingPageStyleContext::createFastChildContext(
186 sal_Int32 nElement,
187 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
189 if( nElement == XML_ELEMENT(STYLE, XML_DRAWING_PAGE_PROPERTIES) )
191 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
192 GetStyles()->GetImportPropertyMapper( GetFamily() );
193 if( xImpPrMap.is() )
194 return new SdXMLDrawingPagePropertySetContext( GetImport(), nElement,
195 xAttrList,
196 GetProperties(),
197 xImpPrMap );
200 return XMLPropStyleContext::createFastChildContext( nElement, xAttrList );
203 void SdXMLDrawingPageStyleContext::Finish( bool bOverwrite )
205 XMLPropStyleContext::Finish( bOverwrite );
207 ::std::vector< XMLPropertyState > &rProperties = GetProperties();
209 const rtl::Reference< XMLPropertySetMapper >& rImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper();
211 for(auto& property : rProperties)
213 if( property.mnIndex == -1 )
214 continue;
216 sal_Int16 nContextID = rImpPrMap->GetEntryContextId(property.mnIndex);
217 switch( nContextID )
219 case CTF_DATE_TIME_FORMAT:
221 OUString sStyleName;
222 property.maValue >>= sStyleName;
224 sal_Int32 nStyle = 0;
226 const SdXMLNumberFormatImportContext* pSdNumStyle =
227 dynamic_cast< const SdXMLNumberFormatImportContext*> (
228 GetStyles()->FindStyleChildContext( XmlStyleFamily::DATA_STYLE, sStyleName, true ) );
230 if( pSdNumStyle )
231 nStyle = pSdNumStyle->GetDrawKey();
233 property.maValue <<= nStyle;
235 break;
242 // #i35918#
243 void XMLDrawingPageStyleContext::FillPropertySet(
244 const Reference< beans::XPropertySet > & rPropSet )
246 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
247 GetStyles()->GetImportPropertyMapper( GetFamily() );
248 SAL_WARN_IF( !xImpPrMap.is(), "xmloff", "There is the import prop mapper" );
249 if( xImpPrMap.is() )
250 xImpPrMap->FillPropertySet(GetProperties(), rPropSet, m_pContextIDs.get());
252 Reference< beans::XPropertySetInfo > xInfo;
253 for (size_t i=0; m_pContextIDs[i].nContextID != -1; ++i)
255 sal_Int32 nIndex = m_pContextIDs[i].nIndex;
256 if( nIndex != -1 )
258 struct XMLPropertyState& rState = GetProperties()[nIndex];
259 OUString sStyleName;
260 rState.maValue >>= sStyleName;
262 if (::xmloff::IsIgnoreFillStyleNamedItem(rPropSet, m_pContextIDs[i].nExpectedFillStyle))
264 SAL_INFO("xmloff.style", "XMLDrawingPageStyleContext: dropping fill named item: " << sStyleName);
265 break; // ignore it, it's not used
268 sStyleName = GetImport().GetStyleDisplayName( m_pFamilies[i],
269 sStyleName );
270 // get property set mapper
271 rtl::Reference<XMLPropertySetMapper> rPropMapper =
272 xImpPrMap->getPropertySetMapper();
274 // set property
275 const OUString& rPropertyName =
276 rPropMapper->GetEntryAPIName(rState.mnIndex);
277 if( !xInfo.is() )
278 xInfo = rPropSet->getPropertySetInfo();
279 if ( xInfo->hasPropertyByName( rPropertyName ) )
281 rPropSet->setPropertyValue( rPropertyName, Any( sStyleName ) );
288 SdXMLPageMasterStyleContext::SdXMLPageMasterStyleContext(
289 SdXMLImport& rImport,
290 sal_Int32 /*nElement*/,
291 const uno::Reference< xml::sax::XFastAttributeList>& xAttrList)
292 : SvXMLStyleContext(rImport, XmlStyleFamily::SD_PAGEMASTERSTYLECONTEXT_ID),
293 mnBorderBottom( 0 ),
294 mnBorderLeft( 0 ),
295 mnBorderRight( 0 ),
296 mnBorderTop( 0 ),
297 mnWidth( 0 ),
298 mnHeight( 0 ),
299 meOrientation(GetSdImport().IsDraw() ? view::PaperOrientation_PORTRAIT : view::PaperOrientation_LANDSCAPE)
301 // set family to something special at SvXMLStyleContext
302 // for differences in search-methods
304 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
306 switch(aIter.getToken())
308 case XML_ELEMENT(FO, XML_MARGIN_TOP):
309 case XML_ELEMENT(FO_COMPAT, XML_MARGIN_TOP):
311 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
312 mnBorderTop, aIter.toView());
313 break;
315 case XML_ELEMENT(FO, XML_MARGIN_BOTTOM):
316 case XML_ELEMENT(FO_COMPAT, XML_MARGIN_BOTTOM):
318 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
319 mnBorderBottom, aIter.toView());
320 break;
322 case XML_ELEMENT(FO, XML_MARGIN_LEFT):
323 case XML_ELEMENT(FO_COMPAT, XML_MARGIN_LEFT):
325 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
326 mnBorderLeft, aIter.toView());
327 break;
329 case XML_ELEMENT(FO, XML_MARGIN_RIGHT):
330 case XML_ELEMENT(FO_COMPAT, XML_MARGIN_RIGHT):
332 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
333 mnBorderRight, aIter.toView());
334 break;
336 case XML_ELEMENT(FO, XML_PAGE_WIDTH):
337 case XML_ELEMENT(FO_COMPAT, XML_PAGE_WIDTH):
339 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
340 mnWidth, aIter.toView());
341 break;
343 case XML_ELEMENT(FO, XML_PAGE_HEIGHT):
344 case XML_ELEMENT(FO_COMPAT, XML_PAGE_HEIGHT):
346 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
347 mnHeight, aIter.toView());
348 break;
350 case XML_ELEMENT(STYLE, XML_PRINT_ORIENTATION):
352 if( IsXMLToken( aIter, XML_PORTRAIT ) )
353 meOrientation = view::PaperOrientation_PORTRAIT;
354 else
355 meOrientation = view::PaperOrientation_LANDSCAPE;
356 break;
358 default:
359 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
364 SdXMLPageMasterStyleContext::~SdXMLPageMasterStyleContext()
369 SdXMLPageMasterContext::SdXMLPageMasterContext(
370 SdXMLImport& rImport,
371 sal_Int32 /*nElement*/,
372 const uno::Reference< xml::sax::XFastAttributeList>& /*xAttrList*/)
373 : SvXMLStyleContext(rImport, XmlStyleFamily::SD_PAGEMASTERCONTEXT_ID)
375 // set family to something special at SvXMLStyleContext
376 // for differences in search-methods
380 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLPageMasterContext::createFastChildContext(
381 sal_Int32 nElement,
382 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
384 if(nElement == XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_PROPERTIES))
386 DBG_ASSERT(!mxPageMasterStyle.is(), "PageMasterStyle is set, there seem to be two of them (!)");
387 mxPageMasterStyle.set(new SdXMLPageMasterStyleContext(GetSdImport(), nElement, xAttrList));
388 return mxPageMasterStyle;
390 else
391 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
393 return nullptr;
396 SdXMLPresentationPageLayoutContext::SdXMLPresentationPageLayoutContext(
397 SdXMLImport& rImport,
398 sal_Int32 /*nElement*/,
399 const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/)
400 : SvXMLStyleContext(rImport, XmlStyleFamily::SD_PRESENTATIONPAGELAYOUT_ID),
401 mnTypeId( AUTOLAYOUT_NONE )
403 // set family to something special at SvXMLStyleContext
404 // for differences in search-methods
407 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLPresentationPageLayoutContext::createFastChildContext(
408 sal_Int32 nElement,
409 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
411 SvXMLImportContextRef xContext;
413 if(nElement == XML_ELEMENT(PRESENTATION, XML_PLACEHOLDER))
415 const rtl::Reference< SdXMLPresentationPlaceholderContext > xLclContext{
416 new SdXMLPresentationPlaceholderContext(GetSdImport(), nElement, xAttrList)};
417 // presentation:placeholder inside style:presentation-page-layout context
418 xContext = xLclContext.get();
420 // remember SdXMLPresentationPlaceholderContext for later evaluation
421 maList.push_back(xLclContext);
423 else
424 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
426 return xContext;
429 void SdXMLPresentationPageLayoutContext::endFastElement(sal_Int32 )
431 // build presentation page layout type here
432 // calc mnTpeId due to content of maList
433 // at the moment only use number of types used there
434 if( maList.empty() )
435 return;
437 SdXMLPresentationPlaceholderContext* pObj0 = maList[ 0 ].get();
438 if( pObj0->GetName() == "handout" )
440 switch( maList.size() )
442 case 1:
443 mnTypeId = AUTOLAYOUT_HANDOUT1;
444 break;
445 case 2:
446 mnTypeId = AUTOLAYOUT_HANDOUT2;
447 break;
448 case 3:
449 mnTypeId = AUTOLAYOUT_HANDOUT3;
450 break;
451 case 4:
452 mnTypeId = AUTOLAYOUT_HANDOUT4;
453 break;
454 case 9:
455 mnTypeId = AUTOLAYOUT_HANDOUT9;
456 break;
457 default:
458 mnTypeId = AUTOLAYOUT_HANDOUT6;
461 else
463 switch( maList.size() )
465 case 1:
467 if( pObj0->GetName() == "title" )
469 mnTypeId = AUTOLAYOUT_TITLE_ONLY;
471 else
473 mnTypeId = AUTOLAYOUT_ONLY_TEXT;
475 break;
477 case 2:
479 SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get();
481 if( pObj1->GetName() == "subtitle" )
483 mnTypeId = AUTOLAYOUT_TITLE;
485 else if( pObj1->GetName() == "outline" )
487 mnTypeId = AUTOLAYOUT_TITLE_CONTENT;
489 else if( pObj1->GetName() == "chart" )
491 mnTypeId = AUTOLAYOUT_CHART;
493 else if( pObj1->GetName() == "table" )
495 mnTypeId = AUTOLAYOUT_TAB;
497 else if( pObj1->GetName() == "object" )
499 mnTypeId = AUTOLAYOUT_OBJ;
501 else if( pObj1->GetName() == "vertical_outline" )
503 if( pObj0->GetName() == "vertical_title" )
505 mnTypeId = AUTOLAYOUT_VTITLE_VCONTENT;
507 else
509 mnTypeId = AUTOLAYOUT_TITLE_VCONTENT;
512 else
514 mnTypeId = AUTOLAYOUT_NOTES;
516 break;
518 case 3:
520 SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get();
521 SdXMLPresentationPlaceholderContext* pObj2 = maList[ 2 ].get();
523 if( pObj1->GetName() == "outline" )
525 if( pObj2->GetName() == "outline" )
527 mnTypeId = AUTOLAYOUT_TITLE_2CONTENT;
529 else if( pObj2->GetName() == "chart" )
531 mnTypeId = AUTOLAYOUT_TEXTCHART;
533 else if( pObj2->GetName() == "graphic" )
535 mnTypeId = AUTOLAYOUT_TEXTCLIP;
537 else
539 if(pObj1->GetX() < pObj2->GetX())
541 mnTypeId = AUTOLAYOUT_TEXTOBJ; // outline left, object right
543 else
545 mnTypeId = AUTOLAYOUT_TEXTOVEROBJ; // outline top, object right
549 else if( pObj1->GetName() == "chart" )
551 mnTypeId = AUTOLAYOUT_CHARTTEXT;
553 else if( pObj1->GetName() == "graphic" )
555 if( pObj2->GetName() == "vertical_outline" )
557 mnTypeId = AUTOLAYOUT_TITLE_2VTEXT;
559 else
561 mnTypeId = AUTOLAYOUT_CLIPTEXT;
564 else if( pObj1->GetName() == "vertical_outline" )
566 mnTypeId = AUTOLAYOUT_VTITLE_VCONTENT_OVER_VCONTENT;
568 else
570 if(pObj1->GetX() < pObj2->GetX())
572 mnTypeId = AUTOLAYOUT_OBJTEXT; // left, right
574 else
576 mnTypeId = AUTOLAYOUT_TITLE_CONTENT_OVER_CONTENT; // top, bottom
579 break;
581 case 4:
583 SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get();
584 SdXMLPresentationPlaceholderContext* pObj2 = maList[ 2 ].get();
586 if( pObj1->GetName() == "object" )
588 if(pObj1->GetX() < pObj2->GetX())
590 mnTypeId = AUTOLAYOUT_TITLE_2CONTENT_OVER_CONTENT;
592 else
594 mnTypeId = AUTOLAYOUT_TITLE_2CONTENT_CONTENT;
597 else
599 mnTypeId = AUTOLAYOUT_TITLE_CONTENT_2CONTENT;
601 break;
603 case 5:
605 SdXMLPresentationPlaceholderContext* pObj1 = maList[ 1 ].get();
607 if( pObj1->GetName() == "object" )
609 mnTypeId = AUTOLAYOUT_TITLE_4CONTENT;
611 else
613 mnTypeId = AUTOLAYOUT_4CLIPART;
615 break;
618 case 7:
620 mnTypeId = AUTOLAYOUT_TITLE_6CONTENT; // tdf#141978: Apply 6content layout
621 break;
623 default:
625 mnTypeId = AUTOLAYOUT_NONE;
626 break;
631 // release remembered contexts, they are no longer needed
632 maList.clear();
635 SdXMLPresentationPlaceholderContext::SdXMLPresentationPlaceholderContext(
636 SdXMLImport& rImport,
637 sal_Int32 /*nElement*/,
638 const uno::Reference< xml::sax::XFastAttributeList>& xAttrList)
639 : SvXMLImportContext( rImport ),
640 mnX(0)
642 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
644 switch(aIter.getToken())
646 case XML_ELEMENT(PRESENTATION, XML_OBJECT):
648 msName = aIter.toString();
649 break;
651 case XML_ELEMENT(SVG, XML_X):
652 case XML_ELEMENT(SVG_COMPAT, XML_X):
654 GetSdImport().GetMM100UnitConverter().convertMeasureToCore(
655 mnX, aIter.toView());
656 break;
658 case XML_ELEMENT(SVG, XML_Y):
659 case XML_ELEMENT(SVG_COMPAT, XML_Y):
661 break;
663 case XML_ELEMENT(SVG, XML_WIDTH):
664 case XML_ELEMENT(SVG_COMPAT, XML_WIDTH):
666 break;
668 case XML_ELEMENT(SVG, XML_HEIGHT):
669 case XML_ELEMENT(SVG_COMPAT, XML_HEIGHT):
671 break;
673 default:
674 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
679 SdXMLPresentationPlaceholderContext::~SdXMLPresentationPlaceholderContext()
684 // Only called for handout master
685 SdXMLMasterPageContext::SdXMLMasterPageContext(
686 SdXMLImport& rImport,
687 sal_Int32 nElement,
688 const uno::Reference< xml::sax::XFastAttributeList>& xAttrList,
689 uno::Reference< drawing::XShapes > const & rShapes)
690 : SdXMLGenericPageContext( rImport, xAttrList, rShapes )
692 assert((nElement & TOKEN_MASK) == XML_HANDOUT_MASTER); (void)nElement;
693 OUString sStyleName, sPageMasterName;
695 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
697 const OUString sValue = aIter.toString();
698 switch(aIter.getToken())
700 case XML_ELEMENT(STYLE, XML_NAME):
702 msName = sValue;
703 break;
705 case XML_ELEMENT(STYLE, XML_DISPLAY_NAME):
707 msDisplayName = sValue;
708 break;
710 case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_NAME):
712 sPageMasterName = sValue;
713 break;
715 case XML_ELEMENT(DRAW, XML_STYLE_NAME):
717 sStyleName = sValue;
718 break;
720 case XML_ELEMENT(PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME):
722 maPageLayoutName = sValue;
723 break;
725 case XML_ELEMENT(PRESENTATION, XML_USE_HEADER_NAME):
727 maUseHeaderDeclName = sValue;
728 break;
730 case XML_ELEMENT(PRESENTATION, XML_USE_FOOTER_NAME):
732 maUseFooterDeclName = sValue;
733 break;
735 case XML_ELEMENT(PRESENTATION, XML_USE_DATE_TIME_NAME):
737 maUseDateTimeDeclName = sValue;
738 break;
740 default:
741 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
745 if( msDisplayName.isEmpty() )
746 msDisplayName = msName;
747 else if( msDisplayName != msName )
748 GetImport().AddStyleDisplayName( XmlStyleFamily::MASTER_PAGE, msName, msDisplayName );
750 GetImport().GetShapeImport()->startPage( GetLocalShapesContext() );
752 // set page-master?
753 if(!sPageMasterName.isEmpty())
755 SetPageMaster( sPageMasterName );
758 SetStyle( sStyleName );
760 SetLayout();
762 DeleteAllShapes();
765 // only called for normal master pages
766 SdXMLMasterPageContext::SdXMLMasterPageContext(
767 SdXMLImport& rImport,
768 sal_Int32 nElement,
769 const uno::Reference< xml::sax::XFastAttributeList>& xAttrList,
770 uno::Reference< drawing::XDrawPages2 > const & xMasterPages)
771 : SdXMLGenericPageContext( rImport, xAttrList )
773 assert((nElement & TOKEN_MASK) != XML_HANDOUT_MASTER); (void)nElement;
774 OUString sStyleName, sPageMasterName;
776 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
778 const OUString sValue = aIter.toString();
779 switch(aIter.getToken())
781 case XML_ELEMENT(STYLE, XML_NAME):
783 msName = sValue;
784 break;
786 case XML_ELEMENT(STYLE, XML_DISPLAY_NAME):
788 msDisplayName = sValue;
789 break;
791 case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT_NAME):
793 sPageMasterName = sValue;
794 break;
796 case XML_ELEMENT(DRAW, XML_STYLE_NAME):
798 sStyleName = sValue;
799 break;
801 case XML_ELEMENT(PRESENTATION, XML_PRESENTATION_PAGE_LAYOUT_NAME):
803 maPageLayoutName = sValue;
804 break;
806 case XML_ELEMENT(PRESENTATION, XML_USE_HEADER_NAME):
808 maUseHeaderDeclName = sValue;
809 break;
811 case XML_ELEMENT(PRESENTATION, XML_USE_FOOTER_NAME):
813 maUseFooterDeclName = sValue;
814 break;
816 case XML_ELEMENT(PRESENTATION, XML_USE_DATE_TIME_NAME):
818 maUseDateTimeDeclName = sValue;
819 break;
821 default:
822 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
826 if( msDisplayName.isEmpty() )
827 msDisplayName = msName;
828 else if( msDisplayName != msName )
829 GetImport().AddStyleDisplayName( XmlStyleFamily::MASTER_PAGE, msName, msDisplayName );
831 sal_Int32 nNewMasterPageCount = GetSdImport().GetNewMasterPageCount();
832 sal_Int32 nMasterPageCount = xMasterPages->getCount();
833 uno::Reference< drawing::XDrawPage > xNewMasterPage;
834 if (nNewMasterPageCount + 1 > nMasterPageCount)
836 // new page, create and insert
837 xNewMasterPage = xMasterPages->insertNamedNewByIndex(nMasterPageCount, msDisplayName);
838 SetShapes(xNewMasterPage);
840 else
842 // existing page, use it
843 xMasterPages->getByIndex(nNewMasterPageCount) >>= xNewMasterPage;
844 SetShapes(xNewMasterPage);
845 if(!msDisplayName.isEmpty())
847 uno::Reference < container::XNamed > xNamed(xNewMasterPage, uno::UNO_QUERY);
848 if(xNamed.is())
849 xNamed->setName(msDisplayName);
852 // increment global import page counter
853 GetSdImport().IncrementNewMasterPageCount();
855 GetImport().GetShapeImport()->startPage( GetLocalShapesContext() );
857 // set page-master?
858 if(!sPageMasterName.isEmpty())
860 SetPageMaster( sPageMasterName );
863 SetStyle( sStyleName );
865 SetLayout();
867 DeleteAllShapes();
870 SdXMLMasterPageContext::~SdXMLMasterPageContext()
874 void SdXMLMasterPageContext::endFastElement(sal_Int32 nElement)
876 // set styles on master-page
877 if(!msName.isEmpty() && GetSdImport().GetShapeImport()->GetStylesContext())
879 SvXMLImportContext* pContext = GetSdImport().GetShapeImport()->GetStylesContext();
880 if (SdXMLStylesContext* pSdContext = dynamic_cast<SdXMLStylesContext*>(pContext))
881 pSdContext->SetMasterPageStyles(*this);
884 SdXMLGenericPageContext::endFastElement(nElement);
885 GetImport().GetShapeImport()->endPage(GetLocalShapesContext());
888 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLMasterPageContext::createFastChildContext(
889 sal_Int32 nElement,
890 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
892 switch (nElement)
894 // some special objects inside style:masterpage context
895 case XML_ELEMENT(STYLE, XML_STYLE):
897 if(GetSdImport().GetShapeImport()->GetStylesContext())
899 // style:style inside master-page context -> presentation style
900 XMLShapeStyleContext* pNew = new XMLShapeStyleContext(
901 GetSdImport(),
902 *GetSdImport().GetShapeImport()->GetStylesContext(),
903 XmlStyleFamily::SD_PRESENTATION_ID);
905 // add this style to the outer StylesContext class for later processing
906 GetSdImport().GetShapeImport()->GetStylesContext()->AddStyle(*pNew);
907 return pNew;
909 break;
911 case XML_ELEMENT(PRESENTATION, XML_NOTES):
913 if( GetSdImport().IsImpress() )
915 // get notes page
916 uno::Reference< presentation::XPresentationPage > xPresPage(GetLocalShapesContext(), uno::UNO_QUERY);
917 if(xPresPage.is())
919 uno::Reference< drawing::XDrawPage > xNotesDrawPage = xPresPage->getNotesPage();
920 if(xNotesDrawPage.is())
922 // presentation:notes inside master-page context
923 return new SdXMLNotesContext( GetSdImport(), xAttrList, xNotesDrawPage);
927 break;
929 case XML_ELEMENT(LO_EXT, XML_THEME):
931 uno::Reference<drawing::XDrawPage> xMasterPage(GetLocalShapesContext(), uno::UNO_QUERY);
932 return new XMLThemeContext(GetSdImport(), xAttrList, xMasterPage);
933 break;
936 return SdXMLGenericPageContext::createFastChildContext(nElement, xAttrList);
939 SdXMLStylesContext::SdXMLStylesContext(
940 SdXMLImport& rImport,
941 bool bIsAutoStyle)
942 : SvXMLStylesContext(rImport),
943 mbIsAutoStyle(bIsAutoStyle)
945 Reference< uno::XComponentContext > xContext = rImport.GetComponentContext();
946 mpNumFormatter = std::make_unique<SvNumberFormatter>( xContext, LANGUAGE_SYSTEM );
947 mpNumFmtHelper = std::make_unique<SvXMLNumFmtHelper>( mpNumFormatter.get(), xContext );
950 SvXMLStyleContext* SdXMLStylesContext::CreateStyleChildContext(
951 sal_Int32 nElement,
952 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
954 switch (nElement)
956 case XML_ELEMENT(TABLE, XML_TABLE_TEMPLATE):
958 auto pContext = GetImport().GetShapeImport()->GetShapeTableImport()->CreateTableTemplateContext(nElement, xAttrList );
959 if (pContext)
960 return pContext;
961 break;
963 case XML_ELEMENT(STYLE, XML_PAGE_LAYOUT):
964 // style:page-master inside office:styles context
965 return new SdXMLPageMasterContext(GetSdImport(), nElement, xAttrList);
966 case XML_ELEMENT(STYLE, XML_PRESENTATION_PAGE_LAYOUT):
967 // style:presentation-page-layout inside office:styles context
968 return new SdXMLPresentationPageLayoutContext(GetSdImport(), nElement, xAttrList);
969 case XML_ELEMENT(NUMBER, XML_DATE_STYLE):
970 // number:date-style or number:time-style
971 return new SdXMLNumberFormatImportContext( GetSdImport(), nElement, mpNumFmtHelper->getData(), SvXMLStylesTokens::DATE_STYLE, xAttrList, *this );
972 case XML_ELEMENT(NUMBER, XML_TIME_STYLE):
973 // number:date-style or number:time-style
974 return new SdXMLNumberFormatImportContext( GetSdImport(), nElement, mpNumFmtHelper->getData(), SvXMLStylesTokens::TIME_STYLE, xAttrList, *this );
975 case XML_ELEMENT(NUMBER, XML_NUMBER_STYLE):
976 return new SvXMLNumFormatContext( GetSdImport(), nElement,
977 mpNumFmtHelper->getData(), SvXMLStylesTokens::NUMBER_STYLE, xAttrList, *this );
978 case XML_ELEMENT(NUMBER, XML_CURRENCY_STYLE):
979 return new SvXMLNumFormatContext( GetSdImport(), nElement,
980 mpNumFmtHelper->getData(), SvXMLStylesTokens::CURRENCY_STYLE, xAttrList, *this );
981 case XML_ELEMENT(NUMBER, XML_PERCENTAGE_STYLE):
982 return new SvXMLNumFormatContext( GetSdImport(), nElement,
983 mpNumFmtHelper->getData(), SvXMLStylesTokens::PERCENTAGE_STYLE, xAttrList, *this );
984 case XML_ELEMENT(NUMBER, XML_BOOLEAN_STYLE):
985 return new SvXMLNumFormatContext( GetSdImport(), nElement,
986 mpNumFmtHelper->getData(), SvXMLStylesTokens::BOOLEAN_STYLE, xAttrList, *this );
987 case XML_ELEMENT(NUMBER, XML_TEXT_STYLE):
988 return new SvXMLNumFormatContext( GetSdImport(), nElement,
989 mpNumFmtHelper->getData(), SvXMLStylesTokens::TEXT_STYLE, xAttrList, *this );
990 case XML_ELEMENT(PRESENTATION, XML_HEADER_DECL):
991 case XML_ELEMENT(PRESENTATION, XML_FOOTER_DECL):
992 case XML_ELEMENT(PRESENTATION, XML_DATE_TIME_DECL):
993 return new SdXMLHeaderFooterDeclContext( GetImport(), xAttrList );
994 case XML_ELEMENT(STYLE, XML_STYLE):
995 break; // ignore
996 default:
997 XMLOFF_INFO_UNKNOWN_ELEMENT("xmloff", nElement);
1000 // call base class
1001 return SvXMLStylesContext::CreateStyleChildContext(nElement, xAttrList);
1004 SvXMLStyleContext* SdXMLStylesContext::CreateStyleStyleChildContext(
1005 XmlStyleFamily nFamily,
1006 sal_Int32 nElement,
1007 const uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
1009 switch( nFamily )
1011 case XmlStyleFamily::SD_DRAWINGPAGE_ID:
1012 return new SdXMLDrawingPageStyleContext(GetSdImport(), *this );
1013 case XmlStyleFamily::TABLE_CELL:
1014 case XmlStyleFamily::TABLE_COLUMN:
1015 case XmlStyleFamily::TABLE_ROW:
1016 return new XMLShapeStyleContext( GetSdImport(), *this, nFamily );
1017 default: break;
1020 // call base class
1021 return SvXMLStylesContext::CreateStyleStyleChildContext(nFamily, nElement, xAttrList);
1024 SvXMLStyleContext* SdXMLStylesContext::CreateDefaultStyleStyleChildContext(
1025 XmlStyleFamily nFamily,
1026 sal_Int32 nElement,
1027 const Reference< XFastAttributeList > & xAttrList )
1029 switch( nFamily )
1031 case XmlStyleFamily::SD_GRAPHICS_ID:
1032 return new XMLGraphicsDefaultStyle(GetSdImport(), *this );
1033 default: break;
1036 // call base class
1037 return SvXMLStylesContext::CreateDefaultStyleStyleChildContext(nFamily, nElement, xAttrList);
1040 rtl::Reference< SvXMLImportPropertyMapper > SdXMLStylesContext::GetImportPropertyMapper(
1041 XmlStyleFamily nFamily) const
1043 rtl::Reference < SvXMLImportPropertyMapper > xMapper;
1045 switch( nFamily )
1047 case XmlStyleFamily::SD_DRAWINGPAGE_ID:
1049 if(!xPresImpPropMapper.is())
1051 rtl::Reference< XMLShapeImportHelper > aImpHelper = const_cast<SvXMLImport&>(GetImport()).GetShapeImport();
1052 const_cast<SdXMLStylesContext*>(this)->xPresImpPropMapper =
1053 aImpHelper->GetPresPagePropsMapper();
1055 xMapper = xPresImpPropMapper;
1056 break;
1059 case XmlStyleFamily::TABLE_COLUMN:
1060 case XmlStyleFamily::TABLE_ROW:
1061 case XmlStyleFamily::TABLE_CELL:
1063 const rtl::Reference< XMLTableImport >& xTableImport( const_cast< SvXMLImport& >( GetImport() ).GetShapeImport()->GetShapeTableImport() );
1065 switch( nFamily )
1067 case XmlStyleFamily::TABLE_COLUMN: xMapper = xTableImport->GetColumnImportPropertySetMapper().get(); break;
1068 case XmlStyleFamily::TABLE_ROW: xMapper = xTableImport->GetRowImportPropertySetMapper().get(); break;
1069 case XmlStyleFamily::TABLE_CELL: xMapper = xTableImport->GetCellImportPropertySetMapper().get(); break;
1070 default: break;
1072 break;
1074 default: break;
1077 // call base class
1078 if( !xMapper.is() )
1079 xMapper = SvXMLStylesContext::GetImportPropertyMapper(nFamily);
1080 return xMapper;
1083 // Process all style and object info
1085 void SdXMLStylesContext::endFastElement(sal_Int32 )
1087 if(mbIsAutoStyle)
1089 // AutoStyles for text import
1090 GetImport().GetTextImport()->SetAutoStyles( this );
1092 // AutoStyles for chart
1093 GetImport().GetChartImport()->SetAutoStylesContext( this );
1095 // AutoStyles for forms
1096 GetImport().GetFormImport()->setAutoStyleContext( this );
1098 // associate AutoStyles with styles in preparation to setting Styles on shapes
1099 for(sal_uInt32 a(0); a < GetStyleCount(); a++)
1101 const SvXMLStyleContext* pStyle = GetStyle(a);
1102 if (const XMLShapeStyleContext* pDocStyle = dynamic_cast<const XMLShapeStyleContext*>(pStyle))
1104 SvXMLStylesContext* pStylesContext = GetSdImport().GetShapeImport()->GetStylesContext();
1105 if (pStylesContext)
1107 pStyle = pStylesContext->FindStyleChildContext(pStyle->GetFamily(), pStyle->GetParentName());
1109 if (const XMLShapeStyleContext* pParentStyle = dynamic_cast<const XMLShapeStyleContext*>(pStyle))
1111 if(pParentStyle->GetStyle().is())
1113 const_cast<XMLShapeStyleContext*>(pDocStyle)->SetStyle(pParentStyle->GetStyle());
1120 FinishStyles( false );
1122 else
1124 // Process styles list
1125 ImpSetGraphicStyles();
1126 ImpSetCellStyles();
1127 GetImport().GetShapeImport()->GetShapeTableImport()->finishStyles();
1129 // put style infos in the info set for other components ( content import f.e. )
1130 uno::Reference< beans::XPropertySet > xInfoSet( GetImport().getImportInfo() );
1131 if( xInfoSet.is() )
1133 uno::Reference< beans::XPropertySetInfo > xInfoSetInfo( xInfoSet->getPropertySetInfo() );
1135 if( xInfoSetInfo->hasPropertyByName(u"PageLayouts"_ustr) )
1136 xInfoSet->setPropertyValue(u"PageLayouts"_ustr, uno::Any( getPageLayouts() ) );
1142 // set master-page styles (all with family="presentation" and a special
1143 // prefix) on given master-page.
1145 void SdXMLStylesContext::SetMasterPageStyles(SdXMLMasterPageContext const & rMaster) const
1147 const uno::Reference<container::XNameAccess>& rStyleFamilies =
1148 GetSdImport().GetLocalDocStyleFamilies();
1150 if (!rStyleFamilies.is())
1151 return;
1153 if (!rStyleFamilies->hasByName(rMaster.GetDisplayName()))
1154 return;
1158 uno::Reference< container::XNameAccess > xMasterPageStyles( rStyleFamilies->getByName(rMaster.GetDisplayName()), UNO_QUERY_THROW );
1159 OUString sPrefix(rMaster.GetDisplayName() + "-");
1160 ImpSetGraphicStyles(xMasterPageStyles, XmlStyleFamily::SD_PRESENTATION_ID, sPrefix);
1162 catch (const uno::Exception&)
1164 TOOLS_WARN_EXCEPTION("xmloff.draw", "");
1168 // Process styles list:
1169 // set graphic styles (all with family="graphics"). Remember xStyle at list element.
1171 void SdXMLStylesContext::ImpSetGraphicStyles() const
1173 if(GetSdImport().GetLocalDocStyleFamilies().is()) try
1175 uno::Reference< container::XNameAccess > xGraphicPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName(u"graphics"_ustr), uno::UNO_QUERY_THROW );
1177 ImpSetGraphicStyles(xGraphicPageStyles, XmlStyleFamily::SD_GRAPHICS_ID, u""_ustr);
1179 catch( uno::Exception& )
1181 TOOLS_WARN_EXCEPTION("xmloff.draw", "");
1185 void SdXMLStylesContext::ImpSetCellStyles() const
1187 if(GetSdImport().GetLocalDocStyleFamilies().is()) try
1189 uno::Reference< container::XNameAccess > xGraphicPageStyles( GetSdImport().GetLocalDocStyleFamilies()->getByName(u"cell"_ustr), uno::UNO_QUERY_THROW );
1191 ImpSetGraphicStyles(xGraphicPageStyles, XmlStyleFamily::TABLE_CELL, u""_ustr);
1193 catch( uno::Exception& )
1195 TOOLS_WARN_EXCEPTION("xmloff.draw", "");
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)
1208 bool bCanSkipReset = false;
1209 if (pPropStyle && rName == u"TextAutoGrowHeight")
1211 bool bOldStyleTextAutoGrowHeight(false);
1212 rPropSet->getPropertyValue(u"TextAutoGrowHeight"_ustr) >>= bOldStyleTextAutoGrowHeight;
1214 sal_Int32 nIndexStyle = rPrMap->GetEntryIndex(XML_NAMESPACE_DRAW, u"auto-grow-height", 0);
1215 if (nIndexStyle != -1)
1217 const ::std::vector< XMLPropertyState > &rProperties = pPropStyle->GetProperties();
1218 auto property = std::find_if(rProperties.cbegin(), rProperties.cend(),
1219 [nIndexStyle](const XMLPropertyState& rProp) { return rProp.mnIndex == nIndexStyle; });
1220 if (property != rProperties.cend())
1222 bool bNewStyleTextAutoGrowHeight(false);
1223 property->maValue >>= bNewStyleTextAutoGrowHeight;
1224 bCanSkipReset = (bNewStyleTextAutoGrowHeight == bOldStyleTextAutoGrowHeight);
1228 return bCanSkipReset;
1231 // help function used by ImpSetGraphicStyles() and ImpSetMasterPageStyles()
1233 void SdXMLStylesContext::ImpSetGraphicStyles( uno::Reference< container::XNameAccess > const & xPageStyles, XmlStyleFamily nFamily, const OUString& rPrefix) const
1235 sal_Int32 nPrefLen(rPrefix.getLength());
1237 // set defaults
1238 auto [itStart1, itEnd1] = FindStyleChildContextByDisplayNamePrefix(nFamily, u""_ustr);
1239 for (auto it = itStart1; it != itEnd1; ++it)
1241 const SvXMLStyleContext* pStyle = *it;
1242 if(pStyle->IsDefaultStyle())
1244 const_cast<SvXMLStyleContext*>(pStyle)->SetDefaults();
1248 // create all styles and set properties
1249 auto [itStart, itEnd] = FindStyleChildContextByDisplayNamePrefix(nFamily, rPrefix);
1250 for (auto it = itStart; it != itEnd; ++it)
1252 const SvXMLStyleContext* pStyle = *it;
1255 if(!pStyle->IsDefaultStyle())
1257 OUString aStyleName(pStyle->GetDisplayName());
1258 if( nPrefLen )
1259 aStyleName = aStyleName.copy( nPrefLen );
1261 XMLPropStyleContext* pPropStyle = dynamic_cast< XMLPropStyleContext* >(const_cast< SvXMLStyleContext* >( pStyle ) );
1263 uno::Reference< style::XStyle > xStyle;
1264 if(xPageStyles->hasByName(aStyleName))
1266 xPageStyles->getByName(aStyleName) >>= xStyle;
1268 // set properties of existing styles to default
1269 uno::Reference< beans::XPropertySet > xPropSet( xStyle, uno::UNO_QUERY );
1270 uno::Reference< beans::XPropertySetInfo > xPropSetInfo;
1271 if( xPropSet.is() )
1272 xPropSetInfo = xPropSet->getPropertySetInfo();
1274 uno::Reference< beans::XPropertyState > xPropState( xStyle, uno::UNO_QUERY );
1276 if( xPropState.is() )
1278 rtl::Reference < XMLPropertySetMapper > xPrMap;
1279 rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetImportPropertyMapper( nFamily );
1280 SAL_WARN_IF( !xImpPrMap.is(), "xmloff", "There is the import prop mapper" );
1281 if( xImpPrMap.is() )
1282 xPrMap = xImpPrMap->getPropertySetMapper();
1283 if( xPrMap.is() )
1285 const sal_Int32 nCount = xPrMap->GetEntryCount();
1286 for( sal_Int32 i = 0; i < nCount; i++ )
1288 const OUString& rName = xPrMap->GetEntryAPIName( i );
1289 if( xPropSetInfo->hasPropertyByName( rName ) && beans::PropertyState_DIRECT_VALUE == xPropState->getPropertyState( rName ) )
1291 bool bCanSkipReset = canSkipReset(rName, pPropStyle, xPropSet, xPrMap);
1292 if (bCanSkipReset)
1293 continue;
1294 xPropState->setPropertyToDefault( rName );
1300 else
1302 // graphics style does not exist, create and add it
1303 uno::Reference< lang::XSingleServiceFactory > xServiceFact(xPageStyles, uno::UNO_QUERY);
1304 if(xServiceFact.is())
1306 uno::Reference< style::XStyle > xNewStyle( xServiceFact->createInstance(), uno::UNO_QUERY);
1308 if(xNewStyle.is())
1310 // remember style
1311 xStyle = std::move(xNewStyle);
1313 // add new style to graphics style pool
1314 uno::Reference< container::XNameContainer > xInsertContainer(xPageStyles, uno::UNO_QUERY);
1315 if(xInsertContainer.is())
1316 xInsertContainer->insertByName(aStyleName, uno::Any( xStyle ) );
1321 if(xStyle.is())
1323 // set properties at style
1324 uno::Reference< beans::XPropertySet > xPropSet(xStyle, uno::UNO_QUERY);
1325 if(xPropSet.is() && pPropStyle)
1327 pPropStyle->FillPropertySet(xPropSet);
1328 pPropStyle->SetStyle(xStyle);
1333 catch(const Exception& e)
1335 const_cast<SdXMLImport*>(&GetSdImport())->SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, {}, e.Message, nullptr );
1339 // now set parents for all styles (when necessary)
1340 for (auto it = itStart; it != itEnd; ++it)
1342 const SvXMLStyleContext* pStyle = *it;
1344 if(pStyle->GetDisplayName().isEmpty())
1345 continue;
1348 OUString aStyleName(pStyle->GetDisplayName());
1349 if( nPrefLen )
1350 aStyleName = aStyleName.copy( nPrefLen );
1352 uno::Reference< style::XStyle > xStyle( xPageStyles->getByName(aStyleName), UNO_QUERY );
1353 if(xStyle.is())
1355 // set parent style name
1356 OUString sParentStyleDisplayName( GetImport().GetStyleDisplayName( pStyle->GetFamily(), pStyle->GetParentName() ) );
1357 if( nPrefLen )
1359 sal_Int32 nStylePrefLen = sParentStyleDisplayName.lastIndexOf( '-' ) + 1;
1360 if( (nPrefLen != nStylePrefLen) || !sParentStyleDisplayName.startsWith( rPrefix ) )
1361 continue;
1363 sParentStyleDisplayName = sParentStyleDisplayName.copy( nPrefLen );
1365 if (xStyle->getParentStyle() != sParentStyleDisplayName)
1366 xStyle->setParentStyle( sParentStyleDisplayName );
1369 catch( const Exception& e )
1371 const_cast<SdXMLImport*>(&GetSdImport())->SetError( XMLERROR_FLAG_WARNING | XMLERROR_API, {}, e.Message, nullptr );
1376 // helper function to create the uno component that hold the mappings from
1377 // xml auto layout name to internal autolayout id
1379 uno::Reference< container::XNameAccess > SdXMLStylesContext::getPageLayouts() const
1381 uno::Reference< container::XNameContainer > xLayouts( comphelper::NameContainer_createInstance( ::cppu::UnoType<sal_Int32>::get()) );
1383 for(sal_uInt32 a(0); a < GetStyleCount(); a++)
1385 const SvXMLStyleContext* pStyle = GetStyle(a);
1386 if (const SdXMLPresentationPageLayoutContext* pContext = dynamic_cast<const SdXMLPresentationPageLayoutContext*>(pStyle))
1388 xLayouts->insertByName(pStyle->GetName(), uno::Any(static_cast<sal_Int32>(pContext->GetTypeId())));
1392 return xLayouts;
1396 SdXMLMasterStylesContext::SdXMLMasterStylesContext(
1397 SdXMLImport& rImport)
1398 : SvXMLImportContext( rImport )
1402 css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLMasterStylesContext::createFastChildContext(
1403 sal_Int32 nElement,
1404 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
1406 if( nElement == XML_ELEMENT(DRAW, XML_LAYER_SET) )
1408 return new SdXMLLayerSetContext( GetImport() );
1410 else if( nElement == XML_ELEMENT(STYLE, XML_MASTER_PAGE) )
1412 // style:masterpage inside office:styles context
1413 uno::Reference< drawing::XDrawPages2 > xMasterPages(GetSdImport().GetLocalMasterPages());
1415 if( xMasterPages.is() )
1417 sal_Int32 nMasterPageCount = xMasterPages->getCount();
1418 // arbitrary limit to master pages when fuzzing to avoid deadend timeouts
1419 if (nMasterPageCount >= 64 && comphelper::IsFuzzing())
1420 return nullptr;
1422 // new page, create and insert
1424 if(GetSdImport().GetShapeImport()->GetStylesContext())
1426 const rtl::Reference<SdXMLMasterPageContext> xLclContext{
1427 new SdXMLMasterPageContext(GetSdImport(),
1428 nElement, xAttrList, xMasterPages)};
1429 maMasterPageList.push_back(xLclContext);
1430 return xLclContext;
1434 else if( nElement == XML_ELEMENT(STYLE, XML_HANDOUT_MASTER) )
1436 uno::Reference< presentation::XHandoutMasterSupplier > xHandoutSupp( GetSdImport().GetModel(), uno::UNO_QUERY );
1437 if( xHandoutSupp.is() )
1439 uno::Reference< drawing::XShapes > xHandoutPage = xHandoutSupp->getHandoutMasterPage();
1440 if(xHandoutPage.is() && GetSdImport().GetShapeImport()->GetStylesContext())
1442 return new SdXMLMasterPageContext(GetSdImport(),
1443 nElement, xAttrList, xHandoutPage);
1447 else
1448 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement);
1449 return nullptr;
1452 SdXMLHeaderFooterDeclContext::SdXMLHeaderFooterDeclContext(SvXMLImport& rImport,
1453 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList)
1454 : SvXMLStyleContext( rImport )
1455 , mbFixed(false)
1457 for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
1459 if( aIter.getToken() == XML_ELEMENT(PRESENTATION, XML_NAME) )
1461 maStrName = aIter.toString();
1463 else if( aIter.getToken() == XML_ELEMENT(PRESENTATION, XML_SOURCE) )
1465 mbFixed = IsXMLToken( aIter, XML_FIXED );
1467 else if( aIter.getToken() == XML_ELEMENT(STYLE, XML_DATA_STYLE_NAME) )
1469 maStrDateTimeFormat = aIter.toString();
1471 else
1473 XMLOFF_WARN_UNKNOWN("xmloff", aIter);
1478 bool SdXMLHeaderFooterDeclContext::IsTransient() const
1480 return true;
1483 void SdXMLHeaderFooterDeclContext::endFastElement(sal_Int32 nToken)
1485 SdXMLImport& rImport = dynamic_cast<SdXMLImport&>(GetImport());
1486 auto nElement = nToken & TOKEN_MASK;
1487 if( nElement == XML_HEADER_DECL )
1489 rImport.AddHeaderDecl( maStrName, maStrText );
1491 else if( nElement == XML_FOOTER_DECL )
1493 rImport.AddFooterDecl( maStrName, maStrText );
1495 else if( nElement == XML_DATE_TIME_DECL )
1497 rImport.AddDateTimeDecl( maStrName, maStrText, mbFixed, maStrDateTimeFormat );
1499 else
1501 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nToken);
1505 void SdXMLHeaderFooterDeclContext::characters( const OUString& rChars )
1507 maStrText += rChars;
1510 namespace xmloff {
1512 bool IsIgnoreFillStyleNamedItem(
1513 css::uno::Reference<css::beans::XPropertySet> const& xProps,
1514 drawing::FillStyle const nExpectedFillStyle)
1516 assert(xProps.is());
1517 if (nExpectedFillStyle == drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE)
1519 return false;
1522 // note: the caller must have called FillPropertySet() previously
1523 drawing::FillStyle fillStyle{drawing::FillStyle_NONE};
1524 xProps->getPropertyValue(u"FillStyle"_ustr) >>= fillStyle;
1525 return fillStyle != nExpectedFillStyle;
1528 } // namespace xmloff
1530 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */