2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: subsystems/win32/win32k/objects/path.c
5 * PURPOSE: Graphics paths (BeginPath, EndPath etc.)
6 * PROGRAMMER: Copyright 1997, 1998 Martin Boehme
8 * 2005 Dmitry Timoshkov
18 #pragma warning(disable:4244)
21 #define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
22 #define GROW_FACTOR_NUMER 2 /* Numerator of grow factor for the array */
23 #define GROW_FACTOR_DENOM 1 /* Denominator of grow factor */
25 /***********************************************************************
29 /* PATH_DestroyGdiPath
31 * Destroys a GdiPath structure (frees the memory in the arrays).
35 PATH_DestroyGdiPath ( PPATH pPath
)
39 if (pPath
->pPoints
) ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
40 if (pPath
->pFlags
) ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
45 PATH_Delete(HPATH hPath
)
48 if (!hPath
) return FALSE
;
49 pPath
= PATH_LockPath( hPath
);
50 if (!pPath
) return FALSE
;
51 PATH_DestroyGdiPath( pPath
);
52 GDIOBJ_vDeleteObject(&pPath
->BaseObject
);
59 IntGdiCloseFigure(PPATH pPath
)
61 ASSERT(pPath
->state
== PATH_Open
);
63 // FIXME: Shouldn't we draw a line to the beginning of the figure?
64 // Set PT_CLOSEFIGURE on the last entry and start a new stroke
65 if(pPath
->numEntriesUsed
)
67 pPath
->pFlags
[pPath
->numEntriesUsed
-1]|=PT_CLOSEFIGURE
;
68 pPath
->newStroke
=TRUE
;
72 /* MSDN: This fails if the device coordinates exceed 27 bits, or if the converted
73 logical coordinates exceed 32 bits. */
76 GdiPathDPtoLP(PDC pdc
, PPOINT ppt
, INT count
)
80 XFORMOBJ_vInit(&xo
, &pdc
->pdcattr
->mxDeviceToWorld
);
81 return XFORMOBJ_bApplyXform(&xo
, XF_LTOL
, count
, (PPOINTL
)ppt
, (PPOINTL
)ppt
);
90 PATH_FillPath( PDC dc
, PPATH pPath
)
92 //INT mapMode, graphicsMode;
93 //SIZE ptViewportExt, ptWindowExt;
94 //POINTL ptViewportOrg, ptWindowOrg;
97 PDC_ATTR pdcattr
= dc
->pdcattr
;
99 if( pPath
->state
!= PATH_Closed
)
101 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
105 if( PATH_PathToRegion( pPath
, pdcattr
->jFillMode
, &hrgn
))
107 /* Since PaintRgn interprets the region as being in logical coordinates
108 * but the points we store for the path are already in device
109 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
110 * Using SaveDC to save information about the mapping mode / world
111 * transform would be easier but would require more overhead, especially
112 * now that SaveDC saves the current path.
115 /* Save the information about the old mapping mode */
116 //mapMode = pdcattr->iMapMode;
117 //ptViewportExt = pdcattr->szlViewportExt;
118 //ptViewportOrg = pdcattr->ptlViewportOrg;
119 //ptWindowExt = pdcattr->szlWindowExt;
120 //ptWindowOrg = pdcattr->ptlWindowOrg;
122 /* Save world transform
123 * NB: The Windows documentation on world transforms would lead one to
124 * believe that this has to be done only in GM_ADVANCED; however, my
125 * tests show that resetting the graphics mode to GM_COMPATIBLE does
126 * not reset the world transform.
128 MatrixS2XForm(&xform
, &dc
->pdcattr
->mxWorldToPage
);
131 // IntGdiSetMapMode( dc, MM_TEXT );
132 // pdcattr->ptlViewportOrg.x = 0;
133 // pdcattr->ptlViewportOrg.y = 0;
134 // pdcattr->ptlWindowOrg.x = 0;
135 // pdcattr->ptlWindowOrg.y = 0;
137 // graphicsMode = pdcattr->iGraphicsMode;
138 // pdcattr->iGraphicsMode = GM_ADVANCED;
139 // IntGdiModifyWorldTransform( dc, &xform, MWT_IDENTITY );
140 // pdcattr->iGraphicsMode = graphicsMode;
142 /* Paint the region */
143 IntGdiPaintRgn( dc
, hrgn
);
144 GreDeleteObject( hrgn
);
145 /* Restore the old mapping mode */
146 // IntGdiSetMapMode( dc, mapMode );
147 // pdcattr->szlViewportExt = ptViewportExt;
148 // pdcattr->ptlViewportOrg = ptViewportOrg;
149 // pdcattr->szlWindowExt = ptWindowExt;
150 // pdcattr->ptlWindowOrg = ptWindowOrg;
152 /* Go to GM_ADVANCED temporarily to restore the world transform */
153 //graphicsMode = pdcattr->iGraphicsMode;
154 // pdcattr->iGraphicsMode = GM_ADVANCED;
155 // IntGdiModifyWorldTransform( dc, &xform, MWT_MAX+1 );
156 // pdcattr->iGraphicsMode = graphicsMode;
164 * Initializes the GdiPath structure.
168 PATH_InitGdiPath ( PPATH pPath
)
172 pPath
->state
=PATH_Null
;
175 pPath
->numEntriesUsed
=0;
176 pPath
->numEntriesAllocated
=0;
179 /* PATH_AssignGdiPath
181 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
182 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
183 * not just the pointers. Since this means that the arrays in pPathDest may
184 * need to be resized, pPathDest should have been initialized using
185 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
186 * not a copy constructor).
187 * Returns TRUE if successful, else FALSE.
191 PATH_AssignGdiPath ( PPATH pPathDest
, const PPATH pPathSrc
)
193 ASSERT(pPathDest
!=NULL
&& pPathSrc
!=NULL
);
195 /* Make sure destination arrays are big enough */
196 if ( !PATH_ReserveEntries(pPathDest
, pPathSrc
->numEntriesUsed
) )
199 /* Perform the copy operation */
200 memcpy(pPathDest
->pPoints
, pPathSrc
->pPoints
,
201 sizeof(POINT
)*pPathSrc
->numEntriesUsed
);
202 memcpy(pPathDest
->pFlags
, pPathSrc
->pFlags
,
203 sizeof(BYTE
)*pPathSrc
->numEntriesUsed
);
205 pPathDest
->state
=pPathSrc
->state
;
206 pPathDest
->numEntriesUsed
=pPathSrc
->numEntriesUsed
;
207 pPathDest
->newStroke
=pPathSrc
->newStroke
;
213 * Should be called when a MoveTo is performed on a DC that has an
214 * open path. This starts a new stroke. Returns TRUE if successful, else
219 PATH_MoveTo ( PDC dc
)
221 PPATH pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
222 if (!pPath
) return FALSE
;
224 /* Check that path is open */
225 if ( pPath
->state
!= PATH_Open
)
227 PATH_UnlockPath( pPath
);
228 /* FIXME: Do we have to call SetLastError? */
231 /* Start a new stroke */
232 pPath
->newStroke
= TRUE
;
233 PATH_UnlockPath( pPath
);
239 * Should be called when a LineTo is performed on a DC that has an
240 * open path. This adds a PT_LINETO entry to the path (and possibly
241 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
242 * Returns TRUE if successful, else FALSE.
246 PATH_LineTo ( PDC dc
, INT x
, INT y
)
250 POINT point
, pointCurPos
;
252 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
253 if (!pPath
) return FALSE
;
255 /* Check that path is open */
256 if ( pPath
->state
!= PATH_Open
)
258 PATH_UnlockPath( pPath
);
262 /* Convert point to device coordinates */
265 CoordLPtoDP ( dc
, &point
);
267 /* Add a PT_MOVETO if necessary */
268 if ( pPath
->newStroke
)
270 pPath
->newStroke
= FALSE
;
271 IntGetCurrentPositionEx ( dc
, &pointCurPos
);
272 CoordLPtoDP ( dc
, &pointCurPos
);
273 if ( !PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
) )
275 PATH_UnlockPath( pPath
);
280 /* Add a PT_LINETO entry */
281 Ret
= PATH_AddEntry(pPath
, &point
, PT_LINETO
);
282 PATH_UnlockPath( pPath
);
288 * Should be called when a call to Rectangle is performed on a DC that has
289 * an open path. Returns TRUE if successful, else FALSE.
293 PATH_Rectangle ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
)
296 POINT corners
[2], pointTemp
;
299 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
300 if (!pPath
) return FALSE
;
302 /* Check that path is open */
303 if ( pPath
->state
!= PATH_Open
)
305 PATH_UnlockPath( pPath
);
309 /* Convert points to device coordinates */
314 IntLPtoDP ( dc
, corners
, 2 );
316 /* Make sure first corner is top left and second corner is bottom right */
317 if ( corners
[0].x
> corners
[1].x
)
320 corners
[0].x
=corners
[1].x
;
323 if ( corners
[0].y
> corners
[1].y
)
326 corners
[0].y
=corners
[1].y
;
330 /* In GM_COMPATIBLE, don't include bottom and right edges */
331 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
337 /* Close any previous figure */
338 IntGdiCloseFigure(pPath
);
340 /* Add four points to the path */
341 pointTemp
.x
=corners
[1].x
;
342 pointTemp
.y
=corners
[0].y
;
343 if ( !PATH_AddEntry(pPath
, &pointTemp
, PT_MOVETO
) )
345 PATH_UnlockPath( pPath
);
348 if ( !PATH_AddEntry(pPath
, corners
, PT_LINETO
) )
350 PATH_UnlockPath( pPath
);
353 pointTemp
.x
=corners
[0].x
;
354 pointTemp
.y
=corners
[1].y
;
355 if ( !PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
) )
357 PATH_UnlockPath( pPath
);
360 if ( !PATH_AddEntry(pPath
, corners
+1, PT_LINETO
) )
362 PATH_UnlockPath( pPath
);
366 /* Close the rectangle figure */
367 IntGdiCloseFigure(pPath
) ;
368 PATH_UnlockPath( pPath
);
374 * Should be called when a call to RoundRect is performed on a DC that has
375 * an open path. Returns TRUE if successful, else FALSE.
377 * FIXME: It adds the same entries to the path as windows does, but there
378 * is an error in the bezier drawing code so that there are small pixel-size
379 * gaps when the resulting path is drawn by StrokePath()
381 BOOL FASTCALL
PATH_RoundRect(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
, INT ell_width
, INT ell_height
)
384 POINT corners
[2], pointTemp
;
385 FLOAT_POINT ellCorners
[2];
387 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
388 if (!pPath
) return FALSE
;
390 /* Check that path is open */
391 if(pPath
->state
!=PATH_Open
)
393 PATH_UnlockPath( pPath
);
397 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
399 PATH_UnlockPath( pPath
);
403 /* Add points to the roundrect path */
404 ellCorners
[0].x
= corners
[1].x
-ell_width
;
405 ellCorners
[0].y
= corners
[0].y
;
406 ellCorners
[1].x
= corners
[1].x
;
407 ellCorners
[1].y
= corners
[0].y
+ell_height
;
408 if(!PATH_DoArcPart(pPath
, ellCorners
, 0, -M_PI_2
, PT_MOVETO
))
410 PATH_UnlockPath( pPath
);
413 pointTemp
.x
= corners
[0].x
+ell_width
/2;
414 pointTemp
.y
= corners
[0].y
;
415 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
417 PATH_UnlockPath( pPath
);
420 ellCorners
[0].x
= corners
[0].x
;
421 ellCorners
[1].x
= corners
[0].x
+ell_width
;
422 if(!PATH_DoArcPart(pPath
, ellCorners
, -M_PI_2
, -M_PI
, FALSE
))
424 PATH_UnlockPath( pPath
);
427 pointTemp
.x
= corners
[0].x
;
428 pointTemp
.y
= corners
[1].y
-ell_height
/2;
429 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
431 PATH_UnlockPath( pPath
);
434 ellCorners
[0].y
= corners
[1].y
-ell_height
;
435 ellCorners
[1].y
= corners
[1].y
;
436 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI
, M_PI_2
, FALSE
))
438 PATH_UnlockPath( pPath
);
441 pointTemp
.x
= corners
[1].x
-ell_width
/2;
442 pointTemp
.y
= corners
[1].y
;
443 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
445 PATH_UnlockPath( pPath
);
448 ellCorners
[0].x
= corners
[1].x
-ell_width
;
449 ellCorners
[1].x
= corners
[1].x
;
450 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI_2
, 0, FALSE
))
452 PATH_UnlockPath( pPath
);
456 IntGdiCloseFigure(pPath
);
457 PATH_UnlockPath( pPath
);
463 * Should be called when a call to Ellipse is performed on a DC that has
464 * an open path. This adds four Bezier splines representing the ellipse
465 * to the path. Returns TRUE if successful, else FALSE.
469 PATH_Ellipse ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
)
472 /* TODO: This should probably be revised to call PATH_AngleArc */
473 /* (once it exists) */
474 BOOL Ret
= PATH_Arc ( dc
, x1
, y1
, x2
, y2
, x1
, (y1
+y2
)/2, x1
, (y1
+y2
)/2, GdiTypeArc
);
477 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
478 if (!pPath
) return FALSE
;
479 IntGdiCloseFigure(pPath
);
480 PATH_UnlockPath( pPath
);
487 * Should be called when a call to Arc is performed on a DC that has
488 * an open path. This adds up to five Bezier splines representing the arc
489 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
490 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
491 * -1 we add 1 extra line from the current DC position to the starting position
492 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
497 PATH_Arc ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
,
498 INT xStart
, INT yStart
, INT xEnd
, INT yEnd
, INT lines
)
500 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
=0.0;
501 /* Initialize angleEndQuadrant to silence gcc's warning */
503 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
504 POINT centre
, pointCurPos
;
505 BOOL start
, end
, Ret
= TRUE
;
510 /* FIXME: This function should check for all possible error returns */
511 /* FIXME: Do we have to respect newStroke? */
515 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
516 if (!pPath
) return FALSE
;
518 clockwise
= ((dc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
520 /* Check that path is open */
521 if ( pPath
->state
!= PATH_Open
)
527 /* Check for zero height / width */
528 /* FIXME: Only in GM_COMPATIBLE? */
529 if ( x1
==x2
|| y1
==y2
)
534 /* Convert points to device coordinates */
535 corners
[0].x
=(FLOAT
)x1
;
536 corners
[0].y
=(FLOAT
)y1
;
537 corners
[1].x
=(FLOAT
)x2
;
538 corners
[1].y
=(FLOAT
)y2
;
539 pointStart
.x
=(FLOAT
)xStart
;
540 pointStart
.y
=(FLOAT
)yStart
;
541 pointEnd
.x
=(FLOAT
)xEnd
;
542 pointEnd
.y
=(FLOAT
)yEnd
;
543 INTERNAL_LPTODP_FLOAT(dc
, corners
);
544 INTERNAL_LPTODP_FLOAT(dc
, corners
+1);
545 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
);
546 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
);
548 /* Make sure first corner is top left and second corner is bottom right */
549 if ( corners
[0].x
> corners
[1].x
)
552 corners
[0].x
=corners
[1].x
;
555 if ( corners
[0].y
> corners
[1].y
)
558 corners
[0].y
=corners
[1].y
;
562 /* Compute start and end angle */
563 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
564 angleStart
=atan2(y
, x
);
565 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
566 angleEnd
=atan2(y
, x
);
568 /* Make sure the end angle is "on the right side" of the start angle */
571 if ( angleEnd
<= angleStart
)
574 ASSERT(angleEnd
>=angleStart
);
579 if(angleEnd
>=angleStart
)
582 ASSERT(angleEnd
<=angleStart
);
586 /* In GM_COMPATIBLE, don't include bottom and right edges */
587 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
593 /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
594 if(lines
==GdiTypeArcTo
&& pPath
->newStroke
) // -1
596 pPath
->newStroke
=FALSE
;
597 IntGetCurrentPositionEx ( dc
, &pointCurPos
);
598 CoordLPtoDP(dc
, &pointCurPos
);
599 if(!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
606 /* Add the arc to the path with one Bezier spline per quadrant that the
612 /* Determine the start and end angles for this quadrant */
615 angleStartQuadrant
=angleStart
;
617 angleEndQuadrant
=(floor(angleStart
/M_PI_2
)+1.0)*M_PI_2
;
619 angleEndQuadrant
=(ceil(angleStart
/M_PI_2
)-1.0)*M_PI_2
;
623 angleStartQuadrant
=angleEndQuadrant
;
625 angleEndQuadrant
+=M_PI_2
;
627 angleEndQuadrant
-=M_PI_2
;
630 /* Have we reached the last part of the arc? */
631 if ( (clockwise
&& angleEnd
<angleEndQuadrant
)
632 || (!clockwise
&& angleEnd
>angleEndQuadrant
)
635 /* Adjust the end angle for this quadrant */
636 angleEndQuadrant
= angleEnd
;
640 /* Add the Bezier spline to the path */
641 PATH_DoArcPart ( pPath
, corners
, angleStartQuadrant
, angleEndQuadrant
,
642 start
? (lines
==GdiTypeArcTo
? PT_LINETO
: PT_MOVETO
) : FALSE
); // -1
646 /* chord: close figure. pie: add line and close figure */
647 if (lines
==GdiTypeChord
) // 1
649 IntGdiCloseFigure(pPath
);
651 else if (lines
==GdiTypePie
) // 2
653 centre
.x
= (corners
[0].x
+corners
[1].x
)/2;
654 centre
.y
= (corners
[0].y
+corners
[1].y
)/2;
655 if(!PATH_AddEntry(pPath
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
659 PATH_UnlockPath( pPath
);
665 PATH_PolyBezierTo ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
675 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
676 if (!pPath
) return FALSE
;
678 /* Check that path is open */
679 if ( pPath
->state
!= PATH_Open
)
681 PATH_UnlockPath( pPath
);
685 /* Add a PT_MOVETO if necessary */
686 if ( pPath
->newStroke
)
688 pPath
->newStroke
=FALSE
;
689 IntGetCurrentPositionEx ( dc
, &pt
);
690 CoordLPtoDP ( dc
, &pt
);
691 if ( !PATH_AddEntry(pPath
, &pt
, PT_MOVETO
) )
693 PATH_UnlockPath( pPath
);
698 for(i
= 0; i
< cbPoints
; i
++)
701 CoordLPtoDP ( dc
, &pt
);
702 PATH_AddEntry(pPath
, &pt
, PT_BEZIERTO
);
704 PATH_UnlockPath( pPath
);
710 PATH_PolyBezier ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
720 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
721 if (!pPath
) return FALSE
;
723 /* Check that path is open */
724 if ( pPath
->state
!= PATH_Open
)
726 PATH_UnlockPath( pPath
);
730 for ( i
= 0; i
< cbPoints
; i
++ )
733 CoordLPtoDP ( dc
, &pt
);
734 PATH_AddEntry ( pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_BEZIERTO
);
736 PATH_UnlockPath( pPath
);
742 PATH_PolyDraw(PDC dc
, const POINT
*pts
, const BYTE
*types
, DWORD cbPoints
)
745 POINT lastmove
, orig_pos
;
748 BOOL State
= FALSE
, Ret
= FALSE
;
750 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
751 if (!pPath
) return FALSE
;
753 if ( pPath
->state
!= PATH_Open
)
755 PATH_UnlockPath( pPath
);
759 pdcattr
= dc
->pdcattr
;
761 lastmove
.x
= orig_pos
.x
= pdcattr
->ptlCurrent
.x
;
762 lastmove
.y
= orig_pos
.y
= pdcattr
->ptlCurrent
.y
;
764 i
= pPath
->numEntriesUsed
;
769 if (pPath
->pFlags
[i
] == PT_MOVETO
)
771 lastmove
.x
= pPath
->pPoints
[i
].x
;
772 lastmove
.y
= pPath
->pPoints
[i
].y
;
773 if (!GdiPathDPtoLP(dc
, &lastmove
, 1))
775 PATH_UnlockPath( pPath
);
782 for (i
= 0; i
< cbPoints
; i
++)
784 if (types
[i
] == PT_MOVETO
)
786 pPath
->newStroke
= TRUE
;
787 lastmove
.x
= pts
[i
].x
;
788 lastmove
.y
= pts
[i
].y
;
790 else if((types
[i
] & ~PT_CLOSEFIGURE
) == PT_LINETO
)
792 PATH_LineTo(dc
, pts
[i
].x
, pts
[i
].y
);
794 else if(types
[i
] == PT_BEZIERTO
)
796 if (!((i
+ 2 < cbPoints
) && (types
[i
+ 1] == PT_BEZIERTO
)
797 && ((types
[i
+ 2] & ~PT_CLOSEFIGURE
) == PT_BEZIERTO
)))
799 PATH_PolyBezierTo(dc
, &(pts
[i
]), 3);
805 pdcattr
->ptlCurrent
.x
= pts
[i
].x
;
806 pdcattr
->ptlCurrent
.y
= pts
[i
].y
;
809 if (types
[i
] & PT_CLOSEFIGURE
)
811 pPath
->pFlags
[pPath
->numEntriesUsed
-1] |= PT_CLOSEFIGURE
;
812 pPath
->newStroke
= TRUE
;
813 pdcattr
->ptlCurrent
.x
= lastmove
.x
;
814 pdcattr
->ptlCurrent
.y
= lastmove
.y
;
822 if ((pdcattr
->ptlCurrent
.x
!= orig_pos
.x
) || (pdcattr
->ptlCurrent
.y
!= orig_pos
.y
))
824 pPath
->newStroke
= TRUE
;
825 pdcattr
->ptlCurrent
.x
= orig_pos
.x
;
826 pdcattr
->ptlCurrent
.y
= orig_pos
.y
;
830 if (State
) // State change?
832 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
833 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
834 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
836 PATH_UnlockPath( pPath
);
842 PATH_Polyline ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
852 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
853 if (!pPath
) return FALSE
;
855 /* Check that path is open */
856 if ( pPath
->state
!= PATH_Open
)
858 PATH_UnlockPath( pPath
);
861 for ( i
= 0; i
< cbPoints
; i
++ )
864 CoordLPtoDP ( dc
, &pt
);
865 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_LINETO
);
867 PATH_UnlockPath( pPath
);
873 PATH_PolylineTo ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
883 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
884 if (!pPath
) return FALSE
;
886 /* Check that path is open */
887 if ( pPath
->state
!= PATH_Open
)
889 PATH_UnlockPath( pPath
);
893 /* Add a PT_MOVETO if necessary */
894 if ( pPath
->newStroke
)
896 pPath
->newStroke
= FALSE
;
897 IntGetCurrentPositionEx ( dc
, &pt
);
898 CoordLPtoDP ( dc
, &pt
);
899 if ( !PATH_AddEntry(pPath
, &pt
, PT_MOVETO
) )
901 PATH_UnlockPath( pPath
);
906 for(i
= 0; i
< cbPoints
; i
++)
909 CoordLPtoDP ( dc
, &pt
);
910 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
912 PATH_UnlockPath( pPath
);
919 PATH_Polygon ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
928 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
929 if (!pPath
) return FALSE
;
931 /* Check that path is open */
932 if ( pPath
->state
!= PATH_Open
)
934 PATH_UnlockPath( pPath
);
938 for(i
= 0; i
< cbPoints
; i
++)
941 CoordLPtoDP ( dc
, &pt
);
942 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
:
943 ((i
== cbPoints
-1) ? PT_LINETO
| PT_CLOSEFIGURE
:
946 PATH_UnlockPath( pPath
);
952 PATH_PolyPolygon ( PDC dc
, const POINT
* pts
, const INT
* counts
, UINT polygons
)
955 ULONG poly
, point
, i
;
963 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
964 if (!pPath
) return FALSE
;
966 /* Check that path is open */
967 if ( pPath
->state
!= PATH_Open
)
969 PATH_UnlockPath( pPath
);
973 for(i
= 0, poly
= 0; poly
< polygons
; poly
++)
975 for(point
= 0; point
< (ULONG
) counts
[poly
]; point
++, i
++)
978 CoordLPtoDP ( dc
, &pt
);
979 if(point
== 0) startpt
= pt
;
980 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
982 /* Win98 adds an extra line to close the figure for some reason */
983 PATH_AddEntry(pPath
, &startpt
, PT_LINETO
| PT_CLOSEFIGURE
);
985 PATH_UnlockPath( pPath
);
991 PATH_PolyPolyline ( PDC dc
, const POINT
* pts
, const DWORD
* counts
, DWORD polylines
)
994 ULONG poly
, point
, i
;
1000 ASSERT ( polylines
);
1002 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
1003 if (!pPath
) return FALSE
;
1005 /* Check that path is open */
1006 if ( pPath
->state
!= PATH_Open
)
1008 PATH_UnlockPath( pPath
);
1012 for(i
= 0, poly
= 0; poly
< polylines
; poly
++)
1014 for(point
= 0; point
< counts
[poly
]; point
++, i
++)
1017 CoordLPtoDP ( dc
, &pt
);
1018 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1021 PATH_UnlockPath( pPath
);
1026 /* PATH_CheckCorners
1028 * Helper function for PATH_RoundRect() and PATH_Rectangle()
1030 BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
)
1033 PDC_ATTR pdcattr
= dc
->pdcattr
;
1035 /* Convert points to device coordinates */
1040 CoordLPtoDP(dc
, &corners
[0]);
1041 CoordLPtoDP(dc
, &corners
[1]);
1043 /* Make sure first corner is top left and second corner is bottom right */
1044 if(corners
[0].x
>corners
[1].x
)
1047 corners
[0].x
=corners
[1].x
;
1050 if(corners
[0].y
>corners
[1].y
)
1053 corners
[0].y
=corners
[1].y
;
1057 /* In GM_COMPATIBLE, don't include bottom and right edges */
1058 if(pdcattr
->iGraphicsMode
==GM_COMPATIBLE
)
1068 /* PATH_AddFlatBezier
1073 PATH_AddFlatBezier ( PPATH pPath
, POINT
*pt
, BOOL closed
)
1078 pts
= GDI_Bezier( pt
, 4, &no
);
1079 if ( !pts
) return FALSE
;
1081 for(i
= 1; i
< no
; i
++)
1082 PATH_AddEntry(pPath
, &pts
[i
], (i
== no
-1 && closed
) ? PT_LINETO
| PT_CLOSEFIGURE
: PT_LINETO
);
1084 ExFreePoolWithTag(pts
, TAG_BEZIER
);
1090 * Replaces Beziers with line segments
1095 PATH_FlattenPath(PPATH pPath
)
1100 RtlZeroMemory(&newPath
, sizeof(newPath
));
1101 newPath
.state
= PATH_Open
;
1102 for(srcpt
= 0; srcpt
< pPath
->numEntriesUsed
; srcpt
++) {
1103 switch(pPath
->pFlags
[srcpt
] & ~PT_CLOSEFIGURE
) {
1106 PATH_AddEntry(&newPath
, &pPath
->pPoints
[srcpt
], pPath
->pFlags
[srcpt
]);
1109 PATH_AddFlatBezier(&newPath
, &pPath
->pPoints
[srcpt
-1], pPath
->pFlags
[srcpt
+2] & PT_CLOSEFIGURE
);
1114 newPath
.state
= PATH_Closed
;
1115 PATH_AssignGdiPath(pPath
, &newPath
);
1116 PATH_EmptyPath(&newPath
);
1121 /* PATH_PathToRegion
1123 * Creates a region from the specified path using the specified polygon
1124 * filling mode. The path is left unchanged. A handle to the region that
1125 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1126 * error occurs, SetLastError is called with the appropriate value and
1127 * FALSE is returned.
1131 PATH_PathToRegion ( PPATH pPath
, INT nPolyFillMode
, HRGN
*pHrgn
)
1133 int numStrokes
, iStroke
, i
;
1134 PULONG pNumPointsInStroke
;
1137 ASSERT(pPath
!=NULL
);
1138 ASSERT(pHrgn
!=NULL
);
1140 PATH_FlattenPath ( pPath
);
1142 /* First pass: Find out how many strokes there are in the path */
1143 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1145 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1146 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1154 /* Allocate memory for number-of-points-in-stroke array */
1155 pNumPointsInStroke
= ExAllocatePoolWithTag(PagedPool
, sizeof(ULONG
) * numStrokes
, TAG_PATH
);
1156 if(!pNumPointsInStroke
)
1158 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1162 /* Second pass: remember number of points in each polygon */
1163 iStroke
=-1; /* Will get incremented to 0 at beginning of first stroke */
1164 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1166 /* Is this the beginning of a new stroke? */
1167 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1170 _PRAGMA_WARNING_SUPPRESS(__WARNING_WRITE_OVERRUN
)
1171 pNumPointsInStroke
[iStroke
]=0;
1174 _PRAGMA_WARNING_SUPPRESS(__WARNING_READ_OVERRUN
)
1175 pNumPointsInStroke
[iStroke
]++;
1178 /* Create a region from the strokes */
1179 hrgn
= IntCreatePolyPolygonRgn( pPath
->pPoints
,
1185 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1189 /* Free memory for number-of-points-in-stroke array */
1190 ExFreePoolWithTag(pNumPointsInStroke
, TAG_PATH
);
1199 * Removes all entries from the path and sets the path state to PATH_Null.
1203 PATH_EmptyPath ( PPATH pPath
)
1205 ASSERT(pPath
!=NULL
);
1207 pPath
->state
=PATH_Null
;
1208 pPath
->numEntriesUsed
=0;
1213 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1214 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1215 * successful, FALSE otherwise (e.g. if not enough memory was available).
1219 PATH_AddEntry ( PPATH pPath
, const POINT
*pPoint
, BYTE flags
)
1221 ASSERT(pPath
!=NULL
);
1223 /* FIXME: If newStroke is true, perhaps we want to check that we're
1224 * getting a PT_MOVETO
1227 /* Check that path is open */
1228 if ( pPath
->state
!= PATH_Open
)
1231 /* Reserve enough memory for an extra path entry */
1232 if ( !PATH_ReserveEntries(pPath
, pPath
->numEntriesUsed
+1) )
1235 /* Store information in path entry */
1236 pPath
->pPoints
[pPath
->numEntriesUsed
]=*pPoint
;
1237 pPath
->pFlags
[pPath
->numEntriesUsed
]=flags
;
1239 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1240 if((flags
& PT_CLOSEFIGURE
) == PT_CLOSEFIGURE
)
1241 pPath
->newStroke
=TRUE
;
1243 /* Increment entry count */
1244 pPath
->numEntriesUsed
++;
1249 /* PATH_ReserveEntries
1251 * Ensures that at least "numEntries" entries (for points and flags) have
1252 * been allocated; allocates larger arrays and copies the existing entries
1253 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1257 PATH_ReserveEntries ( PPATH pPath
, INT numEntries
)
1259 INT numEntriesToAllocate
;
1263 ASSERT(pPath
!=NULL
);
1264 ASSERT(numEntries
>=0);
1266 /* Do we have to allocate more memory? */
1267 if(numEntries
> pPath
->numEntriesAllocated
)
1269 /* Find number of entries to allocate. We let the size of the array
1270 * grow exponentially, since that will guarantee linear time
1272 if(pPath
->numEntriesAllocated
)
1274 numEntriesToAllocate
=pPath
->numEntriesAllocated
;
1275 while(numEntriesToAllocate
<numEntries
)
1276 numEntriesToAllocate
=numEntriesToAllocate
*GROW_FACTOR_NUMER
/GROW_FACTOR_DENOM
;
1278 numEntriesToAllocate
=numEntries
;
1280 /* Allocate new arrays */
1281 pPointsNew
=(POINT
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(POINT
), TAG_PATH
);
1284 pFlagsNew
=(BYTE
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(BYTE
), TAG_PATH
);
1287 ExFreePoolWithTag(pPointsNew
, TAG_PATH
);
1291 /* Copy old arrays to new arrays and discard old arrays */
1294 ASSERT(pPath
->pFlags
);
1296 memcpy(pPointsNew
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
1297 memcpy(pFlagsNew
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
1299 ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
1300 ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
1302 pPath
->pPoints
=pPointsNew
;
1303 pPath
->pFlags
=pFlagsNew
;
1304 pPath
->numEntriesAllocated
=numEntriesToAllocate
;
1312 * Creates a Bezier spline that corresponds to part of an arc and appends the
1313 * corresponding points to the path. The start and end angles are passed in
1314 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1315 * at most. If "startEntryType" is non-zero, an entry of that type for the first
1316 * control point is added to the path; otherwise, it is assumed that the current
1317 * position is equal to the first control point.
1321 PATH_DoArcPart ( PPATH pPath
, FLOAT_POINT corners
[],
1322 double angleStart
, double angleEnd
, BYTE startEntryType
)
1324 double halfAngle
, a
;
1325 double xNorm
[4], yNorm
[4];
1329 ASSERT(fabs(angleEnd
-angleStart
)<=M_PI_2
);
1331 /* FIXME: Is there an easier way of computing this? */
1333 /* Compute control points */
1334 halfAngle
=(angleEnd
-angleStart
)/2.0;
1335 if(fabs(halfAngle
)>1e-8)
1337 a
=4.0/3.0*(1-cos(halfAngle
))/sin(halfAngle
);
1338 xNorm
[0]=cos(angleStart
);
1339 yNorm
[0]=sin(angleStart
);
1340 xNorm
[1]=xNorm
[0] - a
*yNorm
[0];
1341 yNorm
[1]=yNorm
[0] + a
*xNorm
[0];
1342 xNorm
[3]=cos(angleEnd
);
1343 yNorm
[3]=sin(angleEnd
);
1344 xNorm
[2]=xNorm
[3] + a
*yNorm
[3];
1345 yNorm
[2]=yNorm
[3] - a
*xNorm
[3];
1349 xNorm
[i
]=cos(angleStart
);
1350 yNorm
[i
]=sin(angleStart
);
1353 /* Add starting point to path if desired */
1356 PATH_ScaleNormalizedPoint(corners
, xNorm
[0], yNorm
[0], &point
);
1357 if(!PATH_AddEntry(pPath
, &point
, startEntryType
))
1361 /* Add remaining control points */
1364 PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &point
);
1365 if(!PATH_AddEntry(pPath
, &point
, PT_BEZIERTO
))
1372 /* PATH_ScaleNormalizedPoint
1374 * Scales a normalized point (x, y) with respect to the box whose corners are
1375 * passed in "corners". The point is stored in "*pPoint". The normalized
1376 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1377 * (1.0, 1.0) correspond to corners[1].
1381 PATH_ScaleNormalizedPoint ( FLOAT_POINT corners
[], double x
,
1382 double y
, POINT
*pPoint
)
1386 pPoint
->x
=GDI_ROUND( (double)corners
[0].x
+ (double)(corners
[1].x
-corners
[0].x
)*0.5*(x
+1.0) );
1387 pPoint
->y
=GDI_ROUND( (double)corners
[0].y
+ (double)(corners
[1].y
-corners
[0].y
)*0.5*(y
+1.0) );
1390 /* PATH_NormalizePoint
1392 * Normalizes a point with respect to the box whose corners are passed in
1393 * corners. The normalized coordinates are stored in *pX and *pY.
1397 PATH_NormalizePoint ( FLOAT_POINT corners
[],
1398 const FLOAT_POINT
*pPoint
,
1399 double *pX
, double *pY
)
1405 *pX
=(double)(pPoint
->x
-corners
[0].x
)/(double)(corners
[1].x
-corners
[0].x
) * 2.0 - 1.0;
1406 *pY
=(double)(pPoint
->y
-corners
[0].y
)/(double)(corners
[1].y
-corners
[0].y
) * 2.0 - 1.0;
1410 BOOL FASTCALL
PATH_StrokePath(DC
*dc
, PPATH pPath
)
1414 INT nLinePts
, nAlloc
;
1415 POINT
*pLinePts
= NULL
;
1416 POINT ptViewportOrg
, ptWindowOrg
;
1417 SIZE szViewportExt
, szWindowExt
;
1418 DWORD mapMode
, graphicsMode
;
1420 PDC_ATTR pdcattr
= dc
->pdcattr
;
1422 DPRINT("Enter %s\n", __FUNCTION__
);
1424 if (pPath
->state
!= PATH_Closed
)
1427 /* Save the mapping mode info */
1428 mapMode
= pdcattr
->iMapMode
;
1430 szViewportExt
= *DC_pszlViewportExt(dc
);
1431 ptViewportOrg
= dc
->pdcattr
->ptlViewportOrg
;
1432 szWindowExt
= dc
->pdcattr
->szlWindowExt
;
1433 ptWindowOrg
= dc
->pdcattr
->ptlWindowOrg
;
1435 MatrixS2XForm(&xform
, &dc
->pdcattr
->mxWorldToPage
);
1438 pdcattr
->iMapMode
= MM_TEXT
;
1439 pdcattr
->ptlViewportOrg
.x
= 0;
1440 pdcattr
->ptlViewportOrg
.y
= 0;
1441 pdcattr
->ptlWindowOrg
.x
= 0;
1442 pdcattr
->ptlWindowOrg
.y
= 0;
1443 graphicsMode
= pdcattr
->iGraphicsMode
;
1444 pdcattr
->iGraphicsMode
= GM_ADVANCED
;
1445 GreModifyWorldTransform(dc
, (XFORML
*)&xform
, MWT_IDENTITY
);
1446 pdcattr
->iGraphicsMode
= graphicsMode
;
1448 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1449 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1450 * space in case we get one to keep the number of reallocations small. */
1451 nAlloc
= pPath
->numEntriesUsed
+ 1 + 300;
1452 pLinePts
= ExAllocatePoolWithTag(PagedPool
, nAlloc
* sizeof(POINT
), TAG_PATH
);
1455 DPRINT1("Can't allocate pool!\n");
1456 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1461 for(i
= 0; i
< pPath
->numEntriesUsed
; i
++)
1463 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
))
1464 && (pPath
->pFlags
[i
] != PT_MOVETO
))
1466 DPRINT1("Expected PT_MOVETO %s, got path flag %d\n",
1467 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1468 (INT
)pPath
->pFlags
[i
]);
1472 switch(pPath
->pFlags
[i
])
1475 DPRINT("Got PT_MOVETO (%ld, %ld)\n",
1476 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1477 if(nLinePts
>= 2) IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1479 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1482 case (PT_LINETO
| PT_CLOSEFIGURE
):
1483 DPRINT("Got PT_LINETO (%ld, %ld)\n",
1484 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1485 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1488 DPRINT("Got PT_BEZIERTO\n");
1489 if(pPath
->pFlags
[i
+1] != PT_BEZIERTO
||
1490 (pPath
->pFlags
[i
+2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
)
1492 DPRINT1("Path didn't contain 3 successive PT_BEZIERTOs\n");
1498 INT nBzrPts
, nMinAlloc
;
1499 POINT
*pBzrPts
= GDI_Bezier(&pPath
->pPoints
[i
-1], 4, &nBzrPts
);
1500 /* Make sure we have allocated enough memory for the lines of
1501 * this bezier and the rest of the path, assuming we won't get
1502 * another one (since we won't reallocate again then). */
1503 nMinAlloc
= nLinePts
+ (pPath
->numEntriesUsed
- i
) + nBzrPts
;
1504 if(nAlloc
< nMinAlloc
)
1506 // Reallocate memory
1508 POINT
*Realloc
= NULL
;
1509 nAlloc
= nMinAlloc
* 2;
1511 Realloc
= ExAllocatePoolWithTag(PagedPool
,
1512 nAlloc
* sizeof(POINT
),
1517 DPRINT1("Can't allocate pool!\n");
1521 memcpy(Realloc
, pLinePts
, nLinePts
*sizeof(POINT
));
1522 ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1525 memcpy(&pLinePts
[nLinePts
], &pBzrPts
[1], (nBzrPts
- 1) * sizeof(POINT
));
1526 nLinePts
+= nBzrPts
- 1;
1527 ExFreePoolWithTag(pBzrPts
, TAG_BEZIER
);
1532 DPRINT1("Got path flag %d (not supported)\n", (INT
)pPath
->pFlags
[i
]);
1536 if(pPath
->pFlags
[i
] & PT_CLOSEFIGURE
)
1538 pLinePts
[nLinePts
++] = pLinePts
[0];
1542 IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1547 if(pLinePts
) ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1549 /* Restore the old mapping mode */
1550 pdcattr
->iMapMode
= mapMode
;
1551 pdcattr
->szlWindowExt
.cx
= szWindowExt
.cx
;
1552 pdcattr
->szlWindowExt
.cy
= szWindowExt
.cy
;
1553 pdcattr
->ptlWindowOrg
.x
= ptWindowOrg
.x
;
1554 pdcattr
->ptlWindowOrg
.y
= ptWindowOrg
.y
;
1556 pdcattr
->szlViewportExt
.cx
= szViewportExt
.cx
;
1557 pdcattr
->szlViewportExt
.cy
= szViewportExt
.cy
;
1558 pdcattr
->ptlViewportOrg
.x
= ptViewportOrg
.x
;
1559 pdcattr
->ptlViewportOrg
.y
= ptViewportOrg
.y
;
1561 /* Restore the world transform */
1562 XForm2MatrixS(&dc
->pdcattr
->mxWorldToPage
, &xform
);
1564 /* If we've moved the current point then get its new position
1565 which will be in device (MM_TEXT) co-ords, convert it to
1566 logical co-ords and re-set it. This basically updates
1567 dc->CurPosX|Y so that their values are in the correct mapping
1573 IntGetCurrentPositionEx(dc
, &pt
);
1574 IntDPtoLP(dc
, &pt
, 1);
1575 IntGdiMoveToEx(dc
, pt
.x
, pt
.y
, NULL
, FALSE
);
1577 DPRINT("Leave %s, ret=%d\n", __FUNCTION__
, ret
);
1581 #define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1586 PATH_WidenPath(DC
*dc
)
1588 INT i
, j
, numStrokes
, numOldStrokes
, penWidth
, penWidthIn
, penWidthOut
, size
, penStyle
;
1590 PPATH pPath
, pNewPath
, *pStrokes
= NULL
, *pOldStrokes
, pUpPath
, pDownPath
;
1592 DWORD obj_type
, joint
, endcap
, penType
;
1593 PDC_ATTR pdcattr
= dc
->pdcattr
;
1595 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
1596 if (!pPath
) return FALSE
;
1598 if(pPath
->state
== PATH_Open
)
1600 PATH_UnlockPath( pPath
);
1601 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1605 PATH_FlattenPath(pPath
);
1607 size
= GreGetObject( pdcattr
->hpen
, 0, NULL
);
1610 PATH_UnlockPath( pPath
);
1611 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1615 elp
= ExAllocatePoolWithTag(PagedPool
, size
, TAG_PATH
);
1616 GreGetObject(pdcattr
->hpen
, size
, elp
);
1618 obj_type
= GDI_HANDLE_GET_TYPE(pdcattr
->hpen
);
1619 if(obj_type
== GDI_OBJECT_TYPE_PEN
)
1621 penStyle
= ((LOGPEN
*)elp
)->lopnStyle
;
1623 else if(obj_type
== GDI_OBJECT_TYPE_EXTPEN
)
1625 penStyle
= elp
->elpPenStyle
;
1629 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1630 ExFreePoolWithTag(elp
, TAG_PATH
);
1631 PATH_UnlockPath( pPath
);
1635 penWidth
= elp
->elpWidth
;
1636 ExFreePoolWithTag(elp
, TAG_PATH
);
1638 endcap
= (PS_ENDCAP_MASK
& penStyle
);
1639 joint
= (PS_JOIN_MASK
& penStyle
);
1640 penType
= (PS_TYPE_MASK
& penStyle
);
1642 /* The function cannot apply to cosmetic pens */
1643 if(obj_type
== GDI_OBJECT_TYPE_EXTPEN
&& penType
== PS_COSMETIC
)
1645 PATH_UnlockPath( pPath
);
1646 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1650 penWidthIn
= penWidth
/ 2;
1651 penWidthOut
= penWidth
/ 2;
1652 if(penWidthIn
+ penWidthOut
< penWidth
)
1657 for(i
= 0, j
= 0; i
< pPath
->numEntriesUsed
; i
++, j
++)
1660 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
)) &&
1661 (pPath
->pFlags
[i
] != PT_MOVETO
))
1663 DPRINT1("Expected PT_MOVETO %s, got path flag %c\n",
1664 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1668 switch(pPath
->pFlags
[i
])
1673 pStrokes
[numStrokes
- 1]->state
= PATH_Closed
;
1675 numOldStrokes
= numStrokes
;
1678 if (numStrokes
== 1)
1679 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1682 pOldStrokes
= pStrokes
; // Save old pointer.
1683 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1684 if (!pStrokes
) return FALSE
;
1685 RtlCopyMemory(pStrokes
, pOldStrokes
, numOldStrokes
* sizeof(PPATH
));
1686 ExFreePoolWithTag(pOldStrokes
, TAG_PATH
); // Free old pointer.
1688 if (!pStrokes
) return FALSE
;
1689 pStrokes
[numStrokes
- 1] = ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1690 if (!pStrokes
[numStrokes
- 1])
1692 ASSERT(FALSE
); // FIXME
1695 PATH_InitGdiPath(pStrokes
[numStrokes
- 1]);
1696 pStrokes
[numStrokes
- 1]->state
= PATH_Open
;
1698 case (PT_LINETO
| PT_CLOSEFIGURE
):
1699 point
.x
= pPath
->pPoints
[i
].x
;
1700 point
.y
= pPath
->pPoints
[i
].y
;
1701 PATH_AddEntry(pStrokes
[numStrokes
- 1], &point
, pPath
->pFlags
[i
]);
1704 /* Should never happen because of the FlattenPath call */
1705 DPRINT1("Should never happen\n");
1708 DPRINT1("Got path flag %c\n", pPath
->pFlags
[i
]);
1713 pNewPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1716 ASSERT(FALSE
); // FIXME
1718 PATH_InitGdiPath(pNewPath
);
1719 pNewPath
->state
= PATH_Open
;
1721 for(i
= 0; i
< numStrokes
; i
++)
1723 pUpPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1724 PATH_InitGdiPath(pUpPath
);
1725 pUpPath
->state
= PATH_Open
;
1726 pDownPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1727 PATH_InitGdiPath(pDownPath
);
1728 pDownPath
->state
= PATH_Open
;
1730 for(j
= 0; j
< pStrokes
[i
]->numEntriesUsed
; j
++)
1732 /* Beginning or end of the path if not closed */
1733 if((!(pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) && (j
== 0 || j
== pStrokes
[i
]->numEntriesUsed
- 1) )
1735 /* Compute segment angle */
1736 double xo
, yo
, xa
, ya
, theta
;
1738 FLOAT_POINT corners
[2];
1741 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1742 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1743 xa
= pStrokes
[i
]->pPoints
[1].x
;
1744 ya
= pStrokes
[i
]->pPoints
[1].y
;
1748 xa
= pStrokes
[i
]->pPoints
[j
- 1].x
;
1749 ya
= pStrokes
[i
]->pPoints
[j
- 1].y
;
1750 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1751 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1753 theta
= atan2( ya
- yo
, xa
- xo
);
1756 case PS_ENDCAP_SQUARE
:
1757 pt
.x
= xo
+ round(sqrt(2) * penWidthOut
* cos(M_PI_4
+ theta
));
1758 pt
.y
= yo
+ round(sqrt(2) * penWidthOut
* sin(M_PI_4
+ theta
));
1759 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
) );
1760 pt
.x
= xo
+ round(sqrt(2) * penWidthIn
* cos(- M_PI_4
+ theta
));
1761 pt
.y
= yo
+ round(sqrt(2) * penWidthIn
* sin(- M_PI_4
+ theta
));
1762 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1764 case PS_ENDCAP_FLAT
:
1765 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1766 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1767 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1768 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1769 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1770 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1772 case PS_ENDCAP_ROUND
:
1774 corners
[0].x
= xo
- penWidthIn
;
1775 corners
[0].y
= yo
- penWidthIn
;
1776 corners
[1].x
= xo
+ penWidthOut
;
1777 corners
[1].y
= yo
+ penWidthOut
;
1778 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI_2
, theta
+ 3 * M_PI_4
, (j
== 0 ? PT_MOVETO
: FALSE
));
1779 PATH_DoArcPart(pUpPath
,corners
, theta
+ 3 * M_PI_4
, theta
+ M_PI
, FALSE
);
1780 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI
, theta
+ 5 * M_PI_4
, FALSE
);
1781 PATH_DoArcPart(pUpPath
,corners
, theta
+ 5 * M_PI_4
, theta
+ 3 * M_PI_2
, FALSE
);
1785 /* Corpse of the path */
1790 double xa
, ya
, xb
, yb
, xo
, yo
;
1791 double alpha
, theta
, miterWidth
;
1792 DWORD _joint
= joint
;
1794 PPATH pInsidePath
, pOutsidePath
;
1795 if(j
> 0 && j
< pStrokes
[i
]->numEntriesUsed
- 1)
1802 previous
= pStrokes
[i
]->numEntriesUsed
- 1;
1810 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1811 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1812 xa
= pStrokes
[i
]->pPoints
[previous
].x
;
1813 ya
= pStrokes
[i
]->pPoints
[previous
].y
;
1814 xb
= pStrokes
[i
]->pPoints
[next
].x
;
1815 yb
= pStrokes
[i
]->pPoints
[next
].y
;
1816 theta
= atan2( yo
- ya
, xo
- xa
);
1817 alpha
= atan2( yb
- yo
, xb
- xo
) - theta
;
1818 if (alpha
> 0) alpha
-= M_PI
;
1820 if(_joint
== PS_JOIN_MITER
&& dc
->dclevel
.laPath
.eMiterLimit
< fabs(1 / sin(alpha
/2)))
1822 _joint
= PS_JOIN_BEVEL
;
1826 pInsidePath
= pUpPath
;
1827 pOutsidePath
= pDownPath
;
1831 pInsidePath
= pDownPath
;
1832 pOutsidePath
= pUpPath
;
1838 /* Inside angle points */
1841 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1842 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1846 pt
.x
= xo
+ round( penWidthIn
* cos(theta
+ M_PI_2
) );
1847 pt
.y
= yo
+ round( penWidthIn
* sin(theta
+ M_PI_2
) );
1849 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1852 pt
.x
= xo
+ round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1853 pt
.y
= yo
+ round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1857 pt
.x
= xo
- round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1858 pt
.y
= yo
- round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1860 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1861 /* Outside angle point */
1864 case PS_JOIN_MITER
:
1865 miterWidth
= fabs(penWidthOut
/ cos(M_PI_2
- fabs(alpha
) / 2));
1866 pt
.x
= xo
+ round( miterWidth
* cos(theta
+ alpha
/ 2) );
1867 pt
.y
= yo
+ round( miterWidth
* sin(theta
+ alpha
/ 2) );
1868 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1870 case PS_JOIN_BEVEL
:
1873 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1874 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1878 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1879 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1881 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1884 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1885 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1889 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1890 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1892 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1894 case PS_JOIN_ROUND
:
1898 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1899 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1903 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1904 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1906 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1907 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ alpha
/ 2) );
1908 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ alpha
/ 2) );
1909 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1912 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1913 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1917 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1918 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1920 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1925 for(j
= 0; j
< pUpPath
->numEntriesUsed
; j
++)
1928 pt
.x
= pUpPath
->pPoints
[j
].x
;
1929 pt
.y
= pUpPath
->pPoints
[j
].y
;
1930 PATH_AddEntry(pNewPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1932 for(j
= 0; j
< pDownPath
->numEntriesUsed
; j
++)
1935 pt
.x
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].x
;
1936 pt
.y
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].y
;
1937 PATH_AddEntry(pNewPath
, &pt
, ( (j
== 0 && (pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) ? PT_MOVETO
: PT_LINETO
));
1940 PATH_DestroyGdiPath(pStrokes
[i
]);
1941 ExFreePoolWithTag(pStrokes
[i
], TAG_PATH
);
1942 PATH_DestroyGdiPath(pUpPath
);
1943 ExFreePoolWithTag(pUpPath
, TAG_PATH
);
1944 PATH_DestroyGdiPath(pDownPath
);
1945 ExFreePoolWithTag(pDownPath
, TAG_PATH
);
1947 if (pStrokes
) ExFreePoolWithTag(pStrokes
, TAG_PATH
);
1949 pNewPath
->state
= PATH_Closed
;
1950 if (!(ret
= PATH_AssignGdiPath(pPath
, pNewPath
)))
1951 DPRINT1("Assign path failed\n");
1952 PATH_DestroyGdiPath(pNewPath
);
1953 ExFreePoolWithTag(pNewPath
, TAG_PATH
);
1954 PATH_UnlockPath(pPath
);
1958 static inline INT
int_from_fixed(FIXED f
)
1960 return (f
.fract
>= 0x8000) ? (f
.value
+ 1) : f
.value
;
1963 /**********************************************************************
1966 * Internally used by PATH_add_outline
1971 PATH_BezierTo(PPATH pPath
, POINT
*lppt
, INT n
)
1977 PATH_AddEntry(pPath
, &lppt
[1], PT_LINETO
);
1981 PATH_AddEntry(pPath
, &lppt
[0], PT_BEZIERTO
);
1982 PATH_AddEntry(pPath
, &lppt
[1], PT_BEZIERTO
);
1983 PATH_AddEntry(pPath
, &lppt
[2], PT_BEZIERTO
);
1997 pt
[2].x
= (lppt
[i
+2].x
+ lppt
[i
+1].x
) / 2;
1998 pt
[2].y
= (lppt
[i
+2].y
+ lppt
[i
+1].y
) / 2;
1999 PATH_BezierTo(pPath
, pt
, 3);
2007 PATH_BezierTo(pPath
, pt
, 3);
2014 PATH_add_outline(PDC dc
, INT x
, INT y
, TTPOLYGONHEADER
*header
, DWORD size
)
2017 TTPOLYGONHEADER
*start
;
2019 BOOL bResult
= FALSE
;
2023 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2029 while ((char *)header
< (char *)start
+ size
)
2033 if (header
->dwType
!= TT_POLYGON_TYPE
)
2035 DPRINT1("Unknown header type %lu\n", header
->dwType
);
2039 pt
.x
= x
+ int_from_fixed(header
->pfxStart
.x
);
2040 pt
.y
= y
- int_from_fixed(header
->pfxStart
.y
);
2041 PATH_AddEntry(pPath
, &pt
, PT_MOVETO
);
2043 curve
= (TTPOLYCURVE
*)(header
+ 1);
2045 while ((char *)curve
< (char *)header
+ header
->cb
)
2047 /*DPRINT1("curve->wType %d\n", curve->wType);*/
2049 switch(curve
->wType
)
2055 for (i
= 0; i
< curve
->cpfx
; i
++)
2057 pt
.x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
2058 pt
.y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
2059 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
2064 case TT_PRIM_QSPLINE
:
2065 case TT_PRIM_CSPLINE
:
2069 POINT
*pts
= ExAllocatePoolWithTag(PagedPool
, (curve
->cpfx
+ 1) * sizeof(POINT
), TAG_PATH
);
2071 if (!pts
) goto cleanup
;
2073 ptfx
= *(POINTFX
*)((char *)curve
- sizeof(POINTFX
));
2075 pts
[0].x
= x
+ int_from_fixed(ptfx
.x
);
2076 pts
[0].y
= y
- int_from_fixed(ptfx
.y
);
2078 for (i
= 0; i
< curve
->cpfx
; i
++)
2080 pts
[i
+ 1].x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
2081 pts
[i
+ 1].y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
2084 PATH_BezierTo(pPath
, pts
, curve
->cpfx
+ 1);
2086 ExFreePoolWithTag(pts
, TAG_PATH
);
2091 DPRINT1("Unknown curve type %04x\n", curve
->wType
);
2095 curve
= (TTPOLYCURVE
*)&curve
->apfx
[curve
->cpfx
];
2097 header
= (TTPOLYGONHEADER
*)((char *)header
+ header
->cb
);
2103 IntGdiCloseFigure( pPath
);
2104 PATH_UnlockPath( pPath
);
2108 /**********************************************************************
2113 PATH_ExtTextOut(PDC dc
, INT x
, INT y
, UINT flags
, const RECTL
*lprc
,
2114 LPCWSTR str
, UINT count
, const INT
*dx
)
2117 POINT offset
= {0, 0};
2119 if (!count
) return TRUE
;
2121 for (idx
= 0; idx
< count
; idx
++)
2123 MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
2128 dwSize
= ftGdiGetGlyphOutline( dc
,
2130 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2136 if (dwSize
== GDI_ERROR
) return FALSE
;
2138 /* Add outline only if char is printable */
2141 outline
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_PATH
);
2142 if (!outline
) return FALSE
;
2144 ftGdiGetGlyphOutline( dc
,
2146 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2153 PATH_add_outline(dc
, x
+ offset
.x
, y
+ offset
.y
, outline
, dwSize
);
2155 ExFreePoolWithTag(outline
, TAG_PATH
);
2160 if (flags
& ETO_PDY
)
2162 offset
.x
+= dx
[idx
* 2];
2163 offset
.y
+= dx
[idx
* 2 + 1];
2166 offset
.x
+= dx
[idx
];
2170 offset
.x
+= gm
.gmCellIncX
;
2171 offset
.y
+= gm
.gmCellIncY
;
2178 /***********************************************************************
2179 * Exported functions
2184 NtGdiAbortPath(HDC hDC
)
2187 PDC dc
= DC_LockDc ( hDC
);
2190 EngSetLastError(ERROR_INVALID_HANDLE
);
2194 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2201 PATH_EmptyPath(pPath
);
2203 PATH_UnlockPath(pPath
);
2204 dc
->dclevel
.flPath
&= ~DCPATH_ACTIVE
;
2212 NtGdiBeginPath( HDC hDC
)
2217 dc
= DC_LockDc ( hDC
);
2220 EngSetLastError(ERROR_INVALID_HANDLE
);
2224 /* If path is already open, do nothing. Check if not Save DC state */
2225 if ((dc
->dclevel
.flPath
& DCPATH_ACTIVE
) && !(dc
->dclevel
.flPath
& DCPATH_SAVE
))
2231 if ( dc
->dclevel
.hPath
)
2233 DPRINT("BeginPath 1 0x%p\n", dc
->dclevel
.hPath
);
2234 if ( !(dc
->dclevel
.flPath
& DCPATH_SAVE
) )
2235 { // Remove previous handle.
2236 if (!PATH_Delete(dc
->dclevel
.hPath
))
2243 { // Clear flags and Handle.
2244 dc
->dclevel
.flPath
&= ~(DCPATH_SAVE
|DCPATH_ACTIVE
);
2245 dc
->dclevel
.hPath
= NULL
;
2248 pPath
= PATH_AllocPathWithHandle();
2251 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2254 dc
->dclevel
.flPath
|= DCPATH_ACTIVE
; // Set active ASAP!
2256 dc
->dclevel
.hPath
= pPath
->BaseObject
.hHmgr
;
2258 DPRINT("BeginPath 2 h 0x%p p 0x%p\n", dc
->dclevel
.hPath
, pPath
);
2259 // Path handles are shared. Also due to recursion with in the same thread.
2260 GDIOBJ_vUnlockObject((POBJ
)pPath
); // Unlock
2261 pPath
= PATH_LockPath(dc
->dclevel
.hPath
); // Share Lock.
2263 /* Make sure that path is empty */
2264 PATH_EmptyPath( pPath
);
2266 /* Initialize variables for new path */
2267 pPath
->newStroke
= TRUE
;
2268 pPath
->state
= PATH_Open
;
2270 PATH_UnlockPath(pPath
);
2277 NtGdiCloseFigure(HDC hDC
)
2279 BOOL Ret
= FALSE
; // Default to failure
2283 DPRINT("Enter %s\n", __FUNCTION__
);
2285 pDc
= DC_LockDc(hDC
);
2288 EngSetLastError(ERROR_INVALID_PARAMETER
);
2291 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2298 if (pPath
->state
==PATH_Open
)
2300 IntGdiCloseFigure(pPath
);
2305 // FIXME: Check if lasterror is set correctly
2306 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2309 PATH_UnlockPath( pPath
);
2316 NtGdiEndPath(HDC hDC
)
2320 PDC dc
= DC_LockDc ( hDC
);
2324 EngSetLastError(ERROR_INVALID_HANDLE
);
2328 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2334 /* Check that path is currently being constructed */
2335 if ( (pPath
->state
!= PATH_Open
) || !(dc
->dclevel
.flPath
& DCPATH_ACTIVE
) )
2337 DPRINT1("EndPath ERROR! 0x%p\n", dc
->dclevel
.hPath
);
2338 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2341 /* Set flag to indicate that path is finished */
2344 DPRINT("EndPath 0x%p\n", dc
->dclevel
.hPath
);
2345 pPath
->state
= PATH_Closed
;
2346 dc
->dclevel
.flPath
&= ~DCPATH_ACTIVE
;
2348 PATH_UnlockPath( pPath
);
2355 NtGdiFillPath(HDC hDC
)
2362 dc
= DC_LockDc(hDC
);
2365 EngSetLastError(ERROR_INVALID_PARAMETER
);
2369 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2376 DC_vPrepareDCsForBlit(dc
, dc
->rosdc
.CombinedClip
->rclBounds
,
2377 NULL
, dc
->rosdc
.CombinedClip
->rclBounds
);
2379 pdcattr
= dc
->pdcattr
;
2381 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2382 DC_vUpdateLineBrush(dc
);
2384 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
2385 DC_vUpdateFillBrush(dc
);
2387 ret
= PATH_FillPath( dc
, pPath
);
2390 /* FIXME: Should the path be emptied even if conversion
2392 PATH_EmptyPath( pPath
);
2395 PATH_UnlockPath( pPath
);
2396 DC_vFinishBlit(dc
, NULL
);
2403 NtGdiFlattenPath(HDC hDC
)
2409 DPRINT("Enter %s\n", __FUNCTION__
);
2411 pDc
= DC_LockDc(hDC
);
2414 EngSetLastError(ERROR_INVALID_HANDLE
);
2418 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2421 DC_UnlockDc ( pDc
);
2424 if (pPath
->state
== PATH_Open
)
2425 Ret
= PATH_FlattenPath(pPath
);
2427 PATH_UnlockPath( pPath
);
2432 _Success_(return != FALSE
)
2437 _Out_ PDWORD pdwOut
)
2440 BOOL bResult
= TRUE
;
2442 if (!(pDc
= DC_LockDc(hdc
)))
2444 EngSetLastError(ERROR_INVALID_PARAMETER
);
2450 ProbeForWrite(pdwOut
, sizeof(DWORD
), 1);
2451 *pdwOut
= pDc
->dclevel
.laPath
.eMiterLimit
;
2453 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2455 SetLastNtError(_SEH2_GetExceptionCode());
2476 DC
*dc
= DC_LockDc(hDC
);
2479 DPRINT1("Can't lock dc!\n");
2480 EngSetLastError(ERROR_INVALID_PARAMETER
);
2484 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2491 if (pPath
->state
!= PATH_Closed
)
2493 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2499 ret
= pPath
->numEntriesUsed
;
2501 else if(nSize
<pPath
->numEntriesUsed
)
2503 EngSetLastError(ERROR_INVALID_PARAMETER
);
2510 memcpy(Points
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
2511 memcpy(Types
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
2513 /* Convert the points to logical coordinates */
2514 if (!GdiPathDPtoLP(dc
, Points
, pPath
->numEntriesUsed
))
2516 EngSetLastError(ERROR_ARITHMETIC_OVERFLOW
);
2520 ret
= pPath
->numEntriesUsed
;
2522 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2524 SetLastNtError(_SEH2_GetExceptionCode());
2530 PATH_UnlockPath( pPath
);
2537 NtGdiPathToRegion(HDC hDC
)
2544 DPRINT("Enter %s\n", __FUNCTION__
);
2546 pDc
= DC_LockDc(hDC
);
2549 EngSetLastError(ERROR_INVALID_PARAMETER
);
2553 pdcattr
= pDc
->pdcattr
;
2555 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2558 DC_UnlockDc ( pDc
);
2562 if (pPath
->state
!=PATH_Closed
)
2564 // FIXME: Check that setlasterror is being called correctly
2565 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2569 /* FIXME: Should we empty the path even if conversion failed? */
2570 if(PATH_PathToRegion(pPath
, pdcattr
->jFillMode
, &hrgnRval
))
2571 PATH_EmptyPath(pPath
);
2574 PATH_UnlockPath( pPath
);
2584 IN OUT OPTIONAL PDWORD pdwOut
)
2587 gxf_long worker
, worker1
;
2588 BOOL bResult
= TRUE
;
2590 if (!(pDc
= DC_LockDc(hdc
)))
2592 EngSetLastError(ERROR_INVALID_PARAMETER
);
2597 worker1
.f
= pDc
->dclevel
.laPath
.eMiterLimit
;
2598 pDc
->dclevel
.laPath
.eMiterLimit
= worker
.f
;
2604 ProbeForWrite(pdwOut
, sizeof(DWORD
), 1);
2605 *pdwOut
= worker1
.l
;
2607 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2609 SetLastNtError(_SEH2_GetExceptionCode());
2621 NtGdiStrokeAndFillPath(HDC hDC
)
2628 DPRINT1("Enter %s\n", __FUNCTION__
);
2630 if (!(pDc
= DC_LockDc(hDC
)))
2632 EngSetLastError(ERROR_INVALID_PARAMETER
);
2635 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2638 DC_UnlockDc ( pDc
);
2642 DC_vPrepareDCsForBlit(pDc
, pDc
->rosdc
.CombinedClip
->rclBounds
,
2643 NULL
, pDc
->rosdc
.CombinedClip
->rclBounds
);
2645 pdcattr
= pDc
->pdcattr
;
2647 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
2648 DC_vUpdateFillBrush(pDc
);
2650 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2651 DC_vUpdateLineBrush(pDc
);
2653 bRet
= PATH_FillPath(pDc
, pPath
);
2654 if (bRet
) bRet
= PATH_StrokePath(pDc
, pPath
);
2655 if (bRet
) PATH_EmptyPath(pPath
);
2657 PATH_UnlockPath( pPath
);
2658 DC_vFinishBlit(pDc
, NULL
);
2665 NtGdiStrokePath(HDC hDC
)
2672 DPRINT("Enter %s\n", __FUNCTION__
);
2674 if (!(pDc
= DC_LockDc(hDC
)))
2676 EngSetLastError(ERROR_INVALID_PARAMETER
);
2679 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2682 DC_UnlockDc ( pDc
);
2686 DC_vPrepareDCsForBlit(pDc
, pDc
->rosdc
.CombinedClip
->rclBounds
,
2687 NULL
, pDc
->rosdc
.CombinedClip
->rclBounds
);
2689 pdcattr
= pDc
->pdcattr
;
2691 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2692 DC_vUpdateLineBrush(pDc
);
2694 bRet
= PATH_StrokePath(pDc
, pPath
);
2696 DC_vFinishBlit(pDc
, NULL
);
2697 PATH_EmptyPath(pPath
);
2699 PATH_UnlockPath( pPath
);
2706 NtGdiWidenPath(HDC hDC
)
2709 PDC pdc
= DC_LockDc ( hDC
);
2712 EngSetLastError(ERROR_INVALID_PARAMETER
);
2715 Ret
= PATH_WidenPath(pdc
);
2716 DC_UnlockDc ( pdc
);