1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
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() );
59 if( xGradient
->hasByName( maStrName
) )
61 xGradient
->replaceByName( maStrName
, maAny
);
65 xGradient
->insertByName( maStrName
, maAny
);
69 catch( container::ElementExistException
& )
73 bool XMLGradientStyleContext::IsTransient() const
79 XMLHatchStyleContext::XMLHatchStyleContext( SvXMLImport
& rImport
, sal_Int32
/*nElement*/,
80 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
81 : SvXMLStyleContext(rImport
)
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() );
100 if( xHatch
->hasByName( maStrName
) )
102 xHatch
->replaceByName( maStrName
, maAny
);
106 xHatch
->insertByName( maStrName
, maAny
);
110 catch( container::ElementExistException
& )
114 bool XMLHatchStyleContext::IsTransient() const
120 XMLBitmapStyleContext::XMLBitmapStyleContext( SvXMLImport
& rImport
, sal_Int32
/*nElement*/,
121 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
122 : SvXMLStyleContext(rImport
)
125 XMLImageStyle::importXML( xAttrList
, maAny
, maStrName
, rImport
);
128 XMLBitmapStyleContext::~XMLBitmapStyleContext()
132 css::uno::Reference
< css::xml::sax::XFastContextHandler
> XMLBitmapStyleContext::createFastChildContext(
134 const css::uno::Reference
< css::xml::sax::XFastAttributeList
>& )
136 if( nElement
== XML_ELEMENT(OFFICE
, xmloff::token::XML_BINARY_DATA
) )
140 if( sURL
.isEmpty() && !mxBase64Stream
.is() )
142 mxBase64Stream
= GetImport().GetStreamForGraphicObjectURLFromBase64();
143 if( mxBase64Stream
.is() )
144 return new XMLBase64ImportContext( GetImport(), mxBase64Stream
);
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
);
163 if (!maAny
.has
<uno::Reference
<graphic::XGraphic
>>())
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
));
181 xBitmapContainer
->insertByName(maStrName
, uno::Any(xBitmap
));
185 catch (container::ElementExistException
&)
189 bool XMLBitmapStyleContext::IsTransient() const
195 XMLTransGradientStyleContext::XMLTransGradientStyleContext( SvXMLImport
& rImport
, sal_Int32
/*nElement*/,
196 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
197 : SvXMLStyleContext(rImport
)
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
);
222 xTransGradient
->insertByName( maStrName
, maAny
);
226 catch( container::ElementExistException
& )
230 bool XMLTransGradientStyleContext::IsTransient() const
236 XMLMarkerStyleContext::XMLMarkerStyleContext( SvXMLImport
& rImport
, sal_Int32
/*nElement*/,
237 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
238 : SvXMLStyleContext(rImport
)
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() );
257 if( xMarker
->hasByName( maStrName
) )
259 xMarker
->replaceByName( maStrName
, maAny
);
263 xMarker
->insertByName( maStrName
, maAny
);
267 catch( container::ElementExistException
& )
271 bool XMLMarkerStyleContext::IsTransient() const
277 XMLDashStyleContext::XMLDashStyleContext( SvXMLImport
& rImport
, sal_Int32
/*nElement*/,
278 const uno::Reference
< xml::sax::XFastAttributeList
>& xAttrList
)
279 : SvXMLStyleContext(rImport
)
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() );
298 if( xDashes
->hasByName( maStrName
) )
300 xDashes
->replaceByName( maStrName
, maAny
);
304 xDashes
->insertByName( maStrName
, maAny
);
308 catch( container::ElementExistException
& )
312 bool XMLDashStyleContext::IsTransient() const
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */