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 
24 #include <sax/tools/converter.hxx>
25 
26 #include <xmloff/xmlnmspe.hxx>
27 #include <xmloff/xmltoken.hxx>
28 #include <rtl/ustrbuf.hxx>
29 #include <xmloff/xmlexp.hxx>
31 
32 
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;
37 
39  rExport( rExp )
40 {
41 }
42 
44 {
45 }
46 
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 )
53 {
54  GraphicLocation ePos;
55  if( !(pPos && ((*pPos) >>= ePos)) )
56  ePos = GraphicLocation_AREA;
57 
58  uno::Reference<graphic::XGraphic> xGraphic;
59  if (rGraphicAny.has<uno::Reference<graphic::XGraphic>>())
60  xGraphic = rGraphicAny.get<uno::Reference<graphic::XGraphic>>();
61 
62  if (xGraphic.is() && GraphicLocation_NONE != ePos)
63  {
64  OUString sUsedMimeType;
65  OUString sInternalURL(GetExport().AddEmbeddedXGraphic(xGraphic, sUsedMimeType));
66 
67  if (!sInternalURL.isEmpty())
68  {
72  }
73 
74  OUStringBuffer aOut;
75  switch( ePos )
76  {
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;
94  }
95 
96  if( !aOut.isEmpty() )
97  {
98  aOut.append( ' ' );
99 
100  switch( ePos )
101  {
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;
119  }
120  }
121  if( !aOut.isEmpty() )
123  XML_POSITION, aOut.makeStringAndClear() );
124 
125  if( GraphicLocation_AREA == ePos )
126  {
127  aOut.append( GetXMLToken(XML_STRETCH) );
128  }
129  else if( GraphicLocation_NONE != ePos && GraphicLocation_TILED != ePos )
130  {
131  aOut.append( GetXMLToken(XML_BACKGROUND_NO_REPEAT) );
132  }
133  if( !aOut.isEmpty() )
135  aOut.makeStringAndClear() );
136 
137  if( pFilter )
138  {
139  OUString sFilter;
140  (*pFilter) >>= sFilter;
141  if( !sFilter.isEmpty() )
143  sFilter );
144  }
145 
146  if( pTransparency )
147  {
148  sal_Int8 nTransparency = sal_Int8();
149  if( (*pTransparency) >>= nTransparency )
150  {
151  OUStringBuffer aTransOut;
152  ::sax::Converter::convertPercent(aTransOut, 100-nTransparency);
154  aTransOut.makeStringAndClear() );
155  }
156  }
157  }
158 
159  {
160  SvXMLElementExport aElem(GetExport(), nPrefix, rLocalName, true, true);
161  if (xGraphic.is() && GraphicLocation_NONE != ePos)
162  {
163  // optional office:binary-data
165  }
166  }
167 }
168 
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr sal_uInt16 XML_NAMESPACE_STYLE
Definition: xmlnmspe.hxx:30
signed char sal_Int8
css::chart::ChartAxisLabelPosition ePos
void AddAttribute(sal_uInt16 nPrefix, const char *pName, const OUString &rValue)
Definition: xmlexp.cxx:926
constexpr sal_uInt16 XML_NAMESPACE_DRAW
Definition: xmlnmspe.hxx:33
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)
constexpr sal_uInt16 XML_NAMESPACE_XLINK
Definition: xmlnmspe.hxx:35
XMLBackgroundImageExport(SvXMLExport &rExport)
const OUString & GetXMLToken(enum XMLTokenEnum eToken)
return the OUString representation for eToken
Definition: xmltoken.cxx:3366
Handling of tokens in XML:
bool AddEmbeddedXGraphicAsBase64(css::uno::Reference< css::graphic::XGraphic > const &rxGraphic)
Definition: xmlexp.cxx:1900
css::uno::Any const SvXMLExport & rExport
Definition: ImageStyle.hxx:38
Reference< XGraphic > xGraphic
static bool convertPercent(sal_Int32 &rValue, const OUString &rString)