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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/port.h"
31 #if defined(HAVE_FLOAT_H)
41 #include "gdi_private.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
46 /* Notes on the implementation
48 * The implementation is based on dynamically resizable arrays of points and
49 * flags. I dithered for a bit before deciding on this implementation, and
50 * I had even done a bit of work on a linked list version before switching
51 * to arrays. It's a bit of a tradeoff. When you use linked lists, the
52 * implementation of FlattenPath is easier, because you can rip the
53 * PT_BEZIERTO entries out of the middle of the list and link the
54 * corresponding PT_LINETO entries in. However, when you use arrays,
55 * PathToRegion becomes easier, since you can essentially just pass your array
56 * of points to CreatePolyPolygonRgn. Also, if I'd used linked lists, I would
57 * have had the extra effort of creating a chunk-based allocation scheme
58 * in order to use memory effectively. That's why I finally decided to use
59 * arrays. Note by the way that the array based implementation has the same
60 * linear time complexity that linked lists would have since the arrays grow
63 * The points are stored in the path in device coordinates. This is
64 * consistent with the way Windows does things (for instance, see the Win32
65 * SDK documentation for GetPath).
67 * The word "stroke" appears in several places (e.g. in the flag
68 * GdiPath.newStroke). A stroke consists of a PT_MOVETO followed by one or
69 * more PT_LINETOs or PT_BEZIERTOs, up to, but not including, the next
70 * PT_MOVETO. Note that this is not the same as the definition of a figure;
71 * a figure can contain several strokes.
73 * I modified the drawing functions (MoveTo, LineTo etc.) to test whether
74 * the path is open and to call the corresponding function in path.c if this
75 * is the case. A more elegant approach would be to modify the function
76 * pointers in the DC_FUNCTIONS structure; however, this would be a lot more
77 * complex. Also, the performance degradation caused by my approach in the
78 * case where no path is open is so small that it cannot be measured.
83 /* FIXME: A lot of stuff isn't implemented yet. There is much more to come. */
85 #define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
86 #define GROW_FACTOR_NUMER 2 /* Numerator of grow factor for the array */
87 #define GROW_FACTOR_DENOM 1 /* Denominator of grow factor */
89 /* A floating point version of the POINT structure */
90 typedef struct tagFLOAT_POINT
96 static BOOL
PATH_PathToRegion(GdiPath
*pPath
, INT nPolyFillMode
,
98 static void PATH_EmptyPath(GdiPath
*pPath
);
99 static BOOL
PATH_ReserveEntries(GdiPath
*pPath
, INT numEntries
);
100 static BOOL
PATH_DoArcPart(GdiPath
*pPath
, FLOAT_POINT corners
[],
101 double angleStart
, double angleEnd
, BOOL addMoveTo
);
102 static void PATH_ScaleNormalizedPoint(FLOAT_POINT corners
[], double x
,
103 double y
, POINT
*pPoint
);
104 static void PATH_NormalizePoint(FLOAT_POINT corners
[], const FLOAT_POINT
105 *pPoint
, double *pX
, double *pY
);
106 static BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
);
108 /* Performs a world-to-viewport transformation on the specified point (which
109 * is in floating point format).
111 static inline void INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
115 /* Perform the transformation */
118 point
->x
= x
* dc
->xformWorld2Vport
.eM11
+
119 y
* dc
->xformWorld2Vport
.eM21
+
120 dc
->xformWorld2Vport
.eDx
;
121 point
->y
= x
* dc
->xformWorld2Vport
.eM12
+
122 y
* dc
->xformWorld2Vport
.eM22
+
123 dc
->xformWorld2Vport
.eDy
;
126 /* Performs a world-to-viewport transformation on the specified width.
128 static inline void INTERNAL_WSTODS(DC
*dc
, DWORD
*width
)
131 pt
[0].x
= pt
[0].y
= 0;
134 LPtoDP(dc
->hSelf
, pt
, 2);
135 *width
= pt
[1].x
- pt
[0].x
;
138 /***********************************************************************
139 * BeginPath (GDI32.@)
141 BOOL WINAPI
BeginPath(HDC hdc
)
144 DC
*dc
= DC_GetDCPtr( hdc
);
146 if(!dc
) return FALSE
;
148 if(dc
->funcs
->pBeginPath
)
149 ret
= dc
->funcs
->pBeginPath(dc
->physDev
);
152 /* If path is already open, do nothing */
153 if(dc
->path
.state
!= PATH_Open
)
155 /* Make sure that path is empty */
156 PATH_EmptyPath(&dc
->path
);
158 /* Initialize variables for new path */
159 dc
->path
.newStroke
=TRUE
;
160 dc
->path
.state
=PATH_Open
;
163 GDI_ReleaseObj( hdc
);
168 /***********************************************************************
171 BOOL WINAPI
EndPath(HDC hdc
)
174 DC
*dc
= DC_GetDCPtr( hdc
);
176 if(!dc
) return FALSE
;
178 if(dc
->funcs
->pEndPath
)
179 ret
= dc
->funcs
->pEndPath(dc
->physDev
);
182 /* Check that path is currently being constructed */
183 if(dc
->path
.state
!=PATH_Open
)
185 SetLastError(ERROR_CAN_NOT_COMPLETE
);
188 /* Set flag to indicate that path is finished */
189 else dc
->path
.state
=PATH_Closed
;
191 GDI_ReleaseObj( hdc
);
196 /******************************************************************************
197 * AbortPath [GDI32.@]
198 * Closes and discards paths from device context
201 * Check that SetLastError is being called correctly
204 * hdc [I] Handle to device context
210 BOOL WINAPI
AbortPath( HDC hdc
)
213 DC
*dc
= DC_GetDCPtr( hdc
);
215 if(!dc
) return FALSE
;
217 if(dc
->funcs
->pAbortPath
)
218 ret
= dc
->funcs
->pAbortPath(dc
->physDev
);
219 else /* Remove all entries from the path */
220 PATH_EmptyPath( &dc
->path
);
221 GDI_ReleaseObj( hdc
);
226 /***********************************************************************
227 * CloseFigure (GDI32.@)
229 * FIXME: Check that SetLastError is being called correctly
231 BOOL WINAPI
CloseFigure(HDC hdc
)
234 DC
*dc
= DC_GetDCPtr( hdc
);
236 if(!dc
) return FALSE
;
238 if(dc
->funcs
->pCloseFigure
)
239 ret
= dc
->funcs
->pCloseFigure(dc
->physDev
);
242 /* Check that path is open */
243 if(dc
->path
.state
!=PATH_Open
)
245 SetLastError(ERROR_CAN_NOT_COMPLETE
);
250 /* FIXME: Shouldn't we draw a line to the beginning of the
252 /* Set PT_CLOSEFIGURE on the last entry and start a new stroke */
253 if(dc
->path
.numEntriesUsed
)
255 dc
->path
.pFlags
[dc
->path
.numEntriesUsed
-1]|=PT_CLOSEFIGURE
;
256 dc
->path
.newStroke
=TRUE
;
260 GDI_ReleaseObj( hdc
);
265 /***********************************************************************
268 INT WINAPI
GetPath(HDC hdc
, LPPOINT pPoints
, LPBYTE pTypes
,
273 DC
*dc
= DC_GetDCPtr( hdc
);
279 /* Check that path is closed */
280 if(pPath
->state
!=PATH_Closed
)
282 SetLastError(ERROR_CAN_NOT_COMPLETE
);
287 ret
= pPath
->numEntriesUsed
;
288 else if(nSize
<pPath
->numEntriesUsed
)
290 SetLastError(ERROR_INVALID_PARAMETER
);
295 memcpy(pPoints
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
296 memcpy(pTypes
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
298 /* Convert the points to logical coordinates */
299 if(!DPtoLP(hdc
, pPoints
, pPath
->numEntriesUsed
))
301 /* FIXME: Is this the correct value? */
302 SetLastError(ERROR_CAN_NOT_COMPLETE
);
305 else ret
= pPath
->numEntriesUsed
;
308 GDI_ReleaseObj( hdc
);
313 /***********************************************************************
314 * PathToRegion (GDI32.@)
317 * Check that SetLastError is being called correctly
319 * The documentation does not state this explicitly, but a test under Windows
320 * shows that the region which is returned should be in device coordinates.
322 HRGN WINAPI
PathToRegion(HDC hdc
)
326 DC
*dc
= DC_GetDCPtr( hdc
);
328 /* Get pointer to path */
333 /* Check that path is closed */
334 if(pPath
->state
!=PATH_Closed
) SetLastError(ERROR_CAN_NOT_COMPLETE
);
337 /* FIXME: Should we empty the path even if conversion failed? */
338 if(PATH_PathToRegion(pPath
, GetPolyFillMode(hdc
), &hrgnRval
))
339 PATH_EmptyPath(pPath
);
343 GDI_ReleaseObj( hdc
);
347 static BOOL
PATH_FillPath(DC
*dc
, GdiPath
*pPath
)
349 INT mapMode
, graphicsMode
;
350 SIZE ptViewportExt
, ptWindowExt
;
351 POINT ptViewportOrg
, ptWindowOrg
;
355 if(dc
->funcs
->pFillPath
)
356 return dc
->funcs
->pFillPath(dc
->physDev
);
358 /* Check that path is closed */
359 if(pPath
->state
!=PATH_Closed
)
361 SetLastError(ERROR_CAN_NOT_COMPLETE
);
365 /* Construct a region from the path and fill it */
366 if(PATH_PathToRegion(pPath
, dc
->polyFillMode
, &hrgn
))
368 /* Since PaintRgn interprets the region as being in logical coordinates
369 * but the points we store for the path are already in device
370 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
371 * Using SaveDC to save information about the mapping mode / world
372 * transform would be easier but would require more overhead, especially
373 * now that SaveDC saves the current path.
376 /* Save the information about the old mapping mode */
377 mapMode
=GetMapMode(dc
->hSelf
);
378 GetViewportExtEx(dc
->hSelf
, &ptViewportExt
);
379 GetViewportOrgEx(dc
->hSelf
, &ptViewportOrg
);
380 GetWindowExtEx(dc
->hSelf
, &ptWindowExt
);
381 GetWindowOrgEx(dc
->hSelf
, &ptWindowOrg
);
383 /* Save world transform
384 * NB: The Windows documentation on world transforms would lead one to
385 * believe that this has to be done only in GM_ADVANCED; however, my
386 * tests show that resetting the graphics mode to GM_COMPATIBLE does
387 * not reset the world transform.
389 GetWorldTransform(dc
->hSelf
, &xform
);
392 SetMapMode(dc
->hSelf
, MM_TEXT
);
393 SetViewportOrgEx(dc
->hSelf
, 0, 0, NULL
);
394 SetWindowOrgEx(dc
->hSelf
, 0, 0, NULL
);
395 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
396 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
397 ModifyWorldTransform(dc
->hSelf
, &xform
, MWT_IDENTITY
);
398 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
400 /* Paint the region */
401 PaintRgn(dc
->hSelf
, hrgn
);
403 /* Restore the old mapping mode */
404 SetMapMode(dc
->hSelf
, mapMode
);
405 SetViewportExtEx(dc
->hSelf
, ptViewportExt
.cx
, ptViewportExt
.cy
, NULL
);
406 SetViewportOrgEx(dc
->hSelf
, ptViewportOrg
.x
, ptViewportOrg
.y
, NULL
);
407 SetWindowExtEx(dc
->hSelf
, ptWindowExt
.cx
, ptWindowExt
.cy
, NULL
);
408 SetWindowOrgEx(dc
->hSelf
, ptWindowOrg
.x
, ptWindowOrg
.y
, NULL
);
410 /* Go to GM_ADVANCED temporarily to restore the world transform */
411 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
412 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
413 SetWorldTransform(dc
->hSelf
, &xform
);
414 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
421 /***********************************************************************
425 * Check that SetLastError is being called correctly
427 BOOL WINAPI
FillPath(HDC hdc
)
429 DC
*dc
= DC_GetDCPtr( hdc
);
432 if(!dc
) return FALSE
;
434 if(dc
->funcs
->pFillPath
)
435 bRet
= dc
->funcs
->pFillPath(dc
->physDev
);
438 bRet
= PATH_FillPath(dc
, &dc
->path
);
441 /* FIXME: Should the path be emptied even if conversion
443 PATH_EmptyPath(&dc
->path
);
446 GDI_ReleaseObj( hdc
);
451 /***********************************************************************
452 * SelectClipPath (GDI32.@)
454 * Check that SetLastError is being called correctly
456 BOOL WINAPI
SelectClipPath(HDC hdc
, INT iMode
)
460 BOOL success
= FALSE
;
461 DC
*dc
= DC_GetDCPtr( hdc
);
463 if(!dc
) return FALSE
;
465 if(dc
->funcs
->pSelectClipPath
)
466 success
= dc
->funcs
->pSelectClipPath(dc
->physDev
, iMode
);
471 /* Check that path is closed */
472 if(pPath
->state
!=PATH_Closed
)
473 SetLastError(ERROR_CAN_NOT_COMPLETE
);
474 /* Construct a region from the path */
475 else if(PATH_PathToRegion(pPath
, GetPolyFillMode(hdc
), &hrgnPath
))
477 success
= ExtSelectClipRgn( hdc
, hrgnPath
, iMode
) != ERROR
;
478 DeleteObject(hrgnPath
);
482 PATH_EmptyPath(pPath
);
483 /* FIXME: Should this function delete the path even if it failed? */
486 GDI_ReleaseObj( hdc
);
491 /***********************************************************************
497 * Initializes the GdiPath structure.
499 void PATH_InitGdiPath(GdiPath
*pPath
)
503 pPath
->state
=PATH_Null
;
506 pPath
->numEntriesUsed
=0;
507 pPath
->numEntriesAllocated
=0;
510 /* PATH_DestroyGdiPath
512 * Destroys a GdiPath structure (frees the memory in the arrays).
514 void PATH_DestroyGdiPath(GdiPath
*pPath
)
518 HeapFree( GetProcessHeap(), 0, pPath
->pPoints
);
519 HeapFree( GetProcessHeap(), 0, pPath
->pFlags
);
522 /* PATH_AssignGdiPath
524 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
525 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
526 * not just the pointers. Since this means that the arrays in pPathDest may
527 * need to be resized, pPathDest should have been initialized using
528 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
529 * not a copy constructor).
530 * Returns TRUE if successful, else FALSE.
532 BOOL
PATH_AssignGdiPath(GdiPath
*pPathDest
, const GdiPath
*pPathSrc
)
534 assert(pPathDest
!=NULL
&& pPathSrc
!=NULL
);
536 /* Make sure destination arrays are big enough */
537 if(!PATH_ReserveEntries(pPathDest
, pPathSrc
->numEntriesUsed
))
540 /* Perform the copy operation */
541 memcpy(pPathDest
->pPoints
, pPathSrc
->pPoints
,
542 sizeof(POINT
)*pPathSrc
->numEntriesUsed
);
543 memcpy(pPathDest
->pFlags
, pPathSrc
->pFlags
,
544 sizeof(BYTE
)*pPathSrc
->numEntriesUsed
);
546 pPathDest
->state
=pPathSrc
->state
;
547 pPathDest
->numEntriesUsed
=pPathSrc
->numEntriesUsed
;
548 pPathDest
->newStroke
=pPathSrc
->newStroke
;
555 * Should be called when a MoveTo is performed on a DC that has an
556 * open path. This starts a new stroke. Returns TRUE if successful, else
559 BOOL
PATH_MoveTo(DC
*dc
)
561 GdiPath
*pPath
= &dc
->path
;
563 /* Check that path is open */
564 if(pPath
->state
!=PATH_Open
)
565 /* FIXME: Do we have to call SetLastError? */
568 /* Start a new stroke */
569 pPath
->newStroke
=TRUE
;
576 * Should be called when a LineTo is performed on a DC that has an
577 * open path. This adds a PT_LINETO entry to the path (and possibly
578 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
579 * Returns TRUE if successful, else FALSE.
581 BOOL
PATH_LineTo(DC
*dc
, INT x
, INT y
)
583 GdiPath
*pPath
= &dc
->path
;
584 POINT point
, pointCurPos
;
586 /* Check that path is open */
587 if(pPath
->state
!=PATH_Open
)
590 /* Convert point to device coordinates */
593 if(!LPtoDP(dc
->hSelf
, &point
, 1))
596 /* Add a PT_MOVETO if necessary */
599 pPath
->newStroke
=FALSE
;
600 pointCurPos
.x
= dc
->CursPosX
;
601 pointCurPos
.y
= dc
->CursPosY
;
602 if(!LPtoDP(dc
->hSelf
, &pointCurPos
, 1))
604 if(!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
608 /* Add a PT_LINETO entry */
609 return PATH_AddEntry(pPath
, &point
, PT_LINETO
);
614 * Should be called when a call to RoundRect is performed on a DC that has
615 * an open path. Returns TRUE if successful, else FALSE.
617 * FIXME: it adds the same entries to the path as windows does, but there
618 * is an error in the bezier drawing code so that there are small pixel-size
619 * gaps when the resulting path is drawn by StrokePath()
621 BOOL
PATH_RoundRect(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
, INT ell_width
, INT ell_height
)
623 GdiPath
*pPath
= &dc
->path
;
624 POINT corners
[2], pointTemp
;
625 FLOAT_POINT ellCorners
[2];
627 /* Check that path is open */
628 if(pPath
->state
!=PATH_Open
)
631 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
634 /* Add points to the roundrect path */
635 ellCorners
[0].x
= corners
[1].x
-ell_width
;
636 ellCorners
[0].y
= corners
[0].y
;
637 ellCorners
[1].x
= corners
[1].x
;
638 ellCorners
[1].y
= corners
[0].y
+ell_height
;
639 if(!PATH_DoArcPart(pPath
, ellCorners
, 0, -M_PI_2
, TRUE
))
641 pointTemp
.x
= corners
[0].x
+ell_width
/2;
642 pointTemp
.y
= corners
[0].y
;
643 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
645 ellCorners
[0].x
= corners
[0].x
;
646 ellCorners
[1].x
= corners
[0].x
+ell_width
;
647 if(!PATH_DoArcPart(pPath
, ellCorners
, -M_PI_2
, -M_PI
, FALSE
))
649 pointTemp
.x
= corners
[0].x
;
650 pointTemp
.y
= corners
[1].y
-ell_height
/2;
651 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
653 ellCorners
[0].y
= corners
[1].y
-ell_height
;
654 ellCorners
[1].y
= corners
[1].y
;
655 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI
, M_PI_2
, FALSE
))
657 pointTemp
.x
= corners
[1].x
-ell_width
/2;
658 pointTemp
.y
= corners
[1].y
;
659 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
661 ellCorners
[0].x
= corners
[1].x
-ell_width
;
662 ellCorners
[1].x
= corners
[1].x
;
663 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI_2
, 0, FALSE
))
666 /* Close the roundrect figure */
667 if(!CloseFigure(dc
->hSelf
))
675 * Should be called when a call to Rectangle is performed on a DC that has
676 * an open path. Returns TRUE if successful, else FALSE.
678 BOOL
PATH_Rectangle(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
)
680 GdiPath
*pPath
= &dc
->path
;
681 POINT corners
[2], pointTemp
;
683 /* Check that path is open */
684 if(pPath
->state
!=PATH_Open
)
687 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
690 /* Close any previous figure */
691 if(!CloseFigure(dc
->hSelf
))
693 /* The CloseFigure call shouldn't have failed */
698 /* Add four points to the path */
699 pointTemp
.x
=corners
[1].x
;
700 pointTemp
.y
=corners
[0].y
;
701 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_MOVETO
))
703 if(!PATH_AddEntry(pPath
, corners
, PT_LINETO
))
705 pointTemp
.x
=corners
[0].x
;
706 pointTemp
.y
=corners
[1].y
;
707 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
709 if(!PATH_AddEntry(pPath
, corners
+1, PT_LINETO
))
712 /* Close the rectangle figure */
713 if(!CloseFigure(dc
->hSelf
))
715 /* The CloseFigure call shouldn't have failed */
725 * Should be called when a call to Ellipse is performed on a DC that has
726 * an open path. This adds four Bezier splines representing the ellipse
727 * to the path. Returns TRUE if successful, else FALSE.
729 BOOL
PATH_Ellipse(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
)
731 return( PATH_Arc(dc
, x1
, y1
, x2
, y2
, x1
, (y1
+y2
)/2, x1
, (y1
+y2
)/2,0) &&
732 CloseFigure(dc
->hSelf
) );
737 * Should be called when a call to Arc is performed on a DC that has
738 * an open path. This adds up to five Bezier splines representing the arc
739 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
740 * and when 'lines' is 2, we add 2 extra lines to get a pie.
741 * Returns TRUE if successful, else FALSE.
743 BOOL
PATH_Arc(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
,
744 INT xStart
, INT yStart
, INT xEnd
, INT yEnd
, INT lines
)
746 GdiPath
*pPath
= &dc
->path
;
747 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
=0.0;
748 /* Initialize angleEndQuadrant to silence gcc's warning */
750 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
755 /* FIXME: This function should check for all possible error returns */
756 /* FIXME: Do we have to respect newStroke? */
758 /* Check that path is open */
759 if(pPath
->state
!=PATH_Open
)
762 /* Check for zero height / width */
763 /* FIXME: Only in GM_COMPATIBLE? */
767 /* Convert points to device coordinates */
768 corners
[0].x
=(FLOAT
)x1
;
769 corners
[0].y
=(FLOAT
)y1
;
770 corners
[1].x
=(FLOAT
)x2
;
771 corners
[1].y
=(FLOAT
)y2
;
772 pointStart
.x
=(FLOAT
)xStart
;
773 pointStart
.y
=(FLOAT
)yStart
;
774 pointEnd
.x
=(FLOAT
)xEnd
;
775 pointEnd
.y
=(FLOAT
)yEnd
;
776 INTERNAL_LPTODP_FLOAT(dc
, corners
);
777 INTERNAL_LPTODP_FLOAT(dc
, corners
+1);
778 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
);
779 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
);
781 /* Make sure first corner is top left and second corner is bottom right */
782 if(corners
[0].x
>corners
[1].x
)
785 corners
[0].x
=corners
[1].x
;
788 if(corners
[0].y
>corners
[1].y
)
791 corners
[0].y
=corners
[1].y
;
795 /* Compute start and end angle */
796 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
797 angleStart
=atan2(y
, x
);
798 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
799 angleEnd
=atan2(y
, x
);
801 /* Make sure the end angle is "on the right side" of the start angle */
802 if(dc
->ArcDirection
==AD_CLOCKWISE
)
804 if(angleEnd
<=angleStart
)
807 assert(angleEnd
>=angleStart
);
812 if(angleEnd
>=angleStart
)
815 assert(angleEnd
<=angleStart
);
819 /* In GM_COMPATIBLE, don't include bottom and right edges */
820 if(dc
->GraphicsMode
==GM_COMPATIBLE
)
826 /* Add the arc to the path with one Bezier spline per quadrant that the
832 /* Determine the start and end angles for this quadrant */
835 angleStartQuadrant
=angleStart
;
836 if(dc
->ArcDirection
==AD_CLOCKWISE
)
837 angleEndQuadrant
=(floor(angleStart
/M_PI_2
)+1.0)*M_PI_2
;
839 angleEndQuadrant
=(ceil(angleStart
/M_PI_2
)-1.0)*M_PI_2
;
843 angleStartQuadrant
=angleEndQuadrant
;
844 if(dc
->ArcDirection
==AD_CLOCKWISE
)
845 angleEndQuadrant
+=M_PI_2
;
847 angleEndQuadrant
-=M_PI_2
;
850 /* Have we reached the last part of the arc? */
851 if((dc
->ArcDirection
==AD_CLOCKWISE
&&
852 angleEnd
<angleEndQuadrant
) ||
853 (dc
->ArcDirection
==AD_COUNTERCLOCKWISE
&&
854 angleEnd
>angleEndQuadrant
))
856 /* Adjust the end angle for this quadrant */
857 angleEndQuadrant
=angleEnd
;
861 /* Add the Bezier spline to the path */
862 PATH_DoArcPart(pPath
, corners
, angleStartQuadrant
, angleEndQuadrant
,
867 /* chord: close figure. pie: add line and close figure */
870 if(!CloseFigure(dc
->hSelf
))
875 centre
.x
= (corners
[0].x
+corners
[1].x
)/2;
876 centre
.y
= (corners
[0].y
+corners
[1].y
)/2;
877 if(!PATH_AddEntry(pPath
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
884 BOOL
PATH_PolyBezierTo(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
886 GdiPath
*pPath
= &dc
->path
;
890 /* Check that path is open */
891 if(pPath
->state
!=PATH_Open
)
894 /* Add a PT_MOVETO if necessary */
897 pPath
->newStroke
=FALSE
;
900 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
902 if(!PATH_AddEntry(pPath
, &pt
, PT_MOVETO
))
906 for(i
= 0; i
< cbPoints
; i
++) {
908 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
910 PATH_AddEntry(pPath
, &pt
, PT_BEZIERTO
);
915 BOOL
PATH_PolyBezier(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
917 GdiPath
*pPath
= &dc
->path
;
921 /* Check that path is open */
922 if(pPath
->state
!=PATH_Open
)
925 for(i
= 0; i
< cbPoints
; i
++) {
927 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
929 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_BEZIERTO
);
934 BOOL
PATH_Polyline(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
936 GdiPath
*pPath
= &dc
->path
;
940 /* Check that path is open */
941 if(pPath
->state
!=PATH_Open
)
944 for(i
= 0; i
< cbPoints
; i
++) {
946 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
948 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_LINETO
);
953 BOOL
PATH_PolylineTo(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
955 GdiPath
*pPath
= &dc
->path
;
959 /* Check that path is open */
960 if(pPath
->state
!=PATH_Open
)
963 /* Add a PT_MOVETO if necessary */
966 pPath
->newStroke
=FALSE
;
969 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
971 if(!PATH_AddEntry(pPath
, &pt
, PT_MOVETO
))
975 for(i
= 0; i
< cbPoints
; i
++) {
977 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
979 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
986 BOOL
PATH_Polygon(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
988 GdiPath
*pPath
= &dc
->path
;
992 /* Check that path is open */
993 if(pPath
->state
!=PATH_Open
)
996 for(i
= 0; i
< cbPoints
; i
++) {
998 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1000 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
:
1001 ((i
== cbPoints
-1) ? PT_LINETO
| PT_CLOSEFIGURE
:
1007 BOOL
PATH_PolyPolygon( DC
*dc
, const POINT
* pts
, const INT
* counts
,
1010 GdiPath
*pPath
= &dc
->path
;
1015 /* Check that path is open */
1016 if(pPath
->state
!=PATH_Open
)
1019 for(i
= 0, poly
= 0; poly
< polygons
; poly
++) {
1020 for(point
= 0; point
< counts
[poly
]; point
++, i
++) {
1022 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1024 if(point
== 0) startpt
= pt
;
1025 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1027 /* win98 adds an extra line to close the figure for some reason */
1028 PATH_AddEntry(pPath
, &startpt
, PT_LINETO
| PT_CLOSEFIGURE
);
1033 BOOL
PATH_PolyPolyline( DC
*dc
, const POINT
* pts
, const DWORD
* counts
,
1036 GdiPath
*pPath
= &dc
->path
;
1038 UINT poly
, point
, i
;
1040 /* Check that path is open */
1041 if(pPath
->state
!=PATH_Open
)
1044 for(i
= 0, poly
= 0; poly
< polylines
; poly
++) {
1045 for(point
= 0; point
< counts
[poly
]; point
++, i
++) {
1047 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1049 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1055 /***********************************************************************
1056 * Internal functions
1059 /* PATH_CheckCorners
1061 * Helper function for PATH_RoundRect() and PATH_Rectangle()
1063 static BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
)
1067 /* Convert points to device coordinates */
1072 if(!LPtoDP(dc
->hSelf
, corners
, 2))
1075 /* Make sure first corner is top left and second corner is bottom right */
1076 if(corners
[0].x
>corners
[1].x
)
1079 corners
[0].x
=corners
[1].x
;
1082 if(corners
[0].y
>corners
[1].y
)
1085 corners
[0].y
=corners
[1].y
;
1089 /* In GM_COMPATIBLE, don't include bottom and right edges */
1090 if(dc
->GraphicsMode
==GM_COMPATIBLE
)
1099 /* PATH_AddFlatBezier
1101 static BOOL
PATH_AddFlatBezier(GdiPath
*pPath
, POINT
*pt
, BOOL closed
)
1106 pts
= GDI_Bezier( pt
, 4, &no
);
1107 if(!pts
) return FALSE
;
1109 for(i
= 1; i
< no
; i
++)
1110 PATH_AddEntry(pPath
, &pts
[i
],
1111 (i
== no
-1 && closed
) ? PT_LINETO
| PT_CLOSEFIGURE
: PT_LINETO
);
1112 HeapFree( GetProcessHeap(), 0, pts
);
1118 * Replaces Beziers with line segments
1121 static BOOL
PATH_FlattenPath(GdiPath
*pPath
)
1126 memset(&newPath
, 0, sizeof(newPath
));
1127 newPath
.state
= PATH_Open
;
1128 for(srcpt
= 0; srcpt
< pPath
->numEntriesUsed
; srcpt
++) {
1129 switch(pPath
->pFlags
[srcpt
] & ~PT_CLOSEFIGURE
) {
1132 PATH_AddEntry(&newPath
, &pPath
->pPoints
[srcpt
],
1133 pPath
->pFlags
[srcpt
]);
1136 PATH_AddFlatBezier(&newPath
, &pPath
->pPoints
[srcpt
-1],
1137 pPath
->pFlags
[srcpt
+2] & PT_CLOSEFIGURE
);
1142 newPath
.state
= PATH_Closed
;
1143 PATH_AssignGdiPath(pPath
, &newPath
);
1144 PATH_DestroyGdiPath(&newPath
);
1148 /* PATH_PathToRegion
1150 * Creates a region from the specified path using the specified polygon
1151 * filling mode. The path is left unchanged. A handle to the region that
1152 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1153 * error occurs, SetLastError is called with the appropriate value and
1154 * FALSE is returned.
1156 static BOOL
PATH_PathToRegion(GdiPath
*pPath
, INT nPolyFillMode
,
1159 int numStrokes
, iStroke
, i
;
1160 INT
*pNumPointsInStroke
;
1163 assert(pPath
!=NULL
);
1164 assert(pHrgn
!=NULL
);
1166 PATH_FlattenPath(pPath
);
1168 /* FIXME: What happens when number of points is zero? */
1170 /* First pass: Find out how many strokes there are in the path */
1171 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1173 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1174 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1177 /* Allocate memory for number-of-points-in-stroke array */
1178 pNumPointsInStroke
=HeapAlloc( GetProcessHeap(), 0, sizeof(int) * numStrokes
);
1179 if(!pNumPointsInStroke
)
1181 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1185 /* Second pass: remember number of points in each polygon */
1186 iStroke
=-1; /* Will get incremented to 0 at beginning of first stroke */
1187 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1189 /* Is this the beginning of a new stroke? */
1190 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1193 pNumPointsInStroke
[iStroke
]=0;
1196 pNumPointsInStroke
[iStroke
]++;
1199 /* Create a region from the strokes */
1200 hrgn
=CreatePolyPolygonRgn(pPath
->pPoints
, pNumPointsInStroke
,
1201 numStrokes
, nPolyFillMode
);
1203 /* Free memory for number-of-points-in-stroke array */
1204 HeapFree( GetProcessHeap(), 0, pNumPointsInStroke
);
1208 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1217 static inline INT
int_from_fixed(FIXED f
)
1219 return (f
.fract
>= 0x8000) ? (f
.value
+ 1) : f
.value
;
1222 /**********************************************************************
1225 * internally used by PATH_add_outline
1227 static void PATH_BezierTo(GdiPath
*pPath
, POINT
*lppt
, INT n
)
1233 PATH_AddEntry(pPath
, &lppt
[1], PT_LINETO
);
1237 PATH_AddEntry(pPath
, &lppt
[0], PT_BEZIERTO
);
1238 PATH_AddEntry(pPath
, &lppt
[1], PT_BEZIERTO
);
1239 PATH_AddEntry(pPath
, &lppt
[2], PT_BEZIERTO
);
1253 pt
[2].x
= (lppt
[i
+2].x
+ lppt
[i
+1].x
) / 2;
1254 pt
[2].y
= (lppt
[i
+2].y
+ lppt
[i
+1].y
) / 2;
1255 PATH_BezierTo(pPath
, pt
, 3);
1263 PATH_BezierTo(pPath
, pt
, 3);
1267 static BOOL
PATH_add_outline(DC
*dc
, INT x
, INT y
, TTPOLYGONHEADER
*header
, DWORD size
)
1269 GdiPath
*pPath
= &dc
->path
;
1270 TTPOLYGONHEADER
*start
;
1275 while ((char *)header
< (char *)start
+ size
)
1279 if (header
->dwType
!= TT_POLYGON_TYPE
)
1281 FIXME("Unknown header type %ld\n", header
->dwType
);
1285 pt
.x
= x
+ int_from_fixed(header
->pfxStart
.x
);
1286 pt
.y
= y
- int_from_fixed(header
->pfxStart
.y
);
1287 LPtoDP(dc
->hSelf
, &pt
, 1);
1288 PATH_AddEntry(pPath
, &pt
, PT_MOVETO
);
1290 curve
= (TTPOLYCURVE
*)(header
+ 1);
1292 while ((char *)curve
< (char *)header
+ header
->cb
)
1294 /*TRACE("curve->wType %d\n", curve->wType);*/
1296 switch(curve
->wType
)
1302 for (i
= 0; i
< curve
->cpfx
; i
++)
1304 pt
.x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1305 pt
.y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1306 LPtoDP(dc
->hSelf
, &pt
, 1);
1307 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
1312 case TT_PRIM_QSPLINE
:
1313 case TT_PRIM_CSPLINE
:
1317 POINT
*pts
= HeapAlloc(GetProcessHeap(), 0, (curve
->cpfx
+ 1) * sizeof(POINT
));
1319 if (!pts
) return FALSE
;
1321 ptfx
= *(POINTFX
*)((char *)curve
- sizeof(POINTFX
));
1323 pts
[0].x
= x
+ int_from_fixed(ptfx
.x
);
1324 pts
[0].y
= y
- int_from_fixed(ptfx
.y
);
1325 LPtoDP(dc
->hSelf
, &pts
[0], 1);
1327 for(i
= 0; i
< curve
->cpfx
; i
++)
1329 pts
[i
+ 1].x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1330 pts
[i
+ 1].y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1331 LPtoDP(dc
->hSelf
, &pts
[i
+ 1], 1);
1334 PATH_BezierTo(pPath
, pts
, curve
->cpfx
+ 1);
1336 HeapFree(GetProcessHeap(), 0, pts
);
1341 FIXME("Unknown curve type %04x\n", curve
->wType
);
1345 curve
= (TTPOLYCURVE
*)&curve
->apfx
[curve
->cpfx
];
1348 header
= (TTPOLYGONHEADER
*)((char *)header
+ header
->cb
);
1351 return CloseFigure(dc
->hSelf
);
1354 /**********************************************************************
1357 BOOL
PATH_ExtTextOut(DC
*dc
, INT x
, INT y
, UINT flags
, const RECT
*lprc
,
1358 LPCWSTR str
, UINT count
, const INT
*dx
)
1361 double cosEsc
, sinEsc
;
1364 HDC hdc
= dc
->hSelf
;
1366 TRACE("%p, %d, %d, %08x, %s, %s, %d, %p)\n", hdc
, x
, y
, flags
,
1367 wine_dbgstr_rect(lprc
), debugstr_wn(str
, count
), count
, dx
);
1369 if (!count
) return TRUE
;
1371 GetObjectW(GetCurrentObject(hdc
, OBJ_FONT
), sizeof(lf
), &lf
);
1373 if (lf
.lfEscapement
!= 0)
1375 cosEsc
= cos(lf
.lfEscapement
* M_PI
/ 1800);
1376 sinEsc
= sin(lf
.lfEscapement
* M_PI
/ 1800);
1383 GetDCOrgEx(hdc
, &org
);
1385 for (idx
= 0; idx
< count
; idx
++)
1387 INT offset
= 0, xoff
= 0, yoff
= 0;
1392 dwSize
= GetGlyphOutlineW(hdc
, str
[idx
], GGO_GLYPH_INDEX
| GGO_NATIVE
, &gm
, 0, NULL
, NULL
);
1393 if (!dwSize
) return FALSE
;
1395 outline
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
1396 if (!outline
) return FALSE
;
1398 GetGlyphOutlineW(hdc
, str
[idx
], GGO_GLYPH_INDEX
| GGO_NATIVE
, &gm
, dwSize
, outline
, NULL
);
1400 PATH_add_outline(dc
, org
.x
+ x
+ xoff
, org
.x
+ y
+ yoff
, outline
, dwSize
);
1402 HeapFree(GetProcessHeap(), 0, outline
);
1407 xoff
= offset
* cosEsc
;
1408 yoff
= offset
* -sinEsc
;
1412 xoff
+= gm
.gmCellIncX
;
1413 yoff
+= gm
.gmCellIncY
;
1421 * Removes all entries from the path and sets the path state to PATH_Null.
1423 static void PATH_EmptyPath(GdiPath
*pPath
)
1425 assert(pPath
!=NULL
);
1427 pPath
->state
=PATH_Null
;
1428 pPath
->numEntriesUsed
=0;
1433 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1434 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1435 * successful, FALSE otherwise (e.g. if not enough memory was available).
1437 BOOL
PATH_AddEntry(GdiPath
*pPath
, const POINT
*pPoint
, BYTE flags
)
1439 assert(pPath
!=NULL
);
1441 /* FIXME: If newStroke is true, perhaps we want to check that we're
1442 * getting a PT_MOVETO
1444 TRACE("(%ld,%ld) - %d\n", pPoint
->x
, pPoint
->y
, flags
);
1446 /* Check that path is open */
1447 if(pPath
->state
!=PATH_Open
)
1450 /* Reserve enough memory for an extra path entry */
1451 if(!PATH_ReserveEntries(pPath
, pPath
->numEntriesUsed
+1))
1454 /* Store information in path entry */
1455 pPath
->pPoints
[pPath
->numEntriesUsed
]=*pPoint
;
1456 pPath
->pFlags
[pPath
->numEntriesUsed
]=flags
;
1458 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1459 if((flags
& PT_CLOSEFIGURE
) == PT_CLOSEFIGURE
)
1460 pPath
->newStroke
=TRUE
;
1462 /* Increment entry count */
1463 pPath
->numEntriesUsed
++;
1468 /* PATH_ReserveEntries
1470 * Ensures that at least "numEntries" entries (for points and flags) have
1471 * been allocated; allocates larger arrays and copies the existing entries
1472 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1474 static BOOL
PATH_ReserveEntries(GdiPath
*pPath
, INT numEntries
)
1476 INT numEntriesToAllocate
;
1480 assert(pPath
!=NULL
);
1481 assert(numEntries
>=0);
1483 /* Do we have to allocate more memory? */
1484 if(numEntries
> pPath
->numEntriesAllocated
)
1486 /* Find number of entries to allocate. We let the size of the array
1487 * grow exponentially, since that will guarantee linear time
1489 if(pPath
->numEntriesAllocated
)
1491 numEntriesToAllocate
=pPath
->numEntriesAllocated
;
1492 while(numEntriesToAllocate
<numEntries
)
1493 numEntriesToAllocate
=numEntriesToAllocate
*GROW_FACTOR_NUMER
/
1497 numEntriesToAllocate
=numEntries
;
1499 /* Allocate new arrays */
1500 pPointsNew
=HeapAlloc( GetProcessHeap(), 0, numEntriesToAllocate
* sizeof(POINT
) );
1503 pFlagsNew
=HeapAlloc( GetProcessHeap(), 0, numEntriesToAllocate
* sizeof(BYTE
) );
1506 HeapFree( GetProcessHeap(), 0, pPointsNew
);
1510 /* Copy old arrays to new arrays and discard old arrays */
1513 assert(pPath
->pFlags
);
1515 memcpy(pPointsNew
, pPath
->pPoints
,
1516 sizeof(POINT
)*pPath
->numEntriesUsed
);
1517 memcpy(pFlagsNew
, pPath
->pFlags
,
1518 sizeof(BYTE
)*pPath
->numEntriesUsed
);
1520 HeapFree( GetProcessHeap(), 0, pPath
->pPoints
);
1521 HeapFree( GetProcessHeap(), 0, pPath
->pFlags
);
1523 pPath
->pPoints
=pPointsNew
;
1524 pPath
->pFlags
=pFlagsNew
;
1525 pPath
->numEntriesAllocated
=numEntriesToAllocate
;
1533 * Creates a Bezier spline that corresponds to part of an arc and appends the
1534 * corresponding points to the path. The start and end angles are passed in
1535 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1536 * at most. If "addMoveTo" is true, a PT_MOVETO entry for the first control
1537 * point is added to the path; otherwise, it is assumed that the current
1538 * position is equal to the first control point.
1540 static BOOL
PATH_DoArcPart(GdiPath
*pPath
, FLOAT_POINT corners
[],
1541 double angleStart
, double angleEnd
, BOOL addMoveTo
)
1543 double halfAngle
, a
;
1544 double xNorm
[4], yNorm
[4];
1548 assert(fabs(angleEnd
-angleStart
)<=M_PI_2
);
1550 /* FIXME: Is there an easier way of computing this? */
1552 /* Compute control points */
1553 halfAngle
=(angleEnd
-angleStart
)/2.0;
1554 if(fabs(halfAngle
)>1e-8)
1556 a
=4.0/3.0*(1-cos(halfAngle
))/sin(halfAngle
);
1557 xNorm
[0]=cos(angleStart
);
1558 yNorm
[0]=sin(angleStart
);
1559 xNorm
[1]=xNorm
[0] - a
*yNorm
[0];
1560 yNorm
[1]=yNorm
[0] + a
*xNorm
[0];
1561 xNorm
[3]=cos(angleEnd
);
1562 yNorm
[3]=sin(angleEnd
);
1563 xNorm
[2]=xNorm
[3] + a
*yNorm
[3];
1564 yNorm
[2]=yNorm
[3] - a
*xNorm
[3];
1569 xNorm
[i
]=cos(angleStart
);
1570 yNorm
[i
]=sin(angleStart
);
1573 /* Add starting point to path if desired */
1576 PATH_ScaleNormalizedPoint(corners
, xNorm
[0], yNorm
[0], &point
);
1577 if(!PATH_AddEntry(pPath
, &point
, PT_MOVETO
))
1581 /* Add remaining control points */
1584 PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &point
);
1585 if(!PATH_AddEntry(pPath
, &point
, PT_BEZIERTO
))
1592 /* PATH_ScaleNormalizedPoint
1594 * Scales a normalized point (x, y) with respect to the box whose corners are
1595 * passed in "corners". The point is stored in "*pPoint". The normalized
1596 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1597 * (1.0, 1.0) correspond to corners[1].
1599 static void PATH_ScaleNormalizedPoint(FLOAT_POINT corners
[], double x
,
1600 double y
, POINT
*pPoint
)
1602 pPoint
->x
=GDI_ROUND( (double)corners
[0].x
+
1603 (double)(corners
[1].x
-corners
[0].x
)*0.5*(x
+1.0) );
1604 pPoint
->y
=GDI_ROUND( (double)corners
[0].y
+
1605 (double)(corners
[1].y
-corners
[0].y
)*0.5*(y
+1.0) );
1608 /* PATH_NormalizePoint
1610 * Normalizes a point with respect to the box whose corners are passed in
1611 * "corners". The normalized coordinates are stored in "*pX" and "*pY".
1613 static void PATH_NormalizePoint(FLOAT_POINT corners
[],
1614 const FLOAT_POINT
*pPoint
,
1615 double *pX
, double *pY
)
1617 *pX
=(double)(pPoint
->x
-corners
[0].x
)/(double)(corners
[1].x
-corners
[0].x
) *
1619 *pY
=(double)(pPoint
->y
-corners
[0].y
)/(double)(corners
[1].y
-corners
[0].y
) *
1624 /*******************************************************************
1625 * FlattenPath [GDI32.@]
1629 BOOL WINAPI
FlattenPath(HDC hdc
)
1632 DC
*dc
= DC_GetDCPtr( hdc
);
1634 if(!dc
) return FALSE
;
1636 if(dc
->funcs
->pFlattenPath
) ret
= dc
->funcs
->pFlattenPath(dc
->physDev
);
1639 GdiPath
*pPath
= &dc
->path
;
1640 if(pPath
->state
!= PATH_Closed
)
1641 ret
= PATH_FlattenPath(pPath
);
1643 GDI_ReleaseObj( hdc
);
1648 static BOOL
PATH_StrokePath(DC
*dc
, GdiPath
*pPath
)
1650 INT i
, nLinePts
, nAlloc
;
1652 POINT ptViewportOrg
, ptWindowOrg
;
1653 SIZE szViewportExt
, szWindowExt
;
1654 DWORD mapMode
, graphicsMode
;
1660 if(dc
->funcs
->pStrokePath
)
1661 return dc
->funcs
->pStrokePath(dc
->physDev
);
1663 if(pPath
->state
!= PATH_Closed
)
1666 /* Convert pen properties from logical to device units for MWT_IDENTITY */
1667 hOldPen
= GetCurrentObject(dc
->hSelf
, OBJ_PEN
);
1668 if(GetObjectType(hOldPen
) == OBJ_EXTPEN
) {
1671 GetObjectW(hOldPen
, sizeof(EXTLOGPEN
), &elp
);
1672 if(elp
.elpPenStyle
& PS_GEOMETRIC
) {
1673 INTERNAL_WSTODS(dc
, &elp
.elpWidth
);
1674 if(elp
.elpPenStyle
& PS_USERSTYLE
)
1675 for(i
= 0; i
< elp
.elpNumEntries
; i
++)
1676 INTERNAL_WSTODS(dc
, &elp
.elpStyleEntry
[i
]);
1678 lb
.lbStyle
= elp
.elpBrushStyle
;
1679 lb
.lbColor
= elp
.elpColor
;
1680 lb
.lbHatch
= elp
.elpHatch
;
1681 hNewPen
= ExtCreatePen(elp
.elpPenStyle
, elp
.elpWidth
, &lb
,
1682 elp
.elpNumEntries
, elp
.elpStyleEntry
);
1683 } else /* OBJ_PEN */ {
1685 GetObjectW(hOldPen
, sizeof(LOGPEN
), &lp
);
1686 if(lp
.lopnWidth
.x
> 0)
1687 INTERNAL_WSTODS(dc
, (DWORD
*)&lp
.lopnWidth
.x
);
1688 hNewPen
= CreatePenIndirect(&lp
);
1690 SelectObject(dc
->hSelf
, hNewPen
);
1692 /* Save the mapping mode info */
1693 mapMode
=GetMapMode(dc
->hSelf
);
1694 GetViewportExtEx(dc
->hSelf
, &szViewportExt
);
1695 GetViewportOrgEx(dc
->hSelf
, &ptViewportOrg
);
1696 GetWindowExtEx(dc
->hSelf
, &szWindowExt
);
1697 GetWindowOrgEx(dc
->hSelf
, &ptWindowOrg
);
1698 GetWorldTransform(dc
->hSelf
, &xform
);
1701 SetMapMode(dc
->hSelf
, MM_TEXT
);
1702 SetViewportOrgEx(dc
->hSelf
, 0, 0, NULL
);
1703 SetWindowOrgEx(dc
->hSelf
, 0, 0, NULL
);
1704 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
1705 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
1706 ModifyWorldTransform(dc
->hSelf
, &xform
, MWT_IDENTITY
);
1707 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
1709 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1710 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1711 * space in case we get one to keep the number of reallocations small. */
1712 nAlloc
= pPath
->numEntriesUsed
+ 1 + 300;
1713 pLinePts
= HeapAlloc(GetProcessHeap(), 0, nAlloc
* sizeof(POINT
));
1716 for(i
= 0; i
< pPath
->numEntriesUsed
; i
++) {
1717 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
)) &&
1718 (pPath
->pFlags
[i
] != PT_MOVETO
)) {
1719 ERR("Expected PT_MOVETO %s, got path flag %d\n",
1720 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1721 (INT
)pPath
->pFlags
[i
]);
1725 switch(pPath
->pFlags
[i
]) {
1727 TRACE("Got PT_MOVETO (%ld, %ld)\n",
1728 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1730 Polyline(dc
->hSelf
, pLinePts
, nLinePts
);
1732 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1735 case (PT_LINETO
| PT_CLOSEFIGURE
):
1736 TRACE("Got PT_LINETO (%ld, %ld)\n",
1737 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1738 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1741 TRACE("Got PT_BEZIERTO\n");
1742 if(pPath
->pFlags
[i
+1] != PT_BEZIERTO
||
1743 (pPath
->pFlags
[i
+2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
) {
1744 ERR("Path didn't contain 3 successive PT_BEZIERTOs\n");
1748 INT nBzrPts
, nMinAlloc
;
1749 POINT
*pBzrPts
= GDI_Bezier(&pPath
->pPoints
[i
-1], 4, &nBzrPts
);
1750 /* Make sure we have allocated enough memory for the lines of
1751 * this bezier and the rest of the path, assuming we won't get
1752 * another one (since we won't reallocate again then). */
1753 nMinAlloc
= nLinePts
+ (pPath
->numEntriesUsed
- i
) + nBzrPts
;
1754 if(nAlloc
< nMinAlloc
)
1756 nAlloc
= nMinAlloc
* 2;
1757 pLinePts
= HeapReAlloc(GetProcessHeap(), 0, pLinePts
,
1758 nAlloc
* sizeof(POINT
));
1760 memcpy(&pLinePts
[nLinePts
], &pBzrPts
[1],
1761 (nBzrPts
- 1) * sizeof(POINT
));
1762 nLinePts
+= nBzrPts
- 1;
1763 HeapFree(GetProcessHeap(), 0, pBzrPts
);
1768 ERR("Got path flag %d\n", (INT
)pPath
->pFlags
[i
]);
1772 if(pPath
->pFlags
[i
] & PT_CLOSEFIGURE
)
1773 pLinePts
[nLinePts
++] = pLinePts
[0];
1776 Polyline(dc
->hSelf
, pLinePts
, nLinePts
);
1779 HeapFree(GetProcessHeap(), 0, pLinePts
);
1781 /* Restore the old mapping mode */
1782 SetMapMode(dc
->hSelf
, mapMode
);
1783 SetViewportExtEx(dc
->hSelf
, szViewportExt
.cx
, szViewportExt
.cy
, NULL
);
1784 SetViewportOrgEx(dc
->hSelf
, ptViewportOrg
.x
, ptViewportOrg
.y
, NULL
);
1785 SetWindowExtEx(dc
->hSelf
, szWindowExt
.cx
, szWindowExt
.cy
, NULL
);
1786 SetWindowOrgEx(dc
->hSelf
, ptWindowOrg
.x
, ptWindowOrg
.y
, NULL
);
1788 /* Go to GM_ADVANCED temporarily to restore the world transform */
1789 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
1790 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
1791 SetWorldTransform(dc
->hSelf
, &xform
);
1792 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
1794 /* If we've moved the current point then get its new position
1795 which will be in device (MM_TEXT) co-ords, convert it to
1796 logical co-ords and re-set it. This basically updates
1797 dc->CurPosX|Y so that their values are in the correct mapping
1802 GetCurrentPositionEx(dc
->hSelf
, &pt
);
1803 DPtoLP(dc
->hSelf
, &pt
, 1);
1804 MoveToEx(dc
->hSelf
, pt
.x
, pt
.y
, NULL
);
1807 /* Restore old pen */
1808 DeleteObject(hNewPen
);
1809 SelectObject(dc
->hSelf
, hOldPen
);
1815 /*******************************************************************
1816 * StrokeAndFillPath [GDI32.@]
1820 BOOL WINAPI
StrokeAndFillPath(HDC hdc
)
1822 DC
*dc
= DC_GetDCPtr( hdc
);
1825 if(!dc
) return FALSE
;
1827 if(dc
->funcs
->pStrokeAndFillPath
)
1828 bRet
= dc
->funcs
->pStrokeAndFillPath(dc
->physDev
);
1831 bRet
= PATH_FillPath(dc
, &dc
->path
);
1832 if(bRet
) bRet
= PATH_StrokePath(dc
, &dc
->path
);
1833 if(bRet
) PATH_EmptyPath(&dc
->path
);
1835 GDI_ReleaseObj( hdc
);
1840 /*******************************************************************
1841 * StrokePath [GDI32.@]
1845 BOOL WINAPI
StrokePath(HDC hdc
)
1847 DC
*dc
= DC_GetDCPtr( hdc
);
1851 TRACE("(%p)\n", hdc
);
1852 if(!dc
) return FALSE
;
1854 if(dc
->funcs
->pStrokePath
)
1855 bRet
= dc
->funcs
->pStrokePath(dc
->physDev
);
1859 bRet
= PATH_StrokePath(dc
, pPath
);
1860 PATH_EmptyPath(pPath
);
1862 GDI_ReleaseObj( hdc
);
1867 /*******************************************************************
1868 * WidenPath [GDI32.@]
1872 BOOL WINAPI
WidenPath(HDC hdc
)
1874 DC
*dc
= DC_GetDCPtr( hdc
);
1877 if(!dc
) return FALSE
;
1879 if(dc
->funcs
->pWidenPath
)
1880 ret
= dc
->funcs
->pWidenPath(dc
->physDev
);
1883 GDI_ReleaseObj( hdc
);