Line data Source code
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 :
23 : #include <sax/tools/converter.hxx>
24 :
25 : #include <xmloff/xmlnmspe.hxx>
26 : #include <xmloff/xmltoken.hxx>
27 : #include <rtl/ustrbuf.hxx>
28 : #include <xmloff/xmlexp.hxx>
29 : #include "XMLBackgroundImageExport.hxx"
30 :
31 : using ::rtl::OUString;
32 : using ::rtl::OUStringBuffer;
33 :
34 : using namespace ::com::sun::star;
35 : using namespace ::com::sun::star::uno;
36 : using namespace ::com::sun::star::style;
37 : using namespace ::xmloff::token;
38 :
39 74 : XMLBackgroundImageExport::XMLBackgroundImageExport( SvXMLExport& rExp ) :
40 74 : rExport( rExp )
41 : {
42 74 : }
43 :
44 74 : XMLBackgroundImageExport::~XMLBackgroundImageExport()
45 : {
46 74 : }
47 :
48 4 : void XMLBackgroundImageExport::exportXML( const Any& rURL,
49 : const Any *pPos,
50 : const Any *pFilter,
51 : const Any *pTransparency,
52 : sal_uInt16 nPrefix,
53 : const ::rtl::OUString& rLocalName )
54 : {
55 : GraphicLocation ePos;
56 4 : if( !(pPos && ((*pPos) >>= ePos)) )
57 0 : ePos = GraphicLocation_AREA;
58 :
59 4 : OUString sURL;
60 4 : rURL >>= sURL;
61 4 : if( !sURL.isEmpty() && GraphicLocation_NONE != ePos )
62 : {
63 0 : OUString sTempURL( GetExport().AddEmbeddedGraphicObject( sURL ) );
64 0 : if( !sTempURL.isEmpty() )
65 : {
66 0 : GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_HREF, sTempURL );
67 0 : GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_TYPE,
68 0 : XML_SIMPLE );
69 0 : GetExport().AddAttribute( XML_NAMESPACE_XLINK, XML_ACTUATE,
70 0 : XML_ONLOAD );
71 : }
72 :
73 0 : OUStringBuffer aOut;
74 0 : switch( ePos )
75 : {
76 : case GraphicLocation_LEFT_TOP:
77 : case GraphicLocation_MIDDLE_TOP:
78 : case GraphicLocation_RIGHT_TOP:
79 0 : aOut.append( GetXMLToken(XML_TOP) );
80 0 : break;
81 : case GraphicLocation_LEFT_MIDDLE:
82 : case GraphicLocation_MIDDLE_MIDDLE:
83 : case GraphicLocation_RIGHT_MIDDLE:
84 0 : aOut.append( GetXMLToken(XML_CENTER) );
85 0 : break;
86 : case GraphicLocation_LEFT_BOTTOM:
87 : case GraphicLocation_MIDDLE_BOTTOM:
88 : case GraphicLocation_RIGHT_BOTTOM:
89 0 : aOut.append( GetXMLToken(XML_BOTTOM) );
90 0 : break;
91 : default:
92 0 : break;
93 : }
94 :
95 0 : if( aOut.getLength() )
96 : {
97 0 : aOut.append( sal_Unicode( ' ' ) );
98 :
99 0 : switch( ePos )
100 : {
101 : case GraphicLocation_LEFT_TOP:
102 : case GraphicLocation_LEFT_BOTTOM:
103 : case GraphicLocation_LEFT_MIDDLE:
104 0 : aOut.append( GetXMLToken(XML_LEFT) );
105 0 : break;
106 : case GraphicLocation_MIDDLE_TOP:
107 : case GraphicLocation_MIDDLE_MIDDLE:
108 : case GraphicLocation_MIDDLE_BOTTOM:
109 0 : aOut.append( GetXMLToken(XML_CENTER) );
110 0 : break;
111 : case GraphicLocation_RIGHT_MIDDLE:
112 : case GraphicLocation_RIGHT_TOP:
113 : case GraphicLocation_RIGHT_BOTTOM:
114 0 : aOut.append( GetXMLToken(XML_RIGHT) );
115 0 : break;
116 : default:
117 0 : break;
118 : }
119 : }
120 0 : if( aOut.getLength() )
121 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE,
122 0 : XML_POSITION, aOut.makeStringAndClear() );
123 :
124 0 : if( GraphicLocation_AREA == ePos )
125 : {
126 0 : aOut.append( GetXMLToken(XML_BACKGROUND_STRETCH) );
127 : }
128 0 : else if( GraphicLocation_NONE != ePos && GraphicLocation_TILED != ePos )
129 : {
130 0 : aOut.append( GetXMLToken(XML_BACKGROUND_NO_REPEAT) );
131 : }
132 0 : if( aOut.getLength() )
133 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_REPEAT,
134 0 : aOut.makeStringAndClear() );
135 :
136 0 : if( pFilter )
137 : {
138 0 : OUString sFilter;
139 0 : (*pFilter) >>= sFilter;
140 0 : if( !sFilter.isEmpty() )
141 0 : GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_FILTER_NAME,
142 0 : sFilter );
143 : }
144 :
145 0 : if( pTransparency )
146 : {
147 0 : sal_Int8 nTransparency = sal_Int8();
148 0 : if( (*pTransparency) >>= nTransparency )
149 : {
150 0 : OUStringBuffer aTransOut;
151 0 : ::sax::Converter::convertPercent(aTransOut, 100-nTransparency);
152 0 : GetExport().AddAttribute( XML_NAMESPACE_DRAW, XML_OPACITY,
153 0 : aTransOut.makeStringAndClear() );
154 : }
155 0 : }
156 : }
157 :
158 : {
159 4 : SvXMLElementExport aElem( GetExport(), nPrefix, rLocalName, sal_True, sal_True );
160 4 : if( !sURL.isEmpty() && GraphicLocation_NONE != ePos )
161 : {
162 : // optional office:binary-data
163 0 : GetExport().AddEmbeddedGraphicObjectAsBase64( sURL );
164 4 : }
165 4 : }
166 4 : }
167 :
168 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|