2 * Graphics paths (BeginPath, EndPath etc.)
4 * Copyright 1997, 1998 Martin Boehme
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
29 #if defined(HAVE_FLOAT_H)
39 #include "gdi_private.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
44 /* Notes on the implementation
46 * The implementation is based on dynamically resizable arrays of points and
47 * flags. I dithered for a bit before deciding on this implementation, and
48 * I had even done a bit of work on a linked list version before switching
49 * to arrays. It's a bit of a tradeoff. When you use linked lists, the
50 * implementation of FlattenPath is easier, because you can rip the
51 * PT_BEZIERTO entries out of the middle of the list and link the
52 * corresponding PT_LINETO entries in. However, when you use arrays,
53 * PathToRegion becomes easier, since you can essentially just pass your array
54 * of points to CreatePolyPolygonRgn. Also, if I'd used linked lists, I would
55 * have had the extra effort of creating a chunk-based allocation scheme
56 * in order to use memory effectively. That's why I finally decided to use
57 * arrays. Note by the way that the array based implementation has the same
58 * linear time complexity that linked lists would have since the arrays grow
61 * The points are stored in the path in device coordinates. This is
62 * consistent with the way Windows does things (for instance, see the Win32
63 * SDK documentation for GetPath).
65 * The word "stroke" appears in several places (e.g. in the flag
66 * GdiPath.newStroke). A stroke consists of a PT_MOVETO followed by one or
67 * more PT_LINETOs or PT_BEZIERTOs, up to, but not including, the next
68 * PT_MOVETO. Note that this is not the same as the definition of a figure;
69 * a figure can contain several strokes.
71 * I modified the drawing functions (MoveTo, LineTo etc.) to test whether
72 * the path is open and to call the corresponding function in path.c if this
73 * is the case. A more elegant approach would be to modify the function
74 * pointers in the DC_FUNCTIONS structure; however, this would be a lot more
75 * complex. Also, the performance degradation caused by my approach in the
76 * case where no path is open is so small that it cannot be measured.
81 /* FIXME: A lot of stuff isn't implemented yet. There is much more to come. */
83 #define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
84 #define GROW_FACTOR_NUMER 2 /* Numerator of grow factor for the array */
85 #define GROW_FACTOR_DENOM 1 /* Denominator of grow factor */
87 /* A floating point version of the POINT structure */
88 typedef struct tagFLOAT_POINT
94 static BOOL
PATH_PathToRegion(GdiPath
*pPath
, INT nPolyFillMode
,
96 static void PATH_EmptyPath(GdiPath
*pPath
);
97 static BOOL
PATH_ReserveEntries(GdiPath
*pPath
, INT numEntries
);
98 static BOOL
PATH_DoArcPart(GdiPath
*pPath
, FLOAT_POINT corners
[],
99 double angleStart
, double angleEnd
, BOOL addMoveTo
);
100 static void PATH_ScaleNormalizedPoint(FLOAT_POINT corners
[], double x
,
101 double y
, POINT
*pPoint
);
102 static void PATH_NormalizePoint(FLOAT_POINT corners
[], const FLOAT_POINT
103 *pPoint
, double *pX
, double *pY
);
104 static BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
);
106 /* Performs a world-to-viewport transformation on the specified point (which
107 * is in floating point format).
109 static inline void INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
113 /* Perform the transformation */
116 point
->x
= x
* dc
->xformWorld2Vport
.eM11
+
117 y
* dc
->xformWorld2Vport
.eM21
+
118 dc
->xformWorld2Vport
.eDx
;
119 point
->y
= x
* dc
->xformWorld2Vport
.eM12
+
120 y
* dc
->xformWorld2Vport
.eM22
+
121 dc
->xformWorld2Vport
.eDy
;
124 /* Performs a world-to-viewport transformation on the specified width.
126 static inline void INTERNAL_WSTODS(DC
*dc
, LONG
*width
)
129 pt
[0].x
= pt
[0].y
= 0;
132 LPtoDP(dc
->hSelf
, pt
, 2);
133 *width
= pt
[1].x
- pt
[0].x
;
136 /***********************************************************************
137 * BeginPath (GDI32.@)
139 BOOL WINAPI
BeginPath(HDC hdc
)
142 DC
*dc
= DC_GetDCPtr( hdc
);
144 if(!dc
) return FALSE
;
146 if(dc
->funcs
->pBeginPath
)
147 ret
= dc
->funcs
->pBeginPath(dc
->physDev
);
150 /* If path is already open, do nothing */
151 if(dc
->path
.state
!= PATH_Open
)
153 /* Make sure that path is empty */
154 PATH_EmptyPath(&dc
->path
);
156 /* Initialize variables for new path */
157 dc
->path
.newStroke
=TRUE
;
158 dc
->path
.state
=PATH_Open
;
161 GDI_ReleaseObj( hdc
);
166 /***********************************************************************
169 BOOL WINAPI
EndPath(HDC hdc
)
172 DC
*dc
= DC_GetDCPtr( hdc
);
174 if(!dc
) return FALSE
;
176 if(dc
->funcs
->pEndPath
)
177 ret
= dc
->funcs
->pEndPath(dc
->physDev
);
180 /* Check that path is currently being constructed */
181 if(dc
->path
.state
!=PATH_Open
)
183 SetLastError(ERROR_CAN_NOT_COMPLETE
);
186 /* Set flag to indicate that path is finished */
187 else dc
->path
.state
=PATH_Closed
;
189 GDI_ReleaseObj( hdc
);
194 /******************************************************************************
195 * AbortPath [GDI32.@]
196 * Closes and discards paths from device context
199 * Check that SetLastError is being called correctly
202 * hdc [I] Handle to device context
206 BOOL WINAPI
AbortPath( HDC hdc
)
209 DC
*dc
= DC_GetDCPtr( hdc
);
211 if(!dc
) return FALSE
;
213 if(dc
->funcs
->pAbortPath
)
214 ret
= dc
->funcs
->pAbortPath(dc
->physDev
);
215 else /* Remove all entries from the path */
216 PATH_EmptyPath( &dc
->path
);
217 GDI_ReleaseObj( hdc
);
222 /***********************************************************************
223 * CloseFigure (GDI32.@)
225 * FIXME: Check that SetLastError is being called correctly
227 BOOL WINAPI
CloseFigure(HDC hdc
)
230 DC
*dc
= DC_GetDCPtr( hdc
);
232 if(!dc
) return FALSE
;
234 if(dc
->funcs
->pCloseFigure
)
235 ret
= dc
->funcs
->pCloseFigure(dc
->physDev
);
238 /* Check that path is open */
239 if(dc
->path
.state
!=PATH_Open
)
241 SetLastError(ERROR_CAN_NOT_COMPLETE
);
246 /* FIXME: Shouldn't we draw a line to the beginning of the
248 /* Set PT_CLOSEFIGURE on the last entry and start a new stroke */
249 if(dc
->path
.numEntriesUsed
)
251 dc
->path
.pFlags
[dc
->path
.numEntriesUsed
-1]|=PT_CLOSEFIGURE
;
252 dc
->path
.newStroke
=TRUE
;
256 GDI_ReleaseObj( hdc
);
261 /***********************************************************************
264 INT WINAPI
GetPath(HDC hdc
, LPPOINT pPoints
, LPBYTE pTypes
,
269 DC
*dc
= DC_GetDCPtr( hdc
);
275 /* Check that path is closed */
276 if(pPath
->state
!=PATH_Closed
)
278 SetLastError(ERROR_CAN_NOT_COMPLETE
);
283 ret
= pPath
->numEntriesUsed
;
284 else if(nSize
<pPath
->numEntriesUsed
)
286 SetLastError(ERROR_INVALID_PARAMETER
);
291 memcpy(pPoints
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
292 memcpy(pTypes
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
294 /* Convert the points to logical coordinates */
295 if(!DPtoLP(hdc
, pPoints
, pPath
->numEntriesUsed
))
297 /* FIXME: Is this the correct value? */
298 SetLastError(ERROR_CAN_NOT_COMPLETE
);
301 else ret
= pPath
->numEntriesUsed
;
304 GDI_ReleaseObj( hdc
);
309 /***********************************************************************
310 * PathToRegion (GDI32.@)
313 * Check that SetLastError is being called correctly
315 * The documentation does not state this explicitly, but a test under Windows
316 * shows that the region which is returned should be in device coordinates.
318 HRGN WINAPI
PathToRegion(HDC hdc
)
322 DC
*dc
= DC_GetDCPtr( hdc
);
324 /* Get pointer to path */
329 /* Check that path is closed */
330 if(pPath
->state
!=PATH_Closed
) SetLastError(ERROR_CAN_NOT_COMPLETE
);
333 /* FIXME: Should we empty the path even if conversion failed? */
334 if(PATH_PathToRegion(pPath
, GetPolyFillMode(hdc
), &hrgnRval
))
335 PATH_EmptyPath(pPath
);
339 GDI_ReleaseObj( hdc
);
343 static BOOL
PATH_FillPath(DC
*dc
, GdiPath
*pPath
)
345 INT mapMode
, graphicsMode
;
346 SIZE ptViewportExt
, ptWindowExt
;
347 POINT ptViewportOrg
, ptWindowOrg
;
351 if(dc
->funcs
->pFillPath
)
352 return dc
->funcs
->pFillPath(dc
->physDev
);
354 /* Check that path is closed */
355 if(pPath
->state
!=PATH_Closed
)
357 SetLastError(ERROR_CAN_NOT_COMPLETE
);
361 /* Construct a region from the path and fill it */
362 if(PATH_PathToRegion(pPath
, dc
->polyFillMode
, &hrgn
))
364 /* Since PaintRgn interprets the region as being in logical coordinates
365 * but the points we store for the path are already in device
366 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
367 * Using SaveDC to save information about the mapping mode / world
368 * transform would be easier but would require more overhead, especially
369 * now that SaveDC saves the current path.
372 /* Save the information about the old mapping mode */
373 mapMode
=GetMapMode(dc
->hSelf
);
374 GetViewportExtEx(dc
->hSelf
, &ptViewportExt
);
375 GetViewportOrgEx(dc
->hSelf
, &ptViewportOrg
);
376 GetWindowExtEx(dc
->hSelf
, &ptWindowExt
);
377 GetWindowOrgEx(dc
->hSelf
, &ptWindowOrg
);
379 /* Save world transform
380 * NB: The Windows documentation on world transforms would lead one to
381 * believe that this has to be done only in GM_ADVANCED; however, my
382 * tests show that resetting the graphics mode to GM_COMPATIBLE does
383 * not reset the world transform.
385 GetWorldTransform(dc
->hSelf
, &xform
);
388 SetMapMode(dc
->hSelf
, MM_TEXT
);
389 SetViewportOrgEx(dc
->hSelf
, 0, 0, NULL
);
390 SetWindowOrgEx(dc
->hSelf
, 0, 0, NULL
);
391 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
392 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
393 ModifyWorldTransform(dc
->hSelf
, &xform
, MWT_IDENTITY
);
394 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
396 /* Paint the region */
397 PaintRgn(dc
->hSelf
, hrgn
);
399 /* Restore the old mapping mode */
400 SetMapMode(dc
->hSelf
, mapMode
);
401 SetViewportExtEx(dc
->hSelf
, ptViewportExt
.cx
, ptViewportExt
.cy
, NULL
);
402 SetViewportOrgEx(dc
->hSelf
, ptViewportOrg
.x
, ptViewportOrg
.y
, NULL
);
403 SetWindowExtEx(dc
->hSelf
, ptWindowExt
.cx
, ptWindowExt
.cy
, NULL
);
404 SetWindowOrgEx(dc
->hSelf
, ptWindowOrg
.x
, ptWindowOrg
.y
, NULL
);
406 /* Go to GM_ADVANCED temporarily to restore the world transform */
407 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
408 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
409 SetWorldTransform(dc
->hSelf
, &xform
);
410 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
417 /***********************************************************************
421 * Check that SetLastError is being called correctly
423 BOOL WINAPI
FillPath(HDC hdc
)
425 DC
*dc
= DC_GetDCPtr( hdc
);
428 if(!dc
) return FALSE
;
430 if(dc
->funcs
->pFillPath
)
431 bRet
= dc
->funcs
->pFillPath(dc
->physDev
);
434 bRet
= PATH_FillPath(dc
, &dc
->path
);
437 /* FIXME: Should the path be emptied even if conversion
439 PATH_EmptyPath(&dc
->path
);
442 GDI_ReleaseObj( hdc
);
447 /***********************************************************************
448 * SelectClipPath (GDI32.@)
450 * Check that SetLastError is being called correctly
452 BOOL WINAPI
SelectClipPath(HDC hdc
, INT iMode
)
456 BOOL success
= FALSE
;
457 DC
*dc
= DC_GetDCPtr( hdc
);
459 if(!dc
) return FALSE
;
461 if(dc
->funcs
->pSelectClipPath
)
462 success
= dc
->funcs
->pSelectClipPath(dc
->physDev
, iMode
);
467 /* Check that path is closed */
468 if(pPath
->state
!=PATH_Closed
)
469 SetLastError(ERROR_CAN_NOT_COMPLETE
);
470 /* Construct a region from the path */
471 else if(PATH_PathToRegion(pPath
, GetPolyFillMode(hdc
), &hrgnPath
))
473 success
= ExtSelectClipRgn( hdc
, hrgnPath
, iMode
) != ERROR
;
474 DeleteObject(hrgnPath
);
478 PATH_EmptyPath(pPath
);
479 /* FIXME: Should this function delete the path even if it failed? */
482 GDI_ReleaseObj( hdc
);
487 /***********************************************************************
493 * Initializes the GdiPath structure.
495 void PATH_InitGdiPath(GdiPath
*pPath
)
499 pPath
->state
=PATH_Null
;
502 pPath
->numEntriesUsed
=0;
503 pPath
->numEntriesAllocated
=0;
506 /* PATH_DestroyGdiPath
508 * Destroys a GdiPath structure (frees the memory in the arrays).
510 void PATH_DestroyGdiPath(GdiPath
*pPath
)
514 HeapFree( GetProcessHeap(), 0, pPath
->pPoints
);
515 HeapFree( GetProcessHeap(), 0, pPath
->pFlags
);
518 /* PATH_AssignGdiPath
520 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
521 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
522 * not just the pointers. Since this means that the arrays in pPathDest may
523 * need to be resized, pPathDest should have been initialized using
524 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
525 * not a copy constructor).
526 * Returns TRUE if successful, else FALSE.
528 BOOL
PATH_AssignGdiPath(GdiPath
*pPathDest
, const GdiPath
*pPathSrc
)
530 assert(pPathDest
!=NULL
&& pPathSrc
!=NULL
);
532 /* Make sure destination arrays are big enough */
533 if(!PATH_ReserveEntries(pPathDest
, pPathSrc
->numEntriesUsed
))
536 /* Perform the copy operation */
537 memcpy(pPathDest
->pPoints
, pPathSrc
->pPoints
,
538 sizeof(POINT
)*pPathSrc
->numEntriesUsed
);
539 memcpy(pPathDest
->pFlags
, pPathSrc
->pFlags
,
540 sizeof(BYTE
)*pPathSrc
->numEntriesUsed
);
542 pPathDest
->state
=pPathSrc
->state
;
543 pPathDest
->numEntriesUsed
=pPathSrc
->numEntriesUsed
;
544 pPathDest
->newStroke
=pPathSrc
->newStroke
;
551 * Should be called when a MoveTo is performed on a DC that has an
552 * open path. This starts a new stroke. Returns TRUE if successful, else
555 BOOL
PATH_MoveTo(DC
*dc
)
557 GdiPath
*pPath
= &dc
->path
;
559 /* Check that path is open */
560 if(pPath
->state
!=PATH_Open
)
561 /* FIXME: Do we have to call SetLastError? */
564 /* Start a new stroke */
565 pPath
->newStroke
=TRUE
;
572 * Should be called when a LineTo is performed on a DC that has an
573 * open path. This adds a PT_LINETO entry to the path (and possibly
574 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
575 * Returns TRUE if successful, else FALSE.
577 BOOL
PATH_LineTo(DC
*dc
, INT x
, INT y
)
579 GdiPath
*pPath
= &dc
->path
;
580 POINT point
, pointCurPos
;
582 /* Check that path is open */
583 if(pPath
->state
!=PATH_Open
)
586 /* Convert point to device coordinates */
589 if(!LPtoDP(dc
->hSelf
, &point
, 1))
592 /* Add a PT_MOVETO if necessary */
595 pPath
->newStroke
=FALSE
;
596 pointCurPos
.x
= dc
->CursPosX
;
597 pointCurPos
.y
= dc
->CursPosY
;
598 if(!LPtoDP(dc
->hSelf
, &pointCurPos
, 1))
600 if(!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
604 /* Add a PT_LINETO entry */
605 return PATH_AddEntry(pPath
, &point
, PT_LINETO
);
610 * Should be called when a call to RoundRect is performed on a DC that has
611 * an open path. Returns TRUE if successful, else FALSE.
613 * FIXME: it adds the same entries to the path as windows does, but there
614 * is an error in the bezier drawing code so that there are small pixel-size
615 * gaps when the resulting path is drawn by StrokePath()
617 BOOL
PATH_RoundRect(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
, INT ell_width
, INT ell_height
)
619 GdiPath
*pPath
= &dc
->path
;
620 POINT corners
[2], pointTemp
;
621 FLOAT_POINT ellCorners
[2];
623 /* Check that path is open */
624 if(pPath
->state
!=PATH_Open
)
627 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
630 /* Add points to the roundrect path */
631 ellCorners
[0].x
= corners
[1].x
-ell_width
;
632 ellCorners
[0].y
= corners
[0].y
;
633 ellCorners
[1].x
= corners
[1].x
;
634 ellCorners
[1].y
= corners
[0].y
+ell_height
;
635 if(!PATH_DoArcPart(pPath
, ellCorners
, 0, -M_PI_2
, TRUE
))
637 pointTemp
.x
= corners
[0].x
+ell_width
/2;
638 pointTemp
.y
= corners
[0].y
;
639 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
641 ellCorners
[0].x
= corners
[0].x
;
642 ellCorners
[1].x
= corners
[0].x
+ell_width
;
643 if(!PATH_DoArcPart(pPath
, ellCorners
, -M_PI_2
, -M_PI
, FALSE
))
645 pointTemp
.x
= corners
[0].x
;
646 pointTemp
.y
= corners
[1].y
-ell_height
/2;
647 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
649 ellCorners
[0].y
= corners
[1].y
-ell_height
;
650 ellCorners
[1].y
= corners
[1].y
;
651 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI
, M_PI_2
, FALSE
))
653 pointTemp
.x
= corners
[1].x
-ell_width
/2;
654 pointTemp
.y
= corners
[1].y
;
655 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
657 ellCorners
[0].x
= corners
[1].x
-ell_width
;
658 ellCorners
[1].x
= corners
[1].x
;
659 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI_2
, 0, FALSE
))
662 /* Close the roundrect figure */
663 if(!CloseFigure(dc
->hSelf
))
671 * Should be called when a call to Rectangle is performed on a DC that has
672 * an open path. Returns TRUE if successful, else FALSE.
674 BOOL
PATH_Rectangle(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
)
676 GdiPath
*pPath
= &dc
->path
;
677 POINT corners
[2], pointTemp
;
679 /* Check that path is open */
680 if(pPath
->state
!=PATH_Open
)
683 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
686 /* Close any previous figure */
687 if(!CloseFigure(dc
->hSelf
))
689 /* The CloseFigure call shouldn't have failed */
694 /* Add four points to the path */
695 pointTemp
.x
=corners
[1].x
;
696 pointTemp
.y
=corners
[0].y
;
697 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_MOVETO
))
699 if(!PATH_AddEntry(pPath
, corners
, PT_LINETO
))
701 pointTemp
.x
=corners
[0].x
;
702 pointTemp
.y
=corners
[1].y
;
703 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
705 if(!PATH_AddEntry(pPath
, corners
+1, PT_LINETO
))
708 /* Close the rectangle figure */
709 if(!CloseFigure(dc
->hSelf
))
711 /* The CloseFigure call shouldn't have failed */
721 * Should be called when a call to Ellipse is performed on a DC that has
722 * an open path. This adds four Bezier splines representing the ellipse
723 * to the path. Returns TRUE if successful, else FALSE.
725 BOOL
PATH_Ellipse(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
)
727 return( PATH_Arc(dc
, x1
, y1
, x2
, y2
, x1
, (y1
+y2
)/2, x1
, (y1
+y2
)/2,0) &&
728 CloseFigure(dc
->hSelf
) );
733 * Should be called when a call to Arc is performed on a DC that has
734 * an open path. This adds up to five Bezier splines representing the arc
735 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
736 * and when 'lines' is 2, we add 2 extra lines to get a pie.
737 * Returns TRUE if successful, else FALSE.
739 BOOL
PATH_Arc(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
,
740 INT xStart
, INT yStart
, INT xEnd
, INT yEnd
, INT lines
)
742 GdiPath
*pPath
= &dc
->path
;
743 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
=0.0;
744 /* Initialize angleEndQuadrant to silence gcc's warning */
746 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
751 /* FIXME: This function should check for all possible error returns */
752 /* FIXME: Do we have to respect newStroke? */
754 /* Check that path is open */
755 if(pPath
->state
!=PATH_Open
)
758 /* Check for zero height / width */
759 /* FIXME: Only in GM_COMPATIBLE? */
763 /* Convert points to device coordinates */
764 corners
[0].x
=(FLOAT
)x1
;
765 corners
[0].y
=(FLOAT
)y1
;
766 corners
[1].x
=(FLOAT
)x2
;
767 corners
[1].y
=(FLOAT
)y2
;
768 pointStart
.x
=(FLOAT
)xStart
;
769 pointStart
.y
=(FLOAT
)yStart
;
770 pointEnd
.x
=(FLOAT
)xEnd
;
771 pointEnd
.y
=(FLOAT
)yEnd
;
772 INTERNAL_LPTODP_FLOAT(dc
, corners
);
773 INTERNAL_LPTODP_FLOAT(dc
, corners
+1);
774 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
);
775 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
);
777 /* Make sure first corner is top left and second corner is bottom right */
778 if(corners
[0].x
>corners
[1].x
)
781 corners
[0].x
=corners
[1].x
;
784 if(corners
[0].y
>corners
[1].y
)
787 corners
[0].y
=corners
[1].y
;
791 /* Compute start and end angle */
792 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
793 angleStart
=atan2(y
, x
);
794 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
795 angleEnd
=atan2(y
, x
);
797 /* Make sure the end angle is "on the right side" of the start angle */
798 if(dc
->ArcDirection
==AD_CLOCKWISE
)
800 if(angleEnd
<=angleStart
)
803 assert(angleEnd
>=angleStart
);
808 if(angleEnd
>=angleStart
)
811 assert(angleEnd
<=angleStart
);
815 /* In GM_COMPATIBLE, don't include bottom and right edges */
816 if(dc
->GraphicsMode
==GM_COMPATIBLE
)
822 /* Add the arc to the path with one Bezier spline per quadrant that the
828 /* Determine the start and end angles for this quadrant */
831 angleStartQuadrant
=angleStart
;
832 if(dc
->ArcDirection
==AD_CLOCKWISE
)
833 angleEndQuadrant
=(floor(angleStart
/M_PI_2
)+1.0)*M_PI_2
;
835 angleEndQuadrant
=(ceil(angleStart
/M_PI_2
)-1.0)*M_PI_2
;
839 angleStartQuadrant
=angleEndQuadrant
;
840 if(dc
->ArcDirection
==AD_CLOCKWISE
)
841 angleEndQuadrant
+=M_PI_2
;
843 angleEndQuadrant
-=M_PI_2
;
846 /* Have we reached the last part of the arc? */
847 if((dc
->ArcDirection
==AD_CLOCKWISE
&&
848 angleEnd
<angleEndQuadrant
) ||
849 (dc
->ArcDirection
==AD_COUNTERCLOCKWISE
&&
850 angleEnd
>angleEndQuadrant
))
852 /* Adjust the end angle for this quadrant */
853 angleEndQuadrant
=angleEnd
;
857 /* Add the Bezier spline to the path */
858 PATH_DoArcPart(pPath
, corners
, angleStartQuadrant
, angleEndQuadrant
,
863 /* chord: close figure. pie: add line and close figure */
866 if(!CloseFigure(dc
->hSelf
))
871 centre
.x
= (corners
[0].x
+corners
[1].x
)/2;
872 centre
.y
= (corners
[0].y
+corners
[1].y
)/2;
873 if(!PATH_AddEntry(pPath
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
880 BOOL
PATH_PolyBezierTo(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
882 GdiPath
*pPath
= &dc
->path
;
886 /* Check that path is open */
887 if(pPath
->state
!=PATH_Open
)
890 /* Add a PT_MOVETO if necessary */
893 pPath
->newStroke
=FALSE
;
896 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
898 if(!PATH_AddEntry(pPath
, &pt
, PT_MOVETO
))
902 for(i
= 0; i
< cbPoints
; i
++) {
904 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
906 PATH_AddEntry(pPath
, &pt
, PT_BEZIERTO
);
911 BOOL
PATH_PolyBezier(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
913 GdiPath
*pPath
= &dc
->path
;
917 /* Check that path is open */
918 if(pPath
->state
!=PATH_Open
)
921 for(i
= 0; i
< cbPoints
; i
++) {
923 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
925 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_BEZIERTO
);
930 BOOL
PATH_Polyline(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
932 GdiPath
*pPath
= &dc
->path
;
936 /* Check that path is open */
937 if(pPath
->state
!=PATH_Open
)
940 for(i
= 0; i
< cbPoints
; i
++) {
942 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
944 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_LINETO
);
949 BOOL
PATH_PolylineTo(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
951 GdiPath
*pPath
= &dc
->path
;
955 /* Check that path is open */
956 if(pPath
->state
!=PATH_Open
)
959 /* Add a PT_MOVETO if necessary */
962 pPath
->newStroke
=FALSE
;
965 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
967 if(!PATH_AddEntry(pPath
, &pt
, PT_MOVETO
))
971 for(i
= 0; i
< cbPoints
; i
++) {
973 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
975 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
982 BOOL
PATH_Polygon(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
984 GdiPath
*pPath
= &dc
->path
;
988 /* Check that path is open */
989 if(pPath
->state
!=PATH_Open
)
992 for(i
= 0; i
< cbPoints
; i
++) {
994 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
996 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
:
997 ((i
== cbPoints
-1) ? PT_LINETO
| PT_CLOSEFIGURE
:
1003 BOOL
PATH_PolyPolygon( DC
*dc
, const POINT
* pts
, const INT
* counts
,
1006 GdiPath
*pPath
= &dc
->path
;
1011 /* Check that path is open */
1012 if(pPath
->state
!=PATH_Open
)
1015 for(i
= 0, poly
= 0; poly
< polygons
; poly
++) {
1016 for(point
= 0; point
< counts
[poly
]; point
++, i
++) {
1018 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1020 if(point
== 0) startpt
= pt
;
1021 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1023 /* win98 adds an extra line to close the figure for some reason */
1024 PATH_AddEntry(pPath
, &startpt
, PT_LINETO
| PT_CLOSEFIGURE
);
1029 BOOL
PATH_PolyPolyline( DC
*dc
, const POINT
* pts
, const DWORD
* counts
,
1032 GdiPath
*pPath
= &dc
->path
;
1034 UINT poly
, point
, i
;
1036 /* Check that path is open */
1037 if(pPath
->state
!=PATH_Open
)
1040 for(i
= 0, poly
= 0; poly
< polylines
; poly
++) {
1041 for(point
= 0; point
< counts
[poly
]; point
++, i
++) {
1043 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1045 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1051 /***********************************************************************
1052 * Internal functions
1055 /* PATH_CheckCorners
1057 * Helper function for PATH_RoundRect() and PATH_Rectangle()
1059 static BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
)
1063 /* Convert points to device coordinates */
1068 if(!LPtoDP(dc
->hSelf
, corners
, 2))
1071 /* Make sure first corner is top left and second corner is bottom right */
1072 if(corners
[0].x
>corners
[1].x
)
1075 corners
[0].x
=corners
[1].x
;
1078 if(corners
[0].y
>corners
[1].y
)
1081 corners
[0].y
=corners
[1].y
;
1085 /* In GM_COMPATIBLE, don't include bottom and right edges */
1086 if(dc
->GraphicsMode
==GM_COMPATIBLE
)
1095 /* PATH_AddFlatBezier
1097 static BOOL
PATH_AddFlatBezier(GdiPath
*pPath
, POINT
*pt
, BOOL closed
)
1102 pts
= GDI_Bezier( pt
, 4, &no
);
1103 if(!pts
) return FALSE
;
1105 for(i
= 1; i
< no
; i
++)
1106 PATH_AddEntry(pPath
, &pts
[i
],
1107 (i
== no
-1 && closed
) ? PT_LINETO
| PT_CLOSEFIGURE
: PT_LINETO
);
1108 HeapFree( GetProcessHeap(), 0, pts
);
1114 * Replaces Beziers with line segments
1117 static BOOL
PATH_FlattenPath(GdiPath
*pPath
)
1122 memset(&newPath
, 0, sizeof(newPath
));
1123 newPath
.state
= PATH_Open
;
1124 for(srcpt
= 0; srcpt
< pPath
->numEntriesUsed
; srcpt
++) {
1125 switch(pPath
->pFlags
[srcpt
] & ~PT_CLOSEFIGURE
) {
1128 PATH_AddEntry(&newPath
, &pPath
->pPoints
[srcpt
],
1129 pPath
->pFlags
[srcpt
]);
1132 PATH_AddFlatBezier(&newPath
, &pPath
->pPoints
[srcpt
-1],
1133 pPath
->pFlags
[srcpt
+2] & PT_CLOSEFIGURE
);
1138 newPath
.state
= PATH_Closed
;
1139 PATH_AssignGdiPath(pPath
, &newPath
);
1140 PATH_DestroyGdiPath(&newPath
);
1144 /* PATH_PathToRegion
1146 * Creates a region from the specified path using the specified polygon
1147 * filling mode. The path is left unchanged. A handle to the region that
1148 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1149 * error occurs, SetLastError is called with the appropriate value and
1150 * FALSE is returned.
1152 static BOOL
PATH_PathToRegion(GdiPath
*pPath
, INT nPolyFillMode
,
1155 int numStrokes
, iStroke
, i
;
1156 INT
*pNumPointsInStroke
;
1159 assert(pPath
!=NULL
);
1160 assert(pHrgn
!=NULL
);
1162 PATH_FlattenPath(pPath
);
1164 /* FIXME: What happens when number of points is zero? */
1166 /* First pass: Find out how many strokes there are in the path */
1167 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1169 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1170 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1173 /* Allocate memory for number-of-points-in-stroke array */
1174 pNumPointsInStroke
=HeapAlloc( GetProcessHeap(), 0, sizeof(int) * numStrokes
);
1175 if(!pNumPointsInStroke
)
1177 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1181 /* Second pass: remember number of points in each polygon */
1182 iStroke
=-1; /* Will get incremented to 0 at beginning of first stroke */
1183 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1185 /* Is this the beginning of a new stroke? */
1186 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1189 pNumPointsInStroke
[iStroke
]=0;
1192 pNumPointsInStroke
[iStroke
]++;
1195 /* Create a region from the strokes */
1196 hrgn
=CreatePolyPolygonRgn(pPath
->pPoints
, pNumPointsInStroke
,
1197 numStrokes
, nPolyFillMode
);
1199 /* Free memory for number-of-points-in-stroke array */
1200 HeapFree( GetProcessHeap(), 0, pNumPointsInStroke
);
1204 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1215 * Removes all entries from the path and sets the path state to PATH_Null.
1217 static void PATH_EmptyPath(GdiPath
*pPath
)
1219 assert(pPath
!=NULL
);
1221 pPath
->state
=PATH_Null
;
1222 pPath
->numEntriesUsed
=0;
1227 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1228 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1229 * successful, FALSE otherwise (e.g. if not enough memory was available).
1231 BOOL
PATH_AddEntry(GdiPath
*pPath
, const POINT
*pPoint
, BYTE flags
)
1233 assert(pPath
!=NULL
);
1235 /* FIXME: If newStroke is true, perhaps we want to check that we're
1236 * getting a PT_MOVETO
1238 TRACE("(%ld,%ld) - %d\n", pPoint
->x
, pPoint
->y
, flags
);
1240 /* Check that path is open */
1241 if(pPath
->state
!=PATH_Open
)
1244 /* Reserve enough memory for an extra path entry */
1245 if(!PATH_ReserveEntries(pPath
, pPath
->numEntriesUsed
+1))
1248 /* Store information in path entry */
1249 pPath
->pPoints
[pPath
->numEntriesUsed
]=*pPoint
;
1250 pPath
->pFlags
[pPath
->numEntriesUsed
]=flags
;
1252 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1253 if((flags
& PT_CLOSEFIGURE
) == PT_CLOSEFIGURE
)
1254 pPath
->newStroke
=TRUE
;
1256 /* Increment entry count */
1257 pPath
->numEntriesUsed
++;
1262 /* PATH_ReserveEntries
1264 * Ensures that at least "numEntries" entries (for points and flags) have
1265 * been allocated; allocates larger arrays and copies the existing entries
1266 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1268 static BOOL
PATH_ReserveEntries(GdiPath
*pPath
, INT numEntries
)
1270 INT numEntriesToAllocate
;
1274 assert(pPath
!=NULL
);
1275 assert(numEntries
>=0);
1277 /* Do we have to allocate more memory? */
1278 if(numEntries
> pPath
->numEntriesAllocated
)
1280 /* Find number of entries to allocate. We let the size of the array
1281 * grow exponentially, since that will guarantee linear time
1283 if(pPath
->numEntriesAllocated
)
1285 numEntriesToAllocate
=pPath
->numEntriesAllocated
;
1286 while(numEntriesToAllocate
<numEntries
)
1287 numEntriesToAllocate
=numEntriesToAllocate
*GROW_FACTOR_NUMER
/
1291 numEntriesToAllocate
=numEntries
;
1293 /* Allocate new arrays */
1294 pPointsNew
=HeapAlloc( GetProcessHeap(), 0, numEntriesToAllocate
* sizeof(POINT
) );
1297 pFlagsNew
=HeapAlloc( GetProcessHeap(), 0, numEntriesToAllocate
* sizeof(BYTE
) );
1300 HeapFree( GetProcessHeap(), 0, pPointsNew
);
1304 /* Copy old arrays to new arrays and discard old arrays */
1307 assert(pPath
->pFlags
);
1309 memcpy(pPointsNew
, pPath
->pPoints
,
1310 sizeof(POINT
)*pPath
->numEntriesUsed
);
1311 memcpy(pFlagsNew
, pPath
->pFlags
,
1312 sizeof(BYTE
)*pPath
->numEntriesUsed
);
1314 HeapFree( GetProcessHeap(), 0, pPath
->pPoints
);
1315 HeapFree( GetProcessHeap(), 0, pPath
->pFlags
);
1317 pPath
->pPoints
=pPointsNew
;
1318 pPath
->pFlags
=pFlagsNew
;
1319 pPath
->numEntriesAllocated
=numEntriesToAllocate
;
1327 * Creates a Bezier spline that corresponds to part of an arc and appends the
1328 * corresponding points to the path. The start and end angles are passed in
1329 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1330 * at most. If "addMoveTo" is true, a PT_MOVETO entry for the first control
1331 * point is added to the path; otherwise, it is assumed that the current
1332 * position is equal to the first control point.
1334 static BOOL
PATH_DoArcPart(GdiPath
*pPath
, FLOAT_POINT corners
[],
1335 double angleStart
, double angleEnd
, BOOL addMoveTo
)
1337 double halfAngle
, a
;
1338 double xNorm
[4], yNorm
[4];
1342 assert(fabs(angleEnd
-angleStart
)<=M_PI_2
);
1344 /* FIXME: Is there an easier way of computing this? */
1346 /* Compute control points */
1347 halfAngle
=(angleEnd
-angleStart
)/2.0;
1348 if(fabs(halfAngle
)>1e-8)
1350 a
=4.0/3.0*(1-cos(halfAngle
))/sin(halfAngle
);
1351 xNorm
[0]=cos(angleStart
);
1352 yNorm
[0]=sin(angleStart
);
1353 xNorm
[1]=xNorm
[0] - a
*yNorm
[0];
1354 yNorm
[1]=yNorm
[0] + a
*xNorm
[0];
1355 xNorm
[3]=cos(angleEnd
);
1356 yNorm
[3]=sin(angleEnd
);
1357 xNorm
[2]=xNorm
[3] + a
*yNorm
[3];
1358 yNorm
[2]=yNorm
[3] - a
*xNorm
[3];
1363 xNorm
[i
]=cos(angleStart
);
1364 yNorm
[i
]=sin(angleStart
);
1367 /* Add starting point to path if desired */
1370 PATH_ScaleNormalizedPoint(corners
, xNorm
[0], yNorm
[0], &point
);
1371 if(!PATH_AddEntry(pPath
, &point
, PT_MOVETO
))
1375 /* Add remaining control points */
1378 PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &point
);
1379 if(!PATH_AddEntry(pPath
, &point
, PT_BEZIERTO
))
1386 /* PATH_ScaleNormalizedPoint
1388 * Scales a normalized point (x, y) with respect to the box whose corners are
1389 * passed in "corners". The point is stored in "*pPoint". The normalized
1390 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1391 * (1.0, 1.0) correspond to corners[1].
1393 static void PATH_ScaleNormalizedPoint(FLOAT_POINT corners
[], double x
,
1394 double y
, POINT
*pPoint
)
1396 pPoint
->x
=GDI_ROUND( (double)corners
[0].x
+
1397 (double)(corners
[1].x
-corners
[0].x
)*0.5*(x
+1.0) );
1398 pPoint
->y
=GDI_ROUND( (double)corners
[0].y
+
1399 (double)(corners
[1].y
-corners
[0].y
)*0.5*(y
+1.0) );
1402 /* PATH_NormalizePoint
1404 * Normalizes a point with respect to the box whose corners are passed in
1405 * "corners". The normalized coordinates are stored in "*pX" and "*pY".
1407 static void PATH_NormalizePoint(FLOAT_POINT corners
[],
1408 const FLOAT_POINT
*pPoint
,
1409 double *pX
, double *pY
)
1411 *pX
=(double)(pPoint
->x
-corners
[0].x
)/(double)(corners
[1].x
-corners
[0].x
) *
1413 *pY
=(double)(pPoint
->y
-corners
[0].y
)/(double)(corners
[1].y
-corners
[0].y
) *
1418 /*******************************************************************
1419 * FlattenPath [GDI32.@]
1423 BOOL WINAPI
FlattenPath(HDC hdc
)
1426 DC
*dc
= DC_GetDCPtr( hdc
);
1428 if(!dc
) return FALSE
;
1430 if(dc
->funcs
->pFlattenPath
) ret
= dc
->funcs
->pFlattenPath(dc
->physDev
);
1433 GdiPath
*pPath
= &dc
->path
;
1434 if(pPath
->state
!= PATH_Closed
)
1435 ret
= PATH_FlattenPath(pPath
);
1437 GDI_ReleaseObj( hdc
);
1442 static BOOL
PATH_StrokePath(DC
*dc
, GdiPath
*pPath
)
1444 INT i
, nLinePts
, nAlloc
;
1446 POINT ptViewportOrg
, ptWindowOrg
;
1447 SIZE szViewportExt
, szWindowExt
;
1448 DWORD mapMode
, graphicsMode
;
1454 if(dc
->funcs
->pStrokePath
)
1455 return dc
->funcs
->pStrokePath(dc
->physDev
);
1457 if(pPath
->state
!= PATH_Closed
)
1460 /* Convert pen properties from logical to device units for MWT_IDENTITY */
1461 hOldPen
= GetCurrentObject(dc
->hSelf
, OBJ_PEN
);
1462 if(GetObjectType(hOldPen
) == OBJ_EXTPEN
) {
1465 GetObjectW(hOldPen
, sizeof(EXTLOGPEN
), &elp
);
1466 if(elp
.elpPenStyle
& PS_GEOMETRIC
) {
1467 INTERNAL_WSTODS(dc
, &elp
.elpWidth
);
1468 if(elp
.elpPenStyle
& PS_USERSTYLE
)
1469 for(i
= 0; i
< elp
.elpNumEntries
; i
++)
1470 INTERNAL_WSTODS(dc
, &elp
.elpStyleEntry
[i
]);
1472 lb
.lbStyle
= elp
.elpBrushStyle
;
1473 lb
.lbColor
= elp
.elpColor
;
1474 lb
.lbHatch
= elp
.elpHatch
;
1475 hNewPen
= ExtCreatePen(elp
.elpPenStyle
, elp
.elpWidth
, &lb
,
1476 elp
.elpNumEntries
, elp
.elpStyleEntry
);
1477 } else /* OBJ_PEN */ {
1479 GetObjectW(hOldPen
, sizeof(LOGPEN
), &lp
);
1480 if(lp
.lopnWidth
.x
> 0)
1481 INTERNAL_WSTODS(dc
, &lp
.lopnWidth
.x
);
1482 hNewPen
= CreatePenIndirect(&lp
);
1484 SelectObject(dc
->hSelf
, hNewPen
);
1486 /* Save the mapping mode info */
1487 mapMode
=GetMapMode(dc
->hSelf
);
1488 GetViewportExtEx(dc
->hSelf
, &szViewportExt
);
1489 GetViewportOrgEx(dc
->hSelf
, &ptViewportOrg
);
1490 GetWindowExtEx(dc
->hSelf
, &szWindowExt
);
1491 GetWindowOrgEx(dc
->hSelf
, &ptWindowOrg
);
1492 GetWorldTransform(dc
->hSelf
, &xform
);
1495 SetMapMode(dc
->hSelf
, MM_TEXT
);
1496 SetViewportOrgEx(dc
->hSelf
, 0, 0, NULL
);
1497 SetWindowOrgEx(dc
->hSelf
, 0, 0, NULL
);
1498 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
1499 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
1500 ModifyWorldTransform(dc
->hSelf
, &xform
, MWT_IDENTITY
);
1501 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
1503 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1504 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1505 * space in case we get one to keep the number of reallocations small. */
1506 nAlloc
= pPath
->numEntriesUsed
+ 1 + 300;
1507 pLinePts
= HeapAlloc(GetProcessHeap(), 0, nAlloc
* sizeof(POINT
));
1510 for(i
= 0; i
< pPath
->numEntriesUsed
; i
++) {
1511 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
)) &&
1512 (pPath
->pFlags
[i
] != PT_MOVETO
)) {
1513 ERR("Expected PT_MOVETO %s, got path flag %d\n",
1514 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1515 (INT
)pPath
->pFlags
[i
]);
1519 switch(pPath
->pFlags
[i
]) {
1521 TRACE("Got PT_MOVETO (%ld, %ld)\n",
1522 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1524 Polyline(dc
->hSelf
, pLinePts
, nLinePts
);
1526 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1529 case (PT_LINETO
| PT_CLOSEFIGURE
):
1530 TRACE("Got PT_LINETO (%ld, %ld)\n",
1531 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1532 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1535 TRACE("Got PT_BEZIERTO\n");
1536 if(pPath
->pFlags
[i
+1] != PT_BEZIERTO
||
1537 (pPath
->pFlags
[i
+2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
) {
1538 ERR("Path didn't contain 3 successive PT_BEZIERTOs\n");
1542 INT nBzrPts
, nMinAlloc
;
1543 POINT
*pBzrPts
= GDI_Bezier(&pPath
->pPoints
[i
-1], 4, &nBzrPts
);
1544 /* Make sure we have allocated enough memory for the lines of
1545 * this bezier and the rest of the path, assuming we won't get
1546 * another one (since we won't reallocate again then). */
1547 nMinAlloc
= nLinePts
+ (pPath
->numEntriesUsed
- i
) + nBzrPts
;
1548 if(nAlloc
< nMinAlloc
)
1550 nAlloc
= nMinAlloc
* 2;
1551 pLinePts
= HeapReAlloc(GetProcessHeap(), 0, pLinePts
,
1552 nAlloc
* sizeof(POINT
));
1554 memcpy(&pLinePts
[nLinePts
], &pBzrPts
[1],
1555 (nBzrPts
- 1) * sizeof(POINT
));
1556 nLinePts
+= nBzrPts
- 1;
1557 HeapFree(GetProcessHeap(), 0, pBzrPts
);
1562 ERR("Got path flag %d\n", (INT
)pPath
->pFlags
[i
]);
1566 if(pPath
->pFlags
[i
] & PT_CLOSEFIGURE
)
1567 pLinePts
[nLinePts
++] = pLinePts
[0];
1570 Polyline(dc
->hSelf
, pLinePts
, nLinePts
);
1573 HeapFree(GetProcessHeap(), 0, pLinePts
);
1575 /* Restore the old mapping mode */
1576 SetMapMode(dc
->hSelf
, mapMode
);
1577 SetViewportExtEx(dc
->hSelf
, szViewportExt
.cx
, szViewportExt
.cy
, NULL
);
1578 SetViewportOrgEx(dc
->hSelf
, ptViewportOrg
.x
, ptViewportOrg
.y
, NULL
);
1579 SetWindowExtEx(dc
->hSelf
, szWindowExt
.cx
, szWindowExt
.cy
, NULL
);
1580 SetWindowOrgEx(dc
->hSelf
, ptWindowOrg
.x
, ptWindowOrg
.y
, NULL
);
1582 /* Go to GM_ADVANCED temporarily to restore the world transform */
1583 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
1584 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
1585 SetWorldTransform(dc
->hSelf
, &xform
);
1586 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
1588 /* If we've moved the current point then get its new position
1589 which will be in device (MM_TEXT) co-ords, convert it to
1590 logical co-ords and re-set it. This basically updates
1591 dc->CurPosX|Y so that their values are in the correct mapping
1596 GetCurrentPositionEx(dc
->hSelf
, &pt
);
1597 DPtoLP(dc
->hSelf
, &pt
, 1);
1598 MoveToEx(dc
->hSelf
, pt
.x
, pt
.y
, NULL
);
1601 /* Restore old pen */
1602 DeleteObject(hNewPen
);
1603 SelectObject(dc
->hSelf
, hOldPen
);
1609 /*******************************************************************
1610 * StrokeAndFillPath [GDI32.@]
1614 BOOL WINAPI
StrokeAndFillPath(HDC hdc
)
1616 DC
*dc
= DC_GetDCPtr( hdc
);
1619 if(!dc
) return FALSE
;
1621 if(dc
->funcs
->pStrokeAndFillPath
)
1622 bRet
= dc
->funcs
->pStrokeAndFillPath(dc
->physDev
);
1625 bRet
= PATH_FillPath(dc
, &dc
->path
);
1626 if(bRet
) bRet
= PATH_StrokePath(dc
, &dc
->path
);
1627 if(bRet
) PATH_EmptyPath(&dc
->path
);
1629 GDI_ReleaseObj( hdc
);
1634 /*******************************************************************
1635 * StrokePath [GDI32.@]
1639 BOOL WINAPI
StrokePath(HDC hdc
)
1641 DC
*dc
= DC_GetDCPtr( hdc
);
1645 TRACE("(%p)\n", hdc
);
1646 if(!dc
) return FALSE
;
1648 if(dc
->funcs
->pStrokePath
)
1649 bRet
= dc
->funcs
->pStrokePath(dc
->physDev
);
1653 bRet
= PATH_StrokePath(dc
, pPath
);
1654 PATH_EmptyPath(pPath
);
1656 GDI_ReleaseObj( hdc
);
1661 /*******************************************************************
1662 * WidenPath [GDI32.@]
1666 BOOL WINAPI
WidenPath(HDC hdc
)
1668 DC
*dc
= DC_GetDCPtr( hdc
);
1671 if(!dc
) return FALSE
;
1673 if(dc
->funcs
->pWidenPath
)
1674 ret
= dc
->funcs
->pWidenPath(dc
->physDev
);
1677 GDI_ReleaseObj( hdc
);