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 "SVGLinearGradientElementImpl.h"
|
|
20 |
#include "SVGDocumentImpl.h"
|
|
21 |
#include "SVGSchemaData.h"
|
|
22 |
#include "SvgStopElementImpl.h"
|
|
23 |
#include "SVGIntCssValueImpl.h"
|
|
24 |
|
|
25 |
#include "GfxAffineTransform.h"
|
|
26 |
|
|
27 |
_LIT(X1,"x1");
|
|
28 |
_LIT(X2,"x2");
|
|
29 |
_LIT(Y1,"y1");
|
|
30 |
_LIT(Y2,"y2");
|
|
31 |
// ---------------------------------------------------------------------------
|
|
32 |
//
|
|
33 |
// ---------------------------------------------------------------------------
|
|
34 |
CSvgLinearGradientElementImpl* CSvgLinearGradientElementImpl::NewL(const TUint8 aElemID, CSvgDocumentImpl* aDoc )
|
|
35 |
{
|
|
36 |
CSvgLinearGradientElementImpl *self = new (ELeave) CSvgLinearGradientElementImpl(aDoc);
|
|
37 |
CleanupStack::PushL(self);
|
|
38 |
self->ConstructL(aElemID);
|
|
39 |
CleanupStack::Pop(self);
|
|
40 |
return self;
|
|
41 |
}
|
|
42 |
|
|
43 |
// ---------------------------------------------------------------------------
|
|
44 |
//
|
|
45 |
// ---------------------------------------------------------------------------
|
|
46 |
void CSvgLinearGradientElementImpl::ConstructL(const TUint8 aElemID)
|
|
47 |
{
|
|
48 |
CSvgGradientElementImpl::ConstructL(aElemID);
|
|
49 |
|
|
50 |
}
|
|
51 |
|
|
52 |
// ---------------------------------------------------------------------------
|
|
53 |
//
|
|
54 |
// ---------------------------------------------------------------------------
|
|
55 |
CSvgLinearGradientElementImpl::CSvgLinearGradientElementImpl( CSvgDocumentImpl* aDoc ):
|
|
56 |
CSvgGradientElementImpl(aDoc)
|
|
57 |
{
|
|
58 |
iGradientPaint = &iGfxLinearPaint;
|
|
59 |
}
|
|
60 |
|
|
61 |
// ---------------------------------------------------------------------------
|
|
62 |
//Dt:17-Feb-2009 modified the function to support the % values for X1,Y1,X2,Y2
|
|
63 |
//TSW ISSUE ID: ANAE-7NZ8B8
|
|
64 |
// ---------------------------------------------------------------------------
|
|
65 |
TInt CSvgLinearGradientElementImpl::SetAttributeL(const TDesC &aName, const TDesC &aValue)
|
|
66 |
{
|
|
67 |
TFloatFixPt KZero( KFloatFixZero );
|
|
68 |
TFloatFixPt KOne( KFloatFixOne );
|
|
69 |
TFloatFixPt val;
|
|
70 |
if ( aName == X1 || aName == X2 || aName == Y1 || aName == Y2 )
|
|
71 |
{
|
|
72 |
|
|
73 |
if ( IsValidValue(aValue) )
|
|
74 |
{
|
|
75 |
val = TFloatFixPt::ConvertString(aValue);
|
|
76 |
if ( aValue.Locate('%') != KErrNotFound )
|
|
77 |
{
|
|
78 |
val = val / TFloatFixPt(100);
|
|
79 |
}
|
|
80 |
}
|
|
81 |
else
|
|
82 |
{
|
|
83 |
if( aName == X2 )
|
|
84 |
{
|
|
85 |
val = KOne;
|
|
86 |
}
|
|
87 |
else
|
|
88 |
{
|
|
89 |
val = KZero;
|
|
90 |
}
|
|
91 |
}
|
|
92 |
if( aName==X1 )
|
|
93 |
{
|
|
94 |
iGfxLinearPaint.iX1 = val;
|
|
95 |
}
|
|
96 |
else if( aName==Y1 )
|
|
97 |
{
|
|
98 |
iGfxLinearPaint.iY1 = val;
|
|
99 |
}
|
|
100 |
else if( aName==X2 )
|
|
101 |
{
|
|
102 |
iGfxLinearPaint.iX2 = val;
|
|
103 |
}
|
|
104 |
else
|
|
105 |
{
|
|
106 |
iGfxLinearPaint.iY2 = val;
|
|
107 |
}
|
|
108 |
|
|
109 |
}
|
|
110 |
else
|
|
111 |
{
|
|
112 |
CSvgGradientElementImpl::SetAttributeL( aName, aValue );
|
|
113 |
}
|
|
114 |
return 0;
|
|
115 |
}
|
|
116 |
|
|
117 |
// ---------------------------------------------------------------------------
|
|
118 |
//
|
|
119 |
// ---------------------------------------------------------------------------
|
|
120 |
MGfxPaint *CSvgLinearGradientElementImpl::PaintAttribute()
|
|
121 |
{
|
|
122 |
TInt i=0;
|
|
123 |
TFloatFixPt lOffset;
|
|
124 |
TUint32 lStopColor;
|
|
125 |
TFloatFixPt lStopOpacity;
|
|
126 |
if( iStopElementData )
|
|
127 |
{
|
|
128 |
iStopElementData->Reset();
|
|
129 |
}
|
|
130 |
|
|
131 |
TInt svgStopEleArrayCnt = iSvgStopElementArray->Count();
|
|
132 |
for(i=0;i<svgStopEleArrayCnt ;i++)
|
|
133 |
{
|
|
134 |
CSvgStopElementImpl* temp = (*iSvgStopElementArray)[i];
|
|
135 |
|
|
136 |
// Check if the element has valid offset value. If the offset had invalid value
|
|
137 |
// it will be made zero but this function will return FALSE.
|
|
138 |
if( temp->IsValidElement() )
|
|
139 |
{
|
|
140 |
temp->GetOffset(lOffset);
|
|
141 |
temp->GetStopColor(lStopColor);
|
|
142 |
temp->GetStopOpacity (lStopOpacity);
|
|
143 |
TSvgStopData la ;
|
|
144 |
la.iOffset = lOffset;
|
|
145 |
la.iStopColor = lStopColor;
|
|
146 |
la.iStopOpacity = lStopOpacity;
|
|
147 |
TInt error = iStopElementData->Append(la);
|
|
148 |
if(error != KErrNone)
|
|
149 |
{
|
|
150 |
// not enough memory
|
|
151 |
break;
|
|
152 |
}
|
|
153 |
}
|
|
154 |
|
|
155 |
}
|
|
156 |
iGfxLinearPaint.iStopData = iStopElementData;
|
|
157 |
const TGfxAffineTransform& tempTransform = GetCTM();
|
|
158 |
iGradientPaint->iGradientTransform.matrix[0][0] = tempTransform.iM00.iValue;
|
|
159 |
iGradientPaint->iGradientTransform.matrix[0][1] = tempTransform.iM01.iValue;
|
|
160 |
iGradientPaint->iGradientTransform.matrix[0][2] = tempTransform.iM02.iValue;
|
|
161 |
iGradientPaint->iGradientTransform.matrix[1][0] = tempTransform.iM10.iValue;
|
|
162 |
iGradientPaint->iGradientTransform.matrix[1][1] = tempTransform.iM11.iValue;
|
|
163 |
iGradientPaint->iGradientTransform.matrix[1][2] = tempTransform.iM12.iValue;
|
|
164 |
return &iGfxLinearPaint;
|
|
165 |
}
|
|
166 |
|
|
167 |
// ---------------------------------------------------------------------------
|
|
168 |
//
|
|
169 |
// ---------------------------------------------------------------------------
|
|
170 |
TInt CSvgLinearGradientElementImpl::GetAttributeFloat( const TInt aNameId, TFloatFixPt& aValue )
|
|
171 |
{
|
|
172 |
switch ( aNameId )
|
|
173 |
{
|
|
174 |
case KAtrX1:
|
|
175 |
aValue = iGfxLinearPaint.iX1 ;
|
|
176 |
break;
|
|
177 |
case KAtrY1:
|
|
178 |
aValue = iGfxLinearPaint.iY1 ;
|
|
179 |
break;
|
|
180 |
case KAtrX2 :
|
|
181 |
aValue = iGfxLinearPaint.iX2 ;
|
|
182 |
break;
|
|
183 |
case KAtrY2 :
|
|
184 |
aValue = iGfxLinearPaint.iY2 ;
|
|
185 |
break;
|
|
186 |
default:
|
|
187 |
return CSvgElementImpl::GetAttributeFloat( aNameId, aValue );
|
|
188 |
}
|
|
189 |
return 0;
|
|
190 |
}
|
|
191 |
|
|
192 |
// ---------------------------------------------------------------------------
|
|
193 |
//
|
|
194 |
// ---------------------------------------------------------------------------
|
|
195 |
TInt CSvgLinearGradientElementImpl::SetAttributeFloatL( const TInt aNameId, const TFloatFixPt aValue )
|
|
196 |
{
|
|
197 |
switch ( aNameId )
|
|
198 |
{
|
|
199 |
case KAtrX1:
|
|
200 |
iGfxLinearPaint.iX1 = aValue;
|
|
201 |
break;
|
|
202 |
case KAtrY1:
|
|
203 |
iGfxLinearPaint.iY1 = aValue;
|
|
204 |
break;
|
|
205 |
case KAtrX2 :
|
|
206 |
iGfxLinearPaint.iX2 = aValue;
|
|
207 |
break;
|
|
208 |
case KAtrY2 :
|
|
209 |
iGfxLinearPaint.iY2 = aValue;
|
|
210 |
break;
|
|
211 |
default:
|
|
212 |
return CSvgElementImpl::SetAttributeFloatL( aNameId, aValue );
|
|
213 |
}
|
|
214 |
return 0;
|
|
215 |
}
|
|
216 |
TInt CSvgLinearGradientElementImpl::SetAttributeIntL( const TInt aNameId,
|
|
217 |
const TInt32 aValue )
|
|
218 |
{
|
|
219 |
CSvgGradientElementImpl::SetAttributeIntL( aNameId,
|
|
220 |
aValue );
|
|
221 |
return 0;
|
|
222 |
|
|
223 |
}
|
|
224 |
TInt CSvgLinearGradientElementImpl::GetAttributeIntL( const TInt aNameId, TInt32& aValue )
|
|
225 |
{
|
|
226 |
CSvgGradientElementImpl::GetAttributeIntL(aNameId, aValue );
|
|
227 |
return 0;
|
|
228 |
}
|
|
229 |
|
|
230 |
|
|
231 |
// ---------------------------------------------------------------------------
|
|
232 |
//
|
|
233 |
// ---------------------------------------------------------------------------
|
|
234 |
CSvgLinearGradientElementImpl::~CSvgLinearGradientElementImpl()
|
|
235 |
{
|
|
236 |
|
|
237 |
}
|
|
238 |
|
|
239 |
void CSvgLinearGradientElementImpl::Print( TBool aIsEncodeOn )
|
|
240 |
{
|
|
241 |
if (!aIsEncodeOn)
|
|
242 |
{
|
|
243 |
#ifdef _DEBUG
|
|
244 |
RDebug::Printf("<linearGradient xlink:href=\"hmm\" spreadMethod=\"hmm\" gradientUnits=\"hmm\" gradientTransform=\"hmm\" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\"/>",
|
|
245 |
/*Href(),*/ (int)iGfxLinearPaint.iX1, (int)iGfxLinearPaint.iY1, (int)iGfxLinearPaint.iX2, (int)iGfxLinearPaint.iY2);
|
|
246 |
#endif
|
|
247 |
}
|
|
248 |
}
|
|
249 |
TBool CSvgLinearGradientElementImpl::IsValidValue(const TDesC& aValue)
|
|
250 |
{
|
|
251 |
TBool lValidValue = ETrue;
|
|
252 |
// aValue can only contain these characters "-+.%0123456789", If it contains any thing
|
|
253 |
// other than this it should be treated as 0.
|
|
254 |
|
|
255 |
_LIT(KValidChars,"-+.%0123456789");
|
|
256 |
TBufC<14> lValidChars(KValidChars);
|
|
257 |
|
|
258 |
TInt llength = aValue.Length();
|
|
259 |
|
|
260 |
for( int charpos = 0 ; charpos < llength; charpos++ )
|
|
261 |
{
|
|
262 |
if( lValidChars.Locate(aValue[charpos]) == KErrNotFound )
|
|
263 |
{
|
|
264 |
|
|
265 |
lValidValue = EFalse;
|
|
266 |
break;
|
|
267 |
}
|
|
268 |
}
|
|
269 |
|
|
270 |
return lValidValue;
|
|
271 |
}
|