merge the formfield patch from ooo-build
[ooovba.git] / xmloff / source / style / XMLBackgroundImageExport.cxx
blob9bb32a935c679d2b55b8c0e5576d4afe48c1dfd0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLBackgroundImageExport.cxx,v $
10 * $Revision: 1.15 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_xmloff.hxx"
33 #include <com/sun/star/style/GraphicLocation.hpp>
35 #include <xmlnmspe.hxx>
36 #include <xmloff/xmltoken.hxx>
37 #include <rtl/ustrbuf.hxx>
38 #include <xmloff/xmlexp.hxx>
39 #include "XMLBackgroundImageExport.hxx"
40 #include <xmloff/xmluconv.hxx>
42 using ::rtl::OUString;
43 using ::rtl::OUStringBuffer;
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::style;
48 using namespace ::xmloff::token;
50 XMLBackgroundImageExport::XMLBackgroundImageExport( SvXMLExport& rExp ) :
51 rExport( rExp )
55 XMLBackgroundImageExport::~XMLBackgroundImageExport()
59 void XMLBackgroundImageExport::exportXML( const Any& rURL,
60 const Any *pPos,
61 const Any *pFilter,
62 const Any *pTransparency,
63 sal_uInt16 nPrefix,
64 const ::rtl::OUString& rLocalName )
66 GraphicLocation ePos;
67 if( !(pPos && ((*pPos) >>= ePos)) )
68 ePos = GraphicLocation_AREA;
70 OUString sURL;
71 rURL >>= sURL;
72 if( sURL.getLength() && GraphicLocation_NONE != ePos )
74 OUString sTempURL( GetExport().AddEmbeddedGraphicObject( sURL ) );
75 if( sTempURL.getLength() )
77 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sTempURL );
78 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE,
79 XML_SIMPLE );
80 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE,
81 XML_ONLOAD );
84 OUStringBuffer aOut;
85 switch( ePos )
87 case GraphicLocation_LEFT_TOP:
88 case GraphicLocation_MIDDLE_TOP:
89 case GraphicLocation_RIGHT_TOP:
90 aOut.append( GetXMLToken(XML_TOP) );
91 break;
92 case GraphicLocation_LEFT_MIDDLE:
93 case GraphicLocation_MIDDLE_MIDDLE:
94 case GraphicLocation_RIGHT_MIDDLE:
95 aOut.append( GetXMLToken(XML_CENTER) );
96 break;
97 case GraphicLocation_LEFT_BOTTOM:
98 case GraphicLocation_MIDDLE_BOTTOM:
99 case GraphicLocation_RIGHT_BOTTOM:
100 aOut.append( GetXMLToken(XML_BOTTOM) );
101 break;
102 default:
103 break;
106 if( aOut.getLength() )
108 aOut.append( sal_Unicode( ' ' ) );
110 switch( ePos )
112 case GraphicLocation_LEFT_TOP:
113 case GraphicLocation_LEFT_BOTTOM:
114 case GraphicLocation_LEFT_MIDDLE:
115 aOut.append( GetXMLToken(XML_LEFT) );
116 break;
117 case GraphicLocation_MIDDLE_TOP:
118 case GraphicLocation_MIDDLE_MIDDLE:
119 case GraphicLocation_MIDDLE_BOTTOM:
120 aOut.append( GetXMLToken(XML_CENTER) );
121 break;
122 case GraphicLocation_RIGHT_MIDDLE:
123 case GraphicLocation_RIGHT_TOP:
124 case GraphicLocation_RIGHT_BOTTOM:
125 aOut.append( GetXMLToken(XML_RIGHT) );
126 break;
127 default:
128 break;
131 if( aOut.getLength() )
132 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
133 XML_POSITION, aOut.makeStringAndClear() );
135 if( GraphicLocation_AREA == ePos )
137 aOut.append( GetXMLToken(XML_BACKGROUND_STRETCH) );
139 else if( GraphicLocation_NONE != ePos && GraphicLocation_TILED != ePos )
141 aOut.append( GetXMLToken(XML_BACKGROUND_NO_REPEAT) );
143 if( aOut.getLength() )
144 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REPEAT,
145 aOut.makeStringAndClear() );
147 if( pFilter )
149 OUString sFilter;
150 (*pFilter) >>= sFilter;
151 if( sFilter.getLength() )
152 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FILTER_NAME,
153 sFilter );
156 if( pTransparency )
158 sal_Int8 nTransparency = sal_Int8();
159 if( (*pTransparency) >>= nTransparency )
161 OUStringBuffer aTransOut;
162 SvXMLUnitConverter::convertPercent( aTransOut, 100-nTransparency );
163 GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_OPACITY,
164 aTransOut.makeStringAndClear() );
170 SvXMLElementExport aElem( GetExport(), nPrefix, rLocalName, sal_True, sal_True );
171 if( sURL.getLength() && GraphicLocation_NONE != ePos )
173 // optional office:binary-data
174 GetExport().AddEmbeddedGraphicObjectAsBase64( sURL );