1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLBackgroundImageExport.cxx,v $
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
) :
55 XMLBackgroundImageExport::~XMLBackgroundImageExport()
59 void XMLBackgroundImageExport::exportXML( const Any
& rURL
,
62 const Any
*pTransparency
,
64 const ::rtl::OUString
& rLocalName
)
67 if( !(pPos
&& ((*pPos
) >>= ePos
)) )
68 ePos
= GraphicLocation_AREA
;
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
,
80 GetExport().AddAttribute( XML_NAMESPACE_XLINK
, XML_ACTUATE
,
87 case GraphicLocation_LEFT_TOP
:
88 case GraphicLocation_MIDDLE_TOP
:
89 case GraphicLocation_RIGHT_TOP
:
90 aOut
.append( GetXMLToken(XML_TOP
) );
92 case GraphicLocation_LEFT_MIDDLE
:
93 case GraphicLocation_MIDDLE_MIDDLE
:
94 case GraphicLocation_RIGHT_MIDDLE
:
95 aOut
.append( GetXMLToken(XML_CENTER
) );
97 case GraphicLocation_LEFT_BOTTOM
:
98 case GraphicLocation_MIDDLE_BOTTOM
:
99 case GraphicLocation_RIGHT_BOTTOM
:
100 aOut
.append( GetXMLToken(XML_BOTTOM
) );
106 if( aOut
.getLength() )
108 aOut
.append( sal_Unicode( ' ' ) );
112 case GraphicLocation_LEFT_TOP
:
113 case GraphicLocation_LEFT_BOTTOM
:
114 case GraphicLocation_LEFT_MIDDLE
:
115 aOut
.append( GetXMLToken(XML_LEFT
) );
117 case GraphicLocation_MIDDLE_TOP
:
118 case GraphicLocation_MIDDLE_MIDDLE
:
119 case GraphicLocation_MIDDLE_BOTTOM
:
120 aOut
.append( GetXMLToken(XML_CENTER
) );
122 case GraphicLocation_RIGHT_MIDDLE
:
123 case GraphicLocation_RIGHT_TOP
:
124 case GraphicLocation_RIGHT_BOTTOM
:
125 aOut
.append( GetXMLToken(XML_RIGHT
) );
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() );
150 (*pFilter
) >>= sFilter
;
151 if( sFilter
.getLength() )
152 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_FILTER_NAME
,
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
);