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