2 * Graphics paths (BeginPath, EndPath etc.)
4 * Copyright 1997, 1998 Martin Boehme
6 * Copyright 2005 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * Addaped for the use in ReactOS.
28 * PROJECT: ReactOS win32 kernel mode subsystem
29 * LICENSE: GPL - See COPYING in the top level directory
30 * FILE: subsystems/win32/win32k/objects/path.c
31 * PURPOSE: Path support
41 #define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
42 #define GROW_FACTOR_NUMER 2 /* Numerator of grow factor for the array */
43 #define GROW_FACTOR_DENOM 1 /* Denominator of grow factor */
45 BOOL FASTCALL
PATH_AddEntry (PPATH pPath
, const POINT
*pPoint
, BYTE flags
);
46 BOOL FASTCALL
PATH_AddFlatBezier (PPATH pPath
, POINT
*pt
, BOOL closed
);
47 BOOL FASTCALL
PATH_DoArcPart (PPATH pPath
, FLOAT_POINT corners
[], double angleStart
, double angleEnd
, BYTE startEntryType
);
48 BOOL FASTCALL
PATH_FillPath( PDC dc
, PPATH pPath
);
49 BOOL FASTCALL
PATH_FlattenPath (PPATH pPath
);
50 VOID FASTCALL
PATH_NormalizePoint (FLOAT_POINT corners
[], const FLOAT_POINT
*pPoint
, double *pX
, double *pY
);
52 BOOL FASTCALL
PATH_ReserveEntries (PPATH pPath
, INT numEntries
);
53 VOID FASTCALL
PATH_ScaleNormalizedPoint (FLOAT_POINT corners
[], double x
, double y
, POINT
*pPoint
);
54 BOOL FASTCALL
PATH_StrokePath(DC
*dc
, PPATH pPath
);
55 BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
);
57 VOID FASTCALL
IntGetCurrentPositionEx(PDC dc
, LPPOINT pt
);
59 /***********************************************************************
65 PATH_Delete(HPATH hPath
)
67 if (!hPath
) return FALSE
;
68 PPATH pPath
= PATH_LockPath( hPath
);
69 if (!pPath
) return FALSE
;
70 PATH_DestroyGdiPath( pPath
);
71 PATH_UnlockPath( pPath
);
72 PATH_FreeExtPathByHandle(hPath
);
79 IntGdiCloseFigure(PPATH pPath
)
81 ASSERT(pPath
->state
== PATH_Open
);
83 // FIXME: Shouldn't we draw a line to the beginning of the figure?
84 // Set PT_CLOSEFIGURE on the last entry and start a new stroke
85 if(pPath
->numEntriesUsed
)
87 pPath
->pFlags
[pPath
->numEntriesUsed
-1]|=PT_CLOSEFIGURE
;
88 pPath
->newStroke
=TRUE
;
98 PATH_FillPath( PDC dc
, PPATH pPath
)
100 INT mapMode
, graphicsMode
;
101 SIZE ptViewportExt
, ptWindowExt
;
102 POINTL ptViewportOrg
, ptWindowOrg
;
105 PDC_ATTR pdcattr
= dc
->pdcattr
;
107 if( pPath
->state
!= PATH_Closed
)
109 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
113 if( PATH_PathToRegion( pPath
, pdcattr
->jFillMode
, &hrgn
))
115 /* Since PaintRgn interprets the region as being in logical coordinates
116 * but the points we store for the path are already in device
117 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
118 * Using SaveDC to save information about the mapping mode / world
119 * transform would be easier but would require more overhead, especially
120 * now that SaveDC saves the current path.
123 /* Save the information about the old mapping mode */
124 mapMode
= pdcattr
->iMapMode
;
125 ptViewportExt
= pdcattr
->szlViewportExt
;
126 ptViewportOrg
= pdcattr
->ptlViewportOrg
;
127 ptWindowExt
= pdcattr
->szlWindowExt
;
128 ptWindowOrg
= pdcattr
->ptlWindowOrg
;
130 /* Save world transform
131 * NB: The Windows documentation on world transforms would lead one to
132 * believe that this has to be done only in GM_ADVANCED; however, my
133 * tests show that resetting the graphics mode to GM_COMPATIBLE does
134 * not reset the world transform.
136 MatrixS2XForm(&xform
, &dc
->dclevel
.mxWorldToPage
);
139 // IntGdiSetMapMode( dc, MM_TEXT );
140 // pdcattr->ptlViewportOrg.x = 0;
141 // pdcattr->ptlViewportOrg.y = 0;
142 // pdcattr->ptlWindowOrg.x = 0;
143 // pdcattr->ptlWindowOrg.y = 0;
145 graphicsMode
= pdcattr
->iGraphicsMode
;
146 // pdcattr->iGraphicsMode = GM_ADVANCED;
147 // IntGdiModifyWorldTransform( dc, &xform, MWT_IDENTITY );
148 // pdcattr->iGraphicsMode = graphicsMode;
150 /* Paint the region */
151 IntGdiPaintRgn( dc
, hrgn
);
152 GreDeleteObject( hrgn
);
153 /* Restore the old mapping mode */
154 // IntGdiSetMapMode( dc, mapMode );
155 // pdcattr->szlViewportExt = ptViewportExt;
156 // pdcattr->ptlViewportOrg = ptViewportOrg;
157 // pdcattr->szlWindowExt = ptWindowExt;
158 // pdcattr->ptlWindowOrg = ptWindowOrg;
160 /* Go to GM_ADVANCED temporarily to restore the world transform */
161 graphicsMode
= pdcattr
->iGraphicsMode
;
162 // pdcattr->iGraphicsMode = GM_ADVANCED;
163 // IntGdiModifyWorldTransform( dc, &xform, MWT_MAX+1 );
164 // pdcattr->iGraphicsMode = graphicsMode;
172 * Initializes the GdiPath structure.
176 PATH_InitGdiPath ( PPATH pPath
)
180 pPath
->state
=PATH_Null
;
183 pPath
->numEntriesUsed
=0;
184 pPath
->numEntriesAllocated
=0;
187 /* PATH_DestroyGdiPath
189 * Destroys a GdiPath structure (frees the memory in the arrays).
193 PATH_DestroyGdiPath ( PPATH pPath
)
197 if (pPath
->pPoints
) ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
198 if (pPath
->pFlags
) ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
201 /* PATH_AssignGdiPath
203 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
204 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
205 * not just the pointers. Since this means that the arrays in pPathDest may
206 * need to be resized, pPathDest should have been initialized using
207 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
208 * not a copy constructor).
209 * Returns TRUE if successful, else FALSE.
213 PATH_AssignGdiPath ( PPATH pPathDest
, const PPATH pPathSrc
)
215 ASSERT(pPathDest
!=NULL
&& pPathSrc
!=NULL
);
217 /* Make sure destination arrays are big enough */
218 if ( !PATH_ReserveEntries(pPathDest
, pPathSrc
->numEntriesUsed
) )
221 /* Perform the copy operation */
222 memcpy(pPathDest
->pPoints
, pPathSrc
->pPoints
,
223 sizeof(POINT
)*pPathSrc
->numEntriesUsed
);
224 memcpy(pPathDest
->pFlags
, pPathSrc
->pFlags
,
225 sizeof(BYTE
)*pPathSrc
->numEntriesUsed
);
227 pPathDest
->state
=pPathSrc
->state
;
228 pPathDest
->numEntriesUsed
=pPathSrc
->numEntriesUsed
;
229 pPathDest
->newStroke
=pPathSrc
->newStroke
;
235 * Should be called when a MoveTo is performed on a DC that has an
236 * open path. This starts a new stroke. Returns TRUE if successful, else
241 PATH_MoveTo ( PDC dc
)
243 PPATH pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
244 if (!pPath
) return FALSE
;
246 /* Check that path is open */
247 if ( pPath
->state
!= PATH_Open
)
249 PATH_UnlockPath( pPath
);
250 /* FIXME: Do we have to call SetLastError? */
253 /* Start a new stroke */
254 pPath
->newStroke
= TRUE
;
255 PATH_UnlockPath( pPath
);
261 * Should be called when a LineTo is performed on a DC that has an
262 * open path. This adds a PT_LINETO entry to the path (and possibly
263 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
264 * Returns TRUE if successful, else FALSE.
268 PATH_LineTo ( PDC dc
, INT x
, INT y
)
272 POINT point
, pointCurPos
;
274 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
275 if (!pPath
) return FALSE
;
277 /* Check that path is open */
278 if ( pPath
->state
!= PATH_Open
)
280 PATH_UnlockPath( pPath
);
284 /* Convert point to device coordinates */
287 CoordLPtoDP ( dc
, &point
);
289 /* Add a PT_MOVETO if necessary */
290 if ( pPath
->newStroke
)
292 pPath
->newStroke
= FALSE
;
293 IntGetCurrentPositionEx ( dc
, &pointCurPos
);
294 CoordLPtoDP ( dc
, &pointCurPos
);
295 if ( !PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
) )
297 PATH_UnlockPath( pPath
);
302 /* Add a PT_LINETO entry */
303 Ret
= PATH_AddEntry(pPath
, &point
, PT_LINETO
);
304 PATH_UnlockPath( pPath
);
310 * Should be called when a call to Rectangle is performed on a DC that has
311 * an open path. Returns TRUE if successful, else FALSE.
315 PATH_Rectangle ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
)
318 POINT corners
[2], pointTemp
;
321 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
322 if (!pPath
) return FALSE
;
324 /* Check that path is open */
325 if ( pPath
->state
!= PATH_Open
)
327 PATH_UnlockPath( pPath
);
331 /* Convert points to device coordinates */
336 IntLPtoDP ( dc
, corners
, 2 );
338 /* Make sure first corner is top left and second corner is bottom right */
339 if ( corners
[0].x
> corners
[1].x
)
342 corners
[0].x
=corners
[1].x
;
345 if ( corners
[0].y
> corners
[1].y
)
348 corners
[0].y
=corners
[1].y
;
352 /* In GM_COMPATIBLE, don't include bottom and right edges */
353 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
359 /* Close any previous figure */
360 IntGdiCloseFigure(pPath
);
362 /* Add four points to the path */
363 pointTemp
.x
=corners
[1].x
;
364 pointTemp
.y
=corners
[0].y
;
365 if ( !PATH_AddEntry(pPath
, &pointTemp
, PT_MOVETO
) )
367 PATH_UnlockPath( pPath
);
370 if ( !PATH_AddEntry(pPath
, corners
, PT_LINETO
) )
372 PATH_UnlockPath( pPath
);
375 pointTemp
.x
=corners
[0].x
;
376 pointTemp
.y
=corners
[1].y
;
377 if ( !PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
) )
379 PATH_UnlockPath( pPath
);
382 if ( !PATH_AddEntry(pPath
, corners
+1, PT_LINETO
) )
384 PATH_UnlockPath( pPath
);
388 /* Close the rectangle figure */
389 IntGdiCloseFigure(pPath
) ;
390 PATH_UnlockPath( pPath
);
396 * Should be called when a call to RoundRect is performed on a DC that has
397 * an open path. Returns TRUE if successful, else FALSE.
399 * FIXME: it adds the same entries to the path as windows does, but there
400 * is an error in the bezier drawing code so that there are small pixel-size
401 * gaps when the resulting path is drawn by StrokePath()
403 BOOL FASTCALL
PATH_RoundRect(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
, INT ell_width
, INT ell_height
)
406 POINT corners
[2], pointTemp
;
407 FLOAT_POINT ellCorners
[2];
409 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
410 if (!pPath
) return FALSE
;
412 /* Check that path is open */
413 if(pPath
->state
!=PATH_Open
)
415 PATH_UnlockPath( pPath
);
419 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
421 PATH_UnlockPath( pPath
);
425 /* Add points to the roundrect path */
426 ellCorners
[0].x
= corners
[1].x
-ell_width
;
427 ellCorners
[0].y
= corners
[0].y
;
428 ellCorners
[1].x
= corners
[1].x
;
429 ellCorners
[1].y
= corners
[0].y
+ell_height
;
430 if(!PATH_DoArcPart(pPath
, ellCorners
, 0, -M_PI_2
, PT_MOVETO
))
432 PATH_UnlockPath( pPath
);
435 pointTemp
.x
= corners
[0].x
+ell_width
/2;
436 pointTemp
.y
= corners
[0].y
;
437 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
439 PATH_UnlockPath( pPath
);
442 ellCorners
[0].x
= corners
[0].x
;
443 ellCorners
[1].x
= corners
[0].x
+ell_width
;
444 if(!PATH_DoArcPart(pPath
, ellCorners
, -M_PI_2
, -M_PI
, FALSE
))
446 PATH_UnlockPath( pPath
);
449 pointTemp
.x
= corners
[0].x
;
450 pointTemp
.y
= corners
[1].y
-ell_height
/2;
451 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
453 PATH_UnlockPath( pPath
);
456 ellCorners
[0].y
= corners
[1].y
-ell_height
;
457 ellCorners
[1].y
= corners
[1].y
;
458 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI
, M_PI_2
, FALSE
))
460 PATH_UnlockPath( pPath
);
463 pointTemp
.x
= corners
[1].x
-ell_width
/2;
464 pointTemp
.y
= corners
[1].y
;
465 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
467 PATH_UnlockPath( pPath
);
470 ellCorners
[0].x
= corners
[1].x
-ell_width
;
471 ellCorners
[1].x
= corners
[1].x
;
472 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI_2
, 0, FALSE
))
474 PATH_UnlockPath( pPath
);
478 IntGdiCloseFigure(pPath
);
479 PATH_UnlockPath( pPath
);
485 * Should be called when a call to Ellipse is performed on a DC that has
486 * an open path. This adds four Bezier splines representing the ellipse
487 * to the path. Returns TRUE if successful, else FALSE.
491 PATH_Ellipse ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
)
494 /* TODO: This should probably be revised to call PATH_AngleArc */
495 /* (once it exists) */
496 BOOL Ret
= PATH_Arc ( dc
, x1
, y1
, x2
, y2
, x1
, (y1
+y2
)/2, x1
, (y1
+y2
)/2, GdiTypeArc
);
499 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
500 if (!pPath
) return FALSE
;
501 IntGdiCloseFigure(pPath
);
502 PATH_UnlockPath( pPath
);
509 * Should be called when a call to Arc is performed on a DC that has
510 * an open path. This adds up to five Bezier splines representing the arc
511 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
512 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
513 * -1 we add 1 extra line from the current DC position to the starting position
514 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
519 PATH_Arc ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
,
520 INT xStart
, INT yStart
, INT xEnd
, INT yEnd
, INT lines
)
522 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
=0.0;
523 /* Initialize angleEndQuadrant to silence gcc's warning */
525 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
526 POINT centre
, pointCurPos
;
527 BOOL start
, end
, Ret
= TRUE
;
532 /* FIXME: This function should check for all possible error returns */
533 /* FIXME: Do we have to respect newStroke? */
537 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
538 if (!pPath
) return FALSE
;
540 clockwise
= ((dc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
542 /* Check that path is open */
543 if ( pPath
->state
!= PATH_Open
)
549 /* Check for zero height / width */
550 /* FIXME: Only in GM_COMPATIBLE? */
551 if ( x1
==x2
|| y1
==y2
)
556 /* Convert points to device coordinates */
557 corners
[0].x
=(FLOAT
)x1
;
558 corners
[0].y
=(FLOAT
)y1
;
559 corners
[1].x
=(FLOAT
)x2
;
560 corners
[1].y
=(FLOAT
)y2
;
561 pointStart
.x
=(FLOAT
)xStart
;
562 pointStart
.y
=(FLOAT
)yStart
;
563 pointEnd
.x
=(FLOAT
)xEnd
;
564 pointEnd
.y
=(FLOAT
)yEnd
;
565 INTERNAL_LPTODP_FLOAT(dc
, corners
);
566 INTERNAL_LPTODP_FLOAT(dc
, corners
+1);
567 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
);
568 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
);
570 /* Make sure first corner is top left and second corner is bottom right */
571 if ( corners
[0].x
> corners
[1].x
)
574 corners
[0].x
=corners
[1].x
;
577 if ( corners
[0].y
> corners
[1].y
)
580 corners
[0].y
=corners
[1].y
;
584 /* Compute start and end angle */
585 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
586 angleStart
=atan2(y
, x
);
587 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
588 angleEnd
=atan2(y
, x
);
590 /* Make sure the end angle is "on the right side" of the start angle */
593 if ( angleEnd
<= angleStart
)
596 ASSERT(angleEnd
>=angleStart
);
601 if(angleEnd
>=angleStart
)
604 ASSERT(angleEnd
<=angleStart
);
608 /* In GM_COMPATIBLE, don't include bottom and right edges */
609 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
615 /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
616 if(lines
==GdiTypeArcTo
&& pPath
->newStroke
) // -1
618 pPath
->newStroke
=FALSE
;
619 IntGetCurrentPositionEx ( dc
, &pointCurPos
);
620 CoordLPtoDP(dc
, &pointCurPos
);
621 if(!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
628 /* Add the arc to the path with one Bezier spline per quadrant that the
634 /* Determine the start and end angles for this quadrant */
637 angleStartQuadrant
=angleStart
;
639 angleEndQuadrant
=(floor(angleStart
/M_PI_2
)+1.0)*M_PI_2
;
641 angleEndQuadrant
=(ceil(angleStart
/M_PI_2
)-1.0)*M_PI_2
;
645 angleStartQuadrant
=angleEndQuadrant
;
647 angleEndQuadrant
+=M_PI_2
;
649 angleEndQuadrant
-=M_PI_2
;
652 /* Have we reached the last part of the arc? */
653 if ( (clockwise
&& angleEnd
<angleEndQuadrant
)
654 || (!clockwise
&& angleEnd
>angleEndQuadrant
)
657 /* Adjust the end angle for this quadrant */
658 angleEndQuadrant
= angleEnd
;
662 /* Add the Bezier spline to the path */
663 PATH_DoArcPart ( pPath
, corners
, angleStartQuadrant
, angleEndQuadrant
,
664 start
? (lines
==GdiTypeArcTo
? PT_LINETO
: PT_MOVETO
) : FALSE
); // -1
668 /* chord: close figure. pie: add line and close figure */
669 if (lines
==GdiTypeChord
) // 1
671 IntGdiCloseFigure(pPath
);
673 else if (lines
==GdiTypePie
) // 2
675 centre
.x
= (corners
[0].x
+corners
[1].x
)/2;
676 centre
.y
= (corners
[0].y
+corners
[1].y
)/2;
677 if(!PATH_AddEntry(pPath
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
681 PATH_UnlockPath( pPath
);
687 PATH_PolyBezierTo ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
697 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
698 if (!pPath
) return FALSE
;
700 /* Check that path is open */
701 if ( pPath
->state
!= PATH_Open
)
703 PATH_UnlockPath( pPath
);
707 /* Add a PT_MOVETO if necessary */
708 if ( pPath
->newStroke
)
710 pPath
->newStroke
=FALSE
;
711 IntGetCurrentPositionEx ( dc
, &pt
);
712 CoordLPtoDP ( dc
, &pt
);
713 if ( !PATH_AddEntry(pPath
, &pt
, PT_MOVETO
) )
715 PATH_UnlockPath( pPath
);
720 for(i
= 0; i
< cbPoints
; i
++)
723 CoordLPtoDP ( dc
, &pt
);
724 PATH_AddEntry(pPath
, &pt
, PT_BEZIERTO
);
726 PATH_UnlockPath( pPath
);
732 PATH_PolyBezier ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
742 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
743 if (!pPath
) return FALSE
;
745 /* Check that path is open */
746 if ( pPath
->state
!= PATH_Open
)
748 PATH_UnlockPath( pPath
);
752 for ( i
= 0; i
< cbPoints
; i
++ )
755 CoordLPtoDP ( dc
, &pt
);
756 PATH_AddEntry ( pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_BEZIERTO
);
758 PATH_UnlockPath( pPath
);
764 PATH_Polyline ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
774 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
775 if (!pPath
) return FALSE
;
777 /* Check that path is open */
778 if ( pPath
->state
!= PATH_Open
)
780 PATH_UnlockPath( pPath
);
783 for ( i
= 0; i
< cbPoints
; i
++ )
786 CoordLPtoDP ( dc
, &pt
);
787 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_LINETO
);
789 PATH_UnlockPath( pPath
);
795 PATH_PolylineTo ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
805 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
806 if (!pPath
) return FALSE
;
808 /* Check that path is open */
809 if ( pPath
->state
!= PATH_Open
)
811 PATH_UnlockPath( pPath
);
815 /* Add a PT_MOVETO if necessary */
816 if ( pPath
->newStroke
)
818 pPath
->newStroke
= FALSE
;
819 IntGetCurrentPositionEx ( dc
, &pt
);
820 CoordLPtoDP ( dc
, &pt
);
821 if ( !PATH_AddEntry(pPath
, &pt
, PT_MOVETO
) )
823 PATH_UnlockPath( pPath
);
828 for(i
= 0; i
< cbPoints
; i
++)
831 CoordLPtoDP ( dc
, &pt
);
832 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
834 PATH_UnlockPath( pPath
);
841 PATH_Polygon ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
850 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
851 if (!pPath
) return FALSE
;
853 /* Check that path is open */
854 if ( pPath
->state
!= PATH_Open
)
856 PATH_UnlockPath( pPath
);
860 for(i
= 0; i
< cbPoints
; i
++)
863 CoordLPtoDP ( dc
, &pt
);
864 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
:
865 ((i
== cbPoints
-1) ? PT_LINETO
| PT_CLOSEFIGURE
:
868 PATH_UnlockPath( pPath
);
874 PATH_PolyPolygon ( PDC dc
, const POINT
* pts
, const INT
* counts
, UINT polygons
)
877 ULONG poly
, point
, i
;
885 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
886 if (!pPath
) return FALSE
;
888 /* Check that path is open */
889 if ( pPath
->state
!= PATH_Open
)
891 PATH_UnlockPath( pPath
);
895 for(i
= 0, poly
= 0; poly
< polygons
; poly
++)
897 for(point
= 0; point
< (ULONG
) counts
[poly
]; point
++, i
++)
900 CoordLPtoDP ( dc
, &pt
);
901 if(point
== 0) startpt
= pt
;
902 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
904 /* win98 adds an extra line to close the figure for some reason */
905 PATH_AddEntry(pPath
, &startpt
, PT_LINETO
| PT_CLOSEFIGURE
);
907 PATH_UnlockPath( pPath
);
913 PATH_PolyPolyline ( PDC dc
, const POINT
* pts
, const DWORD
* counts
, DWORD polylines
)
916 ULONG poly
, point
, i
;
922 ASSERT ( polylines
);
924 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
925 if (!pPath
) return FALSE
;
927 /* Check that path is open */
928 if ( pPath
->state
!= PATH_Open
)
930 PATH_UnlockPath( pPath
);
934 for(i
= 0, poly
= 0; poly
< polylines
; poly
++)
936 for(point
= 0; point
< counts
[poly
]; point
++, i
++)
939 CoordLPtoDP ( dc
, &pt
);
940 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
943 PATH_UnlockPath( pPath
);
950 * Helper function for PATH_RoundRect() and PATH_Rectangle()
952 BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
)
955 PDC_ATTR pdcattr
= dc
->pdcattr
;
957 /* Convert points to device coordinates */
962 CoordLPtoDP(dc
, &corners
[0]);
963 CoordLPtoDP(dc
, &corners
[1]);
965 /* Make sure first corner is top left and second corner is bottom right */
966 if(corners
[0].x
>corners
[1].x
)
969 corners
[0].x
=corners
[1].x
;
972 if(corners
[0].y
>corners
[1].y
)
975 corners
[0].y
=corners
[1].y
;
979 /* In GM_COMPATIBLE, don't include bottom and right edges */
980 if(pdcattr
->iGraphicsMode
==GM_COMPATIBLE
)
990 /* PATH_AddFlatBezier
995 PATH_AddFlatBezier ( PPATH pPath
, POINT
*pt
, BOOL closed
)
1000 pts
= GDI_Bezier( pt
, 4, &no
);
1001 if ( !pts
) return FALSE
;
1003 for(i
= 1; i
< no
; i
++)
1004 PATH_AddEntry(pPath
, &pts
[i
], (i
== no
-1 && closed
) ? PT_LINETO
| PT_CLOSEFIGURE
: PT_LINETO
);
1006 ExFreePoolWithTag(pts
, TAG_BEZIER
);
1012 * Replaces Beziers with line segments
1017 PATH_FlattenPath(PPATH pPath
)
1022 RtlZeroMemory(&newPath
, sizeof(newPath
));
1023 newPath
.state
= PATH_Open
;
1024 for(srcpt
= 0; srcpt
< pPath
->numEntriesUsed
; srcpt
++) {
1025 switch(pPath
->pFlags
[srcpt
] & ~PT_CLOSEFIGURE
) {
1028 PATH_AddEntry(&newPath
, &pPath
->pPoints
[srcpt
], pPath
->pFlags
[srcpt
]);
1031 PATH_AddFlatBezier(&newPath
, &pPath
->pPoints
[srcpt
-1], pPath
->pFlags
[srcpt
+2] & PT_CLOSEFIGURE
);
1036 newPath
.state
= PATH_Closed
;
1037 PATH_AssignGdiPath(pPath
, &newPath
);
1038 PATH_EmptyPath(&newPath
);
1043 /* PATH_PathToRegion
1045 * Creates a region from the specified path using the specified polygon
1046 * filling mode. The path is left unchanged. A handle to the region that
1047 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1048 * error occurs, SetLastError is called with the appropriate value and
1049 * FALSE is returned.
1053 PATH_PathToRegion ( PPATH pPath
, INT nPolyFillMode
, HRGN
*pHrgn
)
1055 int numStrokes
, iStroke
, i
;
1056 PULONG pNumPointsInStroke
;
1059 ASSERT(pPath
!=NULL
);
1060 ASSERT(pHrgn
!=NULL
);
1062 PATH_FlattenPath ( pPath
);
1064 /* FIXME: What happens when number of points is zero? */
1066 /* First pass: Find out how many strokes there are in the path */
1067 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1069 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1070 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1073 /* Allocate memory for number-of-points-in-stroke array */
1074 pNumPointsInStroke
= ExAllocatePoolWithTag(PagedPool
, sizeof(ULONG
) * numStrokes
, TAG_PATH
);
1075 if(!pNumPointsInStroke
)
1077 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1081 /* Second pass: remember number of points in each polygon */
1082 iStroke
=-1; /* Will get incremented to 0 at beginning of first stroke */
1083 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1085 /* Is this the beginning of a new stroke? */
1086 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1089 pNumPointsInStroke
[iStroke
]=0;
1092 pNumPointsInStroke
[iStroke
]++;
1095 /* Create a region from the strokes */
1096 hrgn
= IntCreatePolyPolygonRgn( pPath
->pPoints
,
1102 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1106 /* Free memory for number-of-points-in-stroke array */
1107 ExFreePoolWithTag(pNumPointsInStroke
, TAG_PATH
);
1116 * Removes all entries from the path and sets the path state to PATH_Null.
1120 PATH_EmptyPath ( PPATH pPath
)
1122 ASSERT(pPath
!=NULL
);
1124 pPath
->state
=PATH_Null
;
1125 pPath
->numEntriesUsed
=0;
1130 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1131 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1132 * successful, FALSE otherwise (e.g. if not enough memory was available).
1136 PATH_AddEntry ( PPATH pPath
, const POINT
*pPoint
, BYTE flags
)
1138 ASSERT(pPath
!=NULL
);
1140 /* FIXME: If newStroke is true, perhaps we want to check that we're
1141 * getting a PT_MOVETO
1144 /* Check that path is open */
1145 if ( pPath
->state
!= PATH_Open
)
1148 /* Reserve enough memory for an extra path entry */
1149 if ( !PATH_ReserveEntries(pPath
, pPath
->numEntriesUsed
+1) )
1152 /* Store information in path entry */
1153 pPath
->pPoints
[pPath
->numEntriesUsed
]=*pPoint
;
1154 pPath
->pFlags
[pPath
->numEntriesUsed
]=flags
;
1156 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1157 if((flags
& PT_CLOSEFIGURE
) == PT_CLOSEFIGURE
)
1158 pPath
->newStroke
=TRUE
;
1160 /* Increment entry count */
1161 pPath
->numEntriesUsed
++;
1166 /* PATH_ReserveEntries
1168 * Ensures that at least "numEntries" entries (for points and flags) have
1169 * been allocated; allocates larger arrays and copies the existing entries
1170 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1174 PATH_ReserveEntries ( PPATH pPath
, INT numEntries
)
1176 INT numEntriesToAllocate
;
1180 ASSERT(pPath
!=NULL
);
1181 ASSERT(numEntries
>=0);
1183 /* Do we have to allocate more memory? */
1184 if(numEntries
> pPath
->numEntriesAllocated
)
1186 /* Find number of entries to allocate. We let the size of the array
1187 * grow exponentially, since that will guarantee linear time
1189 if(pPath
->numEntriesAllocated
)
1191 numEntriesToAllocate
=pPath
->numEntriesAllocated
;
1192 while(numEntriesToAllocate
<numEntries
)
1193 numEntriesToAllocate
=numEntriesToAllocate
*GROW_FACTOR_NUMER
/GROW_FACTOR_DENOM
;
1195 numEntriesToAllocate
=numEntries
;
1197 /* Allocate new arrays */
1198 pPointsNew
=(POINT
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(POINT
), TAG_PATH
);
1201 pFlagsNew
=(BYTE
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(BYTE
), TAG_PATH
);
1204 ExFreePoolWithTag(pPointsNew
, TAG_PATH
);
1208 /* Copy old arrays to new arrays and discard old arrays */
1211 ASSERT(pPath
->pFlags
);
1213 memcpy(pPointsNew
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
1214 memcpy(pFlagsNew
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
1216 ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
1217 ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
1219 pPath
->pPoints
=pPointsNew
;
1220 pPath
->pFlags
=pFlagsNew
;
1221 pPath
->numEntriesAllocated
=numEntriesToAllocate
;
1229 * Creates a Bezier spline that corresponds to part of an arc and appends the
1230 * corresponding points to the path. The start and end angles are passed in
1231 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1232 * at most. If "startEntryType" is non-zero, an entry of that type for the first
1233 * control point is added to the path; otherwise, it is assumed that the current
1234 * position is equal to the first control point.
1238 PATH_DoArcPart ( PPATH pPath
, FLOAT_POINT corners
[],
1239 double angleStart
, double angleEnd
, BYTE startEntryType
)
1241 double halfAngle
, a
;
1242 double xNorm
[4], yNorm
[4];
1246 ASSERT(fabs(angleEnd
-angleStart
)<=M_PI_2
);
1248 /* FIXME: Is there an easier way of computing this? */
1250 /* Compute control points */
1251 halfAngle
=(angleEnd
-angleStart
)/2.0;
1252 if(fabs(halfAngle
)>1e-8)
1254 a
=4.0/3.0*(1-cos(halfAngle
))/sin(halfAngle
);
1255 xNorm
[0]=cos(angleStart
);
1256 yNorm
[0]=sin(angleStart
);
1257 xNorm
[1]=xNorm
[0] - a
*yNorm
[0];
1258 yNorm
[1]=yNorm
[0] + a
*xNorm
[0];
1259 xNorm
[3]=cos(angleEnd
);
1260 yNorm
[3]=sin(angleEnd
);
1261 xNorm
[2]=xNorm
[3] + a
*yNorm
[3];
1262 yNorm
[2]=yNorm
[3] - a
*xNorm
[3];
1266 xNorm
[i
]=cos(angleStart
);
1267 yNorm
[i
]=sin(angleStart
);
1270 /* Add starting point to path if desired */
1273 PATH_ScaleNormalizedPoint(corners
, xNorm
[0], yNorm
[0], &point
);
1274 if(!PATH_AddEntry(pPath
, &point
, startEntryType
))
1278 /* Add remaining control points */
1281 PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &point
);
1282 if(!PATH_AddEntry(pPath
, &point
, PT_BEZIERTO
))
1289 /* PATH_ScaleNormalizedPoint
1291 * Scales a normalized point (x, y) with respect to the box whose corners are
1292 * passed in "corners". The point is stored in "*pPoint". The normalized
1293 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1294 * (1.0, 1.0) correspond to corners[1].
1298 PATH_ScaleNormalizedPoint ( FLOAT_POINT corners
[], double x
,
1299 double y
, POINT
*pPoint
)
1303 pPoint
->x
=GDI_ROUND( (double)corners
[0].x
+ (double)(corners
[1].x
-corners
[0].x
)*0.5*(x
+1.0) );
1304 pPoint
->y
=GDI_ROUND( (double)corners
[0].y
+ (double)(corners
[1].y
-corners
[0].y
)*0.5*(y
+1.0) );
1307 /* PATH_NormalizePoint
1309 * Normalizes a point with respect to the box whose corners are passed in
1310 * corners. The normalized coordinates are stored in *pX and *pY.
1314 PATH_NormalizePoint ( FLOAT_POINT corners
[],
1315 const FLOAT_POINT
*pPoint
,
1316 double *pX
, double *pY
)
1322 *pX
=(double)(pPoint
->x
-corners
[0].x
)/(double)(corners
[1].x
-corners
[0].x
) * 2.0 - 1.0;
1323 *pY
=(double)(pPoint
->y
-corners
[0].y
)/(double)(corners
[1].y
-corners
[0].y
) * 2.0 - 1.0;
1327 BOOL FASTCALL
PATH_StrokePath(DC
*dc
, PPATH pPath
)
1331 INT nLinePts
, nAlloc
;
1332 POINT
*pLinePts
= NULL
;
1333 POINT ptViewportOrg
, ptWindowOrg
;
1334 SIZE szViewportExt
, szWindowExt
;
1335 DWORD mapMode
, graphicsMode
;
1337 PDC_ATTR pdcattr
= dc
->pdcattr
;
1339 DPRINT("Enter %s\n", __FUNCTION__
);
1341 if (pPath
->state
!= PATH_Closed
)
1344 /* Save the mapping mode info */
1345 mapMode
= pdcattr
->iMapMode
;
1347 DC_vUpdateViewportExt(dc
);
1348 szViewportExt
= dc
->pdcattr
->szlViewportExt
;
1349 ptViewportOrg
= dc
->pdcattr
->ptlViewportOrg
;
1350 szWindowExt
= dc
->pdcattr
->szlWindowExt
;
1351 ptWindowOrg
= dc
->pdcattr
->ptlWindowOrg
;
1353 MatrixS2XForm(&xform
, &dc
->dclevel
.mxWorldToPage
);
1356 pdcattr
->iMapMode
= MM_TEXT
;
1357 pdcattr
->ptlViewportOrg
.x
= 0;
1358 pdcattr
->ptlViewportOrg
.y
= 0;
1359 pdcattr
->ptlWindowOrg
.x
= 0;
1360 pdcattr
->ptlWindowOrg
.y
= 0;
1361 graphicsMode
= pdcattr
->iGraphicsMode
;
1362 pdcattr
->iGraphicsMode
= GM_ADVANCED
;
1363 IntGdiModifyWorldTransform(dc
, &xform
, MWT_IDENTITY
);
1364 pdcattr
->iGraphicsMode
= graphicsMode
;
1366 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1367 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1368 * space in case we get one to keep the number of reallocations small. */
1369 nAlloc
= pPath
->numEntriesUsed
+ 1 + 300;
1370 pLinePts
= ExAllocatePoolWithTag(PagedPool
, nAlloc
* sizeof(POINT
), TAG_PATH
);
1373 DPRINT1("Can't allocate pool!\n");
1374 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1379 for(i
= 0; i
< pPath
->numEntriesUsed
; i
++)
1381 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
))
1382 && (pPath
->pFlags
[i
] != PT_MOVETO
))
1384 DPRINT1("Expected PT_MOVETO %s, got path flag %d\n",
1385 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1386 (INT
)pPath
->pFlags
[i
]);
1390 switch(pPath
->pFlags
[i
])
1393 DPRINT("Got PT_MOVETO (%ld, %ld)\n",
1394 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1395 if(nLinePts
>= 2) IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1397 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1400 case (PT_LINETO
| PT_CLOSEFIGURE
):
1401 DPRINT("Got PT_LINETO (%ld, %ld)\n",
1402 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1403 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1406 DPRINT("Got PT_BEZIERTO\n");
1407 if(pPath
->pFlags
[i
+1] != PT_BEZIERTO
||
1408 (pPath
->pFlags
[i
+2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
)
1410 DPRINT1("Path didn't contain 3 successive PT_BEZIERTOs\n");
1416 INT nBzrPts
, nMinAlloc
;
1417 POINT
*pBzrPts
= GDI_Bezier(&pPath
->pPoints
[i
-1], 4, &nBzrPts
);
1418 /* Make sure we have allocated enough memory for the lines of
1419 * this bezier and the rest of the path, assuming we won't get
1420 * another one (since we won't reallocate again then). */
1421 nMinAlloc
= nLinePts
+ (pPath
->numEntriesUsed
- i
) + nBzrPts
;
1422 if(nAlloc
< nMinAlloc
)
1424 // Reallocate memory
1426 POINT
*Realloc
= NULL
;
1427 nAlloc
= nMinAlloc
* 2;
1429 Realloc
= ExAllocatePoolWithTag(PagedPool
,
1430 nAlloc
* sizeof(POINT
),
1435 DPRINT1("Can't allocate pool!\n");
1439 memcpy(Realloc
, pLinePts
, nLinePts
*sizeof(POINT
));
1440 ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1443 memcpy(&pLinePts
[nLinePts
], &pBzrPts
[1], (nBzrPts
- 1) * sizeof(POINT
));
1444 nLinePts
+= nBzrPts
- 1;
1445 ExFreePoolWithTag(pBzrPts
, TAG_BEZIER
);
1450 DPRINT1("Got path flag %d (not supported)\n", (INT
)pPath
->pFlags
[i
]);
1454 if(pPath
->pFlags
[i
] & PT_CLOSEFIGURE
)
1456 pLinePts
[nLinePts
++] = pLinePts
[0];
1460 IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1465 if(pLinePts
) ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1467 /* Restore the old mapping mode */
1468 pdcattr
->iMapMode
= mapMode
;
1469 pdcattr
->szlWindowExt
.cx
= szWindowExt
.cx
;
1470 pdcattr
->szlWindowExt
.cy
= szWindowExt
.cy
;
1471 pdcattr
->ptlWindowOrg
.x
= ptWindowOrg
.x
;
1472 pdcattr
->ptlWindowOrg
.y
= ptWindowOrg
.y
;
1474 pdcattr
->szlViewportExt
.cx
= szViewportExt
.cx
;
1475 pdcattr
->szlViewportExt
.cy
= szViewportExt
.cy
;
1476 pdcattr
->ptlViewportOrg
.x
= ptViewportOrg
.x
;
1477 pdcattr
->ptlViewportOrg
.y
= ptViewportOrg
.y
;
1479 /* Restore the world transform */
1480 XForm2MatrixS(&dc
->dclevel
.mxWorldToPage
, &xform
);
1482 /* If we've moved the current point then get its new position
1483 which will be in device (MM_TEXT) co-ords, convert it to
1484 logical co-ords and re-set it. This basically updates
1485 dc->CurPosX|Y so that their values are in the correct mapping
1491 IntGetCurrentPositionEx(dc
, &pt
);
1492 IntDPtoLP(dc
, &pt
, 1);
1493 IntGdiMoveToEx(dc
, pt
.x
, pt
.y
, NULL
);
1495 DPRINT("Leave %s, ret=%d\n", __FUNCTION__
, ret
);
1499 #define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1504 PATH_WidenPath(DC
*dc
)
1506 INT i
, j
, numStrokes
, numOldStrokes
, penWidth
, penWidthIn
, penWidthOut
, size
, penStyle
;
1508 PPATH pPath
, pNewPath
, *pStrokes
, *pOldStrokes
, pUpPath
, pDownPath
;
1510 DWORD obj_type
, joint
, endcap
, penType
;
1511 PDC_ATTR pdcattr
= dc
->pdcattr
;
1513 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
1514 if (!pPath
) return FALSE
;
1516 if(pPath
->state
== PATH_Open
)
1518 PATH_UnlockPath( pPath
);
1519 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1523 PATH_FlattenPath(pPath
);
1525 size
= IntGdiGetObject( pdcattr
->hpen
, 0, NULL
);
1528 PATH_UnlockPath( pPath
);
1529 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1533 elp
= ExAllocatePoolWithTag(PagedPool
, size
, TAG_PATH
);
1534 (VOID
) IntGdiGetObject( pdcattr
->hpen
, size
, elp
);
1536 obj_type
= GDIOBJ_GetObjectType(pdcattr
->hpen
);
1537 if(obj_type
== GDI_OBJECT_TYPE_PEN
)
1539 penStyle
= ((LOGPEN
*)elp
)->lopnStyle
;
1541 else if(obj_type
== GDI_OBJECT_TYPE_EXTPEN
)
1543 penStyle
= elp
->elpPenStyle
;
1547 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1548 ExFreePoolWithTag(elp
, TAG_PATH
);
1549 PATH_UnlockPath( pPath
);
1553 penWidth
= elp
->elpWidth
;
1554 ExFreePoolWithTag(elp
, TAG_PATH
);
1556 endcap
= (PS_ENDCAP_MASK
& penStyle
);
1557 joint
= (PS_JOIN_MASK
& penStyle
);
1558 penType
= (PS_TYPE_MASK
& penStyle
);
1560 /* The function cannot apply to cosmetic pens */
1561 if(obj_type
== GDI_OBJECT_TYPE_EXTPEN
&& penType
== PS_COSMETIC
)
1563 PATH_UnlockPath( pPath
);
1564 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1568 penWidthIn
= penWidth
/ 2;
1569 penWidthOut
= penWidth
/ 2;
1570 if(penWidthIn
+ penWidthOut
< penWidth
)
1576 pStrokes
= ExAllocatePoolWithTag(PagedPool
, sizeof(PPATH
), TAG_PATH
);
1577 pStrokes
[0] = ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1578 PATH_InitGdiPath(pStrokes
[0]);
1579 pStrokes
[0]->pFlags
= ExAllocatePoolWithTag(PagedPool
, pPath
->numEntriesUsed
* sizeof(INT
), TAG_PATH
);
1580 pStrokes
[0]->pPoints
= ExAllocatePoolWithTag(PagedPool
, pPath
->numEntriesUsed
* sizeof(POINT
), TAG_PATH
);
1581 pStrokes
[0]->numEntriesUsed
= 0;
1583 for(i
= 0, j
= 0; i
< pPath
->numEntriesUsed
; i
++, j
++)
1586 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
)) &&
1587 (pPath
->pFlags
[i
] != PT_MOVETO
))
1589 DPRINT1("Expected PT_MOVETO %s, got path flag %c\n",
1590 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1594 switch(pPath
->pFlags
[i
])
1599 pStrokes
[numStrokes
- 1]->state
= PATH_Closed
;
1603 pOldStrokes
= pStrokes
; // Save old pointer.
1604 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1605 RtlCopyMemory(pStrokes
, pOldStrokes
, numOldStrokes
* sizeof(PPATH
));
1606 numOldStrokes
= numStrokes
; // Save orig count.
1607 ExFreePoolWithTag(pOldStrokes
, TAG_PATH
); // Free old pointer.
1608 pStrokes
[numStrokes
- 1] = ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1610 PATH_InitGdiPath(pStrokes
[numStrokes
- 1]);
1611 pStrokes
[numStrokes
- 1]->state
= PATH_Open
;
1613 case (PT_LINETO
| PT_CLOSEFIGURE
):
1614 point
.x
= pPath
->pPoints
[i
].x
;
1615 point
.y
= pPath
->pPoints
[i
].y
;
1616 PATH_AddEntry(pStrokes
[numStrokes
- 1], &point
, pPath
->pFlags
[i
]);
1619 /* should never happen because of the FlattenPath call */
1620 DPRINT1("Should never happen\n");
1623 DPRINT1("Got path flag %c\n", pPath
->pFlags
[i
]);
1628 pNewPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1629 PATH_InitGdiPath(pNewPath
);
1630 pNewPath
->state
= PATH_Open
;
1632 for(i
= 0; i
< numStrokes
; i
++)
1634 pUpPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1635 PATH_InitGdiPath(pUpPath
);
1636 pUpPath
->state
= PATH_Open
;
1637 pDownPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1638 PATH_InitGdiPath(pDownPath
);
1639 pDownPath
->state
= PATH_Open
;
1641 for(j
= 0; j
< pStrokes
[i
]->numEntriesUsed
; j
++)
1643 /* Beginning or end of the path if not closed */
1644 if((!(pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) && (j
== 0 || j
== pStrokes
[i
]->numEntriesUsed
- 1) )
1646 /* Compute segment angle */
1647 double xo
, yo
, xa
, ya
, theta
;
1649 FLOAT_POINT corners
[2];
1652 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1653 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1654 xa
= pStrokes
[i
]->pPoints
[1].x
;
1655 ya
= pStrokes
[i
]->pPoints
[1].y
;
1659 xa
= pStrokes
[i
]->pPoints
[j
- 1].x
;
1660 ya
= pStrokes
[i
]->pPoints
[j
- 1].y
;
1661 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1662 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1664 theta
= atan2( ya
- yo
, xa
- xo
);
1667 case PS_ENDCAP_SQUARE
:
1668 pt
.x
= xo
+ round(sqrt(2) * penWidthOut
* cos(M_PI_4
+ theta
));
1669 pt
.y
= yo
+ round(sqrt(2) * penWidthOut
* sin(M_PI_4
+ theta
));
1670 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
) );
1671 pt
.x
= xo
+ round(sqrt(2) * penWidthIn
* cos(- M_PI_4
+ theta
));
1672 pt
.y
= yo
+ round(sqrt(2) * penWidthIn
* sin(- M_PI_4
+ theta
));
1673 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1675 case PS_ENDCAP_FLAT
:
1676 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1677 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1678 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1679 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1680 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1681 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1683 case PS_ENDCAP_ROUND
:
1685 corners
[0].x
= xo
- penWidthIn
;
1686 corners
[0].y
= yo
- penWidthIn
;
1687 corners
[1].x
= xo
+ penWidthOut
;
1688 corners
[1].y
= yo
+ penWidthOut
;
1689 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI_2
, theta
+ 3 * M_PI_4
, (j
== 0 ? PT_MOVETO
: FALSE
));
1690 PATH_DoArcPart(pUpPath
,corners
, theta
+ 3 * M_PI_4
, theta
+ M_PI
, FALSE
);
1691 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI
, theta
+ 5 * M_PI_4
, FALSE
);
1692 PATH_DoArcPart(pUpPath
,corners
, theta
+ 5 * M_PI_4
, theta
+ 3 * M_PI_2
, FALSE
);
1696 /* Corpse of the path */
1701 double xa
, ya
, xb
, yb
, xo
, yo
;
1702 double alpha
, theta
, miterWidth
;
1703 DWORD _joint
= joint
;
1705 PPATH pInsidePath
, pOutsidePath
;
1706 if(j
> 0 && j
< pStrokes
[i
]->numEntriesUsed
- 1)
1713 previous
= pStrokes
[i
]->numEntriesUsed
- 1;
1721 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1722 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1723 xa
= pStrokes
[i
]->pPoints
[previous
].x
;
1724 ya
= pStrokes
[i
]->pPoints
[previous
].y
;
1725 xb
= pStrokes
[i
]->pPoints
[next
].x
;
1726 yb
= pStrokes
[i
]->pPoints
[next
].y
;
1727 theta
= atan2( yo
- ya
, xo
- xa
);
1728 alpha
= atan2( yb
- yo
, xb
- xo
) - theta
;
1729 if (alpha
> 0) alpha
-= M_PI
;
1731 if(_joint
== PS_JOIN_MITER
&& dc
->dclevel
.laPath
.eMiterLimit
< fabs(1 / sin(alpha
/2)))
1733 _joint
= PS_JOIN_BEVEL
;
1737 pInsidePath
= pUpPath
;
1738 pOutsidePath
= pDownPath
;
1742 pInsidePath
= pDownPath
;
1743 pOutsidePath
= pUpPath
;
1749 /* Inside angle points */
1752 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1753 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1757 pt
.x
= xo
+ round( penWidthIn
* cos(theta
+ M_PI_2
) );
1758 pt
.y
= yo
+ round( penWidthIn
* sin(theta
+ M_PI_2
) );
1760 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1763 pt
.x
= xo
+ round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1764 pt
.y
= yo
+ round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1768 pt
.x
= xo
- round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1769 pt
.y
= yo
- round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1771 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1772 /* Outside angle point */
1775 case PS_JOIN_MITER
:
1776 miterWidth
= fabs(penWidthOut
/ cos(M_PI_2
- fabs(alpha
) / 2));
1777 pt
.x
= xo
+ round( miterWidth
* cos(theta
+ alpha
/ 2) );
1778 pt
.y
= yo
+ round( miterWidth
* sin(theta
+ alpha
/ 2) );
1779 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1781 case PS_JOIN_BEVEL
:
1784 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1785 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1789 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1790 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1792 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1795 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1796 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1800 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1801 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1803 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1805 case PS_JOIN_ROUND
:
1809 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1810 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1814 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1815 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1817 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1818 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ alpha
/ 2) );
1819 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ alpha
/ 2) );
1820 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1823 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1824 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1828 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1829 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1831 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1836 for(j
= 0; j
< pUpPath
->numEntriesUsed
; j
++)
1839 pt
.x
= pUpPath
->pPoints
[j
].x
;
1840 pt
.y
= pUpPath
->pPoints
[j
].y
;
1841 PATH_AddEntry(pNewPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1843 for(j
= 0; j
< pDownPath
->numEntriesUsed
; j
++)
1846 pt
.x
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].x
;
1847 pt
.y
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].y
;
1848 PATH_AddEntry(pNewPath
, &pt
, ( (j
== 0 && (pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) ? PT_MOVETO
: PT_LINETO
));
1851 PATH_DestroyGdiPath(pStrokes
[i
]);
1852 ExFreePoolWithTag(pStrokes
[i
], TAG_PATH
);
1853 PATH_DestroyGdiPath(pUpPath
);
1854 ExFreePoolWithTag(pUpPath
, TAG_PATH
);
1855 PATH_DestroyGdiPath(pDownPath
);
1856 ExFreePoolWithTag(pDownPath
, TAG_PATH
);
1858 ExFreePoolWithTag(pStrokes
, TAG_PATH
);
1860 pNewPath
->state
= PATH_Closed
;
1861 if (!(ret
= PATH_AssignGdiPath(pPath
, pNewPath
)))
1862 DPRINT1("Assign path failed\n");
1863 PATH_DestroyGdiPath(pNewPath
);
1864 ExFreePoolWithTag(pNewPath
, TAG_PATH
);
1868 static inline INT
int_from_fixed(FIXED f
)
1870 return (f
.fract
>= 0x8000) ? (f
.value
+ 1) : f
.value
;
1873 /**********************************************************************
1876 * internally used by PATH_add_outline
1881 PATH_BezierTo(PPATH pPath
, POINT
*lppt
, INT n
)
1887 PATH_AddEntry(pPath
, &lppt
[1], PT_LINETO
);
1891 PATH_AddEntry(pPath
, &lppt
[0], PT_BEZIERTO
);
1892 PATH_AddEntry(pPath
, &lppt
[1], PT_BEZIERTO
);
1893 PATH_AddEntry(pPath
, &lppt
[2], PT_BEZIERTO
);
1907 pt
[2].x
= (lppt
[i
+2].x
+ lppt
[i
+1].x
) / 2;
1908 pt
[2].y
= (lppt
[i
+2].y
+ lppt
[i
+1].y
) / 2;
1909 PATH_BezierTo(pPath
, pt
, 3);
1917 PATH_BezierTo(pPath
, pt
, 3);
1924 PATH_add_outline(PDC dc
, INT x
, INT y
, TTPOLYGONHEADER
*header
, DWORD size
)
1927 TTPOLYGONHEADER
*start
;
1932 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
1937 while ((char *)header
< (char *)start
+ size
)
1941 if (header
->dwType
!= TT_POLYGON_TYPE
)
1943 DPRINT1("Unknown header type %d\n", header
->dwType
);
1947 pt
.x
= x
+ int_from_fixed(header
->pfxStart
.x
);
1948 pt
.y
= y
- int_from_fixed(header
->pfxStart
.y
);
1949 IntLPtoDP(dc
, &pt
, 1);
1950 PATH_AddEntry(pPath
, &pt
, PT_MOVETO
);
1952 curve
= (TTPOLYCURVE
*)(header
+ 1);
1954 while ((char *)curve
< (char *)header
+ header
->cb
)
1956 /*DPRINT1("curve->wType %d\n", curve->wType);*/
1958 switch(curve
->wType
)
1964 for (i
= 0; i
< curve
->cpfx
; i
++)
1966 pt
.x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1967 pt
.y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1968 IntLPtoDP(dc
, &pt
, 1);
1969 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
1974 case TT_PRIM_QSPLINE
:
1975 case TT_PRIM_CSPLINE
:
1979 POINT
*pts
= ExAllocatePoolWithTag(PagedPool
, (curve
->cpfx
+ 1) * sizeof(POINT
), TAG_PATH
);
1981 if (!pts
) return FALSE
;
1983 ptfx
= *(POINTFX
*)((char *)curve
- sizeof(POINTFX
));
1985 pts
[0].x
= x
+ int_from_fixed(ptfx
.x
);
1986 pts
[0].y
= y
- int_from_fixed(ptfx
.y
);
1987 IntLPtoDP(dc
, &pts
[0], 1);
1989 for (i
= 0; i
< curve
->cpfx
; i
++)
1991 pts
[i
+ 1].x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1992 pts
[i
+ 1].y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1993 IntLPtoDP(dc
, &pts
[i
+ 1], 1);
1996 PATH_BezierTo(pPath
, pts
, curve
->cpfx
+ 1);
1998 ExFreePoolWithTag(pts
, TAG_PATH
);
2003 DPRINT1("Unknown curve type %04x\n", curve
->wType
);
2007 curve
= (TTPOLYCURVE
*)&curve
->apfx
[curve
->cpfx
];
2009 header
= (TTPOLYGONHEADER
*)((char *)header
+ header
->cb
);
2012 IntGdiCloseFigure( pPath
);
2013 PATH_UnlockPath( pPath
);
2017 /**********************************************************************
2022 PATH_ExtTextOut(PDC dc
, INT x
, INT y
, UINT flags
, const RECTL
*lprc
,
2023 LPCWSTR str
, UINT count
, const INT
*dx
)
2026 double cosEsc
, sinEsc
;
2031 INT offset
= 0, xoff
= 0, yoff
= 0;
2033 if (!count
) return TRUE
;
2035 pdcattr
= dc
->pdcattr
;
2037 TextObj
= RealizeFontInit( pdcattr
->hlfntNew
);
2038 if ( !TextObj
) return FALSE
;
2040 FontGetObject( TextObj
, sizeof(lf
), &lf
);
2042 if (lf
.lfEscapement
!= 0)
2044 cosEsc
= cos(lf
.lfEscapement
* M_PI
/ 1800);
2045 sinEsc
= sin(lf
.lfEscapement
* M_PI
/ 1800);
2052 IntGdiGetDCOrg(dc
, &org
);
2054 for (idx
= 0; idx
< count
; idx
++)
2060 dwSize
= ftGdiGetGlyphOutline( dc
,
2062 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2068 if (!dwSize
) return FALSE
;
2070 outline
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_PATH
);
2071 if (!outline
) return FALSE
;
2073 ftGdiGetGlyphOutline( dc
,
2075 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2082 PATH_add_outline(dc
, org
.x
+ x
+ xoff
, org
.x
+ y
+ yoff
, outline
, dwSize
);
2084 ExFreePoolWithTag(outline
, TAG_PATH
);
2089 xoff
= offset
* cosEsc
;
2090 yoff
= offset
* -sinEsc
;
2094 xoff
+= gm
.gmCellIncX
;
2095 yoff
+= gm
.gmCellIncY
;
2102 /***********************************************************************
2103 * Exported functions
2108 NtGdiAbortPath(HDC hDC
)
2111 PDC dc
= DC_LockDc ( hDC
);
2114 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2118 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2124 PATH_EmptyPath(pPath
);
2126 PATH_UnlockPath(pPath
);
2133 NtGdiBeginPath( HDC hDC
)
2138 dc
= DC_LockDc ( hDC
);
2141 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2145 /* If path is already open, do nothing. Check if not Save DC state */
2146 if ((dc
->dclevel
.flPath
& DCPATH_ACTIVE
) && !(dc
->dclevel
.flPath
& DCPATH_SAVE
))
2152 if ( dc
->dclevel
.hPath
)
2154 DPRINT1("BeginPath 1 0x%x\n", dc
->dclevel
.hPath
);
2155 if ( !(dc
->dclevel
.flPath
& DCPATH_SAVE
) )
2156 { // Remove previous handle.
2157 if (!PATH_Delete(dc
->dclevel
.hPath
))
2164 { // Clear flags and Handle.
2165 dc
->dclevel
.flPath
&= ~(DCPATH_SAVE
|DCPATH_ACTIVE
);
2166 dc
->dclevel
.hPath
= NULL
;
2169 pPath
= PATH_AllocPathWithHandle();
2172 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2175 dc
->dclevel
.flPath
|= DCPATH_ACTIVE
; // Set active ASAP!
2177 dc
->dclevel
.hPath
= pPath
->BaseObject
.hHmgr
;
2179 DPRINT1("BeginPath 2 h 0x%x p 0x%x\n", dc
->dclevel
.hPath
, pPath
);
2180 // Path handles are shared. Also due to recursion with in the same thread.
2181 GDIOBJ_UnlockObjByPtr((POBJ
)pPath
); // Unlock
2182 pPath
= PATH_LockPath(dc
->dclevel
.hPath
); // Share Lock.
2184 /* Make sure that path is empty */
2185 PATH_EmptyPath( pPath
);
2187 /* Initialize variables for new path */
2188 pPath
->newStroke
= TRUE
;
2189 pPath
->state
= PATH_Open
;
2191 PATH_UnlockPath(pPath
);
2198 NtGdiCloseFigure(HDC hDC
)
2200 BOOL Ret
= FALSE
; // default to failure
2204 DPRINT("Enter %s\n", __FUNCTION__
);
2206 pDc
= DC_LockDc(hDC
);
2209 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2212 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2219 if (pPath
->state
==PATH_Open
)
2221 IntGdiCloseFigure(pPath
);
2226 // FIXME: check if lasterror is set correctly
2227 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
2230 PATH_UnlockPath( pPath
);
2237 NtGdiEndPath(HDC hDC
)
2241 PDC dc
= DC_LockDc ( hDC
);
2245 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2249 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2255 /* Check that path is currently being constructed */
2256 if ( (pPath
->state
!= PATH_Open
) || !(dc
->dclevel
.flPath
& DCPATH_ACTIVE
) )
2258 DPRINT1("EndPath ERROR! 0x%x\n", dc
->dclevel
.hPath
);
2259 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
2262 /* Set flag to indicate that path is finished */
2265 DPRINT1("EndPath 0x%x\n", dc
->dclevel
.hPath
);
2266 pPath
->state
= PATH_Closed
;
2267 dc
->dclevel
.flPath
&= ~DCPATH_ACTIVE
;
2269 PATH_UnlockPath( pPath
);
2276 NtGdiFillPath(HDC hDC
)
2281 PDC dc
= DC_LockDc ( hDC
);
2285 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2288 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2295 pdcattr
= dc
->pdcattr
;
2297 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2298 DC_vUpdateLineBrush(dc
);
2300 ret
= PATH_FillPath( dc
, pPath
);
2303 /* FIXME: Should the path be emptied even if conversion
2305 PATH_EmptyPath( pPath
);
2308 PATH_UnlockPath( pPath
);
2315 NtGdiFlattenPath(HDC hDC
)
2321 DPRINT("Enter %s\n", __FUNCTION__
);
2323 pDc
= DC_LockDc(hDC
);
2326 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2330 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2333 DC_UnlockDc ( pDc
);
2336 if (pPath
->state
== PATH_Open
)
2337 Ret
= PATH_FlattenPath(pPath
);
2339 PATH_UnlockPath( pPath
);
2353 NTSTATUS Status
= STATUS_SUCCESS
;
2355 if (!(pDc
= DC_LockDc(hdc
)))
2357 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2361 worker
.f
= pDc
->dclevel
.laPath
.eMiterLimit
;
2367 ProbeForWrite(pdwOut
,
2372 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2374 Status
= _SEH2_GetExceptionCode();
2377 if (!NT_SUCCESS(Status
))
2379 SetLastNtError(Status
);
2401 DC
*dc
= DC_LockDc(hDC
);
2404 DPRINT1("Can't lock dc!\n");
2405 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2409 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2416 if (pPath
->state
!= PATH_Closed
)
2418 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
2424 ret
= pPath
->numEntriesUsed
;
2426 else if(nSize
<pPath
->numEntriesUsed
)
2428 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2435 memcpy(Points
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
2436 memcpy(Types
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
2438 /* Convert the points to logical coordinates */
2439 IntDPtoLP(dc
, Points
, pPath
->numEntriesUsed
);
2441 ret
= pPath
->numEntriesUsed
;
2443 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2445 SetLastNtError(_SEH2_GetExceptionCode());
2451 PATH_UnlockPath( pPath
);
2458 NtGdiPathToRegion(HDC hDC
)
2465 DPRINT("Enter %s\n", __FUNCTION__
);
2467 pDc
= DC_LockDc(hDC
);
2470 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2474 pdcattr
= pDc
->pdcattr
;
2476 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2479 DC_UnlockDc ( pDc
);
2483 if (pPath
->state
!=PATH_Closed
)
2485 //FIXME: check that setlasterror is being called correctly
2486 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
2490 /* FIXME: Should we empty the path even if conversion failed? */
2491 if(PATH_PathToRegion(pPath
, pdcattr
->jFillMode
, &hrgnRval
))
2492 PATH_EmptyPath(pPath
);
2495 PATH_UnlockPath( pPath
);
2505 IN OUT OPTIONAL PDWORD pdwOut
)
2508 gxf_long worker
, worker1
;
2509 NTSTATUS Status
= STATUS_SUCCESS
;
2511 if (!(pDc
= DC_LockDc(hdc
)))
2513 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2518 worker1
.f
= pDc
->dclevel
.laPath
.eMiterLimit
;
2519 pDc
->dclevel
.laPath
.eMiterLimit
= worker
.f
;
2525 ProbeForWrite(pdwOut
,
2528 *pdwOut
= worker1
.l
;
2530 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2532 Status
= _SEH2_GetExceptionCode();
2535 if (!NT_SUCCESS(Status
))
2537 SetLastNtError(Status
);
2549 NtGdiStrokeAndFillPath(HDC hDC
)
2556 DPRINT1("Enter %s\n", __FUNCTION__
);
2558 if (!(pDc
= DC_LockDc(hDC
)))
2560 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2563 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2566 DC_UnlockDc ( pDc
);
2570 pdcattr
= pDc
->pdcattr
;
2572 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
2573 DC_vUpdateFillBrush(pDc
);
2575 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2576 DC_vUpdateLineBrush(pDc
);
2578 bRet
= PATH_FillPath(pDc
, pPath
);
2579 if (bRet
) bRet
= PATH_StrokePath(pDc
, pPath
);
2580 if (bRet
) PATH_EmptyPath(pPath
);
2582 PATH_UnlockPath( pPath
);
2589 NtGdiStrokePath(HDC hDC
)
2596 DPRINT("Enter %s\n", __FUNCTION__
);
2598 if (!(pDc
= DC_LockDc(hDC
)))
2600 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2603 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2606 DC_UnlockDc ( pDc
);
2610 pdcattr
= pDc
->pdcattr
;
2612 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2613 DC_vUpdateLineBrush(pDc
);
2615 bRet
= PATH_StrokePath(pDc
, pPath
);
2616 PATH_EmptyPath(pPath
);
2618 PATH_UnlockPath( pPath
);
2625 NtGdiWidenPath(HDC hDC
)
2628 PDC pdc
= DC_LockDc ( hDC
);
2631 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2634 Ret
= PATH_WidenPath(pdc
);
2635 DC_UnlockDc ( pdc
);