1*63bba73cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63bba73cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63bba73cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63bba73cSAndrew Rist  * distributed with this work for additional information
6*63bba73cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63bba73cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63bba73cSAndrew Rist  * "License"); you may not use this file except in compliance
9*63bba73cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63bba73cSAndrew Rist  *
11*63bba73cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63bba73cSAndrew Rist  *
13*63bba73cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63bba73cSAndrew Rist  * software distributed under the License is distributed on an
15*63bba73cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63bba73cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63bba73cSAndrew Rist  * specific language governing permissions and limitations
18*63bba73cSAndrew Rist  * under the License.
19*63bba73cSAndrew Rist  *
20*63bba73cSAndrew Rist  *************************************************************/
21*63bba73cSAndrew Rist 
22*63bba73cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
26cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
27cdf0e10cSrcweir #include "FillStyleContext.hxx"
28cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
29cdf0e10cSrcweir #include "xmloff/GradientStyle.hxx"
30cdf0e10cSrcweir #include "xmloff/HatchStyle.hxx"
31cdf0e10cSrcweir #include "xmloff/ImageStyle.hxx"
32cdf0e10cSrcweir #include "TransGradientStyle.hxx"
33cdf0e10cSrcweir #include "xmloff/MarkerStyle.hxx"
34cdf0e10cSrcweir #include "xmloff/DashStyle.hxx"
35cdf0e10cSrcweir #include <xmloff/families.hxx>
36cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
37cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
38cdf0e10cSrcweir #include <xmloff/XMLBase64ImportContext.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace ::com::sun::star;
41cdf0e10cSrcweir using ::rtl::OUString;
42cdf0e10cSrcweir using ::rtl::OUStringBuffer;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
46cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
47cdf0e10cSrcweir 
48cdf0e10cSrcweir TYPEINIT1( XMLGradientStyleContext, SvXMLStyleContext );
49cdf0e10cSrcweir 
XMLGradientStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)50cdf0e10cSrcweir XMLGradientStyleContext::XMLGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
51cdf0e10cSrcweir 										      const OUString& rLName,
52cdf0e10cSrcweir 											  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
53cdf0e10cSrcweir :	SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	// set Family
56cdf0e10cSrcweir //	SetFamily( XML_STYLE_FAMILY_FILLSTYLE_GRADIENT_ID );
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	// start import
59cdf0e10cSrcweir 	XMLGradientStyleImport aGradientStyle( GetImport() );
60cdf0e10cSrcweir 	aGradientStyle.importXML( xAttrList, maAny, maStrName );
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
~XMLGradientStyleContext()63cdf0e10cSrcweir XMLGradientStyleContext::~XMLGradientStyleContext()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
EndElement()67cdf0e10cSrcweir void XMLGradientStyleContext::EndElement()
68cdf0e10cSrcweir {
69cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xGradient( GetImport().GetGradientHelper() );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	try
72cdf0e10cSrcweir 	{
73cdf0e10cSrcweir 		if(xGradient.is())
74cdf0e10cSrcweir 		{
75cdf0e10cSrcweir 			if( xGradient->hasByName( maStrName ) )
76cdf0e10cSrcweir 			{
77cdf0e10cSrcweir 				xGradient->replaceByName( maStrName, maAny );
78cdf0e10cSrcweir 			}
79cdf0e10cSrcweir 			else
80cdf0e10cSrcweir 			{
81cdf0e10cSrcweir 				xGradient->insertByName( maStrName, maAny );
82cdf0e10cSrcweir 			}
83cdf0e10cSrcweir 		}
84cdf0e10cSrcweir 	}
85cdf0e10cSrcweir 	catch( container::ElementExistException& )
86cdf0e10cSrcweir 	{}
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
IsTransient() const89cdf0e10cSrcweir sal_Bool XMLGradientStyleContext::IsTransient() const
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	return sal_True;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
95cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
96cdf0e10cSrcweir 
97cdf0e10cSrcweir TYPEINIT1( XMLHatchStyleContext, SvXMLStyleContext );
98cdf0e10cSrcweir 
XMLHatchStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)99cdf0e10cSrcweir XMLHatchStyleContext::XMLHatchStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
100cdf0e10cSrcweir 										      const OUString& rLName,
101cdf0e10cSrcweir 											  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
102cdf0e10cSrcweir :	SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	// start import
105cdf0e10cSrcweir 	XMLHatchStyleImport aHatchStyle( GetImport() );
106cdf0e10cSrcweir 	aHatchStyle.importXML( xAttrList, maAny, maStrName );
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
~XMLHatchStyleContext()109cdf0e10cSrcweir XMLHatchStyleContext::~XMLHatchStyleContext()
110cdf0e10cSrcweir {
111cdf0e10cSrcweir }
112cdf0e10cSrcweir 
EndElement()113cdf0e10cSrcweir void XMLHatchStyleContext::EndElement()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xHatch( GetImport().GetHatchHelper() );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	try
118cdf0e10cSrcweir 	{
119cdf0e10cSrcweir 		if(xHatch.is())
120cdf0e10cSrcweir 		{
121cdf0e10cSrcweir 			if( xHatch->hasByName( maStrName ) )
122cdf0e10cSrcweir 			{
123cdf0e10cSrcweir 				xHatch->replaceByName( maStrName, maAny );
124cdf0e10cSrcweir 			}
125cdf0e10cSrcweir 			else
126cdf0e10cSrcweir 			{
127cdf0e10cSrcweir 				xHatch->insertByName( maStrName, maAny );
128cdf0e10cSrcweir 			}
129cdf0e10cSrcweir 		}
130cdf0e10cSrcweir 	}
131cdf0e10cSrcweir 	catch( container::ElementExistException& )
132cdf0e10cSrcweir 	{}
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
IsTransient() const135cdf0e10cSrcweir sal_Bool XMLHatchStyleContext::IsTransient() const
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	return sal_True;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
141cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
142cdf0e10cSrcweir 
143cdf0e10cSrcweir TYPEINIT1( XMLBitmapStyleContext, SvXMLStyleContext );
144cdf0e10cSrcweir 
XMLBitmapStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)145cdf0e10cSrcweir XMLBitmapStyleContext::XMLBitmapStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
146cdf0e10cSrcweir 										      const OUString& rLName,
147cdf0e10cSrcweir 											  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
148cdf0e10cSrcweir :	SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir 	// start import
151cdf0e10cSrcweir 	XMLImageStyle aBitmapStyle;
152cdf0e10cSrcweir 	aBitmapStyle.importXML( xAttrList, maAny, maStrName, rImport );
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
~XMLBitmapStyleContext()155cdf0e10cSrcweir XMLBitmapStyleContext::~XMLBitmapStyleContext()
156cdf0e10cSrcweir {
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
CreateChildContext(sal_uInt16 nPrefix,const::rtl::OUString & rLocalName,const::com::sun::star::uno::Reference<::com::sun::star::xml::sax::XAttributeList> & xAttrList)159cdf0e10cSrcweir SvXMLImportContext* XMLBitmapStyleContext::CreateChildContext( sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > & xAttrList )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir 	SvXMLImportContext *pContext = 0;
162cdf0e10cSrcweir 	if( (XML_NAMESPACE_OFFICE == nPrefix) && xmloff::token::IsXMLToken( rLocalName, xmloff::token::XML_BINARY_DATA ) )
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		OUString sURL;
165cdf0e10cSrcweir 		maAny >>= sURL;
166cdf0e10cSrcweir 		if( !sURL.getLength() && !mxBase64Stream.is() )
167cdf0e10cSrcweir 		{
168cdf0e10cSrcweir 			mxBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
169cdf0e10cSrcweir 			if( mxBase64Stream.is() )
170cdf0e10cSrcweir 				pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
171cdf0e10cSrcweir 													rLocalName, xAttrList,
172cdf0e10cSrcweir 													mxBase64Stream );
173cdf0e10cSrcweir 		}
174cdf0e10cSrcweir 	}
175cdf0e10cSrcweir 	if( !pContext )
176cdf0e10cSrcweir 	{
177cdf0e10cSrcweir 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	return pContext;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
EndElement()183cdf0e10cSrcweir void XMLBitmapStyleContext::EndElement()
184cdf0e10cSrcweir {
185cdf0e10cSrcweir 	OUString sURL;
186cdf0e10cSrcweir 	maAny >>= sURL;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	if( !sURL.getLength() && mxBase64Stream.is() )
189cdf0e10cSrcweir 	{
190cdf0e10cSrcweir 		sURL = GetImport().ResolveGraphicObjectURLFromBase64( mxBase64Stream );
191cdf0e10cSrcweir 		mxBase64Stream = 0;
192cdf0e10cSrcweir 		maAny <<= sURL;
193cdf0e10cSrcweir 	}
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xBitmap( GetImport().GetBitmapHelper() );
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 	try
198cdf0e10cSrcweir 	{
199cdf0e10cSrcweir 		if(xBitmap.is())
200cdf0e10cSrcweir 		{
201cdf0e10cSrcweir 			if( xBitmap->hasByName( maStrName ) )
202cdf0e10cSrcweir 			{
203cdf0e10cSrcweir 				xBitmap->replaceByName( maStrName, maAny );
204cdf0e10cSrcweir 			}
205cdf0e10cSrcweir 			else
206cdf0e10cSrcweir 			{
207cdf0e10cSrcweir 				xBitmap->insertByName( maStrName, maAny );
208cdf0e10cSrcweir 			}
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 	}
211cdf0e10cSrcweir 	catch( container::ElementExistException& )
212cdf0e10cSrcweir 	{}
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
IsTransient() const215cdf0e10cSrcweir sal_Bool XMLBitmapStyleContext::IsTransient() const
216cdf0e10cSrcweir {
217cdf0e10cSrcweir 	return sal_True;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 
221cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
222cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
223cdf0e10cSrcweir 
224cdf0e10cSrcweir TYPEINIT1( XMLTransGradientStyleContext, SvXMLStyleContext );
225cdf0e10cSrcweir 
XMLTransGradientStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)226cdf0e10cSrcweir XMLTransGradientStyleContext::XMLTransGradientStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
227cdf0e10cSrcweir 										      const OUString& rLName,
228cdf0e10cSrcweir 											  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
229cdf0e10cSrcweir :	SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
230cdf0e10cSrcweir {
231cdf0e10cSrcweir 	// start import
232cdf0e10cSrcweir 	XMLTransGradientStyleImport aTransGradientStyle( GetImport() );
233cdf0e10cSrcweir 	aTransGradientStyle.importXML( xAttrList, maAny, maStrName );
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
~XMLTransGradientStyleContext()236cdf0e10cSrcweir XMLTransGradientStyleContext::~XMLTransGradientStyleContext()
237cdf0e10cSrcweir {
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
EndElement()240cdf0e10cSrcweir void XMLTransGradientStyleContext::EndElement()
241cdf0e10cSrcweir {
242cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xTransGradient( GetImport().GetTransGradientHelper() );
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 	try
245cdf0e10cSrcweir 	{
246cdf0e10cSrcweir 		if(xTransGradient.is())
247cdf0e10cSrcweir 		{
248cdf0e10cSrcweir 			if( xTransGradient->hasByName( maStrName ) )
249cdf0e10cSrcweir 			{
250cdf0e10cSrcweir 				xTransGradient->replaceByName( maStrName, maAny );
251cdf0e10cSrcweir 			}
252cdf0e10cSrcweir 			else
253cdf0e10cSrcweir 			{
254cdf0e10cSrcweir 				xTransGradient->insertByName( maStrName, maAny );
255cdf0e10cSrcweir 			}
256cdf0e10cSrcweir 		}
257cdf0e10cSrcweir 	}
258cdf0e10cSrcweir 	catch( container::ElementExistException& )
259cdf0e10cSrcweir 	{}
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
IsTransient() const262cdf0e10cSrcweir sal_Bool XMLTransGradientStyleContext::IsTransient() const
263cdf0e10cSrcweir {
264cdf0e10cSrcweir 	return sal_True;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
268cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
269cdf0e10cSrcweir 
270cdf0e10cSrcweir TYPEINIT1( XMLMarkerStyleContext, SvXMLStyleContext );
271cdf0e10cSrcweir 
XMLMarkerStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)272cdf0e10cSrcweir XMLMarkerStyleContext::XMLMarkerStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
273cdf0e10cSrcweir 										      const OUString& rLName,
274cdf0e10cSrcweir 											  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
275cdf0e10cSrcweir :	SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
276cdf0e10cSrcweir {
277cdf0e10cSrcweir 	// start import
278cdf0e10cSrcweir 	XMLMarkerStyleImport aMarkerStyle( GetImport() );
279cdf0e10cSrcweir 	aMarkerStyle.importXML( xAttrList, maAny, maStrName );
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
~XMLMarkerStyleContext()282cdf0e10cSrcweir XMLMarkerStyleContext::~XMLMarkerStyleContext()
283cdf0e10cSrcweir {
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
EndElement()286cdf0e10cSrcweir void XMLMarkerStyleContext::EndElement()
287cdf0e10cSrcweir {
288cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xMarker( GetImport().GetMarkerHelper() );
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 	try
291cdf0e10cSrcweir 	{
292cdf0e10cSrcweir 		if(xMarker.is())
293cdf0e10cSrcweir 		{
294cdf0e10cSrcweir 			if( xMarker->hasByName( maStrName ) )
295cdf0e10cSrcweir 			{
296cdf0e10cSrcweir 				xMarker->replaceByName( maStrName, maAny );
297cdf0e10cSrcweir 			}
298cdf0e10cSrcweir 			else
299cdf0e10cSrcweir 			{
300cdf0e10cSrcweir 				xMarker->insertByName( maStrName, maAny );
301cdf0e10cSrcweir 			}
302cdf0e10cSrcweir 		}
303cdf0e10cSrcweir 	}
304cdf0e10cSrcweir 	catch( container::ElementExistException& )
305cdf0e10cSrcweir 	{}
306cdf0e10cSrcweir }
307cdf0e10cSrcweir 
IsTransient() const308cdf0e10cSrcweir sal_Bool XMLMarkerStyleContext::IsTransient() const
309cdf0e10cSrcweir {
310cdf0e10cSrcweir 	return sal_True;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
314cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
315cdf0e10cSrcweir 
316cdf0e10cSrcweir TYPEINIT1( XMLDashStyleContext, SvXMLStyleContext );
317cdf0e10cSrcweir 
XMLDashStyleContext(SvXMLImport & rImport,sal_uInt16 nPrfx,const OUString & rLName,const uno::Reference<xml::sax::XAttributeList> & xAttrList)318cdf0e10cSrcweir XMLDashStyleContext::XMLDashStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
319cdf0e10cSrcweir 										  const OUString& rLName,
320cdf0e10cSrcweir 										  const uno::Reference< xml::sax::XAttributeList >& xAttrList)
321cdf0e10cSrcweir :	SvXMLStyleContext(rImport, nPrfx, rLName, xAttrList)
322cdf0e10cSrcweir {
323cdf0e10cSrcweir 	// start import
324cdf0e10cSrcweir 	XMLDashStyleImport aDashStyle( GetImport() );
325cdf0e10cSrcweir 	aDashStyle.importXML( xAttrList, maAny, maStrName );
326cdf0e10cSrcweir }
327cdf0e10cSrcweir 
~XMLDashStyleContext()328cdf0e10cSrcweir XMLDashStyleContext::~XMLDashStyleContext()
329cdf0e10cSrcweir {
330cdf0e10cSrcweir }
331cdf0e10cSrcweir 
EndElement()332cdf0e10cSrcweir void XMLDashStyleContext::EndElement()
333cdf0e10cSrcweir {
334cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xDashes( GetImport().GetDashHelper() );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 	try
337cdf0e10cSrcweir 	{
338cdf0e10cSrcweir 		if(xDashes.is())
339cdf0e10cSrcweir 		{
340cdf0e10cSrcweir 			if( xDashes->hasByName( maStrName ) )
341cdf0e10cSrcweir 			{
342cdf0e10cSrcweir 				xDashes->replaceByName( maStrName, maAny );
343cdf0e10cSrcweir 			}
344cdf0e10cSrcweir 			else
345cdf0e10cSrcweir 			{
346cdf0e10cSrcweir 				xDashes->insertByName( maStrName, maAny );
347cdf0e10cSrcweir 			}
348cdf0e10cSrcweir 		}
349cdf0e10cSrcweir 	}
350cdf0e10cSrcweir 	catch( container::ElementExistException& )
351cdf0e10cSrcweir 	{}
352cdf0e10cSrcweir }
353cdf0e10cSrcweir 
IsTransient() const354cdf0e10cSrcweir sal_Bool XMLDashStyleContext::IsTransient() const
355cdf0e10cSrcweir {
356cdf0e10cSrcweir 	return sal_True;
357cdf0e10cSrcweir }
358