1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_xmloff.hxx"
30*cdf0e10cSrcweir #include <tools/debug.hxx>
31*cdf0e10cSrcweir #include <com/sun/star/io/XOutputStream.hpp>
32*cdf0e10cSrcweir #include <xmloff/xmltkmap.hxx>
33*cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
34*cdf0e10cSrcweir #include "xmloff/xmlnmspe.hxx"
35*cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
36*cdf0e10cSrcweir #include <xmloff/xmlimp.hxx>
37*cdf0e10cSrcweir #include <xmloff/nmspmap.hxx>
38*cdf0e10cSrcweir #include <xmloff/XMLBase64ImportContext.hxx>
39*cdf0e10cSrcweir #include "XMLBackgroundImageContext.hxx"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir using ::rtl::OUString;
42*cdf0e10cSrcweir using ::rtl::OUStringBuffer;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir using namespace ::com::sun::star;
45*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46*cdf0e10cSrcweir using namespace ::com::sun::star::style;
47*cdf0e10cSrcweir using namespace ::com::sun::star::io;
48*cdf0e10cSrcweir using namespace ::xmloff::token;
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir enum SvXMLTokenMapAttrs
51*cdf0e10cSrcweir {
52*cdf0e10cSrcweir 	XML_TOK_BGIMG_HREF,
53*cdf0e10cSrcweir 	XML_TOK_BGIMG_TYPE,
54*cdf0e10cSrcweir 	XML_TOK_BGIMG_ACTUATE,
55*cdf0e10cSrcweir 	XML_TOK_BGIMG_SHOW,
56*cdf0e10cSrcweir 	XML_TOK_BGIMG_POSITION,
57*cdf0e10cSrcweir 	XML_TOK_BGIMG_REPEAT,
58*cdf0e10cSrcweir 	XML_TOK_BGIMG_FILTER,
59*cdf0e10cSrcweir     XML_TOK_BGIMG_OPACITY,
60*cdf0e10cSrcweir 	XML_TOK_NGIMG_END=XML_TOK_UNKNOWN
61*cdf0e10cSrcweir };
62*cdf0e10cSrcweir const SvXMLTokenMapEntry* lcl_getBGImgAttributesAttrTokenMap()
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir     static __FAR_DATA SvXMLTokenMapEntry aBGImgAttributesAttrTokenMap[] =
65*cdf0e10cSrcweir     {
66*cdf0e10cSrcweir 	    { XML_NAMESPACE_XLINK, XML_HREF, 		XML_TOK_BGIMG_HREF		},
67*cdf0e10cSrcweir 	    { XML_NAMESPACE_XLINK, XML_TYPE, 		XML_TOK_BGIMG_TYPE		},
68*cdf0e10cSrcweir 	    { XML_NAMESPACE_XLINK, XML_ACTUATE,	    XML_TOK_BGIMG_ACTUATE	},
69*cdf0e10cSrcweir 	    { XML_NAMESPACE_XLINK, XML_SHOW, 		XML_TOK_BGIMG_SHOW 		},
70*cdf0e10cSrcweir 	    { XML_NAMESPACE_STYLE, XML_POSITION, 	XML_TOK_BGIMG_POSITION	},
71*cdf0e10cSrcweir 	    { XML_NAMESPACE_STYLE, XML_REPEAT, 	    XML_TOK_BGIMG_REPEAT	},
72*cdf0e10cSrcweir 	    { XML_NAMESPACE_STYLE, XML_FILTER_NAME, XML_TOK_BGIMG_FILTER	},
73*cdf0e10cSrcweir         { XML_NAMESPACE_DRAW,  XML_OPACITY,		XML_TOK_BGIMG_OPACITY	},
74*cdf0e10cSrcweir 	    XML_TOKEN_MAP_END
75*cdf0e10cSrcweir     };
76*cdf0e10cSrcweir     return aBGImgAttributesAttrTokenMap;
77*cdf0e10cSrcweir }
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir SvXMLEnumMapEntry psXML_BrushHoriPos[] =
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir 	{ XML_LEFT, 		GraphicLocation_LEFT_MIDDLE	},
84*cdf0e10cSrcweir 	{ XML_RIGHT,		GraphicLocation_RIGHT_MIDDLE	},
85*cdf0e10cSrcweir 	{ XML_TOKEN_INVALID,					0			}
86*cdf0e10cSrcweir };
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir SvXMLEnumMapEntry psXML_BrushVertPos[] =
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir 	{ XML_TOP,			GraphicLocation_MIDDLE_TOP	},
91*cdf0e10cSrcweir 	{ XML_BOTTOM,		GraphicLocation_MIDDLE_BOTTOM	},
92*cdf0e10cSrcweir 	{ XML_TOKEN_INVALID,					0			}
93*cdf0e10cSrcweir };
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir void lcl_xmlbic_MergeHoriPos( GraphicLocation& ePos,
96*cdf0e10cSrcweir 								   GraphicLocation eHori )
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir 	DBG_ASSERT( GraphicLocation_LEFT_MIDDLE==eHori ||
99*cdf0e10cSrcweir 				GraphicLocation_MIDDLE_MIDDLE==eHori ||
100*cdf0e10cSrcweir 				GraphicLocation_RIGHT_MIDDLE==eHori,
101*cdf0e10cSrcweir 				"lcl_xmlbic_MergeHoriPos: vertical pos must be middle" );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 	switch( ePos )
104*cdf0e10cSrcweir 	{
105*cdf0e10cSrcweir 	case GraphicLocation_LEFT_TOP:
106*cdf0e10cSrcweir 	case GraphicLocation_MIDDLE_TOP:
107*cdf0e10cSrcweir 	case GraphicLocation_RIGHT_TOP:
108*cdf0e10cSrcweir 		ePos = GraphicLocation_LEFT_MIDDLE==eHori
109*cdf0e10cSrcweir 				? GraphicLocation_LEFT_TOP
110*cdf0e10cSrcweir 				: (GraphicLocation_MIDDLE_MIDDLE==eHori
111*cdf0e10cSrcweir 						? GraphicLocation_MIDDLE_TOP
112*cdf0e10cSrcweir 						: GraphicLocation_RIGHT_TOP);
113*cdf0e10cSrcweir 		break;
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	case GraphicLocation_LEFT_MIDDLE:
116*cdf0e10cSrcweir 	case GraphicLocation_MIDDLE_MIDDLE:
117*cdf0e10cSrcweir 	case GraphicLocation_RIGHT_MIDDLE:
118*cdf0e10cSrcweir 		ePos = eHori;
119*cdf0e10cSrcweir 		break;
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 	case GraphicLocation_LEFT_BOTTOM:
122*cdf0e10cSrcweir 	case GraphicLocation_MIDDLE_BOTTOM:
123*cdf0e10cSrcweir 	case GraphicLocation_RIGHT_BOTTOM:
124*cdf0e10cSrcweir 		ePos = GraphicLocation_LEFT_MIDDLE==eHori
125*cdf0e10cSrcweir 				? GraphicLocation_LEFT_BOTTOM
126*cdf0e10cSrcweir 				: (GraphicLocation_MIDDLE_MIDDLE==eHori
127*cdf0e10cSrcweir 						? GraphicLocation_MIDDLE_BOTTOM
128*cdf0e10cSrcweir 						: GraphicLocation_RIGHT_BOTTOM);
129*cdf0e10cSrcweir 		break;
130*cdf0e10cSrcweir 	default:
131*cdf0e10cSrcweir 		break;
132*cdf0e10cSrcweir 	}
133*cdf0e10cSrcweir }
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir void lcl_xmlbic_MergeVertPos( GraphicLocation& ePos,
136*cdf0e10cSrcweir 							  	   			  GraphicLocation eVert )
137*cdf0e10cSrcweir {
138*cdf0e10cSrcweir 	DBG_ASSERT( GraphicLocation_MIDDLE_TOP==eVert ||
139*cdf0e10cSrcweir 				GraphicLocation_MIDDLE_MIDDLE==eVert ||
140*cdf0e10cSrcweir 				GraphicLocation_MIDDLE_BOTTOM==eVert,
141*cdf0e10cSrcweir 				"lcl_xmlbic_MergeVertPos: horizontal pos must be middle" );
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 	switch( ePos )
144*cdf0e10cSrcweir 	{
145*cdf0e10cSrcweir 	case GraphicLocation_LEFT_TOP:
146*cdf0e10cSrcweir 	case GraphicLocation_LEFT_MIDDLE:
147*cdf0e10cSrcweir 	case GraphicLocation_LEFT_BOTTOM:
148*cdf0e10cSrcweir 		ePos = GraphicLocation_MIDDLE_TOP==eVert
149*cdf0e10cSrcweir 				? GraphicLocation_LEFT_TOP
150*cdf0e10cSrcweir 				: (GraphicLocation_MIDDLE_MIDDLE==eVert
151*cdf0e10cSrcweir 						? GraphicLocation_LEFT_MIDDLE
152*cdf0e10cSrcweir 						: GraphicLocation_LEFT_BOTTOM);
153*cdf0e10cSrcweir 		ePos = eVert;
154*cdf0e10cSrcweir 		break;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 	case GraphicLocation_MIDDLE_TOP:
157*cdf0e10cSrcweir 	case GraphicLocation_MIDDLE_MIDDLE:
158*cdf0e10cSrcweir 	case GraphicLocation_MIDDLE_BOTTOM:
159*cdf0e10cSrcweir 		ePos = eVert;
160*cdf0e10cSrcweir 		break;
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 	case GraphicLocation_RIGHT_TOP:
163*cdf0e10cSrcweir 	case GraphicLocation_RIGHT_MIDDLE:
164*cdf0e10cSrcweir 	case GraphicLocation_RIGHT_BOTTOM:
165*cdf0e10cSrcweir 		ePos = GraphicLocation_MIDDLE_TOP==eVert
166*cdf0e10cSrcweir 				? GraphicLocation_RIGHT_TOP
167*cdf0e10cSrcweir 				: (GraphicLocation_MIDDLE_MIDDLE==eVert
168*cdf0e10cSrcweir 						? GraphicLocation_RIGHT_MIDDLE
169*cdf0e10cSrcweir 						: GraphicLocation_RIGHT_BOTTOM);
170*cdf0e10cSrcweir 		break;
171*cdf0e10cSrcweir 	default:
172*cdf0e10cSrcweir 		break;
173*cdf0e10cSrcweir 	}
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir TYPEINIT1( XMLBackgroundImageContext, XMLElementPropertyContext );
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir void XMLBackgroundImageContext::ProcessAttrs(
179*cdf0e10cSrcweir 		const Reference< xml::sax::XAttributeList >& xAttrList )
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir 	SvXMLTokenMap aTokenMap( lcl_getBGImgAttributesAttrTokenMap() );
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 	ePos = GraphicLocation_NONE;
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
186*cdf0e10cSrcweir 	for( sal_Int16 i=0; i < nAttrCount; i++ )
187*cdf0e10cSrcweir 	{
188*cdf0e10cSrcweir 		const OUString& rAttrName = xAttrList->getNameByIndex( i );
189*cdf0e10cSrcweir 		OUString aLocalName;
190*cdf0e10cSrcweir 		sal_uInt16 nPrefix =
191*cdf0e10cSrcweir 			GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
192*cdf0e10cSrcweir 															&aLocalName );
193*cdf0e10cSrcweir 		const OUString& rValue = xAttrList->getValueByIndex( i );
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir 		switch( aTokenMap.Get( nPrefix, aLocalName ) )
196*cdf0e10cSrcweir 		{
197*cdf0e10cSrcweir 		case XML_TOK_BGIMG_HREF:
198*cdf0e10cSrcweir 			sURL = rValue;
199*cdf0e10cSrcweir 			if( GraphicLocation_NONE == ePos )
200*cdf0e10cSrcweir 				ePos = GraphicLocation_TILED;
201*cdf0e10cSrcweir 			break;
202*cdf0e10cSrcweir 		case XML_TOK_BGIMG_TYPE:
203*cdf0e10cSrcweir 		case XML_TOK_BGIMG_ACTUATE:
204*cdf0e10cSrcweir 		case XML_TOK_BGIMG_SHOW:
205*cdf0e10cSrcweir 			break;
206*cdf0e10cSrcweir 		case XML_TOK_BGIMG_POSITION:
207*cdf0e10cSrcweir 			{
208*cdf0e10cSrcweir 				GraphicLocation eNewPos = GraphicLocation_NONE, eTmp;
209*cdf0e10cSrcweir 				sal_uInt16 nTmp;
210*cdf0e10cSrcweir 				SvXMLTokenEnumerator aTokenEnum( rValue );
211*cdf0e10cSrcweir 				OUString aToken;
212*cdf0e10cSrcweir 				sal_Bool bHori = sal_False, bVert = sal_False;
213*cdf0e10cSrcweir 				sal_Bool bOK = sal_True;
214*cdf0e10cSrcweir 				while( bOK && aTokenEnum.getNextToken( aToken ) )
215*cdf0e10cSrcweir 				{
216*cdf0e10cSrcweir 					if( bHori && bVert )
217*cdf0e10cSrcweir 					{
218*cdf0e10cSrcweir 						bOK = sal_False;
219*cdf0e10cSrcweir 					}
220*cdf0e10cSrcweir 					else if( -1 != aToken.indexOf( sal_Unicode('%') ) )
221*cdf0e10cSrcweir 					{
222*cdf0e10cSrcweir 						sal_Int32 nPrc = 50;
223*cdf0e10cSrcweir 						if( SvXMLUnitConverter::convertPercent( nPrc, aToken ) )
224*cdf0e10cSrcweir 						{
225*cdf0e10cSrcweir 							if( !bHori )
226*cdf0e10cSrcweir 							{
227*cdf0e10cSrcweir 								eNewPos = nPrc < 25
228*cdf0e10cSrcweir 									? GraphicLocation_LEFT_TOP
229*cdf0e10cSrcweir 									: (nPrc < 75 ? GraphicLocation_MIDDLE_MIDDLE
230*cdf0e10cSrcweir 												: GraphicLocation_RIGHT_BOTTOM);
231*cdf0e10cSrcweir 								bHori = sal_True;
232*cdf0e10cSrcweir 							}
233*cdf0e10cSrcweir 							else
234*cdf0e10cSrcweir 							{
235*cdf0e10cSrcweir 								eTmp = nPrc < 25
236*cdf0e10cSrcweir 									? GraphicLocation_LEFT_TOP
237*cdf0e10cSrcweir 									: (nPrc < 75 ? GraphicLocation_LEFT_MIDDLE
238*cdf0e10cSrcweir 											     : GraphicLocation_LEFT_BOTTOM);
239*cdf0e10cSrcweir 								lcl_xmlbic_MergeVertPos( eNewPos, eTmp );
240*cdf0e10cSrcweir 								bVert = sal_True;
241*cdf0e10cSrcweir 							}
242*cdf0e10cSrcweir 						}
243*cdf0e10cSrcweir 						else
244*cdf0e10cSrcweir 						{
245*cdf0e10cSrcweir 							// wrong percentage
246*cdf0e10cSrcweir 							bOK = sal_False;
247*cdf0e10cSrcweir 						}
248*cdf0e10cSrcweir 					}
249*cdf0e10cSrcweir 					else if( IsXMLToken( aToken, XML_CENTER ) )
250*cdf0e10cSrcweir 					{
251*cdf0e10cSrcweir 						if( bHori )
252*cdf0e10cSrcweir 							lcl_xmlbic_MergeVertPos( eNewPos,
253*cdf0e10cSrcweir 										  GraphicLocation_MIDDLE_MIDDLE );
254*cdf0e10cSrcweir 						else if ( bVert )
255*cdf0e10cSrcweir 							lcl_xmlbic_MergeHoriPos( eNewPos,
256*cdf0e10cSrcweir 										  GraphicLocation_MIDDLE_MIDDLE );
257*cdf0e10cSrcweir 						else
258*cdf0e10cSrcweir 							eNewPos = GraphicLocation_MIDDLE_MIDDLE;
259*cdf0e10cSrcweir 					}
260*cdf0e10cSrcweir 					else if( SvXMLUnitConverter::convertEnum( nTmp, aToken,
261*cdf0e10cSrcweir 														 psXML_BrushHoriPos ) )
262*cdf0e10cSrcweir 					{
263*cdf0e10cSrcweir 						if( bVert )
264*cdf0e10cSrcweir 							lcl_xmlbic_MergeHoriPos( eNewPos,
265*cdf0e10cSrcweir 										(GraphicLocation)nTmp );
266*cdf0e10cSrcweir 						else if( !bHori )
267*cdf0e10cSrcweir 							eNewPos = (GraphicLocation)nTmp;
268*cdf0e10cSrcweir 						else
269*cdf0e10cSrcweir 							bOK = sal_False;
270*cdf0e10cSrcweir 						bHori = sal_True;
271*cdf0e10cSrcweir 					}
272*cdf0e10cSrcweir 					else if( SvXMLUnitConverter::convertEnum( nTmp, aToken,
273*cdf0e10cSrcweir 														 psXML_BrushVertPos ) )
274*cdf0e10cSrcweir 					{
275*cdf0e10cSrcweir 						if( bHori )
276*cdf0e10cSrcweir 							lcl_xmlbic_MergeVertPos( eNewPos,
277*cdf0e10cSrcweir 											(GraphicLocation)nTmp );
278*cdf0e10cSrcweir 						else if( !bVert )
279*cdf0e10cSrcweir 							eNewPos = (GraphicLocation)nTmp;
280*cdf0e10cSrcweir 						else
281*cdf0e10cSrcweir 							bOK = sal_False;
282*cdf0e10cSrcweir 						bVert = sal_True;
283*cdf0e10cSrcweir 					}
284*cdf0e10cSrcweir 					else
285*cdf0e10cSrcweir 					{
286*cdf0e10cSrcweir 						bOK = sal_False;
287*cdf0e10cSrcweir 					}
288*cdf0e10cSrcweir 				}
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir 				bOK &= GraphicLocation_NONE != eNewPos;
291*cdf0e10cSrcweir 				if( bOK )
292*cdf0e10cSrcweir 					ePos = eNewPos;
293*cdf0e10cSrcweir 			}
294*cdf0e10cSrcweir 			break;
295*cdf0e10cSrcweir 		case XML_TOK_BGIMG_REPEAT:
296*cdf0e10cSrcweir 			{
297*cdf0e10cSrcweir 				sal_uInt16 nPos = GraphicLocation_NONE;
298*cdf0e10cSrcweir                 static SvXMLEnumMapEntry psXML_BrushRepeat[] =
299*cdf0e10cSrcweir                 {
300*cdf0e10cSrcweir 	                { XML_BACKGROUND_REPEAT,		GraphicLocation_TILED	},
301*cdf0e10cSrcweir 	                { XML_BACKGROUND_NO_REPEAT, 	GraphicLocation_MIDDLE_MIDDLE		},
302*cdf0e10cSrcweir 	                { XML_BACKGROUND_STRETCH,		GraphicLocation_AREA	},
303*cdf0e10cSrcweir 	                { XML_TOKEN_INVALID,			0			}
304*cdf0e10cSrcweir                 };
305*cdf0e10cSrcweir 				if( SvXMLUnitConverter::convertEnum( nPos, rValue,
306*cdf0e10cSrcweir 												psXML_BrushRepeat ) )
307*cdf0e10cSrcweir 				{
308*cdf0e10cSrcweir 					if( GraphicLocation_MIDDLE_MIDDLE != nPos ||
309*cdf0e10cSrcweir 						GraphicLocation_NONE == ePos ||
310*cdf0e10cSrcweir 						GraphicLocation_AREA == ePos ||
311*cdf0e10cSrcweir 						GraphicLocation_TILED == ePos )
312*cdf0e10cSrcweir 						ePos = (GraphicLocation)nPos;
313*cdf0e10cSrcweir 				}
314*cdf0e10cSrcweir 			}
315*cdf0e10cSrcweir 			break;
316*cdf0e10cSrcweir 		case XML_TOK_BGIMG_FILTER:
317*cdf0e10cSrcweir 			sFilter = rValue;
318*cdf0e10cSrcweir 			break;
319*cdf0e10cSrcweir         case XML_TOK_BGIMG_OPACITY:
320*cdf0e10cSrcweir             {
321*cdf0e10cSrcweir                 sal_Int32 nTmp;
322*cdf0e10cSrcweir                 // convert from percent and clip
323*cdf0e10cSrcweir                 if( SvXMLUnitConverter::convertPercent( nTmp, rValue ) )
324*cdf0e10cSrcweir                 {
325*cdf0e10cSrcweir                     if( (nTmp >= 0) && (nTmp <= 100) )
326*cdf0e10cSrcweir                         nTransparency = static_cast<sal_Int8>( 100-nTmp );
327*cdf0e10cSrcweir                 }
328*cdf0e10cSrcweir             }
329*cdf0e10cSrcweir             break;
330*cdf0e10cSrcweir 		}
331*cdf0e10cSrcweir 	}
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir }
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir XMLBackgroundImageContext::XMLBackgroundImageContext(
336*cdf0e10cSrcweir 		SvXMLImport& rImport, sal_uInt16 nPrfx,
337*cdf0e10cSrcweir 		const OUString& rLName,
338*cdf0e10cSrcweir 		const Reference< xml::sax::XAttributeList > & xAttrList,
339*cdf0e10cSrcweir 		const XMLPropertyState& rProp,
340*cdf0e10cSrcweir 		sal_Int32 nPosIdx,
341*cdf0e10cSrcweir 		sal_Int32 nFilterIdx,
342*cdf0e10cSrcweir         sal_Int32 nTransparencyIdx,
343*cdf0e10cSrcweir 		::std::vector< XMLPropertyState > &rProps ) :
344*cdf0e10cSrcweir 	XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ),
345*cdf0e10cSrcweir 	aPosProp( nPosIdx ),
346*cdf0e10cSrcweir 	aFilterProp( nFilterIdx ),
347*cdf0e10cSrcweir     aTransparencyProp( nTransparencyIdx ),
348*cdf0e10cSrcweir     nTransparency( 0 )
349*cdf0e10cSrcweir {
350*cdf0e10cSrcweir 	ProcessAttrs( xAttrList );
351*cdf0e10cSrcweir }
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir XMLBackgroundImageContext::~XMLBackgroundImageContext()
354*cdf0e10cSrcweir {
355*cdf0e10cSrcweir }
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir SvXMLImportContext *XMLBackgroundImageContext::CreateChildContext(
358*cdf0e10cSrcweir 		sal_uInt16 nPrefix, const OUString& rLocalName,
359*cdf0e10cSrcweir 		const Reference< xml::sax::XAttributeList > & xAttrList )
360*cdf0e10cSrcweir {
361*cdf0e10cSrcweir 	SvXMLImportContext *pContext = NULL;
362*cdf0e10cSrcweir 	if( (XML_NAMESPACE_OFFICE == nPrefix) &&
363*cdf0e10cSrcweir 		xmloff::token::IsXMLToken( rLocalName,
364*cdf0e10cSrcweir 										xmloff::token::XML_BINARY_DATA ) )
365*cdf0e10cSrcweir 	{
366*cdf0e10cSrcweir 		if( !sURL.getLength() && !xBase64Stream.is() )
367*cdf0e10cSrcweir 		{
368*cdf0e10cSrcweir 			xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64();
369*cdf0e10cSrcweir 			if( xBase64Stream.is() )
370*cdf0e10cSrcweir 				pContext = new XMLBase64ImportContext( GetImport(), nPrefix,
371*cdf0e10cSrcweir 													rLocalName, xAttrList,
372*cdf0e10cSrcweir 													xBase64Stream );
373*cdf0e10cSrcweir 		}
374*cdf0e10cSrcweir 	}
375*cdf0e10cSrcweir 	if( !pContext )
376*cdf0e10cSrcweir 	{
377*cdf0e10cSrcweir 		pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
378*cdf0e10cSrcweir 	}
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir 	return pContext;
381*cdf0e10cSrcweir }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir void XMLBackgroundImageContext::EndElement()
384*cdf0e10cSrcweir {
385*cdf0e10cSrcweir 	if( sURL.getLength() )
386*cdf0e10cSrcweir 	{
387*cdf0e10cSrcweir 		sURL = GetImport().ResolveGraphicObjectURL( sURL, sal_False );
388*cdf0e10cSrcweir 	}
389*cdf0e10cSrcweir 	else if( xBase64Stream.is() )
390*cdf0e10cSrcweir 	{
391*cdf0e10cSrcweir 		sURL = GetImport().ResolveGraphicObjectURLFromBase64( xBase64Stream );
392*cdf0e10cSrcweir 		xBase64Stream = 0;
393*cdf0e10cSrcweir 	}
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir 	if( !sURL.getLength() )
396*cdf0e10cSrcweir 		ePos = GraphicLocation_NONE;
397*cdf0e10cSrcweir 	else if( GraphicLocation_NONE == ePos )
398*cdf0e10cSrcweir 		ePos = GraphicLocation_TILED;
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir 	aProp.maValue <<= sURL;
401*cdf0e10cSrcweir 	aPosProp.maValue <<= ePos;
402*cdf0e10cSrcweir 	aFilterProp.maValue <<= sFilter;
403*cdf0e10cSrcweir     aTransparencyProp.maValue <<= nTransparency;
404*cdf0e10cSrcweir 
405*cdf0e10cSrcweir 	SetInsert( sal_True );
406*cdf0e10cSrcweir 	XMLElementPropertyContext::EndElement();
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir 	if( -1 != aPosProp.mnIndex )
409*cdf0e10cSrcweir 		rProperties.push_back( aPosProp );
410*cdf0e10cSrcweir 	if( -1 != aFilterProp.mnIndex )
411*cdf0e10cSrcweir 		rProperties.push_back( aFilterProp );
412*cdf0e10cSrcweir 	if( -1 != aTransparencyProp.mnIndex )
413*cdf0e10cSrcweir 		rProperties.push_back( aTransparencyProp );
414*cdf0e10cSrcweir }
415