nss: upgrade to release 3.73
[LibreOffice.git] / xmloff / source / style / XMLBackgroundImageExport.cxx
blob496856caa799848a8f791ad8b4d6ba10b19cfb8a
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>
22 #include <com/sun/star/graphic/XGraphic.hpp>
24 #include <sax/tools/converter.hxx>
26 #include <xmloff/xmlnamespace.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <rtl/ustrbuf.hxx>
29 #include <xmloff/xmlexp.hxx>
30 #include <XMLBackgroundImageExport.hxx>
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::style;
36 using namespace ::xmloff::token;
38 XMLBackgroundImageExport::XMLBackgroundImageExport( SvXMLExport& rExp ) :
39 rExport( rExp )
43 XMLBackgroundImageExport::~XMLBackgroundImageExport()
47 void XMLBackgroundImageExport::exportXML( const Any& rGraphicAny,
48 const Any *pPos,
49 const Any *pFilter,
50 const Any *pTransparency,
51 sal_uInt16 nPrefix,
52 const OUString& rLocalName )
54 GraphicLocation ePos;
55 if( !(pPos && ((*pPos) >>= ePos)) )
56 ePos = GraphicLocation_AREA;
58 uno::Reference<graphic::XGraphic> xGraphic;
59 if (rGraphicAny.has<uno::Reference<graphic::XGraphic>>())
60 xGraphic = rGraphicAny.get<uno::Reference<graphic::XGraphic>>();
62 if (xGraphic.is() && GraphicLocation_NONE != ePos)
64 OUString sUsedMimeType;
65 OUString sInternalURL(GetExport().AddEmbeddedXGraphic(xGraphic, sUsedMimeType));
67 if (!sInternalURL.isEmpty())
69 GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sInternalURL);
70 GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
71 GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD);
74 OUStringBuffer aOut;
75 switch( ePos )
77 case GraphicLocation_LEFT_TOP:
78 case GraphicLocation_MIDDLE_TOP:
79 case GraphicLocation_RIGHT_TOP:
80 aOut.append( GetXMLToken(XML_TOP) );
81 break;
82 case GraphicLocation_LEFT_MIDDLE:
83 case GraphicLocation_MIDDLE_MIDDLE:
84 case GraphicLocation_RIGHT_MIDDLE:
85 aOut.append( GetXMLToken(XML_CENTER) );
86 break;
87 case GraphicLocation_LEFT_BOTTOM:
88 case GraphicLocation_MIDDLE_BOTTOM:
89 case GraphicLocation_RIGHT_BOTTOM:
90 aOut.append( GetXMLToken(XML_BOTTOM) );
91 break;
92 default:
93 break;
96 if( !aOut.isEmpty() )
98 aOut.append( ' ' );
100 switch( ePos )
102 case GraphicLocation_LEFT_TOP:
103 case GraphicLocation_LEFT_BOTTOM:
104 case GraphicLocation_LEFT_MIDDLE:
105 aOut.append( GetXMLToken(XML_LEFT) );
106 break;
107 case GraphicLocation_MIDDLE_TOP:
108 case GraphicLocation_MIDDLE_MIDDLE:
109 case GraphicLocation_MIDDLE_BOTTOM:
110 aOut.append( GetXMLToken(XML_CENTER) );
111 break;
112 case GraphicLocation_RIGHT_MIDDLE:
113 case GraphicLocation_RIGHT_TOP:
114 case GraphicLocation_RIGHT_BOTTOM:
115 aOut.append( GetXMLToken(XML_RIGHT) );
116 break;
117 default:
118 break;
121 if( !aOut.isEmpty() )
122 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
123 XML_POSITION, aOut.makeStringAndClear() );
125 if( GraphicLocation_AREA == ePos )
127 aOut.append( GetXMLToken(XML_STRETCH) );
129 else if( GraphicLocation_NONE != ePos && GraphicLocation_TILED != ePos )
131 aOut.append( GetXMLToken(XML_BACKGROUND_NO_REPEAT) );
133 if( !aOut.isEmpty() )
134 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REPEAT,
135 aOut.makeStringAndClear() );
137 if( pFilter )
139 OUString sFilter;
140 (*pFilter) >>= sFilter;
141 if( !sFilter.isEmpty() )
142 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FILTER_NAME,
143 sFilter );
146 if( pTransparency )
148 sal_Int8 nTransparency = sal_Int8();
149 if( (*pTransparency) >>= nTransparency )
151 OUStringBuffer aTransOut;
152 ::sax::Converter::convertPercent(aTransOut, 100-nTransparency);
153 GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_OPACITY,
154 aTransOut.makeStringAndClear() );
160 SvXMLElementExport aElem(GetExport(), nPrefix, rLocalName, true, true);
161 if (xGraphic.is() && GraphicLocation_NONE != ePos)
163 // optional office:binary-data
164 GetExport().AddEmbeddedXGraphicAsBase64(xGraphic);
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */