|
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 Engine header file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CSVGCONTENTHANDLER_H |
|
20 #define CSVGCONTENTHANDLER_H |
|
21 |
|
22 |
|
23 #include <e32base.h> |
|
24 #include <s32strm.h> |
|
25 |
|
26 #include "GfxColor.h" |
|
27 #include "SVGEngineInterfaceImpl.h" |
|
28 #include "SVGAttributeVerifier.h" |
|
29 #include "SVGErrorImpl.h" |
|
30 |
|
31 #include "mxmlattributes.h" |
|
32 #include "mxmlcontenthandler.h" |
|
33 |
|
34 #include "SVGSchemaData.h" |
|
35 #include "SVGDocumentImpl.h" |
|
36 |
|
37 /** |
|
38 * SMIL2 parser class |
|
39 */ |
|
40 class CSvgElementImpl; |
|
41 class CSvgScriptElementImpl; |
|
42 class CSvgImageElementImpl; |
|
43 |
|
44 |
|
45 /** |
|
46 * Class description goes here. |
|
47 * |
|
48 * @lib SVGEngine.lib |
|
49 * @since 1.0 |
|
50 */ |
|
51 class CSvgContentHandler : public CBase, public MXMLContentHandler |
|
52 { |
|
53 public: |
|
54 /** |
|
55 * Parser phase one constructor |
|
56 * |
|
57 * Takes the player interface object as a parameter. This interface |
|
58 * is used by the parser for reporting parse errors and for getting values |
|
59 * of the content control attributes. It is also passed to the created |
|
60 * presentation object. |
|
61 */ |
|
62 |
|
63 /** |
|
64 * Two phase constructor |
|
65 * |
|
66 * @since 1.0 |
|
67 * @param None |
|
68 * @return An isntance of this class |
|
69 */ |
|
70 static CSvgContentHandler* NewL( TBool aRemoveFalseSwitchElements = ETrue ); |
|
71 |
|
72 /** |
|
73 * Two phase constructor |
|
74 * |
|
75 * @since 1.0 |
|
76 * @param None |
|
77 * @return An instance of this class |
|
78 */ |
|
79 static CSvgContentHandler* NewLC(); |
|
80 |
|
81 |
|
82 /** |
|
83 * Part of two phase construction |
|
84 * |
|
85 * @since 1.0 |
|
86 * @param None |
|
87 * @return None |
|
88 */ |
|
89 virtual void ConstructL( TBool aRemoveFalseSwitchElements = ETrue ); |
|
90 |
|
91 /** |
|
92 * Destructor. |
|
93 */ |
|
94 |
|
95 /** |
|
96 * Destructor |
|
97 * |
|
98 * @since 1.0 |
|
99 * @param None |
|
100 * @return None |
|
101 */ |
|
102 virtual ~CSvgContentHandler(); |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 /** |
|
108 * |
|
109 * Parses the given encrypted SVG source, constructing the presentation objects. |
|
110 * This is a variant of ParseL and processes encrypted SVG sources. |
|
111 * |
|
112 * @since 1.0 |
|
113 * @param aDocument - The document object to which this document is constructed |
|
114 * @param aSvgFileName - The URI to the encrypted SVG source |
|
115 * @param aSuccess - An error code that signals successful/unsuccessful parsing |
|
116 * @return Instance of the root element of the SVG document. |
|
117 */ |
|
118 CSvgElementImpl* ParseByteData( CSvgDocumentImpl* aDocument, |
|
119 const TDesC8& aByteData, |
|
120 CSvgErrorImpl& aError ); |
|
121 |
|
122 /* |
|
123 * Parse the given 16 bit string of SVG |
|
124 * This method is used primarily for JSR226 to avoid conversion of strings |
|
125 * |
|
126 */ |
|
127 CSvgElementImpl* Parse16BitData( CSvgDocumentImpl* aDocument, |
|
128 const TDesC16& aSvgString, |
|
129 CSvgErrorImpl& aError ); |
|
130 |
|
131 |
|
132 |
|
133 CSvgElementImpl* ParseFile( CSvgDocumentImpl* aDocument, |
|
134 const TDesC& aFileName, |
|
135 CSvgErrorImpl& aError ); |
|
136 /*************** MXMLContentHandler interface methods **************/ |
|
137 |
|
138 /** |
|
139 * A callback that signals start of a document |
|
140 * |
|
141 * @since 1.0 |
|
142 * @param |
|
143 * @return A value that indicates success/failure |
|
144 */ |
|
145 TInt StartDocument(); |
|
146 |
|
147 /** |
|
148 * A callback that signals end of a document |
|
149 * |
|
150 * @since 1.0 |
|
151 * @param |
|
152 * @return A value that indicates success/failure |
|
153 */ |
|
154 TInt EndDocument(); |
|
155 |
|
156 /** |
|
157 * Returns reader index |
|
158 * @since Series60 3.1 |
|
159 * @param aIndex - reader index |
|
160 */ |
|
161 void ReaderIndex(NW_Uint32 aIndex); |
|
162 |
|
163 /** |
|
164 * A callback that signals beginning of an element |
|
165 * |
|
166 * @since 1.0 |
|
167 * @param aURI - |
|
168 * @param aLocalName - |
|
169 * @param aName - Name of the element |
|
170 * @param aAttributeList - a list that keeps track of the attributes found for this element |
|
171 * @return A value that indicates success/failure |
|
172 */ |
|
173 TInt StartElement( TDesC& aURI, TDesC& aLocalName, |
|
174 TDesC& aName, MXMLAttributes* aAttributeList ); |
|
175 /** |
|
176 * A callback that signals end of an element |
|
177 * |
|
178 * @since 1.0 |
|
179 * @param aURI - |
|
180 * @param aLocalName - |
|
181 * @param aName - Name of the element |
|
182 * @return A value that indicates success/failure |
|
183 */ |
|
184 TInt EndElement( TDesC& aURI, TDesC& aLocalName, TDesC& aName ); |
|
185 |
|
186 /** |
|
187 * Callback that signals characters inside an XML document |
|
188 * |
|
189 * @since 1.0 |
|
190 * @param aBuf - A string buffer that will contain the characters |
|
191 * @param aStart - An index indicating the starting position of the characters |
|
192 * @param aLenght - AN offset indicating the terminal position of the characters |
|
193 * @return A value that indicates success/failure |
|
194 */ |
|
195 TInt Charecters( TDesC& aBuf, TInt aStart, TInt aLength ); |
|
196 |
|
197 /** |
|
198 * A callback that signals a XML comment |
|
199 * |
|
200 * @since 1.0 |
|
201 * @param aComment - A string buffer that cintains the comment |
|
202 * @return A value that indicates success/failure |
|
203 */ |
|
204 |
|
205 TInt Comment( TDesC& aComment ); |
|
206 |
|
207 /** |
|
208 * Need method description |
|
209 * |
|
210 * @since 1.0 |
|
211 * @param |
|
212 * @return A value that indicates success/failure |
|
213 */ |
|
214 TInt ProcessingInstructions( TDesC& aTarget, TDesC& aData ); |
|
215 |
|
216 /** |
|
217 * Need method description |
|
218 * |
|
219 * @since 1.0 |
|
220 * @param |
|
221 * @return A value that indicates success/failure |
|
222 */ |
|
223 TInt IgnoreWhiteSpace( TDesC& aString ); |
|
224 |
|
225 /** |
|
226 * A callback that signals beginning of an entity element |
|
227 * |
|
228 * @since 1.0 |
|
229 * @param aName - A string buffer that will contain the entity name |
|
230 * @return A value that indicates success/failure |
|
231 */ |
|
232 TInt StartEntity( TDesC& aName ); |
|
233 |
|
234 /** |
|
235 * A callback that signals end of an entity element |
|
236 * |
|
237 * @since 1.0 |
|
238 * @param aName - A string buffer that will contain the entity name |
|
239 * @return A value that indicates success/failure |
|
240 */ |
|
241 TInt EndEntity( TDesC& aName ); |
|
242 |
|
243 /** |
|
244 * Need method description |
|
245 * |
|
246 * @since 1.0 |
|
247 * @param |
|
248 * @return A value that indicates success/failure |
|
249 */ |
|
250 TInt SkippedEntity( TDesC& aName ); |
|
251 |
|
252 /** |
|
253 * A callback that signals beginning of a CDATA section |
|
254 * |
|
255 * @since 1.0 |
|
256 * @param |
|
257 * @return A value that indicates success/failure |
|
258 */ |
|
259 TInt StartCDATA(); |
|
260 |
|
261 /** |
|
262 * A callback that signals end of a CDATA section |
|
263 * |
|
264 * @since 1.0 |
|
265 * @param |
|
266 * @return A value that indicates success/failure |
|
267 */ |
|
268 TInt EndCDATA(); |
|
269 |
|
270 /** |
|
271 * Need method description |
|
272 * |
|
273 * @since 1.0 |
|
274 * @param |
|
275 * @return A value that indicates success/failure |
|
276 */ |
|
277 TInt Error( TInt aErrorCode, TInt aSeverity ); |
|
278 |
|
279 void DataBuffer(const TDesC16& aBuf); |
|
280 |
|
281 /** |
|
282 * Request to cancel parsing. |
|
283 */ |
|
284 void CancelParsing(); |
|
285 |
|
286 protected: |
|
287 |
|
288 |
|
289 /** |
|
290 * Method to verify the value of the attribute based on its type. If the value is |
|
291 * valid then this method sets the value to the corresponding attribtue in the |
|
292 * current element |
|
293 * @since 1.0 |
|
294 * @aAttrName - name of the attribute |
|
295 * @aAttrValue - value of the attribute |
|
296 * @return |
|
297 */ |
|
298 |
|
299 TBool ProcessNConvertAttrL( const TDesC& aName, const TDesC& aAttrName, const TDesC& aAttrValue ); |
|
300 |
|
301 |
|
302 |
|
303 /** |
|
304 * Parse for a color from the given string. |
|
305 * |
|
306 * @since 1.0 |
|
307 * @param aString : color string to parse for color value |
|
308 * @param aTransparent : transparent flag. |
|
309 * @return parsed color. |
|
310 */ |
|
311 TGfxColor ParseColor( const TDesC& aString, |
|
312 TBool& aTransparent ); |
|
313 /** |
|
314 * Process for a color from the given attribute name and value. |
|
315 * |
|
316 * @since 1.0 |
|
317 * @param aName : attribute name |
|
318 * @param aValue : attribute value. |
|
319 * @return true if attribute is processes as a color attribute. |
|
320 */ |
|
321 TBool ProcessColorAttributeL( const TDesC& aName, |
|
322 const TDesC& aValue ); |
|
323 |
|
324 |
|
325 /** |
|
326 * Process a for style info. |
|
327 * |
|
328 * @since 1.0 |
|
329 * @param aName : attribute name |
|
330 * @param aValue : attribute value |
|
331 * @return true if a style info is processed. |
|
332 */ |
|
333 TBool ProcessStyleL( const TDesC& aValue ); |
|
334 |
|
335 /** |
|
336 * Process a for transform info. |
|
337 * |
|
338 * @since 1.0 |
|
339 * @param aName : attribute name |
|
340 * @param aValue : attribute value |
|
341 * @return true if a transform info is processed. |
|
342 */ |
|
343 TBool ProcessTransformL( const TDesC& aName, |
|
344 const TDesC& aValue ); |
|
345 |
|
346 /** |
|
347 * Process a for unit info. |
|
348 * |
|
349 * @since 1.0 |
|
350 * @param aName : attribute name |
|
351 * @param aValue : attribute value |
|
352 * @return true if a unit info is processed. |
|
353 */ |
|
354 TBool ProcessUnitsL( const TDesC& aName, |
|
355 const TDesC& aValue ); |
|
356 |
|
357 /** |
|
358 * Convert any xml entity characters in the given string list to unicode characters. |
|
359 * |
|
360 * @since 1.0 |
|
361 * @param aArray : array of strings to search for xml entities characters. |
|
362 * @return |
|
363 */ |
|
364 void ConvertEntitiesToCharsL( CDesCArrayFlat& aArray ); |
|
365 |
|
366 /** |
|
367 * Convert any xml entity characters in the given string to unicode characters. |
|
368 * |
|
369 * @since 1.0 |
|
370 * @param aString : string to search for xml entities characters. |
|
371 * @return non-NULL if at least one entity character is encountered. |
|
372 */ |
|
373 HBufC* ConvertEntitiesToCharsL( const TDesC& aString ); |
|
374 |
|
375 /** |
|
376 * Find the given character in the given string at the starting index. |
|
377 * |
|
378 * @since 1.0 |
|
379 * @param aString : string to find character. |
|
380 * @param aStartIndex : starting index. |
|
381 * @param aChar : character to search. |
|
382 * @return index of first character encounterd, if found, -1 otherwise. |
|
383 */ |
|
384 TInt Find( const TDesC& aString, TInt aStartIndex, TChar aChar ); |
|
385 |
|
386 /** |
|
387 * Create a substring from the given string. |
|
388 * |
|
389 * @since 1.0 |
|
390 * @param aString : string to create a substring. |
|
391 * @param aStartIndex : starting index. |
|
392 * @param aEndIndex : endind index. |
|
393 * @return substring from starting and ending indices. |
|
394 */ |
|
395 HBufC* SubstringL( const TDesC& aString, TInt aStartIndex, TInt aEndIndex ); |
|
396 |
|
397 /** |
|
398 * Convert the given string (xml entity character) to an unicode character. |
|
399 * |
|
400 * @since 1.0 |
|
401 * @param aChar : character object to store unicode character. |
|
402 * @param aString : xml entity character string. |
|
403 * @return true if there was a conversion. |
|
404 */ |
|
405 TBool ConvertEntityToChar( TChar& aChar, const TDesC& aString ); |
|
406 |
|
407 /** |
|
408 * Append a substring to the given string at given indices. |
|
409 * |
|
410 * @since 1.0 |
|
411 * @param aDest : string to append substring to. |
|
412 * @param aSource : string to append substring from. |
|
413 * @param aStartIndex : starting index for substring. |
|
414 * @param aEndIndex : ending index for substring. |
|
415 * @return |
|
416 */ |
|
417 void Append( TDes& aDest, const TDesC& aSource, TInt aStartIndex, TInt aEndIndex ); |
|
418 |
|
419 /** |
|
420 * Convert the given string (xml entity character) an unicode character. |
|
421 * |
|
422 * @since 1.0 |
|
423 * @param aChar : character object to store unicode character. |
|
424 * @param aString : xml decimal entity character string. |
|
425 * @return true if a conversion was made. |
|
426 */ |
|
427 TBool ConvertDecimalStringToChar( TChar& aChar, const TDesC& aString ); |
|
428 |
|
429 /** |
|
430 * Convert the given string (xml entity character) an unicode character. |
|
431 * |
|
432 * @since 1.0 |
|
433 * @param aChar : character object to store unicode character. |
|
434 * @param aString : xml hexadecimal entity character string. |
|
435 * @return true if a conversion was made. |
|
436 */ |
|
437 TBool ConvertHexStringToChar( TChar& aChar, const TDesC& aString ); |
|
438 |
|
439 |
|
440 void FilterCharactersL( TDesC& aString ); |
|
441 |
|
442 // Leaveable StartElementL function called by StartElement |
|
443 TInt StartElementL( TDesC& aURI, TDesC& aLocalName, |
|
444 TDesC& aName, MXMLAttributes* aAttributeList ); |
|
445 |
|
446 |
|
447 void AppendToCData( const TDesC& aText ); |
|
448 |
|
449 TBool ExtractStyleValuePair( const TDesC& aString, TPtrC& aName, TPtrC& aValue ); |
|
450 |
|
451 void SetForwardReferences(CSvgErrorImpl& aError); |
|
452 |
|
453 void RemoveFalseSwitchCasesOrMakeInvisible(); |
|
454 void RemoveFalseElementsOrMakeInvisible(); |
|
455 TBool VerifyReqExReqFtrSysL( CSvgElementImpl* aElement ); |
|
456 |
|
457 // Initiate image loading for <image> elements |
|
458 void LoadImages(); |
|
459 |
|
460 /** |
|
461 * Find out the system language for the client environment based on |
|
462 * SVG source hint |
|
463 * |
|
464 * @since 1.0 |
|
465 * @param aValue - A string buffer that contains the System Language hint |
|
466 * @return None |
|
467 */ |
|
468 void SystemLanguage( TPtr aValue ); |
|
469 |
|
470 /** |
|
471 * Private constructor |
|
472 * |
|
473 * @since 1.0 |
|
474 * @param |
|
475 * @return |
|
476 */ |
|
477 CSvgContentHandler(); |
|
478 |
|
479 /** |
|
480 * Check for possible svg elements placed inside entity references. |
|
481 * If so, attempt to parse as part of the document. |
|
482 * If parsing was successful, return ETrue, otherwise return EFalse. |
|
483 * |
|
484 * @since 1.0 |
|
485 * @param |
|
486 * @return If parsing was successful |
|
487 */ |
|
488 TBool ParseEntity( const TDesC& aEntity ); |
|
489 |
|
490 /** |
|
491 * Post parsing processing, such as removing false switch elements. |
|
492 * |
|
493 * @since 1.0 |
|
494 * @param |
|
495 * @return none |
|
496 */ |
|
497 void PostParseProcessing(); |
|
498 |
|
499 /** |
|
500 * Removes references of element. Usually called before the element is |
|
501 * deleted. |
|
502 * |
|
503 * @since s60 3.2 |
|
504 * @param aElement Pointer of element that is about to be deleted. |
|
505 * @return none |
|
506 */ |
|
507 void RemoveInternalReferences( CSvgElementImpl* aElement ); |
|
508 |
|
509 private: |
|
510 |
|
511 CSvgElementImpl*iRootElement; // SVG Element |
|
512 CSvgElementImpl*iCurrentElement; // Latest discovered element |
|
513 CSvgElementImpl*iCurrentParentElement; // Parent element for the current depth |
|
514 CSvgDocumentImpl* iDocument; // The document object to which this SVG source is processed |
|
515 |
|
516 |
|
517 |
|
518 // Various booleans that indicate success/failure or true/false for various attributes |
|
519 TBool iIsColorAnim; |
|
520 // Indicating begin or end attribute. |
|
521 TBool iBeginEndAtr; |
|
522 |
|
523 |
|
524 // Various buffers that hold animation time values |
|
525 TPtrC iFromVal; |
|
526 TPtrC iToVal; |
|
527 TPtrC iByVal; |
|
528 TPtrC iValues; |
|
529 TPtrC iTimes; |
|
530 TPtrC iSplines; |
|
531 |
|
532 HBufC* iSystemLanguage; |
|
533 |
|
534 // Various attributes that hold document "depth" information |
|
535 TInt iIgnoreDepth; |
|
536 TBool iIsSvgElement; |
|
537 |
|
538 CSvgErrorImpl* iSvgError; |
|
539 |
|
540 /*Added to support forward references in Use and animtion elements */ |
|
541 RPointerArray<CSvgElementImpl>* iUseElementArray; |
|
542 RPointerArray<CSvgElementImpl>* iAnimRefElementArray; |
|
543 |
|
544 //array to keep track of switch elements |
|
545 //so we can go back at the end of parsing and remove the elements |
|
546 //that dont evaluate to true from memory |
|
547 RPointerArray<CSvgElementImpl>* iSwitchElementArray; |
|
548 RPointerArray<CSvgElementImpl>* iReqFetAttSysArray; |
|
549 RPointerArray<CSvgElementImpl>* iAnimationElementArray; |
|
550 // CData container -- used to append pieces of cdata from XML parser |
|
551 // callbacks: Charecters & StartEntity |
|
552 HBufC* iCData; |
|
553 |
|
554 // Reference to loading listeners |
|
555 const RPointerArray<MSvgLoadingListener>* iLoadingListeners; |
|
556 |
|
557 TBool iCancelRequested; |
|
558 |
|
559 RPointerArray<CSvgImageElementImpl> iImageElements; |
|
560 TBool iRemoveFalseSwitchElements; |
|
561 }; |
|
562 |
|
563 #endif |