|
1 /* |
|
2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: SVG Implementation source file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #if !defined(__E32BASE_H__) |
|
20 #include <e32base.h> |
|
21 #endif |
|
22 #include "SVGCircleElementImpl.h" |
|
23 #include "SVGElementImpl.h" |
|
24 #include "SVGDocumentImpl.h" |
|
25 #include "SVGSchemaData.h" |
|
26 |
|
27 #include "GfxAffineTransform.h" |
|
28 |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 // --------------------------------------------------------------------------- |
|
33 CSvgCircleElementImpl* CSvgCircleElementImpl::NewL( const TUint8 aElemID, |
|
34 CSvgDocumentImpl* aDoc ) |
|
35 { |
|
36 CSvgCircleElementImpl* self = new ( ELeave ) |
|
37 CSvgCircleElementImpl( aDoc ); |
|
38 CleanupStack::PushL( self ); |
|
39 self->ConstructL( aElemID ); |
|
40 CleanupStack::Pop(); |
|
41 |
|
42 return self; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 // --------------------------------------------------------------------------- |
|
48 CSvgCircleElementImpl* CSvgCircleElementImpl::NewLC( const TUint8 aElemID, |
|
49 CSvgDocumentImpl* aDoc ) |
|
50 { |
|
51 CSvgCircleElementImpl* self = new ( ELeave ) |
|
52 CSvgCircleElementImpl( aDoc ); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL( aElemID ); |
|
55 |
|
56 return self; |
|
57 } |
|
58 |
|
59 |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 // --------------------------------------------------------------------------- |
|
63 void CSvgCircleElementImpl::ConstructL( const TUint8 aElemID ) |
|
64 { |
|
65 CSvgElementImpl::InitializeL( aElemID ); |
|
66 |
|
67 iSvgStyleProperties = new(ELeave) RPointerArray<CCssValue>(KCSS_MAX_ATTR); |
|
68 User::LeaveIfError( iSvgStyleProperties->Append( NULL ) ); |
|
69 iSvgStyleProperties->Remove( 0 ); |
|
70 |
|
71 iSvgTransformable = CSvgTransformableImpl::NewL(); |
|
72 |
|
73 iReqAttrFlag=KSVG_CIRCLE_ELEMFLAG; |
|
74 |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 // --------------------------------------------------------------------------- |
|
80 CSvgCircleElementImpl::~CSvgCircleElementImpl() |
|
81 { |
|
82 |
|
83 if ( iSvgStyleProperties ) |
|
84 { |
|
85 iSvgStyleProperties->Close(); |
|
86 delete iSvgStyleProperties; |
|
87 iSvgStyleProperties = NULL; |
|
88 } |
|
89 } |
|
90 |
|
91 // ******************************************************* |
|
92 // From SVG DOM |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 // --------------------------------------------------------------------------- |
|
97 TFloatFixPt CSvgCircleElementImpl::Cx() |
|
98 { |
|
99 #ifdef SVG_FLOAT_BUILD |
|
100 return iCircle.iX + (iCircle.iWidth * TFloatFixPt( 0.5f ) ); |
|
101 #else |
|
102 return iCircle.iX + (iCircle.iWidth >> 1); |
|
103 #endif |
|
104 |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 // --------------------------------------------------------------------------- |
|
110 |
|
111 TFloatFixPt CSvgCircleElementImpl::Cy() |
|
112 { |
|
113 #ifdef SVG_FLOAT_BUILD |
|
114 return iCircle.iY + (iCircle.iHeight * .5f); |
|
115 #else |
|
116 return iCircle.iY + (iCircle.iHeight >> 1); |
|
117 #endif |
|
118 } |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 // --------------------------------------------------------------------------- |
|
122 |
|
123 TFloatFixPt CSvgCircleElementImpl::R() |
|
124 { |
|
125 #ifdef SVG_FLOAT_BUILD |
|
126 return iCircle.iWidth * .5f; |
|
127 #else |
|
128 return iCircle.iWidth >> 1; |
|
129 #endif |
|
130 } |
|
131 |
|
132 // ******************************************************* |
|
133 // SVG Implementation |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 // --------------------------------------------------------------------------- |
|
138 |
|
139 void CSvgCircleElementImpl::SetCx( TFloatFixPt aCx ) |
|
140 { |
|
141 #ifdef SVG_FLOAT_BUILD |
|
142 iCircle.iX = aCx - (iCircle.iWidth * .5f); |
|
143 #else |
|
144 iCircle.iX = aCx - (iCircle.iWidth >> 1); |
|
145 #endif |
|
146 } |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // |
|
150 // --------------------------------------------------------------------------- |
|
151 |
|
152 void CSvgCircleElementImpl::SetCy( TFloatFixPt aCy ) |
|
153 { |
|
154 #ifdef SVG_FLOAT_BUILD |
|
155 iCircle.iY = aCy - (iCircle.iHeight * .5f); |
|
156 #else |
|
157 iCircle.iY = aCy - (iCircle.iHeight >> 1); |
|
158 #endif |
|
159 |
|
160 } |
|
161 |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 // --------------------------------------------------------------------------- |
|
165 |
|
166 void CSvgCircleElementImpl::SetR( TFloatFixPt aR ) |
|
167 { |
|
168 #ifdef SVG_FLOAT_BUILD |
|
169 if (aR < TFloatFixPt(0)) |
|
170 { |
|
171 aR = 0; |
|
172 } |
|
173 iCircle.iX += (iCircle.iWidth * TFloatFixPt(.5f)) - aR; |
|
174 iCircle.iWidth = aR * TFloatFixPt(2.0f); |
|
175 // Both x and width will be changed. |
|
176 iCircle.iY += (iCircle.iHeight * TFloatFixPt(.5f)) - aR; |
|
177 iCircle.iHeight = aR * TFloatFixPt(2.0f); |
|
178 #else |
|
179 if (aR < TFloatFixPt(0, ETrue)) |
|
180 { |
|
181 aR = TFloatFixPt(0, ETrue); |
|
182 } |
|
183 iCircle.iX += (iCircle.iWidth >> 1) - aR; |
|
184 iCircle.iWidth = aR << 1; |
|
185 // Both x and width will be changed. |
|
186 iCircle.iY += (iCircle.iHeight >> 1) - aR; |
|
187 iCircle.iHeight = aR << 1; |
|
188 #endif |
|
189 |
|
190 } |
|
191 |
|
192 // ******************************************************* |
|
193 // From MXmlElement |
|
194 |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 // --------------------------------------------------------------------------- |
|
198 TInt CSvgCircleElementImpl::SetAttributeL( const TDesC& aName, |
|
199 const TDesC& aValue ) |
|
200 { |
|
201 CSvgElementImpl::SetAttributeL(aName,aValue); |
|
202 return KErrNone; |
|
203 } |
|
204 |
|
205 |
|
206 // From MXmlElementOpt |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // |
|
210 // --------------------------------------------------------------------------- |
|
211 TInt CSvgCircleElementImpl::GetAttributeFloat( const TInt aNameId, |
|
212 TFloatFixPt& aValue ) |
|
213 { |
|
214 switch ( aNameId ) |
|
215 { |
|
216 case KAtrCx: |
|
217 case KAtrRefX: |
|
218 aValue = Cx(); |
|
219 break; |
|
220 case KAtrCy: |
|
221 case KAtrRefY: |
|
222 aValue = Cy(); |
|
223 break; |
|
224 case KAtrRadius: |
|
225 aValue = R(); |
|
226 break; |
|
227 default: |
|
228 return CSvgElementImpl::GetAttributeFloat( aNameId, aValue ); |
|
229 } |
|
230 |
|
231 return KErrNone; |
|
232 } |
|
233 |
|
234 // --------------------------------------------------------------------------- |
|
235 // |
|
236 // --------------------------------------------------------------------------- |
|
237 TInt CSvgCircleElementImpl::SetAttributeFloatL( const TInt aNameId, |
|
238 const TFloatFixPt aValue ) |
|
239 { |
|
240 switch ( aNameId ) |
|
241 { |
|
242 case KAtrCx: |
|
243 SetCx( aValue ); |
|
244 break; |
|
245 case KAtrCy: |
|
246 SetCy( aValue ); |
|
247 break; |
|
248 case KAtrRadius: |
|
249 SetR( aValue ); |
|
250 iReqAttrFlag = 0; |
|
251 if ( WasTurnedOff() ) |
|
252 { |
|
253 _LIT(KInline , "inline"); |
|
254 // turn it on. this means all the required attributes Are present and |
|
255 // hence we can render it. |
|
256 CSvgElementImpl::SetPropertyL(KCSS_ATTR_DISPLAY, KInline); |
|
257 SetTurnOff( EFalse ); |
|
258 } |
|
259 break; |
|
260 default: |
|
261 return CSvgElementImpl::SetAttributeFloatL( aNameId, aValue ); |
|
262 } |
|
263 return KErrNone; |
|
264 } |
|
265 |
|
266 // ******************************************************* |
|
267 // From CSvgElementImpl |
|
268 |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 // --------------------------------------------------------------------------- |
|
272 TBool CSvgCircleElementImpl::DrawL( CGfx2dGc* aGc, CSvgElementImpl* aElement ) |
|
273 { |
|
274 TFloatFixPt lValue; |
|
275 this->GetAttributeFloat(KAtrRadius,lValue); |
|
276 if (lValue.iValue <= 0) |
|
277 { |
|
278 return ETrue; |
|
279 } |
|
280 this->DrawShapeL( aGc, iCircle, aElement ); |
|
281 return ETrue; |
|
282 } |
|
283 |
|
284 // ******************************************************* |
|
285 // Private |
|
286 |
|
287 |
|
288 |
|
289 // --------------------------------------------------------------------------- |
|
290 // |
|
291 // --------------------------------------------------------------------------- |
|
292 |
|
293 CSvgCircleElementImpl::CSvgCircleElementImpl( CSvgDocumentImpl* aDoc ) : iCircle( 0, |
|
294 0, |
|
295 0, |
|
296 0 ) |
|
297 { |
|
298 SetOwnerDocument(aDoc); |
|
299 } |
|
300 |
|
301 |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // |
|
305 // --------------------------------------------------------------------------- |
|
306 void CSvgCircleElementImpl::GetBBox( TGfxRectangle2D& aBbox ) |
|
307 { |
|
308 iCircle.GetBounds( GetCTM(), aBbox ); |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // |
|
313 // --------------------------------------------------------------------------- |
|
314 void CSvgCircleElementImpl::GetUnscaledBBox( TGfxRectangle2D& aBbox ) |
|
315 { |
|
316 TGfxAffineTransform identityTx; |
|
317 iCircle.GetBounds( identityTx, aBbox ); |
|
318 } |
|
319 |
|
320 // perform a deep clone of this object |
|
321 // --------------------------------------------------------------------------- |
|
322 // |
|
323 // --------------------------------------------------------------------------- |
|
324 MXmlElement* CSvgCircleElementImpl::CloneL(MXmlElement* aParentElement) |
|
325 { |
|
326 |
|
327 CSvgCircleElementImpl* newElement = CSvgCircleElementImpl::NewL( this->ElemID(), |
|
328 ((CSvgDocumentImpl*)iOwnerDocument) ); |
|
329 |
|
330 |
|
331 CleanupStack::PushL(newElement); |
|
332 newElement->iParentNode = aParentElement; |
|
333 |
|
334 // copy everything over |
|
335 this->CopyL(newElement); |
|
336 CleanupStack::Pop(); |
|
337 |
|
338 return newElement; |
|
339 } |
|
340 |
|
341 // perform a deep copy of this object |
|
342 // --------------------------------------------------------------------------- |
|
343 // |
|
344 // --------------------------------------------------------------------------- |
|
345 void CSvgCircleElementImpl::CopyL( CSvgCircleElementImpl* aDestElement ) |
|
346 { |
|
347 if(aDestElement) |
|
348 { |
|
349 // copy iCircle items special to circle |
|
350 aDestElement->iCircle.iX = this->iCircle.iX; |
|
351 aDestElement->iCircle.iY = this->iCircle.iY; |
|
352 aDestElement->iCircle.iWidth = this->iCircle.iWidth; |
|
353 aDestElement->iCircle.iHeight = this->iCircle.iHeight; |
|
354 |
|
355 // copy the reference to idoc (CSvgDocumentImpl) |
|
356 |
|
357 aDestElement->iOwnerDocument = this->iOwnerDocument; |
|
358 |
|
359 // copy stuff from superclass |
|
360 this->CSvgElementImpl::CopyL(aDestElement); |
|
361 } |
|
362 |
|
363 } |
|
364 |
|
365 void CSvgCircleElementImpl::Print( TBool aIsEncodeOn ) |
|
366 { |
|
367 if (!aIsEncodeOn) |
|
368 { |
|
369 #ifdef _DEBUG |
|
370 RDebug::Printf("<circle x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\">", (int)iCircle.iX, (int)iCircle.iY, (int)iCircle.iWidth, (int)iCircle.iHeight); |
|
371 #endif |
|
372 } |
|
373 } |