|
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 header file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef _INC_CSVGTEXTELEMENTIMPL_ |
|
20 #define _INC_CSVGTEXTELEMENTIMPL_ |
|
21 |
|
22 #include "SVGElementImpl.h" |
|
23 #include "SVGLangSpaceImpl.h" |
|
24 #include "SVGFourPointRect.h" |
|
25 #include "SVGListener.h" |
|
26 #include "GfxPoint2D.h" |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 class CSvgErrorImpl; |
|
32 |
|
33 class CSvgDocumentImpl; |
|
34 class MXmlDocument; |
|
35 |
|
36 enum TTextAnchor |
|
37 { |
|
38 EStartAnchor = 0, |
|
39 EMiddleAnchor, |
|
40 EEndAnchor |
|
41 }; |
|
42 |
|
43 /** |
|
44 * Class description goes here. |
|
45 * |
|
46 * @lib SVGEngine.lib |
|
47 * @since 1.0 |
|
48 */ |
|
49 class CSvgTextElementImpl : public CSvgElementImpl, |
|
50 public MSvgMouseListener |
|
51 { |
|
52 public: |
|
53 |
|
54 // Constructor/deconstructor |
|
55 |
|
56 |
|
57 |
|
58 /** |
|
59 * Need method description |
|
60 * |
|
61 * @since 1.0 |
|
62 * @param |
|
63 * @return |
|
64 */ |
|
65 static CSvgTextElementImpl*NewL( const TUint8 aElemID, |
|
66 CSvgDocumentImpl* aDoc ); |
|
67 |
|
68 /** |
|
69 * Need method description |
|
70 * |
|
71 * @since 1.0 |
|
72 * @param |
|
73 * @return |
|
74 */ |
|
75 static CSvgTextElementImpl*NewLC( const TUint8 aElemID, |
|
76 CSvgDocumentImpl* aDoc ); |
|
77 |
|
78 private: |
|
79 /** |
|
80 * Need method description |
|
81 * |
|
82 * @since 1.0 |
|
83 * @param |
|
84 * @return |
|
85 */ |
|
86 void ConstructL( const TUint8 aElemID ); |
|
87 |
|
88 |
|
89 |
|
90 public: |
|
91 |
|
92 void UpdateCurrentScaledFont(); |
|
93 |
|
94 /** |
|
95 * Need method description |
|
96 * |
|
97 * @since 1.0 |
|
98 * @param |
|
99 * @return |
|
100 */ |
|
101 ~CSvgTextElementImpl(); |
|
102 // From SVG DOM |
|
103 |
|
104 /** |
|
105 * Need method description |
|
106 * |
|
107 * @since 1.0 |
|
108 * @param |
|
109 * @return |
|
110 */ |
|
111 TInt32 NumberOfChars(); |
|
112 |
|
113 /** |
|
114 * Need method description |
|
115 * |
|
116 * @since 1.0 |
|
117 * @param |
|
118 * @return |
|
119 */ |
|
120 void GetX( CArrayFix<TFloatFixPt>* aX ); |
|
121 |
|
122 /** |
|
123 * Need method description |
|
124 * |
|
125 * @since 1.0 |
|
126 * @param |
|
127 * @return |
|
128 */ |
|
129 void GetY( CArrayFix<TFloatFixPt>* aY ); |
|
130 |
|
131 // SVG Implementation |
|
132 |
|
133 /** |
|
134 * Need method description |
|
135 * |
|
136 * @since 1.0 |
|
137 * @param |
|
138 * @return |
|
139 */ |
|
140 TBool IsNumberAttributeValid( const TDesC& aValue ); |
|
141 |
|
142 |
|
143 void SetTextL( const TDesC& aText ); // This is temporary API until CDATA is implemented |
|
144 |
|
145 TDesC& GetText(); |
|
146 |
|
147 TBool LoadExternalSVGFontL( const TDesC& aText ); |
|
148 |
|
149 /** |
|
150 * Need method description |
|
151 * |
|
152 * @since 1.0 |
|
153 * @param |
|
154 * @return |
|
155 */ |
|
156 void SetX( CArrayFix<TFloatFixPt>* aX ); |
|
157 |
|
158 /** |
|
159 * Need method description |
|
160 * |
|
161 * @since 1.0 |
|
162 * @param |
|
163 * @return |
|
164 */ |
|
165 void SetY( CArrayFix<TFloatFixPt>* aX ); |
|
166 |
|
167 |
|
168 void SetXYArray(TUint16 aAtrId, CArrayFixFlat<TFloatFixPt>*& aX ); |
|
169 |
|
170 |
|
171 |
|
172 /** |
|
173 * Need method description |
|
174 * |
|
175 * @since 1.0 |
|
176 * @param |
|
177 * @return |
|
178 */ |
|
179 void SetTextDecoration( const TDesC& aValue ); |
|
180 |
|
181 /** |
|
182 * Need method description |
|
183 * |
|
184 * @since 1.0 |
|
185 * @param |
|
186 * @return |
|
187 */ |
|
188 void SetTextAnchor( const TDesC& aValue ); |
|
189 |
|
190 |
|
191 /** |
|
192 * Need method description |
|
193 * |
|
194 * @since 1.0 |
|
195 * @param |
|
196 * @return |
|
197 */ |
|
198 void SetFontFamilyL( const TDesC& aValue ); |
|
199 |
|
200 /** |
|
201 * Need method description |
|
202 * |
|
203 * @since 1.0 |
|
204 * @param |
|
205 * @return |
|
206 */ |
|
207 void SetRotateL( const TDesC& aValue ); |
|
208 |
|
209 /** |
|
210 * Need method description |
|
211 * |
|
212 * @since 1.0 |
|
213 * @param |
|
214 * @return |
|
215 */ |
|
216 |
|
217 |
|
218 |
|
219 /** |
|
220 * Using generic function instead of SetArrayXL or SetArrrayYL |
|
221 * |
|
222 * @since 1.0 |
|
223 * aValue - the string containing the coordinates |
|
224 * aIsX - Flag to determine whether it is X or Y coordinate values |
|
225 */ |
|
226 |
|
227 void SetArrayL( const TDesC& aValue , const TBool aIsX); |
|
228 |
|
229 |
|
230 |
|
231 // From MXmlElement API |
|
232 |
|
233 |
|
234 /** |
|
235 * Need method description |
|
236 * |
|
237 * @since 1.0 |
|
238 * @param |
|
239 * @return |
|
240 */ |
|
241 TInt SetAttributeL( const TDesC& aName, |
|
242 const TDesC& aValue ); |
|
243 // From MXmlElementOpt API |
|
244 |
|
245 |
|
246 /** |
|
247 * Need method description |
|
248 * |
|
249 * @since 1.0 |
|
250 * @param |
|
251 * @return |
|
252 */ |
|
253 TInt GetAttributeFloat( const TInt aNameId, |
|
254 TFloatFixPt& aValue ); |
|
255 |
|
256 /** |
|
257 * Need method description |
|
258 * |
|
259 * @since 1.0 |
|
260 * @param |
|
261 * @return |
|
262 */ |
|
263 TInt SetAttributeFloatL( const TInt aNameId, |
|
264 const TFloatFixPt aValue ); |
|
265 |
|
266 |
|
267 /** |
|
268 * Need method description |
|
269 * |
|
270 * @since 1.0 |
|
271 * @param |
|
272 * @return |
|
273 */ |
|
274 TInt GetAttributeDes( const TInt aNameId, |
|
275 TPtrC16& aValue ); |
|
276 |
|
277 /** |
|
278 * Need method description |
|
279 * |
|
280 * @since 1.0 |
|
281 * @param |
|
282 * @return |
|
283 */ |
|
284 TInt SetAttributeDesL( const TInt aNameId, |
|
285 const TDesC& aValue ); |
|
286 |
|
287 // From CSvgElementImpl |
|
288 |
|
289 |
|
290 /** |
|
291 * Need method description |
|
292 * |
|
293 * @since 1.0 |
|
294 * @param |
|
295 * @return |
|
296 */ |
|
297 MXmlElement* CloneL(MXmlElement* aParentElement); |
|
298 |
|
299 |
|
300 void CopyL( CSvgTextElementImpl* aDestElement ); |
|
301 |
|
302 |
|
303 /** |
|
304 * Need method description |
|
305 * |
|
306 * @since 1.0 |
|
307 * @param |
|
308 * @return |
|
309 */ |
|
310 TBool DrawL( CGfx2dGc* aGc, |
|
311 CSvgElementImpl* aElement ); |
|
312 |
|
313 |
|
314 |
|
315 /** |
|
316 * Scale the stroke width in order to nullify the effect of scaling |
|
317 * appiled on the glyph |
|
318 * |
|
319 * @since 3.2 |
|
320 * @param aGc- Graphics context |
|
321 * @return none |
|
322 */ |
|
323 void ScaleStrokeWidth(CGfx2dGc* aGc); |
|
324 |
|
325 |
|
326 // void GetCurrentFontScaled(CFont*& aFont, TFontSpec& aFontSpec); |
|
327 |
|
328 /** |
|
329 * Need method description |
|
330 * |
|
331 * @since 1.0 |
|
332 * @param |
|
333 * @return |
|
334 */ |
|
335 void GetBBox( TGfxRectangle2D& aBbox ); |
|
336 void GetFourPointBBox( TSvgFourPointRect& aFourPointBBox ); |
|
337 void GetBBoxForSVGText( TGfxRectangle2D& aBbox ); |
|
338 void GetBBoxForSVGText( TSvgFourPointRect& aFourPointBbox,const TGfxAffineTransform& aTransform); |
|
339 void GetBBoxForSystemText( TGfxRectangle2D& aBbox ); |
|
340 void GetBBoxForSystemText( TSvgFourPointRect& aFourPointBbox ); |
|
341 void CreateSVGFontL(); |
|
342 /** |
|
343 * Need method description |
|
344 * |
|
345 * @since 1.0 |
|
346 * @param |
|
347 * @return |
|
348 */ |
|
349 virtual void GetUnscaledBBox( TGfxRectangle2D& aBbox ); |
|
350 |
|
351 /** |
|
352 * Need method description |
|
353 * |
|
354 * @since 1.0 |
|
355 * @param |
|
356 * @return |
|
357 */ |
|
358 //Local Function(s) |
|
359 |
|
360 /** |
|
361 * Need method description |
|
362 * |
|
363 * @since 1.0 |
|
364 * @param |
|
365 * @return |
|
366 */ |
|
367 TBool IsWithinUnicodeRange( const TDesC& aUnicodeRange, |
|
368 const TDesC& aCharacter ); |
|
369 |
|
370 /** |
|
371 * Need method description |
|
372 * |
|
373 * @since 1.0 |
|
374 * @param |
|
375 * @return |
|
376 */ |
|
377 void SetUKernPairsL( const TDesC& aU1, |
|
378 const TDesC& aU2 ); |
|
379 |
|
380 |
|
381 /** |
|
382 * Need method description |
|
383 * |
|
384 * @since 1.0 |
|
385 * @param |
|
386 * @return |
|
387 */ |
|
388 void SetGKernPairsL( const TDesC& aG1, |
|
389 const TDesC& aG2 ); |
|
390 |
|
391 |
|
392 /** |
|
393 * Need method description |
|
394 * |
|
395 * @since 1.0 |
|
396 * @param |
|
397 * @return |
|
398 */ |
|
399 TBool IsKerningRequired( const TDesC& aPrevGlyphName, |
|
400 const TDesC& aCurrGlyphName, |
|
401 const TDesC& aPrevUnicode, |
|
402 const TDesC& aCurrUnicode); |
|
403 |
|
404 // function for decoding |
|
405 void SetRotateArray(CArrayFixFlat<TReal32>*& aRotate); |
|
406 void FreeFontData(); |
|
407 |
|
408 /** |
|
409 * Return the font size for this text element. |
|
410 * |
|
411 * @since 1.0 |
|
412 * @param |
|
413 * @return |
|
414 */ |
|
415 TFloatFixPt FontSize(); |
|
416 |
|
417 TFloatFixPt TextAdvance( const TDesC& aText, TInt aIndex = 0); |
|
418 TFloatFixPt Ascent(); |
|
419 TFloatFixPt Descent(); |
|
420 TTextAnchor TextAnchor(); |
|
421 void CacheGlyphsForText(); |
|
422 TBool IsMostBasicLatin(); |
|
423 TBool HasFont(); |
|
424 void SetFont(CFont* aBitmapFont = NULL, CSvgElementImpl* aSVGFont = NULL); |
|
425 |
|
426 void SetEditable( const TDesC& aValue ); |
|
427 |
|
428 void Print( TBool aIsEncodeOn ); |
|
429 const CFont* Font() const; |
|
430 |
|
431 /** |
|
432 * Return wether an svg element is displayable, such as <rect>, <circle>, or |
|
433 * an abstract element, such as <g>, <animate>. |
|
434 * |
|
435 * @since 1.0 |
|
436 * @param None |
|
437 * @return ETrue if element is viewable. |
|
438 */ |
|
439 TBool IsViewable() { return ETrue; } |
|
440 |
|
441 TBool IsEditable(); |
|
442 |
|
443 /** |
|
444 * Notified when the mouse pointer enters a visible svg element. |
|
445 * |
|
446 * @since 1.0 |
|
447 * param : aElements -- SVG elements containing the mouse point. |
|
448 * param : aX -- x coordinate of mouse pointer. |
|
449 * param : aY -- y coordinate of mouse pointer. |
|
450 * @return : For future use. Value is ignored. |
|
451 */ |
|
452 TBool MouseEntered( RPointerArray<CSvgElementImpl>& aElements, |
|
453 TInt aX, TInt aY ); |
|
454 |
|
455 /** |
|
456 * Notified when the mouse pointer exits a visible svg element. |
|
457 * |
|
458 * @since 1.0 |
|
459 * param : aElements -- SVG elements containing the mouse point. |
|
460 * param : aX -- x coordinate of mouse pointer. |
|
461 * param : aY -- y coordinate of mouse pointer. |
|
462 * @return : For future use. Value is ignored. |
|
463 */ |
|
464 TBool MouseExited( RPointerArray<CSvgElementImpl>& aElements, |
|
465 TInt aX, TInt aY ); |
|
466 |
|
467 /** |
|
468 * Notified when the mouse pointer exits a visible svg element. |
|
469 * |
|
470 * @since 1.0 |
|
471 * param : aElements -- SVG elements containing the mouse point. |
|
472 * param : aX -- x coordinate of mouse pointer. |
|
473 * param : aY -- y coordinate of mouse pointer. |
|
474 * @return : For future use. Value is ignored. |
|
475 */ |
|
476 TBool MouseMoved( RPointerArray<CSvgElementImpl>& aElements, |
|
477 TInt aX, TInt aY ); |
|
478 |
|
479 |
|
480 /** |
|
481 * Notified when the mouse pointer is pressed down on visible svg element. |
|
482 * |
|
483 * @since 1.0 |
|
484 * param : aElements -- SVG elements containing the mouse point. |
|
485 * param : aX -- x coordinate of mouse pointer. |
|
486 * param : aY -- y coordinate of mouse pointer. |
|
487 * @return : For future use. Value is ignored. |
|
488 */ |
|
489 TBool MousePressed( RPointerArray<CSvgElementImpl>& aElements, |
|
490 TInt aX, TInt aY ); |
|
491 |
|
492 /** |
|
493 * Notified when the mouse pointer is released on on visible svg element. |
|
494 * |
|
495 * @since 1.0 |
|
496 * param : aElements -- SVG elements containing the mouse point. |
|
497 * param : aX -- x coordinate of mouse pointer. |
|
498 * param : aY -- y coordinate of mouse pointer. |
|
499 * @return : For future use. Value is ignored. |
|
500 */ |
|
501 TBool MouseReleased( RPointerArray<CSvgElementImpl>& aElements, |
|
502 TInt aX, TInt aY ); |
|
503 |
|
504 inline TInt FileOffset() const |
|
505 { |
|
506 return iOffset; |
|
507 } |
|
508 |
|
509 inline void SetFileOffset(TInt aOffset) |
|
510 { |
|
511 if(! FileOffset()) |
|
512 iOffset = aOffset; |
|
513 }; |
|
514 |
|
515 inline void SetOrgLength(TInt aOrgLength) |
|
516 { |
|
517 if(!GetOrgLength()) |
|
518 iOrgLength = aOrgLength; |
|
519 }; |
|
520 |
|
521 inline TInt GetOrgLength() |
|
522 { |
|
523 return iOrgLength; |
|
524 } |
|
525 TFloatFixPt GetTotalTextAdvance(const TFloatFixPt& alK,const TFloatFixPt& alUnitsPerEmInverse,const TFloatFixPt& alFontSize,const TFloatFixPt& alMissingGlyphHorzAdvX,const TFloatFixPt& alFontHorzAdvX); |
|
526 |
|
527 CFont* iBitmapFont; |
|
528 TFontSpec iBitmapFontSpec; //New |
|
529 |
|
530 private: |
|
531 |
|
532 void GetScaledFont( TFloatFixPt aHeight, |
|
533 const TDesC& aTypefaceName, |
|
534 CFont*& aFont, |
|
535 TFontSpec& aFontSpec ); |
|
536 |
|
537 /** |
|
538 * Need method description |
|
539 * |
|
540 * @since 1.0 |
|
541 * @param |
|
542 * @return |
|
543 */ |
|
544 CSvgTextElementImpl( CSvgDocumentImpl* aDoc ); |
|
545 |
|
546 TBool FetchSvgFontL(const TDesC& aUri, CSvgDocumentImpl* aNewFontDoc); |
|
547 //TBool LoadDefaultSvgFont(CSvgDocumentImpl* aNewFontDoc); |
|
548 |
|
549 |
|
550 private: |
|
551 // Text element specific instance variables |
|
552 HBufC* iText; |
|
553 TFloatFixPt iScale; |
|
554 TGfxPoint2D iPoint; |
|
555 TReal iLetterSpacing; |
|
556 TReal iWordSpacing; |
|
557 TReal iRotate; |
|
558 CDesCArrayFlat* iFamilies; |
|
559 CArrayFixFlat<TFloatFixPt>* iArrayX; |
|
560 CArrayFixFlat<TFloatFixPt>* iArrayY; |
|
561 CArrayFixFlat<TReal32>* iArrayRotate; |
|
562 TInt8 iTextAnchor; |
|
563 TInt8 iTextDecoration; |
|
564 |
|
565 RPointerArray<CSvgElementImpl> iGlyphElements; |
|
566 |
|
567 HBufC* iG1; |
|
568 HBufC* iG2; |
|
569 |
|
570 HBufC* iU1; |
|
571 HBufC* iU2; |
|
572 |
|
573 TBool iNeedToCacheGlyphs; |
|
574 TBool iUseDefaultSVGFont; |
|
575 TBool iTriedLoadingSVGFonts; |
|
576 |
|
577 CWsScreenDevice* iWsScreenDevice; //New |
|
578 CSvgElementImpl* iSVGFont; |
|
579 |
|
580 CSvgElementImpl* iFontFaceElement; |
|
581 CSvgElementImpl* iMissingGlyphElement; |
|
582 CSvgElementImpl* iHkernElement; |
|
583 |
|
584 TGfxRectangle2D iSVGBbox; |
|
585 TBool iEditable; |
|
586 |
|
587 public: |
|
588 TInt iOffset; |
|
589 TInt iOrgLength; |
|
590 TSize iBoundingBox; |
|
591 CFont* iFont; |
|
592 |
|
593 CGfx2dGc* iGfx2dGc; |
|
594 }; |
|
595 |
|
596 #endif /* _INC_CSVGTEXTELEMENT_3C61A6080051_INCLUDED */ |