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