|
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 "SVGRectElementImpl.h" |
|
23 #include "SVGElementImpl.h" |
|
24 #include "SVGDocumentImpl.h" |
|
25 #include "SVGSchemaData.h" |
|
26 #include "SVGFourPointRect.h" |
|
27 |
|
28 #include "GfxAffineTransform.h" |
|
29 |
|
30 |
|
31 |
|
32 // ========================================================================== |
|
33 // Need method description |
|
34 // ========================================================================== |
|
35 CSvgRectElementImpl* CSvgRectElementImpl::NewL( const TUint8 aElemID, |
|
36 CSvgDocumentImpl* aDoc ) |
|
37 { |
|
38 CSvgRectElementImpl*self = new ( ELeave ) CSvgRectElementImpl( aDoc ); |
|
39 CleanupStack::PushL( self ); |
|
40 self->ConstructL( aElemID); |
|
41 CleanupStack::Pop(); |
|
42 |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ========================================================================== |
|
47 // Need method description |
|
48 // ========================================================================== |
|
49 CSvgRectElementImpl* CSvgRectElementImpl::NewLC( const TUint8 aElemID, |
|
50 CSvgDocumentImpl* aDoc ) |
|
51 { |
|
52 CSvgRectElementImpl*self = new ( ELeave ) CSvgRectElementImpl( aDoc ); |
|
53 CleanupStack::PushL( self ); |
|
54 self->ConstructL( aElemID ); |
|
55 |
|
56 return self; |
|
57 } |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 // ========================================================================== |
|
63 // Need method description |
|
64 // ========================================================================== |
|
65 CSvgRectElementImpl::~CSvgRectElementImpl() |
|
66 { |
|
67 |
|
68 if ( iSvgStyleProperties ) |
|
69 { |
|
70 iSvgStyleProperties->Close(); |
|
71 delete iSvgStyleProperties; |
|
72 iSvgStyleProperties = NULL; |
|
73 } |
|
74 } |
|
75 |
|
76 // ******************************************************* |
|
77 // From SVG DOM |
|
78 |
|
79 // ========================================================================== |
|
80 // Need method description |
|
81 // ========================================================================== |
|
82 TFloatFixPt CSvgRectElementImpl::X() |
|
83 { |
|
84 return iRectangle.iX; |
|
85 } |
|
86 |
|
87 // ========================================================================== |
|
88 // Need method description |
|
89 // ========================================================================== |
|
90 TFloatFixPt CSvgRectElementImpl::Y() |
|
91 { |
|
92 return iRectangle.iY; |
|
93 } |
|
94 |
|
95 // ========================================================================== |
|
96 // Need method description |
|
97 // ========================================================================== |
|
98 TFloatFixPt CSvgRectElementImpl::Width() |
|
99 { |
|
100 return iRectangle.iWidth; |
|
101 } |
|
102 |
|
103 // ========================================================================== |
|
104 // Need method description |
|
105 // ========================================================================== |
|
106 TFloatFixPt CSvgRectElementImpl::Height() |
|
107 { |
|
108 return iRectangle.iHeight; |
|
109 } |
|
110 |
|
111 // ========================================================================== |
|
112 // Need method description |
|
113 // ========================================================================== |
|
114 TFloatFixPt CSvgRectElementImpl::Rx() |
|
115 { |
|
116 return iRectangle.iArcWidth; |
|
117 } |
|
118 |
|
119 // ========================================================================== |
|
120 // Need method description |
|
121 // ========================================================================== |
|
122 TFloatFixPt CSvgRectElementImpl::Ry() |
|
123 { |
|
124 return iRectangle.iArcHeight; |
|
125 } |
|
126 |
|
127 // ========================================================================== |
|
128 // For JSR support |
|
129 // ========================================================================== |
|
130 void CSvgRectElementImpl::SetRectValues(TFloatFixPt aX, TFloatFixPt aY, TFloatFixPt aWidth, TFloatFixPt aHeight) |
|
131 { |
|
132 iRectangle.iX = aX; |
|
133 iRectangle.iY = aY; |
|
134 iRectangle.iHeight = aHeight; |
|
135 iRectangle.iWidth = aWidth; |
|
136 } |
|
137 |
|
138 |
|
139 // From MXmlElementOpt |
|
140 |
|
141 // ========================================================================== |
|
142 // Need method description |
|
143 // ========================================================================== |
|
144 TInt CSvgRectElementImpl::GetAttributeFloat( const TInt aNameId, |
|
145 TFloatFixPt& aValue ) |
|
146 { |
|
147 switch ( aNameId ) |
|
148 { |
|
149 case KAtrX: |
|
150 case KAtrRefX: |
|
151 aValue = X(); |
|
152 break; |
|
153 case KAtrY: |
|
154 case KAtrRefY: |
|
155 aValue = Y(); |
|
156 break; |
|
157 case KAtrWidth: |
|
158 aValue = Width(); |
|
159 break; |
|
160 case KAtrHeight: |
|
161 aValue = Height(); |
|
162 break; |
|
163 // added as a part of get and Set api update |
|
164 case KAtrRx: |
|
165 aValue = iRectangle.iArcWidth; |
|
166 break; |
|
167 case KAtrRy: |
|
168 aValue = iRectangle.iArcHeight; |
|
169 break; |
|
170 default: |
|
171 return CSvgElementImpl::GetAttributeFloat( aNameId, aValue ); |
|
172 } |
|
173 return KErrNone; |
|
174 } |
|
175 |
|
176 // ========================================================================== |
|
177 // Need method description |
|
178 // ========================================================================== |
|
179 TInt CSvgRectElementImpl::SetAttributeFloatL( const TInt aNameId, |
|
180 const TFloatFixPt aValue ) |
|
181 { |
|
182 switch ( aNameId ) |
|
183 { |
|
184 case KAtrX: |
|
185 iRectangle.iX = aValue; |
|
186 break; |
|
187 case KAtrY: |
|
188 |
|
189 iRectangle.iY = aValue; |
|
190 break; |
|
191 |
|
192 case KAtrRx: |
|
193 iRectangle.iArcWidth = aValue; |
|
194 break; |
|
195 case KAtrRy: |
|
196 iRectangle.iArcHeight = aValue; |
|
197 break; |
|
198 |
|
199 |
|
200 case KAtrWidth: |
|
201 if(iReqAttrFlag == KAtrSVGRec) |
|
202 { |
|
203 iReqAttrFlag = KAtrHeight; |
|
204 } |
|
205 else |
|
206 { |
|
207 iReqAttrFlag = 0; |
|
208 |
|
209 if( WasTurnedOff() ) |
|
210 { |
|
211 _LIT(KInline , "inline"); |
|
212 // turn it on. this means all the required attributes Are present and |
|
213 // hence we can render it. |
|
214 CSvgElementImpl::SetPropertyL(KCSS_ATTR_DISPLAY, KInline); |
|
215 SetTurnOff( EFalse ); |
|
216 } |
|
217 } |
|
218 iRectangle.iWidth = aValue; |
|
219 break; |
|
220 |
|
221 case KAtrHeight: |
|
222 if(iReqAttrFlag == KAtrSVGRec) |
|
223 { |
|
224 iReqAttrFlag = KAtrWidth; |
|
225 } |
|
226 else |
|
227 { |
|
228 iReqAttrFlag = 0; |
|
229 if( WasTurnedOff() ) |
|
230 { |
|
231 _LIT(KInline , "inline"); |
|
232 // turn it on. this means all the required attributes Are present and |
|
233 // hence we can render it. |
|
234 CSvgElementImpl::SetPropertyL(KCSS_ATTR_DISPLAY, KInline); |
|
235 SetTurnOff( EFalse ); |
|
236 } |
|
237 } |
|
238 iRectangle.iHeight = aValue; |
|
239 break; |
|
240 default: |
|
241 return CSvgElementImpl::SetAttributeFloatL( aNameId, aValue ); |
|
242 } |
|
243 return KErrNone; |
|
244 } |
|
245 |
|
246 |
|
247 // ******************************************************* |
|
248 // From MXmlElement |
|
249 |
|
250 |
|
251 // ========================================================================== |
|
252 // Need method description |
|
253 // ========================================================================== |
|
254 TInt CSvgRectElementImpl::SetAttributeL( const TDesC& aName, |
|
255 const TDesC& aValue ) |
|
256 { |
|
257 |
|
258 CSvgElementImpl::SetAttributeL(aName,aValue); |
|
259 return KErrNone; |
|
260 } |
|
261 |
|
262 // ========================================================================== |
|
263 // Need method description |
|
264 // ========================================================================== |
|
265 TBool CSvgRectElementImpl::DrawL( CGfx2dGc* aGc, CSvgElementImpl* aElement ) |
|
266 { |
|
267 if (iRectangle.iWidth.iValue <= 0 || iRectangle.iHeight.iValue <= 0 ) |
|
268 { |
|
269 return ETrue; |
|
270 } |
|
271 DrawShapeL( aGc, iRectangle, aElement ); |
|
272 return ETrue; |
|
273 } |
|
274 |
|
275 |
|
276 // ========================================================================== |
|
277 // Need method description |
|
278 // ========================================================================== |
|
279 void CSvgRectElementImpl::ConstructL( const TUint8 aElemID ) |
|
280 { |
|
281 CSvgElementImpl::InitializeL( aElemID ); |
|
282 |
|
283 iSvgStyleProperties = new(ELeave) RPointerArray<CCssValue>(KCSS_MAX_ATTR ); |
|
284 |
|
285 User::LeaveIfError( iSvgStyleProperties->Append( NULL ) ); |
|
286 iSvgStyleProperties->Remove( 0 ); |
|
287 |
|
288 iSvgTransformable = CSvgTransformableImpl::NewL(); |
|
289 |
|
290 iReqAttrFlag=KSVG_RECT_ELEMFLAG; |
|
291 |
|
292 } |
|
293 |
|
294 |
|
295 |
|
296 // ========================================================================== |
|
297 // Need method description |
|
298 // ========================================================================== |
|
299 |
|
300 CSvgRectElementImpl::CSvgRectElementImpl( CSvgDocumentImpl* aDoc ) : iRectangle() |
|
301 { |
|
302 SetOwnerDocument(aDoc); |
|
303 } |
|
304 |
|
305 // ========================================================================== |
|
306 // Need method description |
|
307 // ========================================================================== |
|
308 void CSvgRectElementImpl::GetFourPointBBox(TSvgFourPointRect& aFourPointBbox) |
|
309 { |
|
310 const TGfxAffineTransform& ctm = GetCTM(); |
|
311 |
|
312 TSvgFourPointRect lFourPointBox(iRectangle.iX, iRectangle.iY, iRectangle.iWidth, iRectangle.iHeight); |
|
313 |
|
314 TGfxPoint2D lPoint1, lPoint2, lPoint3, lPoint4; |
|
315 |
|
316 lFourPointBox.GetPoints(lPoint1, lPoint2, lPoint3, lPoint4); |
|
317 |
|
318 ctm.Transform(&lPoint1, &lPoint1, 1); |
|
319 ctm.Transform(&lPoint2, &lPoint2, 1); |
|
320 ctm.Transform(&lPoint3, &lPoint3, 1); |
|
321 ctm.Transform(&lPoint4, &lPoint4, 1); |
|
322 |
|
323 aFourPointBbox.SetRectPoints(lPoint1, lPoint2, lPoint3, lPoint4); |
|
324 } |
|
325 |
|
326 // ========================================================================== |
|
327 // Need method description |
|
328 // ========================================================================== |
|
329 void CSvgRectElementImpl::GetBBox( TGfxRectangle2D& aBbox ) |
|
330 { |
|
331 iRectangle.GetBounds( GetCTM(), aBbox ); |
|
332 } |
|
333 |
|
334 // ========================================================================== |
|
335 // Need method description |
|
336 // ========================================================================== |
|
337 void CSvgRectElementImpl::GetUnscaledBBox( TGfxRectangle2D& aBbox ) |
|
338 { |
|
339 TGfxAffineTransform identityTx; |
|
340 iRectangle.GetBounds( identityTx, aBbox ); |
|
341 } |
|
342 |
|
343 // ========================================================================== |
|
344 // perform a deep clone of this object |
|
345 // ========================================================================== |
|
346 MXmlElement* CSvgRectElementImpl::CloneL(MXmlElement* aParentElement) |
|
347 { |
|
348 // create new rectangle |
|
349 CSvgRectElementImpl* newElement = CSvgRectElementImpl::NewL( this->ElemID(), ((CSvgDocumentImpl*)iOwnerDocument) ); |
|
350 |
|
351 CleanupStack::PushL(newElement); |
|
352 newElement->iParentNode = aParentElement; |
|
353 // copy everything over |
|
354 this->CopyL(newElement); |
|
355 CleanupStack::Pop(); |
|
356 return newElement; |
|
357 } |
|
358 |
|
359 // ========================================================================== |
|
360 // perform a deep copy of this object |
|
361 // ========================================================================== |
|
362 void CSvgRectElementImpl::CopyL( CSvgRectElementImpl* aDestElement ) |
|
363 { |
|
364 if(aDestElement) |
|
365 { |
|
366 // copy stuff from superclass |
|
367 this->CSvgElementImpl::CopyL(aDestElement); |
|
368 |
|
369 // copy iRectangle items special to circle |
|
370 aDestElement->iRectangle.iX = this->iRectangle.iX; |
|
371 aDestElement->iRectangle.iY = this->iRectangle.iY; |
|
372 aDestElement->iRectangle.iHeight = this->iRectangle.iHeight; |
|
373 aDestElement->iRectangle.iWidth = this->iRectangle.iWidth; |
|
374 aDestElement->iRectangle.iArcHeight = this->iRectangle.iArcHeight; |
|
375 aDestElement->iRectangle.iArcWidth = this->iRectangle.iArcWidth; |
|
376 |
|
377 // copy the reference to idoc (CSvgDocumentImpl) |
|
378 aDestElement->iOwnerDocument = this->iOwnerDocument; |
|
379 } |
|
380 |
|
381 } |
|
382 |
|
383 void CSvgRectElementImpl::Print( TBool aIsEncodeOn ) |
|
384 { |
|
385 if (!aIsEncodeOn) |
|
386 { |
|
387 #ifdef _DEBUG |
|
388 RDebug::Printf("<rect x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"%d\" ry=\"%d\">", (int)iRectangle.iX, (int)iRectangle.iY, (int)iRectangle.iWidth, (int)iRectangle.iHeight, (int)iRectangle.iArcWidth, (int)iRectangle.iArcHeight); |
|
389 #endif |
|
390 } |
|
391 } |