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