|
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 source file |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "GfxGeneralPath.h" |
|
20 #include "GfxGeneralPathIteratorP.h" |
|
21 #include "GfxFlatteningPathIterator.h" |
|
22 |
|
23 |
|
24 |
|
25 // --------------------------------------------------------------------------- |
|
26 // Constructors |
|
27 // --------------------------------------------------------------------------- |
|
28 // -------------------------------------------------------------------------- |
|
29 // CGfxGeneralPath* CGfxGeneralPath::NewL() |
|
30 // --------------------------------------------------------------------------- |
|
31 CGfxGeneralPath* CGfxGeneralPath::NewL() |
|
32 { |
|
33 CGfxGeneralPath* self = NewLC(); |
|
34 CleanupStack::Pop(); |
|
35 return self; |
|
36 } |
|
37 |
|
38 // -------------------------------------------------------------------------- |
|
39 // CGfxGeneralPath* CGfxGeneralPath::NewLC() |
|
40 // --------------------------------------------------------------------------- |
|
41 CGfxGeneralPath* CGfxGeneralPath::NewLC() |
|
42 { |
|
43 CGfxGeneralPath* self = new ( ELeave ) CGfxGeneralPath; |
|
44 CleanupStack::PushL( self ); |
|
45 self->ConstructL(); |
|
46 return self; |
|
47 } |
|
48 |
|
49 // -------------------------------------------------------------------------- |
|
50 // CGfxGeneralPath::CGfxGeneralPath() |
|
51 // --------------------------------------------------------------------------- |
|
52 CGfxGeneralPath::CGfxGeneralPath() |
|
53 { |
|
54 } |
|
55 |
|
56 // -------------------------------------------------------------------------- |
|
57 // void CGfxGeneralPath::ConstructL() |
|
58 // --------------------------------------------------------------------------- |
|
59 void CGfxGeneralPath::ConstructL() |
|
60 { |
|
61 iPointTypes = new ( ELeave ) RArray<TUint32>( 4 ); |
|
62 iPointTypes->AppendL(NULL); |
|
63 iPointTypes->Remove(0); |
|
64 iPointCoords = new ( ELeave ) RArray<TFloatFixPt>( 8 ); |
|
65 iPointCoords->AppendL(NULL); |
|
66 iPointCoords->Remove(0); |
|
67 iPathSegmentTypeArray = NULL; |
|
68 iCount = 0; |
|
69 } |
|
70 |
|
71 // -------------------------------------------------------------------------- |
|
72 // CGfxGeneralPath::~CGfxGeneralPath() |
|
73 // --------------------------------------------------------------------------- |
|
74 CGfxGeneralPath::~CGfxGeneralPath() |
|
75 { |
|
76 if ( iPointTypes ) |
|
77 { |
|
78 iPointTypes->Close(); |
|
79 delete iPointTypes; |
|
80 iPointTypes = NULL; |
|
81 } |
|
82 |
|
83 if ( iPointCoords ) |
|
84 { |
|
85 iPointCoords->Close(); |
|
86 delete iPointCoords; |
|
87 iPointCoords = NULL; |
|
88 } |
|
89 if (iPathSegmentTypeArray) |
|
90 { |
|
91 delete [] iPathSegmentTypeArray; |
|
92 iPathSegmentTypeArray = NULL; |
|
93 } |
|
94 } |
|
95 |
|
96 const TUint32 KSegClose = ( TUint32 ) EGfxSegClose; |
|
97 |
|
98 // -------------------------------------------------------------------------- |
|
99 // TFloatFixPt CGfxGeneralPath::AreaSize() |
|
100 // --------------------------------------------------------------------------- |
|
101 TFloatFixPt CGfxGeneralPath::AreaSize() |
|
102 { |
|
103 return TFloatFixPt(0); |
|
104 } |
|
105 |
|
106 // -------------------------------------------------------------------------- |
|
107 // void CGfxGeneralPath::ClosePathL() |
|
108 // --------------------------------------------------------------------------- |
|
109 void CGfxGeneralPath::ClosePathL() |
|
110 { |
|
111 TInt count = iPointTypes->Count(); |
|
112 if ( count > 0 && (*iPointTypes)[count - 1] != KSegClose ) |
|
113 { |
|
114 iPointTypes->AppendL( KSegClose ); |
|
115 } |
|
116 } |
|
117 |
|
118 // -------------------------------------------------------------------------- |
|
119 // void CGfxGeneralPath::HorizonToL( TFloatFixPt& aX, TBool aAbsolute ) |
|
120 // --------------------------------------------------------------------------- |
|
121 void CGfxGeneralPath::HorizonToL( TFloatFixPt& aX, TBool aAbsolute ) |
|
122 { |
|
123 if ( !aAbsolute && iPointCoords->Count() >= 2 ) |
|
124 { |
|
125 // If the last command was 'Z'/'z' |
|
126 // the current point is the initial point |
|
127 // of the previous segment - 'M'/'m' usually |
|
128 if ( iPointTypes->operator[]( iPointTypes->Count() - 1 ) == KSegClose ) |
|
129 { |
|
130 aX += iLastX; |
|
131 } |
|
132 else |
|
133 { |
|
134 aX += iPointCoords->operator[]( iPointCoords->Count() - 2 ); |
|
135 } |
|
136 } |
|
137 |
|
138 TUint32 KSegLineto = ( TUint32 ) EGfxSegLineTo; // const |
|
139 |
|
140 iPointTypes->AppendL( KSegLineto ); |
|
141 iPointCoords->AppendL( aX ); |
|
142 TFloatFixPt tmpY = ( iPointCoords->Count() < 2 ) ? TFloatFixPt( 0 ) : iPointCoords->operator[]( iPointCoords->Count() - 2 ); |
|
143 iPointCoords->AppendL( tmpY ); |
|
144 } |
|
145 |
|
146 // -------------------------------------------------------------------------- |
|
147 // void CGfxGeneralPath::VertToL( TFloatFixPt& aY, TBool aAbsolute ) |
|
148 // --------------------------------------------------------------------------- |
|
149 void CGfxGeneralPath::VertToL( TFloatFixPt& aY, TBool aAbsolute ) |
|
150 { |
|
151 if ( !aAbsolute && iPointCoords->Count() >= 2 ) |
|
152 { |
|
153 // If the last command was 'Z'/'z' |
|
154 // the current point is the initial point |
|
155 // of the previous segment - 'M'/'m' usually |
|
156 if ( iPointTypes->operator[]( iPointTypes->Count() - 1 ) == KSegClose ) |
|
157 { |
|
158 aY += iLastY; |
|
159 } |
|
160 else |
|
161 { |
|
162 aY += iPointCoords->operator[]( iPointCoords->Count() - 1 ); |
|
163 } |
|
164 } |
|
165 |
|
166 TUint32 KSegLineto = ( TUint32 ) EGfxSegLineTo; // const |
|
167 |
|
168 iPointTypes->AppendL( KSegLineto ); |
|
169 TFloatFixPt tmpX = ( iPointCoords->Count() < 2 ) ? TFloatFixPt( 0 ) : iPointCoords->operator[]( iPointCoords->Count() - 2 ); |
|
170 iPointCoords->AppendL( tmpX ); |
|
171 iPointCoords->AppendL( aY ); |
|
172 } |
|
173 |
|
174 // -------------------------------------------------------------------------- |
|
175 // void CGfxGeneralPath::LineToL( TFloatFixPt& aX, |
|
176 // --------------------------------------------------------------------------- |
|
177 void CGfxGeneralPath::LineToL( TFloatFixPt& aX, |
|
178 TFloatFixPt& aY, |
|
179 TBool aAbsolute ) |
|
180 { |
|
181 if ( !aAbsolute && iPointCoords->Count() >= 2 ) |
|
182 { |
|
183 TFloatFixPt lastX = iPointCoords->operator[]( iPointCoords->Count() - 2 ); |
|
184 TFloatFixPt lastY = iPointCoords->operator[]( iPointCoords->Count() - 1 ); |
|
185 // If the last command was 'Z'/'z' |
|
186 // the current point is the initial point |
|
187 // of the previous segment - 'M'/'m' usually |
|
188 if ( iPointTypes->operator[]( iPointTypes->Count() - 1 ) == KSegClose ) |
|
189 { |
|
190 lastX = iLastX; |
|
191 lastY = iLastY; |
|
192 } |
|
193 aX += lastX; |
|
194 aY += lastY; |
|
195 } |
|
196 |
|
197 TUint32 KSegLineto = ( TUint32 ) EGfxSegLineTo; // const |
|
198 |
|
199 iPointTypes->AppendL( KSegLineto ); |
|
200 iPointCoords->AppendL( aX ); |
|
201 iPointCoords->AppendL( aY ); |
|
202 } |
|
203 |
|
204 // -------------------------------------------------------------------------- |
|
205 // void CGfxGeneralPath::RemoveLastPathCommand() |
|
206 // --------------------------------------------------------------------------- |
|
207 void CGfxGeneralPath::RemoveLastPathCommand() |
|
208 { |
|
209 TInt aTypeCount = iPointTypes->Count(); |
|
210 TInt aPointCount = iPointCoords->Count(); |
|
211 |
|
212 if ( aPointCount >= 2 ) |
|
213 { |
|
214 //we need to remove the last amount from iLastX |
|
215 iLastX -= (*iPointCoords)[aPointCount - 2]; |
|
216 iLastY -= (*iPointCoords)[aPointCount - 1]; |
|
217 } |
|
218 |
|
219 if ( aTypeCount > 0 ) |
|
220 { |
|
221 iPointTypes->Remove( aTypeCount - 1 ); |
|
222 |
|
223 if ( aPointCount >= 2 ) |
|
224 { |
|
225 iPointCoords->Remove( aPointCount - 1 ); |
|
226 iPointCoords->Remove( aPointCount - 2 ); |
|
227 } |
|
228 } |
|
229 } |
|
230 // -------------------------------------------------------------------------- |
|
231 // void CGfxGeneralPath::MoveToL( TFloatFixPt& aX, |
|
232 // --------------------------------------------------------------------------- |
|
233 void CGfxGeneralPath::MoveToL( TFloatFixPt& aX, |
|
234 TFloatFixPt& aY, |
|
235 TBool aAbsolute ) |
|
236 { |
|
237 if ( !aAbsolute && iPointCoords->Count() >= 2 ) |
|
238 { |
|
239 // If the last command was 'Z'/'z' |
|
240 // the current point is the initial point |
|
241 // of the previous segment - 'M'/'m' usually |
|
242 if ( iPointTypes->operator[]( iPointTypes->Count() - 1 ) == KSegClose ) |
|
243 { |
|
244 aX += iLastX; |
|
245 aY += iLastY; |
|
246 } |
|
247 else |
|
248 { |
|
249 TFloatFixPt lastX = iPointCoords->operator[]( iPointCoords->Count() - |
|
250 2 ); |
|
251 TFloatFixPt lastY = iPointCoords->operator[]( iPointCoords->Count() - |
|
252 1 ); |
|
253 aX += lastX; |
|
254 aY += lastY; |
|
255 } |
|
256 } |
|
257 |
|
258 TUint32 KSegMoveto = ( TUint32 ) EGfxSegMoveTo; // const |
|
259 |
|
260 iPointTypes->AppendL( KSegMoveto ); |
|
261 iPointCoords->AppendL( aX ); |
|
262 iPointCoords->AppendL( aY ); |
|
263 // Save initial point of a new segment |
|
264 // Could be the next initial point |
|
265 iLastX = aX; |
|
266 iLastY = aY; |
|
267 } |
|
268 |
|
269 // -------------------------------------------------------------------------- |
|
270 // void CGfxGeneralPath::QuadToL( TFloatFixPt& aX1, |
|
271 // --------------------------------------------------------------------------- |
|
272 void CGfxGeneralPath::QuadToL( TFloatFixPt& aX1, |
|
273 TFloatFixPt& aY1, |
|
274 TFloatFixPt& aX2, |
|
275 TFloatFixPt& aY2, |
|
276 TBool aAbsolute ) |
|
277 { |
|
278 if ( !aAbsolute && iPointCoords->Count() >= 2 ) |
|
279 { |
|
280 TFloatFixPt lastX = iPointCoords->operator[]( iPointCoords->Count() - 2 ); |
|
281 TFloatFixPt lastY = iPointCoords->operator[]( iPointCoords->Count() - 1 ); |
|
282 |
|
283 // If the last command was 'Z'/'z' |
|
284 // the current point is the initial point |
|
285 // of the previous segment - 'M'/'m' usually |
|
286 if ( iPointTypes->operator[]( iPointTypes->Count() - 1 ) == KSegClose ) |
|
287 { |
|
288 lastX = iLastX; |
|
289 lastY = iLastY; |
|
290 } |
|
291 |
|
292 aX1 += lastX; |
|
293 aY1 += lastY; |
|
294 aX2 += lastX; |
|
295 aY2 += lastY; |
|
296 } |
|
297 |
|
298 TUint32 KSegQuadto = ( TUint32 ) EGfxSegQuadTo; |
|
299 iPointTypes->AppendL( KSegQuadto ); |
|
300 iPointCoords->AppendL( aX1 ); |
|
301 iPointCoords->AppendL( aY1 ); |
|
302 iPointCoords->AppendL( aX2 ); |
|
303 iPointCoords->AppendL( aY2 ); |
|
304 |
|
305 } |
|
306 |
|
307 // -------------------------------------------------------------------------- |
|
308 // void CGfxGeneralPath::CubicToL( TFloatFixPt& aX1, |
|
309 // --------------------------------------------------------------------------- |
|
310 void CGfxGeneralPath::CubicToL( TFloatFixPt& aX1, |
|
311 TFloatFixPt& aY1, |
|
312 TFloatFixPt& aX2, |
|
313 TFloatFixPt& aY2, |
|
314 TFloatFixPt& aX3, |
|
315 TFloatFixPt& aY3, |
|
316 TBool aAbsolute ) |
|
317 { |
|
318 if ( !aAbsolute && iPointCoords->Count() >= 2 ) |
|
319 { |
|
320 TFloatFixPt lastX = iPointCoords->operator[]( iPointCoords->Count() - 2 ); |
|
321 TFloatFixPt lastY = iPointCoords->operator[]( iPointCoords->Count() - 1 ); |
|
322 // If the last command was 'Z'/'z' |
|
323 // the current point is the initial point |
|
324 // of the previous segment - 'M'/'m' usually |
|
325 if ( iPointTypes->operator[]( iPointTypes->Count() - 1 ) == KSegClose ) |
|
326 { |
|
327 lastX = iLastX; |
|
328 lastY = iLastY; |
|
329 } |
|
330 aX1 += lastX; |
|
331 aY1 += lastY; |
|
332 aX2 += lastX; |
|
333 aY2 += lastY; |
|
334 aX3 += lastX; |
|
335 aY3 += lastY; |
|
336 } |
|
337 |
|
338 TUint32 KSegCubicto = ( TUint32 ) EGfxSegCubicTo; // const |
|
339 |
|
340 iPointTypes->AppendL( KSegCubicto ); |
|
341 iPointCoords->AppendL( aX1 ); |
|
342 iPointCoords->AppendL( aY1 ); |
|
343 iPointCoords->AppendL( aX2 ); |
|
344 iPointCoords->AppendL( aY2 ); |
|
345 iPointCoords->AppendL( aX3 ); |
|
346 iPointCoords->AppendL( aY3 ); |
|
347 } |
|
348 |
|
349 // -------------------------------------------------------------------------- |
|
350 // void CGfxGeneralPath::ShortQuadToL( TFloatFixPt& aX2, |
|
351 // --------------------------------------------------------------------------- |
|
352 void CGfxGeneralPath::ShortQuadToL( TFloatFixPt& aX2, |
|
353 TFloatFixPt& aY2, |
|
354 TBool aAbsolute ) |
|
355 { |
|
356 if ( !aAbsolute && iPointCoords->Count() >= 2 ) |
|
357 { |
|
358 // If the last command was 'Z'/'z' |
|
359 // the current point is the initial point |
|
360 // of the previous segment - 'M'/'m' usually |
|
361 if ( iPointTypes->operator[]( iPointTypes->Count() - 1 ) == KSegClose ) |
|
362 { |
|
363 aX2 += iLastX; |
|
364 aY2 += iLastY; |
|
365 } |
|
366 else |
|
367 { |
|
368 aX2 += iPointCoords->operator[]( iPointCoords->Count() - 2 ); |
|
369 aY2 += iPointCoords->operator[]( iPointCoords->Count() - 1 ); |
|
370 } |
|
371 } |
|
372 |
|
373 TFloatFixPt aX1, aY1; |
|
374 GetCurveRefPoint( aX1, aY1 ); |
|
375 QuadToL( aX1, aY1, aX2, aY2, ETrue ); |
|
376 } |
|
377 |
|
378 // -------------------------------------------------------------------------- |
|
379 // void CGfxGeneralPath::ShortCubicToL( TFloatFixPt& aX2, |
|
380 // --------------------------------------------------------------------------- |
|
381 void CGfxGeneralPath::ShortCubicToL( TFloatFixPt& aX2, |
|
382 TFloatFixPt& aY2, |
|
383 TFloatFixPt& aX3, |
|
384 TFloatFixPt& aY3, |
|
385 TBool aAbsolute ) |
|
386 { |
|
387 if ( !aAbsolute && iPointCoords->Count() >= 2 ) |
|
388 { |
|
389 TFloatFixPt lastX = iPointCoords->operator[]( iPointCoords->Count() - 2 ); |
|
390 TFloatFixPt lastY = iPointCoords->operator[]( iPointCoords->Count() - 1 ); |
|
391 // If the last command was 'Z'/'z' |
|
392 // the current point is the initial point |
|
393 // of the previous segment - 'M'/'m' usually |
|
394 if ( iPointTypes->operator[]( iPointTypes->Count() - 1 ) == KSegClose ) |
|
395 { |
|
396 lastX = iLastX; |
|
397 lastY = iLastY; |
|
398 } |
|
399 aX2 += lastX; |
|
400 aY2 += lastY; |
|
401 aX3 += lastX; |
|
402 aY3 += lastY; |
|
403 } |
|
404 TFloatFixPt aX1, aY1; |
|
405 GetCurveRefPoint( aX1, aY1 ); |
|
406 // If there is no previous command or if the previous command |
|
407 // was not an C, c, S or s, the first control point shall be coincident |
|
408 // with the current point. |
|
409 TUint32 KSegCubicto = ( TUint32 ) EGfxSegCubicTo; // const |
|
410 if ( iPointTypes->operator[]( iPointTypes->Count() - 1 ) != KSegCubicto ) |
|
411 { |
|
412 aX1 = iLastX; |
|
413 aY1 = iLastY; |
|
414 } |
|
415 |
|
416 CubicToL( aX1, aY1, aX2, aY2, aX3, aY3, ETrue ); |
|
417 } |
|
418 |
|
419 // -------------------------------------------------------------------------- |
|
420 // void CGfxGeneralPath::GetCurveRefPoint( TFloatFixPt& aX, TFloatFixPt& aY ) |
|
421 // --------------------------------------------------------------------------- |
|
422 void CGfxGeneralPath::GetCurveRefPoint( TFloatFixPt& aX, TFloatFixPt& aY ) |
|
423 { |
|
424 if ( iPointCoords->Count() < 4 ) |
|
425 { |
|
426 aX = TFloatFixPt( 0 ); |
|
427 aY = TFloatFixPt( 0 ); |
|
428 return; |
|
429 } |
|
430 TFloatFixPt x0 = iPointCoords->operator[]( iPointCoords->Count() - 4 ); |
|
431 TFloatFixPt y0 = iPointCoords->operator[]( iPointCoords->Count() - 3 ); |
|
432 TFloatFixPt x1 = iPointCoords->operator[]( iPointCoords->Count() - 2 ); |
|
433 TFloatFixPt y1 = iPointCoords->operator[]( iPointCoords->Count() - 1 ); |
|
434 aX = x1 + x1 - x0; |
|
435 aY = y1 + y1 - y0; |
|
436 } |
|
437 |
|
438 // -------------------------------------------------------------------------- |
|
439 // void CGfxGeneralPath::Reset() |
|
440 // --------------------------------------------------------------------------- |
|
441 void CGfxGeneralPath::Reset() |
|
442 { |
|
443 iPointTypes->Reset(); |
|
444 iPointCoords->Reset(); |
|
445 } |
|
446 |
|
447 // -------------------------------------------------------------------------- |
|
448 // void CGfxGeneralPath::AppendL( CGfxPathIterator* aItr ) |
|
449 // --------------------------------------------------------------------------- |
|
450 void CGfxGeneralPath::AppendL( CGfxPathIterator* aItr ) |
|
451 { |
|
452 TFloatFixPt tmpcoords[6]; |
|
453 |
|
454 // Set path data... |
|
455 while ( !aItr->IsDone() ) |
|
456 { |
|
457 switch ( aItr->CurrentSegment( tmpcoords ) ) |
|
458 { |
|
459 case EGfxSegMoveTo: |
|
460 MoveToL( tmpcoords[0], tmpcoords[1], ETrue ); |
|
461 break; |
|
462 case EGfxSegLineTo: |
|
463 LineToL( tmpcoords[0], tmpcoords[1], ETrue ); |
|
464 break; |
|
465 case EGfxSegQuadTo: |
|
466 QuadToL( tmpcoords[0], |
|
467 tmpcoords[1], |
|
468 tmpcoords[2], |
|
469 tmpcoords[3], |
|
470 ETrue ); |
|
471 break; |
|
472 case EGfxSegCubicTo: |
|
473 CubicToL( tmpcoords[0], |
|
474 tmpcoords[1], |
|
475 tmpcoords[2], |
|
476 tmpcoords[3], |
|
477 tmpcoords[4], |
|
478 tmpcoords[5], |
|
479 ETrue ); |
|
480 break; |
|
481 case EGfxSegClose: |
|
482 ClosePathL(); |
|
483 } |
|
484 aItr->NextL(); |
|
485 } |
|
486 } |
|
487 |
|
488 // -------------------------------------------------------------------------- |
|
489 // void CGfxGeneralPath::GetBounds( const TGfxAffineTransform& aAt, |
|
490 // --------------------------------------------------------------------------- |
|
491 void CGfxGeneralPath::GetBounds( const TGfxAffineTransform& aAt, |
|
492 TGfxRectangle2D& aRect ) |
|
493 { |
|
494 TFloatFixPt xMin(KMAXFLOATFIX), yMin(KMAXFLOATFIX), xMax(KMINFLOATFIX), yMax(KMINFLOATFIX); |
|
495 for (TInt i=0; i<iPointCoords->Count(); i+=2) |
|
496 { |
|
497 TGfxPoint2D p((*iPointCoords)[i], (*iPointCoords)[i+1]); |
|
498 aAt.Transform(&p, &p, 1); |
|
499 if (p.iX < xMin) xMin = p.iX; |
|
500 if (p.iX > xMax) xMax = p.iX; |
|
501 if (p.iY < yMin) yMin = p.iY; |
|
502 if (p.iY > yMax) yMax = p.iY; |
|
503 } |
|
504 aRect.iX = xMin; |
|
505 aRect.iY = yMin; |
|
506 aRect.iWidth = xMax - xMin; |
|
507 aRect.iHeight = yMax - yMin; |
|
508 } |
|
509 |
|
510 // -------------------------------------------------------------------------- |
|
511 // void CGfxGeneralPath::GetPathIteratorL( TGfxAffineTransform* aAt, |
|
512 // --------------------------------------------------------------------------- |
|
513 void CGfxGeneralPath::GetPathIteratorL( TGfxAffineTransform* aAt, |
|
514 CGfxPathIterator*& aPitr ) |
|
515 { |
|
516 aPitr = new ( ELeave ) CGfxGeneralPathIteratorP( this, aAt ); |
|
517 } |
|
518 |
|
519 // -------------------------------------------------------------------------- |
|
520 // void CGfxGeneralPath::GetPathIteratorL( TGfxAffineTransform* aAt, |
|
521 // --------------------------------------------------------------------------- |
|
522 void CGfxGeneralPath::GetPathIteratorL( TGfxAffineTransform* aAt, |
|
523 TInt aLimit, |
|
524 CGfxPathIterator*& aPitr ) |
|
525 { |
|
526 aPitr = CGfxFlatteningPathIterator::NewL( this, aAt, aLimit ); |
|
527 |
|
528 } |
|
529 |
|
530 // -------------------------------------------------------------------------- |
|
531 // void CGfxGeneralPath::SetPointTypeArrayL( RArray<TUint32>* aTypesArray ) |
|
532 // --------------------------------------------------------------------------- |
|
533 void CGfxGeneralPath::SetPointTypeArrayL( RArray<TUint32>* aTypesArray ) |
|
534 { |
|
535 TInt count = aTypesArray->Count(); |
|
536 iPointTypes->Reset(); |
|
537 |
|
538 for ( TInt i = 0; i < count; i++ ) |
|
539 { |
|
540 iPointTypes->AppendL( (*aTypesArray)[i] ); |
|
541 } |
|
542 } |
|
543 |
|
544 |
|
545 // -------------------------------------------------------------------------- |
|
546 // void CGfxGeneralPath::SetPointTypeArrayRef( RArray<TUint32>*& aTypesArray ) |
|
547 // --------------------------------------------------------------------------- |
|
548 void CGfxGeneralPath::SetPointTypeArrayRef( RArray<TUint32>*& aTypesArray ) |
|
549 { |
|
550 if (iPointTypes) |
|
551 { |
|
552 iPointTypes->Reset(); |
|
553 delete iPointTypes; |
|
554 iPointTypes= NULL; |
|
555 } |
|
556 iPointTypes= aTypesArray; |
|
557 } |
|
558 |
|
559 |
|
560 // -------------------------------------------------------------------------- |
|
561 // void CGfxGeneralPath::SetPointCoordsArrayRef( RArray<TFloatFixPt>*& aPointCoords ) |
|
562 // --------------------------------------------------------------------------- |
|
563 void CGfxGeneralPath::SetPointCoordsArrayRef( RArray<TFloatFixPt>*& aPointCoords ) |
|
564 { |
|
565 TInt count = aPointCoords->Count(); |
|
566 if (iPointCoords) |
|
567 { |
|
568 iPointCoords->Reset(); |
|
569 delete iPointCoords; |
|
570 iPointCoords= NULL; |
|
571 } |
|
572 iPointCoords= aPointCoords; |
|
573 } |
|
574 |
|
575 |
|
576 // -------------------------------------------------------------------------- |
|
577 // void CGfxGeneralPath::SetPointCoordsArrayL( RArray<TFloatFixPt>* aPointCoords ) |
|
578 // --------------------------------------------------------------------------- |
|
579 void CGfxGeneralPath::SetPointCoordsArrayL( RArray<TFloatFixPt>* aPointCoords ) |
|
580 { |
|
581 TInt count = aPointCoords->Count(); |
|
582 iPointCoords->Reset(); |
|
583 |
|
584 for ( TInt i = 0; (i+1) < count; i+=2 ) |
|
585 { |
|
586 iPointCoords->AppendL( (*aPointCoords)[i] ); |
|
587 iPointCoords->AppendL( (*aPointCoords)[i+1] ); |
|
588 } |
|
589 } |
|
590 |
|
591 // -------------------------------------------------------------------------- |
|
592 // RArray<TUint32>* CGfxGeneralPath::PointTypeArray() |
|
593 // --------------------------------------------------------------------------- |
|
594 RArray<TUint32>* CGfxGeneralPath::PointTypeArray() |
|
595 { |
|
596 return iPointTypes; |
|
597 } |
|
598 |
|
599 unsigned char* CGfxGeneralPath::PathSegmentTypeArray() |
|
600 { |
|
601 return iPathSegmentTypeArray; |
|
602 } |
|
603 |
|
604 void CGfxGeneralPath::PathSegmentTypeArray(unsigned char* aSegmentTypeArray) |
|
605 { |
|
606 iPathSegmentTypeArray = aSegmentTypeArray; |
|
607 } |
|
608 // -------------------------------------------------------------------------- |
|
609 // TFloatFixPt* CGfxGeneralPath::PointCoordsArray() |
|
610 // --------------------------------------------------------------------------- |
|
611 TFloatFixPt* CGfxGeneralPath::PointCoordsArray() |
|
612 { |
|
613 if((iPointCoords) && (iPointCoords->Count() > 0)) |
|
614 return &( iPointCoords->operator[]( 0 ) ); |
|
615 else |
|
616 return NULL; |
|
617 } |
|
618 |
|
619 // -------------------------------------------------------------------------- |
|
620 // RArray<TFloatFixPt>* CGfxGeneralPath::PointCoordsArrayAll() |
|
621 // --------------------------------------------------------------------------- |
|
622 RArray<TFloatFixPt>* CGfxGeneralPath::PointCoordsArrayAll() |
|
623 { |
|
624 return iPointCoords; |
|
625 } |
|
626 // -------------------------------------------------------------------------- |
|
627 // TInt CGfxGeneralPath::GetSegmentCount() |
|
628 // --------------------------------------------------------------------------- |
|
629 TInt CGfxGeneralPath::GetSegmentCount() |
|
630 { |
|
631 return iPointTypes->Count(); |
|
632 } |
|
633 // -------------------------------------------------------------------------- |
|
634 // TInt CGfxGeneralPath::GetSegmentType(TInt aSegmentIndex) |
|
635 // --------------------------------------------------------------------------- |
|
636 TInt CGfxGeneralPath::GetSegmentType(TInt aSegmentIndex) |
|
637 { |
|
638 if(aSegmentIndex > 0 && aSegmentIndex <= iPointTypes->Count()) |
|
639 { |
|
640 TInt SegmentType = iPointTypes->operator[]( aSegmentIndex - 1 ); |
|
641 TInt KSegLineto = ( TInt ) EGfxSegLineTo; |
|
642 if( SegmentType == KSegLineto) |
|
643 { |
|
644 // differentiate between vertical and horizontal lines. |
|
645 TBool isVertical = EFalse; |
|
646 TBool isHorizontal = EFalse; |
|
647 // the following function will tel us that this line segment is horizontal |
|
648 // or vertical. |
|
649 IsHorizontalLineOrVertical(aSegmentIndex-1, isHorizontal, isVertical); |
|
650 if( !isHorizontal ) |
|
651 { |
|
652 if(isVertical) |
|
653 { |
|
654 TUint32 KVertical = 6; |
|
655 return KVertical ; |
|
656 } |
|
657 } |
|
658 else |
|
659 { |
|
660 TUint32 KHorizontal = 5; |
|
661 return KHorizontal ; |
|
662 } |
|
663 return SegmentType; |
|
664 } |
|
665 return SegmentType; |
|
666 } |
|
667 else |
|
668 { |
|
669 return KErrBadHandle; |
|
670 } |
|
671 } |
|
672 // -------------------------------------------------------------------------- |
|
673 // TReal32 CGfxGeneralPath::GetSegmentParameter(TInt aSegmentIndex , TInt aParameterIndex) |
|
674 // --------------------------------------------------------------------------- |
|
675 TReal32 CGfxGeneralPath::GetSegmentParameter(TInt aSegmentIndex , TInt aParameterIndex) |
|
676 { |
|
677 if( aSegmentIndex <= 0 && aSegmentIndex >= iPointTypes->Count()) |
|
678 { |
|
679 return 0.0; |
|
680 } |
|
681 |
|
682 TInt count =0; |
|
683 TInt Param = 0; |
|
684 |
|
685 while(count < (aSegmentIndex -1)) |
|
686 { |
|
687 |
|
688 switch(iPointTypes->operator[]( count)) |
|
689 { |
|
690 |
|
691 case EGfxSegClose: |
|
692 break; |
|
693 case EGfxSegLineTo: |
|
694 Param+=2; |
|
695 break; |
|
696 case EGfxSegQuadTo: |
|
697 Param+= 4; |
|
698 break; |
|
699 case EGfxSegCubicTo: |
|
700 Param +=6; |
|
701 break; |
|
702 case EGfxSegMoveTo: |
|
703 Param+= 2; |
|
704 break; |
|
705 default: |
|
706 break; |
|
707 } |
|
708 count++; |
|
709 } |
|
710 |
|
711 Param--; |
|
712 |
|
713 if((Param + aParameterIndex) >= iPointCoords->Count()) |
|
714 { |
|
715 return 0; |
|
716 } |
|
717 |
|
718 return (TReal32)iPointCoords->operator[](Param + aParameterIndex); |
|
719 } |
|
720 // -------------------------------------------------------------------------- |
|
721 // void CGfxGeneralPath::IsHorizontalLineOrVertical(TInt aSegmentIndex, TBool& aHorizontal, TBool& aVertical) |
|
722 // --------------------------------------------------------------------------- |
|
723 void CGfxGeneralPath::IsHorizontalLineOrVertical(TInt aSegmentIndex, TBool& aHorizontal, TBool& aVertical) |
|
724 { |
|
725 // see the previous segment. |
|
726 if( aSegmentIndex <= 0 && aSegmentIndex >= iPointTypes->Count()) |
|
727 { |
|
728 return; |
|
729 } |
|
730 TInt count =0; |
|
731 TInt Param =0; |
|
732 TInt LastPram = 0; |
|
733 while(count <= aSegmentIndex ) |
|
734 { |
|
735 // this will contain the Index to the last Segment. |
|
736 LastPram= Param; |
|
737 |
|
738 // search for the current segment. |
|
739 switch(iPointTypes->operator[]( count)) |
|
740 { |
|
741 // here increment the Param based on the number of attribute each command needs. |
|
742 case EGfxSegClose: |
|
743 break; |
|
744 case EGfxSegLineTo: |
|
745 Param+=2; |
|
746 break; |
|
747 case EGfxSegQuadTo: |
|
748 Param+= 4; |
|
749 break; |
|
750 case EGfxSegCubicTo: |
|
751 Param +=6; |
|
752 break; |
|
753 case EGfxSegMoveTo: |
|
754 Param+= 2; |
|
755 break; |
|
756 default: |
|
757 break; |
|
758 } |
|
759 count++; |
|
760 } |
|
761 |
|
762 |
|
763 Param--; |
|
764 LastPram--; |
|
765 |
|
766 if ( ( (Param-1) >= 0) && ( (LastPram - 1) >= 0) ) |
|
767 { |
|
768 |
|
769 if(iPointCoords->operator[](Param-1) == iPointCoords->operator[](LastPram-1)) |
|
770 { |
|
771 aVertical = ETrue; |
|
772 return; |
|
773 } |
|
774 if(iPointCoords->operator[](Param) == iPointCoords->operator[](LastPram)) |
|
775 { |
|
776 aHorizontal = ETrue; |
|
777 return; |
|
778 } |
|
779 } |
|
780 else if ( (Param - 1 ) >= 0 ) |
|
781 { |
|
782 //this is the case where there is just a LineTo and nothing else |
|
783 if ( iPointCoords->operator[](Param - 1) >= TFloatFixPt(0) ) |
|
784 { |
|
785 aHorizontal = ETrue; |
|
786 return; |
|
787 } |
|
788 else if ( iPointCoords->operator[](Param) >= TFloatFixPt(0) ) |
|
789 { |
|
790 aVertical = ETrue; |
|
791 return; |
|
792 } |
|
793 } |
|
794 } |
|
795 |
|
796 TUint8 CGfxGeneralPath::Count() |
|
797 { |
|
798 return iCount; |
|
799 } |
|
800 |
|
801 void CGfxGeneralPath::Count(TUint8 aCount) |
|
802 { |
|
803 iCount = aCount; |
|
804 } |
|
805 // -------------------------------------------------------------------------- |
|
806 // CGfxGeneralPath* CGfxGeneralPath::CloneL() |
|
807 // --------------------------------------------------------------------------- |
|
808 CGfxGeneralPath* CGfxGeneralPath::CloneL() |
|
809 { |
|
810 CGfxGeneralPath* path = CGfxGeneralPath::NewLC(); |
|
811 TInt index = 0; |
|
812 |
|
813 for( index = 0; index < iPointTypes->Count(); index++ ) |
|
814 { |
|
815 path->iPointTypes->AppendL( iPointTypes->operator[]( index ) ); |
|
816 } |
|
817 for( index = 0; index < iPointCoords->Count(); index++ ) |
|
818 { |
|
819 path->iPointCoords->AppendL( iPointCoords->operator[]( index ) ); |
|
820 } |
|
821 path->iLastX = iLastX; |
|
822 path->iLastY = iLastY; |
|
823 if(TUint8 count = path->Count()) |
|
824 { |
|
825 path->iPathSegmentTypeArray = new unsigned char[count]; |
|
826 for(int i =0; i<count ; i++) |
|
827 path->iPathSegmentTypeArray[i] = iPathSegmentTypeArray[i]; |
|
828 } |
|
829 else |
|
830 { |
|
831 path->iPathSegmentTypeArray = NULL; |
|
832 } |
|
833 CleanupStack::Pop(); |
|
834 return path; |
|
835 } |
|
836 |
|
837 // -------------------------------------------------------------------------- |
|
838 // void CGfxGeneralPath::QuadToLWithNoControlPoint() |
|
839 // If there is no previous command or if the previous command was not a |
|
840 // Q, q, T or t, the control point shall be current point. |
|
841 // --------------------------------------------------------------------------- |
|
842 void CGfxGeneralPath::QuadToLWithNoControlPoint(TFloatFixPt aX, TFloatFixPt aY) |
|
843 { |
|
844 TUint32 KSegQuadto = ( TUint32 ) EGfxSegQuadTo; |
|
845 iPointTypes->AppendL( KSegQuadto ); |
|
846 iPointCoords->AppendL( iLastX ); |
|
847 iPointCoords->AppendL( iLastY ); |
|
848 iPointCoords->AppendL( aX ); |
|
849 iPointCoords->AppendL( aY ); |
|
850 } |