1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
) :
42 XMLBackgroundImageExport::~XMLBackgroundImageExport()
46 void XMLBackgroundImageExport::exportXML( const Any
& rURL
,
49 const Any
*pTransparency
,
51 const OUString
& rLocalName
)
54 if( !(pPos
&& ((*pPos
) >>= ePos
)) )
55 ePos
= GraphicLocation_AREA
;
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
,
67 GetExport().AddAttribute( XML_NAMESPACE_XLINK
, XML_ACTUATE
,
74 case GraphicLocation_LEFT_TOP
:
75 case GraphicLocation_MIDDLE_TOP
:
76 case GraphicLocation_RIGHT_TOP
:
77 aOut
.append( GetXMLToken(XML_TOP
) );
79 case GraphicLocation_LEFT_MIDDLE
:
80 case GraphicLocation_MIDDLE_MIDDLE
:
81 case GraphicLocation_RIGHT_MIDDLE
:
82 aOut
.append( GetXMLToken(XML_CENTER
) );
84 case GraphicLocation_LEFT_BOTTOM
:
85 case GraphicLocation_MIDDLE_BOTTOM
:
86 case GraphicLocation_RIGHT_BOTTOM
:
87 aOut
.append( GetXMLToken(XML_BOTTOM
) );
99 case GraphicLocation_LEFT_TOP
:
100 case GraphicLocation_LEFT_BOTTOM
:
101 case GraphicLocation_LEFT_MIDDLE
:
102 aOut
.append( GetXMLToken(XML_LEFT
) );
104 case GraphicLocation_MIDDLE_TOP
:
105 case GraphicLocation_MIDDLE_MIDDLE
:
106 case GraphicLocation_MIDDLE_BOTTOM
:
107 aOut
.append( GetXMLToken(XML_CENTER
) );
109 case GraphicLocation_RIGHT_MIDDLE
:
110 case GraphicLocation_RIGHT_TOP
:
111 case GraphicLocation_RIGHT_BOTTOM
:
112 aOut
.append( GetXMLToken(XML_RIGHT
) );
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() );
137 (*pFilter
) >>= sFilter
;
138 if( !sFilter
.isEmpty() )
139 GetExport().AddAttribute( XML_NAMESPACE_STYLE
, XML_FILTER_NAME
,
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: */