LibreOffice Module xmloff (master) 1
XMLBackgroundImageExport.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <com/sun/star/style/GraphicLocation.hpp>
22#include <com/sun/star/graphic/XGraphic.hpp>
23
25
27#include <xmloff/xmltoken.hxx>
28#include <rtl/ustrbuf.hxx>
29#include <xmloff/xmlexp.hxx>
31
32
33using namespace ::com::sun::star;
34using namespace ::com::sun::star::uno;
35using namespace ::com::sun::star::style;
36using namespace ::xmloff::token;
37
39 rExport( rExp )
40{
41}
42
43void 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 )
49{
50 GraphicLocation ePos;
51 if( !(pPos && ((*pPos) >>= ePos)) )
52 ePos = GraphicLocation_AREA;
53
54 uno::Reference<graphic::XGraphic> xGraphic;
55 if (rGraphicAny.has<uno::Reference<graphic::XGraphic>>())
56 xGraphic = rGraphicAny.get<uno::Reference<graphic::XGraphic>>();
57
58 if (xGraphic.is() && GraphicLocation_NONE != ePos)
59 {
60 OUString sUsedMimeType;
61 OUString sInternalURL(GetExport().AddEmbeddedXGraphic(xGraphic, sUsedMimeType));
62
63 if (!sInternalURL.isEmpty())
64 {
68 }
69
70 OUStringBuffer aOut;
71 switch( ePos )
72 {
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;
90 }
91
92 if( !aOut.isEmpty() )
93 {
94 aOut.append( ' ' );
95
96 switch( ePos )
97 {
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;
115 }
116 }
117 if( !aOut.isEmpty() )
119 XML_POSITION, aOut.makeStringAndClear() );
120
121 if( GraphicLocation_AREA == ePos )
122 {
123 aOut.append( GetXMLToken(XML_STRETCH) );
124 }
125 else if( GraphicLocation_NONE != ePos && GraphicLocation_TILED != ePos )
126 {
128 }
129 if( !aOut.isEmpty() )
131 aOut.makeStringAndClear() );
132
133 if( pFilter )
134 {
135 OUString sFilter;
136 (*pFilter) >>= sFilter;
137 if( !sFilter.isEmpty() )
139 sFilter );
140 }
141
142 if( pTransparency )
143 {
144 sal_Int8 nTransparency = sal_Int8();
145 if( (*pTransparency) >>= nTransparency )
146 {
147 OUStringBuffer aTransOut;
148 ::sax::Converter::convertPercent(aTransOut, 100-nTransparency);
150 aTransOut.makeStringAndClear() );
151 }
152 }
153 }
154
155 {
156 SvXMLElementExport aElem(GetExport(), nPrefix, rLocalName, true, true);
157 if (xGraphic.is() && GraphicLocation_NONE != ePos)
158 {
159 // optional office:binary-data
161 }
162 }
163}
164
165/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::chart::ChartAxisLabelPosition ePos
void AddAttribute(sal_uInt16 nPrefix, const OUString &rName, const OUString &rValue)
Definition: xmlexp.cxx:907
bool AddEmbeddedXGraphicAsBase64(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic)
Definition: xmlexp.cxx:1875
void exportXML(const css::uno::Any &rURL, const css::uno::Any *pPos, const css::uno::Any *pFilter, const css::uno::Any *pTransparency, sal_uInt16 nPrefix, const OUString &rLocalName)
XMLBackgroundImageExport(SvXMLExport &rExport)
static bool convertPercent(sal_Int32 &rValue, std::u16string_view rString)
Handling of tokens in XML:
@ XML_BACKGROUND_NO_REPEAT
Definition: xmltoken.hxx:316
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3541
signed char sal_Int8
constexpr sal_uInt16 XML_NAMESPACE_DRAW
constexpr sal_uInt16 XML_NAMESPACE_XLINK
constexpr sal_uInt16 XML_NAMESPACE_STYLE