|
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 "SVGGradientElementImpl.h" |
|
20 #include "SVGDocumentImpl.h" |
|
21 |
|
22 // --------------------------------------------------------------------------- |
|
23 // |
|
24 // --------------------------------------------------------------------------- |
|
25 CSvgGradientElementImpl::CSvgGradientElementImpl( CSvgDocumentImpl* aDoc ) |
|
26 { |
|
27 SetOwnerDocument(aDoc); |
|
28 } |
|
29 |
|
30 // --------------------------------------------------------------------------- |
|
31 // |
|
32 // --------------------------------------------------------------------------- |
|
33 void CSvgGradientElementImpl::ConstructL(const TUint8 aElemID) |
|
34 { |
|
35 CSvgElementImpl::InitializeL( aElemID ); |
|
36 |
|
37 iSvgStyleProperties = new(ELeave) RPointerArray<CCssValue>(KCSS_MAX_ATTR); |
|
38 User::LeaveIfError( iSvgStyleProperties->Append( NULL ) ); |
|
39 iSvgStyleProperties->Remove( 0 ); |
|
40 iSvgUriReferenceImpl = CSvgUriReferenceImpl::NewL(); |
|
41 |
|
42 iSvgTransformable = CSvgTransformableImpl::NewL(); |
|
43 iSvgStopElementArray = new( ELeave ) RPointerArray<CSvgStopElementImpl> ( 1 ); |
|
44 |
|
45 iStopElementData = new(ELeave) RArray<TSvgStopData> (1); |
|
46 iStopElementData->Reset(); |
|
47 } |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 // --------------------------------------------------------------------------- |
|
52 CSvgGradientElementImpl::~CSvgGradientElementImpl() |
|
53 { |
|
54 if(iSvgStopElementArray) |
|
55 { |
|
56 iSvgStopElementArray->Close(); |
|
57 delete iSvgStopElementArray; |
|
58 iSvgStopElementArray = NULL; |
|
59 } |
|
60 |
|
61 if ( iSvgStyleProperties ) |
|
62 { |
|
63 iSvgStyleProperties->Close(); |
|
64 delete iSvgStyleProperties; |
|
65 iSvgStyleProperties = NULL; |
|
66 } |
|
67 |
|
68 if ( iSvgUriReferenceImpl ) |
|
69 { |
|
70 delete iSvgUriReferenceImpl; |
|
71 iSvgUriReferenceImpl = NULL; |
|
72 } |
|
73 |
|
74 if(iStopElementData) |
|
75 { |
|
76 iStopElementData->Close(); |
|
77 delete iStopElementData; |
|
78 iStopElementData = NULL; |
|
79 } |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // |
|
84 // --------------------------------------------------------------------------- |
|
85 TInt CSvgGradientElementImpl::SetAttributeL( const TDesC& aName,const TDesC& aValue ) |
|
86 { |
|
87 CSvgElementImpl::SetAttributeL(aName,aValue); |
|
88 |
|
89 if(aName==_L("gradientUnits")||aName==_L("patternUnits")) |
|
90 { |
|
91 if(aValue==_L("userSpaceOnUse")) |
|
92 iGradientPaint->iGradientUnits = KuserSpaceOnUse; |
|
93 else if(aValue==_L("objectBoundingBox")) |
|
94 iGradientPaint->iGradientUnits = KobjectBoundingBox; |
|
95 } |
|
96 else if(aName==_L("spreadMethod")) |
|
97 { |
|
98 if(aValue==_L("pad")) |
|
99 iGradientPaint->iSpreadMethod = KspreadMethodPad; |
|
100 else if(aValue==_L("reflect")) |
|
101 iGradientPaint->iSpreadMethod = KspreadMethodReflect; |
|
102 else if(aValue==_L("repeat")) |
|
103 iGradientPaint->iSpreadMethod = KspreadMethodRepeat; |
|
104 } |
|
105 return KErrNone; |
|
106 } |
|
107 |
|
108 TInt CSvgGradientElementImpl::SetAttributeIntL( const TInt aNameId, |
|
109 const TInt32 aValue ) |
|
110 { |
|
111 if(aNameId == KAtrSpreadMethods) |
|
112 { |
|
113 |
|
114 iGradientPaint->iSpreadMethod = (TUint16) aValue; |
|
115 } |
|
116 |
|
117 else if(aNameId == KAtrGradientUnits) |
|
118 { |
|
119 iGradientPaint->iGradientUnits = (TUint16) aValue; |
|
120 } |
|
121 |
|
122 else |
|
123 CSvgElementImpl::SetAttributeIntL (aNameId,aValue); |
|
124 return 0; |
|
125 } |
|
126 TInt CSvgGradientElementImpl::GetAttributeIntL( const TInt aNameId, TInt32& aValue ) |
|
127 { |
|
128 if(aNameId == KAtrSpreadMethods) |
|
129 { |
|
130 aValue = iGradientPaint->iSpreadMethod ; |
|
131 } |
|
132 |
|
133 else if(aNameId == KAtrGradientUnits) |
|
134 { |
|
135 aValue = iGradientPaint->iGradientUnits ; |
|
136 } |
|
137 |
|
138 else |
|
139 CSvgElementImpl::GetAttributeIntL (aNameId,aValue); |
|
140 return 0; |
|
141 } |
|
142 |
|
143 // --------------------------------------------------------------------------- |
|
144 // Adjusts the offset values of all the previously added elements such that |
|
145 // each gradient offset value is greater than the previous gradient stop's |
|
146 // offset value. |
|
147 // --------------------------------------------------------------------------- |
|
148 void CSvgGradientElementImpl::UpdateOffsetValues(CSvgStopElementImpl *aStopEl) |
|
149 { |
|
150 TInt count = iSvgStopElementArray->Count(); |
|
151 |
|
152 if (count == 1) |
|
153 { |
|
154 return; |
|
155 } |
|
156 |
|
157 TFloatFixPt aNewOffset = aStopEl->iOffset; |
|
158 |
|
159 //Since the Stop Element is already added, The loop runs for "count - 1" times. |
|
160 for (TInt i=0; i < count - 1; i++) |
|
161 { |
|
162 TFloatFixPt OldOffset = iSvgStopElementArray->operator[](i)->iOffset; |
|
163 |
|
164 if ( OldOffset >= aNewOffset ) |
|
165 { |
|
166 //set this latter value up so it has at least as high a value as the |
|
167 //previous stop offsets |
|
168 aStopEl->iOffset = OldOffset; |
|
169 |
|
170 if (aStopEl->iOffset == TFloatFixPt(0)) |
|
171 { |
|
172 aStopEl->iOffset += TFloatFixPt(.001f); |
|
173 } |
|
174 else |
|
175 { |
|
176 //two stop offsets have the same value now so make the one before ever so slightly less |
|
177 //the latter one will control the "overlap point" |
|
178 OldOffset -= TFloatFixPt(.001f); |
|
179 } |
|
180 |
|
181 iSvgStopElementArray->operator[](i)->iOffset = OldOffset; |
|
182 } |
|
183 } |
|
184 |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // The function not only adds the element in Stop element array but also |
|
189 // adjusts the offset values of all the previously added elements such that |
|
190 // each gradient offset value is greater than the previous gradient stop's |
|
191 // offset value. |
|
192 // --------------------------------------------------------------------------- |
|
193 void CSvgGradientElementImpl::AddStopElementInArray(CSvgStopElementImpl *aStopEl) |
|
194 { |
|
195 |
|
196 TBool lFound = EFalse; |
|
197 |
|
198 TInt err = iSvgStopElementArray->Find(aStopEl); |
|
199 |
|
200 if( err != KErrNotFound ) |
|
201 { |
|
202 lFound = ETrue; |
|
203 } |
|
204 |
|
205 if(!lFound) |
|
206 { |
|
207 iSvgStopElementArray->Append(aStopEl); |
|
208 UpdateOffsetValues(aStopEl); |
|
209 } |
|
210 |
|
211 } |
|
212 |
|
213 void CSvgGradientElementImpl::SetGradientTransMatrix(SVGReal aMatrix[2][3]) |
|
214 { |
|
215 TGfxAffineTransform tempTransform; |
|
216 MSvgTransformList* trList; |
|
217 GetTransform( trList ); |
|
218 TGfxAffineTransform originalTransform = trList->GetItem( 0 ); |
|
219 tempTransform.iM00.iValue = aMatrix[0][0]; |
|
220 tempTransform.iM01.iValue = aMatrix[0][1]; |
|
221 tempTransform.iM02.iValue = aMatrix[0][2]; |
|
222 tempTransform.iM10.iValue = aMatrix[1][0]; |
|
223 tempTransform.iM11.iValue = aMatrix[1][1]; |
|
224 tempTransform.iM12.iValue = aMatrix[1][2]; |
|
225 |
|
226 TUint32 lTransType = KTransformIdentity; |
|
227 |
|
228 TFloatFixPt KZero; |
|
229 TFloatFixPt KOne( KFloatFixOne ); |
|
230 if ( tempTransform.iM02 != KZero || tempTransform.iM12 != KZero ) |
|
231 lTransType |= KTransformTranslate; |
|
232 |
|
233 if ( tempTransform.iM00 != KZero || tempTransform.iM11 != KZero ) |
|
234 lTransType |= KTransformScale; |
|
235 |
|
236 if ( tempTransform.iM01 != KZero || tempTransform.iM10 != KZero ) |
|
237 lTransType |= KTransformShear; |
|
238 |
|
239 if ( (int)lTransType == KTransformScale && |
|
240 tempTransform.iM00 == KOne && tempTransform.iM11 == KOne ) |
|
241 lTransType = KTransformIdentity; |
|
242 |
|
243 tempTransform.iTransType = lTransType; |
|
244 |
|
245 originalTransform.Concatenate( tempTransform ); |
|
246 trList->ReplaceItem( originalTransform, 0 ); |
|
247 } |