tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / xmloff / source / style / XMLBackgroundImageExport.cxx
blobc3ae8748a5381f59b09fa8ea9e9d2dc805c8f87a
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 void XMLBackgroundImageExport::exportXML( const Any& rGraphicAny,
44 const Any *pPos,
45 const Any *pFilter,
46 const Any *pTransparency,
47 sal_uInt16 nPrefix,
48 const OUString& rLocalName )
50 GraphicLocation ePos;
51 if( !(pPos && ((*pPos) >>= ePos)) )
52 ePos = GraphicLocation_AREA;
54 uno::Reference<graphic::XGraphic> xGraphic;
55 if (rGraphicAny.has<uno::Reference<graphic::XGraphic>>())
56 xGraphic = rGraphicAny.get<uno::Reference<graphic::XGraphic>>();
58 if (xGraphic.is() && GraphicLocation_NONE != ePos)
60 OUString sUsedMimeType;
61 OUString sInternalURL(GetExport().AddEmbeddedXGraphic(xGraphic, sUsedMimeType));
63 if (!sInternalURL.isEmpty())
65 GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_HREF, sInternalURL);
66 GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
67 GetExport().AddAttribute(XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD);
70 OUStringBuffer aOut;
71 switch( ePos )
73 case GraphicLocation_LEFT_TOP:
74 case GraphicLocation_MIDDLE_TOP:
75 case GraphicLocation_RIGHT_TOP:
76 aOut.append( GetXMLToken(XML_TOP) );
77 break;
78 case GraphicLocation_LEFT_MIDDLE:
79 case GraphicLocation_MIDDLE_MIDDLE:
80 case GraphicLocation_RIGHT_MIDDLE:
81 aOut.append( GetXMLToken(XML_CENTER) );
82 break;
83 case GraphicLocation_LEFT_BOTTOM:
84 case GraphicLocation_MIDDLE_BOTTOM:
85 case GraphicLocation_RIGHT_BOTTOM:
86 aOut.append( GetXMLToken(XML_BOTTOM) );
87 break;
88 default:
89 break;
92 if( !aOut.isEmpty() )
94 aOut.append( ' ' );
96 switch( ePos )
98 case GraphicLocation_LEFT_TOP:
99 case GraphicLocation_LEFT_BOTTOM:
100 case GraphicLocation_LEFT_MIDDLE:
101 aOut.append( GetXMLToken(XML_LEFT) );
102 break;
103 case GraphicLocation_MIDDLE_TOP:
104 case GraphicLocation_MIDDLE_MIDDLE:
105 case GraphicLocation_MIDDLE_BOTTOM:
106 aOut.append( GetXMLToken(XML_CENTER) );
107 break;
108 case GraphicLocation_RIGHT_MIDDLE:
109 case GraphicLocation_RIGHT_TOP:
110 case GraphicLocation_RIGHT_BOTTOM:
111 aOut.append( GetXMLToken(XML_RIGHT) );
112 break;
113 default:
114 break;
117 if( !aOut.isEmpty() )
118 GetExport().AddAttribute( XML_NAMESPACE_STYLE,
119 XML_POSITION, aOut.makeStringAndClear() );
121 if( GraphicLocation_AREA == ePos )
123 aOut.append( GetXMLToken(XML_STRETCH) );
125 else if( GraphicLocation_NONE != ePos && GraphicLocation_TILED != ePos )
127 aOut.append( GetXMLToken(XML_BACKGROUND_NO_REPEAT) );
129 if( !aOut.isEmpty() )
130 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REPEAT,
131 aOut.makeStringAndClear() );
133 if( pFilter )
135 OUString sFilter;
136 (*pFilter) >>= sFilter;
137 if( !sFilter.isEmpty() )
138 GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FILTER_NAME,
139 sFilter );
142 if( pTransparency )
144 sal_Int8 nTransparency = sal_Int8();
145 if( (*pTransparency) >>= nTransparency )
147 OUStringBuffer aTransOut;
148 ::sax::Converter::convertPercent(aTransOut, 100-nTransparency);
149 GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_OPACITY,
150 aTransOut.makeStringAndClear() );
156 SvXMLElementExport aElem(GetExport(), nPrefix, rLocalName, true, true);
157 if (xGraphic.is() && GraphicLocation_NONE != ePos)
159 // optional office:binary-data
160 GetExport().AddEmbeddedXGraphicAsBase64(xGraphic);
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */