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 |
#include "SVGPaintCssValueImpl.h"
|
|
20 |
#include "SVGFloatCssValueImpl.h"
|
|
21 |
|
|
22 |
#include "SVGElementImpl.h"
|
|
23 |
#include "SVGColor.h"
|
|
24 |
#include "GfxPaint.h"
|
|
25 |
|
|
26 |
#include "SVGDocumentImpl.h"
|
|
27 |
#include "SVGGradientElementImpl.h"
|
|
28 |
#include "SVGSolidColorElementImpl.h"
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
// ---------------------------------------------------------------------------
|
|
33 |
//
|
|
34 |
// ---------------------------------------------------------------------------
|
|
35 |
CPaintCssValueImpl::~CPaintCssValueImpl()
|
|
36 |
{
|
|
37 |
|
|
38 |
if( iUrlId )
|
|
39 |
{
|
|
40 |
delete iUrlId;
|
|
41 |
iUrlId = NULL ;
|
|
42 |
}
|
|
43 |
|
|
44 |
if ( iValue && iIsValueOwned )
|
|
45 |
|
|
46 |
{
|
|
47 |
delete ( TSvgColor * ) iValue;
|
|
48 |
}
|
|
49 |
iValue = NULL;
|
|
50 |
}
|
|
51 |
|
|
52 |
// ---------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
// ---------------------------------------------------------------------------
|
|
55 |
MGfxPaint* CPaintCssValueImpl::Value()
|
|
56 |
{
|
|
57 |
CSvgElementImpl* lReferencedElement = NULL;
|
|
58 |
if ( iUrlFlag && iSvgElementImpl )
|
|
59 |
{
|
|
60 |
// iUrlFlag is true means this paint is gradient.
|
|
61 |
CSvgDocumentImpl *lDoc = (CSvgDocumentImpl *)iSvgElementImpl->OwnerDocument();
|
|
62 |
|
|
63 |
if (lDoc)
|
|
64 |
{
|
|
65 |
if(iUrlId)
|
|
66 |
{
|
|
67 |
lReferencedElement = ( CSvgElementImpl*)lDoc->GetElementById( *iUrlId );
|
|
68 |
if(lReferencedElement)
|
|
69 |
TInt elementId = lReferencedElement->ElemID();
|
|
70 |
if ( lReferencedElement && ((lReferencedElement->ElemID() == KSvgLinearGradientElement) ||
|
|
71 |
(lReferencedElement->ElemID() == KSvgRadialGradientElement)) )
|
|
72 |
{
|
|
73 |
//Get Attributes from Gradient Element
|
|
74 |
iValue = ((CSvgGradientElementImpl *)lReferencedElement)->PaintAttribute();
|
|
75 |
iIsValueOwned = EFalse;
|
|
76 |
}
|
|
77 |
else if (lReferencedElement && lReferencedElement->ElemID() == KSvgSolidColorElement )
|
|
78 |
{
|
|
79 |
// Get Attributes from solidColor element
|
|
80 |
GetColorFromSolidColorElement(lReferencedElement);
|
|
81 |
// delete the reference because we now have a clone.
|
|
82 |
TRAPD(err, SetValueL(iValue->GetColor()));
|
|
83 |
delete iUrlId;
|
|
84 |
iUrlId = NULL;
|
|
85 |
if (err)
|
|
86 |
{
|
|
87 |
#ifdef _DEBUG
|
|
88 |
RDebug::Printf("CPaintCssValueImpl::Value() error trapped=%d", err);
|
|
89 |
#endif
|
|
90 |
}
|
|
91 |
iUrlFlag = EFalse;
|
|
92 |
}
|
|
93 |
else // id = color value... for some reason like <rect id="red" fill="red"
|
|
94 |
{
|
|
95 |
TRAPD(err, SetValueL(iUrlId->Des()));
|
|
96 |
if (err)
|
|
97 |
{
|
|
98 |
#ifdef _DEBUG
|
|
99 |
RDebug::Printf("CPaintCssValueImpl::Value() error trapped=%d", err);
|
|
100 |
#endif
|
|
101 |
}
|
|
102 |
}
|
|
103 |
}
|
|
104 |
}
|
|
105 |
}
|
|
106 |
|
|
107 |
return iValue;
|
|
108 |
}
|
|
109 |
|
|
110 |
// ---------------------------------------------------------------------------
|
|
111 |
//
|
|
112 |
// ---------------------------------------------------------------------------
|
|
113 |
TInt CPaintCssValueImpl::SetValueL( const TDesC& aValue )
|
|
114 |
{
|
|
115 |
if ( iValue )
|
|
116 |
{
|
|
117 |
delete ( TSvgColor * ) iValue;
|
|
118 |
iValue = NULL;
|
|
119 |
iIsValueOwned = EFalse;
|
|
120 |
}
|
|
121 |
|
|
122 |
_LIT( KNone, "none" );
|
|
123 |
|
|
124 |
_LIT( KCurrentColor, "currentColor" );
|
|
125 |
_LIT(KUrl,"url");
|
|
126 |
|
|
127 |
|
|
128 |
TUint32 tempVal = 0x000000;//default is 'black'
|
|
129 |
if ( aValue == KNone )
|
|
130 |
{
|
|
131 |
tempVal = KGfxColorNull;
|
|
132 |
}
|
|
133 |
else if ( aValue == KCurrentColor )
|
|
134 |
{
|
|
135 |
tempVal = KSvgCurrentColor;
|
|
136 |
}
|
|
137 |
else if (aValue.Left(3) == KUrl)
|
|
138 |
{
|
|
139 |
// URL = gradient at the moment...
|
|
140 |
iUrlFlag=ETrue;
|
|
141 |
|
|
142 |
HBufC* lReferenceId = (aValue.Right(aValue.Length()-5)).AllocL();
|
|
143 |
|
|
144 |
|
|
145 |
if( iUrlId )
|
|
146 |
{
|
|
147 |
delete iUrlId;
|
|
148 |
iUrlId = NULL;
|
|
149 |
}
|
|
150 |
|
|
151 |
iUrlId = (lReferenceId->Left(lReferenceId->Length()-1)).AllocL();
|
|
152 |
|
|
153 |
delete lReferenceId;
|
|
154 |
lReferenceId = NULL;
|
|
155 |
|
|
156 |
// Return it from here otherwise a memory Leak will occur
|
|
157 |
return KErrNone;
|
|
158 |
|
|
159 |
}
|
|
160 |
else
|
|
161 |
{
|
|
162 |
|
|
163 |
|
|
164 |
TSvgColor tColor(KGfxColorNull);
|
|
165 |
if( tColor.GetStringL( aValue,tempVal) != EFalse )
|
|
166 |
{
|
|
167 |
}
|
|
168 |
else
|
|
169 |
{
|
|
170 |
tempVal = 0;
|
|
171 |
iDefaultSet = ETrue;
|
|
172 |
}
|
|
173 |
}
|
|
174 |
iValue = new ( ELeave ) TSvgColor( tempVal );
|
|
175 |
iIsValueOwned = ETrue;
|
|
176 |
return KErrNone;
|
|
177 |
}
|
|
178 |
|
|
179 |
// ---------------------------------------------------------------------------
|
|
180 |
//
|
|
181 |
// ---------------------------------------------------------------------------
|
|
182 |
TInt CPaintCssValueImpl::SetValueL( const TInt& aValue )
|
|
183 |
{
|
|
184 |
if ( iValue && !iUrlFlag)
|
|
185 |
{
|
|
186 |
delete ( TSvgColor * ) iValue;
|
|
187 |
iValue = NULL;
|
|
188 |
}
|
|
189 |
iUrlFlag = EFalse;
|
|
190 |
iValue = new ( ELeave ) TSvgColor( aValue );
|
|
191 |
iIsValueOwned = ETrue;
|
|
192 |
return KErrNone;
|
|
193 |
}
|
|
194 |
// ---------------------------------------------------------------------------
|
|
195 |
// This method gets the color value from the referenced solidColor element
|
|
196 |
// ---------------------------------------------------------------------------
|
|
197 |
void CPaintCssValueImpl::GetColorFromSolidColorElement(CSvgElementImpl* aReferencedElement)
|
|
198 |
{
|
|
199 |
CCssValue* lCssValue = NULL;
|
|
200 |
aReferencedElement->FindProperty( KCSS_ATTR_FILL, lCssValue, aReferencedElement );
|
|
201 |
if (lCssValue != NULL)
|
|
202 |
{
|
|
203 |
iValue = ((CPaintCssValueImpl*)lCssValue)->Value();
|
|
204 |
((CSvgSolidColorElementImpl*)aReferencedElement)->ApplyOpacitytoElement( iSvgElementImpl );
|
|
205 |
}
|
|
206 |
}
|
|
207 |
|
|
208 |
/*// ---------------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
// ---------------------------------------------------------------------------
|
|
211 |
void CPaintCssValueImpl::SetL( CPaintCssValueImpl* aValue )
|
|
212 |
{
|
|
213 |
iSvgElementImpl = aValue->iSvgElementImpl;
|
|
214 |
iValueType = aValue->iValueType;
|
|
215 |
|
|
216 |
if (aValue->iValue && !aValue->iUrlFlag)
|
|
217 |
{
|
|
218 |
CloneRGBValueL( ((TSvgColor*)(aValue->iValue))->Value());
|
|
219 |
}
|
|
220 |
else if (aValue->iValue)
|
|
221 |
{
|
|
222 |
iValue = aValue->iValue;
|
|
223 |
}
|
|
224 |
|
|
225 |
iDefaultSet = aValue->iDefaultSet;
|
|
226 |
iUrlFlag = aValue->iUrlFlag;
|
|
227 |
|
|
228 |
if( aValue->iUrlFlag )
|
|
229 |
{
|
|
230 |
SetUrlIdL(aValue->iUrlId->Des());
|
|
231 |
}
|
|
232 |
}
|
|
233 |
*/
|
|
234 |
|
|
235 |
// *******************************************************
|
|
236 |
// Private
|
|
237 |
|
|
238 |
|
|
239 |
// ---------------------------------------------------------------------------
|
|
240 |
//
|
|
241 |
// ---------------------------------------------------------------------------
|
|
242 |
CPaintCssValueImpl::CPaintCssValueImpl() :iUrlId(NULL), iValue( NULL ),
|
|
243 |
iUrlFlag(EFalse),
|
|
244 |
iDefaultSet (EFalse),
|
|
245 |
iIsValueOwned( EFalse )
|
|
246 |
{
|
|
247 |
}
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
// ---------------------------------------------------------------------------
|
|
252 |
//
|
|
253 |
// ---------------------------------------------------------------------------
|
|
254 |
void CPaintCssValueImpl::SetUrlflag()
|
|
255 |
{
|
|
256 |
iUrlFlag= ETrue;
|
|
257 |
}
|
|
258 |
|
|
259 |
// ---------------------------------------------------------------------------
|
|
260 |
//
|
|
261 |
// ---------------------------------------------------------------------------
|
|
262 |
TBool CPaintCssValueImpl::GetUrlflag()
|
|
263 |
{
|
|
264 |
return iUrlFlag;
|
|
265 |
}
|
|
266 |
|
|
267 |
// ---------------------------------------------------------------------------
|
|
268 |
//
|
|
269 |
// ---------------------------------------------------------------------------
|
|
270 |
void CPaintCssValueImpl::SetUrlIdL(const TDesC& aValue)
|
|
271 |
{
|
|
272 |
if( iUrlId )
|
|
273 |
{
|
|
274 |
delete iUrlId;
|
|
275 |
iUrlId = NULL;
|
|
276 |
}
|
|
277 |
iUrlId = aValue.AllocL();
|
|
278 |
}
|
|
279 |
|
|
280 |
|
|
281 |
// ---------------------------------------------------------------------------
|
|
282 |
//
|
|
283 |
// ---------------------------------------------------------------------------
|
|
284 |
TInt CPaintCssValueImpl::CloneRGBValueL(const TInt& aValue)
|
|
285 |
{
|
|
286 |
if (!iUrlFlag)
|
|
287 |
{
|
|
288 |
if(iValue)
|
|
289 |
{
|
|
290 |
delete ( TSvgColor * ) iValue;
|
|
291 |
}
|
|
292 |
iValue = new ( ELeave ) TSvgColor( (TUint32)aValue );
|
|
293 |
iIsValueOwned = ETrue;
|
|
294 |
}
|
|
295 |
|
|
296 |
return KErrNone;
|
|
297 |
}
|
|
298 |
|
|
299 |
// ---------------------------------------------------------------------------
|
|
300 |
//
|
|
301 |
// ---------------------------------------------------------------------------
|
|
302 |
HBufC* CPaintCssValueImpl::GetUrlId()
|
|
303 |
{
|
|
304 |
return iUrlId;
|
|
305 |
}
|
|
306 |
|
|
307 |
// ---------------------------------------------------------------------------
|
|
308 |
//
|
|
309 |
// ---------------------------------------------------------------------------
|
|
310 |
TBool CPaintCssValueImpl::IsEqual( CCssValue* aValue )
|
|
311 |
{
|
|
312 |
if (((CPaintCssValueImpl*)aValue)->iValue == iValue)
|
|
313 |
{
|
|
314 |
return ETrue;
|
|
315 |
}
|
|
316 |
|
|
317 |
return EFalse;
|
|
318 |
}
|
|
319 |
|
|
320 |
|
|
321 |
// ---------------------------------------------------------------------------
|
|
322 |
// IsDefaultSet check if default color is set
|
|
323 |
// ---------------------------------------------------------------------------
|
|
324 |
TBool CPaintCssValueImpl::IsDefaultSet()
|
|
325 |
{
|
|
326 |
return iDefaultSet;
|
|
327 |
}
|
|
328 |
|
|
329 |
|
|
330 |
// ---------------------------------------------------------------------------
|
|
331 |
//
|
|
332 |
// ---------------------------------------------------------------------------
|
|
333 |
void CPaintCssValueImpl::SetElement(CSvgElementImpl* aElement)
|
|
334 |
{
|
|
335 |
iSvgElementImpl = aElement;
|
|
336 |
}
|
|
337 |
|
|
338 |
// ---------------------------------------------------------------------------
|
|
339 |
//
|
|
340 |
// ---------------------------------------------------------------------------
|
|
341 |
CSvgElementImpl* CPaintCssValueImpl::GetElement()
|
|
342 |
{
|
|
343 |
return iSvgElementImpl;
|
|
344 |
}
|
|
345 |
|
|
346 |
// ---------------------------------------------------------------------------
|
|
347 |
//
|
|
348 |
// ---------------------------------------------------------------------------
|
|
349 |
void CPaintCssValueImpl::Print()
|
|
350 |
{
|
|
351 |
#ifdef _DEBUG
|
|
352 |
if (iValue)
|
|
353 |
{
|
|
354 |
RDebug::Printf("%d", (( TSvgColor* )iValue)->GetColor() );
|
|
355 |
}
|
|
356 |
#endif
|
|
357 |
}
|