Version 7.5.1.1, tag libreoffice-7.5.1.1
[LibreOffice.git] / xmloff / source / style / FillStyleContext.cxx
blob8cd99a25b261a7f661709eab8878e4ebb7963375
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 <com/sun/star/container/XNameContainer.hpp>
21 #include <com/sun/star/graphic/XGraphic.hpp>
22 #include <com/sun/star/awt/XBitmap.hpp>
23 #include "FillStyleContext.hxx"
24 #include <xmloff/xmlimp.hxx>
25 #include <xmloff/GradientStyle.hxx>
26 #include <xmloff/HatchStyle.hxx>
27 #include <xmloff/ImageStyle.hxx>
28 #include <TransGradientStyle.hxx>
29 #include <xmloff/MarkerStyle.hxx>
30 #include <xmloff/DashStyle.hxx>
31 #include <xmloff/xmlnamespace.hxx>
32 #include <xmloff/xmltkmap.hxx>
33 #include <xmloff/XMLBase64ImportContext.hxx>
35 using namespace ::com::sun::star;
38 XMLGradientStyleContext::XMLGradientStyleContext( SvXMLImport& rImport, sal_Int32 ,
39 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
40 : SvXMLStyleContext(rImport)
42 // start import
43 XMLGradientStyleImport aGradientStyle( GetImport() );
44 aGradientStyle.importXML( xAttrList, maAny, maStrName );
47 XMLGradientStyleContext::~XMLGradientStyleContext()
51 void XMLGradientStyleContext::endFastElement(sal_Int32 )
53 uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() );
55 try
57 if(xGradient.is())
59 if( xGradient->hasByName( maStrName ) )
61 xGradient->replaceByName( maStrName, maAny );
63 else
65 xGradient->insertByName( maStrName, maAny );
69 catch( container::ElementExistException& )
73 bool XMLGradientStyleContext::IsTransient() const
75 return true;
79 XMLHatchStyleContext::XMLHatchStyleContext( SvXMLImport& rImport, sal_Int32 /*nElement*/,
80 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
81 : SvXMLStyleContext(rImport)
83 // start import
84 XMLHatchStyleImport aHatchStyle( GetImport() );
85 aHatchStyle.importXML( xAttrList, maAny, maStrName );
88 XMLHatchStyleContext::~XMLHatchStyleContext()
92 void XMLHatchStyleContext::endFastElement(sal_Int32 )
94 uno::Reference< container::XNameContainer > xHatch( GetImport().GetHatchHelper() );
96 try
98 if(xHatch.is())
100 if( xHatch->hasByName( maStrName ) )
102 xHatch->replaceByName( maStrName, maAny );
104 else
106 xHatch->insertByName( maStrName, maAny );
110 catch( container::ElementExistException& )
114 bool XMLHatchStyleContext::IsTransient() const
116 return true;
120 XMLBitmapStyleContext::XMLBitmapStyleContext( SvXMLImport& rImport, sal_Int32 /*nElement*/,
121 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
122 : SvXMLStyleContext(rImport)
124 // start import
125 XMLImageStyle::importXML( xAttrList, maAny, maStrName, rImport );
128 XMLBitmapStyleContext::~XMLBitmapStyleContext()
132 css::uno::Reference< css::xml::sax::XFastContextHandler > XMLBitmapStyleContext::createFastChildContext(
133 sal_Int32 nElement,
134 const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
136 if( nElement == XML_ELEMENT(OFFICE, xmloff::token::XML_BINARY_DATA) )
138 OUString sURL;
139 maAny >>= sURL;
140 if( sURL.isEmpty() && !mxBase64Stream.is() )
142 mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
143 if( mxBase64Stream.is() )
144 return new XMLBase64ImportContext( GetImport(), mxBase64Stream );
148 return nullptr;
151 void XMLBitmapStyleContext::endFastElement(sal_Int32 )
153 if (!maAny.has<uno::Reference<graphic::XGraphic>>() && mxBase64Stream.is())
155 // No graphic so far? Then see if it's inline.
156 uno::Reference<graphic::XGraphic> xGraphic = GetImport().loadGraphicFromBase64(mxBase64Stream);
157 if (xGraphic.is())
159 maAny <<= xGraphic;
163 if (!maAny.has<uno::Reference<graphic::XGraphic>>())
164 return;
166 uno::Reference<container::XNameContainer> xBitmapContainer(GetImport().GetBitmapHelper());
168 uno::Reference<graphic::XGraphic> xGraphic = maAny.get<uno::Reference<graphic::XGraphic>>();
169 uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
173 if (xBitmapContainer.is())
175 if (xBitmapContainer->hasByName(maStrName))
177 xBitmapContainer->replaceByName(maStrName, uno::Any(xBitmap));
179 else
181 xBitmapContainer->insertByName(maStrName, uno::Any(xBitmap));
185 catch (container::ElementExistException&)
189 bool XMLBitmapStyleContext::IsTransient() const
191 return true;
195 XMLTransGradientStyleContext::XMLTransGradientStyleContext( SvXMLImport& rImport, sal_Int32 /*nElement*/,
196 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
197 : SvXMLStyleContext(rImport)
199 // start import
200 XMLTransGradientStyleImport aTransGradientStyle( GetImport() );
201 aTransGradientStyle.importXML( xAttrList, maAny, maStrName );
204 XMLTransGradientStyleContext::~XMLTransGradientStyleContext()
208 void XMLTransGradientStyleContext::endFastElement(sal_Int32 )
210 uno::Reference< container::XNameContainer > xTransGradient( GetImport().GetTransGradientHelper() );
214 if(xTransGradient.is())
216 if( xTransGradient->hasByName( maStrName ) )
218 xTransGradient->replaceByName( maStrName, maAny );
220 else
222 xTransGradient->insertByName( maStrName, maAny );
226 catch( container::ElementExistException& )
230 bool XMLTransGradientStyleContext::IsTransient() const
232 return true;
236 XMLMarkerStyleContext::XMLMarkerStyleContext( SvXMLImport& rImport, sal_Int32 /*nElement*/,
237 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
238 : SvXMLStyleContext(rImport)
240 // start import
241 XMLMarkerStyleImport aMarkerStyle( GetImport() );
242 aMarkerStyle.importXML( xAttrList, maAny, maStrName );
245 XMLMarkerStyleContext::~XMLMarkerStyleContext()
249 void XMLMarkerStyleContext::endFastElement(sal_Int32 )
251 uno::Reference< container::XNameContainer > xMarker( GetImport().GetMarkerHelper() );
255 if(xMarker.is())
257 if( xMarker->hasByName( maStrName ) )
259 xMarker->replaceByName( maStrName, maAny );
261 else
263 xMarker->insertByName( maStrName, maAny );
267 catch( container::ElementExistException& )
271 bool XMLMarkerStyleContext::IsTransient() const
273 return true;
277 XMLDashStyleContext::XMLDashStyleContext( SvXMLImport& rImport, sal_Int32 /*nElement*/,
278 const uno::Reference< xml::sax::XFastAttributeList >& xAttrList)
279 : SvXMLStyleContext(rImport)
281 // start import
282 XMLDashStyleImport aDashStyle( GetImport() );
283 aDashStyle.importXML( xAttrList, maAny, maStrName );
286 XMLDashStyleContext::~XMLDashStyleContext()
290 void XMLDashStyleContext::endFastElement(sal_Int32 )
292 uno::Reference< container::XNameContainer > xDashes( GetImport().GetDashHelper() );
296 if(xDashes.is())
298 if( xDashes->hasByName( maStrName ) )
300 xDashes->replaceByName( maStrName, maAny );
302 else
304 xDashes->insertByName( maStrName, maAny );
308 catch( container::ElementExistException& )
312 bool XMLDashStyleContext::IsTransient() const
314 return true;
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */