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
, BYTE startEntryType
);
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
;
126 /***********************************************************************
127 * BeginPath (GDI32.@)
129 BOOL WINAPI
BeginPath(HDC hdc
)
132 DC
*dc
= get_dc_ptr( hdc
);
134 if(!dc
) return FALSE
;
136 if(dc
->funcs
->pBeginPath
)
137 ret
= dc
->funcs
->pBeginPath(dc
->physDev
);
140 /* If path is already open, do nothing */
141 if(dc
->path
.state
!= PATH_Open
)
143 /* Make sure that path is empty */
144 PATH_EmptyPath(&dc
->path
);
146 /* Initialize variables for new path */
147 dc
->path
.newStroke
=TRUE
;
148 dc
->path
.state
=PATH_Open
;
151 release_dc_ptr( dc
);
156 /***********************************************************************
159 BOOL WINAPI
EndPath(HDC hdc
)
162 DC
*dc
= get_dc_ptr( hdc
);
164 if(!dc
) return FALSE
;
166 if(dc
->funcs
->pEndPath
)
167 ret
= dc
->funcs
->pEndPath(dc
->physDev
);
170 /* Check that path is currently being constructed */
171 if(dc
->path
.state
!=PATH_Open
)
173 SetLastError(ERROR_CAN_NOT_COMPLETE
);
176 /* Set flag to indicate that path is finished */
177 else dc
->path
.state
=PATH_Closed
;
179 release_dc_ptr( dc
);
184 /******************************************************************************
185 * AbortPath [GDI32.@]
186 * Closes and discards paths from device context
189 * Check that SetLastError is being called correctly
192 * hdc [I] Handle to device context
198 BOOL WINAPI
AbortPath( HDC hdc
)
201 DC
*dc
= get_dc_ptr( hdc
);
203 if(!dc
) return FALSE
;
205 if(dc
->funcs
->pAbortPath
)
206 ret
= dc
->funcs
->pAbortPath(dc
->physDev
);
207 else /* Remove all entries from the path */
208 PATH_EmptyPath( &dc
->path
);
209 release_dc_ptr( dc
);
214 /***********************************************************************
215 * CloseFigure (GDI32.@)
217 * FIXME: Check that SetLastError is being called correctly
219 BOOL WINAPI
CloseFigure(HDC hdc
)
222 DC
*dc
= get_dc_ptr( hdc
);
224 if(!dc
) return FALSE
;
226 if(dc
->funcs
->pCloseFigure
)
227 ret
= dc
->funcs
->pCloseFigure(dc
->physDev
);
230 /* Check that path is open */
231 if(dc
->path
.state
!=PATH_Open
)
233 SetLastError(ERROR_CAN_NOT_COMPLETE
);
238 /* Set PT_CLOSEFIGURE on the last entry and start a new stroke */
239 /* It is not necessary to draw a line, PT_CLOSEFIGURE is a virtual closing line itself */
240 if(dc
->path
.numEntriesUsed
)
242 dc
->path
.pFlags
[dc
->path
.numEntriesUsed
-1]|=PT_CLOSEFIGURE
;
243 dc
->path
.newStroke
=TRUE
;
247 release_dc_ptr( dc
);
252 /***********************************************************************
255 INT WINAPI
GetPath(HDC hdc
, LPPOINT pPoints
, LPBYTE pTypes
,
260 DC
*dc
= get_dc_ptr( hdc
);
266 /* Check that path is closed */
267 if(pPath
->state
!=PATH_Closed
)
269 SetLastError(ERROR_CAN_NOT_COMPLETE
);
274 ret
= pPath
->numEntriesUsed
;
275 else if(nSize
<pPath
->numEntriesUsed
)
277 SetLastError(ERROR_INVALID_PARAMETER
);
282 memcpy(pPoints
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
283 memcpy(pTypes
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
285 /* Convert the points to logical coordinates */
286 if(!DPtoLP(hdc
, pPoints
, pPath
->numEntriesUsed
))
288 /* FIXME: Is this the correct value? */
289 SetLastError(ERROR_CAN_NOT_COMPLETE
);
292 else ret
= pPath
->numEntriesUsed
;
295 release_dc_ptr( dc
);
300 /***********************************************************************
301 * PathToRegion (GDI32.@)
304 * Check that SetLastError is being called correctly
306 * The documentation does not state this explicitly, but a test under Windows
307 * shows that the region which is returned should be in device coordinates.
309 HRGN WINAPI
PathToRegion(HDC hdc
)
313 DC
*dc
= get_dc_ptr( hdc
);
315 /* Get pointer to path */
320 /* Check that path is closed */
321 if(pPath
->state
!=PATH_Closed
) SetLastError(ERROR_CAN_NOT_COMPLETE
);
324 /* FIXME: Should we empty the path even if conversion failed? */
325 if(PATH_PathToRegion(pPath
, GetPolyFillMode(hdc
), &hrgnRval
))
326 PATH_EmptyPath(pPath
);
330 release_dc_ptr( dc
);
334 static BOOL
PATH_FillPath(DC
*dc
, GdiPath
*pPath
)
336 INT mapMode
, graphicsMode
;
337 SIZE ptViewportExt
, ptWindowExt
;
338 POINT ptViewportOrg
, ptWindowOrg
;
342 if(dc
->funcs
->pFillPath
)
343 return dc
->funcs
->pFillPath(dc
->physDev
);
345 /* Check that path is closed */
346 if(pPath
->state
!=PATH_Closed
)
348 SetLastError(ERROR_CAN_NOT_COMPLETE
);
352 /* Construct a region from the path and fill it */
353 if(PATH_PathToRegion(pPath
, dc
->polyFillMode
, &hrgn
))
355 /* Since PaintRgn interprets the region as being in logical coordinates
356 * but the points we store for the path are already in device
357 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
358 * Using SaveDC to save information about the mapping mode / world
359 * transform would be easier but would require more overhead, especially
360 * now that SaveDC saves the current path.
363 /* Save the information about the old mapping mode */
364 mapMode
=GetMapMode(dc
->hSelf
);
365 GetViewportExtEx(dc
->hSelf
, &ptViewportExt
);
366 GetViewportOrgEx(dc
->hSelf
, &ptViewportOrg
);
367 GetWindowExtEx(dc
->hSelf
, &ptWindowExt
);
368 GetWindowOrgEx(dc
->hSelf
, &ptWindowOrg
);
370 /* Save world transform
371 * NB: The Windows documentation on world transforms would lead one to
372 * believe that this has to be done only in GM_ADVANCED; however, my
373 * tests show that resetting the graphics mode to GM_COMPATIBLE does
374 * not reset the world transform.
376 GetWorldTransform(dc
->hSelf
, &xform
);
379 SetMapMode(dc
->hSelf
, MM_TEXT
);
380 SetViewportOrgEx(dc
->hSelf
, 0, 0, NULL
);
381 SetWindowOrgEx(dc
->hSelf
, 0, 0, NULL
);
382 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
383 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
384 ModifyWorldTransform(dc
->hSelf
, &xform
, MWT_IDENTITY
);
385 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
387 /* Paint the region */
388 PaintRgn(dc
->hSelf
, hrgn
);
390 /* Restore the old mapping mode */
391 SetMapMode(dc
->hSelf
, mapMode
);
392 SetViewportExtEx(dc
->hSelf
, ptViewportExt
.cx
, ptViewportExt
.cy
, NULL
);
393 SetViewportOrgEx(dc
->hSelf
, ptViewportOrg
.x
, ptViewportOrg
.y
, NULL
);
394 SetWindowExtEx(dc
->hSelf
, ptWindowExt
.cx
, ptWindowExt
.cy
, NULL
);
395 SetWindowOrgEx(dc
->hSelf
, ptWindowOrg
.x
, ptWindowOrg
.y
, NULL
);
397 /* Go to GM_ADVANCED temporarily to restore the world transform */
398 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
399 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
400 SetWorldTransform(dc
->hSelf
, &xform
);
401 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
408 /***********************************************************************
412 * Check that SetLastError is being called correctly
414 BOOL WINAPI
FillPath(HDC hdc
)
416 DC
*dc
= get_dc_ptr( hdc
);
419 if(!dc
) return FALSE
;
421 if(dc
->funcs
->pFillPath
)
422 bRet
= dc
->funcs
->pFillPath(dc
->physDev
);
425 bRet
= PATH_FillPath(dc
, &dc
->path
);
428 /* FIXME: Should the path be emptied even if conversion
430 PATH_EmptyPath(&dc
->path
);
433 release_dc_ptr( dc
);
438 /***********************************************************************
439 * SelectClipPath (GDI32.@)
441 * Check that SetLastError is being called correctly
443 BOOL WINAPI
SelectClipPath(HDC hdc
, INT iMode
)
447 BOOL success
= FALSE
;
448 DC
*dc
= get_dc_ptr( hdc
);
450 if(!dc
) return FALSE
;
452 if(dc
->funcs
->pSelectClipPath
)
453 success
= dc
->funcs
->pSelectClipPath(dc
->physDev
, iMode
);
458 /* Check that path is closed */
459 if(pPath
->state
!=PATH_Closed
)
460 SetLastError(ERROR_CAN_NOT_COMPLETE
);
461 /* Construct a region from the path */
462 else if(PATH_PathToRegion(pPath
, GetPolyFillMode(hdc
), &hrgnPath
))
464 success
= ExtSelectClipRgn( hdc
, hrgnPath
, iMode
) != ERROR
;
465 DeleteObject(hrgnPath
);
469 PATH_EmptyPath(pPath
);
470 /* FIXME: Should this function delete the path even if it failed? */
473 release_dc_ptr( dc
);
478 /***********************************************************************
484 * Initializes the GdiPath structure.
486 void PATH_InitGdiPath(GdiPath
*pPath
)
490 pPath
->state
=PATH_Null
;
493 pPath
->numEntriesUsed
=0;
494 pPath
->numEntriesAllocated
=0;
497 /* PATH_DestroyGdiPath
499 * Destroys a GdiPath structure (frees the memory in the arrays).
501 void PATH_DestroyGdiPath(GdiPath
*pPath
)
505 HeapFree( GetProcessHeap(), 0, pPath
->pPoints
);
506 HeapFree( GetProcessHeap(), 0, pPath
->pFlags
);
509 /* PATH_AssignGdiPath
511 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
512 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
513 * not just the pointers. Since this means that the arrays in pPathDest may
514 * need to be resized, pPathDest should have been initialized using
515 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
516 * not a copy constructor).
517 * Returns TRUE if successful, else FALSE.
519 BOOL
PATH_AssignGdiPath(GdiPath
*pPathDest
, const GdiPath
*pPathSrc
)
521 assert(pPathDest
!=NULL
&& pPathSrc
!=NULL
);
523 /* Make sure destination arrays are big enough */
524 if(!PATH_ReserveEntries(pPathDest
, pPathSrc
->numEntriesUsed
))
527 /* Perform the copy operation */
528 memcpy(pPathDest
->pPoints
, pPathSrc
->pPoints
,
529 sizeof(POINT
)*pPathSrc
->numEntriesUsed
);
530 memcpy(pPathDest
->pFlags
, pPathSrc
->pFlags
,
531 sizeof(BYTE
)*pPathSrc
->numEntriesUsed
);
533 pPathDest
->state
=pPathSrc
->state
;
534 pPathDest
->numEntriesUsed
=pPathSrc
->numEntriesUsed
;
535 pPathDest
->newStroke
=pPathSrc
->newStroke
;
542 * Should be called when a MoveTo is performed on a DC that has an
543 * open path. This starts a new stroke. Returns TRUE if successful, else
546 BOOL
PATH_MoveTo(DC
*dc
)
548 GdiPath
*pPath
= &dc
->path
;
550 /* Check that path is open */
551 if(pPath
->state
!=PATH_Open
)
552 /* FIXME: Do we have to call SetLastError? */
555 /* Start a new stroke */
556 pPath
->newStroke
=TRUE
;
563 * Should be called when a LineTo is performed on a DC that has an
564 * open path. This adds a PT_LINETO entry to the path (and possibly
565 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
566 * Returns TRUE if successful, else FALSE.
568 BOOL
PATH_LineTo(DC
*dc
, INT x
, INT y
)
570 GdiPath
*pPath
= &dc
->path
;
571 POINT point
, pointCurPos
;
573 /* Check that path is open */
574 if(pPath
->state
!=PATH_Open
)
577 /* Convert point to device coordinates */
580 if(!LPtoDP(dc
->hSelf
, &point
, 1))
583 /* Add a PT_MOVETO if necessary */
586 pPath
->newStroke
=FALSE
;
587 pointCurPos
.x
= dc
->CursPosX
;
588 pointCurPos
.y
= dc
->CursPosY
;
589 if(!LPtoDP(dc
->hSelf
, &pointCurPos
, 1))
591 if(!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
595 /* Add a PT_LINETO entry */
596 return PATH_AddEntry(pPath
, &point
, PT_LINETO
);
601 * Should be called when a call to RoundRect is performed on a DC that has
602 * an open path. Returns TRUE if successful, else FALSE.
604 * FIXME: it adds the same entries to the path as windows does, but there
605 * is an error in the bezier drawing code so that there are small pixel-size
606 * gaps when the resulting path is drawn by StrokePath()
608 BOOL
PATH_RoundRect(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
, INT ell_width
, INT ell_height
)
610 GdiPath
*pPath
= &dc
->path
;
611 POINT corners
[2], pointTemp
;
612 FLOAT_POINT ellCorners
[2];
614 /* Check that path is open */
615 if(pPath
->state
!=PATH_Open
)
618 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
621 /* Add points to the roundrect path */
622 ellCorners
[0].x
= corners
[1].x
-ell_width
;
623 ellCorners
[0].y
= corners
[0].y
;
624 ellCorners
[1].x
= corners
[1].x
;
625 ellCorners
[1].y
= corners
[0].y
+ell_height
;
626 if(!PATH_DoArcPart(pPath
, ellCorners
, 0, -M_PI_2
, PT_MOVETO
))
628 pointTemp
.x
= corners
[0].x
+ell_width
/2;
629 pointTemp
.y
= corners
[0].y
;
630 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
632 ellCorners
[0].x
= corners
[0].x
;
633 ellCorners
[1].x
= corners
[0].x
+ell_width
;
634 if(!PATH_DoArcPart(pPath
, ellCorners
, -M_PI_2
, -M_PI
, FALSE
))
636 pointTemp
.x
= corners
[0].x
;
637 pointTemp
.y
= corners
[1].y
-ell_height
/2;
638 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
640 ellCorners
[0].y
= corners
[1].y
-ell_height
;
641 ellCorners
[1].y
= corners
[1].y
;
642 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI
, M_PI_2
, FALSE
))
644 pointTemp
.x
= corners
[1].x
-ell_width
/2;
645 pointTemp
.y
= corners
[1].y
;
646 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
648 ellCorners
[0].x
= corners
[1].x
-ell_width
;
649 ellCorners
[1].x
= corners
[1].x
;
650 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI_2
, 0, FALSE
))
653 /* Close the roundrect figure */
654 if(!CloseFigure(dc
->hSelf
))
662 * Should be called when a call to Rectangle is performed on a DC that has
663 * an open path. Returns TRUE if successful, else FALSE.
665 BOOL
PATH_Rectangle(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
)
667 GdiPath
*pPath
= &dc
->path
;
668 POINT corners
[2], pointTemp
;
670 /* Check that path is open */
671 if(pPath
->state
!=PATH_Open
)
674 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
677 /* Close any previous figure */
678 if(!CloseFigure(dc
->hSelf
))
680 /* The CloseFigure call shouldn't have failed */
685 /* Add four points to the path */
686 pointTemp
.x
=corners
[1].x
;
687 pointTemp
.y
=corners
[0].y
;
688 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_MOVETO
))
690 if(!PATH_AddEntry(pPath
, corners
, PT_LINETO
))
692 pointTemp
.x
=corners
[0].x
;
693 pointTemp
.y
=corners
[1].y
;
694 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
696 if(!PATH_AddEntry(pPath
, corners
+1, PT_LINETO
))
699 /* Close the rectangle figure */
700 if(!CloseFigure(dc
->hSelf
))
702 /* The CloseFigure call shouldn't have failed */
712 * Should be called when a call to Ellipse is performed on a DC that has
713 * an open path. This adds four Bezier splines representing the ellipse
714 * to the path. Returns TRUE if successful, else FALSE.
716 BOOL
PATH_Ellipse(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
)
718 return( PATH_Arc(dc
, x1
, y1
, x2
, y2
, x1
, (y1
+y2
)/2, x1
, (y1
+y2
)/2,0) &&
719 CloseFigure(dc
->hSelf
) );
724 * Should be called when a call to Arc is performed on a DC that has
725 * an open path. This adds up to five Bezier splines representing the arc
726 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
727 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
728 * -1 we add 1 extra line from the current DC position to the starting position
729 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
732 BOOL
PATH_Arc(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
,
733 INT xStart
, INT yStart
, INT xEnd
, INT yEnd
, INT lines
)
735 GdiPath
*pPath
= &dc
->path
;
736 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
=0.0;
737 /* Initialize angleEndQuadrant to silence gcc's warning */
739 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
740 POINT centre
, pointCurPos
;
744 /* FIXME: This function should check for all possible error returns */
745 /* FIXME: Do we have to respect newStroke? */
747 /* Check that path is open */
748 if(pPath
->state
!=PATH_Open
)
751 /* Check for zero height / width */
752 /* FIXME: Only in GM_COMPATIBLE? */
756 /* Convert points to device coordinates */
761 pointStart
.x
= xStart
;
762 pointStart
.y
= yStart
;
765 INTERNAL_LPTODP_FLOAT(dc
, corners
);
766 INTERNAL_LPTODP_FLOAT(dc
, corners
+1);
767 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
);
768 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
);
770 /* Make sure first corner is top left and second corner is bottom right */
771 if(corners
[0].x
>corners
[1].x
)
774 corners
[0].x
=corners
[1].x
;
777 if(corners
[0].y
>corners
[1].y
)
780 corners
[0].y
=corners
[1].y
;
784 /* Compute start and end angle */
785 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
786 angleStart
=atan2(y
, x
);
787 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
788 angleEnd
=atan2(y
, x
);
790 /* Make sure the end angle is "on the right side" of the start angle */
791 if(dc
->ArcDirection
==AD_CLOCKWISE
)
793 if(angleEnd
<=angleStart
)
796 assert(angleEnd
>=angleStart
);
801 if(angleEnd
>=angleStart
)
804 assert(angleEnd
<=angleStart
);
808 /* In GM_COMPATIBLE, don't include bottom and right edges */
809 if(dc
->GraphicsMode
==GM_COMPATIBLE
)
815 /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
816 if(lines
==-1 && pPath
->newStroke
)
818 pPath
->newStroke
=FALSE
;
819 pointCurPos
.x
= dc
->CursPosX
;
820 pointCurPos
.y
= dc
->CursPosY
;
821 if(!LPtoDP(dc
->hSelf
, &pointCurPos
, 1))
823 if(!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
827 /* Add the arc to the path with one Bezier spline per quadrant that the
833 /* Determine the start and end angles for this quadrant */
836 angleStartQuadrant
=angleStart
;
837 if(dc
->ArcDirection
==AD_CLOCKWISE
)
838 angleEndQuadrant
=(floor(angleStart
/M_PI_2
)+1.0)*M_PI_2
;
840 angleEndQuadrant
=(ceil(angleStart
/M_PI_2
)-1.0)*M_PI_2
;
844 angleStartQuadrant
=angleEndQuadrant
;
845 if(dc
->ArcDirection
==AD_CLOCKWISE
)
846 angleEndQuadrant
+=M_PI_2
;
848 angleEndQuadrant
-=M_PI_2
;
851 /* Have we reached the last part of the arc? */
852 if((dc
->ArcDirection
==AD_CLOCKWISE
&&
853 angleEnd
<angleEndQuadrant
) ||
854 (dc
->ArcDirection
==AD_COUNTERCLOCKWISE
&&
855 angleEnd
>angleEndQuadrant
))
857 /* Adjust the end angle for this quadrant */
858 angleEndQuadrant
=angleEnd
;
862 /* Add the Bezier spline to the path */
863 PATH_DoArcPart(pPath
, corners
, angleStartQuadrant
, angleEndQuadrant
,
864 start
? (lines
==-1 ? PT_LINETO
: PT_MOVETO
) : FALSE
);
868 /* chord: close figure. pie: add line and close figure */
871 if(!CloseFigure(dc
->hSelf
))
876 centre
.x
= (corners
[0].x
+corners
[1].x
)/2;
877 centre
.y
= (corners
[0].y
+corners
[1].y
)/2;
878 if(!PATH_AddEntry(pPath
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
885 BOOL
PATH_PolyBezierTo(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
887 GdiPath
*pPath
= &dc
->path
;
891 /* Check that path is open */
892 if(pPath
->state
!=PATH_Open
)
895 /* Add a PT_MOVETO if necessary */
898 pPath
->newStroke
=FALSE
;
901 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
903 if(!PATH_AddEntry(pPath
, &pt
, PT_MOVETO
))
907 for(i
= 0; i
< cbPoints
; i
++) {
909 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
911 PATH_AddEntry(pPath
, &pt
, PT_BEZIERTO
);
916 BOOL
PATH_PolyBezier(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
918 GdiPath
*pPath
= &dc
->path
;
922 /* Check that path is open */
923 if(pPath
->state
!=PATH_Open
)
926 for(i
= 0; i
< cbPoints
; i
++) {
928 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
930 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_BEZIERTO
);
937 * Should be called when a call to PolyDraw is performed on a DC that has
938 * an open path. Returns TRUE if successful, else FALSE.
940 BOOL
PATH_PolyDraw(DC
*dc
, const POINT
*pts
, const BYTE
*types
,
943 GdiPath
*pPath
= &dc
->path
;
944 POINT lastmove
, orig_pos
;
947 lastmove
.x
= orig_pos
.x
= dc
->CursPosX
;
948 lastmove
.y
= orig_pos
.y
= dc
->CursPosY
;
950 for(i
= pPath
->numEntriesUsed
- 1; i
>= 0; i
--){
951 if(pPath
->pFlags
[i
] == PT_MOVETO
){
952 lastmove
.x
= pPath
->pPoints
[i
].x
;
953 lastmove
.y
= pPath
->pPoints
[i
].y
;
954 if(!DPtoLP(dc
->hSelf
, &lastmove
, 1))
960 for(i
= 0; i
< cbPoints
; i
++){
961 if(types
[i
] == PT_MOVETO
){
962 pPath
->newStroke
= TRUE
;
963 lastmove
.x
= pts
[i
].x
;
964 lastmove
.y
= pts
[i
].y
;
966 else if((types
[i
] & ~PT_CLOSEFIGURE
) == PT_LINETO
){
967 PATH_LineTo(dc
, pts
[i
].x
, pts
[i
].y
);
969 else if(types
[i
] == PT_BEZIERTO
){
970 if(!((i
+ 2 < cbPoints
) && (types
[i
+ 1] == PT_BEZIERTO
)
971 && ((types
[i
+ 2] & ~PT_CLOSEFIGURE
) == PT_BEZIERTO
)))
973 PATH_PolyBezierTo(dc
, &(pts
[i
]), 3);
979 dc
->CursPosX
= pts
[i
].x
;
980 dc
->CursPosY
= pts
[i
].y
;
982 if(types
[i
] & PT_CLOSEFIGURE
){
983 pPath
->pFlags
[pPath
->numEntriesUsed
-1] |= PT_CLOSEFIGURE
;
984 pPath
->newStroke
= TRUE
;
985 dc
->CursPosX
= lastmove
.x
;
986 dc
->CursPosY
= lastmove
.y
;
993 if((dc
->CursPosX
!= orig_pos
.x
) || (dc
->CursPosY
!= orig_pos
.y
)){
994 pPath
->newStroke
= TRUE
;
995 dc
->CursPosX
= orig_pos
.x
;
996 dc
->CursPosY
= orig_pos
.y
;
1002 BOOL
PATH_Polyline(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
1004 GdiPath
*pPath
= &dc
->path
;
1008 /* Check that path is open */
1009 if(pPath
->state
!=PATH_Open
)
1012 for(i
= 0; i
< cbPoints
; i
++) {
1014 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1016 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_LINETO
);
1021 BOOL
PATH_PolylineTo(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
1023 GdiPath
*pPath
= &dc
->path
;
1027 /* Check that path is open */
1028 if(pPath
->state
!=PATH_Open
)
1031 /* Add a PT_MOVETO if necessary */
1032 if(pPath
->newStroke
)
1034 pPath
->newStroke
=FALSE
;
1035 pt
.x
= dc
->CursPosX
;
1036 pt
.y
= dc
->CursPosY
;
1037 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1039 if(!PATH_AddEntry(pPath
, &pt
, PT_MOVETO
))
1043 for(i
= 0; i
< cbPoints
; i
++) {
1045 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1047 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
1054 BOOL
PATH_Polygon(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
1056 GdiPath
*pPath
= &dc
->path
;
1060 /* Check that path is open */
1061 if(pPath
->state
!=PATH_Open
)
1064 for(i
= 0; i
< cbPoints
; i
++) {
1066 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1068 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
:
1069 ((i
== cbPoints
-1) ? PT_LINETO
| PT_CLOSEFIGURE
:
1075 BOOL
PATH_PolyPolygon( DC
*dc
, const POINT
* pts
, const INT
* counts
,
1078 GdiPath
*pPath
= &dc
->path
;
1083 /* Check that path is open */
1084 if(pPath
->state
!=PATH_Open
)
1087 for(i
= 0, poly
= 0; poly
< polygons
; poly
++) {
1088 for(point
= 0; point
< counts
[poly
]; point
++, i
++) {
1090 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1092 if(point
== 0) startpt
= pt
;
1093 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1095 /* win98 adds an extra line to close the figure for some reason */
1096 PATH_AddEntry(pPath
, &startpt
, PT_LINETO
| PT_CLOSEFIGURE
);
1101 BOOL
PATH_PolyPolyline( DC
*dc
, const POINT
* pts
, const DWORD
* counts
,
1104 GdiPath
*pPath
= &dc
->path
;
1106 UINT poly
, point
, i
;
1108 /* Check that path is open */
1109 if(pPath
->state
!=PATH_Open
)
1112 for(i
= 0, poly
= 0; poly
< polylines
; poly
++) {
1113 for(point
= 0; point
< counts
[poly
]; point
++, i
++) {
1115 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1117 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1123 /***********************************************************************
1124 * Internal functions
1127 /* PATH_CheckCorners
1129 * Helper function for PATH_RoundRect() and PATH_Rectangle()
1131 static BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
)
1135 /* Convert points to device coordinates */
1140 if(!LPtoDP(dc
->hSelf
, corners
, 2))
1143 /* Make sure first corner is top left and second corner is bottom right */
1144 if(corners
[0].x
>corners
[1].x
)
1147 corners
[0].x
=corners
[1].x
;
1150 if(corners
[0].y
>corners
[1].y
)
1153 corners
[0].y
=corners
[1].y
;
1157 /* In GM_COMPATIBLE, don't include bottom and right edges */
1158 if(dc
->GraphicsMode
==GM_COMPATIBLE
)
1167 /* PATH_AddFlatBezier
1169 static BOOL
PATH_AddFlatBezier(GdiPath
*pPath
, POINT
*pt
, BOOL closed
)
1174 pts
= GDI_Bezier( pt
, 4, &no
);
1175 if(!pts
) return FALSE
;
1177 for(i
= 1; i
< no
; i
++)
1178 PATH_AddEntry(pPath
, &pts
[i
],
1179 (i
== no
-1 && closed
) ? PT_LINETO
| PT_CLOSEFIGURE
: PT_LINETO
);
1180 HeapFree( GetProcessHeap(), 0, pts
);
1186 * Replaces Beziers with line segments
1189 static BOOL
PATH_FlattenPath(GdiPath
*pPath
)
1194 memset(&newPath
, 0, sizeof(newPath
));
1195 newPath
.state
= PATH_Open
;
1196 for(srcpt
= 0; srcpt
< pPath
->numEntriesUsed
; srcpt
++) {
1197 switch(pPath
->pFlags
[srcpt
] & ~PT_CLOSEFIGURE
) {
1200 PATH_AddEntry(&newPath
, &pPath
->pPoints
[srcpt
],
1201 pPath
->pFlags
[srcpt
]);
1204 PATH_AddFlatBezier(&newPath
, &pPath
->pPoints
[srcpt
-1],
1205 pPath
->pFlags
[srcpt
+2] & PT_CLOSEFIGURE
);
1210 newPath
.state
= PATH_Closed
;
1211 PATH_AssignGdiPath(pPath
, &newPath
);
1212 PATH_DestroyGdiPath(&newPath
);
1216 /* PATH_PathToRegion
1218 * Creates a region from the specified path using the specified polygon
1219 * filling mode. The path is left unchanged. A handle to the region that
1220 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1221 * error occurs, SetLastError is called with the appropriate value and
1222 * FALSE is returned.
1224 static BOOL
PATH_PathToRegion(GdiPath
*pPath
, INT nPolyFillMode
,
1227 int numStrokes
, iStroke
, i
;
1228 INT
*pNumPointsInStroke
;
1231 assert(pPath
!=NULL
);
1232 assert(pHrgn
!=NULL
);
1234 PATH_FlattenPath(pPath
);
1236 /* FIXME: What happens when number of points is zero? */
1238 /* First pass: Find out how many strokes there are in the path */
1239 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1241 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1242 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1245 /* Allocate memory for number-of-points-in-stroke array */
1246 pNumPointsInStroke
=HeapAlloc( GetProcessHeap(), 0, sizeof(int) * numStrokes
);
1247 if(!pNumPointsInStroke
)
1249 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1253 /* Second pass: remember number of points in each polygon */
1254 iStroke
=-1; /* Will get incremented to 0 at beginning of first stroke */
1255 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1257 /* Is this the beginning of a new stroke? */
1258 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1261 pNumPointsInStroke
[iStroke
]=0;
1264 pNumPointsInStroke
[iStroke
]++;
1267 /* Create a region from the strokes */
1268 hrgn
=CreatePolyPolygonRgn(pPath
->pPoints
, pNumPointsInStroke
,
1269 numStrokes
, nPolyFillMode
);
1271 /* Free memory for number-of-points-in-stroke array */
1272 HeapFree( GetProcessHeap(), 0, pNumPointsInStroke
);
1276 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1285 static inline INT
int_from_fixed(FIXED f
)
1287 return (f
.fract
>= 0x8000) ? (f
.value
+ 1) : f
.value
;
1290 /**********************************************************************
1293 * internally used by PATH_add_outline
1295 static void PATH_BezierTo(GdiPath
*pPath
, POINT
*lppt
, INT n
)
1301 PATH_AddEntry(pPath
, &lppt
[1], PT_LINETO
);
1305 PATH_AddEntry(pPath
, &lppt
[0], PT_BEZIERTO
);
1306 PATH_AddEntry(pPath
, &lppt
[1], PT_BEZIERTO
);
1307 PATH_AddEntry(pPath
, &lppt
[2], PT_BEZIERTO
);
1321 pt
[2].x
= (lppt
[i
+2].x
+ lppt
[i
+1].x
) / 2;
1322 pt
[2].y
= (lppt
[i
+2].y
+ lppt
[i
+1].y
) / 2;
1323 PATH_BezierTo(pPath
, pt
, 3);
1331 PATH_BezierTo(pPath
, pt
, 3);
1335 static BOOL
PATH_add_outline(DC
*dc
, INT x
, INT y
, TTPOLYGONHEADER
*header
, DWORD size
)
1337 GdiPath
*pPath
= &dc
->path
;
1338 TTPOLYGONHEADER
*start
;
1343 while ((char *)header
< (char *)start
+ size
)
1347 if (header
->dwType
!= TT_POLYGON_TYPE
)
1349 FIXME("Unknown header type %d\n", header
->dwType
);
1353 pt
.x
= x
+ int_from_fixed(header
->pfxStart
.x
);
1354 pt
.y
= y
- int_from_fixed(header
->pfxStart
.y
);
1355 LPtoDP(dc
->hSelf
, &pt
, 1);
1356 PATH_AddEntry(pPath
, &pt
, PT_MOVETO
);
1358 curve
= (TTPOLYCURVE
*)(header
+ 1);
1360 while ((char *)curve
< (char *)header
+ header
->cb
)
1362 /*TRACE("curve->wType %d\n", curve->wType);*/
1364 switch(curve
->wType
)
1370 for (i
= 0; i
< curve
->cpfx
; i
++)
1372 pt
.x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1373 pt
.y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1374 LPtoDP(dc
->hSelf
, &pt
, 1);
1375 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
1380 case TT_PRIM_QSPLINE
:
1381 case TT_PRIM_CSPLINE
:
1385 POINT
*pts
= HeapAlloc(GetProcessHeap(), 0, (curve
->cpfx
+ 1) * sizeof(POINT
));
1387 if (!pts
) return FALSE
;
1389 ptfx
= *(POINTFX
*)((char *)curve
- sizeof(POINTFX
));
1391 pts
[0].x
= x
+ int_from_fixed(ptfx
.x
);
1392 pts
[0].y
= y
- int_from_fixed(ptfx
.y
);
1393 LPtoDP(dc
->hSelf
, &pts
[0], 1);
1395 for(i
= 0; i
< curve
->cpfx
; i
++)
1397 pts
[i
+ 1].x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1398 pts
[i
+ 1].y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1399 LPtoDP(dc
->hSelf
, &pts
[i
+ 1], 1);
1402 PATH_BezierTo(pPath
, pts
, curve
->cpfx
+ 1);
1404 HeapFree(GetProcessHeap(), 0, pts
);
1409 FIXME("Unknown curve type %04x\n", curve
->wType
);
1413 curve
= (TTPOLYCURVE
*)&curve
->apfx
[curve
->cpfx
];
1416 header
= (TTPOLYGONHEADER
*)((char *)header
+ header
->cb
);
1419 return CloseFigure(dc
->hSelf
);
1422 /**********************************************************************
1425 BOOL
PATH_ExtTextOut(DC
*dc
, INT x
, INT y
, UINT flags
, const RECT
*lprc
,
1426 LPCWSTR str
, UINT count
, const INT
*dx
)
1429 double cosEsc
, sinEsc
;
1432 HDC hdc
= dc
->hSelf
;
1433 INT offset
= 0, xoff
= 0, yoff
= 0;
1435 TRACE("%p, %d, %d, %08x, %s, %s, %d, %p)\n", hdc
, x
, y
, flags
,
1436 wine_dbgstr_rect(lprc
), debugstr_wn(str
, count
), count
, dx
);
1438 if (!count
) return TRUE
;
1440 GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(lf
), &lf
);
1442 if (lf
.lfEscapement
!= 0)
1444 cosEsc
= cos(lf
.lfEscapement
* M_PI
/ 1800);
1445 sinEsc
= sin(lf
.lfEscapement
* M_PI
/ 1800);
1452 GetDCOrgEx(hdc
, &org
);
1454 for (idx
= 0; idx
< count
; idx
++)
1460 dwSize
= GetGlyphOutlineW(hdc
, str
[idx
], GGO_GLYPH_INDEX
| GGO_NATIVE
, &gm
, 0, NULL
, NULL
);
1461 if (!dwSize
) return FALSE
;
1463 outline
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
1464 if (!outline
) return FALSE
;
1466 GetGlyphOutlineW(hdc
, str
[idx
], GGO_GLYPH_INDEX
| GGO_NATIVE
, &gm
, dwSize
, outline
, NULL
);
1468 PATH_add_outline(dc
, org
.x
+ x
+ xoff
, org
.x
+ y
+ yoff
, outline
, dwSize
);
1470 HeapFree(GetProcessHeap(), 0, outline
);
1475 xoff
= offset
* cosEsc
;
1476 yoff
= offset
* -sinEsc
;
1480 xoff
+= gm
.gmCellIncX
;
1481 yoff
+= gm
.gmCellIncY
;
1489 * Removes all entries from the path and sets the path state to PATH_Null.
1491 static void PATH_EmptyPath(GdiPath
*pPath
)
1493 assert(pPath
!=NULL
);
1495 pPath
->state
=PATH_Null
;
1496 pPath
->numEntriesUsed
=0;
1501 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1502 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1503 * successful, FALSE otherwise (e.g. if not enough memory was available).
1505 BOOL
PATH_AddEntry(GdiPath
*pPath
, const POINT
*pPoint
, BYTE flags
)
1507 assert(pPath
!=NULL
);
1509 /* FIXME: If newStroke is true, perhaps we want to check that we're
1510 * getting a PT_MOVETO
1512 TRACE("(%d,%d) - %d\n", pPoint
->x
, pPoint
->y
, flags
);
1514 /* Check that path is open */
1515 if(pPath
->state
!=PATH_Open
)
1518 /* Reserve enough memory for an extra path entry */
1519 if(!PATH_ReserveEntries(pPath
, pPath
->numEntriesUsed
+1))
1522 /* Store information in path entry */
1523 pPath
->pPoints
[pPath
->numEntriesUsed
]=*pPoint
;
1524 pPath
->pFlags
[pPath
->numEntriesUsed
]=flags
;
1526 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1527 if((flags
& PT_CLOSEFIGURE
) == PT_CLOSEFIGURE
)
1528 pPath
->newStroke
=TRUE
;
1530 /* Increment entry count */
1531 pPath
->numEntriesUsed
++;
1536 /* PATH_ReserveEntries
1538 * Ensures that at least "numEntries" entries (for points and flags) have
1539 * been allocated; allocates larger arrays and copies the existing entries
1540 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1542 static BOOL
PATH_ReserveEntries(GdiPath
*pPath
, INT numEntries
)
1544 INT numEntriesToAllocate
;
1548 assert(pPath
!=NULL
);
1549 assert(numEntries
>=0);
1551 /* Do we have to allocate more memory? */
1552 if(numEntries
> pPath
->numEntriesAllocated
)
1554 /* Find number of entries to allocate. We let the size of the array
1555 * grow exponentially, since that will guarantee linear time
1557 if(pPath
->numEntriesAllocated
)
1559 numEntriesToAllocate
=pPath
->numEntriesAllocated
;
1560 while(numEntriesToAllocate
<numEntries
)
1561 numEntriesToAllocate
=numEntriesToAllocate
*GROW_FACTOR_NUMER
/
1565 numEntriesToAllocate
=numEntries
;
1567 /* Allocate new arrays */
1568 pPointsNew
=HeapAlloc( GetProcessHeap(), 0, numEntriesToAllocate
* sizeof(POINT
) );
1571 pFlagsNew
=HeapAlloc( GetProcessHeap(), 0, numEntriesToAllocate
* sizeof(BYTE
) );
1574 HeapFree( GetProcessHeap(), 0, pPointsNew
);
1578 /* Copy old arrays to new arrays and discard old arrays */
1581 assert(pPath
->pFlags
);
1583 memcpy(pPointsNew
, pPath
->pPoints
,
1584 sizeof(POINT
)*pPath
->numEntriesUsed
);
1585 memcpy(pFlagsNew
, pPath
->pFlags
,
1586 sizeof(BYTE
)*pPath
->numEntriesUsed
);
1588 HeapFree( GetProcessHeap(), 0, pPath
->pPoints
);
1589 HeapFree( GetProcessHeap(), 0, pPath
->pFlags
);
1591 pPath
->pPoints
=pPointsNew
;
1592 pPath
->pFlags
=pFlagsNew
;
1593 pPath
->numEntriesAllocated
=numEntriesToAllocate
;
1601 * Creates a Bezier spline that corresponds to part of an arc and appends the
1602 * corresponding points to the path. The start and end angles are passed in
1603 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1604 * at most. If "startEntryType" is non-zero, an entry of that type for the first
1605 * control point is added to the path; otherwise, it is assumed that the current
1606 * position is equal to the first control point.
1608 static BOOL
PATH_DoArcPart(GdiPath
*pPath
, FLOAT_POINT corners
[],
1609 double angleStart
, double angleEnd
, BYTE startEntryType
)
1611 double halfAngle
, a
;
1612 double xNorm
[4], yNorm
[4];
1616 assert(fabs(angleEnd
-angleStart
)<=M_PI_2
);
1618 /* FIXME: Is there an easier way of computing this? */
1620 /* Compute control points */
1621 halfAngle
=(angleEnd
-angleStart
)/2.0;
1622 if(fabs(halfAngle
)>1e-8)
1624 a
=4.0/3.0*(1-cos(halfAngle
))/sin(halfAngle
);
1625 xNorm
[0]=cos(angleStart
);
1626 yNorm
[0]=sin(angleStart
);
1627 xNorm
[1]=xNorm
[0] - a
*yNorm
[0];
1628 yNorm
[1]=yNorm
[0] + a
*xNorm
[0];
1629 xNorm
[3]=cos(angleEnd
);
1630 yNorm
[3]=sin(angleEnd
);
1631 xNorm
[2]=xNorm
[3] + a
*yNorm
[3];
1632 yNorm
[2]=yNorm
[3] - a
*xNorm
[3];
1637 xNorm
[i
]=cos(angleStart
);
1638 yNorm
[i
]=sin(angleStart
);
1641 /* Add starting point to path if desired */
1644 PATH_ScaleNormalizedPoint(corners
, xNorm
[0], yNorm
[0], &point
);
1645 if(!PATH_AddEntry(pPath
, &point
, startEntryType
))
1649 /* Add remaining control points */
1652 PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &point
);
1653 if(!PATH_AddEntry(pPath
, &point
, PT_BEZIERTO
))
1660 /* PATH_ScaleNormalizedPoint
1662 * Scales a normalized point (x, y) with respect to the box whose corners are
1663 * passed in "corners". The point is stored in "*pPoint". The normalized
1664 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1665 * (1.0, 1.0) correspond to corners[1].
1667 static void PATH_ScaleNormalizedPoint(FLOAT_POINT corners
[], double x
,
1668 double y
, POINT
*pPoint
)
1670 pPoint
->x
=GDI_ROUND( (double)corners
[0].x
+
1671 (double)(corners
[1].x
-corners
[0].x
)*0.5*(x
+1.0) );
1672 pPoint
->y
=GDI_ROUND( (double)corners
[0].y
+
1673 (double)(corners
[1].y
-corners
[0].y
)*0.5*(y
+1.0) );
1676 /* PATH_NormalizePoint
1678 * Normalizes a point with respect to the box whose corners are passed in
1679 * "corners". The normalized coordinates are stored in "*pX" and "*pY".
1681 static void PATH_NormalizePoint(FLOAT_POINT corners
[],
1682 const FLOAT_POINT
*pPoint
,
1683 double *pX
, double *pY
)
1685 *pX
=(double)(pPoint
->x
-corners
[0].x
)/(double)(corners
[1].x
-corners
[0].x
) *
1687 *pY
=(double)(pPoint
->y
-corners
[0].y
)/(double)(corners
[1].y
-corners
[0].y
) *
1692 /*******************************************************************
1693 * FlattenPath [GDI32.@]
1697 BOOL WINAPI
FlattenPath(HDC hdc
)
1700 DC
*dc
= get_dc_ptr( hdc
);
1702 if(!dc
) return FALSE
;
1704 if(dc
->funcs
->pFlattenPath
) ret
= dc
->funcs
->pFlattenPath(dc
->physDev
);
1707 GdiPath
*pPath
= &dc
->path
;
1708 if(pPath
->state
!= PATH_Closed
)
1709 ret
= PATH_FlattenPath(pPath
);
1711 release_dc_ptr( dc
);
1716 static BOOL
PATH_StrokePath(DC
*dc
, GdiPath
*pPath
)
1718 INT i
, nLinePts
, nAlloc
;
1720 POINT ptViewportOrg
, ptWindowOrg
;
1721 SIZE szViewportExt
, szWindowExt
;
1722 DWORD mapMode
, graphicsMode
;
1726 if(dc
->funcs
->pStrokePath
)
1727 return dc
->funcs
->pStrokePath(dc
->physDev
);
1729 if(pPath
->state
!= PATH_Closed
)
1732 /* Save the mapping mode info */
1733 mapMode
=GetMapMode(dc
->hSelf
);
1734 GetViewportExtEx(dc
->hSelf
, &szViewportExt
);
1735 GetViewportOrgEx(dc
->hSelf
, &ptViewportOrg
);
1736 GetWindowExtEx(dc
->hSelf
, &szWindowExt
);
1737 GetWindowOrgEx(dc
->hSelf
, &ptWindowOrg
);
1738 GetWorldTransform(dc
->hSelf
, &xform
);
1741 SetMapMode(dc
->hSelf
, MM_TEXT
);
1742 SetViewportOrgEx(dc
->hSelf
, 0, 0, NULL
);
1743 SetWindowOrgEx(dc
->hSelf
, 0, 0, NULL
);
1744 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
1745 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
1746 ModifyWorldTransform(dc
->hSelf
, &xform
, MWT_IDENTITY
);
1747 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
1749 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1750 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1751 * space in case we get one to keep the number of reallocations small. */
1752 nAlloc
= pPath
->numEntriesUsed
+ 1 + 300;
1753 pLinePts
= HeapAlloc(GetProcessHeap(), 0, nAlloc
* sizeof(POINT
));
1756 for(i
= 0; i
< pPath
->numEntriesUsed
; i
++) {
1757 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
)) &&
1758 (pPath
->pFlags
[i
] != PT_MOVETO
)) {
1759 ERR("Expected PT_MOVETO %s, got path flag %d\n",
1760 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1761 (INT
)pPath
->pFlags
[i
]);
1765 switch(pPath
->pFlags
[i
]) {
1767 TRACE("Got PT_MOVETO (%d, %d)\n",
1768 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1770 Polyline(dc
->hSelf
, pLinePts
, nLinePts
);
1772 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1775 case (PT_LINETO
| PT_CLOSEFIGURE
):
1776 TRACE("Got PT_LINETO (%d, %d)\n",
1777 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1778 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1781 TRACE("Got PT_BEZIERTO\n");
1782 if(pPath
->pFlags
[i
+1] != PT_BEZIERTO
||
1783 (pPath
->pFlags
[i
+2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
) {
1784 ERR("Path didn't contain 3 successive PT_BEZIERTOs\n");
1788 INT nBzrPts
, nMinAlloc
;
1789 POINT
*pBzrPts
= GDI_Bezier(&pPath
->pPoints
[i
-1], 4, &nBzrPts
);
1790 /* Make sure we have allocated enough memory for the lines of
1791 * this bezier and the rest of the path, assuming we won't get
1792 * another one (since we won't reallocate again then). */
1793 nMinAlloc
= nLinePts
+ (pPath
->numEntriesUsed
- i
) + nBzrPts
;
1794 if(nAlloc
< nMinAlloc
)
1796 nAlloc
= nMinAlloc
* 2;
1797 pLinePts
= HeapReAlloc(GetProcessHeap(), 0, pLinePts
,
1798 nAlloc
* sizeof(POINT
));
1800 memcpy(&pLinePts
[nLinePts
], &pBzrPts
[1],
1801 (nBzrPts
- 1) * sizeof(POINT
));
1802 nLinePts
+= nBzrPts
- 1;
1803 HeapFree(GetProcessHeap(), 0, pBzrPts
);
1808 ERR("Got path flag %d\n", (INT
)pPath
->pFlags
[i
]);
1812 if(pPath
->pFlags
[i
] & PT_CLOSEFIGURE
)
1813 pLinePts
[nLinePts
++] = pLinePts
[0];
1816 Polyline(dc
->hSelf
, pLinePts
, nLinePts
);
1819 HeapFree(GetProcessHeap(), 0, pLinePts
);
1821 /* Restore the old mapping mode */
1822 SetMapMode(dc
->hSelf
, mapMode
);
1823 SetWindowExtEx(dc
->hSelf
, szWindowExt
.cx
, szWindowExt
.cy
, NULL
);
1824 SetWindowOrgEx(dc
->hSelf
, ptWindowOrg
.x
, ptWindowOrg
.y
, NULL
);
1825 SetViewportExtEx(dc
->hSelf
, szViewportExt
.cx
, szViewportExt
.cy
, NULL
);
1826 SetViewportOrgEx(dc
->hSelf
, ptViewportOrg
.x
, ptViewportOrg
.y
, NULL
);
1828 /* Go to GM_ADVANCED temporarily to restore the world transform */
1829 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
1830 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
1831 SetWorldTransform(dc
->hSelf
, &xform
);
1832 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
1834 /* If we've moved the current point then get its new position
1835 which will be in device (MM_TEXT) co-ords, convert it to
1836 logical co-ords and re-set it. This basically updates
1837 dc->CurPosX|Y so that their values are in the correct mapping
1842 GetCurrentPositionEx(dc
->hSelf
, &pt
);
1843 DPtoLP(dc
->hSelf
, &pt
, 1);
1844 MoveToEx(dc
->hSelf
, pt
.x
, pt
.y
, NULL
);
1850 #define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1852 static BOOL
PATH_WidenPath(DC
*dc
)
1854 INT i
, j
, numStrokes
, penWidth
, penWidthIn
, penWidthOut
, size
, penStyle
;
1856 GdiPath
*pPath
, *pNewPath
, **pStrokes
, *pUpPath
, *pDownPath
;
1858 DWORD obj_type
, joint
, endcap
, penType
;
1862 if(pPath
->state
== PATH_Open
) {
1863 SetLastError(ERROR_CAN_NOT_COMPLETE
);
1867 PATH_FlattenPath(pPath
);
1869 size
= GetObjectW( dc
->hPen
, 0, NULL
);
1871 SetLastError(ERROR_CAN_NOT_COMPLETE
);
1875 elp
= HeapAlloc( GetProcessHeap(), 0, size
);
1876 GetObjectW( dc
->hPen
, size
, elp
);
1878 obj_type
= GetObjectType(dc
->hPen
);
1879 if(obj_type
== OBJ_PEN
) {
1880 penStyle
= ((LOGPEN
*)elp
)->lopnStyle
;
1882 else if(obj_type
== OBJ_EXTPEN
) {
1883 penStyle
= elp
->elpPenStyle
;
1886 SetLastError(ERROR_CAN_NOT_COMPLETE
);
1887 HeapFree( GetProcessHeap(), 0, elp
);
1891 penWidth
= elp
->elpWidth
;
1892 HeapFree( GetProcessHeap(), 0, elp
);
1894 endcap
= (PS_ENDCAP_MASK
& penStyle
);
1895 joint
= (PS_JOIN_MASK
& penStyle
);
1896 penType
= (PS_TYPE_MASK
& penStyle
);
1898 /* The function cannot apply to cosmetic pens */
1899 if(obj_type
== OBJ_EXTPEN
&& penType
== PS_COSMETIC
) {
1900 SetLastError(ERROR_CAN_NOT_COMPLETE
);
1904 penWidthIn
= penWidth
/ 2;
1905 penWidthOut
= penWidth
/ 2;
1906 if(penWidthIn
+ penWidthOut
< penWidth
)
1911 pStrokes
= HeapAlloc(GetProcessHeap(), 0, numStrokes
* sizeof(GdiPath
*));
1912 pStrokes
[0] = HeapAlloc(GetProcessHeap(), 0, sizeof(GdiPath
));
1913 PATH_InitGdiPath(pStrokes
[0]);
1914 pStrokes
[0]->pFlags
= HeapAlloc(GetProcessHeap(), 0, pPath
->numEntriesUsed
* sizeof(INT
));
1915 pStrokes
[0]->pPoints
= HeapAlloc(GetProcessHeap(), 0, pPath
->numEntriesUsed
* sizeof(POINT
));
1916 pStrokes
[0]->numEntriesUsed
= 0;
1918 for(i
= 0, j
= 0; i
< pPath
->numEntriesUsed
; i
++, j
++) {
1920 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
)) &&
1921 (pPath
->pFlags
[i
] != PT_MOVETO
)) {
1922 ERR("Expected PT_MOVETO %s, got path flag %c\n",
1923 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1927 switch(pPath
->pFlags
[i
]) {
1929 if(numStrokes
> 0) {
1930 pStrokes
[numStrokes
- 1]->state
= PATH_Closed
;
1934 pStrokes
= HeapReAlloc(GetProcessHeap(), 0, pStrokes
, numStrokes
* sizeof(GdiPath
*));
1935 pStrokes
[numStrokes
- 1] = HeapAlloc(GetProcessHeap(), 0, sizeof(GdiPath
));
1936 PATH_InitGdiPath(pStrokes
[numStrokes
- 1]);
1937 pStrokes
[numStrokes
- 1]->state
= PATH_Open
;
1939 case (PT_LINETO
| PT_CLOSEFIGURE
):
1940 point
.x
= pPath
->pPoints
[i
].x
;
1941 point
.y
= pPath
->pPoints
[i
].y
;
1942 PATH_AddEntry(pStrokes
[numStrokes
- 1], &point
, pPath
->pFlags
[i
]);
1945 /* should never happen because of the FlattenPath call */
1946 ERR("Should never happen\n");
1949 ERR("Got path flag %c\n", pPath
->pFlags
[i
]);
1954 pNewPath
= HeapAlloc(GetProcessHeap(), 0, sizeof(GdiPath
));
1955 PATH_InitGdiPath(pNewPath
);
1956 pNewPath
->state
= PATH_Open
;
1958 for(i
= 0; i
< numStrokes
; i
++) {
1959 pUpPath
= HeapAlloc(GetProcessHeap(), 0, sizeof(GdiPath
));
1960 PATH_InitGdiPath(pUpPath
);
1961 pUpPath
->state
= PATH_Open
;
1962 pDownPath
= HeapAlloc(GetProcessHeap(), 0, sizeof(GdiPath
));
1963 PATH_InitGdiPath(pDownPath
);
1964 pDownPath
->state
= PATH_Open
;
1966 for(j
= 0; j
< pStrokes
[i
]->numEntriesUsed
; j
++) {
1967 /* Beginning or end of the path if not closed */
1968 if((!(pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) && (j
== 0 || j
== pStrokes
[i
]->numEntriesUsed
- 1) ) {
1969 /* Compute segment angle */
1970 double xo
, yo
, xa
, ya
, theta
;
1972 FLOAT_POINT corners
[2];
1974 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1975 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1976 xa
= pStrokes
[i
]->pPoints
[1].x
;
1977 ya
= pStrokes
[i
]->pPoints
[1].y
;
1980 xa
= pStrokes
[i
]->pPoints
[j
- 1].x
;
1981 ya
= pStrokes
[i
]->pPoints
[j
- 1].y
;
1982 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1983 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1985 theta
= atan2( ya
- yo
, xa
- xo
);
1987 case PS_ENDCAP_SQUARE
:
1988 pt
.x
= xo
+ round(sqrt(2) * penWidthOut
* cos(M_PI_4
+ theta
));
1989 pt
.y
= yo
+ round(sqrt(2) * penWidthOut
* sin(M_PI_4
+ theta
));
1990 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
) );
1991 pt
.x
= xo
+ round(sqrt(2) * penWidthIn
* cos(- M_PI_4
+ theta
));
1992 pt
.y
= yo
+ round(sqrt(2) * penWidthIn
* sin(- M_PI_4
+ theta
));
1993 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1995 case PS_ENDCAP_FLAT
:
1996 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1997 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1998 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1999 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
2000 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
2001 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
2003 case PS_ENDCAP_ROUND
:
2005 corners
[0].x
= xo
- penWidthIn
;
2006 corners
[0].y
= yo
- penWidthIn
;
2007 corners
[1].x
= xo
+ penWidthOut
;
2008 corners
[1].y
= yo
+ penWidthOut
;
2009 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI_2
, theta
+ 3 * M_PI_4
, (j
== 0 ? PT_MOVETO
: FALSE
));
2010 PATH_DoArcPart(pUpPath
,corners
, theta
+ 3 * M_PI_4
, theta
+ M_PI
, FALSE
);
2011 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI
, theta
+ 5 * M_PI_4
, FALSE
);
2012 PATH_DoArcPart(pUpPath
,corners
, theta
+ 5 * M_PI_4
, theta
+ 3 * M_PI_2
, FALSE
);
2016 /* Corpse of the path */
2020 double xa
, ya
, xb
, yb
, xo
, yo
;
2021 double alpha
, theta
, miterWidth
;
2022 DWORD _joint
= joint
;
2024 GdiPath
*pInsidePath
, *pOutsidePath
;
2025 if(j
> 0 && j
< pStrokes
[i
]->numEntriesUsed
- 1) {
2030 previous
= pStrokes
[i
]->numEntriesUsed
- 1;
2037 xo
= pStrokes
[i
]->pPoints
[j
].x
;
2038 yo
= pStrokes
[i
]->pPoints
[j
].y
;
2039 xa
= pStrokes
[i
]->pPoints
[previous
].x
;
2040 ya
= pStrokes
[i
]->pPoints
[previous
].y
;
2041 xb
= pStrokes
[i
]->pPoints
[next
].x
;
2042 yb
= pStrokes
[i
]->pPoints
[next
].y
;
2043 theta
= atan2( yo
- ya
, xo
- xa
);
2044 alpha
= atan2( yb
- yo
, xb
- xo
) - theta
;
2045 if (alpha
> 0) alpha
-= M_PI
;
2047 if(_joint
== PS_JOIN_MITER
&& dc
->miterLimit
< fabs(1 / sin(alpha
/2))) {
2048 _joint
= PS_JOIN_BEVEL
;
2051 pInsidePath
= pUpPath
;
2052 pOutsidePath
= pDownPath
;
2054 else if(alpha
< 0) {
2055 pInsidePath
= pDownPath
;
2056 pOutsidePath
= pUpPath
;
2061 /* Inside angle points */
2063 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
2064 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
2067 pt
.x
= xo
+ round( penWidthIn
* cos(theta
+ M_PI_2
) );
2068 pt
.y
= yo
+ round( penWidthIn
* sin(theta
+ M_PI_2
) );
2070 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
2072 pt
.x
= xo
+ round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
2073 pt
.y
= yo
+ round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
2076 pt
.x
= xo
- round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
2077 pt
.y
= yo
- round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
2079 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
2080 /* Outside angle point */
2082 case PS_JOIN_MITER
:
2083 miterWidth
= fabs(penWidthOut
/ cos(M_PI_2
- fabs(alpha
) / 2));
2084 pt
.x
= xo
+ round( miterWidth
* cos(theta
+ alpha
/ 2) );
2085 pt
.y
= yo
+ round( miterWidth
* sin(theta
+ alpha
/ 2) );
2086 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
2088 case PS_JOIN_BEVEL
:
2090 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
2091 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
2094 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
2095 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
2097 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
2099 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
2100 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
2103 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
2104 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
2106 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
2108 case PS_JOIN_ROUND
:
2111 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
2112 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
2115 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
2116 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
2118 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
2119 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ alpha
/ 2) );
2120 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ alpha
/ 2) );
2121 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
2123 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
2124 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
2127 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
2128 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
2130 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
2135 for(j
= 0; j
< pUpPath
->numEntriesUsed
; j
++) {
2137 pt
.x
= pUpPath
->pPoints
[j
].x
;
2138 pt
.y
= pUpPath
->pPoints
[j
].y
;
2139 PATH_AddEntry(pNewPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
2141 for(j
= 0; j
< pDownPath
->numEntriesUsed
; j
++) {
2143 pt
.x
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].x
;
2144 pt
.y
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].y
;
2145 PATH_AddEntry(pNewPath
, &pt
, ( (j
== 0 && (pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) ? PT_MOVETO
: PT_LINETO
));
2148 PATH_DestroyGdiPath(pStrokes
[i
]);
2149 HeapFree(GetProcessHeap(), 0, pStrokes
[i
]);
2150 PATH_DestroyGdiPath(pUpPath
);
2151 HeapFree(GetProcessHeap(), 0, pUpPath
);
2152 PATH_DestroyGdiPath(pDownPath
);
2153 HeapFree(GetProcessHeap(), 0, pDownPath
);
2155 HeapFree(GetProcessHeap(), 0, pStrokes
);
2157 pNewPath
->state
= PATH_Closed
;
2158 if (!(ret
= PATH_AssignGdiPath(pPath
, pNewPath
)))
2159 ERR("Assign path failed\n");
2160 PATH_DestroyGdiPath(pNewPath
);
2161 HeapFree(GetProcessHeap(), 0, pNewPath
);
2166 /*******************************************************************
2167 * StrokeAndFillPath [GDI32.@]
2171 BOOL WINAPI
StrokeAndFillPath(HDC hdc
)
2173 DC
*dc
= get_dc_ptr( hdc
);
2176 if(!dc
) return FALSE
;
2178 if(dc
->funcs
->pStrokeAndFillPath
)
2179 bRet
= dc
->funcs
->pStrokeAndFillPath(dc
->physDev
);
2182 bRet
= PATH_FillPath(dc
, &dc
->path
);
2183 if(bRet
) bRet
= PATH_StrokePath(dc
, &dc
->path
);
2184 if(bRet
) PATH_EmptyPath(&dc
->path
);
2186 release_dc_ptr( dc
);
2191 /*******************************************************************
2192 * StrokePath [GDI32.@]
2196 BOOL WINAPI
StrokePath(HDC hdc
)
2198 DC
*dc
= get_dc_ptr( hdc
);
2202 TRACE("(%p)\n", hdc
);
2203 if(!dc
) return FALSE
;
2205 if(dc
->funcs
->pStrokePath
)
2206 bRet
= dc
->funcs
->pStrokePath(dc
->physDev
);
2210 bRet
= PATH_StrokePath(dc
, pPath
);
2211 PATH_EmptyPath(pPath
);
2213 release_dc_ptr( dc
);
2218 /*******************************************************************
2219 * WidenPath [GDI32.@]
2223 BOOL WINAPI
WidenPath(HDC hdc
)
2225 DC
*dc
= get_dc_ptr( hdc
);
2228 if(!dc
) return FALSE
;
2230 if(dc
->funcs
->pWidenPath
)
2231 ret
= dc
->funcs
->pWidenPath(dc
->physDev
);
2233 ret
= PATH_WidenPath(dc
);
2234 release_dc_ptr( dc
);