Fixed WM_GETTEXTLENGTH handling.
[wine/multimedia.git] / graphics / path.c
blob69f4b26d66406b962982ce7e605de51787e74688
1 /*
2 * Graphics paths (BeginPath, EndPath etc.)
4 * Copyright 1997, 1998 Martin Boehme
5 * 1999 Huw D M Davies
6 */
8 #include <assert.h>
9 #include <math.h>
10 #include <string.h>
11 #include "config.h"
12 #if defined(HAVE_FLOAT_H)
13 #include <float.h>
14 #endif
16 #include "winbase.h"
17 #include "wingdi.h"
18 #include "winerror.h"
20 #include "gdi.h"
21 #include "debugtools.h"
22 #include "path.h"
24 DEFAULT_DEBUG_CHANNEL(gdi);
26 /* Notes on the implementation
28 * The implementation is based on dynamically resizable arrays of points and
29 * flags. I dithered for a bit before deciding on this implementation, and
30 * I had even done a bit of work on a linked list version before switching
31 * to arrays. It's a bit of a tradeoff. When you use linked lists, the
32 * implementation of FlattenPath is easier, because you can rip the
33 * PT_BEZIERTO entries out of the middle of the list and link the
34 * corresponding PT_LINETO entries in. However, when you use arrays,
35 * PathToRegion becomes easier, since you can essentially just pass your array
36 * of points to CreatePolyPolygonRgn. Also, if I'd used linked lists, I would
37 * have had the extra effort of creating a chunk-based allocation scheme
38 * in order to use memory effectively. That's why I finally decided to use
39 * arrays. Note by the way that the array based implementation has the same
40 * linear time complexity that linked lists would have since the arrays grow
41 * exponentially.
43 * The points are stored in the path in device coordinates. This is
44 * consistent with the way Windows does things (for instance, see the Win32
45 * SDK documentation for GetPath).
47 * The word "stroke" appears in several places (e.g. in the flag
48 * GdiPath.newStroke). A stroke consists of a PT_MOVETO followed by one or
49 * more PT_LINETOs or PT_BEZIERTOs, up to, but not including, the next
50 * PT_MOVETO. Note that this is not the same as the definition of a figure;
51 * a figure can contain several strokes.
53 * I modified the drawing functions (MoveTo, LineTo etc.) to test whether
54 * the path is open and to call the corresponding function in path.c if this
55 * is the case. A more elegant approach would be to modify the function
56 * pointers in the DC_FUNCTIONS structure; however, this would be a lot more
57 * complex. Also, the performance degradation caused by my approach in the
58 * case where no path is open is so small that it cannot be measured.
60 * Martin Boehme
63 /* FIXME: A lot of stuff isn't implemented yet. There is much more to come. */
65 #define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
66 #define GROW_FACTOR_NUMER 2 /* Numerator of grow factor for the array */
67 #define GROW_FACTOR_DENOM 1 /* Denominator of grow factor */
70 static BOOL PATH_PathToRegion(GdiPath *pPath, INT nPolyFillMode,
71 HRGN *pHrgn);
72 static void PATH_EmptyPath(GdiPath *pPath);
73 static BOOL PATH_ReserveEntries(GdiPath *pPath, INT numEntries);
74 static BOOL PATH_DoArcPart(GdiPath *pPath, FLOAT_POINT corners[],
75 double angleStart, double angleEnd, BOOL addMoveTo);
76 static void PATH_ScaleNormalizedPoint(FLOAT_POINT corners[], double x,
77 double y, POINT *pPoint);
78 static void PATH_NormalizePoint(FLOAT_POINT corners[], const FLOAT_POINT
79 *pPoint, double *pX, double *pY);
80 static BOOL PATH_CheckCorners(DC *dc, POINT corners[], INT x1, INT y1, INT x2, INT y2);
83 /***********************************************************************
84 * BeginPath16 (GDI.512)
86 BOOL16 WINAPI BeginPath16(HDC16 hdc)
88 return (BOOL16)BeginPath((HDC)hdc);
92 /***********************************************************************
93 * BeginPath (GDI32.9)
95 BOOL WINAPI BeginPath(HDC hdc)
97 BOOL ret = TRUE;
98 DC *dc = DC_GetDCPtr( hdc );
100 if(!dc) return FALSE;
102 if(dc->funcs->pBeginPath)
103 ret = dc->funcs->pBeginPath(dc);
104 else
106 /* If path is already open, do nothing */
107 if(dc->path.state != PATH_Open)
109 /* Make sure that path is empty */
110 PATH_EmptyPath(&dc->path);
112 /* Initialize variables for new path */
113 dc->path.newStroke=TRUE;
114 dc->path.state=PATH_Open;
117 GDI_ReleaseObj( hdc );
118 return ret;
122 /***********************************************************************
123 * EndPath16 (GDI.514)
125 BOOL16 WINAPI EndPath16(HDC16 hdc)
127 return (BOOL16)EndPath((HDC)hdc);
131 /***********************************************************************
132 * EndPath (GDI32.78)
134 BOOL WINAPI EndPath(HDC hdc)
136 BOOL ret = TRUE;
137 DC *dc = DC_GetDCPtr( hdc );
139 if(!dc) return FALSE;
141 if(dc->funcs->pEndPath)
142 ret = dc->funcs->pEndPath(dc);
143 else
145 /* Check that path is currently being constructed */
146 if(dc->path.state!=PATH_Open)
148 SetLastError(ERROR_CAN_NOT_COMPLETE);
149 ret = FALSE;
151 /* Set flag to indicate that path is finished */
152 else dc->path.state=PATH_Closed;
154 GDI_ReleaseObj( hdc );
155 return ret;
159 /***********************************************************************
160 * AbortPath16 (GDI.511)
162 BOOL16 WINAPI AbortPath16(HDC16 hdc)
164 return (BOOL16)AbortPath((HDC)hdc);
168 /******************************************************************************
169 * AbortPath [GDI32.1]
170 * Closes and discards paths from device context
172 * NOTES
173 * Check that SetLastError is being called correctly
175 * PARAMS
176 * hdc [I] Handle to device context
178 * RETURNS STD
180 BOOL WINAPI AbortPath( HDC hdc )
182 BOOL ret = TRUE;
183 DC *dc = DC_GetDCPtr( hdc );
185 if(!dc) return FALSE;
187 if(dc->funcs->pAbortPath)
188 ret = dc->funcs->pAbortPath(dc);
189 else /* Remove all entries from the path */
190 PATH_EmptyPath( &dc->path );
191 GDI_ReleaseObj( hdc );
192 return ret;
196 /***********************************************************************
197 * CloseFigure16 (GDI.513)
199 BOOL16 WINAPI CloseFigure16(HDC16 hdc)
201 return (BOOL16)CloseFigure((HDC)hdc);
205 /***********************************************************************
206 * CloseFigure (GDI32.16)
208 * FIXME: Check that SetLastError is being called correctly
210 BOOL WINAPI CloseFigure(HDC hdc)
212 BOOL ret = TRUE;
213 DC *dc = DC_GetDCPtr( hdc );
215 if(!dc) return FALSE;
217 if(dc->funcs->pCloseFigure)
218 ret = dc->funcs->pCloseFigure(dc);
219 else
221 /* Check that path is open */
222 if(dc->path.state!=PATH_Open)
224 SetLastError(ERROR_CAN_NOT_COMPLETE);
225 ret = FALSE;
227 else
229 /* FIXME: Shouldn't we draw a line to the beginning of the
230 figure? */
231 /* Set PT_CLOSEFIGURE on the last entry and start a new stroke */
232 if(dc->path.numEntriesUsed)
234 dc->path.pFlags[dc->path.numEntriesUsed-1]|=PT_CLOSEFIGURE;
235 dc->path.newStroke=TRUE;
239 GDI_ReleaseObj( hdc );
240 return ret;
244 /***********************************************************************
245 * GetPath16 (GDI.517)
247 INT16 WINAPI GetPath16(HDC16 hdc, LPPOINT16 pPoints, LPBYTE pTypes,
248 INT16 nSize)
250 FIXME("(%d,%p,%p): stub\n",hdc,pPoints,pTypes);
252 return 0;
256 /***********************************************************************
257 * GetPath (GDI32.210)
259 INT WINAPI GetPath(HDC hdc, LPPOINT pPoints, LPBYTE pTypes,
260 INT nSize)
262 INT ret = -1;
263 GdiPath *pPath;
264 DC *dc = DC_GetDCPtr( hdc );
266 if(!dc) return -1;
268 pPath = &dc->path;
270 /* Check that path is closed */
271 if(pPath->state!=PATH_Closed)
273 SetLastError(ERROR_CAN_NOT_COMPLETE);
274 goto done;
277 if(nSize==0)
278 ret = pPath->numEntriesUsed;
279 else if(nSize<pPath->numEntriesUsed)
281 SetLastError(ERROR_INVALID_PARAMETER);
282 goto done;
284 else
286 memcpy(pPoints, pPath->pPoints, sizeof(POINT)*pPath->numEntriesUsed);
287 memcpy(pTypes, pPath->pFlags, sizeof(BYTE)*pPath->numEntriesUsed);
289 /* Convert the points to logical coordinates */
290 if(!DPtoLP(hdc, pPoints, pPath->numEntriesUsed))
292 /* FIXME: Is this the correct value? */
293 SetLastError(ERROR_CAN_NOT_COMPLETE);
294 goto done;
296 else ret = pPath->numEntriesUsed;
298 done:
299 GDI_ReleaseObj( hdc );
300 return ret;
303 /***********************************************************************
304 * PathToRegion16 (GDI.518)
306 HRGN16 WINAPI PathToRegion16(HDC16 hdc)
308 return (HRGN16) PathToRegion((HDC) hdc);
311 /***********************************************************************
312 * PathToRegion (GDI32.261)
314 * FIXME
315 * Check that SetLastError is being called correctly
317 * The documentation does not state this explicitly, but a test under Windows
318 * shows that the region which is returned should be in device coordinates.
320 HRGN WINAPI PathToRegion(HDC hdc)
322 GdiPath *pPath;
323 HRGN hrgnRval = 0;
324 DC *dc = DC_GetDCPtr( hdc );
326 /* Get pointer to path */
327 if(!dc) return -1;
329 pPath = &dc->path;
331 /* Check that path is closed */
332 if(pPath->state!=PATH_Closed) SetLastError(ERROR_CAN_NOT_COMPLETE);
333 else
335 /* FIXME: Should we empty the path even if conversion failed? */
336 if(PATH_PathToRegion(pPath, GetPolyFillMode(hdc), &hrgnRval))
337 PATH_EmptyPath(pPath);
338 else
339 hrgnRval=0;
341 GDI_ReleaseObj( hdc );
342 return hrgnRval;
345 static BOOL PATH_FillPath(DC *dc, GdiPath *pPath)
347 INT mapMode, graphicsMode;
348 SIZE ptViewportExt, ptWindowExt;
349 POINT ptViewportOrg, ptWindowOrg;
350 XFORM xform;
351 HRGN hrgn;
353 if(dc->funcs->pFillPath)
354 return dc->funcs->pFillPath(dc);
356 /* Check that path is closed */
357 if(pPath->state!=PATH_Closed)
359 SetLastError(ERROR_CAN_NOT_COMPLETE);
360 return FALSE;
363 /* Construct a region from the path and fill it */
364 if(PATH_PathToRegion(pPath, dc->polyFillMode, &hrgn))
366 /* Since PaintRgn interprets the region as being in logical coordinates
367 * but the points we store for the path are already in device
368 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
369 * Using SaveDC to save information about the mapping mode / world
370 * transform would be easier but would require more overhead, especially
371 * now that SaveDC saves the current path.
374 /* Save the information about the old mapping mode */
375 mapMode=GetMapMode(dc->hSelf);
376 GetViewportExtEx(dc->hSelf, &ptViewportExt);
377 GetViewportOrgEx(dc->hSelf, &ptViewportOrg);
378 GetWindowExtEx(dc->hSelf, &ptWindowExt);
379 GetWindowOrgEx(dc->hSelf, &ptWindowOrg);
381 /* Save world transform
382 * NB: The Windows documentation on world transforms would lead one to
383 * believe that this has to be done only in GM_ADVANCED; however, my
384 * tests show that resetting the graphics mode to GM_COMPATIBLE does
385 * not reset the world transform.
387 GetWorldTransform(dc->hSelf, &xform);
389 /* Set MM_TEXT */
390 SetMapMode(dc->hSelf, MM_TEXT);
391 SetViewportOrgEx(dc->hSelf, 0, 0, NULL);
392 SetWindowOrgEx(dc->hSelf, 0, 0, NULL);
394 /* Paint the region */
395 PaintRgn(dc->hSelf, hrgn);
396 DeleteObject(hrgn);
397 /* Restore the old mapping mode */
398 SetMapMode(dc->hSelf, mapMode);
399 SetViewportExtEx(dc->hSelf, ptViewportExt.cx, ptViewportExt.cy, NULL);
400 SetViewportOrgEx(dc->hSelf, ptViewportOrg.x, ptViewportOrg.y, NULL);
401 SetWindowExtEx(dc->hSelf, ptWindowExt.cx, ptWindowExt.cy, NULL);
402 SetWindowOrgEx(dc->hSelf, ptWindowOrg.x, ptWindowOrg.y, NULL);
404 /* Go to GM_ADVANCED temporarily to restore the world transform */
405 graphicsMode=GetGraphicsMode(dc->hSelf);
406 SetGraphicsMode(dc->hSelf, GM_ADVANCED);
407 SetWorldTransform(dc->hSelf, &xform);
408 SetGraphicsMode(dc->hSelf, graphicsMode);
409 return TRUE;
411 return FALSE;
414 /***********************************************************************
415 * FillPath16 (GDI.515)
417 BOOL16 WINAPI FillPath16(HDC16 hdc)
419 return (BOOL16) FillPath((HDC) hdc);
422 /***********************************************************************
423 * FillPath (GDI32.100)
425 * FIXME
426 * Check that SetLastError is being called correctly
428 BOOL WINAPI FillPath(HDC hdc)
430 DC *dc = DC_GetDCPtr( hdc );
431 BOOL bRet = FALSE;
433 if(!dc) return FALSE;
435 if(dc->funcs->pFillPath)
436 bRet = dc->funcs->pFillPath(dc);
437 else
439 bRet = PATH_FillPath(dc, &dc->path);
440 if(bRet)
442 /* FIXME: Should the path be emptied even if conversion
443 failed? */
444 PATH_EmptyPath(&dc->path);
447 GDI_ReleaseObj( hdc );
448 return bRet;
451 /***********************************************************************
452 * SelectClipPath16 (GDI.519)
454 BOOL16 WINAPI SelectClipPath16(HDC16 hdc, INT16 iMode)
456 return (BOOL16) SelectClipPath((HDC) hdc, iMode);
459 /***********************************************************************
460 * SelectClipPath (GDI32.296)
461 * FIXME
462 * Check that SetLastError is being called correctly
464 BOOL WINAPI SelectClipPath(HDC hdc, INT iMode)
466 GdiPath *pPath;
467 HRGN hrgnPath;
468 BOOL success = FALSE;
469 DC *dc = DC_GetDCPtr( hdc );
471 if(!dc) return FALSE;
473 if(dc->funcs->pSelectClipPath)
474 success = dc->funcs->pSelectClipPath(dc, iMode);
475 else
477 pPath = &dc->path;
479 /* Check that path is closed */
480 if(pPath->state!=PATH_Closed)
481 SetLastError(ERROR_CAN_NOT_COMPLETE);
482 /* Construct a region from the path */
483 else if(PATH_PathToRegion(pPath, GetPolyFillMode(hdc), &hrgnPath))
485 success = ExtSelectClipRgn( hdc, hrgnPath, iMode ) != ERROR;
486 DeleteObject(hrgnPath);
488 /* Empty the path */
489 if(success)
490 PATH_EmptyPath(pPath);
491 /* FIXME: Should this function delete the path even if it failed? */
494 GDI_ReleaseObj( hdc );
495 return success;
499 /***********************************************************************
500 * Exported functions
503 /* PATH_InitGdiPath
505 * Initializes the GdiPath structure.
507 void PATH_InitGdiPath(GdiPath *pPath)
509 assert(pPath!=NULL);
511 pPath->state=PATH_Null;
512 pPath->pPoints=NULL;
513 pPath->pFlags=NULL;
514 pPath->numEntriesUsed=0;
515 pPath->numEntriesAllocated=0;
518 /* PATH_DestroyGdiPath
520 * Destroys a GdiPath structure (frees the memory in the arrays).
522 void PATH_DestroyGdiPath(GdiPath *pPath)
524 assert(pPath!=NULL);
526 if (pPath->pPoints) HeapFree( GetProcessHeap(), 0, pPath->pPoints );
527 if (pPath->pFlags) HeapFree( GetProcessHeap(), 0, pPath->pFlags );
530 /* PATH_AssignGdiPath
532 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
533 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
534 * not just the pointers. Since this means that the arrays in pPathDest may
535 * need to be resized, pPathDest should have been initialized using
536 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
537 * not a copy constructor).
538 * Returns TRUE if successful, else FALSE.
540 BOOL PATH_AssignGdiPath(GdiPath *pPathDest, const GdiPath *pPathSrc)
542 assert(pPathDest!=NULL && pPathSrc!=NULL);
544 /* Make sure destination arrays are big enough */
545 if(!PATH_ReserveEntries(pPathDest, pPathSrc->numEntriesUsed))
546 return FALSE;
548 /* Perform the copy operation */
549 memcpy(pPathDest->pPoints, pPathSrc->pPoints,
550 sizeof(POINT)*pPathSrc->numEntriesUsed);
551 memcpy(pPathDest->pFlags, pPathSrc->pFlags,
552 sizeof(BYTE)*pPathSrc->numEntriesUsed);
554 pPathDest->state=pPathSrc->state;
555 pPathDest->numEntriesUsed=pPathSrc->numEntriesUsed;
556 pPathDest->newStroke=pPathSrc->newStroke;
558 return TRUE;
561 /* PATH_MoveTo
563 * Should be called when a MoveTo is performed on a DC that has an
564 * open path. This starts a new stroke. Returns TRUE if successful, else
565 * FALSE.
567 BOOL PATH_MoveTo(DC *dc)
569 GdiPath *pPath = &dc->path;
571 /* Check that path is open */
572 if(pPath->state!=PATH_Open)
573 /* FIXME: Do we have to call SetLastError? */
574 return FALSE;
576 /* Start a new stroke */
577 pPath->newStroke=TRUE;
579 return TRUE;
582 /* PATH_LineTo
584 * Should be called when a LineTo is performed on a DC that has an
585 * open path. This adds a PT_LINETO entry to the path (and possibly
586 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
587 * Returns TRUE if successful, else FALSE.
589 BOOL PATH_LineTo(DC *dc, INT x, INT y)
591 GdiPath *pPath = &dc->path;
592 POINT point, pointCurPos;
594 /* Check that path is open */
595 if(pPath->state!=PATH_Open)
596 return FALSE;
598 /* Convert point to device coordinates */
599 point.x=x;
600 point.y=y;
601 if(!LPtoDP(dc->hSelf, &point, 1))
602 return FALSE;
604 /* Add a PT_MOVETO if necessary */
605 if(pPath->newStroke)
607 pPath->newStroke=FALSE;
608 pointCurPos.x = dc->CursPosX;
609 pointCurPos.y = dc->CursPosY;
610 if(!LPtoDP(dc->hSelf, &pointCurPos, 1))
611 return FALSE;
612 if(!PATH_AddEntry(pPath, &pointCurPos, PT_MOVETO))
613 return FALSE;
616 /* Add a PT_LINETO entry */
617 return PATH_AddEntry(pPath, &point, PT_LINETO);
620 /* PATH_RoundRect
622 * Should be called when a call to RoundRect is performed on a DC that has
623 * an open path. Returns TRUE if successful, else FALSE.
625 * FIXME: it adds the same entries to the path as windows does, but there
626 * is an error in the bezier drawing code so that there are small pixel-size
627 * gaps when the resulting path is drawn by StrokePath()
629 BOOL PATH_RoundRect(DC *dc, INT x1, INT y1, INT x2, INT y2, INT ell_width, INT ell_height)
631 GdiPath *pPath = &dc->path;
632 POINT corners[2], pointTemp;
633 FLOAT_POINT ellCorners[2];
635 /* Check that path is open */
636 if(pPath->state!=PATH_Open)
637 return FALSE;
639 if(!PATH_CheckCorners(dc,corners,x1,y1,x2,y2))
640 return FALSE;
642 /* Add points to the roundrect path */
643 ellCorners[0].x = corners[1].x-ell_width;
644 ellCorners[0].y = corners[0].y;
645 ellCorners[1].x = corners[1].x;
646 ellCorners[1].y = corners[0].y+ell_height;
647 if(!PATH_DoArcPart(pPath, ellCorners, 0, -M_PI_2, TRUE))
648 return FALSE;
649 pointTemp.x = corners[0].x+ell_width/2;
650 pointTemp.y = corners[0].y;
651 if(!PATH_AddEntry(pPath, &pointTemp, PT_LINETO))
652 return FALSE;
653 ellCorners[0].x = corners[0].x;
654 ellCorners[1].x = corners[0].x+ell_width;
655 if(!PATH_DoArcPart(pPath, ellCorners, -M_PI_2, -M_PI, FALSE))
656 return FALSE;
657 pointTemp.x = corners[0].x;
658 pointTemp.y = corners[1].y-ell_height/2;
659 if(!PATH_AddEntry(pPath, &pointTemp, PT_LINETO))
660 return FALSE;
661 ellCorners[0].y = corners[1].y-ell_height;
662 ellCorners[1].y = corners[1].y;
663 if(!PATH_DoArcPart(pPath, ellCorners, M_PI, M_PI_2, FALSE))
664 return FALSE;
665 pointTemp.x = corners[1].x-ell_width/2;
666 pointTemp.y = corners[1].y;
667 if(!PATH_AddEntry(pPath, &pointTemp, PT_LINETO))
668 return FALSE;
669 ellCorners[0].x = corners[1].x-ell_width;
670 ellCorners[1].x = corners[1].x;
671 if(!PATH_DoArcPart(pPath, ellCorners, M_PI_2, 0, FALSE))
672 return FALSE;
674 /* Close the roundrect figure */
675 if(!CloseFigure(dc->hSelf))
676 return FALSE;
678 return TRUE;
681 /* PATH_Rectangle
683 * Should be called when a call to Rectangle is performed on a DC that has
684 * an open path. Returns TRUE if successful, else FALSE.
686 BOOL PATH_Rectangle(DC *dc, INT x1, INT y1, INT x2, INT y2)
688 GdiPath *pPath = &dc->path;
689 POINT corners[2], pointTemp;
691 /* Check that path is open */
692 if(pPath->state!=PATH_Open)
693 return FALSE;
695 if(!PATH_CheckCorners(dc,corners,x1,y1,x2,y2))
696 return FALSE;
698 /* Close any previous figure */
699 if(!CloseFigure(dc->hSelf))
701 /* The CloseFigure call shouldn't have failed */
702 assert(FALSE);
703 return FALSE;
706 /* Add four points to the path */
707 pointTemp.x=corners[1].x;
708 pointTemp.y=corners[0].y;
709 if(!PATH_AddEntry(pPath, &pointTemp, PT_MOVETO))
710 return FALSE;
711 if(!PATH_AddEntry(pPath, corners, PT_LINETO))
712 return FALSE;
713 pointTemp.x=corners[0].x;
714 pointTemp.y=corners[1].y;
715 if(!PATH_AddEntry(pPath, &pointTemp, PT_LINETO))
716 return FALSE;
717 if(!PATH_AddEntry(pPath, corners+1, PT_LINETO))
718 return FALSE;
720 /* Close the rectangle figure */
721 if(!CloseFigure(dc->hSelf))
723 /* The CloseFigure call shouldn't have failed */
724 assert(FALSE);
725 return FALSE;
728 return TRUE;
731 /* PATH_Ellipse
733 * Should be called when a call to Ellipse is performed on a DC that has
734 * an open path. This adds four Bezier splines representing the ellipse
735 * to the path. Returns TRUE if successful, else FALSE.
737 BOOL PATH_Ellipse(DC *dc, INT x1, INT y1, INT x2, INT y2)
739 return( PATH_Arc(dc, x1, y1, x2, y2, x1, (y1+y2)/2, x1, (y1+y2)/2,0) &&
740 CloseFigure(dc->hSelf) );
743 /* PATH_Arc
745 * Should be called when a call to Arc is performed on a DC that has
746 * an open path. This adds up to five Bezier splines representing the arc
747 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
748 * and when 'lines' is 2, we add 2 extra lines to get a pie.
749 * Returns TRUE if successful, else FALSE.
751 BOOL PATH_Arc(DC *dc, INT x1, INT y1, INT x2, INT y2,
752 INT xStart, INT yStart, INT xEnd, INT yEnd, INT lines)
754 GdiPath *pPath = &dc->path;
755 double angleStart, angleEnd, angleStartQuadrant, angleEndQuadrant=0.0;
756 /* Initialize angleEndQuadrant to silence gcc's warning */
757 double x, y;
758 FLOAT_POINT corners[2], pointStart, pointEnd;
759 POINT centre;
760 BOOL start, end;
761 INT temp;
763 /* FIXME: This function should check for all possible error returns */
764 /* FIXME: Do we have to respect newStroke? */
766 /* Check that path is open */
767 if(pPath->state!=PATH_Open)
768 return FALSE;
770 /* Check for zero height / width */
771 /* FIXME: Only in GM_COMPATIBLE? */
772 if(x1==x2 || y1==y2)
773 return TRUE;
775 /* Convert points to device coordinates */
776 corners[0].x=(FLOAT)x1;
777 corners[0].y=(FLOAT)y1;
778 corners[1].x=(FLOAT)x2;
779 corners[1].y=(FLOAT)y2;
780 pointStart.x=(FLOAT)xStart;
781 pointStart.y=(FLOAT)yStart;
782 pointEnd.x=(FLOAT)xEnd;
783 pointEnd.y=(FLOAT)yEnd;
784 INTERNAL_LPTODP_FLOAT(dc, corners);
785 INTERNAL_LPTODP_FLOAT(dc, corners+1);
786 INTERNAL_LPTODP_FLOAT(dc, &pointStart);
787 INTERNAL_LPTODP_FLOAT(dc, &pointEnd);
789 /* Make sure first corner is top left and second corner is bottom right */
790 if(corners[0].x>corners[1].x)
792 temp=corners[0].x;
793 corners[0].x=corners[1].x;
794 corners[1].x=temp;
796 if(corners[0].y>corners[1].y)
798 temp=corners[0].y;
799 corners[0].y=corners[1].y;
800 corners[1].y=temp;
803 /* Compute start and end angle */
804 PATH_NormalizePoint(corners, &pointStart, &x, &y);
805 angleStart=atan2(y, x);
806 PATH_NormalizePoint(corners, &pointEnd, &x, &y);
807 angleEnd=atan2(y, x);
809 /* Make sure the end angle is "on the right side" of the start angle */
810 if(dc->ArcDirection==AD_CLOCKWISE)
812 if(angleEnd<=angleStart)
814 angleEnd+=2*M_PI;
815 assert(angleEnd>=angleStart);
818 else
820 if(angleEnd>=angleStart)
822 angleEnd-=2*M_PI;
823 assert(angleEnd<=angleStart);
827 /* In GM_COMPATIBLE, don't include bottom and right edges */
828 if(dc->GraphicsMode==GM_COMPATIBLE)
830 corners[1].x--;
831 corners[1].y--;
834 /* Add the arc to the path with one Bezier spline per quadrant that the
835 * arc spans */
836 start=TRUE;
837 end=FALSE;
840 /* Determine the start and end angles for this quadrant */
841 if(start)
843 angleStartQuadrant=angleStart;
844 if(dc->ArcDirection==AD_CLOCKWISE)
845 angleEndQuadrant=(floor(angleStart/M_PI_2)+1.0)*M_PI_2;
846 else
847 angleEndQuadrant=(ceil(angleStart/M_PI_2)-1.0)*M_PI_2;
849 else
851 angleStartQuadrant=angleEndQuadrant;
852 if(dc->ArcDirection==AD_CLOCKWISE)
853 angleEndQuadrant+=M_PI_2;
854 else
855 angleEndQuadrant-=M_PI_2;
858 /* Have we reached the last part of the arc? */
859 if((dc->ArcDirection==AD_CLOCKWISE &&
860 angleEnd<angleEndQuadrant) ||
861 (dc->ArcDirection==AD_COUNTERCLOCKWISE &&
862 angleEnd>angleEndQuadrant))
864 /* Adjust the end angle for this quadrant */
865 angleEndQuadrant=angleEnd;
866 end=TRUE;
869 /* Add the Bezier spline to the path */
870 PATH_DoArcPart(pPath, corners, angleStartQuadrant, angleEndQuadrant,
871 start);
872 start=FALSE;
873 } while(!end);
875 /* chord: close figure. pie: add line and close figure */
876 if(lines==1)
878 if(!CloseFigure(dc->hSelf))
879 return FALSE;
881 else if(lines==2)
883 centre.x = (corners[0].x+corners[1].x)/2;
884 centre.y = (corners[0].y+corners[1].y)/2;
885 if(!PATH_AddEntry(pPath, &centre, PT_LINETO | PT_CLOSEFIGURE))
886 return FALSE;
889 return TRUE;
892 BOOL PATH_PolyBezierTo(DC *dc, const POINT *pts, DWORD cbPoints)
894 GdiPath *pPath = &dc->path;
895 POINT pt;
896 INT i;
898 /* Check that path is open */
899 if(pPath->state!=PATH_Open)
900 return FALSE;
902 /* Add a PT_MOVETO if necessary */
903 if(pPath->newStroke)
905 pPath->newStroke=FALSE;
906 pt.x = dc->CursPosX;
907 pt.y = dc->CursPosY;
908 if(!LPtoDP(dc->hSelf, &pt, 1))
909 return FALSE;
910 if(!PATH_AddEntry(pPath, &pt, PT_MOVETO))
911 return FALSE;
914 for(i = 0; i < cbPoints; i++) {
915 pt = pts[i];
916 if(!LPtoDP(dc->hSelf, &pt, 1))
917 return FALSE;
918 PATH_AddEntry(pPath, &pt, PT_BEZIERTO);
920 return TRUE;
923 BOOL PATH_PolyBezier(DC *dc, const POINT *pts, DWORD cbPoints)
925 GdiPath *pPath = &dc->path;
926 POINT pt;
927 INT i;
929 /* Check that path is open */
930 if(pPath->state!=PATH_Open)
931 return FALSE;
933 for(i = 0; i < cbPoints; i++) {
934 pt = pts[i];
935 if(!LPtoDP(dc->hSelf, &pt, 1))
936 return FALSE;
937 PATH_AddEntry(pPath, &pt, (i == 0) ? PT_MOVETO : PT_BEZIERTO);
939 return TRUE;
942 BOOL PATH_Polyline(DC *dc, const POINT *pts, DWORD cbPoints)
944 GdiPath *pPath = &dc->path;
945 POINT pt;
946 INT i;
948 /* Check that path is open */
949 if(pPath->state!=PATH_Open)
950 return FALSE;
952 for(i = 0; i < cbPoints; i++) {
953 pt = pts[i];
954 if(!LPtoDP(dc->hSelf, &pt, 1))
955 return FALSE;
956 PATH_AddEntry(pPath, &pt, (i == 0) ? PT_MOVETO : PT_LINETO);
958 return TRUE;
961 BOOL PATH_PolylineTo(DC *dc, const POINT *pts, DWORD cbPoints)
963 GdiPath *pPath = &dc->path;
964 POINT pt;
965 INT i;
967 /* Check that path is open */
968 if(pPath->state!=PATH_Open)
969 return FALSE;
971 /* Add a PT_MOVETO if necessary */
972 if(pPath->newStroke)
974 pPath->newStroke=FALSE;
975 pt.x = dc->CursPosX;
976 pt.y = dc->CursPosY;
977 if(!LPtoDP(dc->hSelf, &pt, 1))
978 return FALSE;
979 if(!PATH_AddEntry(pPath, &pt, PT_MOVETO))
980 return FALSE;
983 for(i = 0; i < cbPoints; i++) {
984 pt = pts[i];
985 if(!LPtoDP(dc->hSelf, &pt, 1))
986 return FALSE;
987 PATH_AddEntry(pPath, &pt, PT_LINETO);
990 return TRUE;
994 BOOL PATH_Polygon(DC *dc, const POINT *pts, DWORD cbPoints)
996 GdiPath *pPath = &dc->path;
997 POINT pt;
998 INT i;
1000 /* Check that path is open */
1001 if(pPath->state!=PATH_Open)
1002 return FALSE;
1004 for(i = 0; i < cbPoints; i++) {
1005 pt = pts[i];
1006 if(!LPtoDP(dc->hSelf, &pt, 1))
1007 return FALSE;
1008 PATH_AddEntry(pPath, &pt, (i == 0) ? PT_MOVETO :
1009 ((i == cbPoints-1) ? PT_LINETO | PT_CLOSEFIGURE :
1010 PT_LINETO));
1012 return TRUE;
1015 BOOL PATH_PolyPolygon( DC *dc, const POINT* pts, const INT* counts,
1016 UINT polygons )
1018 GdiPath *pPath = &dc->path;
1019 POINT pt, startpt;
1020 INT poly, point, i;
1022 /* Check that path is open */
1023 if(pPath->state!=PATH_Open)
1024 return FALSE;
1026 for(i = 0, poly = 0; poly < polygons; poly++) {
1027 for(point = 0; point < counts[poly]; point++, i++) {
1028 pt = pts[i];
1029 if(!LPtoDP(dc->hSelf, &pt, 1))
1030 return FALSE;
1031 if(point == 0) startpt = pt;
1032 PATH_AddEntry(pPath, &pt, (point == 0) ? PT_MOVETO : PT_LINETO);
1034 /* win98 adds an extra line to close the figure for some reason */
1035 PATH_AddEntry(pPath, &startpt, PT_LINETO | PT_CLOSEFIGURE);
1037 return TRUE;
1040 BOOL PATH_PolyPolyline( DC *dc, const POINT* pts, const DWORD* counts,
1041 DWORD polylines )
1043 GdiPath *pPath = &dc->path;
1044 POINT pt;
1045 INT poly, point, i;
1047 /* Check that path is open */
1048 if(pPath->state!=PATH_Open)
1049 return FALSE;
1051 for(i = 0, poly = 0; poly < polylines; poly++) {
1052 for(point = 0; point < counts[poly]; point++, i++) {
1053 pt = pts[i];
1054 if(!LPtoDP(dc->hSelf, &pt, 1))
1055 return FALSE;
1056 PATH_AddEntry(pPath, &pt, (point == 0) ? PT_MOVETO : PT_LINETO);
1059 return TRUE;
1062 /***********************************************************************
1063 * Internal functions
1066 /* PATH_CheckCorners
1068 * Helper function for PATH_RoundRect() and PATH_Rectangle()
1070 static BOOL PATH_CheckCorners(DC *dc, POINT corners[], INT x1, INT y1, INT x2, INT y2)
1072 INT temp;
1074 /* Convert points to device coordinates */
1075 corners[0].x=x1;
1076 corners[0].y=y1;
1077 corners[1].x=x2;
1078 corners[1].y=y2;
1079 if(!LPtoDP(dc->hSelf, corners, 2))
1080 return FALSE;
1082 /* Make sure first corner is top left and second corner is bottom right */
1083 if(corners[0].x>corners[1].x)
1085 temp=corners[0].x;
1086 corners[0].x=corners[1].x;
1087 corners[1].x=temp;
1089 if(corners[0].y>corners[1].y)
1091 temp=corners[0].y;
1092 corners[0].y=corners[1].y;
1093 corners[1].y=temp;
1096 /* In GM_COMPATIBLE, don't include bottom and right edges */
1097 if(dc->GraphicsMode==GM_COMPATIBLE)
1099 corners[1].x--;
1100 corners[1].y--;
1103 return TRUE;
1106 /* PATH_AddFlatBezier
1108 static BOOL PATH_AddFlatBezier(GdiPath *pPath, POINT *pt, BOOL closed)
1110 POINT *pts;
1111 INT no, i;
1113 pts = GDI_Bezier( pt, 4, &no );
1114 if(!pts) return FALSE;
1116 for(i = 1; i < no; i++)
1117 PATH_AddEntry(pPath, &pts[i],
1118 (i == no-1 && closed) ? PT_LINETO | PT_CLOSEFIGURE : PT_LINETO);
1119 HeapFree( GetProcessHeap(), 0, pts );
1120 return TRUE;
1123 /* PATH_FlattenPath
1125 * Replaces Beziers with line segments
1128 static BOOL PATH_FlattenPath(GdiPath *pPath)
1130 GdiPath newPath;
1131 INT srcpt;
1133 memset(&newPath, 0, sizeof(newPath));
1134 newPath.state = PATH_Open;
1135 for(srcpt = 0; srcpt < pPath->numEntriesUsed; srcpt++) {
1136 switch(pPath->pFlags[srcpt] & ~PT_CLOSEFIGURE) {
1137 case PT_MOVETO:
1138 case PT_LINETO:
1139 PATH_AddEntry(&newPath, &pPath->pPoints[srcpt],
1140 pPath->pFlags[srcpt]);
1141 break;
1142 case PT_BEZIERTO:
1143 PATH_AddFlatBezier(&newPath, &pPath->pPoints[srcpt-1],
1144 pPath->pFlags[srcpt+2] & PT_CLOSEFIGURE);
1145 srcpt += 2;
1146 break;
1149 newPath.state = PATH_Closed;
1150 PATH_AssignGdiPath(pPath, &newPath);
1151 PATH_EmptyPath(&newPath);
1152 return TRUE;
1155 /* PATH_PathToRegion
1157 * Creates a region from the specified path using the specified polygon
1158 * filling mode. The path is left unchanged. A handle to the region that
1159 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1160 * error occurs, SetLastError is called with the appropriate value and
1161 * FALSE is returned.
1163 static BOOL PATH_PathToRegion(GdiPath *pPath, INT nPolyFillMode,
1164 HRGN *pHrgn)
1166 int numStrokes, iStroke, i;
1167 INT *pNumPointsInStroke;
1168 HRGN hrgn;
1170 assert(pPath!=NULL);
1171 assert(pHrgn!=NULL);
1173 PATH_FlattenPath(pPath);
1175 /* FIXME: What happens when number of points is zero? */
1177 /* First pass: Find out how many strokes there are in the path */
1178 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1179 numStrokes=0;
1180 for(i=0; i<pPath->numEntriesUsed; i++)
1181 if((pPath->pFlags[i] & ~PT_CLOSEFIGURE) == PT_MOVETO)
1182 numStrokes++;
1184 /* Allocate memory for number-of-points-in-stroke array */
1185 pNumPointsInStroke=(int *)HeapAlloc( GetProcessHeap(), 0,
1186 sizeof(int) * numStrokes );
1187 if(!pNumPointsInStroke)
1189 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1190 return FALSE;
1193 /* Second pass: remember number of points in each polygon */
1194 iStroke=-1; /* Will get incremented to 0 at beginning of first stroke */
1195 for(i=0; i<pPath->numEntriesUsed; i++)
1197 /* Is this the beginning of a new stroke? */
1198 if((pPath->pFlags[i] & ~PT_CLOSEFIGURE) == PT_MOVETO)
1200 iStroke++;
1201 pNumPointsInStroke[iStroke]=0;
1204 pNumPointsInStroke[iStroke]++;
1207 /* Create a region from the strokes */
1208 hrgn=CreatePolyPolygonRgn(pPath->pPoints, pNumPointsInStroke,
1209 numStrokes, nPolyFillMode);
1210 if(hrgn==(HRGN)0)
1212 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1213 return FALSE;
1216 /* Free memory for number-of-points-in-stroke array */
1217 HeapFree( GetProcessHeap(), 0, pNumPointsInStroke );
1219 /* Success! */
1220 *pHrgn=hrgn;
1221 return TRUE;
1224 /* PATH_EmptyPath
1226 * Removes all entries from the path and sets the path state to PATH_Null.
1228 static void PATH_EmptyPath(GdiPath *pPath)
1230 assert(pPath!=NULL);
1232 pPath->state=PATH_Null;
1233 pPath->numEntriesUsed=0;
1236 /* PATH_AddEntry
1238 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1239 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1240 * successful, FALSE otherwise (e.g. if not enough memory was available).
1242 BOOL PATH_AddEntry(GdiPath *pPath, const POINT *pPoint, BYTE flags)
1244 assert(pPath!=NULL);
1246 /* FIXME: If newStroke is true, perhaps we want to check that we're
1247 * getting a PT_MOVETO
1249 TRACE("(%ld,%ld) - %d\n", pPoint->x, pPoint->y, flags);
1251 /* Check that path is open */
1252 if(pPath->state!=PATH_Open)
1253 return FALSE;
1255 /* Reserve enough memory for an extra path entry */
1256 if(!PATH_ReserveEntries(pPath, pPath->numEntriesUsed+1))
1257 return FALSE;
1259 /* Store information in path entry */
1260 pPath->pPoints[pPath->numEntriesUsed]=*pPoint;
1261 pPath->pFlags[pPath->numEntriesUsed]=flags;
1263 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1264 if((flags & PT_CLOSEFIGURE) == PT_CLOSEFIGURE)
1265 pPath->newStroke=TRUE;
1267 /* Increment entry count */
1268 pPath->numEntriesUsed++;
1270 return TRUE;
1273 /* PATH_ReserveEntries
1275 * Ensures that at least "numEntries" entries (for points and flags) have
1276 * been allocated; allocates larger arrays and copies the existing entries
1277 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1279 static BOOL PATH_ReserveEntries(GdiPath *pPath, INT numEntries)
1281 INT numEntriesToAllocate;
1282 POINT *pPointsNew;
1283 BYTE *pFlagsNew;
1285 assert(pPath!=NULL);
1286 assert(numEntries>=0);
1288 /* Do we have to allocate more memory? */
1289 if(numEntries > pPath->numEntriesAllocated)
1291 /* Find number of entries to allocate. We let the size of the array
1292 * grow exponentially, since that will guarantee linear time
1293 * complexity. */
1294 if(pPath->numEntriesAllocated)
1296 numEntriesToAllocate=pPath->numEntriesAllocated;
1297 while(numEntriesToAllocate<numEntries)
1298 numEntriesToAllocate=numEntriesToAllocate*GROW_FACTOR_NUMER/
1299 GROW_FACTOR_DENOM;
1301 else
1302 numEntriesToAllocate=numEntries;
1304 /* Allocate new arrays */
1305 pPointsNew=(POINT *)HeapAlloc( GetProcessHeap(), 0,
1306 numEntriesToAllocate * sizeof(POINT) );
1307 if(!pPointsNew)
1308 return FALSE;
1309 pFlagsNew=(BYTE *)HeapAlloc( GetProcessHeap(), 0,
1310 numEntriesToAllocate * sizeof(BYTE) );
1311 if(!pFlagsNew)
1313 HeapFree( GetProcessHeap(), 0, pPointsNew );
1314 return FALSE;
1317 /* Copy old arrays to new arrays and discard old arrays */
1318 if(pPath->pPoints)
1320 assert(pPath->pFlags);
1322 memcpy(pPointsNew, pPath->pPoints,
1323 sizeof(POINT)*pPath->numEntriesUsed);
1324 memcpy(pFlagsNew, pPath->pFlags,
1325 sizeof(BYTE)*pPath->numEntriesUsed);
1327 HeapFree( GetProcessHeap(), 0, pPath->pPoints );
1328 HeapFree( GetProcessHeap(), 0, pPath->pFlags );
1330 pPath->pPoints=pPointsNew;
1331 pPath->pFlags=pFlagsNew;
1332 pPath->numEntriesAllocated=numEntriesToAllocate;
1335 return TRUE;
1338 /* PATH_DoArcPart
1340 * Creates a Bezier spline that corresponds to part of an arc and appends the
1341 * corresponding points to the path. The start and end angles are passed in
1342 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1343 * at most. If "addMoveTo" is true, a PT_MOVETO entry for the first control
1344 * point is added to the path; otherwise, it is assumed that the current
1345 * position is equal to the first control point.
1347 static BOOL PATH_DoArcPart(GdiPath *pPath, FLOAT_POINT corners[],
1348 double angleStart, double angleEnd, BOOL addMoveTo)
1350 double halfAngle, a;
1351 double xNorm[4], yNorm[4];
1352 POINT point;
1353 int i;
1355 assert(fabs(angleEnd-angleStart)<=M_PI_2);
1357 /* FIXME: Is there an easier way of computing this? */
1359 /* Compute control points */
1360 halfAngle=(angleEnd-angleStart)/2.0;
1361 if(fabs(halfAngle)>1e-8)
1363 a=4.0/3.0*(1-cos(halfAngle))/sin(halfAngle);
1364 xNorm[0]=cos(angleStart);
1365 yNorm[0]=sin(angleStart);
1366 xNorm[1]=xNorm[0] - a*yNorm[0];
1367 yNorm[1]=yNorm[0] + a*xNorm[0];
1368 xNorm[3]=cos(angleEnd);
1369 yNorm[3]=sin(angleEnd);
1370 xNorm[2]=xNorm[3] + a*yNorm[3];
1371 yNorm[2]=yNorm[3] - a*xNorm[3];
1373 else
1374 for(i=0; i<4; i++)
1376 xNorm[i]=cos(angleStart);
1377 yNorm[i]=sin(angleStart);
1380 /* Add starting point to path if desired */
1381 if(addMoveTo)
1383 PATH_ScaleNormalizedPoint(corners, xNorm[0], yNorm[0], &point);
1384 if(!PATH_AddEntry(pPath, &point, PT_MOVETO))
1385 return FALSE;
1388 /* Add remaining control points */
1389 for(i=1; i<4; i++)
1391 PATH_ScaleNormalizedPoint(corners, xNorm[i], yNorm[i], &point);
1392 if(!PATH_AddEntry(pPath, &point, PT_BEZIERTO))
1393 return FALSE;
1396 return TRUE;
1399 /* PATH_ScaleNormalizedPoint
1401 * Scales a normalized point (x, y) with respect to the box whose corners are
1402 * passed in "corners". The point is stored in "*pPoint". The normalized
1403 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1404 * (1.0, 1.0) correspond to corners[1].
1406 static void PATH_ScaleNormalizedPoint(FLOAT_POINT corners[], double x,
1407 double y, POINT *pPoint)
1409 pPoint->x=GDI_ROUND( (double)corners[0].x +
1410 (double)(corners[1].x-corners[0].x)*0.5*(x+1.0) );
1411 pPoint->y=GDI_ROUND( (double)corners[0].y +
1412 (double)(corners[1].y-corners[0].y)*0.5*(y+1.0) );
1415 /* PATH_NormalizePoint
1417 * Normalizes a point with respect to the box whose corners are passed in
1418 * "corners". The normalized coordinates are stored in "*pX" and "*pY".
1420 static void PATH_NormalizePoint(FLOAT_POINT corners[],
1421 const FLOAT_POINT *pPoint,
1422 double *pX, double *pY)
1424 *pX=(double)(pPoint->x-corners[0].x)/(double)(corners[1].x-corners[0].x) *
1425 2.0 - 1.0;
1426 *pY=(double)(pPoint->y-corners[0].y)/(double)(corners[1].y-corners[0].y) *
1427 2.0 - 1.0;
1430 /*******************************************************************
1431 * FlattenPath16 [GDI.516]
1435 BOOL16 WINAPI FlattenPath16(HDC16 hdc)
1437 return (BOOL16) FlattenPath((HDC) hdc);
1440 /*******************************************************************
1441 * FlattenPath [GDI32.103]
1445 BOOL WINAPI FlattenPath(HDC hdc)
1447 BOOL ret = FALSE;
1448 DC *dc = DC_GetDCPtr( hdc );
1450 if(!dc) return FALSE;
1452 if(dc->funcs->pFlattenPath) ret = dc->funcs->pFlattenPath(dc);
1453 else
1455 GdiPath *pPath = &dc->path;
1456 if(pPath->state != PATH_Closed)
1457 ret = PATH_FlattenPath(pPath);
1459 GDI_ReleaseObj( hdc );
1460 return ret;
1464 static BOOL PATH_StrokePath(DC *dc, GdiPath *pPath)
1466 INT i;
1467 POINT ptLastMove = {0,0};
1469 if(dc->funcs->pStrokePath)
1470 return dc->funcs->pStrokePath(dc);
1472 if(pPath->state != PATH_Closed)
1473 return FALSE;
1475 SaveDC(dc->hSelf);
1476 SetMapMode(dc->hSelf, MM_TEXT);
1477 SetViewportOrgEx(dc->hSelf, 0, 0, NULL);
1478 SetWindowOrgEx(dc->hSelf, 0, 0, NULL);
1479 for(i = 0; i < pPath->numEntriesUsed; i++) {
1480 switch(pPath->pFlags[i]) {
1481 case PT_MOVETO:
1482 TRACE("Got PT_MOVETO (%ld, %ld)\n",
1483 pPath->pPoints[i].x, pPath->pPoints[i].y);
1484 MoveToEx(dc->hSelf, pPath->pPoints[i].x, pPath->pPoints[i].y, NULL);
1485 ptLastMove = pPath->pPoints[i];
1486 break;
1487 case PT_LINETO:
1488 case (PT_LINETO | PT_CLOSEFIGURE):
1489 TRACE("Got PT_LINETO (%ld, %ld)\n",
1490 pPath->pPoints[i].x, pPath->pPoints[i].y);
1491 LineTo(dc->hSelf, pPath->pPoints[i].x, pPath->pPoints[i].y);
1492 break;
1493 case PT_BEZIERTO:
1494 TRACE("Got PT_BEZIERTO\n");
1495 if(pPath->pFlags[i+1] != PT_BEZIERTO ||
1496 (pPath->pFlags[i+2] & ~PT_CLOSEFIGURE) != PT_BEZIERTO) {
1497 ERR("Path didn't contain 3 successive PT_BEZIERTOs\n");
1498 return FALSE;
1500 PolyBezierTo(dc->hSelf, &pPath->pPoints[i], 3);
1501 i += 2;
1502 break;
1503 default:
1504 ERR("Got path flag %d\n", (INT)pPath->pFlags[i]);
1505 return FALSE;
1507 if(pPath->pFlags[i] & PT_CLOSEFIGURE)
1508 LineTo(dc->hSelf, ptLastMove.x, ptLastMove.y);
1510 RestoreDC(dc->hSelf , -1);
1511 return TRUE;
1515 /*******************************************************************
1516 * StrokeAndFillPath16 [GDI.520]
1520 BOOL16 WINAPI StrokeAndFillPath16(HDC16 hdc)
1522 return (BOOL16) StrokeAndFillPath((HDC) hdc);
1525 /*******************************************************************
1526 * StrokeAndFillPath [GDI32.352]
1530 BOOL WINAPI StrokeAndFillPath(HDC hdc)
1532 DC *dc = DC_GetDCPtr( hdc );
1533 BOOL bRet = FALSE;
1535 if(!dc) return FALSE;
1537 if(dc->funcs->pStrokeAndFillPath)
1538 bRet = dc->funcs->pStrokeAndFillPath(dc);
1539 else
1541 bRet = PATH_FillPath(dc, &dc->path);
1542 if(bRet) bRet = PATH_StrokePath(dc, &dc->path);
1543 if(bRet) PATH_EmptyPath(&dc->path);
1545 GDI_ReleaseObj( hdc );
1546 return bRet;
1549 /*******************************************************************
1550 * StrokePath16 [GDI.521]
1554 BOOL16 WINAPI StrokePath16(HDC16 hdc)
1556 return (BOOL16) StrokePath((HDC) hdc);
1559 /*******************************************************************
1560 * StrokePath [GDI32.353]
1564 BOOL WINAPI StrokePath(HDC hdc)
1566 DC *dc = DC_GetDCPtr( hdc );
1567 GdiPath *pPath;
1568 BOOL bRet = FALSE;
1570 TRACE("(%08x)\n", hdc);
1571 if(!dc) return FALSE;
1573 if(dc->funcs->pStrokePath)
1574 bRet = dc->funcs->pStrokePath(dc);
1575 else
1577 pPath = &dc->path;
1578 bRet = PATH_StrokePath(dc, pPath);
1579 PATH_EmptyPath(pPath);
1581 GDI_ReleaseObj( hdc );
1582 return bRet;
1585 /*******************************************************************
1586 * WidenPath16 [GDI.522]
1590 BOOL16 WINAPI WidenPath16(HDC16 hdc)
1592 return (BOOL16) WidenPath((HDC) hdc);
1595 /*******************************************************************
1596 * WidenPath [GDI32.360]
1600 BOOL WINAPI WidenPath(HDC hdc)
1602 DC *dc = DC_GetDCPtr( hdc );
1603 BOOL ret = FALSE;
1605 if(!dc) return FALSE;
1607 if(dc->funcs->pWidenPath)
1608 ret = dc->funcs->pWidenPath(dc);
1610 FIXME("stub\n");
1611 GDI_ReleaseObj( hdc );
1612 return ret;