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
)
68 if (!hPath
) return FALSE
;
69 pPath
= PATH_LockPath( hPath
);
70 if (!pPath
) return FALSE
;
71 PATH_DestroyGdiPath( pPath
);
72 PATH_UnlockPath( pPath
);
73 PATH_FreeExtPathByHandle(hPath
);
80 IntGdiCloseFigure(PPATH pPath
)
82 ASSERT(pPath
->state
== PATH_Open
);
84 // FIXME: Shouldn't we draw a line to the beginning of the figure?
85 // Set PT_CLOSEFIGURE on the last entry and start a new stroke
86 if(pPath
->numEntriesUsed
)
88 pPath
->pFlags
[pPath
->numEntriesUsed
-1]|=PT_CLOSEFIGURE
;
89 pPath
->newStroke
=TRUE
;
99 PATH_FillPath( PDC dc
, PPATH pPath
)
101 INT mapMode
, graphicsMode
;
102 SIZE ptViewportExt
, ptWindowExt
;
103 POINTL ptViewportOrg
, ptWindowOrg
;
106 PDC_ATTR pdcattr
= dc
->pdcattr
;
108 if( pPath
->state
!= PATH_Closed
)
110 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
114 if( PATH_PathToRegion( pPath
, pdcattr
->jFillMode
, &hrgn
))
116 /* Since PaintRgn interprets the region as being in logical coordinates
117 * but the points we store for the path are already in device
118 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
119 * Using SaveDC to save information about the mapping mode / world
120 * transform would be easier but would require more overhead, especially
121 * now that SaveDC saves the current path.
124 /* Save the information about the old mapping mode */
125 mapMode
= pdcattr
->iMapMode
;
126 ptViewportExt
= pdcattr
->szlViewportExt
;
127 ptViewportOrg
= pdcattr
->ptlViewportOrg
;
128 ptWindowExt
= pdcattr
->szlWindowExt
;
129 ptWindowOrg
= pdcattr
->ptlWindowOrg
;
131 /* Save world transform
132 * NB: The Windows documentation on world transforms would lead one to
133 * believe that this has to be done only in GM_ADVANCED; however, my
134 * tests show that resetting the graphics mode to GM_COMPATIBLE does
135 * not reset the world transform.
137 MatrixS2XForm(&xform
, &dc
->dclevel
.mxWorldToPage
);
140 // IntGdiSetMapMode( dc, MM_TEXT );
141 // pdcattr->ptlViewportOrg.x = 0;
142 // pdcattr->ptlViewportOrg.y = 0;
143 // pdcattr->ptlWindowOrg.x = 0;
144 // pdcattr->ptlWindowOrg.y = 0;
146 graphicsMode
= pdcattr
->iGraphicsMode
;
147 // pdcattr->iGraphicsMode = GM_ADVANCED;
148 // IntGdiModifyWorldTransform( dc, &xform, MWT_IDENTITY );
149 // pdcattr->iGraphicsMode = graphicsMode;
151 /* Paint the region */
152 IntGdiPaintRgn( dc
, hrgn
);
153 GreDeleteObject( hrgn
);
154 /* Restore the old mapping mode */
155 // IntGdiSetMapMode( dc, mapMode );
156 // pdcattr->szlViewportExt = ptViewportExt;
157 // pdcattr->ptlViewportOrg = ptViewportOrg;
158 // pdcattr->szlWindowExt = ptWindowExt;
159 // pdcattr->ptlWindowOrg = ptWindowOrg;
161 /* Go to GM_ADVANCED temporarily to restore the world transform */
162 graphicsMode
= pdcattr
->iGraphicsMode
;
163 // pdcattr->iGraphicsMode = GM_ADVANCED;
164 // IntGdiModifyWorldTransform( dc, &xform, MWT_MAX+1 );
165 // pdcattr->iGraphicsMode = graphicsMode;
173 * Initializes the GdiPath structure.
177 PATH_InitGdiPath ( PPATH pPath
)
181 pPath
->state
=PATH_Null
;
184 pPath
->numEntriesUsed
=0;
185 pPath
->numEntriesAllocated
=0;
188 /* PATH_DestroyGdiPath
190 * Destroys a GdiPath structure (frees the memory in the arrays).
194 PATH_DestroyGdiPath ( PPATH pPath
)
198 if (pPath
->pPoints
) ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
199 if (pPath
->pFlags
) ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
202 /* PATH_AssignGdiPath
204 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
205 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
206 * not just the pointers. Since this means that the arrays in pPathDest may
207 * need to be resized, pPathDest should have been initialized using
208 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
209 * not a copy constructor).
210 * Returns TRUE if successful, else FALSE.
214 PATH_AssignGdiPath ( PPATH pPathDest
, const PPATH pPathSrc
)
216 ASSERT(pPathDest
!=NULL
&& pPathSrc
!=NULL
);
218 /* Make sure destination arrays are big enough */
219 if ( !PATH_ReserveEntries(pPathDest
, pPathSrc
->numEntriesUsed
) )
222 /* Perform the copy operation */
223 memcpy(pPathDest
->pPoints
, pPathSrc
->pPoints
,
224 sizeof(POINT
)*pPathSrc
->numEntriesUsed
);
225 memcpy(pPathDest
->pFlags
, pPathSrc
->pFlags
,
226 sizeof(BYTE
)*pPathSrc
->numEntriesUsed
);
228 pPathDest
->state
=pPathSrc
->state
;
229 pPathDest
->numEntriesUsed
=pPathSrc
->numEntriesUsed
;
230 pPathDest
->newStroke
=pPathSrc
->newStroke
;
236 * Should be called when a MoveTo is performed on a DC that has an
237 * open path. This starts a new stroke. Returns TRUE if successful, else
242 PATH_MoveTo ( PDC dc
)
244 PPATH pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
245 if (!pPath
) return FALSE
;
247 /* Check that path is open */
248 if ( pPath
->state
!= PATH_Open
)
250 PATH_UnlockPath( pPath
);
251 /* FIXME: Do we have to call SetLastError? */
254 /* Start a new stroke */
255 pPath
->newStroke
= TRUE
;
256 PATH_UnlockPath( pPath
);
262 * Should be called when a LineTo is performed on a DC that has an
263 * open path. This adds a PT_LINETO entry to the path (and possibly
264 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
265 * Returns TRUE if successful, else FALSE.
269 PATH_LineTo ( PDC dc
, INT x
, INT y
)
273 POINT point
, pointCurPos
;
275 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
276 if (!pPath
) return FALSE
;
278 /* Check that path is open */
279 if ( pPath
->state
!= PATH_Open
)
281 PATH_UnlockPath( pPath
);
285 /* Convert point to device coordinates */
288 CoordLPtoDP ( dc
, &point
);
290 /* Add a PT_MOVETO if necessary */
291 if ( pPath
->newStroke
)
293 pPath
->newStroke
= FALSE
;
294 IntGetCurrentPositionEx ( dc
, &pointCurPos
);
295 CoordLPtoDP ( dc
, &pointCurPos
);
296 if ( !PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
) )
298 PATH_UnlockPath( pPath
);
303 /* Add a PT_LINETO entry */
304 Ret
= PATH_AddEntry(pPath
, &point
, PT_LINETO
);
305 PATH_UnlockPath( pPath
);
311 * Should be called when a call to Rectangle is performed on a DC that has
312 * an open path. Returns TRUE if successful, else FALSE.
316 PATH_Rectangle ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
)
319 POINT corners
[2], pointTemp
;
322 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
323 if (!pPath
) return FALSE
;
325 /* Check that path is open */
326 if ( pPath
->state
!= PATH_Open
)
328 PATH_UnlockPath( pPath
);
332 /* Convert points to device coordinates */
337 IntLPtoDP ( dc
, corners
, 2 );
339 /* Make sure first corner is top left and second corner is bottom right */
340 if ( corners
[0].x
> corners
[1].x
)
343 corners
[0].x
=corners
[1].x
;
346 if ( corners
[0].y
> corners
[1].y
)
349 corners
[0].y
=corners
[1].y
;
353 /* In GM_COMPATIBLE, don't include bottom and right edges */
354 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
360 /* Close any previous figure */
361 IntGdiCloseFigure(pPath
);
363 /* Add four points to the path */
364 pointTemp
.x
=corners
[1].x
;
365 pointTemp
.y
=corners
[0].y
;
366 if ( !PATH_AddEntry(pPath
, &pointTemp
, PT_MOVETO
) )
368 PATH_UnlockPath( pPath
);
371 if ( !PATH_AddEntry(pPath
, corners
, PT_LINETO
) )
373 PATH_UnlockPath( pPath
);
376 pointTemp
.x
=corners
[0].x
;
377 pointTemp
.y
=corners
[1].y
;
378 if ( !PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
) )
380 PATH_UnlockPath( pPath
);
383 if ( !PATH_AddEntry(pPath
, corners
+1, PT_LINETO
) )
385 PATH_UnlockPath( pPath
);
389 /* Close the rectangle figure */
390 IntGdiCloseFigure(pPath
) ;
391 PATH_UnlockPath( pPath
);
397 * Should be called when a call to RoundRect is performed on a DC that has
398 * an open path. Returns TRUE if successful, else FALSE.
400 * FIXME: it adds the same entries to the path as windows does, but there
401 * is an error in the bezier drawing code so that there are small pixel-size
402 * gaps when the resulting path is drawn by StrokePath()
404 BOOL FASTCALL
PATH_RoundRect(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
, INT ell_width
, INT ell_height
)
407 POINT corners
[2], pointTemp
;
408 FLOAT_POINT ellCorners
[2];
410 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
411 if (!pPath
) return FALSE
;
413 /* Check that path is open */
414 if(pPath
->state
!=PATH_Open
)
416 PATH_UnlockPath( pPath
);
420 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
422 PATH_UnlockPath( pPath
);
426 /* Add points to the roundrect path */
427 ellCorners
[0].x
= corners
[1].x
-ell_width
;
428 ellCorners
[0].y
= corners
[0].y
;
429 ellCorners
[1].x
= corners
[1].x
;
430 ellCorners
[1].y
= corners
[0].y
+ell_height
;
431 if(!PATH_DoArcPart(pPath
, ellCorners
, 0, -M_PI_2
, PT_MOVETO
))
433 PATH_UnlockPath( pPath
);
436 pointTemp
.x
= corners
[0].x
+ell_width
/2;
437 pointTemp
.y
= corners
[0].y
;
438 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
440 PATH_UnlockPath( pPath
);
443 ellCorners
[0].x
= corners
[0].x
;
444 ellCorners
[1].x
= corners
[0].x
+ell_width
;
445 if(!PATH_DoArcPart(pPath
, ellCorners
, -M_PI_2
, -M_PI
, FALSE
))
447 PATH_UnlockPath( pPath
);
450 pointTemp
.x
= corners
[0].x
;
451 pointTemp
.y
= corners
[1].y
-ell_height
/2;
452 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
454 PATH_UnlockPath( pPath
);
457 ellCorners
[0].y
= corners
[1].y
-ell_height
;
458 ellCorners
[1].y
= corners
[1].y
;
459 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI
, M_PI_2
, FALSE
))
461 PATH_UnlockPath( pPath
);
464 pointTemp
.x
= corners
[1].x
-ell_width
/2;
465 pointTemp
.y
= corners
[1].y
;
466 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
468 PATH_UnlockPath( pPath
);
471 ellCorners
[0].x
= corners
[1].x
-ell_width
;
472 ellCorners
[1].x
= corners
[1].x
;
473 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI_2
, 0, FALSE
))
475 PATH_UnlockPath( pPath
);
479 IntGdiCloseFigure(pPath
);
480 PATH_UnlockPath( pPath
);
486 * Should be called when a call to Ellipse is performed on a DC that has
487 * an open path. This adds four Bezier splines representing the ellipse
488 * to the path. Returns TRUE if successful, else FALSE.
492 PATH_Ellipse ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
)
495 /* TODO: This should probably be revised to call PATH_AngleArc */
496 /* (once it exists) */
497 BOOL Ret
= PATH_Arc ( dc
, x1
, y1
, x2
, y2
, x1
, (y1
+y2
)/2, x1
, (y1
+y2
)/2, GdiTypeArc
);
500 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
501 if (!pPath
) return FALSE
;
502 IntGdiCloseFigure(pPath
);
503 PATH_UnlockPath( pPath
);
510 * Should be called when a call to Arc is performed on a DC that has
511 * an open path. This adds up to five Bezier splines representing the arc
512 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
513 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
514 * -1 we add 1 extra line from the current DC position to the starting position
515 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
520 PATH_Arc ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
,
521 INT xStart
, INT yStart
, INT xEnd
, INT yEnd
, INT lines
)
523 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
=0.0;
524 /* Initialize angleEndQuadrant to silence gcc's warning */
526 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
527 POINT centre
, pointCurPos
;
528 BOOL start
, end
, Ret
= TRUE
;
533 /* FIXME: This function should check for all possible error returns */
534 /* FIXME: Do we have to respect newStroke? */
538 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
539 if (!pPath
) return FALSE
;
541 clockwise
= ((dc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
543 /* Check that path is open */
544 if ( pPath
->state
!= PATH_Open
)
550 /* Check for zero height / width */
551 /* FIXME: Only in GM_COMPATIBLE? */
552 if ( x1
==x2
|| y1
==y2
)
557 /* Convert points to device coordinates */
558 corners
[0].x
=(FLOAT
)x1
;
559 corners
[0].y
=(FLOAT
)y1
;
560 corners
[1].x
=(FLOAT
)x2
;
561 corners
[1].y
=(FLOAT
)y2
;
562 pointStart
.x
=(FLOAT
)xStart
;
563 pointStart
.y
=(FLOAT
)yStart
;
564 pointEnd
.x
=(FLOAT
)xEnd
;
565 pointEnd
.y
=(FLOAT
)yEnd
;
566 INTERNAL_LPTODP_FLOAT(dc
, corners
);
567 INTERNAL_LPTODP_FLOAT(dc
, corners
+1);
568 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
);
569 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
);
571 /* Make sure first corner is top left and second corner is bottom right */
572 if ( corners
[0].x
> corners
[1].x
)
575 corners
[0].x
=corners
[1].x
;
578 if ( corners
[0].y
> corners
[1].y
)
581 corners
[0].y
=corners
[1].y
;
585 /* Compute start and end angle */
586 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
587 angleStart
=atan2(y
, x
);
588 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
589 angleEnd
=atan2(y
, x
);
591 /* Make sure the end angle is "on the right side" of the start angle */
594 if ( angleEnd
<= angleStart
)
597 ASSERT(angleEnd
>=angleStart
);
602 if(angleEnd
>=angleStart
)
605 ASSERT(angleEnd
<=angleStart
);
609 /* In GM_COMPATIBLE, don't include bottom and right edges */
610 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
616 /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
617 if(lines
==GdiTypeArcTo
&& pPath
->newStroke
) // -1
619 pPath
->newStroke
=FALSE
;
620 IntGetCurrentPositionEx ( dc
, &pointCurPos
);
621 CoordLPtoDP(dc
, &pointCurPos
);
622 if(!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
629 /* Add the arc to the path with one Bezier spline per quadrant that the
635 /* Determine the start and end angles for this quadrant */
638 angleStartQuadrant
=angleStart
;
640 angleEndQuadrant
=(floor(angleStart
/M_PI_2
)+1.0)*M_PI_2
;
642 angleEndQuadrant
=(ceil(angleStart
/M_PI_2
)-1.0)*M_PI_2
;
646 angleStartQuadrant
=angleEndQuadrant
;
648 angleEndQuadrant
+=M_PI_2
;
650 angleEndQuadrant
-=M_PI_2
;
653 /* Have we reached the last part of the arc? */
654 if ( (clockwise
&& angleEnd
<angleEndQuadrant
)
655 || (!clockwise
&& angleEnd
>angleEndQuadrant
)
658 /* Adjust the end angle for this quadrant */
659 angleEndQuadrant
= angleEnd
;
663 /* Add the Bezier spline to the path */
664 PATH_DoArcPart ( pPath
, corners
, angleStartQuadrant
, angleEndQuadrant
,
665 start
? (lines
==GdiTypeArcTo
? PT_LINETO
: PT_MOVETO
) : FALSE
); // -1
669 /* chord: close figure. pie: add line and close figure */
670 if (lines
==GdiTypeChord
) // 1
672 IntGdiCloseFigure(pPath
);
674 else if (lines
==GdiTypePie
) // 2
676 centre
.x
= (corners
[0].x
+corners
[1].x
)/2;
677 centre
.y
= (corners
[0].y
+corners
[1].y
)/2;
678 if(!PATH_AddEntry(pPath
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
682 PATH_UnlockPath( pPath
);
688 PATH_PolyBezierTo ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
698 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
699 if (!pPath
) return FALSE
;
701 /* Check that path is open */
702 if ( pPath
->state
!= PATH_Open
)
704 PATH_UnlockPath( pPath
);
708 /* Add a PT_MOVETO if necessary */
709 if ( pPath
->newStroke
)
711 pPath
->newStroke
=FALSE
;
712 IntGetCurrentPositionEx ( dc
, &pt
);
713 CoordLPtoDP ( dc
, &pt
);
714 if ( !PATH_AddEntry(pPath
, &pt
, PT_MOVETO
) )
716 PATH_UnlockPath( pPath
);
721 for(i
= 0; i
< cbPoints
; i
++)
724 CoordLPtoDP ( dc
, &pt
);
725 PATH_AddEntry(pPath
, &pt
, PT_BEZIERTO
);
727 PATH_UnlockPath( pPath
);
733 PATH_PolyBezier ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
743 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
744 if (!pPath
) return FALSE
;
746 /* Check that path is open */
747 if ( pPath
->state
!= PATH_Open
)
749 PATH_UnlockPath( pPath
);
753 for ( i
= 0; i
< cbPoints
; i
++ )
756 CoordLPtoDP ( dc
, &pt
);
757 PATH_AddEntry ( pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_BEZIERTO
);
759 PATH_UnlockPath( pPath
);
765 PATH_Polyline ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
775 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
776 if (!pPath
) return FALSE
;
778 /* Check that path is open */
779 if ( pPath
->state
!= PATH_Open
)
781 PATH_UnlockPath( pPath
);
784 for ( i
= 0; i
< cbPoints
; i
++ )
787 CoordLPtoDP ( dc
, &pt
);
788 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_LINETO
);
790 PATH_UnlockPath( pPath
);
796 PATH_PolylineTo ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
806 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
807 if (!pPath
) return FALSE
;
809 /* Check that path is open */
810 if ( pPath
->state
!= PATH_Open
)
812 PATH_UnlockPath( pPath
);
816 /* Add a PT_MOVETO if necessary */
817 if ( pPath
->newStroke
)
819 pPath
->newStroke
= FALSE
;
820 IntGetCurrentPositionEx ( dc
, &pt
);
821 CoordLPtoDP ( dc
, &pt
);
822 if ( !PATH_AddEntry(pPath
, &pt
, PT_MOVETO
) )
824 PATH_UnlockPath( pPath
);
829 for(i
= 0; i
< cbPoints
; i
++)
832 CoordLPtoDP ( dc
, &pt
);
833 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
835 PATH_UnlockPath( pPath
);
842 PATH_Polygon ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
851 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
852 if (!pPath
) return FALSE
;
854 /* Check that path is open */
855 if ( pPath
->state
!= PATH_Open
)
857 PATH_UnlockPath( pPath
);
861 for(i
= 0; i
< cbPoints
; i
++)
864 CoordLPtoDP ( dc
, &pt
);
865 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
:
866 ((i
== cbPoints
-1) ? PT_LINETO
| PT_CLOSEFIGURE
:
869 PATH_UnlockPath( pPath
);
875 PATH_PolyPolygon ( PDC dc
, const POINT
* pts
, const INT
* counts
, UINT polygons
)
878 ULONG poly
, point
, i
;
886 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
887 if (!pPath
) return FALSE
;
889 /* Check that path is open */
890 if ( pPath
->state
!= PATH_Open
)
892 PATH_UnlockPath( pPath
);
896 for(i
= 0, poly
= 0; poly
< polygons
; poly
++)
898 for(point
= 0; point
< (ULONG
) counts
[poly
]; point
++, i
++)
901 CoordLPtoDP ( dc
, &pt
);
902 if(point
== 0) startpt
= pt
;
903 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
905 /* win98 adds an extra line to close the figure for some reason */
906 PATH_AddEntry(pPath
, &startpt
, PT_LINETO
| PT_CLOSEFIGURE
);
908 PATH_UnlockPath( pPath
);
914 PATH_PolyPolyline ( PDC dc
, const POINT
* pts
, const DWORD
* counts
, DWORD polylines
)
917 ULONG poly
, point
, i
;
923 ASSERT ( polylines
);
925 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
926 if (!pPath
) return FALSE
;
928 /* Check that path is open */
929 if ( pPath
->state
!= PATH_Open
)
931 PATH_UnlockPath( pPath
);
935 for(i
= 0, poly
= 0; poly
< polylines
; poly
++)
937 for(point
= 0; point
< counts
[poly
]; point
++, i
++)
940 CoordLPtoDP ( dc
, &pt
);
941 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
944 PATH_UnlockPath( pPath
);
951 * Helper function for PATH_RoundRect() and PATH_Rectangle()
953 BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
)
956 PDC_ATTR pdcattr
= dc
->pdcattr
;
958 /* Convert points to device coordinates */
963 CoordLPtoDP(dc
, &corners
[0]);
964 CoordLPtoDP(dc
, &corners
[1]);
966 /* Make sure first corner is top left and second corner is bottom right */
967 if(corners
[0].x
>corners
[1].x
)
970 corners
[0].x
=corners
[1].x
;
973 if(corners
[0].y
>corners
[1].y
)
976 corners
[0].y
=corners
[1].y
;
980 /* In GM_COMPATIBLE, don't include bottom and right edges */
981 if(pdcattr
->iGraphicsMode
==GM_COMPATIBLE
)
991 /* PATH_AddFlatBezier
996 PATH_AddFlatBezier ( PPATH pPath
, POINT
*pt
, BOOL closed
)
1001 pts
= GDI_Bezier( pt
, 4, &no
);
1002 if ( !pts
) return FALSE
;
1004 for(i
= 1; i
< no
; i
++)
1005 PATH_AddEntry(pPath
, &pts
[i
], (i
== no
-1 && closed
) ? PT_LINETO
| PT_CLOSEFIGURE
: PT_LINETO
);
1007 ExFreePoolWithTag(pts
, TAG_BEZIER
);
1013 * Replaces Beziers with line segments
1018 PATH_FlattenPath(PPATH pPath
)
1023 RtlZeroMemory(&newPath
, sizeof(newPath
));
1024 newPath
.state
= PATH_Open
;
1025 for(srcpt
= 0; srcpt
< pPath
->numEntriesUsed
; srcpt
++) {
1026 switch(pPath
->pFlags
[srcpt
] & ~PT_CLOSEFIGURE
) {
1029 PATH_AddEntry(&newPath
, &pPath
->pPoints
[srcpt
], pPath
->pFlags
[srcpt
]);
1032 PATH_AddFlatBezier(&newPath
, &pPath
->pPoints
[srcpt
-1], pPath
->pFlags
[srcpt
+2] & PT_CLOSEFIGURE
);
1037 newPath
.state
= PATH_Closed
;
1038 PATH_AssignGdiPath(pPath
, &newPath
);
1039 PATH_EmptyPath(&newPath
);
1044 /* PATH_PathToRegion
1046 * Creates a region from the specified path using the specified polygon
1047 * filling mode. The path is left unchanged. A handle to the region that
1048 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1049 * error occurs, SetLastError is called with the appropriate value and
1050 * FALSE is returned.
1054 PATH_PathToRegion ( PPATH pPath
, INT nPolyFillMode
, HRGN
*pHrgn
)
1056 int numStrokes
, iStroke
, i
;
1057 PULONG pNumPointsInStroke
;
1060 ASSERT(pPath
!=NULL
);
1061 ASSERT(pHrgn
!=NULL
);
1063 PATH_FlattenPath ( pPath
);
1065 /* FIXME: What happens when number of points is zero? */
1067 /* First pass: Find out how many strokes there are in the path */
1068 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1070 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1071 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1074 /* Allocate memory for number-of-points-in-stroke array */
1075 pNumPointsInStroke
= ExAllocatePoolWithTag(PagedPool
, sizeof(ULONG
) * numStrokes
, TAG_PATH
);
1076 if(!pNumPointsInStroke
)
1078 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1082 /* Second pass: remember number of points in each polygon */
1083 iStroke
=-1; /* Will get incremented to 0 at beginning of first stroke */
1084 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1086 /* Is this the beginning of a new stroke? */
1087 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1090 pNumPointsInStroke
[iStroke
]=0;
1093 pNumPointsInStroke
[iStroke
]++;
1096 /* Create a region from the strokes */
1097 hrgn
= IntCreatePolyPolygonRgn( pPath
->pPoints
,
1103 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1107 /* Free memory for number-of-points-in-stroke array */
1108 ExFreePoolWithTag(pNumPointsInStroke
, TAG_PATH
);
1117 * Removes all entries from the path and sets the path state to PATH_Null.
1121 PATH_EmptyPath ( PPATH pPath
)
1123 ASSERT(pPath
!=NULL
);
1125 pPath
->state
=PATH_Null
;
1126 pPath
->numEntriesUsed
=0;
1131 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1132 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1133 * successful, FALSE otherwise (e.g. if not enough memory was available).
1137 PATH_AddEntry ( PPATH pPath
, const POINT
*pPoint
, BYTE flags
)
1139 ASSERT(pPath
!=NULL
);
1141 /* FIXME: If newStroke is true, perhaps we want to check that we're
1142 * getting a PT_MOVETO
1145 /* Check that path is open */
1146 if ( pPath
->state
!= PATH_Open
)
1149 /* Reserve enough memory for an extra path entry */
1150 if ( !PATH_ReserveEntries(pPath
, pPath
->numEntriesUsed
+1) )
1153 /* Store information in path entry */
1154 pPath
->pPoints
[pPath
->numEntriesUsed
]=*pPoint
;
1155 pPath
->pFlags
[pPath
->numEntriesUsed
]=flags
;
1157 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1158 if((flags
& PT_CLOSEFIGURE
) == PT_CLOSEFIGURE
)
1159 pPath
->newStroke
=TRUE
;
1161 /* Increment entry count */
1162 pPath
->numEntriesUsed
++;
1167 /* PATH_ReserveEntries
1169 * Ensures that at least "numEntries" entries (for points and flags) have
1170 * been allocated; allocates larger arrays and copies the existing entries
1171 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1175 PATH_ReserveEntries ( PPATH pPath
, INT numEntries
)
1177 INT numEntriesToAllocate
;
1181 ASSERT(pPath
!=NULL
);
1182 ASSERT(numEntries
>=0);
1184 /* Do we have to allocate more memory? */
1185 if(numEntries
> pPath
->numEntriesAllocated
)
1187 /* Find number of entries to allocate. We let the size of the array
1188 * grow exponentially, since that will guarantee linear time
1190 if(pPath
->numEntriesAllocated
)
1192 numEntriesToAllocate
=pPath
->numEntriesAllocated
;
1193 while(numEntriesToAllocate
<numEntries
)
1194 numEntriesToAllocate
=numEntriesToAllocate
*GROW_FACTOR_NUMER
/GROW_FACTOR_DENOM
;
1196 numEntriesToAllocate
=numEntries
;
1198 /* Allocate new arrays */
1199 pPointsNew
=(POINT
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(POINT
), TAG_PATH
);
1202 pFlagsNew
=(BYTE
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(BYTE
), TAG_PATH
);
1205 ExFreePoolWithTag(pPointsNew
, TAG_PATH
);
1209 /* Copy old arrays to new arrays and discard old arrays */
1212 ASSERT(pPath
->pFlags
);
1214 memcpy(pPointsNew
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
1215 memcpy(pFlagsNew
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
1217 ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
1218 ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
1220 pPath
->pPoints
=pPointsNew
;
1221 pPath
->pFlags
=pFlagsNew
;
1222 pPath
->numEntriesAllocated
=numEntriesToAllocate
;
1230 * Creates a Bezier spline that corresponds to part of an arc and appends the
1231 * corresponding points to the path. The start and end angles are passed in
1232 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1233 * at most. If "startEntryType" is non-zero, an entry of that type for the first
1234 * control point is added to the path; otherwise, it is assumed that the current
1235 * position is equal to the first control point.
1239 PATH_DoArcPart ( PPATH pPath
, FLOAT_POINT corners
[],
1240 double angleStart
, double angleEnd
, BYTE startEntryType
)
1242 double halfAngle
, a
;
1243 double xNorm
[4], yNorm
[4];
1247 ASSERT(fabs(angleEnd
-angleStart
)<=M_PI_2
);
1249 /* FIXME: Is there an easier way of computing this? */
1251 /* Compute control points */
1252 halfAngle
=(angleEnd
-angleStart
)/2.0;
1253 if(fabs(halfAngle
)>1e-8)
1255 a
=4.0/3.0*(1-cos(halfAngle
))/sin(halfAngle
);
1256 xNorm
[0]=cos(angleStart
);
1257 yNorm
[0]=sin(angleStart
);
1258 xNorm
[1]=xNorm
[0] - a
*yNorm
[0];
1259 yNorm
[1]=yNorm
[0] + a
*xNorm
[0];
1260 xNorm
[3]=cos(angleEnd
);
1261 yNorm
[3]=sin(angleEnd
);
1262 xNorm
[2]=xNorm
[3] + a
*yNorm
[3];
1263 yNorm
[2]=yNorm
[3] - a
*xNorm
[3];
1267 xNorm
[i
]=cos(angleStart
);
1268 yNorm
[i
]=sin(angleStart
);
1271 /* Add starting point to path if desired */
1274 PATH_ScaleNormalizedPoint(corners
, xNorm
[0], yNorm
[0], &point
);
1275 if(!PATH_AddEntry(pPath
, &point
, startEntryType
))
1279 /* Add remaining control points */
1282 PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &point
);
1283 if(!PATH_AddEntry(pPath
, &point
, PT_BEZIERTO
))
1290 /* PATH_ScaleNormalizedPoint
1292 * Scales a normalized point (x, y) with respect to the box whose corners are
1293 * passed in "corners". The point is stored in "*pPoint". The normalized
1294 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1295 * (1.0, 1.0) correspond to corners[1].
1299 PATH_ScaleNormalizedPoint ( FLOAT_POINT corners
[], double x
,
1300 double y
, POINT
*pPoint
)
1304 pPoint
->x
=GDI_ROUND( (double)corners
[0].x
+ (double)(corners
[1].x
-corners
[0].x
)*0.5*(x
+1.0) );
1305 pPoint
->y
=GDI_ROUND( (double)corners
[0].y
+ (double)(corners
[1].y
-corners
[0].y
)*0.5*(y
+1.0) );
1308 /* PATH_NormalizePoint
1310 * Normalizes a point with respect to the box whose corners are passed in
1311 * corners. The normalized coordinates are stored in *pX and *pY.
1315 PATH_NormalizePoint ( FLOAT_POINT corners
[],
1316 const FLOAT_POINT
*pPoint
,
1317 double *pX
, double *pY
)
1323 *pX
=(double)(pPoint
->x
-corners
[0].x
)/(double)(corners
[1].x
-corners
[0].x
) * 2.0 - 1.0;
1324 *pY
=(double)(pPoint
->y
-corners
[0].y
)/(double)(corners
[1].y
-corners
[0].y
) * 2.0 - 1.0;
1328 BOOL FASTCALL
PATH_StrokePath(DC
*dc
, PPATH pPath
)
1332 INT nLinePts
, nAlloc
;
1333 POINT
*pLinePts
= NULL
;
1334 POINT ptViewportOrg
, ptWindowOrg
;
1335 SIZE szViewportExt
, szWindowExt
;
1336 DWORD mapMode
, graphicsMode
;
1338 PDC_ATTR pdcattr
= dc
->pdcattr
;
1340 DPRINT("Enter %s\n", __FUNCTION__
);
1342 if (pPath
->state
!= PATH_Closed
)
1345 /* Save the mapping mode info */
1346 mapMode
= pdcattr
->iMapMode
;
1348 DC_vUpdateViewportExt(dc
);
1349 szViewportExt
= dc
->pdcattr
->szlViewportExt
;
1350 ptViewportOrg
= dc
->pdcattr
->ptlViewportOrg
;
1351 szWindowExt
= dc
->pdcattr
->szlWindowExt
;
1352 ptWindowOrg
= dc
->pdcattr
->ptlWindowOrg
;
1354 MatrixS2XForm(&xform
, &dc
->dclevel
.mxWorldToPage
);
1357 pdcattr
->iMapMode
= MM_TEXT
;
1358 pdcattr
->ptlViewportOrg
.x
= 0;
1359 pdcattr
->ptlViewportOrg
.y
= 0;
1360 pdcattr
->ptlWindowOrg
.x
= 0;
1361 pdcattr
->ptlWindowOrg
.y
= 0;
1362 graphicsMode
= pdcattr
->iGraphicsMode
;
1363 pdcattr
->iGraphicsMode
= GM_ADVANCED
;
1364 IntGdiModifyWorldTransform(dc
, &xform
, MWT_IDENTITY
);
1365 pdcattr
->iGraphicsMode
= graphicsMode
;
1367 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1368 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1369 * space in case we get one to keep the number of reallocations small. */
1370 nAlloc
= pPath
->numEntriesUsed
+ 1 + 300;
1371 pLinePts
= ExAllocatePoolWithTag(PagedPool
, nAlloc
* sizeof(POINT
), TAG_PATH
);
1374 DPRINT1("Can't allocate pool!\n");
1375 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1380 for(i
= 0; i
< pPath
->numEntriesUsed
; i
++)
1382 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
))
1383 && (pPath
->pFlags
[i
] != PT_MOVETO
))
1385 DPRINT1("Expected PT_MOVETO %s, got path flag %d\n",
1386 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1387 (INT
)pPath
->pFlags
[i
]);
1391 switch(pPath
->pFlags
[i
])
1394 DPRINT("Got PT_MOVETO (%ld, %ld)\n",
1395 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1396 if(nLinePts
>= 2) IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1398 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1401 case (PT_LINETO
| PT_CLOSEFIGURE
):
1402 DPRINT("Got PT_LINETO (%ld, %ld)\n",
1403 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1404 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1407 DPRINT("Got PT_BEZIERTO\n");
1408 if(pPath
->pFlags
[i
+1] != PT_BEZIERTO
||
1409 (pPath
->pFlags
[i
+2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
)
1411 DPRINT1("Path didn't contain 3 successive PT_BEZIERTOs\n");
1417 INT nBzrPts
, nMinAlloc
;
1418 POINT
*pBzrPts
= GDI_Bezier(&pPath
->pPoints
[i
-1], 4, &nBzrPts
);
1419 /* Make sure we have allocated enough memory for the lines of
1420 * this bezier and the rest of the path, assuming we won't get
1421 * another one (since we won't reallocate again then). */
1422 nMinAlloc
= nLinePts
+ (pPath
->numEntriesUsed
- i
) + nBzrPts
;
1423 if(nAlloc
< nMinAlloc
)
1425 // Reallocate memory
1427 POINT
*Realloc
= NULL
;
1428 nAlloc
= nMinAlloc
* 2;
1430 Realloc
= ExAllocatePoolWithTag(PagedPool
,
1431 nAlloc
* sizeof(POINT
),
1436 DPRINT1("Can't allocate pool!\n");
1440 memcpy(Realloc
, pLinePts
, nLinePts
*sizeof(POINT
));
1441 ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1444 memcpy(&pLinePts
[nLinePts
], &pBzrPts
[1], (nBzrPts
- 1) * sizeof(POINT
));
1445 nLinePts
+= nBzrPts
- 1;
1446 ExFreePoolWithTag(pBzrPts
, TAG_BEZIER
);
1451 DPRINT1("Got path flag %d (not supported)\n", (INT
)pPath
->pFlags
[i
]);
1455 if(pPath
->pFlags
[i
] & PT_CLOSEFIGURE
)
1457 pLinePts
[nLinePts
++] = pLinePts
[0];
1461 IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1466 if(pLinePts
) ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1468 /* Restore the old mapping mode */
1469 pdcattr
->iMapMode
= mapMode
;
1470 pdcattr
->szlWindowExt
.cx
= szWindowExt
.cx
;
1471 pdcattr
->szlWindowExt
.cy
= szWindowExt
.cy
;
1472 pdcattr
->ptlWindowOrg
.x
= ptWindowOrg
.x
;
1473 pdcattr
->ptlWindowOrg
.y
= ptWindowOrg
.y
;
1475 pdcattr
->szlViewportExt
.cx
= szViewportExt
.cx
;
1476 pdcattr
->szlViewportExt
.cy
= szViewportExt
.cy
;
1477 pdcattr
->ptlViewportOrg
.x
= ptViewportOrg
.x
;
1478 pdcattr
->ptlViewportOrg
.y
= ptViewportOrg
.y
;
1480 /* Restore the world transform */
1481 XForm2MatrixS(&dc
->dclevel
.mxWorldToPage
, &xform
);
1483 /* If we've moved the current point then get its new position
1484 which will be in device (MM_TEXT) co-ords, convert it to
1485 logical co-ords and re-set it. This basically updates
1486 dc->CurPosX|Y so that their values are in the correct mapping
1492 IntGetCurrentPositionEx(dc
, &pt
);
1493 IntDPtoLP(dc
, &pt
, 1);
1494 IntGdiMoveToEx(dc
, pt
.x
, pt
.y
, NULL
);
1496 DPRINT("Leave %s, ret=%d\n", __FUNCTION__
, ret
);
1500 #define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1505 PATH_WidenPath(DC
*dc
)
1507 INT i
, j
, numStrokes
, numOldStrokes
, penWidth
, penWidthIn
, penWidthOut
, size
, penStyle
;
1509 PPATH pPath
, pNewPath
, *pStrokes
, *pOldStrokes
, pUpPath
, pDownPath
;
1511 DWORD obj_type
, joint
, endcap
, penType
;
1512 PDC_ATTR pdcattr
= dc
->pdcattr
;
1514 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
1515 if (!pPath
) return FALSE
;
1517 if(pPath
->state
== PATH_Open
)
1519 PATH_UnlockPath( pPath
);
1520 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1524 PATH_FlattenPath(pPath
);
1526 size
= IntGdiGetObject( pdcattr
->hpen
, 0, NULL
);
1529 PATH_UnlockPath( pPath
);
1530 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1534 elp
= ExAllocatePoolWithTag(PagedPool
, size
, TAG_PATH
);
1535 (VOID
) IntGdiGetObject( pdcattr
->hpen
, size
, elp
);
1537 obj_type
= GDIOBJ_GetObjectType(pdcattr
->hpen
);
1538 if(obj_type
== GDI_OBJECT_TYPE_PEN
)
1540 penStyle
= ((LOGPEN
*)elp
)->lopnStyle
;
1542 else if(obj_type
== GDI_OBJECT_TYPE_EXTPEN
)
1544 penStyle
= elp
->elpPenStyle
;
1548 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1549 ExFreePoolWithTag(elp
, TAG_PATH
);
1550 PATH_UnlockPath( pPath
);
1554 penWidth
= elp
->elpWidth
;
1555 ExFreePoolWithTag(elp
, TAG_PATH
);
1557 endcap
= (PS_ENDCAP_MASK
& penStyle
);
1558 joint
= (PS_JOIN_MASK
& penStyle
);
1559 penType
= (PS_TYPE_MASK
& penStyle
);
1561 /* The function cannot apply to cosmetic pens */
1562 if(obj_type
== GDI_OBJECT_TYPE_EXTPEN
&& penType
== PS_COSMETIC
)
1564 PATH_UnlockPath( pPath
);
1565 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1569 penWidthIn
= penWidth
/ 2;
1570 penWidthOut
= penWidth
/ 2;
1571 if(penWidthIn
+ penWidthOut
< penWidth
)
1577 pStrokes
= ExAllocatePoolWithTag(PagedPool
, sizeof(PPATH
), TAG_PATH
);
1578 pStrokes
[0] = ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1579 PATH_InitGdiPath(pStrokes
[0]);
1580 pStrokes
[0]->pFlags
= ExAllocatePoolWithTag(PagedPool
, pPath
->numEntriesUsed
* sizeof(INT
), TAG_PATH
);
1581 pStrokes
[0]->pPoints
= ExAllocatePoolWithTag(PagedPool
, pPath
->numEntriesUsed
* sizeof(POINT
), TAG_PATH
);
1582 pStrokes
[0]->numEntriesUsed
= 0;
1584 for(i
= 0, j
= 0; i
< pPath
->numEntriesUsed
; i
++, j
++)
1587 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
)) &&
1588 (pPath
->pFlags
[i
] != PT_MOVETO
))
1590 DPRINT1("Expected PT_MOVETO %s, got path flag %c\n",
1591 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1595 switch(pPath
->pFlags
[i
])
1600 pStrokes
[numStrokes
- 1]->state
= PATH_Closed
;
1604 pOldStrokes
= pStrokes
; // Save old pointer.
1605 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1606 RtlCopyMemory(pStrokes
, pOldStrokes
, numOldStrokes
* sizeof(PPATH
));
1607 numOldStrokes
= numStrokes
; // Save orig count.
1608 ExFreePoolWithTag(pOldStrokes
, TAG_PATH
); // Free old pointer.
1609 pStrokes
[numStrokes
- 1] = ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1611 PATH_InitGdiPath(pStrokes
[numStrokes
- 1]);
1612 pStrokes
[numStrokes
- 1]->state
= PATH_Open
;
1614 case (PT_LINETO
| PT_CLOSEFIGURE
):
1615 point
.x
= pPath
->pPoints
[i
].x
;
1616 point
.y
= pPath
->pPoints
[i
].y
;
1617 PATH_AddEntry(pStrokes
[numStrokes
- 1], &point
, pPath
->pFlags
[i
]);
1620 /* should never happen because of the FlattenPath call */
1621 DPRINT1("Should never happen\n");
1624 DPRINT1("Got path flag %c\n", pPath
->pFlags
[i
]);
1629 pNewPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1630 PATH_InitGdiPath(pNewPath
);
1631 pNewPath
->state
= PATH_Open
;
1633 for(i
= 0; i
< numStrokes
; i
++)
1635 pUpPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1636 PATH_InitGdiPath(pUpPath
);
1637 pUpPath
->state
= PATH_Open
;
1638 pDownPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1639 PATH_InitGdiPath(pDownPath
);
1640 pDownPath
->state
= PATH_Open
;
1642 for(j
= 0; j
< pStrokes
[i
]->numEntriesUsed
; j
++)
1644 /* Beginning or end of the path if not closed */
1645 if((!(pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) && (j
== 0 || j
== pStrokes
[i
]->numEntriesUsed
- 1) )
1647 /* Compute segment angle */
1648 double xo
, yo
, xa
, ya
, theta
;
1650 FLOAT_POINT corners
[2];
1653 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1654 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1655 xa
= pStrokes
[i
]->pPoints
[1].x
;
1656 ya
= pStrokes
[i
]->pPoints
[1].y
;
1660 xa
= pStrokes
[i
]->pPoints
[j
- 1].x
;
1661 ya
= pStrokes
[i
]->pPoints
[j
- 1].y
;
1662 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1663 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1665 theta
= atan2( ya
- yo
, xa
- xo
);
1668 case PS_ENDCAP_SQUARE
:
1669 pt
.x
= xo
+ round(sqrt(2) * penWidthOut
* cos(M_PI_4
+ theta
));
1670 pt
.y
= yo
+ round(sqrt(2) * penWidthOut
* sin(M_PI_4
+ theta
));
1671 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
) );
1672 pt
.x
= xo
+ round(sqrt(2) * penWidthIn
* cos(- M_PI_4
+ theta
));
1673 pt
.y
= yo
+ round(sqrt(2) * penWidthIn
* sin(- M_PI_4
+ theta
));
1674 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1676 case PS_ENDCAP_FLAT
:
1677 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1678 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1679 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1680 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1681 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1682 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1684 case PS_ENDCAP_ROUND
:
1686 corners
[0].x
= xo
- penWidthIn
;
1687 corners
[0].y
= yo
- penWidthIn
;
1688 corners
[1].x
= xo
+ penWidthOut
;
1689 corners
[1].y
= yo
+ penWidthOut
;
1690 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI_2
, theta
+ 3 * M_PI_4
, (j
== 0 ? PT_MOVETO
: FALSE
));
1691 PATH_DoArcPart(pUpPath
,corners
, theta
+ 3 * M_PI_4
, theta
+ M_PI
, FALSE
);
1692 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI
, theta
+ 5 * M_PI_4
, FALSE
);
1693 PATH_DoArcPart(pUpPath
,corners
, theta
+ 5 * M_PI_4
, theta
+ 3 * M_PI_2
, FALSE
);
1697 /* Corpse of the path */
1702 double xa
, ya
, xb
, yb
, xo
, yo
;
1703 double alpha
, theta
, miterWidth
;
1704 DWORD _joint
= joint
;
1706 PPATH pInsidePath
, pOutsidePath
;
1707 if(j
> 0 && j
< pStrokes
[i
]->numEntriesUsed
- 1)
1714 previous
= pStrokes
[i
]->numEntriesUsed
- 1;
1722 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1723 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1724 xa
= pStrokes
[i
]->pPoints
[previous
].x
;
1725 ya
= pStrokes
[i
]->pPoints
[previous
].y
;
1726 xb
= pStrokes
[i
]->pPoints
[next
].x
;
1727 yb
= pStrokes
[i
]->pPoints
[next
].y
;
1728 theta
= atan2( yo
- ya
, xo
- xa
);
1729 alpha
= atan2( yb
- yo
, xb
- xo
) - theta
;
1730 if (alpha
> 0) alpha
-= M_PI
;
1732 if(_joint
== PS_JOIN_MITER
&& dc
->dclevel
.laPath
.eMiterLimit
< fabs(1 / sin(alpha
/2)))
1734 _joint
= PS_JOIN_BEVEL
;
1738 pInsidePath
= pUpPath
;
1739 pOutsidePath
= pDownPath
;
1743 pInsidePath
= pDownPath
;
1744 pOutsidePath
= pUpPath
;
1750 /* Inside angle points */
1753 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1754 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1758 pt
.x
= xo
+ round( penWidthIn
* cos(theta
+ M_PI_2
) );
1759 pt
.y
= yo
+ round( penWidthIn
* sin(theta
+ M_PI_2
) );
1761 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1764 pt
.x
= xo
+ round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1765 pt
.y
= yo
+ round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1769 pt
.x
= xo
- round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1770 pt
.y
= yo
- round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1772 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1773 /* Outside angle point */
1776 case PS_JOIN_MITER
:
1777 miterWidth
= fabs(penWidthOut
/ cos(M_PI_2
- fabs(alpha
) / 2));
1778 pt
.x
= xo
+ round( miterWidth
* cos(theta
+ alpha
/ 2) );
1779 pt
.y
= yo
+ round( miterWidth
* sin(theta
+ alpha
/ 2) );
1780 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1782 case PS_JOIN_BEVEL
:
1785 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1786 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1790 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1791 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1793 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1796 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1797 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1801 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1802 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1804 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1806 case PS_JOIN_ROUND
:
1810 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1811 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1815 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1816 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1818 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1819 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ alpha
/ 2) );
1820 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ alpha
/ 2) );
1821 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1824 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1825 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1829 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1830 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1832 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1837 for(j
= 0; j
< pUpPath
->numEntriesUsed
; j
++)
1840 pt
.x
= pUpPath
->pPoints
[j
].x
;
1841 pt
.y
= pUpPath
->pPoints
[j
].y
;
1842 PATH_AddEntry(pNewPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1844 for(j
= 0; j
< pDownPath
->numEntriesUsed
; j
++)
1847 pt
.x
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].x
;
1848 pt
.y
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].y
;
1849 PATH_AddEntry(pNewPath
, &pt
, ( (j
== 0 && (pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) ? PT_MOVETO
: PT_LINETO
));
1852 PATH_DestroyGdiPath(pStrokes
[i
]);
1853 ExFreePoolWithTag(pStrokes
[i
], TAG_PATH
);
1854 PATH_DestroyGdiPath(pUpPath
);
1855 ExFreePoolWithTag(pUpPath
, TAG_PATH
);
1856 PATH_DestroyGdiPath(pDownPath
);
1857 ExFreePoolWithTag(pDownPath
, TAG_PATH
);
1859 ExFreePoolWithTag(pStrokes
, TAG_PATH
);
1861 pNewPath
->state
= PATH_Closed
;
1862 if (!(ret
= PATH_AssignGdiPath(pPath
, pNewPath
)))
1863 DPRINT1("Assign path failed\n");
1864 PATH_DestroyGdiPath(pNewPath
);
1865 ExFreePoolWithTag(pNewPath
, TAG_PATH
);
1869 static inline INT
int_from_fixed(FIXED f
)
1871 return (f
.fract
>= 0x8000) ? (f
.value
+ 1) : f
.value
;
1874 /**********************************************************************
1877 * internally used by PATH_add_outline
1882 PATH_BezierTo(PPATH pPath
, POINT
*lppt
, INT n
)
1888 PATH_AddEntry(pPath
, &lppt
[1], PT_LINETO
);
1892 PATH_AddEntry(pPath
, &lppt
[0], PT_BEZIERTO
);
1893 PATH_AddEntry(pPath
, &lppt
[1], PT_BEZIERTO
);
1894 PATH_AddEntry(pPath
, &lppt
[2], PT_BEZIERTO
);
1908 pt
[2].x
= (lppt
[i
+2].x
+ lppt
[i
+1].x
) / 2;
1909 pt
[2].y
= (lppt
[i
+2].y
+ lppt
[i
+1].y
) / 2;
1910 PATH_BezierTo(pPath
, pt
, 3);
1918 PATH_BezierTo(pPath
, pt
, 3);
1925 PATH_add_outline(PDC dc
, INT x
, INT y
, TTPOLYGONHEADER
*header
, DWORD size
)
1928 TTPOLYGONHEADER
*start
;
1933 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
1938 while ((char *)header
< (char *)start
+ size
)
1942 if (header
->dwType
!= TT_POLYGON_TYPE
)
1944 DPRINT1("Unknown header type %d\n", header
->dwType
);
1948 pt
.x
= x
+ int_from_fixed(header
->pfxStart
.x
);
1949 pt
.y
= y
- int_from_fixed(header
->pfxStart
.y
);
1950 IntLPtoDP(dc
, &pt
, 1);
1951 PATH_AddEntry(pPath
, &pt
, PT_MOVETO
);
1953 curve
= (TTPOLYCURVE
*)(header
+ 1);
1955 while ((char *)curve
< (char *)header
+ header
->cb
)
1957 /*DPRINT1("curve->wType %d\n", curve->wType);*/
1959 switch(curve
->wType
)
1965 for (i
= 0; i
< curve
->cpfx
; i
++)
1967 pt
.x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1968 pt
.y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1969 IntLPtoDP(dc
, &pt
, 1);
1970 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
1975 case TT_PRIM_QSPLINE
:
1976 case TT_PRIM_CSPLINE
:
1980 POINT
*pts
= ExAllocatePoolWithTag(PagedPool
, (curve
->cpfx
+ 1) * sizeof(POINT
), TAG_PATH
);
1982 if (!pts
) return FALSE
;
1984 ptfx
= *(POINTFX
*)((char *)curve
- sizeof(POINTFX
));
1986 pts
[0].x
= x
+ int_from_fixed(ptfx
.x
);
1987 pts
[0].y
= y
- int_from_fixed(ptfx
.y
);
1988 IntLPtoDP(dc
, &pts
[0], 1);
1990 for (i
= 0; i
< curve
->cpfx
; i
++)
1992 pts
[i
+ 1].x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1993 pts
[i
+ 1].y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1994 IntLPtoDP(dc
, &pts
[i
+ 1], 1);
1997 PATH_BezierTo(pPath
, pts
, curve
->cpfx
+ 1);
1999 ExFreePoolWithTag(pts
, TAG_PATH
);
2004 DPRINT1("Unknown curve type %04x\n", curve
->wType
);
2008 curve
= (TTPOLYCURVE
*)&curve
->apfx
[curve
->cpfx
];
2010 header
= (TTPOLYGONHEADER
*)((char *)header
+ header
->cb
);
2013 IntGdiCloseFigure( pPath
);
2014 PATH_UnlockPath( pPath
);
2018 /**********************************************************************
2023 PATH_ExtTextOut(PDC dc
, INT x
, INT y
, UINT flags
, const RECTL
*lprc
,
2024 LPCWSTR str
, UINT count
, const INT
*dx
)
2027 double cosEsc
, sinEsc
;
2032 INT offset
= 0, xoff
= 0, yoff
= 0;
2034 if (!count
) return TRUE
;
2036 pdcattr
= dc
->pdcattr
;
2038 TextObj
= RealizeFontInit( pdcattr
->hlfntNew
);
2039 if ( !TextObj
) return FALSE
;
2041 FontGetObject( TextObj
, sizeof(lf
), &lf
);
2043 if (lf
.lfEscapement
!= 0)
2045 cosEsc
= cos(lf
.lfEscapement
* M_PI
/ 1800);
2046 sinEsc
= sin(lf
.lfEscapement
* M_PI
/ 1800);
2053 IntGdiGetDCOrg(dc
, &org
);
2055 for (idx
= 0; idx
< count
; idx
++)
2061 dwSize
= ftGdiGetGlyphOutline( dc
,
2063 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2069 if (!dwSize
) return FALSE
;
2071 outline
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_PATH
);
2072 if (!outline
) return FALSE
;
2074 ftGdiGetGlyphOutline( dc
,
2076 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2083 PATH_add_outline(dc
, org
.x
+ x
+ xoff
, org
.x
+ y
+ yoff
, outline
, dwSize
);
2085 ExFreePoolWithTag(outline
, TAG_PATH
);
2090 xoff
= offset
* cosEsc
;
2091 yoff
= offset
* -sinEsc
;
2095 xoff
+= gm
.gmCellIncX
;
2096 yoff
+= gm
.gmCellIncY
;
2103 /***********************************************************************
2104 * Exported functions
2109 NtGdiAbortPath(HDC hDC
)
2112 PDC dc
= DC_LockDc ( hDC
);
2115 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2119 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2125 PATH_EmptyPath(pPath
);
2127 PATH_UnlockPath(pPath
);
2134 NtGdiBeginPath( HDC hDC
)
2139 dc
= DC_LockDc ( hDC
);
2142 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2146 /* If path is already open, do nothing. Check if not Save DC state */
2147 if ((dc
->dclevel
.flPath
& DCPATH_ACTIVE
) && !(dc
->dclevel
.flPath
& DCPATH_SAVE
))
2153 if ( dc
->dclevel
.hPath
)
2155 DPRINT1("BeginPath 1 0x%x\n", dc
->dclevel
.hPath
);
2156 if ( !(dc
->dclevel
.flPath
& DCPATH_SAVE
) )
2157 { // Remove previous handle.
2158 if (!PATH_Delete(dc
->dclevel
.hPath
))
2165 { // Clear flags and Handle.
2166 dc
->dclevel
.flPath
&= ~(DCPATH_SAVE
|DCPATH_ACTIVE
);
2167 dc
->dclevel
.hPath
= NULL
;
2170 pPath
= PATH_AllocPathWithHandle();
2173 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2176 dc
->dclevel
.flPath
|= DCPATH_ACTIVE
; // Set active ASAP!
2178 dc
->dclevel
.hPath
= pPath
->BaseObject
.hHmgr
;
2180 DPRINT1("BeginPath 2 h 0x%x p 0x%x\n", dc
->dclevel
.hPath
, pPath
);
2181 // Path handles are shared. Also due to recursion with in the same thread.
2182 GDIOBJ_UnlockObjByPtr((POBJ
)pPath
); // Unlock
2183 pPath
= PATH_LockPath(dc
->dclevel
.hPath
); // Share Lock.
2185 /* Make sure that path is empty */
2186 PATH_EmptyPath( pPath
);
2188 /* Initialize variables for new path */
2189 pPath
->newStroke
= TRUE
;
2190 pPath
->state
= PATH_Open
;
2192 PATH_UnlockPath(pPath
);
2199 NtGdiCloseFigure(HDC hDC
)
2201 BOOL Ret
= FALSE
; // default to failure
2205 DPRINT("Enter %s\n", __FUNCTION__
);
2207 pDc
= DC_LockDc(hDC
);
2210 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2213 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2220 if (pPath
->state
==PATH_Open
)
2222 IntGdiCloseFigure(pPath
);
2227 // FIXME: check if lasterror is set correctly
2228 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
2231 PATH_UnlockPath( pPath
);
2238 NtGdiEndPath(HDC hDC
)
2242 PDC dc
= DC_LockDc ( hDC
);
2246 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2250 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2256 /* Check that path is currently being constructed */
2257 if ( (pPath
->state
!= PATH_Open
) || !(dc
->dclevel
.flPath
& DCPATH_ACTIVE
) )
2259 DPRINT1("EndPath ERROR! 0x%x\n", dc
->dclevel
.hPath
);
2260 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
2263 /* Set flag to indicate that path is finished */
2266 DPRINT1("EndPath 0x%x\n", dc
->dclevel
.hPath
);
2267 pPath
->state
= PATH_Closed
;
2268 dc
->dclevel
.flPath
&= ~DCPATH_ACTIVE
;
2270 PATH_UnlockPath( pPath
);
2277 NtGdiFillPath(HDC hDC
)
2282 PDC dc
= DC_LockDc ( hDC
);
2286 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2289 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2296 pdcattr
= dc
->pdcattr
;
2298 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2299 DC_vUpdateLineBrush(dc
);
2301 ret
= PATH_FillPath( dc
, pPath
);
2304 /* FIXME: Should the path be emptied even if conversion
2306 PATH_EmptyPath( pPath
);
2309 PATH_UnlockPath( pPath
);
2316 NtGdiFlattenPath(HDC hDC
)
2322 DPRINT("Enter %s\n", __FUNCTION__
);
2324 pDc
= DC_LockDc(hDC
);
2327 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2331 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2334 DC_UnlockDc ( pDc
);
2337 if (pPath
->state
== PATH_Open
)
2338 Ret
= PATH_FlattenPath(pPath
);
2340 PATH_UnlockPath( pPath
);
2354 NTSTATUS Status
= STATUS_SUCCESS
;
2356 if (!(pDc
= DC_LockDc(hdc
)))
2358 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2362 worker
.f
= pDc
->dclevel
.laPath
.eMiterLimit
;
2368 ProbeForWrite(pdwOut
,
2373 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2375 Status
= _SEH2_GetExceptionCode();
2378 if (!NT_SUCCESS(Status
))
2380 SetLastNtError(Status
);
2402 DC
*dc
= DC_LockDc(hDC
);
2405 DPRINT1("Can't lock dc!\n");
2406 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2410 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2417 if (pPath
->state
!= PATH_Closed
)
2419 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
2425 ret
= pPath
->numEntriesUsed
;
2427 else if(nSize
<pPath
->numEntriesUsed
)
2429 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2436 memcpy(Points
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
2437 memcpy(Types
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
2439 /* Convert the points to logical coordinates */
2440 IntDPtoLP(dc
, Points
, pPath
->numEntriesUsed
);
2442 ret
= pPath
->numEntriesUsed
;
2444 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2446 SetLastNtError(_SEH2_GetExceptionCode());
2452 PATH_UnlockPath( pPath
);
2459 NtGdiPathToRegion(HDC hDC
)
2466 DPRINT("Enter %s\n", __FUNCTION__
);
2468 pDc
= DC_LockDc(hDC
);
2471 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2475 pdcattr
= pDc
->pdcattr
;
2477 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2480 DC_UnlockDc ( pDc
);
2484 if (pPath
->state
!=PATH_Closed
)
2486 //FIXME: check that setlasterror is being called correctly
2487 SetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
2491 /* FIXME: Should we empty the path even if conversion failed? */
2492 if(PATH_PathToRegion(pPath
, pdcattr
->jFillMode
, &hrgnRval
))
2493 PATH_EmptyPath(pPath
);
2496 PATH_UnlockPath( pPath
);
2506 IN OUT OPTIONAL PDWORD pdwOut
)
2509 gxf_long worker
, worker1
;
2510 NTSTATUS Status
= STATUS_SUCCESS
;
2512 if (!(pDc
= DC_LockDc(hdc
)))
2514 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2519 worker1
.f
= pDc
->dclevel
.laPath
.eMiterLimit
;
2520 pDc
->dclevel
.laPath
.eMiterLimit
= worker
.f
;
2526 ProbeForWrite(pdwOut
,
2529 *pdwOut
= worker1
.l
;
2531 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2533 Status
= _SEH2_GetExceptionCode();
2536 if (!NT_SUCCESS(Status
))
2538 SetLastNtError(Status
);
2550 NtGdiStrokeAndFillPath(HDC hDC
)
2557 DPRINT1("Enter %s\n", __FUNCTION__
);
2559 if (!(pDc
= DC_LockDc(hDC
)))
2561 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2564 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2567 DC_UnlockDc ( pDc
);
2571 pdcattr
= pDc
->pdcattr
;
2573 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
2574 DC_vUpdateFillBrush(pDc
);
2576 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2577 DC_vUpdateLineBrush(pDc
);
2579 bRet
= PATH_FillPath(pDc
, pPath
);
2580 if (bRet
) bRet
= PATH_StrokePath(pDc
, pPath
);
2581 if (bRet
) PATH_EmptyPath(pPath
);
2583 PATH_UnlockPath( pPath
);
2590 NtGdiStrokePath(HDC hDC
)
2597 DPRINT("Enter %s\n", __FUNCTION__
);
2599 if (!(pDc
= DC_LockDc(hDC
)))
2601 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2604 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2607 DC_UnlockDc ( pDc
);
2611 pdcattr
= pDc
->pdcattr
;
2613 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2614 DC_vUpdateLineBrush(pDc
);
2616 bRet
= PATH_StrokePath(pDc
, pPath
);
2617 PATH_EmptyPath(pPath
);
2619 PATH_UnlockPath( pPath
);
2626 NtGdiWidenPath(HDC hDC
)
2629 PDC pdc
= DC_LockDc ( hDC
);
2632 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2635 Ret
= PATH_WidenPath(pdc
);
2636 DC_UnlockDc ( pdc
);