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/style/GraphicLocation.hpp>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <xmloff/xmlnmspe.hxx>
29cdf0e10cSrcweir #include <xmloff/xmltoken.hxx>
30cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
31cdf0e10cSrcweir #include <xmloff/xmlexp.hxx>
32cdf0e10cSrcweir #include "XMLBackgroundImageExport.hxx"
33cdf0e10cSrcweir #include <xmloff/xmluconv.hxx>
34cdf0e10cSrcweir
35cdf0e10cSrcweir using ::rtl::OUString;
36cdf0e10cSrcweir using ::rtl::OUStringBuffer;
37cdf0e10cSrcweir
38cdf0e10cSrcweir using namespace ::com::sun::star;
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir using namespace ::com::sun::star::style;
41cdf0e10cSrcweir using namespace ::xmloff::token;
42cdf0e10cSrcweir
XMLBackgroundImageExport(SvXMLExport & rExp)43cdf0e10cSrcweir XMLBackgroundImageExport::XMLBackgroundImageExport( SvXMLExport& rExp ) :
44cdf0e10cSrcweir rExport( rExp )
45cdf0e10cSrcweir {
46cdf0e10cSrcweir }
47cdf0e10cSrcweir
~XMLBackgroundImageExport()48cdf0e10cSrcweir XMLBackgroundImageExport::~XMLBackgroundImageExport()
49cdf0e10cSrcweir {
50cdf0e10cSrcweir }
51cdf0e10cSrcweir
exportXML(const Any & rURL,const Any * pPos,const Any * pFilter,const Any * pTransparency,sal_uInt16 nPrefix,const::rtl::OUString & rLocalName)52cdf0e10cSrcweir void XMLBackgroundImageExport::exportXML( const Any& rURL,
53cdf0e10cSrcweir const Any *pPos,
54cdf0e10cSrcweir const Any *pFilter,
55cdf0e10cSrcweir const Any *pTransparency,
56cdf0e10cSrcweir sal_uInt16 nPrefix,
57cdf0e10cSrcweir const ::rtl::OUString& rLocalName )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir GraphicLocation ePos;
60cdf0e10cSrcweir if( !(pPos && ((*pPos) >>= ePos)) )
61cdf0e10cSrcweir ePos = GraphicLocation_AREA;
62cdf0e10cSrcweir
63cdf0e10cSrcweir OUString sURL;
64cdf0e10cSrcweir rURL >>= sURL;
65cdf0e10cSrcweir if( sURL.getLength() && GraphicLocation_NONE != ePos )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir OUString sTempURL( GetExport().AddEmbeddedGraphicObject( sURL ) );
68cdf0e10cSrcweir if( sTempURL.getLength() )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sTempURL );
71cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE,
72cdf0e10cSrcweir XML_SIMPLE );
73cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE,
74cdf0e10cSrcweir XML_ONLOAD );
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir OUStringBuffer aOut;
78cdf0e10cSrcweir switch( ePos )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir case GraphicLocation_LEFT_TOP:
81cdf0e10cSrcweir case GraphicLocation_MIDDLE_TOP:
82cdf0e10cSrcweir case GraphicLocation_RIGHT_TOP:
83cdf0e10cSrcweir aOut.append( GetXMLToken(XML_TOP) );
84cdf0e10cSrcweir break;
85cdf0e10cSrcweir case GraphicLocation_LEFT_MIDDLE:
86cdf0e10cSrcweir case GraphicLocation_MIDDLE_MIDDLE:
87cdf0e10cSrcweir case GraphicLocation_RIGHT_MIDDLE:
88cdf0e10cSrcweir aOut.append( GetXMLToken(XML_CENTER) );
89cdf0e10cSrcweir break;
90cdf0e10cSrcweir case GraphicLocation_LEFT_BOTTOM:
91cdf0e10cSrcweir case GraphicLocation_MIDDLE_BOTTOM:
92cdf0e10cSrcweir case GraphicLocation_RIGHT_BOTTOM:
93cdf0e10cSrcweir aOut.append( GetXMLToken(XML_BOTTOM) );
94cdf0e10cSrcweir break;
95cdf0e10cSrcweir default:
96cdf0e10cSrcweir break;
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
99cdf0e10cSrcweir if( aOut.getLength() )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir aOut.append( sal_Unicode( ' ' ) );
102cdf0e10cSrcweir
103cdf0e10cSrcweir switch( ePos )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir case GraphicLocation_LEFT_TOP:
106cdf0e10cSrcweir case GraphicLocation_LEFT_BOTTOM:
107cdf0e10cSrcweir case GraphicLocation_LEFT_MIDDLE:
108cdf0e10cSrcweir aOut.append( GetXMLToken(XML_LEFT) );
109cdf0e10cSrcweir break;
110cdf0e10cSrcweir case GraphicLocation_MIDDLE_TOP:
111cdf0e10cSrcweir case GraphicLocation_MIDDLE_MIDDLE:
112cdf0e10cSrcweir case GraphicLocation_MIDDLE_BOTTOM:
113cdf0e10cSrcweir aOut.append( GetXMLToken(XML_CENTER) );
114cdf0e10cSrcweir break;
115cdf0e10cSrcweir case GraphicLocation_RIGHT_MIDDLE:
116cdf0e10cSrcweir case GraphicLocation_RIGHT_TOP:
117cdf0e10cSrcweir case GraphicLocation_RIGHT_BOTTOM:
118cdf0e10cSrcweir aOut.append( GetXMLToken(XML_RIGHT) );
119cdf0e10cSrcweir break;
120cdf0e10cSrcweir default:
121cdf0e10cSrcweir break;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir }
124cdf0e10cSrcweir if( aOut.getLength() )
125cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE,
126cdf0e10cSrcweir XML_POSITION, aOut.makeStringAndClear() );
127cdf0e10cSrcweir
128cdf0e10cSrcweir if( GraphicLocation_AREA == ePos )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir aOut.append( GetXMLToken(XML_BACKGROUND_STRETCH) );
131cdf0e10cSrcweir }
132cdf0e10cSrcweir else if( GraphicLocation_NONE != ePos && GraphicLocation_TILED != ePos )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir aOut.append( GetXMLToken(XML_BACKGROUND_NO_REPEAT) );
135cdf0e10cSrcweir }
136cdf0e10cSrcweir if( aOut.getLength() )
137cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REPEAT,
138cdf0e10cSrcweir aOut.makeStringAndClear() );
139cdf0e10cSrcweir
140cdf0e10cSrcweir if( pFilter )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir OUString sFilter;
143cdf0e10cSrcweir (*pFilter) >>= sFilter;
144cdf0e10cSrcweir if( sFilter.getLength() )
145cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FILTER_NAME,
146cdf0e10cSrcweir sFilter );
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
149cdf0e10cSrcweir if( pTransparency )
150cdf0e10cSrcweir {
151cdf0e10cSrcweir sal_Int8 nTransparency = sal_Int8();
152cdf0e10cSrcweir if( (*pTransparency) >>= nTransparency )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir OUStringBuffer aTransOut;
155cdf0e10cSrcweir SvXMLUnitConverter::convertPercent( aTransOut, 100-nTransparency );
156cdf0e10cSrcweir GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_OPACITY,
157cdf0e10cSrcweir aTransOut.makeStringAndClear() );
158cdf0e10cSrcweir }
159cdf0e10cSrcweir }
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
162cdf0e10cSrcweir {
163cdf0e10cSrcweir SvXMLElementExport aElem( GetExport(), nPrefix, rLocalName, sal_True, sal_True );
164cdf0e10cSrcweir if( sURL.getLength() && GraphicLocation_NONE != ePos )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir // optional office:binary-data
167cdf0e10cSrcweir GetExport().AddEmbeddedGraphicObjectAsBase64( sURL );
168cdf0e10cSrcweir }
169cdf0e10cSrcweir }
170cdf0e10cSrcweir }
171