Branch data 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 : : #include "oox/drawingml/fillpropertiesgroupcontext.hxx"
21 : : #include "oox/helper/attributelist.hxx"
22 : : #include "oox/helper/graphichelper.hxx"
23 : : #include "oox/core/xmlfilterbase.hxx"
24 : : #include "oox/drawingml/drawingmltypes.hxx"
25 : : #include "oox/drawingml/fillproperties.hxx"
26 : :
27 : : using ::rtl::OUString;
28 : : using namespace ::com::sun::star;
29 : : using namespace ::com::sun::star::uno;
30 : : using namespace ::com::sun::star::xml::sax;
31 : : using ::oox::core::ContextHandler;
32 : : using ::oox::core::XmlFilterBase;
33 : :
34 : : namespace oox {
35 : : namespace drawingml {
36 : :
37 : : // ============================================================================
38 : :
39 : 114 : SolidFillContext::SolidFillContext( ContextHandler& rParent,
40 : : const Reference< XFastAttributeList >&, FillProperties& rFillProps ) :
41 : 114 : ColorContext( rParent, rFillProps.maFillColor )
42 : : {
43 : 114 : }
44 : :
45 : : // ============================================================================
46 : :
47 : 72 : GradientFillContext::GradientFillContext( ContextHandler& rParent,
48 : : const Reference< XFastAttributeList >& rxAttribs, GradientFillProperties& rGradientProps ) :
49 : : ContextHandler( rParent ),
50 : 72 : mrGradientProps( rGradientProps )
51 : : {
52 [ + - ]: 72 : AttributeList aAttribs( rxAttribs );
53 [ + - ]: 72 : mrGradientProps.moShadeFlip = aAttribs.getToken( XML_flip );
54 [ + - ][ + - ]: 72 : mrGradientProps.moRotateWithShape = aAttribs.getBool( XML_rotWithShape );
55 : 72 : }
56 : :
57 : 378 : Reference< XFastContextHandler > GradientFillContext::createFastChildContext(
58 : : sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
59 : : {
60 [ + - ]: 378 : AttributeList aAttribs( rxAttribs );
61 [ + + + + : 378 : switch( nElement )
+ - - ]
62 : : {
63 : : case A_TOKEN( gsLst ):
64 [ + - ]: 72 : return this; // for gs elements
65 : :
66 : : case A_TOKEN( gs ):
67 [ + - ][ + - ]: 198 : if( aAttribs.hasAttribute( XML_pos ) )
68 : : {
69 [ + - ][ + - ]: 198 : double fPosition = getLimitedValue< double >( aAttribs.getDouble( XML_pos, 0.0 ) / 100000.0, 0.0, 1.0 );
70 [ + - ][ + - ]: 198 : return new ColorContext( *this, mrGradientProps.maGradientStops[ fPosition ] );
[ + - ][ + - ]
71 : : }
72 : 0 : break;
73 : :
74 : : case A_TOKEN( lin ):
75 [ + - ]: 36 : mrGradientProps.moShadeAngle = aAttribs.getInteger( XML_ang );
76 [ + - ]: 36 : mrGradientProps.moShadeScaled = aAttribs.getBool( XML_scaled );
77 : 36 : break;
78 : :
79 : : case A_TOKEN( path ):
80 : : // always set a path type, this disables linear gradient in conversion
81 [ + - ][ + - ]: 36 : mrGradientProps.moGradientPath = aAttribs.getToken( XML_path, XML_rect );
82 [ + - ]: 36 : return this; // for fillToRect element
83 : :
84 : : case A_TOKEN( fillToRect ):
85 [ + - ][ + - ]: 36 : mrGradientProps.moFillToRect = GetRelativeRect( rxAttribs );
86 : 36 : break;
87 : :
88 : : case A_TOKEN( tileRect ):
89 [ # # ][ # # ]: 0 : mrGradientProps.moTileRect = GetRelativeRect( rxAttribs );
90 : 0 : break;
91 : : }
92 [ + - ][ + - ]: 378 : return 0;
93 : : }
94 : :
95 : : // ============================================================================
96 : :
97 : 0 : PatternFillContext::PatternFillContext( ContextHandler& rParent,
98 : : const Reference< XFastAttributeList >& rxAttribs, PatternFillProperties& rPatternProps ) :
99 : : ContextHandler( rParent ),
100 : 0 : mrPatternProps( rPatternProps )
101 : : {
102 [ # # ]: 0 : AttributeList aAttribs( rxAttribs );
103 [ # # ][ # # ]: 0 : mrPatternProps.moPattPreset = aAttribs.getToken( XML_prst );
104 : 0 : }
105 : :
106 : 0 : Reference< XFastContextHandler > PatternFillContext::createFastChildContext(
107 : : sal_Int32 nElement, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException)
108 : : {
109 [ # # # ]: 0 : switch( nElement )
110 : : {
111 : : case A_TOKEN( bgClr ):
112 [ # # ][ # # ]: 0 : return new ColorContext( *this, mrPatternProps.maPattBgColor );
113 : : case A_TOKEN( fgClr ):
114 [ # # ][ # # ]: 0 : return new ColorContext( *this, mrPatternProps.maPattFgColor );
115 : : }
116 : 0 : return 0;
117 : : }
118 : :
119 : : // ============================================================================
120 : : // ============================================================================
121 : :
122 : 0 : ColorChangeContext::ColorChangeContext( ContextHandler& rParent,
123 : : const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) :
124 : : ContextHandler( rParent ),
125 : 0 : mrBlipProps( rBlipProps )
126 : : {
127 [ # # ]: 0 : mrBlipProps.maColorChangeFrom.setUnused();
128 [ # # ]: 0 : mrBlipProps.maColorChangeTo.setUnused();
129 [ # # ]: 0 : AttributeList aAttribs( rxAttribs );
130 [ # # ][ # # ]: 0 : mbUseAlpha = aAttribs.getBool( XML_useA, true );
131 : 0 : }
132 : :
133 : 0 : ColorChangeContext::~ColorChangeContext()
134 : : {
135 [ # # ]: 0 : if( !mbUseAlpha )
136 [ # # ]: 0 : mrBlipProps.maColorChangeTo.clearTransparence();
137 [ # # ]: 0 : }
138 : :
139 : 0 : Reference< XFastContextHandler > ColorChangeContext::createFastChildContext(
140 : : sal_Int32 nElement, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException)
141 : : {
142 [ # # # ]: 0 : switch( nElement )
143 : : {
144 : : case A_TOKEN( clrFrom ):
145 [ # # ][ # # ]: 0 : return new ColorContext( *this, mrBlipProps.maColorChangeFrom );
146 : : case A_TOKEN( clrTo ):
147 [ # # ][ # # ]: 0 : return new ColorContext( *this, mrBlipProps.maColorChangeTo );
148 : : }
149 : 0 : return 0;
150 : : }
151 : :
152 : : // ============================================================================
153 : :
154 : 15 : BlipContext::BlipContext( ContextHandler& rParent,
155 : : const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) :
156 : : ContextHandler( rParent ),
157 : 15 : mrBlipProps( rBlipProps )
158 : : {
159 [ + - ]: 15 : AttributeList aAttribs( rxAttribs );
160 [ + - ][ + - ]: 15 : if( aAttribs.hasAttribute( R_TOKEN( embed ) ) )
161 : : {
162 : : // internal picture URL
163 [ + - ][ + - ]: 15 : OUString aFragmentPath = getFragmentPathFromRelId( aAttribs.getString( R_TOKEN( embed ), OUString() ) );
164 [ + - ]: 15 : if( !aFragmentPath.isEmpty() )
165 [ + - ][ + - ]: 15 : mrBlipProps.mxGraphic = getFilter().getGraphicHelper().importEmbeddedGraphic( aFragmentPath );
[ + - ][ + - ]
166 : : }
167 [ # # ][ # # ]: 0 : else if( aAttribs.hasAttribute( R_TOKEN( link ) ) )
168 : : {
169 : : // external URL
170 [ # # ]: 0 : OUString aRelId = aAttribs.getString( R_TOKEN( link ), OUString() );
171 [ # # ][ # # ]: 0 : OUString aTargetLink = getFilter().getAbsoluteUrl( getRelations().getExternalTargetFromRelId( aRelId ) );
[ # # ][ # # ]
172 : : // TODO: load external picture
173 [ + - ]: 15 : }
174 : 15 : }
175 : :
176 : 0 : Reference< XFastContextHandler > BlipContext::createFastChildContext(
177 : : sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
178 : : {
179 [ # # ]: 0 : AttributeList aAttribs( rxAttribs );
180 [ # # # # ]: 0 : switch( nElement )
181 : : {
182 : : case A_TOKEN( biLevel ):
183 : : case A_TOKEN( grayscl ):
184 [ # # ]: 0 : mrBlipProps.moColorEffect = getBaseToken( nElement );
185 : 0 : break;
186 : :
187 : : case A_TOKEN( clrChange ):
188 [ # # ][ # # ]: 0 : return new ColorChangeContext( *this, rxAttribs, mrBlipProps );
[ # # ]
189 : :
190 : : case A_TOKEN( lum ):
191 [ # # ]: 0 : mrBlipProps.moBrightness = aAttribs.getInteger( XML_bright );
192 [ # # ]: 0 : mrBlipProps.moContrast = aAttribs.getInteger( XML_contrast );
193 : 0 : break;
194 : : }
195 [ # # ][ # # ]: 0 : return 0;
196 : : }
197 : :
198 : : // ============================================================================
199 : :
200 : 15 : BlipFillContext::BlipFillContext( ContextHandler& rParent,
201 : : const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) :
202 : : ContextHandler( rParent ),
203 : 15 : mrBlipProps( rBlipProps )
204 : : {
205 [ + - ]: 15 : AttributeList aAttribs( rxAttribs );
206 [ + - ][ + - ]: 15 : mrBlipProps.moRotateWithShape = aAttribs.getBool( XML_rotWithShape );
207 : 15 : }
208 : :
209 : 57 : Reference< XFastContextHandler > BlipFillContext::createFastChildContext(
210 : : sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
211 : : {
212 [ + - ]: 57 : AttributeList aAttribs( rxAttribs );
213 [ + + - + : 57 : switch( nElement )
+ - ]
214 : : {
215 : : case A_TOKEN( blip ):
216 [ + - ][ + - ]: 15 : return new BlipContext( *this, rxAttribs, mrBlipProps );
[ + - ]
217 : :
218 : : case A_TOKEN( srcRect ):
219 : : {
220 [ + - ]: 12 : rtl::OUString aDefault( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "0" ) ) );
221 : 12 : ::com::sun::star::geometry::IntegerRectangle2D aClipRect;
222 [ + - ][ + - ]: 12 : aClipRect.X1 = GetPercent( aAttribs.getString( XML_l, aDefault ) );
223 [ + - ][ + - ]: 12 : aClipRect.Y1 = GetPercent( aAttribs.getString( XML_t, aDefault ) );
224 [ + - ][ + - ]: 12 : aClipRect.X2 = GetPercent( aAttribs.getString( XML_r, aDefault ) );
225 [ + - ][ + - ]: 12 : aClipRect.Y2 = GetPercent( aAttribs.getString( XML_b, aDefault ) );
226 [ + - ]: 12 : mrBlipProps.moClipRect = aClipRect;
227 : : }
228 : 12 : break;
229 : :
230 : : case A_TOKEN( tile ):
231 [ # # ]: 0 : mrBlipProps.moBitmapMode = getBaseToken( nElement );
232 [ # # ]: 0 : mrBlipProps.moTileOffsetX = aAttribs.getInteger( XML_tx );
233 [ # # ]: 0 : mrBlipProps.moTileOffsetY = aAttribs.getInteger( XML_ty );
234 [ # # ]: 0 : mrBlipProps.moTileScaleX = aAttribs.getInteger( XML_sx );
235 [ # # ]: 0 : mrBlipProps.moTileScaleY = aAttribs.getInteger( XML_sy );
236 [ # # ]: 0 : mrBlipProps.moTileAlign = aAttribs.getToken( XML_algn );
237 [ # # ]: 0 : mrBlipProps.moTileFlip = aAttribs.getToken( XML_flip );
238 : 0 : break;
239 : :
240 : : case A_TOKEN( stretch ):
241 [ + - ]: 15 : mrBlipProps.moBitmapMode = getBaseToken( nElement );
242 [ + - ]: 15 : return this; // for fillRect element
243 : :
244 : : case A_TOKEN( fillRect ):
245 [ + - ][ + - ]: 15 : mrBlipProps.moFillRect = GetRelativeRect( rxAttribs );
246 : 15 : break;
247 : : }
248 [ + - ][ + - ]: 57 : return 0;
249 : : }
250 : :
251 : : // ============================================================================
252 : : // ============================================================================
253 : :
254 : 0 : FillPropertiesContext::FillPropertiesContext( ContextHandler& rParent, FillProperties& rFillProps ) :
255 : : ContextHandler( rParent ),
256 : 0 : mrFillProps( rFillProps )
257 : : {
258 : 0 : }
259 : :
260 : 0 : Reference< XFastContextHandler > FillPropertiesContext::createFastChildContext(
261 : : sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
262 : : throw ( SAXException, RuntimeException )
263 : : {
264 : 0 : return createFillContext( *this, nElement, rxAttribs, mrFillProps );
265 : : }
266 : :
267 : 225 : /*static*/ Reference< XFastContextHandler > FillPropertiesContext::createFillContext(
268 : : ContextHandler& rParent, sal_Int32 nElement,
269 : : const Reference< XFastAttributeList >& rxAttribs, FillProperties& rFillProps )
270 : : {
271 [ + + + - : 225 : switch( nElement )
- - + ]
272 : : {
273 [ + - ]: 27 : case A_TOKEN( noFill ): { rFillProps.moFillType = getBaseToken( nElement ); return 0; };
274 [ + - ][ + - ]: 114 : case A_TOKEN( solidFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new SolidFillContext( rParent, rxAttribs, rFillProps ); };
[ + - ]
275 [ + - ][ + - ]: 72 : case A_TOKEN( gradFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new GradientFillContext( rParent, rxAttribs, rFillProps.maGradientProps ); };
[ + - ]
276 [ # # ][ # # ]: 0 : case A_TOKEN( pattFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new PatternFillContext( rParent, rxAttribs, rFillProps.maPatternProps ); };
[ # # ]
277 [ # # ][ # # ]: 0 : case A_TOKEN( blipFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new BlipFillContext( rParent, rxAttribs, rFillProps.maBlipProps ); };
[ # # ]
278 [ # # ]: 0 : case A_TOKEN( grpFill ): { rFillProps.moFillType = getBaseToken( nElement ); return 0; }; // TODO
279 : : }
280 : 225 : return 0;
281 : : }
282 : :
283 : : // ============================================================================
284 : :
285 : 0 : SimpleFillPropertiesContext::SimpleFillPropertiesContext( ContextHandler& rParent, Color& rColor ) :
286 : : FillPropertiesContext( rParent, *this ),
287 [ # # ]: 0 : mrColor( rColor )
288 : : {
289 : 0 : }
290 : :
291 [ # # ]: 0 : SimpleFillPropertiesContext::~SimpleFillPropertiesContext()
292 : : {
293 [ # # ][ # # ]: 0 : mrColor = getBestSolidColor();
[ # # ]
294 [ # # ]: 0 : }
295 : :
296 : : // ============================================================================
297 : :
298 : : } // namespace drawingml
299 [ + - ][ + - ]: 285 : } // namespace oox
300 : :
301 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|