bump product version to 5.0.4.1
[LibreOffice.git] / xmloff / source / style / XMLBackgroundImageExport.cxx
blobd8578becd0200abb642a6bf0e722ae77c7a301a5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/style/GraphicLocation.hpp>
23 #include <sax/tools/converter.hxx>
25 #include <xmloff/xmlnmspe.hxx>
26 #include <xmloff/xmltoken.hxx>
27 #include <rtl/ustrbuf.hxx>
28 #include <xmloff/xmlexp.hxx>
29 #include "XMLBackgroundImageExport.hxx"
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::style;
35 using namespace ::xmloff::token;
37 XMLBackgroundImageExport::XMLBackgroundImageExport( SvXMLExport& rExp ) :
38 rExport( rExp )
42 XMLBackgroundImageExport::~XMLBackgroundImageExport()
46 void XMLBackgroundImageExport::exportXML( const Any& rURL,
47 const Any *pPos,
48 const Any *pFilter,
49 const Any *pTransparency,
50 sal_uInt16 nPrefix,
51 const OUString& rLocalName )
53 GraphicLocation ePos;
54 if( !(pPos && ((*pPos) >>= ePos)) )
55 ePos = GraphicLocation_AREA;
57 OUString sURL;
58 rURL >>= sURL;
59 if( !sURL.isEmpty() && GraphicLocation_NONE != ePos )
61 OUString sTempURL( GetExport().AddEmbeddedGraphicObject( sURL ) );
62 if( !sTempURL.isEmpty() )
64 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sTempURL );
65 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE,
66 XML_SIMPLE );
67 GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE,
68 XML_ONLOAD );
71 OUStringBuffer aOut;
72 switch( ePos )
74 case GraphicLocation_LEFT_TOP:
75 case GraphicLocation_MIDDLE_TOP:
76 case GraphicLocation_RIGHT_TOP:
77 aOut.append( GetXMLToken(XML_TOP) );
78 break;
79 case GraphicLocation_LEFT_MIDDLE:
80 case GraphicLocation_MIDDLE_MIDDLE:
81 case GraphicLocation_RIGHT_MIDDLE:
82 aOut.append( GetXMLToken(XML_CENTER) );
83 break;
84 case GraphicLocation_LEFT_BOTTOM:
85 case GraphicLocation_MIDDLE_BOTTOM:
86 case GraphicLocation_RIGHT_BOTTOM:
87 aOut.append( GetXMLToken(XML_BOTTOM) );
88 break;
89 default:
90 break;
93 if( !aOut.isEmpty() )
95 aOut.append( ' ' );
97 switch( ePos )
99 case GraphicLocation_LEFT_TOP:
100 case GraphicLocation_LEFT_BOTTOM:
101 case GraphicLocation_LEFT_MIDDLE:
102 aOut.append( GetXMLToken(XML_LEFT) );
103 break;
104 case GraphicLocation_MIDDLE_TOP:
105 case GraphicLocation_MIDDLE_MIDDLE:
106 case GraphicLocation_MIDDLE_BOTTOM:
107 aOut.append( GetXMLToken(XML_CENTER) );
108 break;
109 case GraphicLocation_RIGHT_MIDDLE:
110 case GraphicLocation_RIGHT_TOP:
111 case GraphicLocation_RIGHT_BOTTOM:
112 aOut.append( GetXMLToken(XML_RIGHT) );
113 break;
114 default:
115 break;
118 if( !aOut.isEmpty() )
119 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
120 XML_POSITION, aOut.makeStringAndClear() );
122 if( GraphicLocation_AREA == ePos )
124 aOut.append( GetXMLToken(XML_BACKGROUND_STRETCH) );
126 else if( GraphicLocation_NONE != ePos && GraphicLocation_TILED != ePos )
128 aOut.append( GetXMLToken(XML_BACKGROUND_NO_REPEAT) );
130 if( !aOut.isEmpty() )
131 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REPEAT,
132 aOut.makeStringAndClear() );
134 if( pFilter )
136 OUString sFilter;
137 (*pFilter) >>= sFilter;
138 if( !sFilter.isEmpty() )
139 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FILTER_NAME,
140 sFilter );
143 if( pTransparency )
145 sal_Int8 nTransparency = sal_Int8();
146 if( (*pTransparency) >>= nTransparency )
148 OUStringBuffer aTransOut;
149 ::sax::Converter::convertPercent(aTransOut, 100-nTransparency);
150 GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_OPACITY,
151 aTransOut.makeStringAndClear() );
157 SvXMLElementExport aElem( GetExport(), nPrefix, rLocalName, true, true );
158 if( !sURL.isEmpty() && GraphicLocation_NONE != ePos )
160 // optional office:binary-data
161 GetExport().AddEmbeddedGraphicObjectAsBase64( sURL );
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */