bump product version to 4.1.6.2
[LibreOffice.git] / oox / source / drawingml / fillpropertiesgroupcontext.cxx
blob4a0769328142f90f868517fecedc229e9126ad11
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 .
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 #include <sfx2/docfile.hxx>
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;
34 namespace oox {
35 namespace drawingml {
37 // ============================================================================
39 SolidFillContext::SolidFillContext( ContextHandler& rParent,
40 const Reference< XFastAttributeList >&, FillProperties& rFillProps ) :
41 ColorContext( rParent, rFillProps.maFillColor )
45 // ============================================================================
47 GradientFillContext::GradientFillContext( ContextHandler& rParent,
48 const Reference< XFastAttributeList >& rxAttribs, GradientFillProperties& rGradientProps ) :
49 ContextHandler( rParent ),
50 mrGradientProps( rGradientProps )
52 AttributeList aAttribs( rxAttribs );
53 mrGradientProps.moShadeFlip = aAttribs.getToken( XML_flip );
54 mrGradientProps.moRotateWithShape = aAttribs.getBool( XML_rotWithShape );
57 Reference< XFastContextHandler > GradientFillContext::createFastChildContext(
58 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
60 AttributeList aAttribs( rxAttribs );
61 switch( nElement )
63 case A_TOKEN( gsLst ):
64 return this; // for gs elements
66 case A_TOKEN( gs ):
67 if( aAttribs.hasAttribute( XML_pos ) )
69 double fPosition = getLimitedValue< double >( aAttribs.getDouble( XML_pos, 0.0 ) / 100000.0, 0.0, 1.0 );
70 return new ColorContext( *this, mrGradientProps.maGradientStops[ fPosition ] );
72 break;
74 case A_TOKEN( lin ):
75 mrGradientProps.moShadeAngle = aAttribs.getInteger( XML_ang );
76 mrGradientProps.moShadeScaled = aAttribs.getBool( XML_scaled );
77 break;
79 case A_TOKEN( path ):
80 // always set a path type, this disables linear gradient in conversion
81 mrGradientProps.moGradientPath = aAttribs.getToken( XML_path, XML_rect );
82 return this; // for fillToRect element
84 case A_TOKEN( fillToRect ):
85 mrGradientProps.moFillToRect = GetRelativeRect( rxAttribs );
86 break;
88 case A_TOKEN( tileRect ):
89 mrGradientProps.moTileRect = GetRelativeRect( rxAttribs );
90 break;
92 return 0;
95 // ============================================================================
97 PatternFillContext::PatternFillContext( ContextHandler& rParent,
98 const Reference< XFastAttributeList >& rxAttribs, PatternFillProperties& rPatternProps ) :
99 ContextHandler( rParent ),
100 mrPatternProps( rPatternProps )
102 AttributeList aAttribs( rxAttribs );
103 mrPatternProps.moPattPreset = aAttribs.getToken( XML_prst );
106 Reference< XFastContextHandler > PatternFillContext::createFastChildContext(
107 sal_Int32 nElement, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException)
109 switch( nElement )
111 case A_TOKEN( bgClr ):
112 return new ColorContext( *this, mrPatternProps.maPattBgColor );
113 case A_TOKEN( fgClr ):
114 return new ColorContext( *this, mrPatternProps.maPattFgColor );
116 return 0;
119 // ============================================================================
120 // ============================================================================
122 ColorChangeContext::ColorChangeContext( ContextHandler& rParent,
123 const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) :
124 ContextHandler( rParent ),
125 mrBlipProps( rBlipProps )
127 mrBlipProps.maColorChangeFrom.setUnused();
128 mrBlipProps.maColorChangeTo.setUnused();
129 AttributeList aAttribs( rxAttribs );
130 mbUseAlpha = aAttribs.getBool( XML_useA, true );
133 ColorChangeContext::~ColorChangeContext()
135 if( !mbUseAlpha )
136 mrBlipProps.maColorChangeTo.clearTransparence();
139 Reference< XFastContextHandler > ColorChangeContext::createFastChildContext(
140 sal_Int32 nElement, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException)
142 switch( nElement )
144 case A_TOKEN( clrFrom ):
145 return new ColorContext( *this, mrBlipProps.maColorChangeFrom );
146 case A_TOKEN( clrTo ):
147 return new ColorContext( *this, mrBlipProps.maColorChangeTo );
149 return 0;
152 // ============================================================================
154 BlipContext::BlipContext( ContextHandler& rParent,
155 const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) :
156 ContextHandler( rParent ),
157 mrBlipProps( rBlipProps )
159 AttributeList aAttribs( rxAttribs );
160 if( aAttribs.hasAttribute( R_TOKEN( embed ) ) )
162 // internal picture URL
163 OUString aFragmentPath = getFragmentPathFromRelId( aAttribs.getString( R_TOKEN( embed ), OUString() ) );
164 if( !aFragmentPath.isEmpty() )
165 mrBlipProps.mxGraphic = getFilter().getGraphicHelper().importEmbeddedGraphic( aFragmentPath );
167 else if( aAttribs.hasAttribute( R_TOKEN( link ) ) )
169 // external URL
171 // we will embed this link, this is better than just doing nothing..
172 // TODO: import this graphic as real link, but this requires some
173 // code rework.
174 OUString aRelId = aAttribs.getString( R_TOKEN( link ), OUString() );
175 OUString aTargetLink = getFilter().getAbsoluteUrl( getRelations().getExternalTargetFromRelId( aRelId ) );
176 SfxMedium xMed( aTargetLink, STREAM_STD_READ );
177 xMed.DownLoad();
178 Reference< io::XInputStream > xInStrm = xMed.GetInputStream();
179 if ( xInStrm.is() )
180 mrBlipProps.mxGraphic = getFilter().getGraphicHelper().importGraphic( xInStrm );
184 Reference< XFastContextHandler > BlipContext::createFastChildContext(
185 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
187 AttributeList aAttribs( rxAttribs );
188 switch( nElement )
190 case A_TOKEN( biLevel ):
191 case A_TOKEN( grayscl ):
192 mrBlipProps.moColorEffect = getBaseToken( nElement );
193 break;
195 case A_TOKEN( clrChange ):
196 return new ColorChangeContext( *this, rxAttribs, mrBlipProps );
198 case A_TOKEN( lum ):
199 mrBlipProps.moBrightness = aAttribs.getInteger( XML_bright );
200 mrBlipProps.moContrast = aAttribs.getInteger( XML_contrast );
201 break;
203 return 0;
206 // ============================================================================
208 BlipFillContext::BlipFillContext( ContextHandler& rParent,
209 const Reference< XFastAttributeList >& rxAttribs, BlipFillProperties& rBlipProps ) :
210 ContextHandler( rParent ),
211 mrBlipProps( rBlipProps )
213 AttributeList aAttribs( rxAttribs );
214 mrBlipProps.moRotateWithShape = aAttribs.getBool( XML_rotWithShape );
217 Reference< XFastContextHandler > BlipFillContext::createFastChildContext(
218 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs ) throw (SAXException, RuntimeException)
220 AttributeList aAttribs( rxAttribs );
221 switch( nElement )
223 case A_TOKEN( blip ):
224 return new BlipContext( *this, rxAttribs, mrBlipProps );
226 case A_TOKEN( srcRect ):
228 OUString aDefault( "0" );
229 ::com::sun::star::geometry::IntegerRectangle2D aClipRect;
230 aClipRect.X1 = GetPercent( aAttribs.getString( XML_l, aDefault ) );
231 aClipRect.Y1 = GetPercent( aAttribs.getString( XML_t, aDefault ) );
232 aClipRect.X2 = GetPercent( aAttribs.getString( XML_r, aDefault ) );
233 aClipRect.Y2 = GetPercent( aAttribs.getString( XML_b, aDefault ) );
234 mrBlipProps.moClipRect = aClipRect;
236 break;
238 case A_TOKEN( tile ):
239 mrBlipProps.moBitmapMode = getBaseToken( nElement );
240 mrBlipProps.moTileOffsetX = aAttribs.getInteger( XML_tx );
241 mrBlipProps.moTileOffsetY = aAttribs.getInteger( XML_ty );
242 mrBlipProps.moTileScaleX = aAttribs.getInteger( XML_sx );
243 mrBlipProps.moTileScaleY = aAttribs.getInteger( XML_sy );
244 mrBlipProps.moTileAlign = aAttribs.getToken( XML_algn );
245 mrBlipProps.moTileFlip = aAttribs.getToken( XML_flip );
246 break;
248 case A_TOKEN( stretch ):
249 mrBlipProps.moBitmapMode = getBaseToken( nElement );
250 return this; // for fillRect element
252 case A_TOKEN( fillRect ):
253 mrBlipProps.moFillRect = GetRelativeRect( rxAttribs );
254 break;
256 return 0;
259 // ============================================================================
260 // ============================================================================
262 FillPropertiesContext::FillPropertiesContext( ContextHandler& rParent, FillProperties& rFillProps ) :
263 ContextHandler( rParent ),
264 mrFillProps( rFillProps )
268 Reference< XFastContextHandler > FillPropertiesContext::createFastChildContext(
269 sal_Int32 nElement, const Reference< XFastAttributeList >& rxAttribs )
270 throw ( SAXException, RuntimeException )
272 return createFillContext( *this, nElement, rxAttribs, mrFillProps );
275 Reference< XFastContextHandler > FillPropertiesContext::createFillContext(
276 ContextHandler& rParent, sal_Int32 nElement,
277 const Reference< XFastAttributeList >& rxAttribs, FillProperties& rFillProps )
279 switch( nElement )
281 case A_TOKEN( noFill ): { rFillProps.moFillType = getBaseToken( nElement ); return 0; };
282 case A_TOKEN( solidFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new SolidFillContext( rParent, rxAttribs, rFillProps ); };
283 case A_TOKEN( gradFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new GradientFillContext( rParent, rxAttribs, rFillProps.maGradientProps ); };
284 case A_TOKEN( pattFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new PatternFillContext( rParent, rxAttribs, rFillProps.maPatternProps ); };
285 case A_TOKEN( blipFill ): { rFillProps.moFillType = getBaseToken( nElement ); return new BlipFillContext( rParent, rxAttribs, rFillProps.maBlipProps ); };
286 case A_TOKEN( grpFill ): { rFillProps.moFillType = getBaseToken( nElement ); return 0; }; // TODO
288 return 0;
291 // ============================================================================
293 SimpleFillPropertiesContext::SimpleFillPropertiesContext( ContextHandler& rParent, Color& rColor ) :
294 FillPropertiesContext( rParent, *this ),
295 mrColor( rColor )
299 SimpleFillPropertiesContext::~SimpleFillPropertiesContext()
301 mrColor = getBestSolidColor();
304 // ============================================================================
306 } // namespace drawingml
307 } // namespace oox
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */