|
1 /* |
|
2 * Copyright (c) 2002 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: Graphics Extension Library header file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef GFXFIXPT_H |
|
20 #define GFXFIXPT_H |
|
21 #include <VG/openvg.h> |
|
22 // Enumeration |
|
23 //#define SVG_FLOAT_BUILD |
|
24 |
|
25 enum TGfxTextAnchor |
|
26 { |
|
27 EGfxTextAnchorStart, |
|
28 EGfxTextAnchorMiddle, |
|
29 EGfxTextAnchorEnd, |
|
30 EGfxTextAnchorNone = -1 |
|
31 }; |
|
32 |
|
33 enum TGfxTextDecoration |
|
34 { |
|
35 EGfxTextDecorationReserved, |
|
36 EGfxTextDecorationUnderLine, |
|
37 EGfxTextDecorationOverLine, |
|
38 EGfxTextDecorationLineThrough, |
|
39 EGfxTextDecorationNone = -1 |
|
40 }; |
|
41 |
|
42 enum TGfxCapType |
|
43 { |
|
44 EGfxCapButt = 0, |
|
45 EGfxCapRound = 1, |
|
46 EGfxCapSquare = 2 |
|
47 }; |
|
48 |
|
49 enum TGfxFilterEdgeCondition |
|
50 { |
|
51 EGfxEdgeNoOp, |
|
52 EGfxEdgeZeroFill, |
|
53 EGfxEdgeMirror |
|
54 }; |
|
55 |
|
56 // Image interporation enumeration |
|
57 enum TGfxImageInterpolation |
|
58 { |
|
59 EGfxInterpolationBiLinear, |
|
60 EGfxInterpolationBiCubic, |
|
61 EGfxInterpolationNearestNeighbor |
|
62 }; |
|
63 |
|
64 // Join type enumeration |
|
65 enum TGfxJoinType |
|
66 { |
|
67 EGfxJoinMiter = 0, |
|
68 EGfxJoinRound = 1, |
|
69 EGfxJoinBevel = 2 |
|
70 }; |
|
71 |
|
72 enum TGfxWindingRule |
|
73 { |
|
74 EGfxWindEvenOdd, |
|
75 EGfxWindNonZero |
|
76 }; |
|
77 |
|
78 enum TGfxSegType |
|
79 { |
|
80 EGfxSegMoveTo=VG_MOVE_TO_ABS, |
|
81 EGfxSegLineTo=VG_LINE_TO_ABS, |
|
82 EGfxSegQuadTo=VG_QUAD_TO_ABS, |
|
83 EGfxSegCubicTo=VG_CUBIC_TO_ABS, |
|
84 EGfxSegClose=VG_CLOSE_PATH |
|
85 }; |
|
86 |
|
87 #ifdef SVG_FLOAT_BUILD |
|
88 |
|
89 typedef float SVGReal; |
|
90 |
|
91 class TFloatFixPt |
|
92 { |
|
93 public: |
|
94 |
|
95 static void GetString( float aFloat, TDes& aBuf ); |
|
96 |
|
97 static float ConvertString( const TDesC& aVal ); |
|
98 |
|
99 static TInt ConvertString( const TDesC& aString, float& aValue ); |
|
100 |
|
101 static TInt ConvertString( const TDesC& aString, TFloatFixPt& aValue ); |
|
102 |
|
103 static float Sqrt( float aValue ); |
|
104 |
|
105 static float Cos(float angle); |
|
106 |
|
107 static float SinFloatDouble(float angle); |
|
108 |
|
109 static float CosFloatDouble(float angle); |
|
110 |
|
111 static float CosineDouble(float x); |
|
112 |
|
113 static float TanFloatDouble(float angle); |
|
114 |
|
115 static float SinApprox(float angle); |
|
116 |
|
117 static float CosApprox(float angle); |
|
118 |
|
119 static float FastSin( const float val ); |
|
120 |
|
121 static float FastCos( const float val ); |
|
122 |
|
123 static float FastTan( const float val ); |
|
124 |
|
125 static float FastASin( const float val ); |
|
126 |
|
127 static float FastACos( const float val ); |
|
128 |
|
129 static float FastATan( const float val ); |
|
130 |
|
131 inline TFloatFixPt(); |
|
132 |
|
133 inline TFloatFixPt( TInt aVal ); |
|
134 |
|
135 inline TFloatFixPt( TInt32 aVal ); |
|
136 |
|
137 inline TFloatFixPt( TReal32 aVal ); |
|
138 |
|
139 inline TFloatFixPt( const TFloatFixPt& aFixpt ); |
|
140 |
|
141 inline operator TInt32() const; |
|
142 |
|
143 inline operator TInt() const; |
|
144 |
|
145 inline operator TReal32() const; |
|
146 |
|
147 inline TFloatFixPt& operator=( TInt32 aVal ); |
|
148 |
|
149 inline TFloatFixPt& operator=( TInt aVal ); |
|
150 |
|
151 inline TFloatFixPt& operator=( TReal32 aVal ); |
|
152 |
|
153 inline TFloatFixPt& operator+=( const TFloatFixPt& aVal ); |
|
154 |
|
155 inline TFloatFixPt& operator-=( const TFloatFixPt& aVal ); |
|
156 |
|
157 inline TFloatFixPt& operator*=( const TFloatFixPt& aVal ); |
|
158 |
|
159 inline TFloatFixPt& operator/=( const TFloatFixPt& aVal ); |
|
160 |
|
161 inline TFloatFixPt operator+( const TFloatFixPt& aVal ) const; |
|
162 |
|
163 inline TFloatFixPt operator+( const double& aVal ) const; |
|
164 |
|
165 inline TFloatFixPt operator+( const float& aVal ) const; |
|
166 |
|
167 inline TFloatFixPt operator-( const TFloatFixPt& aVal ) const; |
|
168 |
|
169 inline TFloatFixPt operator-( const double aVal ) const; |
|
170 |
|
171 inline TFloatFixPt operator-( const float aVal ) const; |
|
172 |
|
173 inline TFloatFixPt operator*( const TFloatFixPt& aVal ) const; |
|
174 |
|
175 inline TFloatFixPt operator*( const double aVal ) const; |
|
176 |
|
177 inline TFloatFixPt operator*( const float aVal ) const; |
|
178 |
|
179 inline TFloatFixPt operator/( const TFloatFixPt& aVal ) const; |
|
180 |
|
181 inline TFloatFixPt operator/( const double aVal ) const; |
|
182 |
|
183 inline TFloatFixPt operator/( const float aVal ) const; |
|
184 |
|
185 inline TInt operator==( const TFloatFixPt& aVal ) const; |
|
186 |
|
187 inline TInt operator!=( const TFloatFixPt& aVal ) const; |
|
188 |
|
189 inline TInt operator>=( const TFloatFixPt& aVal ) const; |
|
190 |
|
191 inline TInt operator<=( const TFloatFixPt& aVal ) const; |
|
192 |
|
193 inline TInt operator>( const TFloatFixPt& aVal ) const; |
|
194 |
|
195 inline TInt operator<( const TFloatFixPt& aVal ) const; |
|
196 |
|
197 /** |
|
198 * Return the number rounded to the next whole number. |
|
199 * |
|
200 * @since 1.0 |
|
201 * @return |
|
202 */ |
|
203 inline TInt32 Round(); |
|
204 |
|
205 /** |
|
206 * Return the 32-bit data for this TFixPt. |
|
207 * |
|
208 * @since 1.0 |
|
209 * @return 32-bit value |
|
210 */ |
|
211 inline TInt32 RawData(); |
|
212 |
|
213 /** |
|
214 * Return the absolute value for the given number. |
|
215 * |
|
216 * @since 1.0 |
|
217 * @param aValue : real number to find absolute value |
|
218 * @return absolute value |
|
219 */ |
|
220 TFloatFixPt Abs( TFloatFixPt& aValue ); |
|
221 |
|
222 |
|
223 /** |
|
224 * Return the square root value for this number. |
|
225 * |
|
226 * @since 1.0 |
|
227 * @param aValue : real number to find square root |
|
228 * @return square root value |
|
229 */ |
|
230 static TFloatFixPt Sqrt( TFloatFixPt aValue ); |
|
231 |
|
232 public: |
|
233 |
|
234 float iValue; // Must be the first data member of this class! |
|
235 |
|
236 }; |
|
237 |
|
238 #include "GfxFloatFixPt.inl" |
|
239 |
|
240 #else /*FIXED POINT BUILD*/ |
|
241 |
|
242 typedef int SVGReal; |
|
243 |
|
244 const TInt32 KFixPtFrac = 16; |
|
245 const TInt32 KFixPtFracVal = ( 1 << KFixPtFrac ); |
|
246 |
|
247 /** |
|
248 * Implementation of a real number using 16.16 bits. |
|
249 * |
|
250 * @lib Gfx2D.lib |
|
251 * @since 1.0 |
|
252 */ |
|
253 class TFloatFixPt |
|
254 { |
|
255 public: |
|
256 |
|
257 /** |
|
258 * Construct a TFixPt. The default value is 0.0. |
|
259 * |
|
260 * @since 1.0 |
|
261 * @return |
|
262 */ |
|
263 inline TFloatFixPt(); |
|
264 |
|
265 /** |
|
266 * Construct a TFixPt from the given integer value. |
|
267 * |
|
268 * @since 1.0 |
|
269 * @param aVal : integer value |
|
270 * @return |
|
271 */ |
|
272 inline TFloatFixPt( TInt aVal ); |
|
273 |
|
274 /** |
|
275 * Construct a TFixPt from the given integer value. |
|
276 * |
|
277 * @since 1.0 |
|
278 * @param aVal : integer value |
|
279 * @return |
|
280 */ |
|
281 inline TFloatFixPt( TInt32 aVal ); |
|
282 |
|
283 /** |
|
284 * Construct a TFixPt from the given real 32-bit int. |
|
285 * |
|
286 * @since 1.0 |
|
287 * @param aVal : integer value |
|
288 * @param aBool : not used. |
|
289 * @return |
|
290 */ |
|
291 inline TFloatFixPt( TInt aVal, TBool aBool ); |
|
292 |
|
293 /** |
|
294 * Construct a TFixPt from the given TReal32. |
|
295 * |
|
296 * @since 1.0 |
|
297 * @param aVal : value to copy from |
|
298 * @return |
|
299 */ |
|
300 inline TFloatFixPt( TReal32 aVal ); |
|
301 |
|
302 /** |
|
303 * Construct a TFixPt from the given TFixPt. |
|
304 * |
|
305 * @since 1.0 |
|
306 * @param aFixpt : value to copy from |
|
307 * @return |
|
308 */ |
|
309 inline TFloatFixPt( const TFloatFixPt& aFixpt ); |
|
310 |
|
311 |
|
312 /** |
|
313 * Return the fractional portion as an int representation. |
|
314 * |
|
315 * @since 1.0 |
|
316 * @return the fractional portion value |
|
317 */ |
|
318 inline TInt32 FracAsInt(); |
|
319 |
|
320 |
|
321 /** |
|
322 * Casting operator to TInt32. |
|
323 * |
|
324 * @since 1.0 |
|
325 * @return |
|
326 */ |
|
327 |
|
328 inline operator TInt32() const; |
|
329 |
|
330 /** |
|
331 * Casting operator to TInt. |
|
332 * |
|
333 * @since 1.0 |
|
334 * @return |
|
335 */ |
|
336 inline operator TInt() const; |
|
337 |
|
338 /** |
|
339 * Casting operator to TReal32. |
|
340 * |
|
341 * @since 1.0 |
|
342 * @return |
|
343 */ |
|
344 inline operator TReal32() const; |
|
345 |
|
346 /** |
|
347 * Assignment operator. |
|
348 * |
|
349 * @since 1.0 |
|
350 * @param aVal : value to assign from. |
|
351 * @return |
|
352 */ |
|
353 inline TFloatFixPt& operator=( TInt32 aVal ); |
|
354 |
|
355 /** |
|
356 * Assignment operator. |
|
357 * |
|
358 * @since 1.0 |
|
359 * @param aVal : value to assign from. |
|
360 * @return |
|
361 */ |
|
362 inline TFloatFixPt& operator=( TInt aVal ); |
|
363 |
|
364 /** |
|
365 * Assignment operator. |
|
366 * |
|
367 * @since 1.0 |
|
368 * @param aVal : value to assign from. |
|
369 * @return |
|
370 */ |
|
371 inline TFloatFixPt& operator=( TReal32 aVal ); |
|
372 |
|
373 /** |
|
374 * Addition assignment operator. |
|
375 * |
|
376 * @since 1.0 |
|
377 * @param aVal : value to add with. |
|
378 * @return |
|
379 */ |
|
380 inline TFloatFixPt& operator+=( const TFloatFixPt& aVal ); |
|
381 |
|
382 /** |
|
383 * Subtraction assignment operator. |
|
384 * |
|
385 * @since 1.0 |
|
386 * @param aVal : value to substract. |
|
387 * @return |
|
388 */ |
|
389 inline TFloatFixPt& operator-=( const TFloatFixPt& aVal ); |
|
390 |
|
391 /** |
|
392 * Multiplication assignment operator. |
|
393 * |
|
394 * @since 1.0 |
|
395 * @param aVal : value to multiply with. |
|
396 * @return |
|
397 */ |
|
398 inline TFloatFixPt& operator*=( const TFloatFixPt& aVal ); |
|
399 |
|
400 /** |
|
401 * Division assignment operator. |
|
402 * |
|
403 * @since 1.0 |
|
404 * @param aVal : value to divide with. |
|
405 * @return |
|
406 */ |
|
407 inline TFloatFixPt& operator/=( const TFloatFixPt& aVal ); |
|
408 |
|
409 |
|
410 /** |
|
411 * Addition operator. |
|
412 * |
|
413 * @since 1.0 |
|
414 * @param aVal : value to add with. |
|
415 * @return |
|
416 */ |
|
417 inline TFloatFixPt operator+( const TFloatFixPt& aVal ) const; |
|
418 |
|
419 /** |
|
420 * Subtraction operator. |
|
421 * |
|
422 * @since 1.0 |
|
423 * @param aVal : value to subtract. |
|
424 * @return |
|
425 */ |
|
426 inline TFloatFixPt operator-( const TFloatFixPt& aVal ) const; |
|
427 |
|
428 /** |
|
429 * Multiplication operator. |
|
430 * |
|
431 * @since 1.0 |
|
432 * @param aVal : value to multiply with. |
|
433 * @return |
|
434 */ |
|
435 |
|
436 inline TFloatFixPt operator*( const TFloatFixPt& aVal ) const; |
|
437 |
|
438 /** |
|
439 * Division operator. |
|
440 * |
|
441 * @since 1.0 |
|
442 * @param aVal : value to divide with. |
|
443 * @return |
|
444 */ |
|
445 inline TFloatFixPt operator/( const TFloatFixPt& aVal ) const; |
|
446 |
|
447 /** |
|
448 * Equal operator. |
|
449 * |
|
450 * @since 1.0 |
|
451 * @param aVal : value to compare. |
|
452 * @return non-zero if equal |
|
453 */ |
|
454 |
|
455 inline TInt operator==( const TFloatFixPt& aVal ) const; |
|
456 |
|
457 /** |
|
458 * Not Equals operator. |
|
459 * |
|
460 * @since 1.0 |
|
461 * @param aVal : value to compare. |
|
462 * @return non-zero if not equal |
|
463 */ |
|
464 inline TInt operator!=( const TFloatFixPt& aVal ) const; |
|
465 |
|
466 /** |
|
467 * Greater than or equal to operator. |
|
468 * |
|
469 * @since 1.0 |
|
470 * @param aVal : value to compare. |
|
471 * @return non-zero if greater than or equal to |
|
472 */ |
|
473 inline TInt operator>=( const TFloatFixPt& aVal ) const; |
|
474 |
|
475 /** |
|
476 * Less than or equal to operator. |
|
477 * |
|
478 * @since 1.0 |
|
479 * @param aVal : value to compare. |
|
480 * @return non-zero if less than or equal to |
|
481 */ |
|
482 inline TInt operator<=( const TFloatFixPt& aVal ) const; |
|
483 |
|
484 /** |
|
485 * Greater than operator. |
|
486 * |
|
487 * @since 1.0 |
|
488 * @param aVal : value to compare. |
|
489 * @return non-zero if greater than |
|
490 */ |
|
491 inline TInt operator>( const TFloatFixPt& aVal ) const; |
|
492 |
|
493 /** |
|
494 * Less than operator. |
|
495 * |
|
496 * @since 1.0 |
|
497 * @param aVal : value to compare. |
|
498 * @return non-zero if less than |
|
499 */ |
|
500 inline TInt operator<( const TFloatFixPt& aVal ) const; |
|
501 |
|
502 /** |
|
503 * Operator to left shift |
|
504 * |
|
505 * @since 1.0 |
|
506 * @param aN : bits to be shifted. |
|
507 * @return |
|
508 */ |
|
509 |
|
510 inline TFloatFixPt operator<<( const TInt aN ) const; |
|
511 |
|
512 /** |
|
513 * operator to right shift. |
|
514 * |
|
515 * @since 1.0 |
|
516 * @param aBuf : string output storage. |
|
517 * @return value obtained after shifeting |
|
518 */ |
|
519 |
|
520 inline TFloatFixPt operator>>( const TInt aN ) const; |
|
521 |
|
522 |
|
523 |
|
524 /** |
|
525 * Get the string representation of this real number. |
|
526 * |
|
527 * @since 1.0 |
|
528 * @param aN : bits to be shifted |
|
529 * @return value obtained after shifeting |
|
530 */ |
|
531 void GetString( TDes& aBuf ) const; |
|
532 |
|
533 /** |
|
534 * Parse the given string for a TFixPt. |
|
535 * |
|
536 * @since 1.0 |
|
537 * @param aVal : string containing a real number. |
|
538 * @return TFixPt equal to string representation. |
|
539 */ |
|
540 static TFloatFixPt ConvertString( const TDesC& aVal ); |
|
541 |
|
542 /** |
|
543 * Parse the given string for a TFixPt. |
|
544 * |
|
545 * @since 1.0 |
|
546 * @param aVal : string containing a real number. |
|
547 * @param aVal : parsed number. |
|
548 * @return Error code (KErrNone if no errors). |
|
549 */ |
|
550 static TInt ConvertString( const TDesC& aValueString, TFloatFixPt& aValue ); |
|
551 |
|
552 /** |
|
553 * Return the number rounded to the next whole number. |
|
554 * |
|
555 * @since 1.0 |
|
556 * @return |
|
557 */ |
|
558 inline TInt32 Round(); |
|
559 |
|
560 /** |
|
561 * Return the 32-bit data for this TFixPt. |
|
562 * |
|
563 * @since 1.0 |
|
564 * @return 32-bit value |
|
565 */ |
|
566 inline TInt32 RawData(); |
|
567 |
|
568 /** |
|
569 * Return the absolute value for the given number. |
|
570 * |
|
571 * @since 1.0 |
|
572 * @param aValue : real number to find absolute value |
|
573 * @return absolute value |
|
574 */ |
|
575 TFloatFixPt Abs( TFloatFixPt& aValue ); |
|
576 |
|
577 |
|
578 /** |
|
579 * Return the square root value for this number. |
|
580 * |
|
581 * @since 1.0 |
|
582 * @param aValue : real number to find square root |
|
583 * @return square root value |
|
584 */ |
|
585 static TFloatFixPt Sqrt( TFloatFixPt aValue ); |
|
586 |
|
587 /** |
|
588 * Return the square root value for the given number. |
|
589 * |
|
590 * @since 1.0 |
|
591 * @param aValue : 32-bit representation of real number |
|
592 * @param aFracbits: number of bits allocated for fractional portion. |
|
593 * @return square root value |
|
594 */ |
|
595 static TInt32 FixedSqrtGeneral( TInt32 aValue, TUint32 aFracbits ); |
|
596 |
|
597 private: |
|
598 |
|
599 /** |
|
600 * Optimized method to do multiplication using assembly. |
|
601 * |
|
602 * @since 1.0 |
|
603 * @param aValue : real number to find multiply with |
|
604 * @return |
|
605 */ |
|
606 inline void GfxMultiplyAsm( TInt aValue ); |
|
607 |
|
608 public: |
|
609 |
|
610 TInt iValue; // Must be the first data member of this class! |
|
611 |
|
612 }; |
|
613 |
|
614 #ifdef SVG_FLOAT_BUILD |
|
615 #define KFloatFixOne = (TFloatFixPt(1)) |
|
616 #define KFloatFixZero = (TFloatFixPt()) |
|
617 #define KMAXFLOATFIXVALUE (1e38f) |
|
618 #define KMINFLOATFIXVALUE (-1e38f) |
|
619 #define KMAXFLOATFIX (TFloatFixPt( KMAXFLOATFIXVALUE )) |
|
620 #define KMINFLOATFIX (TFloatFixPt( KMINFLOATFIXVALUE )) |
|
621 #else |
|
622 #define KFloatFixOne (TFloatFixPt( 0x10000, ETrue )) |
|
623 #define KFloatFixZero (TFloatFixPt()) |
|
624 #define KMAXFLOATFIXVALUE (0x7fff) |
|
625 #define KMINFLOATFIXVALUE (-0x7fff) |
|
626 #define KMAXFLOATFIX (TFloatFixPt( 0x7fff0000, ETrue )) |
|
627 #define KMINFLOATFIX (TFloatFixPt( -0x7fff0000, ETrue )) |
|
628 |
|
629 #endif |
|
630 |
|
631 typedef struct |
|
632 { |
|
633 SVGReal matrix[2][3]; |
|
634 } SVGMatrix2x3; |
|
635 |
|
636 #include "GfxFloatFixPt.inl" |
|
637 |
|
638 #endif |
|
639 #endif // GFXFIXPT_H |