2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
27 #define GROW_FACTOR_NUMER 2 /* Numerator of grow factor for the array */
28 #define GROW_FACTOR_DENOM 1 /* Denominator of grow factor */
30 BOOL FASTCALL
PATH_AddEntry (PPATH pPath
, const POINT
*pPoint
, BYTE flags
);
31 BOOL FASTCALL
PATH_AddFlatBezier (PPATH pPath
, POINT
*pt
, BOOL closed
);
32 BOOL FASTCALL
PATH_DoArcPart (PPATH pPath
, FLOAT_POINT corners
[], double angleStart
, double angleEnd
, BYTE startEntryType
);
33 BOOL FASTCALL
PATH_FillPath( PDC dc
, PPATH pPath
);
34 BOOL FASTCALL
PATH_FlattenPath (PPATH pPath
);
35 VOID FASTCALL
PATH_NormalizePoint (FLOAT_POINT corners
[], const FLOAT_POINT
*pPoint
, double *pX
, double *pY
);
37 BOOL FASTCALL
PATH_ReserveEntries (PPATH pPath
, INT numEntries
);
38 VOID FASTCALL
PATH_ScaleNormalizedPoint (FLOAT_POINT corners
[], double x
, double y
, POINT
*pPoint
);
39 BOOL FASTCALL
PATH_StrokePath(DC
*dc
, PPATH pPath
);
40 BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
);
42 VOID FASTCALL
IntGetCurrentPositionEx(PDC dc
, LPPOINT pt
);
44 /***********************************************************************
50 PATH_Delete(HPATH hPath
)
52 if (!hPath
) return FALSE
;
53 PPATH pPath
= PATH_LockPath( hPath
);
54 if (!pPath
) return FALSE
;
55 PATH_DestroyGdiPath( pPath
);
56 PATH_UnlockPath( pPath
);
57 PATH_FreeExtPathByHandle(hPath
);
64 IntGdiCloseFigure(PPATH pPath
)
66 ASSERT(pPath
->state
== PATH_Open
);
68 // FIXME: Shouldn't we draw a line to the beginning of the figure?
69 // Set PT_CLOSEFIGURE on the last entry and start a new stroke
70 if(pPath
->numEntriesUsed
)
72 pPath
->pFlags
[pPath
->numEntriesUsed
-1]|=PT_CLOSEFIGURE
;
73 pPath
->newStroke
=TRUE
;
83 PATH_FillPath( PDC dc
, PPATH pPath
)
85 INT mapMode
, graphicsMode
;
86 SIZE ptViewportExt
, ptWindowExt
;
87 POINTL ptViewportOrg
, ptWindowOrg
;
90 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
92 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
94 if( pPath
->state
!= PATH_Closed
)
96 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
100 if( PATH_PathToRegion( pPath
, Dc_Attr
->jFillMode
, &hrgn
))
102 /* Since PaintRgn interprets the region as being in logical coordinates
103 * but the points we store for the path are already in device
104 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
105 * Using SaveDC to save information about the mapping mode / world
106 * transform would be easier but would require more overhead, especially
107 * now that SaveDC saves the current path.
110 /* Save the information about the old mapping mode */
111 mapMode
= Dc_Attr
->iMapMode
;
112 ptViewportExt
= Dc_Attr
->szlViewportExt
;
113 ptViewportOrg
= Dc_Attr
->ptlViewportOrg
;
114 ptWindowExt
= Dc_Attr
->szlWindowExt
;
115 ptWindowOrg
= Dc_Attr
->ptlWindowOrg
;
117 /* Save world transform
118 * NB: The Windows documentation on world transforms would lead one to
119 * believe that this has to be done only in GM_ADVANCED; however, my
120 * tests show that resetting the graphics mode to GM_COMPATIBLE does
121 * not reset the world transform.
123 MatrixS2XForm(&xform
, &dc
->DcLevel
.mxWorldToPage
);
126 // IntGdiSetMapMode( dc, MM_TEXT );
127 // Dc_Attr->ptlViewportOrg.x = 0;
128 // Dc_Attr->ptlViewportOrg.y = 0;
129 // Dc_Attr->ptlWindowOrg.x = 0;
130 // Dc_Attr->ptlWindowOrg.y = 0;
132 graphicsMode
= Dc_Attr
->iGraphicsMode
;
133 // Dc_Attr->iGraphicsMode = GM_ADVANCED;
134 // IntGdiModifyWorldTransform( dc, &xform, MWT_IDENTITY );
135 // Dc_Attr->iGraphicsMode = graphicsMode;
137 /* Paint the region */
138 IntGdiPaintRgn( dc
, hrgn
);
139 NtGdiDeleteObject( hrgn
);
140 /* Restore the old mapping mode */
141 // IntGdiSetMapMode( dc, mapMode );
142 // Dc_Attr->szlViewportExt = ptViewportExt;
143 // Dc_Attr->ptlViewportOrg = ptViewportOrg;
144 // Dc_Attr->szlWindowExt = ptWindowExt;
145 // Dc_Attr->ptlWindowOrg = ptWindowOrg;
147 /* Go to GM_ADVANCED temporarily to restore the world transform */
148 graphicsMode
= Dc_Attr
->iGraphicsMode
;
149 // Dc_Attr->iGraphicsMode = GM_ADVANCED;
150 // IntGdiModifyWorldTransform( dc, &xform, MWT_MAX+1 );
151 // Dc_Attr->iGraphicsMode = graphicsMode;
159 * Initializes the GdiPath structure.
163 PATH_InitGdiPath ( PPATH pPath
)
167 pPath
->state
=PATH_Null
;
170 pPath
->numEntriesUsed
=0;
171 pPath
->numEntriesAllocated
=0;
174 /* PATH_DestroyGdiPath
176 * Destroys a GdiPath structure (frees the memory in the arrays).
180 PATH_DestroyGdiPath ( PPATH pPath
)
184 if (pPath
->pPoints
) ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
185 if (pPath
->pFlags
) ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
188 /* PATH_AssignGdiPath
190 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
191 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
192 * not just the pointers. Since this means that the arrays in pPathDest may
193 * need to be resized, pPathDest should have been initialized using
194 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
195 * not a copy constructor).
196 * Returns TRUE if successful, else FALSE.
200 PATH_AssignGdiPath ( PPATH pPathDest
, const PPATH pPathSrc
)
202 ASSERT(pPathDest
!=NULL
&& pPathSrc
!=NULL
);
204 /* Make sure destination arrays are big enough */
205 if ( !PATH_ReserveEntries(pPathDest
, pPathSrc
->numEntriesUsed
) )
208 /* Perform the copy operation */
209 memcpy(pPathDest
->pPoints
, pPathSrc
->pPoints
,
210 sizeof(POINT
)*pPathSrc
->numEntriesUsed
);
211 memcpy(pPathDest
->pFlags
, pPathSrc
->pFlags
,
212 sizeof(BYTE
)*pPathSrc
->numEntriesUsed
);
214 pPathDest
->state
=pPathSrc
->state
;
215 pPathDest
->numEntriesUsed
=pPathSrc
->numEntriesUsed
;
216 pPathDest
->newStroke
=pPathSrc
->newStroke
;
222 * Should be called when a MoveTo is performed on a DC that has an
223 * open path. This starts a new stroke. Returns TRUE if successful, else
228 PATH_MoveTo ( PDC dc
)
230 PPATH pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
231 if (!pPath
) return FALSE
;
233 /* Check that path is open */
234 if ( pPath
->state
!= PATH_Open
)
236 PATH_UnlockPath( pPath
);
237 /* FIXME: Do we have to call SetLastError? */
240 /* Start a new stroke */
241 pPath
->newStroke
= TRUE
;
242 PATH_UnlockPath( pPath
);
248 * Should be called when a LineTo is performed on a DC that has an
249 * open path. This adds a PT_LINETO entry to the path (and possibly
250 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
251 * Returns TRUE if successful, else FALSE.
255 PATH_LineTo ( PDC dc
, INT x
, INT y
)
259 POINT point
, pointCurPos
;
261 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
262 if (!pPath
) return FALSE
;
264 /* Check that path is open */
265 if ( pPath
->state
!= PATH_Open
)
267 PATH_UnlockPath( pPath
);
271 /* Convert point to device coordinates */
274 CoordLPtoDP ( dc
, &point
);
276 /* Add a PT_MOVETO if necessary */
277 if ( pPath
->newStroke
)
279 pPath
->newStroke
= FALSE
;
280 IntGetCurrentPositionEx ( dc
, &pointCurPos
);
281 CoordLPtoDP ( dc
, &pointCurPos
);
282 if ( !PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
) )
284 PATH_UnlockPath( pPath
);
289 /* Add a PT_LINETO entry */
290 Ret
= PATH_AddEntry(pPath
, &point
, PT_LINETO
);
291 PATH_UnlockPath( pPath
);
297 * Should be called when a call to Rectangle is performed on a DC that has
298 * an open path. Returns TRUE if successful, else FALSE.
302 PATH_Rectangle ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
)
305 POINT corners
[2], pointTemp
;
308 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
309 if (!pPath
) return FALSE
;
311 /* Check that path is open */
312 if ( pPath
->state
!= PATH_Open
)
314 PATH_UnlockPath( pPath
);
318 /* Convert points to device coordinates */
323 IntLPtoDP ( dc
, corners
, 2 );
325 /* Make sure first corner is top left and second corner is bottom right */
326 if ( corners
[0].x
> corners
[1].x
)
329 corners
[0].x
=corners
[1].x
;
332 if ( corners
[0].y
> corners
[1].y
)
335 corners
[0].y
=corners
[1].y
;
339 /* In GM_COMPATIBLE, don't include bottom and right edges */
340 if ( IntGetGraphicsMode(dc
) == GM_COMPATIBLE
)
346 /* Close any previous figure */
347 IntGdiCloseFigure(pPath
);
349 /* Add four points to the path */
350 pointTemp
.x
=corners
[1].x
;
351 pointTemp
.y
=corners
[0].y
;
352 if ( !PATH_AddEntry(pPath
, &pointTemp
, PT_MOVETO
) )
354 PATH_UnlockPath( pPath
);
357 if ( !PATH_AddEntry(pPath
, corners
, PT_LINETO
) )
359 PATH_UnlockPath( pPath
);
362 pointTemp
.x
=corners
[0].x
;
363 pointTemp
.y
=corners
[1].y
;
364 if ( !PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
) )
366 PATH_UnlockPath( pPath
);
369 if ( !PATH_AddEntry(pPath
, corners
+1, PT_LINETO
) )
371 PATH_UnlockPath( pPath
);
375 /* Close the rectangle figure */
376 IntGdiCloseFigure(pPath
) ;
377 PATH_UnlockPath( pPath
);
383 * Should be called when a call to RoundRect is performed on a DC that has
384 * an open path. Returns TRUE if successful, else FALSE.
386 * FIXME: it adds the same entries to the path as windows does, but there
387 * is an error in the bezier drawing code so that there are small pixel-size
388 * gaps when the resulting path is drawn by StrokePath()
390 BOOL FASTCALL
PATH_RoundRect(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
, INT ell_width
, INT ell_height
)
393 POINT corners
[2], pointTemp
;
394 FLOAT_POINT ellCorners
[2];
396 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
397 if (!pPath
) return FALSE
;
399 /* Check that path is open */
400 if(pPath
->state
!=PATH_Open
)
402 PATH_UnlockPath( pPath
);
406 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
408 PATH_UnlockPath( pPath
);
412 /* Add points to the roundrect path */
413 ellCorners
[0].x
= corners
[1].x
-ell_width
;
414 ellCorners
[0].y
= corners
[0].y
;
415 ellCorners
[1].x
= corners
[1].x
;
416 ellCorners
[1].y
= corners
[0].y
+ell_height
;
417 if(!PATH_DoArcPart(pPath
, ellCorners
, 0, -M_PI_2
, PT_MOVETO
))
419 PATH_UnlockPath( pPath
);
422 pointTemp
.x
= corners
[0].x
+ell_width
/2;
423 pointTemp
.y
= corners
[0].y
;
424 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
426 PATH_UnlockPath( pPath
);
429 ellCorners
[0].x
= corners
[0].x
;
430 ellCorners
[1].x
= corners
[0].x
+ell_width
;
431 if(!PATH_DoArcPart(pPath
, ellCorners
, -M_PI_2
, -M_PI
, FALSE
))
433 PATH_UnlockPath( pPath
);
436 pointTemp
.x
= corners
[0].x
;
437 pointTemp
.y
= corners
[1].y
-ell_height
/2;
438 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
440 PATH_UnlockPath( pPath
);
443 ellCorners
[0].y
= corners
[1].y
-ell_height
;
444 ellCorners
[1].y
= corners
[1].y
;
445 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI
, M_PI_2
, FALSE
))
447 PATH_UnlockPath( pPath
);
450 pointTemp
.x
= corners
[1].x
-ell_width
/2;
451 pointTemp
.y
= corners
[1].y
;
452 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
454 PATH_UnlockPath( pPath
);
457 ellCorners
[0].x
= corners
[1].x
-ell_width
;
458 ellCorners
[1].x
= corners
[1].x
;
459 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI_2
, 0, FALSE
))
461 PATH_UnlockPath( pPath
);
465 IntGdiCloseFigure(pPath
);
466 PATH_UnlockPath( pPath
);
472 * Should be called when a call to Ellipse is performed on a DC that has
473 * an open path. This adds four Bezier splines representing the ellipse
474 * to the path. Returns TRUE if successful, else FALSE.
478 PATH_Ellipse ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
)
481 /* TODO: This should probably be revised to call PATH_AngleArc */
482 /* (once it exists) */
483 BOOL Ret
= PATH_Arc ( dc
, x1
, y1
, x2
, y2
, x1
, (y1
+y2
)/2, x1
, (y1
+y2
)/2, GdiTypeArc
);
486 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
487 if (!pPath
) return FALSE
;
488 IntGdiCloseFigure(pPath
);
489 PATH_UnlockPath( pPath
);
496 * Should be called when a call to Arc is performed on a DC that has
497 * an open path. This adds up to five Bezier splines representing the arc
498 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
499 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
500 * -1 we add 1 extra line from the current DC position to the starting position
501 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
506 PATH_Arc ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
,
507 INT xStart
, INT yStart
, INT xEnd
, INT yEnd
, INT lines
)
509 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
=0.0;
510 /* Initialize angleEndQuadrant to silence gcc's warning */
512 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
513 POINT centre
, pointCurPos
;
514 BOOL start
, end
, Ret
= TRUE
;
519 /* FIXME: This function should check for all possible error returns */
520 /* FIXME: Do we have to respect newStroke? */
524 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
525 if (!pPath
) return FALSE
;
527 clockwise
= ((dc
->DcLevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
529 /* Check that path is open */
530 if ( pPath
->state
!= PATH_Open
)
536 /* Check for zero height / width */
537 /* FIXME: Only in GM_COMPATIBLE? */
538 if ( x1
==x2
|| y1
==y2
)
543 /* Convert points to device coordinates */
544 corners
[0].x
=(FLOAT
)x1
;
545 corners
[0].y
=(FLOAT
)y1
;
546 corners
[1].x
=(FLOAT
)x2
;
547 corners
[1].y
=(FLOAT
)y2
;
548 pointStart
.x
=(FLOAT
)xStart
;
549 pointStart
.y
=(FLOAT
)yStart
;
550 pointEnd
.x
=(FLOAT
)xEnd
;
551 pointEnd
.y
=(FLOAT
)yEnd
;
552 INTERNAL_LPTODP_FLOAT(dc
, corners
);
553 INTERNAL_LPTODP_FLOAT(dc
, corners
+1);
554 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
);
555 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
);
557 /* Make sure first corner is top left and second corner is bottom right */
558 if ( corners
[0].x
> corners
[1].x
)
561 corners
[0].x
=corners
[1].x
;
564 if ( corners
[0].y
> corners
[1].y
)
567 corners
[0].y
=corners
[1].y
;
571 /* Compute start and end angle */
572 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
573 angleStart
=atan2(y
, x
);
574 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
575 angleEnd
=atan2(y
, x
);
577 /* Make sure the end angle is "on the right side" of the start angle */
580 if ( angleEnd
<= angleStart
)
583 ASSERT(angleEnd
>=angleStart
);
588 if(angleEnd
>=angleStart
)
591 ASSERT(angleEnd
<=angleStart
);
595 /* In GM_COMPATIBLE, don't include bottom and right edges */
596 if ( IntGetGraphicsMode(dc
) == GM_COMPATIBLE
)
602 /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
603 if(lines
==GdiTypeArcTo
&& pPath
->newStroke
) // -1
605 pPath
->newStroke
=FALSE
;
606 IntGetCurrentPositionEx ( dc
, &pointCurPos
);
607 CoordLPtoDP(dc
, &pointCurPos
);
608 if(!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
615 /* Add the arc to the path with one Bezier spline per quadrant that the
621 /* Determine the start and end angles for this quadrant */
624 angleStartQuadrant
=angleStart
;
626 angleEndQuadrant
=(floor(angleStart
/M_PI_2
)+1.0)*M_PI_2
;
628 angleEndQuadrant
=(ceil(angleStart
/M_PI_2
)-1.0)*M_PI_2
;
632 angleStartQuadrant
=angleEndQuadrant
;
634 angleEndQuadrant
+=M_PI_2
;
636 angleEndQuadrant
-=M_PI_2
;
639 /* Have we reached the last part of the arc? */
640 if ( (clockwise
&& angleEnd
<angleEndQuadrant
)
641 || (!clockwise
&& angleEnd
>angleEndQuadrant
)
644 /* Adjust the end angle for this quadrant */
645 angleEndQuadrant
= angleEnd
;
649 /* Add the Bezier spline to the path */
650 PATH_DoArcPart ( pPath
, corners
, angleStartQuadrant
, angleEndQuadrant
,
651 start
? (lines
==GdiTypeArcTo
? PT_LINETO
: PT_MOVETO
) : FALSE
); // -1
655 /* chord: close figure. pie: add line and close figure */
656 if (lines
==GdiTypeChord
) // 1
658 IntGdiCloseFigure(pPath
);
660 else if (lines
==GdiTypePie
) // 2
662 centre
.x
= (corners
[0].x
+corners
[1].x
)/2;
663 centre
.y
= (corners
[0].y
+corners
[1].y
)/2;
664 if(!PATH_AddEntry(pPath
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
668 PATH_UnlockPath( pPath
);
674 PATH_PolyBezierTo ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
684 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
685 if (!pPath
) return FALSE
;
687 /* Check that path is open */
688 if ( pPath
->state
!= PATH_Open
)
690 PATH_UnlockPath( pPath
);
694 /* Add a PT_MOVETO if necessary */
695 if ( pPath
->newStroke
)
697 pPath
->newStroke
=FALSE
;
698 IntGetCurrentPositionEx ( dc
, &pt
);
699 CoordLPtoDP ( dc
, &pt
);
700 if ( !PATH_AddEntry(pPath
, &pt
, PT_MOVETO
) )
702 PATH_UnlockPath( pPath
);
707 for(i
= 0; i
< cbPoints
; i
++)
710 CoordLPtoDP ( dc
, &pt
);
711 PATH_AddEntry(pPath
, &pt
, PT_BEZIERTO
);
713 PATH_UnlockPath( pPath
);
719 PATH_PolyBezier ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
729 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
730 if (!pPath
) return FALSE
;
732 /* Check that path is open */
733 if ( pPath
->state
!= PATH_Open
)
735 PATH_UnlockPath( pPath
);
739 for ( i
= 0; i
< cbPoints
; i
++ )
742 CoordLPtoDP ( dc
, &pt
);
743 PATH_AddEntry ( pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_BEZIERTO
);
745 PATH_UnlockPath( pPath
);
751 PATH_Polyline ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
761 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
762 if (!pPath
) return FALSE
;
764 /* Check that path is open */
765 if ( pPath
->state
!= PATH_Open
)
767 PATH_UnlockPath( pPath
);
770 for ( i
= 0; i
< cbPoints
; i
++ )
773 CoordLPtoDP ( dc
, &pt
);
774 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_LINETO
);
776 PATH_UnlockPath( pPath
);
782 PATH_PolylineTo ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
792 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
793 if (!pPath
) return FALSE
;
795 /* Check that path is open */
796 if ( pPath
->state
!= PATH_Open
)
798 PATH_UnlockPath( pPath
);
802 /* Add a PT_MOVETO if necessary */
803 if ( pPath
->newStroke
)
805 pPath
->newStroke
= FALSE
;
806 IntGetCurrentPositionEx ( dc
, &pt
);
807 CoordLPtoDP ( dc
, &pt
);
808 if ( !PATH_AddEntry(pPath
, &pt
, PT_MOVETO
) )
810 PATH_UnlockPath( pPath
);
815 for(i
= 0; i
< cbPoints
; i
++)
818 CoordLPtoDP ( dc
, &pt
);
819 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
821 PATH_UnlockPath( pPath
);
828 PATH_Polygon ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
837 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
838 if (!pPath
) return FALSE
;
840 /* Check that path is open */
841 if ( pPath
->state
!= PATH_Open
)
843 PATH_UnlockPath( pPath
);
847 for(i
= 0; i
< cbPoints
; i
++)
850 CoordLPtoDP ( dc
, &pt
);
851 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
:
852 ((i
== cbPoints
-1) ? PT_LINETO
| PT_CLOSEFIGURE
:
855 PATH_UnlockPath( pPath
);
861 PATH_PolyPolygon ( PDC dc
, const POINT
* pts
, const INT
* counts
, UINT polygons
)
864 ULONG poly
, point
, i
;
872 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
873 if (!pPath
) return FALSE
;
875 /* Check that path is open */
876 if ( pPath
->state
!= PATH_Open
)
878 PATH_UnlockPath( pPath
);
882 for(i
= 0, poly
= 0; poly
< polygons
; poly
++)
884 for(point
= 0; point
< (ULONG
) counts
[poly
]; point
++, i
++)
887 CoordLPtoDP ( dc
, &pt
);
888 if(point
== 0) startpt
= pt
;
889 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
891 /* win98 adds an extra line to close the figure for some reason */
892 PATH_AddEntry(pPath
, &startpt
, PT_LINETO
| PT_CLOSEFIGURE
);
894 PATH_UnlockPath( pPath
);
900 PATH_PolyPolyline ( PDC dc
, const POINT
* pts
, const DWORD
* counts
, DWORD polylines
)
903 ULONG poly
, point
, i
;
909 ASSERT ( polylines
);
911 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
912 if (!pPath
) return FALSE
;
914 /* Check that path is open */
915 if ( pPath
->state
!= PATH_Open
)
917 PATH_UnlockPath( pPath
);
921 for(i
= 0, poly
= 0; poly
< polylines
; poly
++)
923 for(point
= 0; point
< counts
[poly
]; point
++, i
++)
926 CoordLPtoDP ( dc
, &pt
);
927 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
930 PATH_UnlockPath( pPath
);
937 * Helper function for PATH_RoundRect() and PATH_Rectangle()
939 BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
)
942 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
943 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
945 /* Convert points to device coordinates */
950 CoordLPtoDP(dc
, &corners
[0]);
951 CoordLPtoDP(dc
, &corners
[1]);
953 /* Make sure first corner is top left and second corner is bottom right */
954 if(corners
[0].x
>corners
[1].x
)
957 corners
[0].x
=corners
[1].x
;
960 if(corners
[0].y
>corners
[1].y
)
963 corners
[0].y
=corners
[1].y
;
967 /* In GM_COMPATIBLE, don't include bottom and right edges */
968 if(Dc_Attr
->iGraphicsMode
==GM_COMPATIBLE
)
978 /* PATH_AddFlatBezier
983 PATH_AddFlatBezier ( PPATH pPath
, POINT
*pt
, BOOL closed
)
988 pts
= GDI_Bezier( pt
, 4, &no
);
989 if ( !pts
) return FALSE
;
991 for(i
= 1; i
< no
; i
++)
992 PATH_AddEntry(pPath
, &pts
[i
], (i
== no
-1 && closed
) ? PT_LINETO
| PT_CLOSEFIGURE
: PT_LINETO
);
994 ExFreePoolWithTag(pts
, TAG_BEZIER
);
1000 * Replaces Beziers with line segments
1005 PATH_FlattenPath(PPATH pPath
)
1010 RtlZeroMemory(&newPath
, sizeof(newPath
));
1011 newPath
.state
= PATH_Open
;
1012 for(srcpt
= 0; srcpt
< pPath
->numEntriesUsed
; srcpt
++) {
1013 switch(pPath
->pFlags
[srcpt
] & ~PT_CLOSEFIGURE
) {
1016 PATH_AddEntry(&newPath
, &pPath
->pPoints
[srcpt
], pPath
->pFlags
[srcpt
]);
1019 PATH_AddFlatBezier(&newPath
, &pPath
->pPoints
[srcpt
-1], pPath
->pFlags
[srcpt
+2] & PT_CLOSEFIGURE
);
1024 newPath
.state
= PATH_Closed
;
1025 PATH_AssignGdiPath(pPath
, &newPath
);
1026 PATH_EmptyPath(&newPath
);
1031 /* PATH_PathToRegion
1033 * Creates a region from the specified path using the specified polygon
1034 * filling mode. The path is left unchanged. A handle to the region that
1035 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1036 * error occurs, SetLastError is called with the appropriate value and
1037 * FALSE is returned.
1041 PATH_PathToRegion ( PPATH pPath
, INT nPolyFillMode
, HRGN
*pHrgn
)
1043 int numStrokes
, iStroke
, i
;
1044 PULONG pNumPointsInStroke
;
1047 ASSERT(pPath
!=NULL
);
1048 ASSERT(pHrgn
!=NULL
);
1050 PATH_FlattenPath ( pPath
);
1052 /* FIXME: What happens when number of points is zero? */
1054 /* First pass: Find out how many strokes there are in the path */
1055 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1057 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1058 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1061 /* Allocate memory for number-of-points-in-stroke array */
1062 pNumPointsInStroke
= ExAllocatePoolWithTag(PagedPool
, sizeof(ULONG
) * numStrokes
, TAG_PATH
);
1063 if(!pNumPointsInStroke
)
1065 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1069 /* Second pass: remember number of points in each polygon */
1070 iStroke
=-1; /* Will get incremented to 0 at beginning of first stroke */
1071 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1073 /* Is this the beginning of a new stroke? */
1074 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1077 pNumPointsInStroke
[iStroke
]=0;
1080 pNumPointsInStroke
[iStroke
]++;
1083 /* Create a region from the strokes */
1084 hrgn
= IntCreatePolyPolygonRgn( pPath
->pPoints
,
1090 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1094 /* Free memory for number-of-points-in-stroke array */
1095 ExFreePoolWithTag(pNumPointsInStroke
, TAG_PATH
);
1104 * Removes all entries from the path and sets the path state to PATH_Null.
1108 PATH_EmptyPath ( PPATH pPath
)
1110 ASSERT(pPath
!=NULL
);
1112 pPath
->state
=PATH_Null
;
1113 pPath
->numEntriesUsed
=0;
1118 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1119 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1120 * successful, FALSE otherwise (e.g. if not enough memory was available).
1124 PATH_AddEntry ( PPATH pPath
, const POINT
*pPoint
, BYTE flags
)
1126 ASSERT(pPath
!=NULL
);
1128 /* FIXME: If newStroke is true, perhaps we want to check that we're
1129 * getting a PT_MOVETO
1132 /* Check that path is open */
1133 if ( pPath
->state
!= PATH_Open
)
1136 /* Reserve enough memory for an extra path entry */
1137 if ( !PATH_ReserveEntries(pPath
, pPath
->numEntriesUsed
+1) )
1140 /* Store information in path entry */
1141 pPath
->pPoints
[pPath
->numEntriesUsed
]=*pPoint
;
1142 pPath
->pFlags
[pPath
->numEntriesUsed
]=flags
;
1144 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1145 if((flags
& PT_CLOSEFIGURE
) == PT_CLOSEFIGURE
)
1146 pPath
->newStroke
=TRUE
;
1148 /* Increment entry count */
1149 pPath
->numEntriesUsed
++;
1154 /* PATH_ReserveEntries
1156 * Ensures that at least "numEntries" entries (for points and flags) have
1157 * been allocated; allocates larger arrays and copies the existing entries
1158 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1162 PATH_ReserveEntries ( PPATH pPath
, INT numEntries
)
1164 INT numEntriesToAllocate
;
1168 ASSERT(pPath
!=NULL
);
1169 ASSERT(numEntries
>=0);
1171 /* Do we have to allocate more memory? */
1172 if(numEntries
> pPath
->numEntriesAllocated
)
1174 /* Find number of entries to allocate. We let the size of the array
1175 * grow exponentially, since that will guarantee linear time
1177 if(pPath
->numEntriesAllocated
)
1179 numEntriesToAllocate
=pPath
->numEntriesAllocated
;
1180 while(numEntriesToAllocate
<numEntries
)
1181 numEntriesToAllocate
=numEntriesToAllocate
*GROW_FACTOR_NUMER
/GROW_FACTOR_DENOM
;
1183 numEntriesToAllocate
=numEntries
;
1185 /* Allocate new arrays */
1186 pPointsNew
=(POINT
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(POINT
), TAG_PATH
);
1189 pFlagsNew
=(BYTE
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(BYTE
), TAG_PATH
);
1192 ExFreePoolWithTag(pPointsNew
, TAG_PATH
);
1196 /* Copy old arrays to new arrays and discard old arrays */
1199 ASSERT(pPath
->pFlags
);
1201 memcpy(pPointsNew
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
1202 memcpy(pFlagsNew
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
1204 ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
1205 ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
1207 pPath
->pPoints
=pPointsNew
;
1208 pPath
->pFlags
=pFlagsNew
;
1209 pPath
->numEntriesAllocated
=numEntriesToAllocate
;
1217 * Creates a Bezier spline that corresponds to part of an arc and appends the
1218 * corresponding points to the path. The start and end angles are passed in
1219 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1220 * at most. If "startEntryType" is non-zero, an entry of that type for the first
1221 * control point is added to the path; otherwise, it is assumed that the current
1222 * position is equal to the first control point.
1226 PATH_DoArcPart ( PPATH pPath
, FLOAT_POINT corners
[],
1227 double angleStart
, double angleEnd
, BYTE startEntryType
)
1229 double halfAngle
, a
;
1230 double xNorm
[4], yNorm
[4];
1234 ASSERT(fabs(angleEnd
-angleStart
)<=M_PI_2
);
1236 /* FIXME: Is there an easier way of computing this? */
1238 /* Compute control points */
1239 halfAngle
=(angleEnd
-angleStart
)/2.0;
1240 if(fabs(halfAngle
)>1e-8)
1242 a
=4.0/3.0*(1-cos(halfAngle
))/sin(halfAngle
);
1243 xNorm
[0]=cos(angleStart
);
1244 yNorm
[0]=sin(angleStart
);
1245 xNorm
[1]=xNorm
[0] - a
*yNorm
[0];
1246 yNorm
[1]=yNorm
[0] + a
*xNorm
[0];
1247 xNorm
[3]=cos(angleEnd
);
1248 yNorm
[3]=sin(angleEnd
);
1249 xNorm
[2]=xNorm
[3] + a
*yNorm
[3];
1250 yNorm
[2]=yNorm
[3] - a
*xNorm
[3];
1254 xNorm
[i
]=cos(angleStart
);
1255 yNorm
[i
]=sin(angleStart
);
1258 /* Add starting point to path if desired */
1261 PATH_ScaleNormalizedPoint(corners
, xNorm
[0], yNorm
[0], &point
);
1262 if(!PATH_AddEntry(pPath
, &point
, startEntryType
))
1266 /* Add remaining control points */
1269 PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &point
);
1270 if(!PATH_AddEntry(pPath
, &point
, PT_BEZIERTO
))
1277 /* PATH_ScaleNormalizedPoint
1279 * Scales a normalized point (x, y) with respect to the box whose corners are
1280 * passed in "corners". The point is stored in "*pPoint". The normalized
1281 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1282 * (1.0, 1.0) correspond to corners[1].
1286 PATH_ScaleNormalizedPoint ( FLOAT_POINT corners
[], double x
,
1287 double y
, POINT
*pPoint
)
1291 pPoint
->x
=GDI_ROUND( (double)corners
[0].x
+ (double)(corners
[1].x
-corners
[0].x
)*0.5*(x
+1.0) );
1292 pPoint
->y
=GDI_ROUND( (double)corners
[0].y
+ (double)(corners
[1].y
-corners
[0].y
)*0.5*(y
+1.0) );
1295 /* PATH_NormalizePoint
1297 * Normalizes a point with respect to the box whose corners are passed in
1298 * corners. The normalized coordinates are stored in *pX and *pY.
1302 PATH_NormalizePoint ( FLOAT_POINT corners
[],
1303 const FLOAT_POINT
*pPoint
,
1304 double *pX
, double *pY
)
1310 *pX
=(double)(pPoint
->x
-corners
[0].x
)/(double)(corners
[1].x
-corners
[0].x
) * 2.0 - 1.0;
1311 *pY
=(double)(pPoint
->y
-corners
[0].y
)/(double)(corners
[1].y
-corners
[0].y
) * 2.0 - 1.0;
1315 BOOL FASTCALL
PATH_StrokePath(DC
*dc
, PPATH pPath
)
1319 INT nLinePts
, nAlloc
;
1320 POINT
*pLinePts
= NULL
;
1321 POINT ptViewportOrg
, ptWindowOrg
;
1322 SIZE szViewportExt
, szWindowExt
;
1323 DWORD mapMode
, graphicsMode
;
1325 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
1327 DPRINT("Enter %s\n", __FUNCTION__
);
1329 if (pPath
->state
!= PATH_Closed
)
1332 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
1333 /* Save the mapping mode info */
1334 mapMode
= Dc_Attr
->iMapMode
;
1335 IntGetViewportExtEx(dc
, &szViewportExt
);
1336 IntGetViewportOrgEx(dc
, &ptViewportOrg
);
1337 IntGetWindowExtEx(dc
, &szWindowExt
);
1338 IntGetWindowOrgEx(dc
, &ptWindowOrg
);
1340 MatrixS2XForm(&xform
, &dc
->DcLevel
.mxWorldToPage
);
1343 Dc_Attr
->iMapMode
= MM_TEXT
;
1344 Dc_Attr
->ptlViewportOrg
.x
= 0;
1345 Dc_Attr
->ptlViewportOrg
.y
= 0;
1346 Dc_Attr
->ptlWindowOrg
.x
= 0;
1347 Dc_Attr
->ptlWindowOrg
.y
= 0;
1348 graphicsMode
= Dc_Attr
->iGraphicsMode
;
1349 Dc_Attr
->iGraphicsMode
= GM_ADVANCED
;
1350 IntGdiModifyWorldTransform(dc
, &xform
, MWT_IDENTITY
);
1351 Dc_Attr
->iGraphicsMode
= graphicsMode
;
1353 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1354 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1355 * space in case we get one to keep the number of reallocations small. */
1356 nAlloc
= pPath
->numEntriesUsed
+ 1 + 300;
1357 pLinePts
= ExAllocatePoolWithTag(PagedPool
, nAlloc
* sizeof(POINT
), TAG_PATH
);
1360 DPRINT1("Can't allocate pool!\n");
1361 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1366 for(i
= 0; i
< pPath
->numEntriesUsed
; i
++)
1368 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
))
1369 && (pPath
->pFlags
[i
] != PT_MOVETO
))
1371 DPRINT1("Expected PT_MOVETO %s, got path flag %d\n",
1372 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1373 (INT
)pPath
->pFlags
[i
]);
1377 switch(pPath
->pFlags
[i
])
1380 DPRINT("Got PT_MOVETO (%ld, %ld)\n",
1381 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1382 if(nLinePts
>= 2) IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1384 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1387 case (PT_LINETO
| PT_CLOSEFIGURE
):
1388 DPRINT("Got PT_LINETO (%ld, %ld)\n",
1389 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1390 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1393 DPRINT("Got PT_BEZIERTO\n");
1394 if(pPath
->pFlags
[i
+1] != PT_BEZIERTO
||
1395 (pPath
->pFlags
[i
+2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
)
1397 DPRINT1("Path didn't contain 3 successive PT_BEZIERTOs\n");
1403 INT nBzrPts
, nMinAlloc
;
1404 POINT
*pBzrPts
= GDI_Bezier(&pPath
->pPoints
[i
-1], 4, &nBzrPts
);
1405 /* Make sure we have allocated enough memory for the lines of
1406 * this bezier and the rest of the path, assuming we won't get
1407 * another one (since we won't reallocate again then). */
1408 nMinAlloc
= nLinePts
+ (pPath
->numEntriesUsed
- i
) + nBzrPts
;
1409 if(nAlloc
< nMinAlloc
)
1411 // Reallocate memory
1413 POINT
*Realloc
= NULL
;
1414 nAlloc
= nMinAlloc
* 2;
1416 Realloc
= ExAllocatePoolWithTag(PagedPool
,
1417 nAlloc
* sizeof(POINT
),
1422 DPRINT1("Can't allocate pool!\n");
1426 memcpy(Realloc
, pLinePts
, nLinePts
*sizeof(POINT
));
1427 ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1430 memcpy(&pLinePts
[nLinePts
], &pBzrPts
[1], (nBzrPts
- 1) * sizeof(POINT
));
1431 nLinePts
+= nBzrPts
- 1;
1432 ExFreePoolWithTag(pBzrPts
, TAG_BEZIER
);
1437 DPRINT1("Got path flag %d (not supported)\n", (INT
)pPath
->pFlags
[i
]);
1441 if(pPath
->pFlags
[i
] & PT_CLOSEFIGURE
)
1443 pLinePts
[nLinePts
++] = pLinePts
[0];
1447 IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1452 if(pLinePts
) ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1454 /* Restore the old mapping mode */
1455 Dc_Attr
->iMapMode
= mapMode
;
1456 Dc_Attr
->szlWindowExt
.cx
= szWindowExt
.cx
;
1457 Dc_Attr
->szlWindowExt
.cy
= szWindowExt
.cy
;
1458 Dc_Attr
->ptlWindowOrg
.x
= ptWindowOrg
.x
;
1459 Dc_Attr
->ptlWindowOrg
.y
= ptWindowOrg
.y
;
1461 Dc_Attr
->szlViewportExt
.cx
= szViewportExt
.cx
;
1462 Dc_Attr
->szlViewportExt
.cy
= szViewportExt
.cy
;
1463 Dc_Attr
->ptlViewportOrg
.x
= ptViewportOrg
.x
;
1464 Dc_Attr
->ptlViewportOrg
.y
= ptViewportOrg
.y
;
1466 /* Restore the world transform */
1467 XForm2MatrixS(&dc
->DcLevel
.mxWorldToPage
, &xform
);
1469 /* If we've moved the current point then get its new position
1470 which will be in device (MM_TEXT) co-ords, convert it to
1471 logical co-ords and re-set it. This basically updates
1472 dc->CurPosX|Y so that their values are in the correct mapping
1478 IntGetCurrentPositionEx(dc
, &pt
);
1479 IntDPtoLP(dc
, &pt
, 1);
1480 IntGdiMoveToEx(dc
, pt
.x
, pt
.y
, NULL
);
1482 DPRINT("Leave %s, ret=%d\n", __FUNCTION__
, ret
);
1486 #define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1491 PATH_WidenPath(DC
*dc
)
1493 INT i
, j
, numStrokes
, numOldStrokes
, penWidth
, penWidthIn
, penWidthOut
, size
, penStyle
;
1495 PPATH pPath
, pNewPath
, *pStrokes
, *pOldStrokes
, pUpPath
, pDownPath
;
1497 DWORD obj_type
, joint
, endcap
, penType
;
1498 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
1500 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
1501 if (!pPath
) return FALSE
;
1503 if(pPath
->state
== PATH_Open
)
1505 PATH_UnlockPath( pPath
);
1506 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1510 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
1512 PATH_FlattenPath(pPath
);
1514 size
= IntGdiGetObject( Dc_Attr
->hpen
, 0, NULL
);
1517 PATH_UnlockPath( pPath
);
1518 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1522 elp
= ExAllocatePoolWithTag(PagedPool
, size
, TAG_PATH
);
1523 (VOID
) IntGdiGetObject( Dc_Attr
->hpen
, size
, elp
);
1525 obj_type
= GDIOBJ_GetObjectType(Dc_Attr
->hpen
);
1526 if(obj_type
== GDI_OBJECT_TYPE_PEN
)
1528 penStyle
= ((LOGPEN
*)elp
)->lopnStyle
;
1530 else if(obj_type
== GDI_OBJECT_TYPE_EXTPEN
)
1532 penStyle
= elp
->elpPenStyle
;
1536 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1537 ExFreePoolWithTag(elp
, TAG_PATH
);
1538 PATH_UnlockPath( pPath
);
1542 penWidth
= elp
->elpWidth
;
1543 ExFreePoolWithTag(elp
, TAG_PATH
);
1545 endcap
= (PS_ENDCAP_MASK
& penStyle
);
1546 joint
= (PS_JOIN_MASK
& penStyle
);
1547 penType
= (PS_TYPE_MASK
& penStyle
);
1549 /* The function cannot apply to cosmetic pens */
1550 if(obj_type
== GDI_OBJECT_TYPE_EXTPEN
&& penType
== PS_COSMETIC
)
1552 PATH_UnlockPath( pPath
);
1553 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1557 penWidthIn
= penWidth
/ 2;
1558 penWidthOut
= penWidth
/ 2;
1559 if(penWidthIn
+ penWidthOut
< penWidth
)
1565 pStrokes
= ExAllocatePoolWithTag(PagedPool
, sizeof(PPATH
), TAG_PATH
);
1566 pStrokes
[0] = ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1567 PATH_InitGdiPath(pStrokes
[0]);
1568 pStrokes
[0]->pFlags
= ExAllocatePoolWithTag(PagedPool
, pPath
->numEntriesUsed
* sizeof(INT
), TAG_PATH
);
1569 pStrokes
[0]->pPoints
= ExAllocatePoolWithTag(PagedPool
, pPath
->numEntriesUsed
* sizeof(POINT
), TAG_PATH
);
1570 pStrokes
[0]->numEntriesUsed
= 0;
1572 for(i
= 0, j
= 0; i
< pPath
->numEntriesUsed
; i
++, j
++)
1575 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
)) &&
1576 (pPath
->pFlags
[i
] != PT_MOVETO
))
1578 DPRINT1("Expected PT_MOVETO %s, got path flag %c\n",
1579 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1583 switch(pPath
->pFlags
[i
])
1588 pStrokes
[numStrokes
- 1]->state
= PATH_Closed
;
1592 pOldStrokes
= pStrokes
; // Save old pointer.
1593 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1594 RtlCopyMemory(pStrokes
, pOldStrokes
, numOldStrokes
* sizeof(PPATH
));
1595 numOldStrokes
= numStrokes
; // Save orig count.
1596 ExFreePoolWithTag(pOldStrokes
, TAG_PATH
); // Free old pointer.
1597 pStrokes
[numStrokes
- 1] = ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1599 PATH_InitGdiPath(pStrokes
[numStrokes
- 1]);
1600 pStrokes
[numStrokes
- 1]->state
= PATH_Open
;
1602 case (PT_LINETO
| PT_CLOSEFIGURE
):
1603 point
.x
= pPath
->pPoints
[i
].x
;
1604 point
.y
= pPath
->pPoints
[i
].y
;
1605 PATH_AddEntry(pStrokes
[numStrokes
- 1], &point
, pPath
->pFlags
[i
]);
1608 /* should never happen because of the FlattenPath call */
1609 DPRINT1("Should never happen\n");
1612 DPRINT1("Got path flag %c\n", pPath
->pFlags
[i
]);
1617 pNewPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1618 PATH_InitGdiPath(pNewPath
);
1619 pNewPath
->state
= PATH_Open
;
1621 for(i
= 0; i
< numStrokes
; i
++)
1623 pUpPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1624 PATH_InitGdiPath(pUpPath
);
1625 pUpPath
->state
= PATH_Open
;
1626 pDownPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1627 PATH_InitGdiPath(pDownPath
);
1628 pDownPath
->state
= PATH_Open
;
1630 for(j
= 0; j
< pStrokes
[i
]->numEntriesUsed
; j
++)
1632 /* Beginning or end of the path if not closed */
1633 if((!(pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) && (j
== 0 || j
== pStrokes
[i
]->numEntriesUsed
- 1) )
1635 /* Compute segment angle */
1636 double xo
, yo
, xa
, ya
, theta
;
1638 FLOAT_POINT corners
[2];
1641 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1642 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1643 xa
= pStrokes
[i
]->pPoints
[1].x
;
1644 ya
= pStrokes
[i
]->pPoints
[1].y
;
1648 xa
= pStrokes
[i
]->pPoints
[j
- 1].x
;
1649 ya
= pStrokes
[i
]->pPoints
[j
- 1].y
;
1650 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1651 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1653 theta
= atan2( ya
- yo
, xa
- xo
);
1656 case PS_ENDCAP_SQUARE
:
1657 pt
.x
= xo
+ round(sqrt(2) * penWidthOut
* cos(M_PI_4
+ theta
));
1658 pt
.y
= yo
+ round(sqrt(2) * penWidthOut
* sin(M_PI_4
+ theta
));
1659 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
) );
1660 pt
.x
= xo
+ round(sqrt(2) * penWidthIn
* cos(- M_PI_4
+ theta
));
1661 pt
.y
= yo
+ round(sqrt(2) * penWidthIn
* sin(- M_PI_4
+ theta
));
1662 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1664 case PS_ENDCAP_FLAT
:
1665 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1666 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1667 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1668 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1669 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1670 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1672 case PS_ENDCAP_ROUND
:
1674 corners
[0].x
= xo
- penWidthIn
;
1675 corners
[0].y
= yo
- penWidthIn
;
1676 corners
[1].x
= xo
+ penWidthOut
;
1677 corners
[1].y
= yo
+ penWidthOut
;
1678 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI_2
, theta
+ 3 * M_PI_4
, (j
== 0 ? PT_MOVETO
: FALSE
));
1679 PATH_DoArcPart(pUpPath
,corners
, theta
+ 3 * M_PI_4
, theta
+ M_PI
, FALSE
);
1680 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI
, theta
+ 5 * M_PI_4
, FALSE
);
1681 PATH_DoArcPart(pUpPath
,corners
, theta
+ 5 * M_PI_4
, theta
+ 3 * M_PI_2
, FALSE
);
1685 /* Corpse of the path */
1690 double xa
, ya
, xb
, yb
, xo
, yo
;
1691 double alpha
, theta
, miterWidth
;
1692 DWORD _joint
= joint
;
1694 PPATH pInsidePath
, pOutsidePath
;
1695 if(j
> 0 && j
< pStrokes
[i
]->numEntriesUsed
- 1)
1702 previous
= pStrokes
[i
]->numEntriesUsed
- 1;
1710 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1711 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1712 xa
= pStrokes
[i
]->pPoints
[previous
].x
;
1713 ya
= pStrokes
[i
]->pPoints
[previous
].y
;
1714 xb
= pStrokes
[i
]->pPoints
[next
].x
;
1715 yb
= pStrokes
[i
]->pPoints
[next
].y
;
1716 theta
= atan2( yo
- ya
, xo
- xa
);
1717 alpha
= atan2( yb
- yo
, xb
- xo
) - theta
;
1718 if (alpha
> 0) alpha
-= M_PI
;
1720 if(_joint
== PS_JOIN_MITER
&& dc
->DcLevel
.laPath
.eMiterLimit
< fabs(1 / sin(alpha
/2)))
1722 _joint
= PS_JOIN_BEVEL
;
1726 pInsidePath
= pUpPath
;
1727 pOutsidePath
= pDownPath
;
1731 pInsidePath
= pDownPath
;
1732 pOutsidePath
= pUpPath
;
1738 /* Inside angle points */
1741 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1742 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1746 pt
.x
= xo
+ round( penWidthIn
* cos(theta
+ M_PI_2
) );
1747 pt
.y
= yo
+ round( penWidthIn
* sin(theta
+ M_PI_2
) );
1749 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1752 pt
.x
= xo
+ round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1753 pt
.y
= yo
+ round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1757 pt
.x
= xo
- round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1758 pt
.y
= yo
- round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1760 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1761 /* Outside angle point */
1764 case PS_JOIN_MITER
:
1765 miterWidth
= fabs(penWidthOut
/ cos(M_PI_2
- fabs(alpha
) / 2));
1766 pt
.x
= xo
+ round( miterWidth
* cos(theta
+ alpha
/ 2) );
1767 pt
.y
= yo
+ round( miterWidth
* sin(theta
+ alpha
/ 2) );
1768 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1770 case PS_JOIN_BEVEL
:
1773 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1774 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1778 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1779 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1781 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1784 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1785 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1789 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1790 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1792 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1794 case PS_JOIN_ROUND
:
1798 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1799 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1803 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1804 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1806 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1807 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ alpha
/ 2) );
1808 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ alpha
/ 2) );
1809 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1812 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1813 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1817 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1818 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1820 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1825 for(j
= 0; j
< pUpPath
->numEntriesUsed
; j
++)
1828 pt
.x
= pUpPath
->pPoints
[j
].x
;
1829 pt
.y
= pUpPath
->pPoints
[j
].y
;
1830 PATH_AddEntry(pNewPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1832 for(j
= 0; j
< pDownPath
->numEntriesUsed
; j
++)
1835 pt
.x
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].x
;
1836 pt
.y
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].y
;
1837 PATH_AddEntry(pNewPath
, &pt
, ( (j
== 0 && (pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) ? PT_MOVETO
: PT_LINETO
));
1840 PATH_DestroyGdiPath(pStrokes
[i
]);
1841 ExFreePoolWithTag(pStrokes
[i
], TAG_PATH
);
1842 PATH_DestroyGdiPath(pUpPath
);
1843 ExFreePoolWithTag(pUpPath
, TAG_PATH
);
1844 PATH_DestroyGdiPath(pDownPath
);
1845 ExFreePoolWithTag(pDownPath
, TAG_PATH
);
1847 ExFreePoolWithTag(pStrokes
, TAG_PATH
);
1849 pNewPath
->state
= PATH_Closed
;
1850 if (!(ret
= PATH_AssignGdiPath(pPath
, pNewPath
)))
1851 DPRINT1("Assign path failed\n");
1852 PATH_DestroyGdiPath(pNewPath
);
1853 ExFreePoolWithTag(pNewPath
, TAG_PATH
);
1859 /***********************************************************************
1860 * Exported functions
1865 NtGdiAbortPath(HDC hDC
)
1868 PDC dc
= DC_LockDc ( hDC
);
1871 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1875 pPath
= PATH_LockPath(dc
->DcLevel
.hPath
);
1881 PATH_EmptyPath(pPath
);
1883 PATH_UnlockPath(pPath
);
1890 NtGdiBeginPath( HDC hDC
)
1895 dc
= DC_LockDc ( hDC
);
1898 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1902 /* If path is already open, do nothing. Check if not Save DC state */
1903 if ((dc
->DcLevel
.flPath
& DCPATH_ACTIVE
) && !(dc
->DcLevel
.flPath
& DCPATH_SAVE
))
1909 if ( dc
->DcLevel
.hPath
)
1911 DPRINT1("BeginPath 1 0x%x\n", dc
->DcLevel
.hPath
);
1912 if ( !(dc
->DcLevel
.flPath
& DCPATH_SAVE
) )
1913 { // Remove previous handle.
1914 if (!PATH_Delete(dc
->DcLevel
.hPath
))
1921 { // Clear flags and Handle.
1922 dc
->DcLevel
.flPath
&= ~(DCPATH_SAVE
|DCPATH_ACTIVE
);
1923 dc
->DcLevel
.hPath
= NULL
;
1926 pPath
= PATH_AllocPathWithHandle();
1929 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1932 dc
->DcLevel
.flPath
|= DCPATH_ACTIVE
; // Set active ASAP!
1934 dc
->DcLevel
.hPath
= pPath
->BaseObject
.hHmgr
;
1936 DPRINT1("BeginPath 2 h 0x%x p 0x%x\n", dc
->DcLevel
.hPath
, pPath
);
1937 // Path handles are shared. Also due to recursion with in the same thread.
1938 GDIOBJ_UnlockObjByPtr((POBJ
)pPath
); // Unlock
1939 pPath
= PATH_LockPath(dc
->DcLevel
.hPath
); // Share Lock.
1941 /* Make sure that path is empty */
1942 PATH_EmptyPath( pPath
);
1944 /* Initialize variables for new path */
1945 pPath
->newStroke
= TRUE
;
1946 pPath
->state
= PATH_Open
;
1948 PATH_UnlockPath(pPath
);
1955 NtGdiCloseFigure(HDC hDC
)
1957 BOOL Ret
= FALSE
; // default to failure
1961 DPRINT("Enter %s\n", __FUNCTION__
);
1963 pDc
= DC_LockDc(hDC
);
1966 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1969 pPath
= PATH_LockPath( pDc
->DcLevel
.hPath
);
1976 if (pPath
->state
==PATH_Open
)
1978 IntGdiCloseFigure(pPath
);
1983 // FIXME: check if lasterror is set correctly
1984 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1987 PATH_UnlockPath( pPath
);
1994 NtGdiEndPath(HDC hDC
)
1998 PDC dc
= DC_LockDc ( hDC
);
2002 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2006 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
2012 /* Check that path is currently being constructed */
2013 if ( (pPath
->state
!= PATH_Open
) || !(dc
->DcLevel
.flPath
& DCPATH_ACTIVE
) )
2015 DPRINT1("EndPath ERROR! 0x%x\n", dc
->DcLevel
.hPath
);
2016 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
2019 /* Set flag to indicate that path is finished */
2022 DPRINT1("EndPath 0x%x\n", dc
->DcLevel
.hPath
);
2023 pPath
->state
= PATH_Closed
;
2024 dc
->DcLevel
.flPath
&= ~DCPATH_ACTIVE
;
2026 PATH_UnlockPath( pPath
);
2033 NtGdiFillPath(HDC hDC
)
2037 PDC dc
= DC_LockDc ( hDC
);
2041 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2044 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
2051 ret
= PATH_FillPath( dc
, pPath
);
2054 /* FIXME: Should the path be emptied even if conversion
2056 PATH_EmptyPath( pPath
);
2059 PATH_UnlockPath( pPath
);
2066 NtGdiFlattenPath(HDC hDC
)
2072 DPRINT("Enter %s\n", __FUNCTION__
);
2074 pDc
= DC_LockDc(hDC
);
2077 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2081 pPath
= PATH_LockPath( pDc
->DcLevel
.hPath
);
2084 DC_UnlockDc ( pDc
);
2087 if (pPath
->state
== PATH_Open
)
2088 Ret
= PATH_FlattenPath(pPath
);
2090 PATH_UnlockPath( pPath
);
2104 NTSTATUS Status
= STATUS_SUCCESS
;
2106 if (!(pDc
= DC_LockDc(hdc
)))
2108 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2112 worker
.f
= pDc
->DcLevel
.laPath
.eMiterLimit
;
2118 ProbeForWrite(pdwOut
,
2125 Status
= _SEH_GetExceptionCode();
2128 if (!NT_SUCCESS(Status
))
2130 SetLastNtError(Status
);
2152 DC
*dc
= DC_LockDc(hDC
);
2155 DPRINT1("Can't lock dc!\n");
2156 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2160 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
2167 if (pPath
->state
!= PATH_Closed
)
2169 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
2175 ret
= pPath
->numEntriesUsed
;
2177 else if(nSize
<pPath
->numEntriesUsed
)
2179 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2186 memcpy(Points
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
2187 memcpy(Types
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
2189 /* Convert the points to logical coordinates */
2190 IntDPtoLP(dc
, Points
, pPath
->numEntriesUsed
);
2192 ret
= pPath
->numEntriesUsed
;
2196 SetLastNtError(_SEH_GetExceptionCode());
2202 PATH_UnlockPath( pPath
);
2209 NtGdiPathToRegion(HDC hDC
)
2216 DPRINT("Enter %s\n", __FUNCTION__
);
2218 pDc
= DC_LockDc(hDC
);
2221 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2225 Dc_Attr
= pDc
->pDc_Attr
;
2226 if(!Dc_Attr
) Dc_Attr
= &pDc
->Dc_Attr
;
2228 pPath
= PATH_LockPath( pDc
->DcLevel
.hPath
);
2231 DC_UnlockDc ( pDc
);
2235 if (pPath
->state
!=PATH_Closed
)
2237 //FIXME: check that setlasterror is being called correctly
2238 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
2242 /* FIXME: Should we empty the path even if conversion failed? */
2243 if(PATH_PathToRegion(pPath
, Dc_Attr
->jFillMode
, &hrgnRval
))
2244 PATH_EmptyPath(pPath
);
2247 PATH_UnlockPath( pPath
);
2257 IN OUT OPTIONAL PDWORD pdwOut
)
2260 gxf_long worker
, worker1
;
2261 NTSTATUS Status
= STATUS_SUCCESS
;
2263 if (!(pDc
= DC_LockDc(hdc
)))
2265 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2270 worker1
.f
= pDc
->DcLevel
.laPath
.eMiterLimit
;
2271 pDc
->DcLevel
.laPath
.eMiterLimit
= worker
.f
;
2277 ProbeForWrite(pdwOut
,
2280 *pdwOut
= worker1
.l
;
2284 Status
= _SEH_GetExceptionCode();
2287 if (!NT_SUCCESS(Status
))
2289 SetLastNtError(Status
);
2301 NtGdiStrokeAndFillPath(HDC hDC
)
2307 DPRINT1("Enter %s\n", __FUNCTION__
);
2309 if (!(pDc
= DC_LockDc(hDC
)))
2311 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2314 pPath
= PATH_LockPath( pDc
->DcLevel
.hPath
);
2317 DC_UnlockDc ( pDc
);
2320 bRet
= PATH_FillPath(pDc
, pPath
);
2321 if (bRet
) bRet
= PATH_StrokePath(pDc
, pPath
);
2322 if (bRet
) PATH_EmptyPath(pPath
);
2324 PATH_UnlockPath( pPath
);
2331 NtGdiStrokePath(HDC hDC
)
2337 DPRINT("Enter %s\n", __FUNCTION__
);
2339 if (!(pDc
= DC_LockDc(hDC
)))
2341 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2344 pPath
= PATH_LockPath( pDc
->DcLevel
.hPath
);
2347 DC_UnlockDc ( pDc
);
2351 bRet
= PATH_StrokePath(pDc
, pPath
);
2352 PATH_EmptyPath(pPath
);
2354 PATH_UnlockPath( pPath
);
2361 NtGdiWidenPath(HDC hDC
)
2364 PDC pdc
= DC_LockDc ( hDC
);
2367 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2370 Ret
= PATH_WidenPath(pdc
);
2371 DC_UnlockDc ( pdc
);
2377 NtGdiSelectClipPath(HDC hDC
,
2382 BOOL success
= FALSE
;
2384 PDC dc
= DC_LockDc ( hDC
);
2388 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2392 Dc_Attr
= dc
->pDc_Attr
;
2393 if(!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
2395 pPath
= PATH_LockPath( dc
->DcLevel
.hPath
);
2401 /* Check that path is closed */
2402 if( pPath
->state
!= PATH_Closed
)
2404 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
2407 /* Construct a region from the path */
2408 else if( PATH_PathToRegion( pPath
, Dc_Attr
->jFillMode
, &hrgnPath
) )
2410 success
= GdiExtSelectClipRgn( dc
, hrgnPath
, Mode
) != ERROR
;
2411 NtGdiDeleteObject( hrgnPath
);
2413 /* Empty the path */
2415 PATH_EmptyPath( pPath
);
2416 /* FIXME: Should this function delete the path even if it failed? */
2418 PATH_UnlockPath( pPath
);