2 * Graphics paths (BeginPath, EndPath etc.)
4 * Copyright 1997, 1998 Martin Boehme
6 * Copyright 2005 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
31 #if defined(HAVE_FLOAT_H)
40 #include "gdi_private.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdi);
45 /* Notes on the implementation
47 * The implementation is based on dynamically resizable arrays of points and
48 * flags. I dithered for a bit before deciding on this implementation, and
49 * I had even done a bit of work on a linked list version before switching
50 * to arrays. It's a bit of a tradeoff. When you use linked lists, the
51 * implementation of FlattenPath is easier, because you can rip the
52 * PT_BEZIERTO entries out of the middle of the list and link the
53 * corresponding PT_LINETO entries in. However, when you use arrays,
54 * PathToRegion becomes easier, since you can essentially just pass your array
55 * of points to CreatePolyPolygonRgn. Also, if I'd used linked lists, I would
56 * have had the extra effort of creating a chunk-based allocation scheme
57 * in order to use memory effectively. That's why I finally decided to use
58 * arrays. Note by the way that the array based implementation has the same
59 * linear time complexity that linked lists would have since the arrays grow
62 * The points are stored in the path in device coordinates. This is
63 * consistent with the way Windows does things (for instance, see the Win32
64 * SDK documentation for GetPath).
66 * The word "stroke" appears in several places (e.g. in the flag
67 * GdiPath.newStroke). A stroke consists of a PT_MOVETO followed by one or
68 * more PT_LINETOs or PT_BEZIERTOs, up to, but not including, the next
69 * PT_MOVETO. Note that this is not the same as the definition of a figure;
70 * a figure can contain several strokes.
72 * I modified the drawing functions (MoveTo, LineTo etc.) to test whether
73 * the path is open and to call the corresponding function in path.c if this
74 * is the case. A more elegant approach would be to modify the function
75 * pointers in the DC_FUNCTIONS structure; however, this would be a lot more
76 * complex. Also, the performance degradation caused by my approach in the
77 * case where no path is open is so small that it cannot be measured.
82 /* FIXME: A lot of stuff isn't implemented yet. There is much more to come. */
84 #define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
85 #define GROW_FACTOR_NUMER 2 /* Numerator of grow factor for the array */
86 #define GROW_FACTOR_DENOM 1 /* Denominator of grow factor */
88 /* A floating point version of the POINT structure */
89 typedef struct tagFLOAT_POINT
95 static BOOL PATH_PathToRegion(GdiPath *pPath, INT nPolyFillMode,
97 static void PATH_EmptyPath(GdiPath *pPath);
98 static BOOL PATH_ReserveEntries(GdiPath *pPath, INT numEntries);
99 static BOOL PATH_DoArcPart(GdiPath *pPath, FLOAT_POINT corners[],
100 double angleStart, double angleEnd, BOOL addMoveTo);
101 static void PATH_ScaleNormalizedPoint(FLOAT_POINT corners[], double x,
102 double y, POINT *pPoint);
103 static void PATH_NormalizePoint(FLOAT_POINT corners[], const FLOAT_POINT
104 *pPoint, double *pX, double *pY);
105 static BOOL PATH_CheckCorners(DC *dc, POINT corners[], INT x1, INT y1, INT x2, INT y2);
107 /* Performs a world-to-viewport transformation on the specified point (which
108 * is in floating point format).
110 static inline void INTERNAL_LPTODP_FLOAT(DC *dc, FLOAT_POINT *point)
114 /* Perform the transformation */
117 point->x = x * dc->xformWorld2Vport.eM11 +
118 y * dc->xformWorld2Vport.eM21 +
119 dc->xformWorld2Vport.eDx;
120 point->y = x * dc->xformWorld2Vport.eM12 +
121 y * dc->xformWorld2Vport.eM22 +
122 dc->xformWorld2Vport.eDy;
125 /* Performs a world-to-viewport transformation on the specified width.
127 static inline void INTERNAL_WSTODS(DC *dc, DWORD *width)
130 pt[0].x = pt[0].y = 0;
133 LPtoDP(dc->hSelf, pt, 2);
134 *width = pt[1].x - pt[0].x;
137 /***********************************************************************
138 * BeginPath (GDI32.@)
140 BOOL WINAPI BeginPath(HDC hdc)
143 DC *dc = DC_GetDCPtr( hdc );
145 if(!dc) return FALSE;
147 if(dc->funcs->pBeginPath)
148 ret = dc->funcs->pBeginPath(dc->physDev);
151 /* If path is already open, do nothing */
152 if(dc->path.state != PATH_Open)
154 /* Make sure that path is empty */
155 PATH_EmptyPath(&dc->path);
157 /* Initialize variables for new path */
158 dc->path.newStroke=TRUE;
159 dc->path.state=PATH_Open;
162 GDI_ReleaseObj( hdc );
167 /***********************************************************************
170 BOOL WINAPI EndPath(HDC hdc)
173 DC *dc = DC_GetDCPtr( hdc );
175 if(!dc) return FALSE;
177 if(dc->funcs->pEndPath)
178 ret = dc->funcs->pEndPath(dc->physDev);
181 /* Check that path is currently being constructed */
182 if(dc->path.state!=PATH_Open)
184 SetLastError(ERROR_CAN_NOT_COMPLETE);
187 /* Set flag to indicate that path is finished */
188 else dc->path.state=PATH_Closed;
190 GDI_ReleaseObj( hdc );
195 /******************************************************************************
196 * AbortPath [GDI32.@]
197 * Closes and discards paths from device context
200 * Check that SetLastError is being called correctly
203 * hdc [I] Handle to device context
209 BOOL WINAPI AbortPath( HDC hdc )
212 DC *dc = DC_GetDCPtr( hdc );
214 if(!dc) return FALSE;
216 if(dc->funcs->pAbortPath)
217 ret = dc->funcs->pAbortPath(dc->physDev);
218 else /* Remove all entries from the path */
219 PATH_EmptyPath( &dc->path );
220 GDI_ReleaseObj( hdc );
225 /***********************************************************************
226 * CloseFigure (GDI32.@)
228 * FIXME: Check that SetLastError is being called correctly
230 BOOL WINAPI CloseFigure(HDC hdc)
233 DC *dc = DC_GetDCPtr( hdc );
235 if(!dc) return FALSE;
237 if(dc->funcs->pCloseFigure)
238 ret = dc->funcs->pCloseFigure(dc->physDev);
241 /* Check that path is open */
242 if(dc->path.state!=PATH_Open)
244 SetLastError(ERROR_CAN_NOT_COMPLETE);
249 /* FIXME: Shouldn't we draw a line to the beginning of the
251 /* Set PT_CLOSEFIGURE on the last entry and start a new stroke */
252 if(dc->path.numEntriesUsed)
254 dc->path.pFlags[dc->path.numEntriesUsed-1]|=PT_CLOSEFIGURE;
255 dc->path.newStroke=TRUE;
259 GDI_ReleaseObj( hdc );
264 /***********************************************************************
267 INT WINAPI GetPath(HDC hdc, LPPOINT pPoints, LPBYTE pTypes,
272 DC *dc = DC_GetDCPtr( hdc );
278 /* Check that path is closed */
279 if(pPath->state!=PATH_Closed)
281 SetLastError(ERROR_CAN_NOT_COMPLETE);
286 ret = pPath->numEntriesUsed;
287 else if(nSize<pPath->numEntriesUsed)
289 SetLastError(ERROR_INVALID_PARAMETER);
294 memcpy(pPoints, pPath->pPoints, sizeof(POINT)*pPath->numEntriesUsed);
295 memcpy(pTypes, pPath->pFlags, sizeof(BYTE)*pPath->numEntriesUsed);
297 /* Convert the points to logical coordinates */
298 if(!DPtoLP(hdc, pPoints, pPath->numEntriesUsed))
300 /* FIXME: Is this the correct value? */
301 SetLastError(ERROR_CAN_NOT_COMPLETE);
304 else ret = pPath->numEntriesUsed;
307 GDI_ReleaseObj( hdc );
312 /***********************************************************************
313 * PathToRegion (GDI32.@)
316 * Check that SetLastError is being called correctly
318 * The documentation does not state this explicitly, but a test under Windows
319 * shows that the region which is returned should be in device coordinates.
321 HRGN WINAPI PathToRegion(HDC hdc)
325 DC *dc = DC_GetDCPtr( hdc );
327 /* Get pointer to path */
332 /* Check that path is closed */
333 if(pPath->state!=PATH_Closed) SetLastError(ERROR_CAN_NOT_COMPLETE);
336 /* FIXME: Should we empty the path even if conversion failed? */
337 if(PATH_PathToRegion(pPath, GetPolyFillMode(hdc), &hrgnRval))
338 PATH_EmptyPath(pPath);
342 GDI_ReleaseObj( hdc );
346 static BOOL PATH_FillPath(DC *dc, GdiPath *pPath)
348 INT mapMode, graphicsMode;
349 SIZE ptViewportExt, ptWindowExt;
350 POINT ptViewportOrg, ptWindowOrg;
354 if(dc->funcs->pFillPath)
355 return dc->funcs->pFillPath(dc->physDev);
357 /* Check that path is closed */
358 if(pPath->state!=PATH_Closed)
360 SetLastError(ERROR_CAN_NOT_COMPLETE);
364 /* Construct a region from the path and fill it */
365 if(PATH_PathToRegion(pPath, dc->polyFillMode, &hrgn))
367 /* Since PaintRgn interprets the region as being in logical coordinates
368 * but the points we store for the path are already in device
369 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
370 * Using SaveDC to save information about the mapping mode / world
371 * transform would be easier but would require more overhead, especially
372 * now that SaveDC saves the current path.
375 /* Save the information about the old mapping mode */
376 mapMode=GetMapMode(dc->hSelf);
377 GetViewportExtEx(dc->hSelf, &ptViewportExt);
378 GetViewportOrgEx(dc->hSelf, &ptViewportOrg);
379 GetWindowExtEx(dc->hSelf, &ptWindowExt);
380 GetWindowOrgEx(dc->hSelf, &ptWindowOrg);
382 /* Save world transform
383 * NB: The Windows documentation on world transforms would lead one to
384 * believe that this has to be done only in GM_ADVANCED; however, my
385 * tests show that resetting the graphics mode to GM_COMPATIBLE does
386 * not reset the world transform.
388 GetWorldTransform(dc->hSelf, &xform);
391 SetMapMode(dc->hSelf, MM_TEXT);
392 SetViewportOrgEx(dc->hSelf, 0, 0, NULL);
393 SetWindowOrgEx(dc->hSelf, 0, 0, NULL);
394 graphicsMode=GetGraphicsMode(dc->hSelf);
395 SetGraphicsMode(dc->hSelf, GM_ADVANCED);
396 ModifyWorldTransform(dc->hSelf, &xform, MWT_IDENTITY);
397 SetGraphicsMode(dc->hSelf, graphicsMode);
399 /* Paint the region */
400 PaintRgn(dc->hSelf, hrgn);
402 /* Restore the old mapping mode */
403 SetMapMode(dc->hSelf, mapMode);
404 SetViewportExtEx(dc->hSelf, ptViewportExt.cx, ptViewportExt.cy, NULL);
405 SetViewportOrgEx(dc->hSelf, ptViewportOrg.x, ptViewportOrg.y, NULL);
406 SetWindowExtEx(dc->hSelf, ptWindowExt.cx, ptWindowExt.cy, NULL);
407 SetWindowOrgEx(dc->hSelf, ptWindowOrg.x, ptWindowOrg.y, NULL);
409 /* Go to GM_ADVANCED temporarily to restore the world transform */
410 graphicsMode=GetGraphicsMode(dc->hSelf);
411 SetGraphicsMode(dc->hSelf, GM_ADVANCED);
412 SetWorldTransform(dc->hSelf, &xform);
413 SetGraphicsMode(dc->hSelf, graphicsMode);
420 /***********************************************************************
424 * Check that SetLastError is being called correctly
426 BOOL WINAPI FillPath(HDC hdc)
428 DC *dc = DC_GetDCPtr( hdc );
431 if(!dc) return FALSE;
433 if(dc->funcs->pFillPath)
434 bRet = dc->funcs->pFillPath(dc->physDev);
437 bRet = PATH_FillPath(dc, &dc->path);
440 /* FIXME: Should the path be emptied even if conversion
442 PATH_EmptyPath(&dc->path);
445 GDI_ReleaseObj( hdc );
450 /***********************************************************************
451 * SelectClipPath (GDI32.@)
453 * Check that SetLastError is being called correctly
455 BOOL WINAPI SelectClipPath(HDC hdc, INT iMode)
459 BOOL success = FALSE;
460 DC *dc = DC_GetDCPtr( hdc );
462 if(!dc) return FALSE;
464 if(dc->funcs->pSelectClipPath)
465 success = dc->funcs->pSelectClipPath(dc->physDev, iMode);
470 /* Check that path is closed */
471 if(pPath->state!=PATH_Closed)
472 SetLastError(ERROR_CAN_NOT_COMPLETE);
473 /* Construct a region from the path */
474 else if(PATH_PathToRegion(pPath, GetPolyFillMode(hdc), &hrgnPath))
476 success = ExtSelectClipRgn( hdc, hrgnPath, iMode ) != ERROR;
477 DeleteObject(hrgnPath);
481 PATH_EmptyPath(pPath);
482 /* FIXME: Should this function delete the path even if it failed? */
485 GDI_ReleaseObj( hdc );
490 /***********************************************************************
496 * Initializes the GdiPath structure.
498 void PATH_InitGdiPath(GdiPath *pPath)
502 pPath->state=PATH_Null;
505 pPath->numEntriesUsed=0;
506 pPath->numEntriesAllocated=0;
509 /* PATH_DestroyGdiPath
511 * Destroys a GdiPath structure (frees the memory in the arrays).
513 void PATH_DestroyGdiPath(GdiPath *pPath)
517 HeapFree( GetProcessHeap(), 0, pPath->pPoints );
518 HeapFree( GetProcessHeap(), 0, pPath->pFlags );
521 /* PATH_AssignGdiPath
523 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
524 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
525 * not just the pointers. Since this means that the arrays in pPathDest may
526 * need to be resized, pPathDest should have been initialized using
527 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
528 * not a copy constructor).
529 * Returns TRUE if successful, else FALSE.
531 BOOL PATH_AssignGdiPath(GdiPath *pPathDest, const GdiPath *pPathSrc)
533 assert(pPathDest!=NULL && pPathSrc!=NULL);
535 /* Make sure destination arrays are big enough */
536 if(!PATH_ReserveEntries(pPathDest, pPathSrc->numEntriesUsed))
539 /* Perform the copy operation */
540 memcpy(pPathDest->pPoints, pPathSrc->pPoints,
541 sizeof(POINT)*pPathSrc->numEntriesUsed);
542 memcpy(pPathDest->pFlags, pPathSrc->pFlags,
543 sizeof(BYTE)*pPathSrc->numEntriesUsed);
545 pPathDest->state=pPathSrc->state;
546 pPathDest->numEntriesUsed=pPathSrc->numEntriesUsed;
547 pPathDest->newStroke=pPathSrc->newStroke;
554 * Should be called when a MoveTo is performed on a DC that has an
555 * open path. This starts a new stroke. Returns TRUE if successful, else
558 BOOL PATH_MoveTo(DC *dc)
560 GdiPath *pPath = &dc->path;
562 /* Check that path is open */
563 if(pPath->state!=PATH_Open)
564 /* FIXME: Do we have to call SetLastError? */
567 /* Start a new stroke */
568 pPath->newStroke=TRUE;
575 * Should be called when a LineTo is performed on a DC that has an
576 * open path. This adds a PT_LINETO entry to the path (and possibly
577 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
578 * Returns TRUE if successful, else FALSE.
580 BOOL PATH_LineTo(DC *dc, INT x, INT y)
582 GdiPath *pPath = &dc->path;
583 POINT point, pointCurPos;
585 /* Check that path is open */
586 if(pPath->state!=PATH_Open)
589 /* Convert point to device coordinates */
592 if(!LPtoDP(dc->hSelf, &point, 1))
595 /* Add a PT_MOVETO if necessary */
598 pPath->newStroke=FALSE;
599 pointCurPos.x = dc->CursPosX;
600 pointCurPos.y = dc->CursPosY;
601 if(!LPtoDP(dc->hSelf, &pointCurPos, 1))
603 if(!PATH_AddEntry(pPath, &pointCurPos, PT_MOVETO))
607 /* Add a PT_LINETO entry */
608 return PATH_AddEntry(pPath, &point, PT_LINETO);
613 * Should be called when a call to RoundRect is performed on a DC that has
614 * an open path. Returns TRUE if successful, else FALSE.
616 * FIXME: it adds the same entries to the path as windows does, but there
617 * is an error in the bezier drawing code so that there are small pixel-size
618 * gaps when the resulting path is drawn by StrokePath()
620 BOOL PATH_RoundRect(DC *dc, INT x1, INT y1, INT x2, INT y2, INT ell_width, INT ell_height)
622 GdiPath *pPath = &dc->path;
623 POINT corners[2], pointTemp;
624 FLOAT_POINT ellCorners[2];
626 /* Check that path is open */
627 if(pPath->state!=PATH_Open)
630 if(!PATH_CheckCorners(dc,corners,x1,y1,x2,y2))
633 /* Add points to the roundrect path */
634 ellCorners[0].x = corners[1].x-ell_width;
635 ellCorners[0].y = corners[0].y;
636 ellCorners[1].x = corners[1].x;
637 ellCorners[1].y = corners[0].y+ell_height;
638 if(!PATH_DoArcPart(pPath, ellCorners, 0, -M_PI_2, TRUE))
640 pointTemp.x = corners[0].x+ell_width/2;
641 pointTemp.y = corners[0].y;
642 if(!PATH_AddEntry(pPath, &pointTemp, PT_LINETO))
644 ellCorners[0].x = corners[0].x;
645 ellCorners[1].x = corners[0].x+ell_width;
646 if(!PATH_DoArcPart(pPath, ellCorners, -M_PI_2, -M_PI, FALSE))
648 pointTemp.x = corners[0].x;
649 pointTemp.y = corners[1].y-ell_height/2;
650 if(!PATH_AddEntry(pPath, &pointTemp, PT_LINETO))
652 ellCorners[0].y = corners[1].y-ell_height;
653 ellCorners[1].y = corners[1].y;
654 if(!PATH_DoArcPart(pPath, ellCorners, M_PI, M_PI_2, FALSE))
656 pointTemp.x = corners[1].x-ell_width/2;
657 pointTemp.y = corners[1].y;
658 if(!PATH_AddEntry(pPath, &pointTemp, PT_LINETO))
660 ellCorners[0].x = corners[1].x-ell_width;
661 ellCorners[1].x = corners[1].x;
662 if(!PATH_DoArcPart(pPath, ellCorners, M_PI_2, 0, FALSE))
665 /* Close the roundrect figure */
666 if(!CloseFigure(dc->hSelf))
674 * Should be called when a call to Rectangle is performed on a DC that has
675 * an open path. Returns TRUE if successful, else FALSE.
677 BOOL PATH_Rectangle(DC *dc, INT x1, INT y1, INT x2, INT y2)
679 GdiPath *pPath = &dc->path;
680 POINT corners[2], pointTemp;
682 /* Check that path is open */
683 if(pPath->state!=PATH_Open)
686 if(!PATH_CheckCorners(dc,corners,x1,y1,x2,y2))
689 /* Close any previous figure */
690 if(!CloseFigure(dc->hSelf))
692 /* The CloseFigure call shouldn't have failed */
697 /* Add four points to the path */
698 pointTemp.x=corners[1].x;
699 pointTemp.y=corners[0].y;
700 if(!PATH_AddEntry(pPath, &pointTemp, PT_MOVETO))
702 if(!PATH_AddEntry(pPath, corners, PT_LINETO))
704 pointTemp.x=corners[0].x;
705 pointTemp.y=corners[1].y;
706 if(!PATH_AddEntry(pPath, &pointTemp, PT_LINETO))
708 if(!PATH_AddEntry(pPath, corners+1, PT_LINETO))
711 /* Close the rectangle figure */
712 if(!CloseFigure(dc->hSelf))
714 /* The CloseFigure call shouldn't have failed */
724 * Should be called when a call to Ellipse is performed on a DC that has
725 * an open path. This adds four Bezier splines representing the ellipse
726 * to the path. Returns TRUE if successful, else FALSE.
728 BOOL PATH_Ellipse(DC *dc, INT x1, INT y1, INT x2, INT y2)
730 return( PATH_Arc(dc, x1, y1, x2, y2, x1, (y1+y2)/2, x1, (y1+y2)/2,0) &&
731 CloseFigure(dc->hSelf) );
736 * Should be called when a call to Arc is performed on a DC that has
737 * an open path. This adds up to five Bezier splines representing the arc
738 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
739 * and when 'lines' is 2, we add 2 extra lines to get a pie.
740 * Returns TRUE if successful, else FALSE.
742 BOOL PATH_Arc(DC *dc, INT x1, INT y1, INT x2, INT y2,
743 INT xStart, INT yStart, INT xEnd, INT yEnd, INT lines)
745 GdiPath *pPath = &dc->path;
746 double angleStart, angleEnd, angleStartQuadrant, angleEndQuadrant=0.0;
747 /* Initialize angleEndQuadrant to silence gcc's warning */
749 FLOAT_POINT corners[2], pointStart, pointEnd;
754 /* FIXME: This function should check for all possible error returns */
755 /* FIXME: Do we have to respect newStroke? */
757 /* Check that path is open */
758 if(pPath->state!=PATH_Open)
761 /* Check for zero height / width */
762 /* FIXME: Only in GM_COMPATIBLE? */
766 /* Convert points to device coordinates */
767 corners[0].x=(FLOAT)x1;
768 corners[0].y=(FLOAT)y1;
769 corners[1].x=(FLOAT)x2;
770 corners[1].y=(FLOAT)y2;
771 pointStart.x=(FLOAT)xStart;
772 pointStart.y=(FLOAT)yStart;
773 pointEnd.x=(FLOAT)xEnd;
774 pointEnd.y=(FLOAT)yEnd;
775 INTERNAL_LPTODP_FLOAT(dc, corners);
776 INTERNAL_LPTODP_FLOAT(dc, corners+1);
777 INTERNAL_LPTODP_FLOAT(dc, &pointStart);
778 INTERNAL_LPTODP_FLOAT(dc, &pointEnd);
780 /* Make sure first corner is top left and second corner is bottom right */
781 if(corners[0].x>corners[1].x)
784 corners[0].x=corners[1].x;
787 if(corners[0].y>corners[1].y)
790 corners[0].y=corners[1].y;
794 /* Compute start and end angle */
795 PATH_NormalizePoint(corners, &pointStart, &x, &y);
796 angleStart=atan2(y, x);
797 PATH_NormalizePoint(corners, &pointEnd, &x, &y);
798 angleEnd=atan2(y, x);
800 /* Make sure the end angle is "on the right side" of the start angle */
801 if(dc->ArcDirection==AD_CLOCKWISE)
803 if(angleEnd<=angleStart)
806 assert(angleEnd>=angleStart);
811 if(angleEnd>=angleStart)
814 assert(angleEnd<=angleStart);
818 /* In GM_COMPATIBLE, don't include bottom and right edges */
819 if(dc->GraphicsMode==GM_COMPATIBLE)
825 /* Add the arc to the path with one Bezier spline per quadrant that the
831 /* Determine the start and end angles for this quadrant */
834 angleStartQuadrant=angleStart;
835 if(dc->ArcDirection==AD_CLOCKWISE)
836 angleEndQuadrant=(floor(angleStart/M_PI_2)+1.0)*M_PI_2;
838 angleEndQuadrant=(ceil(angleStart/M_PI_2)-1.0)*M_PI_2;
842 angleStartQuadrant=angleEndQuadrant;
843 if(dc->ArcDirection==AD_CLOCKWISE)
844 angleEndQuadrant+=M_PI_2;
846 angleEndQuadrant-=M_PI_2;
849 /* Have we reached the last part of the arc? */
850 if((dc->ArcDirection==AD_CLOCKWISE &&
851 angleEnd<angleEndQuadrant) ||
852 (dc->ArcDirection==AD_COUNTERCLOCKWISE &&
853 angleEnd>angleEndQuadrant))
855 /* Adjust the end angle for this quadrant */
856 angleEndQuadrant=angleEnd;
860 /* Add the Bezier spline to the path */
861 PATH_DoArcPart(pPath, corners, angleStartQuadrant, angleEndQuadrant,
866 /* chord: close figure. pie: add line and close figure */
869 if(!CloseFigure(dc->hSelf))
874 centre.x = (corners[0].x+corners[1].x)/2;
875 centre.y = (corners[0].y+corners[1].y)/2;
876 if(!PATH_AddEntry(pPath, ¢re, PT_LINETO | PT_CLOSEFIGURE))
883 BOOL PATH_PolyBezierTo(DC *dc, const POINT *pts, DWORD cbPoints)
885 GdiPath *pPath = &dc->path;
889 /* Check that path is open */
890 if(pPath->state!=PATH_Open)
893 /* Add a PT_MOVETO if necessary */
896 pPath->newStroke=FALSE;
899 if(!LPtoDP(dc->hSelf, &pt, 1))
901 if(!PATH_AddEntry(pPath, &pt, PT_MOVETO))
905 for(i = 0; i < cbPoints; i++) {
907 if(!LPtoDP(dc->hSelf, &pt, 1))
909 PATH_AddEntry(pPath, &pt, PT_BEZIERTO);
914 BOOL PATH_PolyBezier(DC *dc, const POINT *pts, DWORD cbPoints)
916 GdiPath *pPath = &dc->path;
920 /* Check that path is open */
921 if(pPath->state!=PATH_Open)
924 for(i = 0; i < cbPoints; i++) {
926 if(!LPtoDP(dc->hSelf, &pt, 1))
928 PATH_AddEntry(pPath, &pt, (i == 0) ? PT_MOVETO : PT_BEZIERTO);
933 BOOL PATH_Polyline(DC *dc, const POINT *pts, DWORD cbPoints)
935 GdiPath *pPath = &dc->path;
939 /* Check that path is open */
940 if(pPath->state!=PATH_Open)
943 for(i = 0; i < cbPoints; i++) {
945 if(!LPtoDP(dc->hSelf, &pt, 1))
947 PATH_AddEntry(pPath, &pt, (i == 0) ? PT_MOVETO : PT_LINETO);
952 BOOL PATH_PolylineTo(DC *dc, const POINT *pts, DWORD cbPoints)
954 GdiPath *pPath = &dc->path;
958 /* Check that path is open */
959 if(pPath->state!=PATH_Open)
962 /* Add a PT_MOVETO if necessary */
965 pPath->newStroke=FALSE;
968 if(!LPtoDP(dc->hSelf, &pt, 1))
970 if(!PATH_AddEntry(pPath, &pt, PT_MOVETO))
974 for(i = 0; i < cbPoints; i++) {
976 if(!LPtoDP(dc->hSelf, &pt, 1))
978 PATH_AddEntry(pPath, &pt, PT_LINETO);
985 BOOL PATH_Polygon(DC *dc, const POINT *pts, DWORD cbPoints)
987 GdiPath *pPath = &dc->path;
991 /* Check that path is open */
992 if(pPath->state!=PATH_Open)
995 for(i = 0; i < cbPoints; i++) {
997 if(!LPtoDP(dc->hSelf, &pt, 1))
999 PATH_AddEntry(pPath, &pt, (i == 0) ? PT_MOVETO :
1000 ((i == cbPoints-1) ? PT_LINETO | PT_CLOSEFIGURE :
1006 BOOL PATH_PolyPolygon( DC *dc, const POINT* pts, const INT* counts,
1009 GdiPath *pPath = &dc->path;
1014 /* Check that path is open */
1015 if(pPath->state!=PATH_Open)
1018 for(i = 0, poly = 0; poly < polygons; poly++) {
1019 for(point = 0; point < counts[poly]; point++, i++) {
1021 if(!LPtoDP(dc->hSelf, &pt, 1))
1023 if(point == 0) startpt = pt;
1024 PATH_AddEntry(pPath, &pt, (point == 0) ? PT_MOVETO : PT_LINETO);
1026 /* win98 adds an extra line to close the figure for some reason */
1027 PATH_AddEntry(pPath, &startpt, PT_LINETO | PT_CLOSEFIGURE);
1032 BOOL PATH_PolyPolyline( DC *dc, const POINT* pts, const DWORD* counts,
1035 GdiPath *pPath = &dc->path;
1037 UINT poly, point, i;
1039 /* Check that path is open */
1040 if(pPath->state!=PATH_Open)
1043 for(i = 0, poly = 0; poly < polylines; poly++) {
1044 for(point = 0; point < counts[poly]; point++, i++) {
1046 if(!LPtoDP(dc->hSelf, &pt, 1))
1048 PATH_AddEntry(pPath, &pt, (point == 0) ? PT_MOVETO : PT_LINETO);
1054 /***********************************************************************
1055 * Internal functions
1058 /* PATH_CheckCorners
1060 * Helper function for PATH_RoundRect() and PATH_Rectangle()
1062 static BOOL PATH_CheckCorners(DC *dc, POINT corners[], INT x1, INT y1, INT x2, INT y2)
1066 /* Convert points to device coordinates */
1071 if(!LPtoDP(dc->hSelf, corners, 2))
1074 /* Make sure first corner is top left and second corner is bottom right */
1075 if(corners[0].x>corners[1].x)
1078 corners[0].x=corners[1].x;
1081 if(corners[0].y>corners[1].y)
1084 corners[0].y=corners[1].y;
1088 /* In GM_COMPATIBLE, don't include bottom and right edges */
1089 if(dc->GraphicsMode==GM_COMPATIBLE)
1098 /* PATH_AddFlatBezier
1100 static BOOL PATH_AddFlatBezier(GdiPath *pPath, POINT *pt, BOOL closed)
1105 pts = GDI_Bezier( pt, 4, &no );
1106 if(!pts) return FALSE;
1108 for(i = 1; i < no; i++)
1109 PATH_AddEntry(pPath, &pts[i],
1110 (i == no-1 && closed) ? PT_LINETO | PT_CLOSEFIGURE : PT_LINETO);
1111 HeapFree( GetProcessHeap(), 0, pts );
1117 * Replaces Beziers with line segments
1120 static BOOL PATH_FlattenPath(GdiPath *pPath)
1125 memset(&newPath, 0, sizeof(newPath));
1126 newPath.state = PATH_Open;
1127 for(srcpt = 0; srcpt < pPath->numEntriesUsed; srcpt++) {
1128 switch(pPath->pFlags[srcpt] & ~PT_CLOSEFIGURE) {
1131 PATH_AddEntry(&newPath, &pPath->pPoints[srcpt],
1132 pPath->pFlags[srcpt]);
1135 PATH_AddFlatBezier(&newPath, &pPath->pPoints[srcpt-1],
1136 pPath->pFlags[srcpt+2] & PT_CLOSEFIGURE);
1141 newPath.state = PATH_Closed;
1142 PATH_AssignGdiPath(pPath, &newPath);
1143 PATH_DestroyGdiPath(&newPath);
1147 /* PATH_PathToRegion
1149 * Creates a region from the specified path using the specified polygon
1150 * filling mode. The path is left unchanged. A handle to the region that
1151 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1152 * error occurs, SetLastError is called with the appropriate value and
1153 * FALSE is returned.
1155 static BOOL PATH_PathToRegion(GdiPath *pPath, INT nPolyFillMode,
1158 int numStrokes, iStroke, i;
1159 INT *pNumPointsInStroke;
1162 assert(pPath!=NULL);
1163 assert(pHrgn!=NULL);
1165 PATH_FlattenPath(pPath);
1167 /* FIXME: What happens when number of points is zero? */
1169 /* First pass: Find out how many strokes there are in the path */
1170 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1172 for(i=0; i<pPath->numEntriesUsed; i++)
1173 if((pPath->pFlags[i] & ~PT_CLOSEFIGURE) == PT_MOVETO)
1176 /* Allocate memory for number-of-points-in-stroke array */
1177 pNumPointsInStroke=HeapAlloc( GetProcessHeap(), 0, sizeof(int) * numStrokes );
1178 if(!pNumPointsInStroke)
1180 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1184 /* Second pass: remember number of points in each polygon */
1185 iStroke=-1; /* Will get incremented to 0 at beginning of first stroke */
1186 for(i=0; i<pPath->numEntriesUsed; i++)
1188 /* Is this the beginning of a new stroke? */
1189 if((pPath->pFlags[i] & ~PT_CLOSEFIGURE) == PT_MOVETO)
1192 pNumPointsInStroke[iStroke]=0;
1195 pNumPointsInStroke[iStroke]++;
1198 /* Create a region from the strokes */
1199 hrgn=CreatePolyPolygonRgn(pPath->pPoints, pNumPointsInStroke,
1200 numStrokes, nPolyFillMode);
1202 /* Free memory for number-of-points-in-stroke array */
1203 HeapFree( GetProcessHeap(), 0, pNumPointsInStroke );
1207 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1216 static inline INT int_from_fixed(FIXED f)
1218 return (f.fract >= 0x8000) ? (f.value + 1) : f.value;
1221 /**********************************************************************
1224 * internally used by PATH_add_outline
1226 static void PATH_BezierTo(GdiPath *pPath, POINT *lppt, INT n)
1232 PATH_AddEntry(pPath, &lppt[1], PT_LINETO);
1236 PATH_AddEntry(pPath, &lppt[0], PT_BEZIERTO);
1237 PATH_AddEntry(pPath, &lppt[1], PT_BEZIERTO);
1238 PATH_AddEntry(pPath, &lppt[2], PT_BEZIERTO);
1252 pt[2].x = (lppt[i+2].x + lppt[i+1].x) / 2;
1253 pt[2].y = (lppt[i+2].y + lppt[i+1].y) / 2;
1254 PATH_BezierTo(pPath, pt, 3);
1262 PATH_BezierTo(pPath, pt, 3);
1266 static BOOL PATH_add_outline(DC *dc, INT x, INT y, TTPOLYGONHEADER *header, DWORD size)
1268 GdiPath *pPath = &dc->path;
1269 TTPOLYGONHEADER *start;
1274 while ((char *)header < (char *)start + size)
1278 if (header->dwType != TT_POLYGON_TYPE)
1280 FIXME("Unknown header type %d\n", header->dwType);
1284 pt.x = x + int_from_fixed(header->pfxStart.x);
1285 pt.y = y - int_from_fixed(header->pfxStart.y);
1286 LPtoDP(dc->hSelf, &pt, 1);
1287 PATH_AddEntry(pPath, &pt, PT_MOVETO);
1289 curve = (TTPOLYCURVE *)(header + 1);
1291 while ((char *)curve < (char *)header + header->cb)
1293 /*TRACE("curve->wType %d\n", curve->wType);*/
1295 switch(curve->wType)
1301 for (i = 0; i < curve->cpfx; i++)
1303 pt.x = x + int_from_fixed(curve->apfx[i].x);
1304 pt.y = y - int_from_fixed(curve->apfx[i].y);
1305 LPtoDP(dc->hSelf, &pt, 1);
1306 PATH_AddEntry(pPath, &pt, PT_LINETO);
1311 case TT_PRIM_QSPLINE:
1312 case TT_PRIM_CSPLINE:
1316 POINT *pts = HeapAlloc(GetProcessHeap(), 0, (curve->cpfx + 1) * sizeof(POINT));
1318 if (!pts) return FALSE;
1320 ptfx = *(POINTFX *)((char *)curve - sizeof(POINTFX));
1322 pts[0].x = x + int_from_fixed(ptfx.x);
1323 pts[0].y = y - int_from_fixed(ptfx.y);
1324 LPtoDP(dc->hSelf, &pts[0], 1);
1326 for(i = 0; i < curve->cpfx; i++)
1328 pts[i + 1].x = x + int_from_fixed(curve->apfx[i].x);
1329 pts[i + 1].y = y - int_from_fixed(curve->apfx[i].y);
1330 LPtoDP(dc->hSelf, &pts[i + 1], 1);
1333 PATH_BezierTo(pPath, pts, curve->cpfx + 1);
1335 HeapFree(GetProcessHeap(), 0, pts);
1340 FIXME("Unknown curve type %04x\n", curve->wType);
1344 curve = (TTPOLYCURVE *)&curve->apfx[curve->cpfx];
1347 header = (TTPOLYGONHEADER *)((char *)header + header->cb);
1350 return CloseFigure(dc->hSelf);
1353 /**********************************************************************
1356 BOOL PATH_ExtTextOut(DC *dc, INT x, INT y, UINT flags, const RECT *lprc,
1357 LPCWSTR str, UINT count, const INT *dx)
1360 double cosEsc, sinEsc;
1363 HDC hdc = dc->hSelf;
1365 TRACE("%p, %d, %d, %08x, %s, %s, %d, %p)\n", hdc, x, y, flags,
1366 wine_dbgstr_rect(lprc), debugstr_wn(str, count), count, dx);
1368 if (!count) return TRUE;
1370 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
1372 if (lf.lfEscapement != 0)
1374 cosEsc = cos(lf.lfEscapement * M_PI / 1800);
1375 sinEsc = sin(lf.lfEscapement * M_PI / 1800);
1382 GetDCOrgEx(hdc, &org);
1384 for (idx = 0; idx < count; idx++)
1386 INT offset = 0, xoff = 0, yoff = 0;
1391 dwSize = GetGlyphOutlineW(hdc, str[idx], GGO_GLYPH_INDEX | GGO_NATIVE, &gm, 0, NULL, NULL);
1392 if (!dwSize) return FALSE;
1394 outline = HeapAlloc(GetProcessHeap(), 0, dwSize);
1395 if (!outline) return FALSE;
1397 GetGlyphOutlineW(hdc, str[idx], GGO_GLYPH_INDEX | GGO_NATIVE, &gm, dwSize, outline, NULL);
1399 PATH_add_outline(dc, org.x + x + xoff, org.x + y + yoff, outline, dwSize);
1401 HeapFree(GetProcessHeap(), 0, outline);
1406 xoff = offset * cosEsc;
1407 yoff = offset * -sinEsc;
1411 xoff += gm.gmCellIncX;
1412 yoff += gm.gmCellIncY;
1420 * Removes all entries from the path and sets the path state to PATH_Null.
1422 static void PATH_EmptyPath(GdiPath *pPath)
1424 assert(pPath!=NULL);
1426 pPath->state=PATH_Null;
1427 pPath->numEntriesUsed=0;
1432 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1433 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1434 * successful, FALSE otherwise (e.g. if not enough memory was available).
1436 BOOL PATH_AddEntry(GdiPath *pPath, const POINT *pPoint, BYTE flags)
1438 assert(pPath!=NULL);
1440 /* FIXME: If newStroke is true, perhaps we want to check that we're
1441 * getting a PT_MOVETO
1443 TRACE("(%d,%d) - %d\n", pPoint->x, pPoint->y, flags);
1445 /* Check that path is open */
1446 if(pPath->state!=PATH_Open)
1449 /* Reserve enough memory for an extra path entry */
1450 if(!PATH_ReserveEntries(pPath, pPath->numEntriesUsed+1))
1453 /* Store information in path entry */
1454 pPath->pPoints[pPath->numEntriesUsed]=*pPoint;
1455 pPath->pFlags[pPath->numEntriesUsed]=flags;
1457 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1458 if((flags & PT_CLOSEFIGURE) == PT_CLOSEFIGURE)
1459 pPath->newStroke=TRUE;
1461 /* Increment entry count */
1462 pPath->numEntriesUsed++;
1467 /* PATH_ReserveEntries
1469 * Ensures that at least "numEntries" entries (for points and flags) have
1470 * been allocated; allocates larger arrays and copies the existing entries
1471 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1473 static BOOL PATH_ReserveEntries(GdiPath *pPath, INT numEntries)
1475 INT numEntriesToAllocate;
1479 assert(pPath!=NULL);
1480 assert(numEntries>=0);
1482 /* Do we have to allocate more memory? */
1483 if(numEntries > pPath->numEntriesAllocated)
1485 /* Find number of entries to allocate. We let the size of the array
1486 * grow exponentially, since that will guarantee linear time
1488 if(pPath->numEntriesAllocated)
1490 numEntriesToAllocate=pPath->numEntriesAllocated;
1491 while(numEntriesToAllocate<numEntries)
1492 numEntriesToAllocate=numEntriesToAllocate*GROW_FACTOR_NUMER/
1496 numEntriesToAllocate=numEntries;
1498 /* Allocate new arrays */
1499 pPointsNew=HeapAlloc( GetProcessHeap(), 0, numEntriesToAllocate * sizeof(POINT) );
1502 pFlagsNew=HeapAlloc( GetProcessHeap(), 0, numEntriesToAllocate * sizeof(BYTE) );
1505 HeapFree( GetProcessHeap(), 0, pPointsNew );
1509 /* Copy old arrays to new arrays and discard old arrays */
1512 assert(pPath->pFlags);
1514 memcpy(pPointsNew, pPath->pPoints,
1515 sizeof(POINT)*pPath->numEntriesUsed);
1516 memcpy(pFlagsNew, pPath->pFlags,
1517 sizeof(BYTE)*pPath->numEntriesUsed);
1519 HeapFree( GetProcessHeap(), 0, pPath->pPoints );
1520 HeapFree( GetProcessHeap(), 0, pPath->pFlags );
1522 pPath->pPoints=pPointsNew;
1523 pPath->pFlags=pFlagsNew;
1524 pPath->numEntriesAllocated=numEntriesToAllocate;
1532 * Creates a Bezier spline that corresponds to part of an arc and appends the
1533 * corresponding points to the path. The start and end angles are passed in
1534 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1535 * at most. If "addMoveTo" is true, a PT_MOVETO entry for the first control
1536 * point is added to the path; otherwise, it is assumed that the current
1537 * position is equal to the first control point.
1539 static BOOL PATH_DoArcPart(GdiPath *pPath, FLOAT_POINT corners[],
1540 double angleStart, double angleEnd, BOOL addMoveTo)
1542 double halfAngle, a;
1543 double xNorm[4], yNorm[4];
1547 assert(fabs(angleEnd-angleStart)<=M_PI_2);
1549 /* FIXME: Is there an easier way of computing this? */
1551 /* Compute control points */
1552 halfAngle=(angleEnd-angleStart)/2.0;
1553 if(fabs(halfAngle)>1e-8)
1555 a=4.0/3.0*(1-cos(halfAngle))/sin(halfAngle);
1556 xNorm[0]=cos(angleStart);
1557 yNorm[0]=sin(angleStart);
1558 xNorm[1]=xNorm[0] - a*yNorm[0];
1559 yNorm[1]=yNorm[0] + a*xNorm[0];
1560 xNorm[3]=cos(angleEnd);
1561 yNorm[3]=sin(angleEnd);
1562 xNorm[2]=xNorm[3] + a*yNorm[3];
1563 yNorm[2]=yNorm[3] - a*xNorm[3];
1568 xNorm[i]=cos(angleStart);
1569 yNorm[i]=sin(angleStart);
1572 /* Add starting point to path if desired */
1575 PATH_ScaleNormalizedPoint(corners, xNorm[0], yNorm[0], &point);
1576 if(!PATH_AddEntry(pPath, &point, PT_MOVETO))
1580 /* Add remaining control points */
1583 PATH_ScaleNormalizedPoint(corners, xNorm[i], yNorm[i], &point);
1584 if(!PATH_AddEntry(pPath, &point, PT_BEZIERTO))
1591 /* PATH_ScaleNormalizedPoint
1593 * Scales a normalized point (x, y) with respect to the box whose corners are
1594 * passed in "corners". The point is stored in "*pPoint". The normalized
1595 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1596 * (1.0, 1.0) correspond to corners[1].
1598 static void PATH_ScaleNormalizedPoint(FLOAT_POINT corners[], double x,
1599 double y, POINT *pPoint)
1601 pPoint->x=GDI_ROUND( (double)corners[0].x +
1602 (double)(corners[1].x-corners[0].x)*0.5*(x+1.0) );
1603 pPoint->y=GDI_ROUND( (double)corners[0].y +
1604 (double)(corners[1].y-corners[0].y)*0.5*(y+1.0) );
1607 /* PATH_NormalizePoint
1609 * Normalizes a point with respect to the box whose corners are passed in
1610 * "corners". The normalized coordinates are stored in "*pX" and "*pY".
1612 static void PATH_NormalizePoint(FLOAT_POINT corners[],
1613 const FLOAT_POINT *pPoint,
1614 double *pX, double *pY)
1616 *pX=(double)(pPoint->x-corners[0].x)/(double)(corners[1].x-corners[0].x) *
1618 *pY=(double)(pPoint->y-corners[0].y)/(double)(corners[1].y-corners[0].y) *
1623 /*******************************************************************
1624 * FlattenPath [GDI32.@]
1628 BOOL WINAPI FlattenPath(HDC hdc)
1631 DC *dc = DC_GetDCPtr( hdc );
1633 if(!dc) return FALSE;
1635 if(dc->funcs->pFlattenPath) ret = dc->funcs->pFlattenPath(dc->physDev);
1638 GdiPath *pPath = &dc->path;
1639 if(pPath->state != PATH_Closed)
1640 ret = PATH_FlattenPath(pPath);
1642 GDI_ReleaseObj( hdc );
1647 static BOOL PATH_StrokePath(DC *dc, GdiPath *pPath)
1649 INT i, nLinePts, nAlloc;
1651 POINT ptViewportOrg, ptWindowOrg;
1652 SIZE szViewportExt, szWindowExt;
1653 DWORD mapMode, graphicsMode;
1657 if(dc->funcs->pStrokePath)
1658 return dc->funcs->pStrokePath(dc->physDev);
1660 if(pPath->state != PATH_Closed)
1663 /* Save the mapping mode info */
1664 mapMode=GetMapMode(dc->hSelf);
1665 GetViewportExtEx(dc->hSelf, &szViewportExt);
1666 GetViewportOrgEx(dc->hSelf, &ptViewportOrg);
1667 GetWindowExtEx(dc->hSelf, &szWindowExt);
1668 GetWindowOrgEx(dc->hSelf, &ptWindowOrg);
1669 GetWorldTransform(dc->hSelf, &xform);
1672 SetMapMode(dc->hSelf, MM_TEXT);
1673 SetViewportOrgEx(dc->hSelf, 0, 0, NULL);
1674 SetWindowOrgEx(dc->hSelf, 0, 0, NULL);
1675 graphicsMode=GetGraphicsMode(dc->hSelf);
1676 SetGraphicsMode(dc->hSelf, GM_ADVANCED);
1677 ModifyWorldTransform(dc->hSelf, &xform, MWT_IDENTITY);
1678 SetGraphicsMode(dc->hSelf, graphicsMode);
1680 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1681 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1682 * space in case we get one to keep the number of reallocations small. */
1683 nAlloc = pPath->numEntriesUsed + 1 + 300;
1684 pLinePts = HeapAlloc(GetProcessHeap(), 0, nAlloc * sizeof(POINT));
1687 for(i = 0; i < pPath->numEntriesUsed; i++) {
1688 if((i == 0 || (pPath->pFlags[i-1] & PT_CLOSEFIGURE)) &&
1689 (pPath->pFlags[i] != PT_MOVETO)) {
1690 ERR("Expected PT_MOVETO %s, got path flag %d\n",
1691 i == 0 ? "as first point" : "after PT_CLOSEFIGURE",
1692 (INT)pPath->pFlags[i]);
1696 switch(pPath->pFlags[i]) {
1698 TRACE("Got PT_MOVETO (%d, %d)\n",
1699 pPath->pPoints[i].x, pPath->pPoints[i].y);
1701 Polyline(dc->hSelf, pLinePts, nLinePts);
1703 pLinePts[nLinePts++] = pPath->pPoints[i];
1706 case (PT_LINETO | PT_CLOSEFIGURE):
1707 TRACE("Got PT_LINETO (%d, %d)\n",
1708 pPath->pPoints[i].x, pPath->pPoints[i].y);
1709 pLinePts[nLinePts++] = pPath->pPoints[i];
1712 TRACE("Got PT_BEZIERTO\n");
1713 if(pPath->pFlags[i+1] != PT_BEZIERTO ||
1714 (pPath->pFlags[i+2] & ~PT_CLOSEFIGURE) != PT_BEZIERTO) {
1715 ERR("Path didn't contain 3 successive PT_BEZIERTOs\n");
1719 INT nBzrPts, nMinAlloc;
1720 POINT *pBzrPts = GDI_Bezier(&pPath->pPoints[i-1], 4, &nBzrPts);
1721 /* Make sure we have allocated enough memory for the lines of
1722 * this bezier and the rest of the path, assuming we won't get
1723 * another one (since we won't reallocate again then). */
1724 nMinAlloc = nLinePts + (pPath->numEntriesUsed - i) + nBzrPts;
1725 if(nAlloc < nMinAlloc)
1727 nAlloc = nMinAlloc * 2;
1728 pLinePts = HeapReAlloc(GetProcessHeap(), 0, pLinePts,
1729 nAlloc * sizeof(POINT));
1731 memcpy(&pLinePts[nLinePts], &pBzrPts[1],
1732 (nBzrPts - 1) * sizeof(POINT));
1733 nLinePts += nBzrPts - 1;
1734 HeapFree(GetProcessHeap(), 0, pBzrPts);
1739 ERR("Got path flag %d\n", (INT)pPath->pFlags[i]);
1743 if(pPath->pFlags[i] & PT_CLOSEFIGURE)
1744 pLinePts[nLinePts++] = pLinePts[0];
1747 Polyline(dc->hSelf, pLinePts, nLinePts);
1750 HeapFree(GetProcessHeap(), 0, pLinePts);
1752 /* Restore the old mapping mode */
1753 SetMapMode(dc->hSelf, mapMode);
1754 SetWindowExtEx(dc->hSelf, szWindowExt.cx, szWindowExt.cy, NULL);
1755 SetWindowOrgEx(dc->hSelf, ptWindowOrg.x, ptWindowOrg.y, NULL);
1756 SetViewportExtEx(dc->hSelf, szViewportExt.cx, szViewportExt.cy, NULL);
1757 SetViewportOrgEx(dc->hSelf, ptViewportOrg.x, ptViewportOrg.y, NULL);
1759 /* Go to GM_ADVANCED temporarily to restore the world transform */
1760 graphicsMode=GetGraphicsMode(dc->hSelf);
1761 SetGraphicsMode(dc->hSelf, GM_ADVANCED);
1762 SetWorldTransform(dc->hSelf, &xform);
1763 SetGraphicsMode(dc->hSelf, graphicsMode);
1765 /* If we've moved the current point then get its new position
1766 which will be in device (MM_TEXT) co-ords, convert it to
1767 logical co-ords and re-set it. This basically updates
1768 dc->CurPosX|Y so that their values are in the correct mapping
1773 GetCurrentPositionEx(dc->hSelf, &pt);
1774 DPtoLP(dc->hSelf, &pt, 1);
1775 MoveToEx(dc->hSelf, pt.x, pt.y, NULL);
1782 /*******************************************************************
1783 * StrokeAndFillPath [GDI32.@]
1787 BOOL WINAPI StrokeAndFillPath(HDC hdc)
1789 DC *dc = DC_GetDCPtr( hdc );
1792 if(!dc) return FALSE;
1794 if(dc->funcs->pStrokeAndFillPath)
1795 bRet = dc->funcs->pStrokeAndFillPath(dc->physDev);
1798 bRet = PATH_FillPath(dc, &dc->path);
1799 if(bRet) bRet = PATH_StrokePath(dc, &dc->path);
1800 if(bRet) PATH_EmptyPath(&dc->path);
1802 GDI_ReleaseObj( hdc );
1807 /*******************************************************************
1808 * StrokePath [GDI32.@]
1812 BOOL WINAPI StrokePath(HDC hdc)
1814 DC *dc = DC_GetDCPtr( hdc );
1818 TRACE("(%p)\n", hdc);
1819 if(!dc) return FALSE;
1821 if(dc->funcs->pStrokePath)
1822 bRet = dc->funcs->pStrokePath(dc->physDev);
1826 bRet = PATH_StrokePath(dc, pPath);
1827 PATH_EmptyPath(pPath);
1829 GDI_ReleaseObj( hdc );
1834 /*******************************************************************
1835 * WidenPath [GDI32.@]
1839 BOOL WINAPI WidenPath(HDC hdc)
1841 DC *dc = DC_GetDCPtr( hdc );
1844 if(!dc) return FALSE;
1846 if(dc->funcs->pWidenPath)
1847 ret = dc->funcs->pWidenPath(dc->physDev);
1850 GDI_ReleaseObj( hdc );