|
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 |
|
20 |
|
21 #if !defined(__E32BASE_H__) |
|
22 #include <e32base.h> |
|
23 #endif |
|
24 #include "SVGDescElementImpl.h" |
|
25 #include "SVGElementImpl.h" |
|
26 #include "SVGDocumentImpl.h" |
|
27 #include "SVGSchemaData.h" |
|
28 |
|
29 #include "GfxAffineTransform.h" |
|
30 |
|
31 // ******************************************************* |
|
32 // Constructor/deconstructor |
|
33 |
|
34 // ========================================================================== |
|
35 // Need method description |
|
36 // ========================================================================== |
|
37 CSvgDescElementImpl* CSvgDescElementImpl::NewL( const TUint8 aElemID, |
|
38 CSvgDocumentImpl* aDoc ) |
|
39 { |
|
40 CSvgDescElementImpl*self = new ( ELeave ) CSvgDescElementImpl( aDoc ); |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL( aElemID ); |
|
43 CleanupStack::Pop(); |
|
44 |
|
45 return self; |
|
46 } |
|
47 |
|
48 // ========================================================================== |
|
49 // Need method description |
|
50 // ========================================================================== |
|
51 CSvgDescElementImpl* CSvgDescElementImpl::NewLC( const TUint8 aElemID, |
|
52 CSvgDocumentImpl* aDoc ) |
|
53 { |
|
54 CSvgDescElementImpl*self = new ( ELeave ) CSvgDescElementImpl( aDoc ); |
|
55 CleanupStack::PushL( self ); |
|
56 self->ConstructL( aElemID ); |
|
57 |
|
58 return self; |
|
59 } |
|
60 |
|
61 // ========================================================================== |
|
62 // Need method description |
|
63 // ========================================================================== |
|
64 CSvgDescElementImpl::~CSvgDescElementImpl() |
|
65 { |
|
66 |
|
67 if ( iText ) |
|
68 { |
|
69 delete iText; |
|
70 iText = NULL; |
|
71 } |
|
72 } |
|
73 |
|
74 // ========================================================================== |
|
75 // Need method description |
|
76 // ========================================================================== |
|
77 TInt CSvgDescElementImpl::GetAttributeDes( const TInt aNameId, TPtrC16& aValue ) |
|
78 { |
|
79 switch ( aNameId ) |
|
80 { |
|
81 case KAtrCdata: |
|
82 aValue.Set(*iText); |
|
83 break; |
|
84 default: |
|
85 return CSvgElementImpl::GetAttributeDes( aNameId, aValue ); |
|
86 } |
|
87 return KErrNone; |
|
88 } |
|
89 |
|
90 // ========================================================================== |
|
91 // Need method description |
|
92 // ========================================================================== |
|
93 TInt CSvgDescElementImpl::SetAttributeDesL( const TInt aNameId, |
|
94 const TDesC& aValue ) |
|
95 { |
|
96 switch ( aNameId ) |
|
97 { |
|
98 case KAtrCdata: |
|
99 SetTextL( aValue ); |
|
100 break; |
|
101 |
|
102 default: |
|
103 return CSvgElementImpl::SetAttributeDesL( aNameId, aValue ); |
|
104 } |
|
105 |
|
106 return KErrNone; |
|
107 } |
|
108 |
|
109 // ******************************************************* |
|
110 // From MXmlElement |
|
111 |
|
112 // ========================================================================== |
|
113 // Need method description |
|
114 // ========================================================================== |
|
115 TInt CSvgDescElementImpl::SetAttributeL( const TDesC& aName, |
|
116 const TDesC& aValue ) |
|
117 { |
|
118 |
|
119 if ( this->SetLangSpaceAttributeL( aName, aValue ) ) |
|
120 { |
|
121 return KErrNone; |
|
122 } |
|
123 |
|
124 |
|
125 |
|
126 if ( this->SetTransform( aName, aValue ) ) |
|
127 { |
|
128 return KErrNone; |
|
129 } |
|
130 |
|
131 if ( this->SetTestAttributeL( aName, aValue ) ) |
|
132 { |
|
133 return KErrNone; |
|
134 } |
|
135 |
|
136 if ( SetIdandXmlbaseL( aName, aValue ) ) |
|
137 { |
|
138 return KErrNone; |
|
139 } |
|
140 |
|
141 return KErrNone; |
|
142 } |
|
143 |
|
144 // ========================================================================== |
|
145 // xml:space is an inheritable attribute which can have one of two values: |
|
146 // |
|
147 // default (the initial/default value for xml:space) - When xml:space="default": |
|
148 // - Remove all newline characters. |
|
149 // - Convert all tab characters into space characters. |
|
150 // - Strip off all leading and trailing space characters. |
|
151 // - All contiguous space characters will be consolidated. |
|
152 // |
|
153 // preserve - When xml:space="preserve" : |
|
154 // - Convert all newline and tab characters into space characters. |
|
155 // ========================================================================== |
|
156 void CSvgDescElementImpl::SetTextL( const TDesC& aText ) |
|
157 { |
|
158 _LIT( KPreserve, "preserve" ); |
|
159 |
|
160 if ( iText ) |
|
161 { |
|
162 delete iText; |
|
163 iText = NULL; |
|
164 } |
|
165 |
|
166 iText = aText.AllocL(); |
|
167 TPtr textDes = iText->Des(); |
|
168 |
|
169 // default |
|
170 if ( XMLSpace() != KPreserve ) |
|
171 { |
|
172 for (TInt i = textDes.Length() - 1; i >= 0; i--) |
|
173 { |
|
174 if (textDes[i] == '\n' || textDes[i] == '\r') |
|
175 { |
|
176 textDes.Delete(i,1); |
|
177 } |
|
178 } |
|
179 textDes.TrimRight(); |
|
180 textDes.TrimLeft(); |
|
181 } |
|
182 // preserve |
|
183 else |
|
184 { |
|
185 TInt textDesLength = textDes.Length(); |
|
186 for ( TInt i = 0; i < textDesLength; i++ ) |
|
187 { |
|
188 // ms-dos carriage return contains two characters: 13, 10 |
|
189 if ( i + 1 < textDesLength && (TInt)textDes[i] == 13 && (TInt)textDes[i+1] == 10 ) |
|
190 { |
|
191 textDes[i] = ' '; |
|
192 textDes.Delete( i+1, 1 ); |
|
193 } |
|
194 else if ( TChar(textDes[i]).IsSpace() ) |
|
195 { |
|
196 textDes[i] = ' '; |
|
197 } |
|
198 } |
|
199 } |
|
200 } |
|
201 |
|
202 // ******************************************************* |
|
203 // From CSvgElementImpl |
|
204 |
|
205 // perform a deep clone of this object |
|
206 // ========================================================================== |
|
207 // Need method description |
|
208 // ========================================================================== |
|
209 MXmlElement* CSvgDescElementImpl::CloneL(MXmlElement* aParentElement) |
|
210 { |
|
211 CSvgDescElementImpl* newElement = CSvgDescElementImpl::NewL( this->ElemID(), ((CSvgDocumentImpl*)iOwnerDocument) ); |
|
212 |
|
213 CleanupStack::PushL(newElement); |
|
214 newElement->iParentNode = aParentElement; |
|
215 // copy everything over |
|
216 this->CopyL(newElement); |
|
217 CleanupStack::Pop(); |
|
218 return newElement; |
|
219 |
|
220 } |
|
221 |
|
222 // ========================================================================== |
|
223 // perform a deep copy of this object |
|
224 // ========================================================================== |
|
225 void CSvgDescElementImpl::CopyL( CSvgDescElementImpl* aDestElement ) |
|
226 { |
|
227 if(aDestElement) |
|
228 { |
|
229 |
|
230 // copy stuff from superclass |
|
231 this->CSvgElementImpl::CopyL(aDestElement); |
|
232 |
|
233 if(this->iText) |
|
234 { |
|
235 delete aDestElement->iText; |
|
236 aDestElement->iText= NULL; |
|
237 aDestElement->iText= (this->iText)->AllocL(); |
|
238 } |
|
239 |
|
240 // copy the reference to idoc (CSvgDocumentImpl) |
|
241 aDestElement->iOwnerDocument = this->iOwnerDocument; |
|
242 } |
|
243 } |
|
244 |
|
245 // ========================================================================== |
|
246 // Need method description |
|
247 // ========================================================================== |
|
248 TBool CSvgDescElementImpl::DrawL( CGfx2dGc* /* aGc */, |
|
249 CSvgElementImpl* /* aElement */ ) |
|
250 { |
|
251 return EFalse; |
|
252 } |
|
253 |
|
254 |
|
255 // ******************************************************* |
|
256 // Private |
|
257 |
|
258 // ========================================================================== |
|
259 // Need method description |
|
260 // ========================================================================== |
|
261 void CSvgDescElementImpl::ConstructL( const TUint8 aElemID ) |
|
262 { |
|
263 CSvgElementImpl::InitializeL( aElemID ); |
|
264 |
|
265 iText = HBufC::NewL( 2 ); |
|
266 } |
|
267 |
|
268 // ========================================================================== |
|
269 // Need method description |
|
270 // ========================================================================== |
|
271 CSvgDescElementImpl::CSvgDescElementImpl( CSvgDocumentImpl* aDoc ) |
|
272 { |
|
273 SetOwnerDocument(aDoc); |
|
274 } |
|
275 |
|
276 // ========================================================================== |
|
277 // Need method description |
|
278 // ========================================================================== |
|
279 void CSvgDescElementImpl::Print( TBool aIsEncodeOn ) |
|
280 { |
|
281 if (!aIsEncodeOn) |
|
282 { |
|
283 #ifdef _DEBUG |
|
284 RDebug::Printf("<desc>"); |
|
285 //need to add code here to output iText |
|
286 RDebug::Printf("</desc>"); |
|
287 #endif |
|
288 } |
|
289 } |
|
290 |
|
291 |
|
292 |