* Reorganize the whole ReactOS codebase into a new layout. Discussing it will only...
[reactos.git] / reactos / win32ss / gdi / ntgdi / path.c
1 /*
2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: subsystems/win32/win32k/objects/path.c
5 * PURPOSE: Graphics paths (BeginPath, EndPath etc.)
6 * PROGRAMMER: Copyright 1997, 1998 Martin Boehme
7 * 1999 Huw D M Davies
8 * 2005 Dmitry Timoshkov
9 */
10
11 #include <win32k.h>
12
13 #define NDEBUG
14 #include <debug.h>
15
16 #ifdef _MSC_VER
17 #pragma warning(disable:4244)
18 #endif
19
20 #define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
21 #define GROW_FACTOR_NUMER 2 /* Numerator of grow factor for the array */
22 #define GROW_FACTOR_DENOM 1 /* Denominator of grow factor */
23
24 /***********************************************************************
25 * Internal functions
26 */
27
28 /* PATH_DestroyGdiPath
29 *
30 * Destroys a GdiPath structure (frees the memory in the arrays).
31 */
32 VOID
33 FASTCALL
34 PATH_DestroyGdiPath ( PPATH pPath )
35 {
36 ASSERT(pPath!=NULL);
37
38 if (pPath->pPoints) ExFreePoolWithTag(pPath->pPoints, TAG_PATH);
39 if (pPath->pFlags) ExFreePoolWithTag(pPath->pFlags, TAG_PATH);
40 }
41
42 BOOL
43 FASTCALL
44 PATH_Delete(HPATH hPath)
45 {
46 PPATH pPath;
47 if (!hPath) return FALSE;
48 pPath = PATH_LockPath( hPath );
49 if (!pPath) return FALSE;
50 PATH_DestroyGdiPath( pPath );
51 GDIOBJ_vDeleteObject(&pPath->BaseObject);
52 return TRUE;
53 }
54
55
56 VOID
57 FASTCALL
58 IntGdiCloseFigure(PPATH pPath)
59 {
60 ASSERT(pPath->state == PATH_Open);
61
62 // FIXME: Shouldn't we draw a line to the beginning of the figure?
63 // Set PT_CLOSEFIGURE on the last entry and start a new stroke
64 if(pPath->numEntriesUsed)
65 {
66 pPath->pFlags[pPath->numEntriesUsed-1]|=PT_CLOSEFIGURE;
67 pPath->newStroke=TRUE;
68 }
69 }
70
71 /* MSDN: This fails if the device coordinates exceed 27 bits, or if the converted
72 logical coordinates exceed 32 bits. */
73 BOOL
74 FASTCALL
75 GdiPathDPtoLP(PDC pdc, PPOINT ppt, INT count)
76 {
77 XFORMOBJ xo;
78
79 XFORMOBJ_vInit(&xo, &pdc->dclevel.mxDeviceToWorld);
80 return XFORMOBJ_bApplyXform(&xo, XF_LTOL, count, (PPOINTL)ppt, (PPOINTL)ppt);
81 }
82
83 /* PATH_FillPath
84 *
85 *
86 */
87 BOOL
88 FASTCALL
89 PATH_FillPath( PDC dc, PPATH pPath )
90 {
91 //INT mapMode, graphicsMode;
92 //SIZE ptViewportExt, ptWindowExt;
93 //POINTL ptViewportOrg, ptWindowOrg;
94 XFORM xform;
95 HRGN hrgn;
96 PDC_ATTR pdcattr = dc->pdcattr;
97
98 if( pPath->state != PATH_Closed )
99 {
100 EngSetLastError(ERROR_CAN_NOT_COMPLETE);
101 return FALSE;
102 }
103
104 if( PATH_PathToRegion( pPath, pdcattr->jFillMode, &hrgn ))
105 {
106 /* Since PaintRgn interprets the region as being in logical coordinates
107 * but the points we store for the path are already in device
108 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
109 * Using SaveDC to save information about the mapping mode / world
110 * transform would be easier but would require more overhead, especially
111 * now that SaveDC saves the current path.
112 */
113
114 /* Save the information about the old mapping mode */
115 //mapMode = pdcattr->iMapMode;
116 //ptViewportExt = pdcattr->szlViewportExt;
117 //ptViewportOrg = pdcattr->ptlViewportOrg;
118 //ptWindowExt = pdcattr->szlWindowExt;
119 //ptWindowOrg = pdcattr->ptlWindowOrg;
120
121 /* Save world transform
122 * NB: The Windows documentation on world transforms would lead one to
123 * believe that this has to be done only in GM_ADVANCED; however, my
124 * tests show that resetting the graphics mode to GM_COMPATIBLE does
125 * not reset the world transform.
126 */
127 MatrixS2XForm(&xform, &dc->dclevel.mxWorldToPage);
128
129 /* Set MM_TEXT */
130 // IntGdiSetMapMode( dc, MM_TEXT );
131 // pdcattr->ptlViewportOrg.x = 0;
132 // pdcattr->ptlViewportOrg.y = 0;
133 // pdcattr->ptlWindowOrg.x = 0;
134 // pdcattr->ptlWindowOrg.y = 0;
135
136 // graphicsMode = pdcattr->iGraphicsMode;
137 // pdcattr->iGraphicsMode = GM_ADVANCED;
138 // IntGdiModifyWorldTransform( dc, &xform, MWT_IDENTITY );
139 // pdcattr->iGraphicsMode = graphicsMode;
140
141 /* Paint the region */
142 IntGdiPaintRgn( dc, hrgn );
143 GreDeleteObject( hrgn );
144 /* Restore the old mapping mode */
145 // IntGdiSetMapMode( dc, mapMode );
146 // pdcattr->szlViewportExt = ptViewportExt;
147 // pdcattr->ptlViewportOrg = ptViewportOrg;
148 // pdcattr->szlWindowExt = ptWindowExt;
149 // pdcattr->ptlWindowOrg = ptWindowOrg;
150
151 /* Go to GM_ADVANCED temporarily to restore the world transform */
152 //graphicsMode = pdcattr->iGraphicsMode;
153 // pdcattr->iGraphicsMode = GM_ADVANCED;
154 // IntGdiModifyWorldTransform( dc, &xform, MWT_MAX+1 );
155 // pdcattr->iGraphicsMode = graphicsMode;
156 return TRUE;
157 }
158 return FALSE;
159 }
160
161 /* PATH_InitGdiPath
162 *
163 * Initializes the GdiPath structure.
164 */
165 VOID
166 FASTCALL
167 PATH_InitGdiPath ( PPATH pPath )
168 {
169 ASSERT(pPath!=NULL);
170
171 pPath->state=PATH_Null;
172 pPath->pPoints=NULL;
173 pPath->pFlags=NULL;
174 pPath->numEntriesUsed=0;
175 pPath->numEntriesAllocated=0;
176 }
177
178 /* PATH_AssignGdiPath
179 *
180 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
181 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
182 * not just the pointers. Since this means that the arrays in pPathDest may
183 * need to be resized, pPathDest should have been initialized using
184 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
185 * not a copy constructor).
186 * Returns TRUE if successful, else FALSE.
187 */
188 BOOL
189 FASTCALL
190 PATH_AssignGdiPath ( PPATH pPathDest, const PPATH pPathSrc )
191 {
192 ASSERT(pPathDest!=NULL && pPathSrc!=NULL);
193
194 /* Make sure destination arrays are big enough */
195 if ( !PATH_ReserveEntries(pPathDest, pPathSrc->numEntriesUsed) )
196 return FALSE;
197
198 /* Perform the copy operation */
199 memcpy(pPathDest->pPoints, pPathSrc->pPoints,
200 sizeof(POINT)*pPathSrc->numEntriesUsed);
201 memcpy(pPathDest->pFlags, pPathSrc->pFlags,
202 sizeof(BYTE)*pPathSrc->numEntriesUsed);
203
204 pPathDest->state=pPathSrc->state;
205 pPathDest->numEntriesUsed=pPathSrc->numEntriesUsed;
206 pPathDest->newStroke=pPathSrc->newStroke;
207 return TRUE;
208 }
209
210 /* PATH_MoveTo
211 *
212 * Should be called when a MoveTo is performed on a DC that has an
213 * open path. This starts a new stroke. Returns TRUE if successful, else
214 * FALSE.
215 */
216 BOOL
217 FASTCALL
218 PATH_MoveTo ( PDC dc )
219 {
220 PPATH pPath = PATH_LockPath( dc->dclevel.hPath );
221 if (!pPath) return FALSE;
222
223 /* Check that path is open */
224 if ( pPath->state != PATH_Open )
225 {
226 PATH_UnlockPath( pPath );
227 /* FIXME: Do we have to call SetLastError? */
228 return FALSE;
229 }
230 /* Start a new stroke */
231 pPath->newStroke = TRUE;
232 PATH_UnlockPath( pPath );
233 return TRUE;
234 }
235
236 /* PATH_LineTo
237 *
238 * Should be called when a LineTo is performed on a DC that has an
239 * open path. This adds a PT_LINETO entry to the path (and possibly
240 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
241 * Returns TRUE if successful, else FALSE.
242 */
243 BOOL
244 FASTCALL
245 PATH_LineTo ( PDC dc, INT x, INT y )
246 {
247 BOOL Ret;
248 PPATH pPath;
249 POINT point, pointCurPos;
250
251 pPath = PATH_LockPath( dc->dclevel.hPath );
252 if (!pPath) return FALSE;
253
254 /* Check that path is open */
255 if ( pPath->state != PATH_Open )
256 {
257 PATH_UnlockPath( pPath );
258 return FALSE;
259 }
260
261 /* Convert point to device coordinates */
262 point.x=x;
263 point.y=y;
264 CoordLPtoDP ( dc, &point );
265
266 /* Add a PT_MOVETO if necessary */
267 if ( pPath->newStroke )
268 {
269 pPath->newStroke = FALSE;
270 IntGetCurrentPositionEx ( dc, &pointCurPos );
271 CoordLPtoDP ( dc, &pointCurPos );
272 if ( !PATH_AddEntry(pPath, &pointCurPos, PT_MOVETO) )
273 {
274 PATH_UnlockPath( pPath );
275 return FALSE;
276 }
277 }
278
279 /* Add a PT_LINETO entry */
280 Ret = PATH_AddEntry(pPath, &point, PT_LINETO);
281 PATH_UnlockPath( pPath );
282 return Ret;
283 }
284
285 /* PATH_Rectangle
286 *
287 * Should be called when a call to Rectangle is performed on a DC that has
288 * an open path. Returns TRUE if successful, else FALSE.
289 */
290 BOOL
291 FASTCALL
292 PATH_Rectangle ( PDC dc, INT x1, INT y1, INT x2, INT y2 )
293 {
294 PPATH pPath;
295 POINT corners[2], pointTemp;
296 INT temp;
297
298 pPath = PATH_LockPath( dc->dclevel.hPath );
299 if (!pPath) return FALSE;
300
301 /* Check that path is open */
302 if ( pPath->state != PATH_Open )
303 {
304 PATH_UnlockPath( pPath );
305 return FALSE;
306 }
307
308 /* Convert points to device coordinates */
309 corners[0].x=x1;
310 corners[0].y=y1;
311 corners[1].x=x2;
312 corners[1].y=y2;
313 IntLPtoDP ( dc, corners, 2 );
314
315 /* Make sure first corner is top left and second corner is bottom right */
316 if ( corners[0].x > corners[1].x )
317 {
318 temp=corners[0].x;
319 corners[0].x=corners[1].x;
320 corners[1].x=temp;
321 }
322 if ( corners[0].y > corners[1].y )
323 {
324 temp=corners[0].y;
325 corners[0].y=corners[1].y;
326 corners[1].y=temp;
327 }
328
329 /* In GM_COMPATIBLE, don't include bottom and right edges */
330 if (dc->pdcattr->iGraphicsMode == GM_COMPATIBLE)
331 {
332 corners[1].x--;
333 corners[1].y--;
334 }
335
336 /* Close any previous figure */
337 IntGdiCloseFigure(pPath);
338
339 /* Add four points to the path */
340 pointTemp.x=corners[1].x;
341 pointTemp.y=corners[0].y;
342 if ( !PATH_AddEntry(pPath, &pointTemp, PT_MOVETO) )
343 {
344 PATH_UnlockPath( pPath );
345 return FALSE;
346 }
347 if ( !PATH_AddEntry(pPath, corners, PT_LINETO) )
348 {
349 PATH_UnlockPath( pPath );
350 return FALSE;
351 }
352 pointTemp.x=corners[0].x;
353 pointTemp.y=corners[1].y;
354 if ( !PATH_AddEntry(pPath, &pointTemp, PT_LINETO) )
355 {
356 PATH_UnlockPath( pPath );
357 return FALSE;
358 }
359 if ( !PATH_AddEntry(pPath, corners+1, PT_LINETO) )
360 {
361 PATH_UnlockPath( pPath );
362 return FALSE;
363 }
364
365 /* Close the rectangle figure */
366 IntGdiCloseFigure(pPath) ;
367 PATH_UnlockPath( pPath );
368 return TRUE;
369 }
370
371 /* PATH_RoundRect
372 *
373 * Should be called when a call to RoundRect is performed on a DC that has
374 * an open path. Returns TRUE if successful, else FALSE.
375 *
376 * FIXME: It adds the same entries to the path as windows does, but there
377 * is an error in the bezier drawing code so that there are small pixel-size
378 * gaps when the resulting path is drawn by StrokePath()
379 */
380 BOOL FASTCALL PATH_RoundRect(DC *dc, INT x1, INT y1, INT x2, INT y2, INT ell_width, INT ell_height)
381 {
382 PPATH pPath;
383 POINT corners[2], pointTemp;
384 FLOAT_POINT ellCorners[2];
385
386 pPath = PATH_LockPath( dc->dclevel.hPath );
387 if (!pPath) return FALSE;
388
389 /* Check that path is open */
390 if(pPath->state!=PATH_Open)
391 {
392 PATH_UnlockPath( pPath );
393 return FALSE;
394 }
395
396 if(!PATH_CheckCorners(dc,corners,x1,y1,x2,y2))
397 {
398 PATH_UnlockPath( pPath );
399 return FALSE;
400 }
401
402 /* Add points to the roundrect path */
403 ellCorners[0].x = corners[1].x-ell_width;
404 ellCorners[0].y = corners[0].y;
405 ellCorners[1].x = corners[1].x;
406 ellCorners[1].y = corners[0].y+ell_height;
407 if(!PATH_DoArcPart(pPath, ellCorners, 0, -M_PI_2, PT_MOVETO))
408 {
409 PATH_UnlockPath( pPath );
410 return FALSE;
411 }
412 pointTemp.x = corners[0].x+ell_width/2;
413 pointTemp.y = corners[0].y;
414 if(!PATH_AddEntry(pPath, &pointTemp, PT_LINETO))
415 {
416 PATH_UnlockPath( pPath );
417 return FALSE;
418 }
419 ellCorners[0].x = corners[0].x;
420 ellCorners[1].x = corners[0].x+ell_width;
421 if(!PATH_DoArcPart(pPath, ellCorners, -M_PI_2, -M_PI, FALSE))
422 {
423 PATH_UnlockPath( pPath );
424 return FALSE;
425 }
426 pointTemp.x = corners[0].x;
427 pointTemp.y = corners[1].y-ell_height/2;
428 if(!PATH_AddEntry(pPath, &pointTemp, PT_LINETO))
429 {
430 PATH_UnlockPath( pPath );
431 return FALSE;
432 }
433 ellCorners[0].y = corners[1].y-ell_height;
434 ellCorners[1].y = corners[1].y;
435 if(!PATH_DoArcPart(pPath, ellCorners, M_PI, M_PI_2, FALSE))
436 {
437 PATH_UnlockPath( pPath );
438 return FALSE;
439 }
440 pointTemp.x = corners[1].x-ell_width/2;
441 pointTemp.y = corners[1].y;
442 if(!PATH_AddEntry(pPath, &pointTemp, PT_LINETO))
443 {
444 PATH_UnlockPath( pPath );
445 return FALSE;
446 }
447 ellCorners[0].x = corners[1].x-ell_width;
448 ellCorners[1].x = corners[1].x;
449 if(!PATH_DoArcPart(pPath, ellCorners, M_PI_2, 0, FALSE))
450 {
451 PATH_UnlockPath( pPath );
452 return FALSE;
453 }
454
455 IntGdiCloseFigure(pPath);
456 PATH_UnlockPath( pPath );
457 return TRUE;
458 }
459
460 /* PATH_Ellipse
461 *
462 * Should be called when a call to Ellipse is performed on a DC that has
463 * an open path. This adds four Bezier splines representing the ellipse
464 * to the path. Returns TRUE if successful, else FALSE.
465 */
466 BOOL
467 FASTCALL
468 PATH_Ellipse ( PDC dc, INT x1, INT y1, INT x2, INT y2 )
469 {
470 PPATH pPath;
471 /* TODO: This should probably be revised to call PATH_AngleArc */
472 /* (once it exists) */
473 BOOL Ret = PATH_Arc ( dc, x1, y1, x2, y2, x1, (y1+y2)/2, x1, (y1+y2)/2, GdiTypeArc );
474 if (Ret)
475 {
476 pPath = PATH_LockPath( dc->dclevel.hPath );
477 if (!pPath) return FALSE;
478 IntGdiCloseFigure(pPath);
479 PATH_UnlockPath( pPath );
480 }
481 return Ret;
482 }
483
484 /* PATH_Arc
485 *
486 * Should be called when a call to Arc is performed on a DC that has
487 * an open path. This adds up to five Bezier splines representing the arc
488 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
489 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
490 * -1 we add 1 extra line from the current DC position to the starting position
491 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
492 * else FALSE.
493 */
494 BOOL
495 FASTCALL
496 PATH_Arc ( PDC dc, INT x1, INT y1, INT x2, INT y2,
497 INT xStart, INT yStart, INT xEnd, INT yEnd, INT lines)
498 {
499 double angleStart, angleEnd, angleStartQuadrant, angleEndQuadrant=0.0;
500 /* Initialize angleEndQuadrant to silence gcc's warning */
501 double x, y;
502 FLOAT_POINT corners[2], pointStart, pointEnd;
503 POINT centre, pointCurPos;
504 BOOL start, end, Ret = TRUE;
505 INT temp;
506 BOOL clockwise;
507 PPATH pPath;
508
509 /* FIXME: This function should check for all possible error returns */
510 /* FIXME: Do we have to respect newStroke? */
511
512 ASSERT ( dc );
513
514 pPath = PATH_LockPath( dc->dclevel.hPath );
515 if (!pPath) return FALSE;
516
517 clockwise = ((dc->dclevel.flPath & DCPATH_CLOCKWISE) != 0);
518
519 /* Check that path is open */
520 if ( pPath->state != PATH_Open )
521 {
522 Ret = FALSE;
523 goto ArcExit;
524 }
525
526 /* Check for zero height / width */
527 /* FIXME: Only in GM_COMPATIBLE? */
528 if ( x1==x2 || y1==y2 )
529 {
530 Ret = TRUE;
531 goto ArcExit;
532 }
533 /* Convert points to device coordinates */
534 corners[0].x=(FLOAT)x1;
535 corners[0].y=(FLOAT)y1;
536 corners[1].x=(FLOAT)x2;
537 corners[1].y=(FLOAT)y2;
538 pointStart.x=(FLOAT)xStart;
539 pointStart.y=(FLOAT)yStart;
540 pointEnd.x=(FLOAT)xEnd;
541 pointEnd.y=(FLOAT)yEnd;
542 INTERNAL_LPTODP_FLOAT(dc, corners);
543 INTERNAL_LPTODP_FLOAT(dc, corners+1);
544 INTERNAL_LPTODP_FLOAT(dc, &pointStart);
545 INTERNAL_LPTODP_FLOAT(dc, &pointEnd);
546
547 /* Make sure first corner is top left and second corner is bottom right */
548 if ( corners[0].x > corners[1].x )
549 {
550 temp=corners[0].x;
551 corners[0].x=corners[1].x;
552 corners[1].x=temp;
553 }
554 if ( corners[0].y > corners[1].y )
555 {
556 temp=corners[0].y;
557 corners[0].y=corners[1].y;
558 corners[1].y=temp;
559 }
560
561 /* Compute start and end angle */
562 PATH_NormalizePoint(corners, &pointStart, &x, &y);
563 angleStart=atan2(y, x);
564 PATH_NormalizePoint(corners, &pointEnd, &x, &y);
565 angleEnd=atan2(y, x);
566
567 /* Make sure the end angle is "on the right side" of the start angle */
568 if ( clockwise )
569 {
570 if ( angleEnd <= angleStart )
571 {
572 angleEnd+=2*M_PI;
573 ASSERT(angleEnd>=angleStart);
574 }
575 }
576 else
577 {
578 if(angleEnd>=angleStart)
579 {
580 angleEnd-=2*M_PI;
581 ASSERT(angleEnd<=angleStart);
582 }
583 }
584
585 /* In GM_COMPATIBLE, don't include bottom and right edges */
586 if (dc->pdcattr->iGraphicsMode == GM_COMPATIBLE )
587 {
588 corners[1].x--;
589 corners[1].y--;
590 }
591
592 /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
593 if(lines==GdiTypeArcTo && pPath->newStroke) // -1
594 {
595 pPath->newStroke=FALSE;
596 IntGetCurrentPositionEx ( dc, &pointCurPos );
597 CoordLPtoDP(dc, &pointCurPos);
598 if(!PATH_AddEntry(pPath, &pointCurPos, PT_MOVETO))
599 {
600 Ret = FALSE;
601 goto ArcExit;
602 }
603 }
604
605 /* Add the arc to the path with one Bezier spline per quadrant that the
606 * arc spans */
607 start=TRUE;
608 end=FALSE;
609 do
610 {
611 /* Determine the start and end angles for this quadrant */
612 if(start)
613 {
614 angleStartQuadrant=angleStart;
615 if ( clockwise )
616 angleEndQuadrant=(floor(angleStart/M_PI_2)+1.0)*M_PI_2;
617 else
618 angleEndQuadrant=(ceil(angleStart/M_PI_2)-1.0)*M_PI_2;
619 }
620 else
621 {
622 angleStartQuadrant=angleEndQuadrant;
623 if ( clockwise )
624 angleEndQuadrant+=M_PI_2;
625 else
626 angleEndQuadrant-=M_PI_2;
627 }
628
629 /* Have we reached the last part of the arc? */
630 if ( (clockwise && angleEnd<angleEndQuadrant)
631 || (!clockwise && angleEnd>angleEndQuadrant)
632 )
633 {
634 /* Adjust the end angle for this quadrant */
635 angleEndQuadrant = angleEnd;
636 end = TRUE;
637 }
638
639 /* Add the Bezier spline to the path */
640 PATH_DoArcPart ( pPath, corners, angleStartQuadrant, angleEndQuadrant,
641 start ? (lines==GdiTypeArcTo ? PT_LINETO : PT_MOVETO) : FALSE ); // -1
642 start = FALSE;
643 } while(!end);
644
645 /* chord: close figure. pie: add line and close figure */
646 if (lines==GdiTypeChord) // 1
647 {
648 IntGdiCloseFigure(pPath);
649 }
650 else if (lines==GdiTypePie) // 2
651 {
652 centre.x = (corners[0].x+corners[1].x)/2;
653 centre.y = (corners[0].y+corners[1].y)/2;
654 if(!PATH_AddEntry(pPath, &centre, PT_LINETO | PT_CLOSEFIGURE))
655 Ret = FALSE;
656 }
657 ArcExit:
658 PATH_UnlockPath( pPath );
659 return Ret;
660 }
661
662 BOOL
663 FASTCALL
664 PATH_PolyBezierTo ( PDC dc, const POINT *pts, DWORD cbPoints )
665 {
666 POINT pt;
667 ULONG i;
668 PPATH pPath;
669
670 ASSERT ( dc );
671 ASSERT ( pts );
672 ASSERT ( cbPoints );
673
674 pPath = PATH_LockPath( dc->dclevel.hPath );
675 if (!pPath) return FALSE;
676
677 /* Check that path is open */
678 if ( pPath->state != PATH_Open )
679 {
680 PATH_UnlockPath( pPath );
681 return FALSE;
682 }
683
684 /* Add a PT_MOVETO if necessary */
685 if ( pPath->newStroke )
686 {
687 pPath->newStroke=FALSE;
688 IntGetCurrentPositionEx ( dc, &pt );
689 CoordLPtoDP ( dc, &pt );
690 if ( !PATH_AddEntry(pPath, &pt, PT_MOVETO) )
691 {
692 PATH_UnlockPath( pPath );
693 return FALSE;
694 }
695 }
696
697 for(i = 0; i < cbPoints; i++)
698 {
699 pt = pts[i];
700 CoordLPtoDP ( dc, &pt );
701 PATH_AddEntry(pPath, &pt, PT_BEZIERTO);
702 }
703 PATH_UnlockPath( pPath );
704 return TRUE;
705 }
706
707 BOOL
708 FASTCALL
709 PATH_PolyBezier ( PDC dc, const POINT *pts, DWORD cbPoints )
710 {
711 POINT pt;
712 ULONG i;
713 PPATH pPath;
714
715 ASSERT ( dc );
716 ASSERT ( pts );
717 ASSERT ( cbPoints );
718
719 pPath = PATH_LockPath( dc->dclevel.hPath );
720 if (!pPath) return FALSE;
721
722 /* Check that path is open */
723 if ( pPath->state != PATH_Open )
724 {
725 PATH_UnlockPath( pPath );
726 return FALSE;
727 }
728
729 for ( i = 0; i < cbPoints; i++ )
730 {
731 pt = pts[i];
732 CoordLPtoDP ( dc, &pt );
733 PATH_AddEntry ( pPath, &pt, (i == 0) ? PT_MOVETO : PT_BEZIERTO );
734 }
735 PATH_UnlockPath( pPath );
736 return TRUE;
737 }
738
739 BOOL
740 FASTCALL
741 PATH_PolyDraw(PDC dc, const POINT *pts, const BYTE *types, DWORD cbPoints)
742 {
743 PPATH pPath;
744 POINT lastmove, orig_pos;
745 ULONG i;
746 PDC_ATTR pdcattr;
747 BOOL State = FALSE, Ret = FALSE;
748
749 pPath = PATH_LockPath( dc->dclevel.hPath );
750 if (!pPath) return FALSE;
751
752 if ( pPath->state != PATH_Open )
753 {
754 PATH_UnlockPath( pPath );
755 return FALSE;
756 }
757
758 pdcattr = dc->pdcattr;
759
760 lastmove.x = orig_pos.x = pdcattr->ptlCurrent.x;
761 lastmove.y = orig_pos.y = pdcattr->ptlCurrent.y;
762
763 i = pPath->numEntriesUsed;
764
765 while (i != 0)
766 {
767 i--;
768 if (pPath->pFlags[i] == PT_MOVETO)
769 {
770 lastmove.x = pPath->pPoints[i].x;
771 lastmove.y = pPath->pPoints[i].y;
772 if (!GdiPathDPtoLP(dc, &lastmove, 1))
773 {
774 PATH_UnlockPath( pPath );
775 return FALSE;
776 }
777 break;
778 }
779 }
780
781 for (i = 0; i < cbPoints; i++)
782 {
783 if (types[i] == PT_MOVETO)
784 {
785 pPath->newStroke = TRUE;
786 lastmove.x = pts[i].x;
787 lastmove.y = pts[i].y;
788 }
789 else if((types[i] & ~PT_CLOSEFIGURE) == PT_LINETO)
790 {
791 PATH_LineTo(dc, pts[i].x, pts[i].y);
792 }
793 else if(types[i] == PT_BEZIERTO)
794 {
795 if (!((i + 2 < cbPoints) && (types[i + 1] == PT_BEZIERTO)
796 && ((types[i + 2] & ~PT_CLOSEFIGURE) == PT_BEZIERTO)))
797 goto err;
798 PATH_PolyBezierTo(dc, &(pts[i]), 3);
799 i += 2;
800 }
801 else
802 goto err;
803
804 pdcattr->ptlCurrent.x = pts[i].x;
805 pdcattr->ptlCurrent.y = pts[i].y;
806 State = TRUE;
807
808 if (types[i] & PT_CLOSEFIGURE)
809 {
810 pPath->pFlags[pPath->numEntriesUsed-1] |= PT_CLOSEFIGURE;
811 pPath->newStroke = TRUE;
812 pdcattr->ptlCurrent.x = lastmove.x;
813 pdcattr->ptlCurrent.y = lastmove.y;
814 State = TRUE;
815 }
816 }
817 Ret = TRUE;
818 goto Exit;
819
820 err:
821 if ((pdcattr->ptlCurrent.x != orig_pos.x) || (pdcattr->ptlCurrent.y != orig_pos.y))
822 {
823 pPath->newStroke = TRUE;
824 pdcattr->ptlCurrent.x = orig_pos.x;
825 pdcattr->ptlCurrent.y = orig_pos.y;
826 State = TRUE;
827 }
828 Exit:
829 if (State) // State change?
830 {
831 pdcattr->ptfxCurrent = pdcattr->ptlCurrent;
832 CoordLPtoDP(dc, &pdcattr->ptfxCurrent); // Update fx
833 pdcattr->ulDirty_ &= ~(DIRTY_PTLCURRENT|DIRTY_PTFXCURRENT|DIRTY_STYLESTATE);
834 }
835 PATH_UnlockPath( pPath );
836 return Ret;
837 }
838
839 BOOL
840 FASTCALL
841 PATH_Polyline ( PDC dc, const POINT *pts, DWORD cbPoints )
842 {
843 POINT pt;
844 ULONG i;
845 PPATH pPath;
846
847 ASSERT ( dc );
848 ASSERT ( pts );
849 ASSERT ( cbPoints );
850
851 pPath = PATH_LockPath( dc->dclevel.hPath );
852 if (!pPath) return FALSE;
853
854 /* Check that path is open */
855 if ( pPath->state != PATH_Open )
856 {
857 PATH_UnlockPath( pPath );
858 return FALSE;
859 }
860 for ( i = 0; i < cbPoints; i++ )
861 {
862 pt = pts[i];
863 CoordLPtoDP ( dc, &pt );
864 PATH_AddEntry(pPath, &pt, (i == 0) ? PT_MOVETO : PT_LINETO);
865 }
866 PATH_UnlockPath( pPath );
867 return TRUE;
868 }
869
870 BOOL
871 FASTCALL
872 PATH_PolylineTo ( PDC dc, const POINT *pts, DWORD cbPoints )
873 {
874 POINT pt;
875 ULONG i;
876 PPATH pPath;
877
878 ASSERT ( dc );
879 ASSERT ( pts );
880 ASSERT ( cbPoints );
881
882 pPath = PATH_LockPath( dc->dclevel.hPath );
883 if (!pPath) return FALSE;
884
885 /* Check that path is open */
886 if ( pPath->state != PATH_Open )
887 {
888 PATH_UnlockPath( pPath );
889 return FALSE;
890 }
891
892 /* Add a PT_MOVETO if necessary */
893 if ( pPath->newStroke )
894 {
895 pPath->newStroke = FALSE;
896 IntGetCurrentPositionEx ( dc, &pt );
897 CoordLPtoDP ( dc, &pt );
898 if ( !PATH_AddEntry(pPath, &pt, PT_MOVETO) )
899 {
900 PATH_UnlockPath( pPath );
901 return FALSE;
902 }
903 }
904
905 for(i = 0; i < cbPoints; i++)
906 {
907 pt = pts[i];
908 CoordLPtoDP ( dc, &pt );
909 PATH_AddEntry(pPath, &pt, PT_LINETO);
910 }
911 PATH_UnlockPath( pPath );
912 return TRUE;
913 }
914
915
916 BOOL
917 FASTCALL
918 PATH_Polygon ( PDC dc, const POINT *pts, DWORD cbPoints )
919 {
920 POINT pt;
921 ULONG i;
922 PPATH pPath;
923
924 ASSERT ( dc );
925 ASSERT ( pts );
926
927 pPath = PATH_LockPath( dc->dclevel.hPath );
928 if (!pPath) return FALSE;
929
930 /* Check that path is open */
931 if ( pPath->state != PATH_Open )
932 {
933 PATH_UnlockPath( pPath );
934 return FALSE;
935 }
936
937 for(i = 0; i < cbPoints; i++)
938 {
939 pt = pts[i];
940 CoordLPtoDP ( dc, &pt );
941 PATH_AddEntry(pPath, &pt, (i == 0) ? PT_MOVETO :
942 ((i == cbPoints-1) ? PT_LINETO | PT_CLOSEFIGURE :
943 PT_LINETO));
944 }
945 PATH_UnlockPath( pPath );
946 return TRUE;
947 }
948
949 BOOL
950 FASTCALL
951 PATH_PolyPolygon ( PDC dc, const POINT* pts, const INT* counts, UINT polygons )
952 {
953 POINT pt, startpt;
954 ULONG poly, point, i;
955 PPATH pPath;
956
957 ASSERT ( dc );
958 ASSERT ( pts );
959 ASSERT ( counts );
960 ASSERT ( polygons );
961
962 pPath = PATH_LockPath( dc->dclevel.hPath );
963 if (!pPath) return FALSE;
964
965 /* Check that path is open */
966 if ( pPath->state != PATH_Open )
967 {
968 PATH_UnlockPath( pPath );
969 return FALSE;
970 }
971
972 for(i = 0, poly = 0; poly < polygons; poly++)
973 {
974 for(point = 0; point < (ULONG) counts[poly]; point++, i++)
975 {
976 pt = pts[i];
977 CoordLPtoDP ( dc, &pt );
978 if(point == 0) startpt = pt;
979 PATH_AddEntry(pPath, &pt, (point == 0) ? PT_MOVETO : PT_LINETO);
980 }
981 /* Win98 adds an extra line to close the figure for some reason */
982 PATH_AddEntry(pPath, &startpt, PT_LINETO | PT_CLOSEFIGURE);
983 }
984 PATH_UnlockPath( pPath );
985 return TRUE;
986 }
987
988 BOOL
989 FASTCALL
990 PATH_PolyPolyline ( PDC dc, const POINT* pts, const DWORD* counts, DWORD polylines )
991 {
992 POINT pt;
993 ULONG poly, point, i;
994 PPATH pPath;
995
996 ASSERT ( dc );
997 ASSERT ( pts );
998 ASSERT ( counts );
999 ASSERT ( polylines );
1000
1001 pPath = PATH_LockPath( dc->dclevel.hPath );
1002 if (!pPath) return FALSE;
1003
1004 /* Check that path is open */
1005 if ( pPath->state != PATH_Open )
1006 {
1007 PATH_UnlockPath( pPath );
1008 return FALSE;
1009 }
1010
1011 for(i = 0, poly = 0; poly < polylines; poly++)
1012 {
1013 for(point = 0; point < counts[poly]; point++, i++)
1014 {
1015 pt = pts[i];
1016 CoordLPtoDP ( dc, &pt );
1017 PATH_AddEntry(pPath, &pt, (point == 0) ? PT_MOVETO : PT_LINETO);
1018 }
1019 }
1020 PATH_UnlockPath( pPath );
1021 return TRUE;
1022 }
1023
1024
1025 /* PATH_CheckCorners
1026 *
1027 * Helper function for PATH_RoundRect() and PATH_Rectangle()
1028 */
1029 BOOL PATH_CheckCorners(DC *dc, POINT corners[], INT x1, INT y1, INT x2, INT y2)
1030 {
1031 INT temp;
1032 PDC_ATTR pdcattr = dc->pdcattr;
1033
1034 /* Convert points to device coordinates */
1035 corners[0].x=x1;
1036 corners[0].y=y1;
1037 corners[1].x=x2;
1038 corners[1].y=y2;
1039 CoordLPtoDP(dc, &corners[0]);
1040 CoordLPtoDP(dc, &corners[1]);
1041
1042 /* Make sure first corner is top left and second corner is bottom right */
1043 if(corners[0].x>corners[1].x)
1044 {
1045 temp=corners[0].x;
1046 corners[0].x=corners[1].x;
1047 corners[1].x=temp;
1048 }
1049 if(corners[0].y>corners[1].y)
1050 {
1051 temp=corners[0].y;
1052 corners[0].y=corners[1].y;
1053 corners[1].y=temp;
1054 }
1055
1056 /* In GM_COMPATIBLE, don't include bottom and right edges */
1057 if(pdcattr->iGraphicsMode==GM_COMPATIBLE)
1058 {
1059 corners[1].x--;
1060 corners[1].y--;
1061 }
1062
1063 return TRUE;
1064 }
1065
1066
1067 /* PATH_AddFlatBezier
1068 *
1069 */
1070 BOOL
1071 FASTCALL
1072 PATH_AddFlatBezier ( PPATH pPath, POINT *pt, BOOL closed )
1073 {
1074 POINT *pts;
1075 INT no, i;
1076
1077 pts = GDI_Bezier( pt, 4, &no );
1078 if ( !pts ) return FALSE;
1079
1080 for(i = 1; i < no; i++)
1081 PATH_AddEntry(pPath, &pts[i], (i == no-1 && closed) ? PT_LINETO | PT_CLOSEFIGURE : PT_LINETO);
1082
1083 ExFreePoolWithTag(pts, TAG_BEZIER);
1084 return TRUE;
1085 }
1086
1087 /* PATH_FlattenPath
1088 *
1089 * Replaces Beziers with line segments
1090 *
1091 */
1092 BOOL
1093 FASTCALL
1094 PATH_FlattenPath(PPATH pPath)
1095 {
1096 PATH newPath;
1097 INT srcpt;
1098
1099 RtlZeroMemory(&newPath, sizeof(newPath));
1100 newPath.state = PATH_Open;
1101 for(srcpt = 0; srcpt < pPath->numEntriesUsed; srcpt++) {
1102 switch(pPath->pFlags[srcpt] & ~PT_CLOSEFIGURE) {
1103 case PT_MOVETO:
1104 case PT_LINETO:
1105 PATH_AddEntry(&newPath, &pPath->pPoints[srcpt], pPath->pFlags[srcpt]);
1106 break;
1107 case PT_BEZIERTO:
1108 PATH_AddFlatBezier(&newPath, &pPath->pPoints[srcpt-1], pPath->pFlags[srcpt+2] & PT_CLOSEFIGURE);
1109 srcpt += 2;
1110 break;
1111 }
1112 }
1113 newPath.state = PATH_Closed;
1114 PATH_AssignGdiPath(pPath, &newPath);
1115 PATH_EmptyPath(&newPath);
1116 return TRUE;
1117 }
1118
1119
1120 /* PATH_PathToRegion
1121 *
1122 * Creates a region from the specified path using the specified polygon
1123 * filling mode. The path is left unchanged. A handle to the region that
1124 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1125 * error occurs, SetLastError is called with the appropriate value and
1126 * FALSE is returned.
1127 */
1128 BOOL
1129 FASTCALL
1130 PATH_PathToRegion ( PPATH pPath, INT nPolyFillMode, HRGN *pHrgn )
1131 {
1132 int numStrokes, iStroke, i;
1133 PULONG pNumPointsInStroke;
1134 HRGN hrgn = 0;
1135
1136 ASSERT(pPath!=NULL);
1137 ASSERT(pHrgn!=NULL);
1138
1139 PATH_FlattenPath ( pPath );
1140
1141 /* First pass: Find out how many strokes there are in the path */
1142 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1143 numStrokes=0;
1144 for(i=0; i<pPath->numEntriesUsed; i++)
1145 if((pPath->pFlags[i] & ~PT_CLOSEFIGURE) == PT_MOVETO)
1146 numStrokes++;
1147
1148 if(numStrokes == 0)
1149 {
1150 return FALSE;
1151 }
1152
1153 /* Allocate memory for number-of-points-in-stroke array */
1154 pNumPointsInStroke = ExAllocatePoolWithTag(PagedPool, sizeof(ULONG) * numStrokes, TAG_PATH);
1155 if(!pNumPointsInStroke)
1156 {
1157 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
1158 return FALSE;
1159 }
1160
1161 /* Second pass: remember number of points in each polygon */
1162 iStroke=-1; /* Will get incremented to 0 at beginning of first stroke */
1163 for(i=0; i<pPath->numEntriesUsed; i++)
1164 {
1165 /* Is this the beginning of a new stroke? */
1166 if((pPath->pFlags[i] & ~PT_CLOSEFIGURE) == PT_MOVETO)
1167 {
1168 iStroke++;
1169 pNumPointsInStroke[iStroke]=0;
1170 }
1171
1172 pNumPointsInStroke[iStroke]++;
1173 }
1174
1175 /* Create a region from the strokes */
1176 hrgn = IntCreatePolyPolygonRgn( pPath->pPoints,
1177 pNumPointsInStroke,
1178 numStrokes,
1179 nPolyFillMode);
1180 if(hrgn==(HRGN)0)
1181 {
1182 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
1183 return FALSE;
1184 }
1185
1186 /* Free memory for number-of-points-in-stroke array */
1187 ExFreePoolWithTag(pNumPointsInStroke, TAG_PATH);
1188
1189 /* Success! */
1190 *pHrgn=hrgn;
1191 return TRUE;
1192 }
1193
1194 /* PATH_EmptyPath
1195 *
1196 * Removes all entries from the path and sets the path state to PATH_Null.
1197 */
1198 VOID
1199 FASTCALL
1200 PATH_EmptyPath ( PPATH pPath )
1201 {
1202 ASSERT(pPath!=NULL);
1203
1204 pPath->state=PATH_Null;
1205 pPath->numEntriesUsed=0;
1206 }
1207
1208 /* PATH_AddEntry
1209 *
1210 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1211 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1212 * successful, FALSE otherwise (e.g. if not enough memory was available).
1213 */
1214 BOOL
1215 FASTCALL
1216 PATH_AddEntry ( PPATH pPath, const POINT *pPoint, BYTE flags )
1217 {
1218 ASSERT(pPath!=NULL);
1219
1220 /* FIXME: If newStroke is true, perhaps we want to check that we're
1221 * getting a PT_MOVETO
1222 */
1223
1224 /* Check that path is open */
1225 if ( pPath->state != PATH_Open )
1226 return FALSE;
1227
1228 /* Reserve enough memory for an extra path entry */
1229 if ( !PATH_ReserveEntries(pPath, pPath->numEntriesUsed+1) )
1230 return FALSE;
1231
1232 /* Store information in path entry */
1233 pPath->pPoints[pPath->numEntriesUsed]=*pPoint;
1234 pPath->pFlags[pPath->numEntriesUsed]=flags;
1235
1236 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1237 if((flags & PT_CLOSEFIGURE) == PT_CLOSEFIGURE)
1238 pPath->newStroke=TRUE;
1239
1240 /* Increment entry count */
1241 pPath->numEntriesUsed++;
1242
1243 return TRUE;
1244 }
1245
1246 /* PATH_ReserveEntries
1247 *
1248 * Ensures that at least "numEntries" entries (for points and flags) have
1249 * been allocated; allocates larger arrays and copies the existing entries
1250 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1251 */
1252 BOOL
1253 FASTCALL
1254 PATH_ReserveEntries ( PPATH pPath, INT numEntries )
1255 {
1256 INT numEntriesToAllocate;
1257 POINT *pPointsNew;
1258 BYTE *pFlagsNew;
1259
1260 ASSERT(pPath!=NULL);
1261 ASSERT(numEntries>=0);
1262
1263 /* Do we have to allocate more memory? */
1264 if(numEntries > pPath->numEntriesAllocated)
1265 {
1266 /* Find number of entries to allocate. We let the size of the array
1267 * grow exponentially, since that will guarantee linear time
1268 * complexity. */
1269 if(pPath->numEntriesAllocated)
1270 {
1271 numEntriesToAllocate=pPath->numEntriesAllocated;
1272 while(numEntriesToAllocate<numEntries)
1273 numEntriesToAllocate=numEntriesToAllocate*GROW_FACTOR_NUMER/GROW_FACTOR_DENOM;
1274 } else
1275 numEntriesToAllocate=numEntries;
1276
1277 /* Allocate new arrays */
1278 pPointsNew=(POINT *)ExAllocatePoolWithTag(PagedPool, numEntriesToAllocate * sizeof(POINT), TAG_PATH);
1279 if(!pPointsNew)
1280 return FALSE;
1281 pFlagsNew=(BYTE *)ExAllocatePoolWithTag(PagedPool, numEntriesToAllocate * sizeof(BYTE), TAG_PATH);
1282 if(!pFlagsNew)
1283 {
1284 ExFreePoolWithTag(pPointsNew, TAG_PATH);
1285 return FALSE;
1286 }
1287
1288 /* Copy old arrays to new arrays and discard old arrays */
1289 if(pPath->pPoints)
1290 {
1291 ASSERT(pPath->pFlags);
1292
1293 memcpy(pPointsNew, pPath->pPoints, sizeof(POINT)*pPath->numEntriesUsed);
1294 memcpy(pFlagsNew, pPath->pFlags, sizeof(BYTE)*pPath->numEntriesUsed);
1295
1296 ExFreePoolWithTag(pPath->pPoints, TAG_PATH);
1297 ExFreePoolWithTag(pPath->pFlags, TAG_PATH);
1298 }
1299 pPath->pPoints=pPointsNew;
1300 pPath->pFlags=pFlagsNew;
1301 pPath->numEntriesAllocated=numEntriesToAllocate;
1302 }
1303
1304 return TRUE;
1305 }
1306
1307 /* PATH_DoArcPart
1308 *
1309 * Creates a Bezier spline that corresponds to part of an arc and appends the
1310 * corresponding points to the path. The start and end angles are passed in
1311 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1312 * at most. If "startEntryType" is non-zero, an entry of that type for the first
1313 * control point is added to the path; otherwise, it is assumed that the current
1314 * position is equal to the first control point.
1315 */
1316 BOOL
1317 FASTCALL
1318 PATH_DoArcPart ( PPATH pPath, FLOAT_POINT corners[],
1319 double angleStart, double angleEnd, BYTE startEntryType )
1320 {
1321 double halfAngle, a;
1322 double xNorm[4], yNorm[4];
1323 POINT point;
1324 int i;
1325
1326 ASSERT(fabs(angleEnd-angleStart)<=M_PI_2);
1327
1328 /* FIXME: Is there an easier way of computing this? */
1329
1330 /* Compute control points */
1331 halfAngle=(angleEnd-angleStart)/2.0;
1332 if(fabs(halfAngle)>1e-8)
1333 {
1334 a=4.0/3.0*(1-cos(halfAngle))/sin(halfAngle);
1335 xNorm[0]=cos(angleStart);
1336 yNorm[0]=sin(angleStart);
1337 xNorm[1]=xNorm[0] - a*yNorm[0];
1338 yNorm[1]=yNorm[0] + a*xNorm[0];
1339 xNorm[3]=cos(angleEnd);
1340 yNorm[3]=sin(angleEnd);
1341 xNorm[2]=xNorm[3] + a*yNorm[3];
1342 yNorm[2]=yNorm[3] - a*xNorm[3];
1343 } else
1344 for(i=0; i<4; i++)
1345 {
1346 xNorm[i]=cos(angleStart);
1347 yNorm[i]=sin(angleStart);
1348 }
1349
1350 /* Add starting point to path if desired */
1351 if(startEntryType)
1352 {
1353 PATH_ScaleNormalizedPoint(corners, xNorm[0], yNorm[0], &point);
1354 if(!PATH_AddEntry(pPath, &point, startEntryType))
1355 return FALSE;
1356 }
1357
1358 /* Add remaining control points */
1359 for(i=1; i<4; i++)
1360 {
1361 PATH_ScaleNormalizedPoint(corners, xNorm[i], yNorm[i], &point);
1362 if(!PATH_AddEntry(pPath, &point, PT_BEZIERTO))
1363 return FALSE;
1364 }
1365
1366 return TRUE;
1367 }
1368
1369 /* PATH_ScaleNormalizedPoint
1370 *
1371 * Scales a normalized point (x, y) with respect to the box whose corners are
1372 * passed in "corners". The point is stored in "*pPoint". The normalized
1373 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1374 * (1.0, 1.0) correspond to corners[1].
1375 */
1376 VOID
1377 FASTCALL
1378 PATH_ScaleNormalizedPoint ( FLOAT_POINT corners[], double x,
1379 double y, POINT *pPoint )
1380 {
1381 ASSERT ( corners );
1382 ASSERT ( pPoint );
1383 pPoint->x=GDI_ROUND( (double)corners[0].x + (double)(corners[1].x-corners[0].x)*0.5*(x+1.0) );
1384 pPoint->y=GDI_ROUND( (double)corners[0].y + (double)(corners[1].y-corners[0].y)*0.5*(y+1.0) );
1385 }
1386
1387 /* PATH_NormalizePoint
1388 *
1389 * Normalizes a point with respect to the box whose corners are passed in
1390 * corners. The normalized coordinates are stored in *pX and *pY.
1391 */
1392 VOID
1393 FASTCALL
1394 PATH_NormalizePoint ( FLOAT_POINT corners[],
1395 const FLOAT_POINT *pPoint,
1396 double *pX, double *pY)
1397 {
1398 ASSERT ( corners );
1399 ASSERT ( pPoint );
1400 ASSERT ( pX );
1401 ASSERT ( pY );
1402 *pX=(double)(pPoint->x-corners[0].x)/(double)(corners[1].x-corners[0].x) * 2.0 - 1.0;
1403 *pY=(double)(pPoint->y-corners[0].y)/(double)(corners[1].y-corners[0].y) * 2.0 - 1.0;
1404 }
1405
1406
1407 BOOL FASTCALL PATH_StrokePath(DC *dc, PPATH pPath)
1408 {
1409 BOOL ret = FALSE;
1410 INT i=0;
1411 INT nLinePts, nAlloc;
1412 POINT *pLinePts = NULL;
1413 POINT ptViewportOrg, ptWindowOrg;
1414 SIZE szViewportExt, szWindowExt;
1415 DWORD mapMode, graphicsMode;
1416 XFORM xform;
1417 PDC_ATTR pdcattr = dc->pdcattr;
1418
1419 DPRINT("Enter %s\n", __FUNCTION__);
1420
1421 if (pPath->state != PATH_Closed)
1422 return FALSE;
1423
1424 /* Save the mapping mode info */
1425 mapMode = pdcattr->iMapMode;
1426
1427 szViewportExt = *DC_pszlViewportExt(dc);
1428 ptViewportOrg = dc->pdcattr->ptlViewportOrg;
1429 szWindowExt = dc->pdcattr->szlWindowExt;
1430 ptWindowOrg = dc->pdcattr->ptlWindowOrg;
1431
1432 MatrixS2XForm(&xform, &dc->dclevel.mxWorldToPage);
1433
1434 /* Set MM_TEXT */
1435 pdcattr->iMapMode = MM_TEXT;
1436 pdcattr->ptlViewportOrg.x = 0;
1437 pdcattr->ptlViewportOrg.y = 0;
1438 pdcattr->ptlWindowOrg.x = 0;
1439 pdcattr->ptlWindowOrg.y = 0;
1440 graphicsMode = pdcattr->iGraphicsMode;
1441 pdcattr->iGraphicsMode = GM_ADVANCED;
1442 GreModifyWorldTransform(dc, (XFORML*)&xform, MWT_IDENTITY);
1443 pdcattr->iGraphicsMode = graphicsMode;
1444
1445 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1446 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1447 * space in case we get one to keep the number of reallocations small. */
1448 nAlloc = pPath->numEntriesUsed + 1 + 300;
1449 pLinePts = ExAllocatePoolWithTag(PagedPool, nAlloc * sizeof(POINT), TAG_PATH);
1450 if(!pLinePts)
1451 {
1452 DPRINT1("Can't allocate pool!\n");
1453 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
1454 goto end;
1455 }
1456 nLinePts = 0;
1457
1458 for(i = 0; i < pPath->numEntriesUsed; i++)
1459 {
1460 if((i == 0 || (pPath->pFlags[i-1] & PT_CLOSEFIGURE))
1461 && (pPath->pFlags[i] != PT_MOVETO))
1462 {
1463 DPRINT1("Expected PT_MOVETO %s, got path flag %d\n",
1464 i == 0 ? "as first point" : "after PT_CLOSEFIGURE",
1465 (INT)pPath->pFlags[i]);
1466 goto end;
1467 }
1468
1469 switch(pPath->pFlags[i])
1470 {
1471 case PT_MOVETO:
1472 DPRINT("Got PT_MOVETO (%ld, %ld)\n",
1473 pPath->pPoints[i].x, pPath->pPoints[i].y);
1474 if(nLinePts >= 2) IntGdiPolyline(dc, pLinePts, nLinePts);
1475 nLinePts = 0;
1476 pLinePts[nLinePts++] = pPath->pPoints[i];
1477 break;
1478 case PT_LINETO:
1479 case (PT_LINETO | PT_CLOSEFIGURE):
1480 DPRINT("Got PT_LINETO (%ld, %ld)\n",
1481 pPath->pPoints[i].x, pPath->pPoints[i].y);
1482 pLinePts[nLinePts++] = pPath->pPoints[i];
1483 break;
1484 case PT_BEZIERTO:
1485 DPRINT("Got PT_BEZIERTO\n");
1486 if(pPath->pFlags[i+1] != PT_BEZIERTO ||
1487 (pPath->pFlags[i+2] & ~PT_CLOSEFIGURE) != PT_BEZIERTO)
1488 {
1489 DPRINT1("Path didn't contain 3 successive PT_BEZIERTOs\n");
1490 ret = FALSE;
1491 goto end;
1492 }
1493 else
1494 {
1495 INT nBzrPts, nMinAlloc;
1496 POINT *pBzrPts = GDI_Bezier(&pPath->pPoints[i-1], 4, &nBzrPts);
1497 /* Make sure we have allocated enough memory for the lines of
1498 * this bezier and the rest of the path, assuming we won't get
1499 * another one (since we won't reallocate again then). */
1500 nMinAlloc = nLinePts + (pPath->numEntriesUsed - i) + nBzrPts;
1501 if(nAlloc < nMinAlloc)
1502 {
1503 // Reallocate memory
1504
1505 POINT *Realloc = NULL;
1506 nAlloc = nMinAlloc * 2;
1507
1508 Realloc = ExAllocatePoolWithTag(PagedPool,
1509 nAlloc * sizeof(POINT),
1510 TAG_PATH);
1511
1512 if(!Realloc)
1513 {
1514 DPRINT1("Can't allocate pool!\n");
1515 goto end;
1516 }
1517
1518 memcpy(Realloc, pLinePts, nLinePts*sizeof(POINT));
1519 ExFreePoolWithTag(pLinePts, TAG_PATH);
1520 pLinePts = Realloc;
1521 }
1522 memcpy(&pLinePts[nLinePts], &pBzrPts[1], (nBzrPts - 1) * sizeof(POINT));
1523 nLinePts += nBzrPts - 1;
1524 ExFreePoolWithTag(pBzrPts, TAG_BEZIER);
1525 i += 2;
1526 }
1527 break;
1528 default:
1529 DPRINT1("Got path flag %d (not supported)\n", (INT)pPath->pFlags[i]);
1530 goto end;
1531 }
1532
1533 if(pPath->pFlags[i] & PT_CLOSEFIGURE)
1534 {
1535 pLinePts[nLinePts++] = pLinePts[0];
1536 }
1537 }
1538 if(nLinePts >= 2)
1539 IntGdiPolyline(dc, pLinePts, nLinePts);
1540
1541 ret = TRUE;
1542
1543 end:
1544 if(pLinePts) ExFreePoolWithTag(pLinePts, TAG_PATH);
1545
1546 /* Restore the old mapping mode */
1547 pdcattr->iMapMode = mapMode;
1548 pdcattr->szlWindowExt.cx = szWindowExt.cx;
1549 pdcattr->szlWindowExt.cy = szWindowExt.cy;
1550 pdcattr->ptlWindowOrg.x = ptWindowOrg.x;
1551 pdcattr->ptlWindowOrg.y = ptWindowOrg.y;
1552
1553 pdcattr->szlViewportExt.cx = szViewportExt.cx;
1554 pdcattr->szlViewportExt.cy = szViewportExt.cy;
1555 pdcattr->ptlViewportOrg.x = ptViewportOrg.x;
1556 pdcattr->ptlViewportOrg.y = ptViewportOrg.y;
1557
1558 /* Restore the world transform */
1559 XForm2MatrixS(&dc->dclevel.mxWorldToPage, &xform);
1560
1561 /* If we've moved the current point then get its new position
1562 which will be in device (MM_TEXT) co-ords, convert it to
1563 logical co-ords and re-set it. This basically updates
1564 dc->CurPosX|Y so that their values are in the correct mapping
1565 mode.
1566 */
1567 if(i > 0)
1568 {
1569 POINT pt;
1570 IntGetCurrentPositionEx(dc, &pt);
1571 IntDPtoLP(dc, &pt, 1);
1572 IntGdiMoveToEx(dc, pt.x, pt.y, NULL, FALSE);
1573 }
1574 DPRINT("Leave %s, ret=%d\n", __FUNCTION__, ret);
1575 return ret;
1576 }
1577
1578 #define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1579
1580 static
1581 BOOL
1582 FASTCALL
1583 PATH_WidenPath(DC *dc)
1584 {
1585 INT i, j, numStrokes, numOldStrokes, penWidth, penWidthIn, penWidthOut, size, penStyle;
1586 BOOL ret = FALSE;
1587 PPATH pPath, pNewPath, *pStrokes = NULL, *pOldStrokes, pUpPath, pDownPath;
1588 EXTLOGPEN *elp;
1589 DWORD obj_type, joint, endcap, penType;
1590 PDC_ATTR pdcattr = dc->pdcattr;
1591
1592 pPath = PATH_LockPath( dc->dclevel.hPath );
1593 if (!pPath) return FALSE;
1594
1595 if(pPath->state == PATH_Open)
1596 {
1597 PATH_UnlockPath( pPath );
1598 EngSetLastError(ERROR_CAN_NOT_COMPLETE);
1599 return FALSE;
1600 }
1601
1602 PATH_FlattenPath(pPath);
1603
1604 size = GreGetObject( pdcattr->hpen, 0, NULL);
1605 if (!size)
1606 {
1607 PATH_UnlockPath( pPath );
1608 EngSetLastError(ERROR_CAN_NOT_COMPLETE);
1609 return FALSE;
1610 }
1611
1612 elp = ExAllocatePoolWithTag(PagedPool, size, TAG_PATH);
1613 GreGetObject(pdcattr->hpen, size, elp);
1614
1615 obj_type = GDI_HANDLE_GET_TYPE(pdcattr->hpen);
1616 if(obj_type == GDI_OBJECT_TYPE_PEN)
1617 {
1618 penStyle = ((LOGPEN*)elp)->lopnStyle;
1619 }
1620 else if(obj_type == GDI_OBJECT_TYPE_EXTPEN)
1621 {
1622 penStyle = elp->elpPenStyle;
1623 }
1624 else
1625 {
1626 EngSetLastError(ERROR_CAN_NOT_COMPLETE);
1627 ExFreePoolWithTag(elp, TAG_PATH);
1628 PATH_UnlockPath( pPath );
1629 return FALSE;
1630 }
1631
1632 penWidth = elp->elpWidth;
1633 ExFreePoolWithTag(elp, TAG_PATH);
1634
1635 endcap = (PS_ENDCAP_MASK & penStyle);
1636 joint = (PS_JOIN_MASK & penStyle);
1637 penType = (PS_TYPE_MASK & penStyle);
1638
1639 /* The function cannot apply to cosmetic pens */
1640 if(obj_type == GDI_OBJECT_TYPE_EXTPEN && penType == PS_COSMETIC)
1641 {
1642 PATH_UnlockPath( pPath );
1643 EngSetLastError(ERROR_CAN_NOT_COMPLETE);
1644 return FALSE;
1645 }
1646
1647 penWidthIn = penWidth / 2;
1648 penWidthOut = penWidth / 2;
1649 if(penWidthIn + penWidthOut < penWidth)
1650 penWidthOut++;
1651
1652 numStrokes = 0;
1653
1654 for(i = 0, j = 0; i < pPath->numEntriesUsed; i++, j++)
1655 {
1656 POINT point;
1657 if((i == 0 || (pPath->pFlags[i-1] & PT_CLOSEFIGURE)) &&
1658 (pPath->pFlags[i] != PT_MOVETO))
1659 {
1660 DPRINT1("Expected PT_MOVETO %s, got path flag %c\n",
1661 i == 0 ? "as first point" : "after PT_CLOSEFIGURE",
1662 pPath->pFlags[i]);
1663 return FALSE;
1664 }
1665 switch(pPath->pFlags[i])
1666 {
1667 case PT_MOVETO:
1668 if(numStrokes > 0)
1669 {
1670 pStrokes[numStrokes - 1]->state = PATH_Closed;
1671 }
1672 numOldStrokes = numStrokes;
1673 numStrokes++;
1674 j = 0;
1675 if (numStrokes == 1)
1676 pStrokes = ExAllocatePoolWithTag(PagedPool, numStrokes * sizeof(PPATH), TAG_PATH);
1677 else
1678 {
1679 pOldStrokes = pStrokes; // Save old pointer.
1680 pStrokes = ExAllocatePoolWithTag(PagedPool, numStrokes * sizeof(PPATH), TAG_PATH);
1681 if (!pStrokes) return FALSE;
1682 RtlCopyMemory(pStrokes, pOldStrokes, numOldStrokes * sizeof(PPATH));
1683 ExFreePoolWithTag(pOldStrokes, TAG_PATH); // Free old pointer.
1684 }
1685 if (!pStrokes) return FALSE;
1686 pStrokes[numStrokes - 1] = ExAllocatePoolWithTag(PagedPool, sizeof(PATH), TAG_PATH);
1687
1688 PATH_InitGdiPath(pStrokes[numStrokes - 1]);
1689 pStrokes[numStrokes - 1]->state = PATH_Open;
1690 case PT_LINETO:
1691 case (PT_LINETO | PT_CLOSEFIGURE):
1692 point.x = pPath->pPoints[i].x;
1693 point.y = pPath->pPoints[i].y;
1694 PATH_AddEntry(pStrokes[numStrokes - 1], &point, pPath->pFlags[i]);
1695 break;
1696 case PT_BEZIERTO:
1697 /* Should never happen because of the FlattenPath call */
1698 DPRINT1("Should never happen\n");
1699 break;
1700 default:
1701 DPRINT1("Got path flag %c\n", pPath->pFlags[i]);
1702 return FALSE;
1703 }
1704 }
1705
1706 pNewPath = ExAllocatePoolWithTag(PagedPool, sizeof(PATH), TAG_PATH);
1707 PATH_InitGdiPath(pNewPath);
1708 pNewPath->state = PATH_Open;
1709
1710 for(i = 0; i < numStrokes; i++)
1711 {
1712 pUpPath = ExAllocatePoolWithTag(PagedPool, sizeof(PATH), TAG_PATH);
1713 PATH_InitGdiPath(pUpPath);
1714 pUpPath->state = PATH_Open;
1715 pDownPath = ExAllocatePoolWithTag(PagedPool, sizeof(PATH), TAG_PATH);
1716 PATH_InitGdiPath(pDownPath);
1717 pDownPath->state = PATH_Open;
1718
1719 for(j = 0; j < pStrokes[i]->numEntriesUsed; j++)
1720 {
1721 /* Beginning or end of the path if not closed */
1722 if((!(pStrokes[i]->pFlags[pStrokes[i]->numEntriesUsed - 1] & PT_CLOSEFIGURE)) && (j == 0 || j == pStrokes[i]->numEntriesUsed - 1) )
1723 {
1724 /* Compute segment angle */
1725 double xo, yo, xa, ya, theta;
1726 POINT pt;
1727 FLOAT_POINT corners[2];
1728 if(j == 0)
1729 {
1730 xo = pStrokes[i]->pPoints[j].x;
1731 yo = pStrokes[i]->pPoints[j].y;
1732 xa = pStrokes[i]->pPoints[1].x;
1733 ya = pStrokes[i]->pPoints[1].y;
1734 }
1735 else
1736 {
1737 xa = pStrokes[i]->pPoints[j - 1].x;
1738 ya = pStrokes[i]->pPoints[j - 1].y;
1739 xo = pStrokes[i]->pPoints[j].x;
1740 yo = pStrokes[i]->pPoints[j].y;
1741 }
1742 theta = atan2( ya - yo, xa - xo );
1743 switch(endcap)
1744 {
1745 case PS_ENDCAP_SQUARE :
1746 pt.x = xo + round(sqrt(2) * penWidthOut * cos(M_PI_4 + theta));
1747 pt.y = yo + round(sqrt(2) * penWidthOut * sin(M_PI_4 + theta));
1748 PATH_AddEntry(pUpPath, &pt, (j == 0 ? PT_MOVETO : PT_LINETO) );
1749 pt.x = xo + round(sqrt(2) * penWidthIn * cos(- M_PI_4 + theta));
1750 pt.y = yo + round(sqrt(2) * penWidthIn * sin(- M_PI_4 + theta));
1751 PATH_AddEntry(pUpPath, &pt, PT_LINETO);
1752 break;
1753 case PS_ENDCAP_FLAT :
1754 pt.x = xo + round( penWidthOut * cos(theta + M_PI_2) );
1755 pt.y = yo + round( penWidthOut * sin(theta + M_PI_2) );
1756 PATH_AddEntry(pUpPath, &pt, (j == 0 ? PT_MOVETO : PT_LINETO));
1757 pt.x = xo - round( penWidthIn * cos(theta + M_PI_2) );
1758 pt.y = yo - round( penWidthIn * sin(theta + M_PI_2) );
1759 PATH_AddEntry(pUpPath, &pt, PT_LINETO);
1760 break;
1761 case PS_ENDCAP_ROUND :
1762 default :
1763 corners[0].x = xo - penWidthIn;
1764 corners[0].y = yo - penWidthIn;
1765 corners[1].x = xo + penWidthOut;
1766 corners[1].y = yo + penWidthOut;
1767 PATH_DoArcPart(pUpPath ,corners, theta + M_PI_2 , theta + 3 * M_PI_4, (j == 0 ? PT_MOVETO : FALSE));
1768 PATH_DoArcPart(pUpPath ,corners, theta + 3 * M_PI_4 , theta + M_PI, FALSE);
1769 PATH_DoArcPart(pUpPath ,corners, theta + M_PI, theta + 5 * M_PI_4, FALSE);
1770 PATH_DoArcPart(pUpPath ,corners, theta + 5 * M_PI_4 , theta + 3 * M_PI_2, FALSE);
1771 break;
1772 }
1773 }
1774 /* Corpse of the path */
1775 else
1776 {
1777 /* Compute angle */
1778 INT previous, next;
1779 double xa, ya, xb, yb, xo, yo;
1780 double alpha, theta, miterWidth;
1781 DWORD _joint = joint;
1782 POINT pt;
1783 PPATH pInsidePath, pOutsidePath;
1784 if(j > 0 && j < pStrokes[i]->numEntriesUsed - 1)
1785 {
1786 previous = j - 1;
1787 next = j + 1;
1788 }
1789 else if (j == 0)
1790 {
1791 previous = pStrokes[i]->numEntriesUsed - 1;
1792 next = j + 1;
1793 }
1794 else
1795 {
1796 previous = j - 1;
1797 next = 0;
1798 }
1799 xo = pStrokes[i]->pPoints[j].x;
1800 yo = pStrokes[i]->pPoints[j].y;
1801 xa = pStrokes[i]->pPoints[previous].x;
1802 ya = pStrokes[i]->pPoints[previous].y;
1803 xb = pStrokes[i]->pPoints[next].x;
1804 yb = pStrokes[i]->pPoints[next].y;
1805 theta = atan2( yo - ya, xo - xa );
1806 alpha = atan2( yb - yo, xb - xo ) - theta;
1807 if (alpha > 0) alpha -= M_PI;
1808 else alpha += M_PI;
1809 if(_joint == PS_JOIN_MITER && dc->dclevel.laPath.eMiterLimit < fabs(1 / sin(alpha/2)))
1810 {
1811 _joint = PS_JOIN_BEVEL;
1812 }
1813 if(alpha > 0)
1814 {
1815 pInsidePath = pUpPath;
1816 pOutsidePath = pDownPath;
1817 }
1818 else if(alpha < 0)
1819 {
1820 pInsidePath = pDownPath;
1821 pOutsidePath = pUpPath;
1822 }
1823 else
1824 {
1825 continue;
1826 }
1827 /* Inside angle points */
1828 if(alpha > 0)
1829 {
1830 pt.x = xo - round( penWidthIn * cos(theta + M_PI_2) );
1831 pt.y = yo - round( penWidthIn * sin(theta + M_PI_2) );
1832 }
1833 else
1834 {
1835 pt.x = xo + round( penWidthIn * cos(theta + M_PI_2) );
1836 pt.y = yo + round( penWidthIn * sin(theta + M_PI_2) );
1837 }
1838 PATH_AddEntry(pInsidePath, &pt, PT_LINETO);
1839 if(alpha > 0)
1840 {
1841 pt.x = xo + round( penWidthIn * cos(M_PI_2 + alpha + theta) );
1842 pt.y = yo + round( penWidthIn * sin(M_PI_2 + alpha + theta) );
1843 }
1844 else
1845 {
1846 pt.x = xo - round( penWidthIn * cos(M_PI_2 + alpha + theta) );
1847 pt.y = yo - round( penWidthIn * sin(M_PI_2 + alpha + theta) );
1848 }
1849 PATH_AddEntry(pInsidePath, &pt, PT_LINETO);
1850 /* Outside angle point */
1851 switch(_joint)
1852 {
1853 case PS_JOIN_MITER :
1854 miterWidth = fabs(penWidthOut / cos(M_PI_2 - fabs(alpha) / 2));
1855 pt.x = xo + round( miterWidth * cos(theta + alpha / 2) );
1856 pt.y = yo + round( miterWidth * sin(theta + alpha / 2) );
1857 PATH_AddEntry(pOutsidePath, &pt, PT_LINETO);
1858 break;
1859 case PS_JOIN_BEVEL :
1860 if(alpha > 0)
1861 {
1862 pt.x = xo + round( penWidthOut * cos(theta + M_PI_2) );
1863 pt.y = yo + round( penWidthOut * sin(theta + M_PI_2) );
1864 }
1865 else
1866 {
1867 pt.x = xo - round( penWidthOut * cos(theta + M_PI_2) );
1868 pt.y = yo - round( penWidthOut * sin(theta + M_PI_2) );
1869 }
1870 PATH_AddEntry(pOutsidePath, &pt, PT_LINETO);
1871 if(alpha > 0)
1872 {
1873 pt.x = xo - round( penWidthOut * cos(M_PI_2 + alpha + theta) );
1874 pt.y = yo - round( penWidthOut * sin(M_PI_2 + alpha + theta) );
1875 }
1876 else
1877 {
1878 pt.x = xo + round( penWidthOut * cos(M_PI_2 + alpha + theta) );
1879 pt.y = yo + round( penWidthOut * sin(M_PI_2 + alpha + theta) );
1880 }
1881 PATH_AddEntry(pOutsidePath, &pt, PT_LINETO);
1882 break;
1883 case PS_JOIN_ROUND :
1884 default :
1885 if(alpha > 0)
1886 {
1887 pt.x = xo + round( penWidthOut * cos(theta + M_PI_2) );
1888 pt.y = yo + round( penWidthOut * sin(theta + M_PI_2) );
1889 }
1890 else
1891 {
1892 pt.x = xo - round( penWidthOut * cos(theta + M_PI_2) );
1893 pt.y = yo - round( penWidthOut * sin(theta + M_PI_2) );
1894 }
1895 PATH_AddEntry(pOutsidePath, &pt, PT_BEZIERTO);
1896 pt.x = xo + round( penWidthOut * cos(theta + alpha / 2) );
1897 pt.y = yo + round( penWidthOut * sin(theta + alpha / 2) );
1898 PATH_AddEntry(pOutsidePath, &pt, PT_BEZIERTO);
1899 if(alpha > 0)
1900 {
1901 pt.x = xo - round( penWidthOut * cos(M_PI_2 + alpha + theta) );
1902 pt.y = yo - round( penWidthOut * sin(M_PI_2 + alpha + theta) );
1903 }
1904 else
1905 {
1906 pt.x = xo + round( penWidthOut * cos(M_PI_2 + alpha + theta) );
1907 pt.y = yo + round( penWidthOut * sin(M_PI_2 + alpha + theta) );
1908 }
1909 PATH_AddEntry(pOutsidePath, &pt, PT_BEZIERTO);
1910 break;
1911 }
1912 }
1913 }
1914 for(j = 0; j < pUpPath->numEntriesUsed; j++)
1915 {
1916 POINT pt;
1917 pt.x = pUpPath->pPoints[j].x;
1918 pt.y = pUpPath->pPoints[j].y;
1919 PATH_AddEntry(pNewPath, &pt, (j == 0 ? PT_MOVETO : PT_LINETO));
1920 }
1921 for(j = 0; j < pDownPath->numEntriesUsed; j++)
1922 {
1923 POINT pt;
1924 pt.x = pDownPath->pPoints[pDownPath->numEntriesUsed - j - 1].x;
1925 pt.y = pDownPath->pPoints[pDownPath->numEntriesUsed - j - 1].y;
1926 PATH_AddEntry(pNewPath, &pt, ( (j == 0 && (pStrokes[i]->pFlags[pStrokes[i]->numEntriesUsed - 1] & PT_CLOSEFIGURE)) ? PT_MOVETO : PT_LINETO));
1927 }
1928
1929 PATH_DestroyGdiPath(pStrokes[i]);
1930 ExFreePoolWithTag(pStrokes[i], TAG_PATH);
1931 PATH_DestroyGdiPath(pUpPath);
1932 ExFreePoolWithTag(pUpPath, TAG_PATH);
1933 PATH_DestroyGdiPath(pDownPath);
1934 ExFreePoolWithTag(pDownPath, TAG_PATH);
1935 }
1936 if (pStrokes) ExFreePoolWithTag(pStrokes, TAG_PATH);
1937
1938 pNewPath->state = PATH_Closed;
1939 if (!(ret = PATH_AssignGdiPath(pPath, pNewPath)))
1940 DPRINT1("Assign path failed\n");
1941 PATH_DestroyGdiPath(pNewPath);
1942 ExFreePoolWithTag(pNewPath, TAG_PATH);
1943 PATH_UnlockPath(pPath);
1944 return ret;
1945 }
1946
1947 static inline INT int_from_fixed(FIXED f)
1948 {
1949 return (f.fract >= 0x8000) ? (f.value + 1) : f.value;
1950 }
1951
1952 /**********************************************************************
1953 * PATH_BezierTo
1954 *
1955 * Internally used by PATH_add_outline
1956 */
1957 static
1958 VOID
1959 FASTCALL
1960 PATH_BezierTo(PPATH pPath, POINT *lppt, INT n)
1961 {
1962 if (n < 2) return;
1963
1964 if (n == 2)
1965 {
1966 PATH_AddEntry(pPath, &lppt[1], PT_LINETO);
1967 }
1968 else if (n == 3)
1969 {
1970 PATH_AddEntry(pPath, &lppt[0], PT_BEZIERTO);
1971 PATH_AddEntry(pPath, &lppt[1], PT_BEZIERTO);
1972 PATH_AddEntry(pPath, &lppt[2], PT_BEZIERTO);
1973 }
1974 else
1975 {
1976 POINT pt[3];
1977 INT i = 0;
1978
1979 pt[2] = lppt[0];
1980 n--;
1981
1982 while (n > 2)
1983 {
1984 pt[0] = pt[2];
1985 pt[1] = lppt[i+1];
1986 pt[2].x = (lppt[i+2].x + lppt[i+1].x) / 2;
1987 pt[2].y = (lppt[i+2].y + lppt[i+1].y) / 2;
1988 PATH_BezierTo(pPath, pt, 3);
1989 n--;
1990 i++;
1991 }
1992
1993 pt[0] = pt[2];
1994 pt[1] = lppt[i+1];
1995 pt[2] = lppt[i+2];
1996 PATH_BezierTo(pPath, pt, 3);
1997 }
1998 }
1999
2000 static
2001 BOOL
2002 FASTCALL
2003 PATH_add_outline(PDC dc, INT x, INT y, TTPOLYGONHEADER *header, DWORD size)
2004 {
2005 PPATH pPath;
2006 TTPOLYGONHEADER *start;
2007 POINT pt;
2008
2009 start = header;
2010
2011 pPath = PATH_LockPath(dc->dclevel.hPath);
2012 {
2013 return FALSE;
2014 }
2015
2016 while ((char *)header < (char *)start + size)
2017 {
2018 TTPOLYCURVE *curve;
2019
2020 if (header->dwType != TT_POLYGON_TYPE)
2021 {
2022 DPRINT1("Unknown header type %d\n", header->dwType);
2023 return FALSE;
2024 }
2025
2026 pt.x = x + int_from_fixed(header->pfxStart.x);
2027 pt.y = y - int_from_fixed(header->pfxStart.y);
2028 PATH_AddEntry(pPath, &pt, PT_MOVETO);
2029
2030 curve = (TTPOLYCURVE *)(header + 1);
2031
2032 while ((char *)curve < (char *)header + header->cb)
2033 {
2034 /*DPRINT1("curve->wType %d\n", curve->wType);*/
2035
2036 switch(curve->wType)
2037 {
2038 case TT_PRIM_LINE:
2039 {
2040 WORD i;
2041
2042 for (i = 0; i < curve->cpfx; i++)
2043 {
2044 pt.x = x + int_from_fixed(curve->apfx[i].x);
2045 pt.y = y - int_from_fixed(curve->apfx[i].y);
2046 PATH_AddEntry(pPath, &pt, PT_LINETO);
2047 }
2048 break;
2049 }
2050
2051 case TT_PRIM_QSPLINE:
2052 case TT_PRIM_CSPLINE:
2053 {
2054 WORD i;
2055 POINTFX ptfx;
2056 POINT *pts = ExAllocatePoolWithTag(PagedPool, (curve->cpfx + 1) * sizeof(POINT), TAG_PATH);
2057
2058 if (!pts) return FALSE;
2059
2060 ptfx = *(POINTFX *)((char *)curve - sizeof(POINTFX));
2061
2062 pts[0].x = x + int_from_fixed(ptfx.x);
2063 pts[0].y = y - int_from_fixed(ptfx.y);
2064
2065 for (i = 0; i < curve->cpfx; i++)
2066 {
2067 pts[i + 1].x = x + int_from_fixed(curve->apfx[i].x);
2068 pts[i + 1].y = y - int_from_fixed(curve->apfx[i].y);
2069 }
2070
2071 PATH_BezierTo(pPath, pts, curve->cpfx + 1);
2072
2073 ExFreePoolWithTag(pts, TAG_PATH);
2074 break;
2075 }
2076
2077 default:
2078 DPRINT1("Unknown curve type %04x\n", curve->wType);
2079 return FALSE;
2080 }
2081
2082 curve = (TTPOLYCURVE *)&curve->apfx[curve->cpfx];
2083 }
2084 header = (TTPOLYGONHEADER *)((char *)header + header->cb);
2085 }
2086
2087 IntGdiCloseFigure( pPath );
2088 PATH_UnlockPath( pPath );
2089 return TRUE;
2090 }
2091
2092 /**********************************************************************
2093 * PATH_ExtTextOut
2094 */
2095 BOOL
2096 FASTCALL
2097 PATH_ExtTextOut(PDC dc, INT x, INT y, UINT flags, const RECTL *lprc,
2098 LPCWSTR str, UINT count, const INT *dx)
2099 {
2100 unsigned int idx;
2101 POINT offset = {0, 0};
2102
2103 if (!count) return TRUE;
2104
2105 for (idx = 0; idx < count; idx++)
2106 {
2107 MAT2 identity = { {0,1},{0,0},{0,0},{0,1} };
2108 GLYPHMETRICS gm;
2109 DWORD dwSize;
2110 void *outline;
2111
2112 dwSize = ftGdiGetGlyphOutline( dc,
2113 str[idx],
2114 GGO_GLYPH_INDEX | GGO_NATIVE,
2115 &gm,
2116 0,
2117 NULL,
2118 &identity,
2119 TRUE);
2120 if (dwSize == GDI_ERROR) return FALSE;
2121
2122 /* Add outline only if char is printable */
2123 if (dwSize)
2124 {
2125 outline = ExAllocatePoolWithTag(PagedPool, dwSize, TAG_PATH);
2126 if (!outline) return FALSE;
2127
2128 ftGdiGetGlyphOutline( dc,
2129 str[idx],
2130 GGO_GLYPH_INDEX | GGO_NATIVE,
2131 &gm,
2132 dwSize,
2133 outline,
2134 &identity,
2135 TRUE);
2136
2137 PATH_add_outline(dc, x + offset.x, y + offset.y, outline, dwSize);
2138
2139 ExFreePoolWithTag(outline, TAG_PATH);
2140 }
2141
2142 if (dx)
2143 {
2144 if (flags & ETO_PDY)
2145 {
2146 offset.x += dx[idx * 2];
2147 offset.y += dx[idx * 2 + 1];
2148 }
2149 else
2150 offset.x += dx[idx];
2151 }
2152 else
2153 {
2154 offset.x += gm.gmCellIncX;
2155 offset.y += gm.gmCellIncY;
2156 }
2157 }
2158 return TRUE;
2159 }
2160
2161
2162 /***********************************************************************
2163 * Exported functions
2164 */
2165
2166 BOOL
2167 APIENTRY
2168 NtGdiAbortPath(HDC hDC)
2169 {
2170 PPATH pPath;
2171 PDC dc = DC_LockDc ( hDC );
2172 if ( !dc )
2173 {
2174 EngSetLastError(ERROR_INVALID_HANDLE);
2175 return FALSE;
2176 }
2177
2178 pPath = PATH_LockPath(dc->dclevel.hPath);
2179 if (!pPath)
2180 {
2181 DC_UnlockDc(dc);
2182 return FALSE;
2183 }
2184
2185 PATH_EmptyPath(pPath);
2186
2187 PATH_UnlockPath(pPath);
2188 dc->dclevel.flPath &= ~DCPATH_ACTIVE;
2189
2190 DC_UnlockDc ( dc );
2191 return TRUE;
2192 }
2193
2194 BOOL
2195 APIENTRY
2196 NtGdiBeginPath( HDC hDC )
2197 {
2198 PPATH pPath;
2199 PDC dc;
2200
2201 dc = DC_LockDc ( hDC );
2202 if ( !dc )
2203 {
2204 EngSetLastError(ERROR_INVALID_HANDLE);
2205 return FALSE;
2206 }
2207
2208 /* If path is already open, do nothing. Check if not Save DC state */
2209 if ((dc->dclevel.flPath & DCPATH_ACTIVE) && !(dc->dclevel.flPath & DCPATH_SAVE))
2210 {
2211 DC_UnlockDc ( dc );
2212 return TRUE;
2213 }
2214
2215 if ( dc->dclevel.hPath )
2216 {
2217 DPRINT("BeginPath 1 0x%x\n", dc->dclevel.hPath);
2218 if ( !(dc->dclevel.flPath & DCPATH_SAVE) )
2219 { // Remove previous handle.
2220 if (!PATH_Delete(dc->dclevel.hPath))
2221 {
2222 DC_UnlockDc ( dc );
2223 return FALSE;
2224 }
2225 }
2226 else
2227 { // Clear flags and Handle.
2228 dc->dclevel.flPath &= ~(DCPATH_SAVE|DCPATH_ACTIVE);
2229 dc->dclevel.hPath = NULL;
2230 }
2231 }
2232 pPath = PATH_AllocPathWithHandle();
2233 if (!pPath)
2234 {
2235 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
2236 return FALSE;
2237 }
2238 dc->dclevel.flPath |= DCPATH_ACTIVE; // Set active ASAP!
2239
2240 dc->dclevel.hPath = pPath->BaseObject.hHmgr;
2241
2242 DPRINT("BeginPath 2 h 0x%x p 0x%x\n", dc->dclevel.hPath, pPath);
2243 // Path handles are shared. Also due to recursion with in the same thread.
2244 GDIOBJ_vUnlockObject((POBJ)pPath); // Unlock
2245 pPath = PATH_LockPath(dc->dclevel.hPath); // Share Lock.
2246
2247 /* Make sure that path is empty */
2248 PATH_EmptyPath( pPath );
2249
2250 /* Initialize variables for new path */
2251 pPath->newStroke = TRUE;
2252 pPath->state = PATH_Open;
2253
2254 PATH_UnlockPath(pPath);
2255 DC_UnlockDc ( dc );
2256 return TRUE;
2257 }
2258
2259 BOOL
2260 APIENTRY
2261 NtGdiCloseFigure(HDC hDC)
2262 {
2263 BOOL Ret = FALSE; // Default to failure
2264 PDC pDc;
2265 PPATH pPath;
2266
2267 DPRINT("Enter %s\n", __FUNCTION__);
2268
2269 pDc = DC_LockDc(hDC);
2270 if (!pDc)
2271 {
2272 EngSetLastError(ERROR_INVALID_PARAMETER);
2273 return FALSE;
2274 }
2275 pPath = PATH_LockPath( pDc->dclevel.hPath );
2276 if (!pPath)
2277 {
2278 DC_UnlockDc(pDc);
2279 return FALSE;
2280 }
2281
2282 if (pPath->state==PATH_Open)
2283 {
2284 IntGdiCloseFigure(pPath);
2285 Ret = TRUE;
2286 }
2287 else
2288 {
2289 // FIXME: Check if lasterror is set correctly
2290 EngSetLastError(ERROR_CAN_NOT_COMPLETE);
2291 }
2292
2293 PATH_UnlockPath( pPath );
2294 DC_UnlockDc(pDc);
2295 return Ret;
2296 }
2297
2298 BOOL
2299 APIENTRY
2300 NtGdiEndPath(HDC hDC)
2301 {
2302 BOOL ret = TRUE;
2303 PPATH pPath;
2304 PDC dc = DC_LockDc ( hDC );
2305
2306 if ( !dc )
2307 {
2308 EngSetLastError(ERROR_INVALID_HANDLE);
2309 return FALSE;
2310 }
2311
2312 pPath = PATH_LockPath( dc->dclevel.hPath );
2313 if (!pPath)
2314 {
2315 DC_UnlockDc ( dc );
2316 return FALSE;
2317 }
2318 /* Check that path is currently being constructed */
2319 if ( (pPath->state != PATH_Open) || !(dc->dclevel.flPath & DCPATH_ACTIVE) )
2320 {
2321 DPRINT1("EndPath ERROR! 0x%x\n", dc->dclevel.hPath);
2322 EngSetLastError(ERROR_CAN_NOT_COMPLETE);
2323 ret = FALSE;
2324 }
2325 /* Set flag to indicate that path is finished */
2326 else
2327 {
2328 DPRINT("EndPath 0x%x\n", dc->dclevel.hPath);
2329 pPath->state = PATH_Closed;
2330 dc->dclevel.flPath &= ~DCPATH_ACTIVE;
2331 }
2332 PATH_UnlockPath( pPath );
2333 DC_UnlockDc ( dc );
2334 return ret;
2335 }
2336
2337 BOOL
2338 APIENTRY
2339 NtGdiFillPath(HDC hDC)
2340 {
2341 BOOL ret = FALSE;
2342 PPATH pPath;
2343 PDC_ATTR pdcattr;
2344 PDC dc;
2345
2346 dc = DC_LockDc(hDC);
2347 if (!dc)
2348 {
2349 EngSetLastError(ERROR_INVALID_PARAMETER);
2350 return FALSE;
2351 }
2352
2353 pPath = PATH_LockPath( dc->dclevel.hPath );
2354 if (!pPath)
2355 {
2356 DC_UnlockDc ( dc );
2357 return FALSE;
2358 }
2359
2360 DC_vPrepareDCsForBlit(dc, dc->rosdc.CombinedClip->rclBounds,
2361 NULL, dc->rosdc.CombinedClip->rclBounds);
2362
2363 pdcattr = dc->pdcattr;
2364
2365 if (pdcattr->ulDirty_ & (DIRTY_LINE | DC_PEN_DIRTY))
2366 DC_vUpdateLineBrush(dc);
2367
2368 if (pdcattr->ulDirty_ & (DIRTY_FILL | DC_BRUSH_DIRTY))
2369 DC_vUpdateFillBrush(dc);
2370
2371 ret = PATH_FillPath( dc, pPath );
2372 if ( ret )
2373 {
2374 /* FIXME: Should the path be emptied even if conversion
2375 failed? */
2376 PATH_EmptyPath( pPath );
2377 }
2378
2379 PATH_UnlockPath( pPath );
2380 DC_vFinishBlit(dc, NULL);
2381 DC_UnlockDc ( dc );
2382 return ret;
2383 }
2384
2385 BOOL
2386 APIENTRY
2387 NtGdiFlattenPath(HDC hDC)
2388 {
2389 BOOL Ret = FALSE;
2390 DC *pDc;
2391 PPATH pPath;
2392
2393 DPRINT("Enter %s\n", __FUNCTION__);
2394
2395 pDc = DC_LockDc(hDC);
2396 if (!pDc)
2397 {
2398 EngSetLastError(ERROR_INVALID_HANDLE);
2399 return FALSE;
2400 }
2401
2402 pPath = PATH_LockPath( pDc->dclevel.hPath );
2403 if (!pPath)
2404 {
2405 DC_UnlockDc ( pDc );
2406 return FALSE;
2407 }
2408 if (pPath->state == PATH_Open)
2409 Ret = PATH_FlattenPath(pPath);
2410
2411 PATH_UnlockPath( pPath );
2412 DC_UnlockDc(pDc);
2413 return Ret;
2414 }
2415
2416
2417 BOOL
2418 APIENTRY
2419 NtGdiGetMiterLimit(
2420 IN HDC hdc,
2421 OUT PDWORD pdwOut)
2422 {
2423 DC *pDc;
2424 gxf_long worker;
2425 NTSTATUS Status = STATUS_SUCCESS;
2426
2427 if (!(pDc = DC_LockDc(hdc)))
2428 {
2429 EngSetLastError(ERROR_INVALID_PARAMETER);
2430 return FALSE;
2431 }
2432
2433 worker.f = pDc->dclevel.laPath.eMiterLimit;
2434
2435 if (pdwOut)
2436 {
2437 _SEH2_TRY
2438 {
2439 ProbeForWrite(pdwOut,
2440 sizeof(DWORD),
2441 1);
2442 *pdwOut = worker.l;
2443 }
2444 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
2445 {
2446 Status = _SEH2_GetExceptionCode();
2447 }
2448 _SEH2_END;
2449 if (!NT_SUCCESS(Status))
2450 {
2451 SetLastNtError(Status);
2452 DC_UnlockDc(pDc);
2453 return FALSE;
2454 }
2455 }
2456
2457 DC_UnlockDc(pDc);
2458 return TRUE;
2459
2460 }
2461
2462 INT
2463 APIENTRY
2464 NtGdiGetPath(
2465 HDC hDC,
2466 LPPOINT Points,
2467 LPBYTE Types,
2468 INT nSize)
2469 {
2470 INT ret = -1;
2471 PPATH pPath;
2472
2473 DC *dc = DC_LockDc(hDC);
2474 if (!dc)
2475 {
2476 DPRINT1("Can't lock dc!\n");
2477 EngSetLastError(ERROR_INVALID_PARAMETER);
2478 return -1;
2479 }
2480
2481 pPath = PATH_LockPath( dc->dclevel.hPath );
2482 if (!pPath)
2483 {
2484 DC_UnlockDc ( dc );
2485 return -1;
2486 }
2487
2488 if (pPath->state != PATH_Closed)
2489 {
2490 EngSetLastError(ERROR_CAN_NOT_COMPLETE);
2491 goto done;
2492 }
2493
2494 if (nSize==0)
2495 {
2496 ret = pPath->numEntriesUsed;
2497 }
2498 else if(nSize<pPath->numEntriesUsed)
2499 {
2500 EngSetLastError(ERROR_INVALID_PARAMETER);
2501 goto done;
2502 }
2503 else
2504 {
2505 _SEH2_TRY
2506 {
2507 memcpy(Points, pPath->pPoints, sizeof(POINT)*pPath->numEntriesUsed);
2508 memcpy(Types, pPath->pFlags, sizeof(BYTE)*pPath->numEntriesUsed);
2509
2510 /* Convert the points to logical coordinates */
2511 if (!GdiPathDPtoLP(dc, Points, pPath->numEntriesUsed))
2512 {
2513 EngSetLastError(ERROR_ARITHMETIC_OVERFLOW);
2514 _SEH2_LEAVE;
2515 }
2516
2517 ret = pPath->numEntriesUsed;
2518 }
2519 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
2520 {
2521 SetLastNtError(_SEH2_GetExceptionCode());
2522 }
2523 _SEH2_END
2524 }
2525
2526 done:
2527 PATH_UnlockPath( pPath );
2528 DC_UnlockDc(dc);
2529 return ret;
2530 }
2531
2532 HRGN
2533 APIENTRY
2534 NtGdiPathToRegion(HDC hDC)
2535 {
2536 PPATH pPath;
2537 HRGN hrgnRval = 0;
2538 DC *pDc;
2539 PDC_ATTR pdcattr;
2540
2541 DPRINT("Enter %s\n", __FUNCTION__);
2542
2543 pDc = DC_LockDc(hDC);
2544 if (!pDc)
2545 {
2546 EngSetLastError(ERROR_INVALID_PARAMETER);
2547 return NULL;
2548 }
2549
2550 pdcattr = pDc->pdcattr;
2551
2552 pPath = PATH_LockPath( pDc->dclevel.hPath );
2553 if (!pPath)
2554 {
2555 DC_UnlockDc ( pDc );
2556 return NULL;
2557 }
2558
2559 if (pPath->state!=PATH_Closed)
2560 {
2561 // FIXME: Check that setlasterror is being called correctly
2562 EngSetLastError(ERROR_CAN_NOT_COMPLETE);
2563 }
2564 else
2565 {
2566 /* FIXME: Should we empty the path even if conversion failed? */
2567 if(PATH_PathToRegion(pPath, pdcattr->jFillMode, &hrgnRval))
2568 PATH_EmptyPath(pPath);
2569 }
2570
2571 PATH_UnlockPath( pPath );
2572 DC_UnlockDc(pDc);
2573 return hrgnRval;
2574 }
2575
2576 BOOL
2577 APIENTRY
2578 NtGdiSetMiterLimit(
2579 IN HDC hdc,
2580 IN DWORD dwNew,
2581 IN OUT OPTIONAL PDWORD pdwOut)
2582 {
2583 DC *pDc;
2584 gxf_long worker, worker1;
2585 NTSTATUS Status = STATUS_SUCCESS;
2586
2587 if (!(pDc = DC_LockDc(hdc)))
2588 {
2589 EngSetLastError(ERROR_INVALID_PARAMETER);
2590 return FALSE;
2591 }
2592
2593 worker.l = dwNew;
2594 worker1.f = pDc->dclevel.laPath.eMiterLimit;
2595 pDc->dclevel.laPath.eMiterLimit = worker.f;
2596
2597 if (pdwOut)
2598 {
2599 _SEH2_TRY
2600 {
2601 ProbeForWrite(pdwOut,
2602 sizeof(DWORD),
2603 1);
2604 *pdwOut = worker1.l;
2605 }
2606 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
2607 {
2608 Status = _SEH2_GetExceptionCode();
2609 }
2610 _SEH2_END;
2611 if (!NT_SUCCESS(Status))
2612 {
2613 SetLastNtError(Status);
2614 DC_UnlockDc(pDc);
2615 return FALSE;
2616 }
2617 }
2618
2619 DC_UnlockDc(pDc);
2620 return TRUE;
2621 }
2622
2623 BOOL
2624 APIENTRY
2625 NtGdiStrokeAndFillPath(HDC hDC)
2626 {
2627 DC *pDc;
2628 PDC_ATTR pdcattr;
2629 PPATH pPath;
2630 BOOL bRet = FALSE;
2631
2632 DPRINT1("Enter %s\n", __FUNCTION__);
2633
2634 if (!(pDc = DC_LockDc(hDC)))
2635 {
2636 EngSetLastError(ERROR_INVALID_PARAMETER);
2637 return FALSE;
2638 }
2639 pPath = PATH_LockPath( pDc->dclevel.hPath );
2640 if (!pPath)
2641 {
2642 DC_UnlockDc ( pDc );
2643 return FALSE;
2644 }
2645
2646 DC_vPrepareDCsForBlit(pDc, pDc->rosdc.CombinedClip->rclBounds,
2647 NULL, pDc->rosdc.CombinedClip->rclBounds);
2648
2649 pdcattr = pDc->pdcattr;
2650
2651 if (pdcattr->ulDirty_ & (DIRTY_FILL | DC_BRUSH_DIRTY))
2652 DC_vUpdateFillBrush(pDc);
2653
2654 if (pdcattr->ulDirty_ & (DIRTY_LINE | DC_PEN_DIRTY))
2655 DC_vUpdateLineBrush(pDc);
2656
2657 bRet = PATH_FillPath(pDc, pPath);
2658 if (bRet) bRet = PATH_StrokePath(pDc, pPath);
2659 if (bRet) PATH_EmptyPath(pPath);
2660
2661 PATH_UnlockPath( pPath );
2662 DC_vFinishBlit(pDc, NULL);
2663 DC_UnlockDc(pDc);
2664 return bRet;
2665 }
2666
2667 BOOL
2668 APIENTRY
2669 NtGdiStrokePath(HDC hDC)
2670 {
2671 DC *pDc;
2672 PDC_ATTR pdcattr;
2673 PPATH pPath;
2674 BOOL bRet = FALSE;
2675
2676 DPRINT("Enter %s\n", __FUNCTION__);
2677
2678 if (!(pDc = DC_LockDc(hDC)))
2679 {
2680 EngSetLastError(ERROR_INVALID_PARAMETER);
2681 return FALSE;
2682 }
2683 pPath = PATH_LockPath( pDc->dclevel.hPath );
2684 if (!pPath)
2685 {
2686 DC_UnlockDc ( pDc );
2687 return FALSE;
2688 }
2689
2690 DC_vPrepareDCsForBlit(pDc, pDc->rosdc.CombinedClip->rclBounds,
2691 NULL, pDc->rosdc.CombinedClip->rclBounds);
2692
2693 pdcattr = pDc->pdcattr;
2694
2695 if (pdcattr->ulDirty_ & (DIRTY_LINE | DC_PEN_DIRTY))
2696 DC_vUpdateLineBrush(pDc);
2697
2698 bRet = PATH_StrokePath(pDc, pPath);
2699
2700 DC_vFinishBlit(pDc, NULL);
2701 PATH_EmptyPath(pPath);
2702
2703 PATH_UnlockPath( pPath );
2704 DC_UnlockDc(pDc);
2705 return bRet;
2706 }
2707
2708 BOOL
2709 APIENTRY
2710 NtGdiWidenPath(HDC hDC)
2711 {
2712 BOOL Ret;
2713 PDC pdc = DC_LockDc ( hDC );
2714 if ( !pdc )
2715 {
2716 EngSetLastError(ERROR_INVALID_PARAMETER);
2717 return FALSE;
2718 }
2719 Ret = PATH_WidenPath(pdc);
2720 DC_UnlockDc ( pdc );
2721 return Ret;
2722 }
2723
2724 /* EOF */