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
17 #pragma warning(disable:4244)
20 #define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
21 #define GROW_FACTOR_NUMER 2 /* Numerator of grow factor for the array */
22 #define GROW_FACTOR_DENOM 1 /* Denominator of grow factor */
24 /***********************************************************************
28 /* PATH_DestroyGdiPath
30 * Destroys a GdiPath structure (frees the memory in the arrays).
34 PATH_DestroyGdiPath ( PPATH pPath
)
38 if (pPath
->pPoints
) ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
39 if (pPath
->pFlags
) ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
44 PATH_Delete(HPATH hPath
)
47 if (!hPath
) return FALSE
;
48 pPath
= PATH_LockPath( hPath
);
49 if (!pPath
) return FALSE
;
50 PATH_DestroyGdiPath( pPath
);
51 GDIOBJ_vDeleteObject(&pPath
->BaseObject
);
58 IntGdiCloseFigure(PPATH pPath
)
60 ASSERT(pPath
->state
== PATH_Open
);
62 // FIXME: Shouldn't we draw a line to the beginning of the figure?
63 // Set PT_CLOSEFIGURE on the last entry and start a new stroke
64 if(pPath
->numEntriesUsed
)
66 pPath
->pFlags
[pPath
->numEntriesUsed
-1]|=PT_CLOSEFIGURE
;
67 pPath
->newStroke
=TRUE
;
71 /* MSDN: This fails if the device coordinates exceed 27 bits, or if the converted
72 logical coordinates exceed 32 bits. */
75 GdiPathDPtoLP(PDC pdc
, PPOINT ppt
, INT count
)
79 XFORMOBJ_vInit(&xo
, &pdc
->pdcattr
->mxDeviceToWorld
);
80 return XFORMOBJ_bApplyXform(&xo
, XF_LTOL
, count
, (PPOINTL
)ppt
, (PPOINTL
)ppt
);
89 PATH_FillPath( PDC dc
, PPATH pPath
)
91 //INT mapMode, graphicsMode;
92 //SIZE ptViewportExt, ptWindowExt;
93 //POINTL ptViewportOrg, ptWindowOrg;
96 PDC_ATTR pdcattr
= dc
->pdcattr
;
98 if( pPath
->state
!= PATH_Closed
)
100 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
104 if( PATH_PathToRegion( pPath
, pdcattr
->jFillMode
, &hrgn
))
106 /* Since PaintRgn interprets the region as being in logical coordinates
107 * but the points we store for the path are already in device
108 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
109 * Using SaveDC to save information about the mapping mode / world
110 * transform would be easier but would require more overhead, especially
111 * now that SaveDC saves the current path.
114 /* Save the information about the old mapping mode */
115 //mapMode = pdcattr->iMapMode;
116 //ptViewportExt = pdcattr->szlViewportExt;
117 //ptViewportOrg = pdcattr->ptlViewportOrg;
118 //ptWindowExt = pdcattr->szlWindowExt;
119 //ptWindowOrg = pdcattr->ptlWindowOrg;
121 /* Save world transform
122 * NB: The Windows documentation on world transforms would lead one to
123 * believe that this has to be done only in GM_ADVANCED; however, my
124 * tests show that resetting the graphics mode to GM_COMPATIBLE does
125 * not reset the world transform.
127 MatrixS2XForm(&xform
, &dc
->pdcattr
->mxWorldToPage
);
130 // IntGdiSetMapMode( dc, MM_TEXT );
131 // pdcattr->ptlViewportOrg.x = 0;
132 // pdcattr->ptlViewportOrg.y = 0;
133 // pdcattr->ptlWindowOrg.x = 0;
134 // pdcattr->ptlWindowOrg.y = 0;
136 // graphicsMode = pdcattr->iGraphicsMode;
137 // pdcattr->iGraphicsMode = GM_ADVANCED;
138 // IntGdiModifyWorldTransform( dc, &xform, MWT_IDENTITY );
139 // pdcattr->iGraphicsMode = graphicsMode;
141 /* Paint the region */
142 IntGdiPaintRgn( dc
, hrgn
);
143 GreDeleteObject( hrgn
);
144 /* Restore the old mapping mode */
145 // IntGdiSetMapMode( dc, mapMode );
146 // pdcattr->szlViewportExt = ptViewportExt;
147 // pdcattr->ptlViewportOrg = ptViewportOrg;
148 // pdcattr->szlWindowExt = ptWindowExt;
149 // pdcattr->ptlWindowOrg = ptWindowOrg;
151 /* Go to GM_ADVANCED temporarily to restore the world transform */
152 //graphicsMode = pdcattr->iGraphicsMode;
153 // pdcattr->iGraphicsMode = GM_ADVANCED;
154 // IntGdiModifyWorldTransform( dc, &xform, MWT_MAX+1 );
155 // pdcattr->iGraphicsMode = graphicsMode;
163 * Initializes the GdiPath structure.
167 PATH_InitGdiPath ( PPATH pPath
)
171 pPath
->state
=PATH_Null
;
174 pPath
->numEntriesUsed
=0;
175 pPath
->numEntriesAllocated
=0;
178 /* PATH_AssignGdiPath
180 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
181 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
182 * not just the pointers. Since this means that the arrays in pPathDest may
183 * need to be resized, pPathDest should have been initialized using
184 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
185 * not a copy constructor).
186 * Returns TRUE if successful, else FALSE.
190 PATH_AssignGdiPath ( PPATH pPathDest
, const PPATH pPathSrc
)
192 ASSERT(pPathDest
!=NULL
&& pPathSrc
!=NULL
);
194 /* Make sure destination arrays are big enough */
195 if ( !PATH_ReserveEntries(pPathDest
, pPathSrc
->numEntriesUsed
) )
198 /* Perform the copy operation */
199 memcpy(pPathDest
->pPoints
, pPathSrc
->pPoints
,
200 sizeof(POINT
)*pPathSrc
->numEntriesUsed
);
201 memcpy(pPathDest
->pFlags
, pPathSrc
->pFlags
,
202 sizeof(BYTE
)*pPathSrc
->numEntriesUsed
);
204 pPathDest
->state
=pPathSrc
->state
;
205 pPathDest
->numEntriesUsed
=pPathSrc
->numEntriesUsed
;
206 pPathDest
->newStroke
=pPathSrc
->newStroke
;
212 * Should be called when a MoveTo is performed on a DC that has an
213 * open path. This starts a new stroke. Returns TRUE if successful, else
218 PATH_MoveTo ( PDC dc
)
220 PPATH pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
221 if (!pPath
) return FALSE
;
223 /* Check that path is open */
224 if ( pPath
->state
!= PATH_Open
)
226 PATH_UnlockPath( pPath
);
227 /* FIXME: Do we have to call SetLastError? */
230 /* Start a new stroke */
231 pPath
->newStroke
= TRUE
;
232 PATH_UnlockPath( pPath
);
238 * Should be called when a LineTo is performed on a DC that has an
239 * open path. This adds a PT_LINETO entry to the path (and possibly
240 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
241 * Returns TRUE if successful, else FALSE.
245 PATH_LineTo ( PDC dc
, INT x
, INT y
)
249 POINT point
, pointCurPos
;
251 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
252 if (!pPath
) return FALSE
;
254 /* Check that path is open */
255 if ( pPath
->state
!= PATH_Open
)
257 PATH_UnlockPath( pPath
);
261 /* Convert point to device coordinates */
264 CoordLPtoDP ( dc
, &point
);
266 /* Add a PT_MOVETO if necessary */
267 if ( pPath
->newStroke
)
269 pPath
->newStroke
= FALSE
;
270 IntGetCurrentPositionEx ( dc
, &pointCurPos
);
271 CoordLPtoDP ( dc
, &pointCurPos
);
272 if ( !PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
) )
274 PATH_UnlockPath( pPath
);
279 /* Add a PT_LINETO entry */
280 Ret
= PATH_AddEntry(pPath
, &point
, PT_LINETO
);
281 PATH_UnlockPath( pPath
);
287 * Should be called when a call to Rectangle is performed on a DC that has
288 * an open path. Returns TRUE if successful, else FALSE.
292 PATH_Rectangle ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
)
295 POINT corners
[2], pointTemp
;
298 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
299 if (!pPath
) return FALSE
;
301 /* Check that path is open */
302 if ( pPath
->state
!= PATH_Open
)
304 PATH_UnlockPath( pPath
);
308 /* Convert points to device coordinates */
313 IntLPtoDP ( dc
, corners
, 2 );
315 /* Make sure first corner is top left and second corner is bottom right */
316 if ( corners
[0].x
> corners
[1].x
)
319 corners
[0].x
=corners
[1].x
;
322 if ( corners
[0].y
> corners
[1].y
)
325 corners
[0].y
=corners
[1].y
;
329 /* In GM_COMPATIBLE, don't include bottom and right edges */
330 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
336 /* Close any previous figure */
337 IntGdiCloseFigure(pPath
);
339 /* Add four points to the path */
340 pointTemp
.x
=corners
[1].x
;
341 pointTemp
.y
=corners
[0].y
;
342 if ( !PATH_AddEntry(pPath
, &pointTemp
, PT_MOVETO
) )
344 PATH_UnlockPath( pPath
);
347 if ( !PATH_AddEntry(pPath
, corners
, PT_LINETO
) )
349 PATH_UnlockPath( pPath
);
352 pointTemp
.x
=corners
[0].x
;
353 pointTemp
.y
=corners
[1].y
;
354 if ( !PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
) )
356 PATH_UnlockPath( pPath
);
359 if ( !PATH_AddEntry(pPath
, corners
+1, PT_LINETO
) )
361 PATH_UnlockPath( pPath
);
365 /* Close the rectangle figure */
366 IntGdiCloseFigure(pPath
) ;
367 PATH_UnlockPath( pPath
);
373 * Should be called when a call to RoundRect is performed on a DC that has
374 * an open path. Returns TRUE if successful, else FALSE.
376 * FIXME: It adds the same entries to the path as windows does, but there
377 * is an error in the bezier drawing code so that there are small pixel-size
378 * gaps when the resulting path is drawn by StrokePath()
380 BOOL FASTCALL
PATH_RoundRect(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
, INT ell_width
, INT ell_height
)
383 POINT corners
[2], pointTemp
;
384 FLOAT_POINT ellCorners
[2];
386 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
387 if (!pPath
) return FALSE
;
389 /* Check that path is open */
390 if(pPath
->state
!=PATH_Open
)
392 PATH_UnlockPath( pPath
);
396 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
398 PATH_UnlockPath( pPath
);
402 /* Add points to the roundrect path */
403 ellCorners
[0].x
= corners
[1].x
-ell_width
;
404 ellCorners
[0].y
= corners
[0].y
;
405 ellCorners
[1].x
= corners
[1].x
;
406 ellCorners
[1].y
= corners
[0].y
+ell_height
;
407 if(!PATH_DoArcPart(pPath
, ellCorners
, 0, -M_PI_2
, PT_MOVETO
))
409 PATH_UnlockPath( pPath
);
412 pointTemp
.x
= corners
[0].x
+ell_width
/2;
413 pointTemp
.y
= corners
[0].y
;
414 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
416 PATH_UnlockPath( pPath
);
419 ellCorners
[0].x
= corners
[0].x
;
420 ellCorners
[1].x
= corners
[0].x
+ell_width
;
421 if(!PATH_DoArcPart(pPath
, ellCorners
, -M_PI_2
, -M_PI
, FALSE
))
423 PATH_UnlockPath( pPath
);
426 pointTemp
.x
= corners
[0].x
;
427 pointTemp
.y
= corners
[1].y
-ell_height
/2;
428 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
430 PATH_UnlockPath( pPath
);
433 ellCorners
[0].y
= corners
[1].y
-ell_height
;
434 ellCorners
[1].y
= corners
[1].y
;
435 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI
, M_PI_2
, FALSE
))
437 PATH_UnlockPath( pPath
);
440 pointTemp
.x
= corners
[1].x
-ell_width
/2;
441 pointTemp
.y
= corners
[1].y
;
442 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
444 PATH_UnlockPath( pPath
);
447 ellCorners
[0].x
= corners
[1].x
-ell_width
;
448 ellCorners
[1].x
= corners
[1].x
;
449 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI_2
, 0, FALSE
))
451 PATH_UnlockPath( pPath
);
455 IntGdiCloseFigure(pPath
);
456 PATH_UnlockPath( pPath
);
462 * Should be called when a call to Ellipse is performed on a DC that has
463 * an open path. This adds four Bezier splines representing the ellipse
464 * to the path. Returns TRUE if successful, else FALSE.
468 PATH_Ellipse ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
)
471 /* TODO: This should probably be revised to call PATH_AngleArc */
472 /* (once it exists) */
473 BOOL Ret
= PATH_Arc ( dc
, x1
, y1
, x2
, y2
, x1
, (y1
+y2
)/2, x1
, (y1
+y2
)/2, GdiTypeArc
);
476 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
477 if (!pPath
) return FALSE
;
478 IntGdiCloseFigure(pPath
);
479 PATH_UnlockPath( pPath
);
486 * Should be called when a call to Arc is performed on a DC that has
487 * an open path. This adds up to five Bezier splines representing the arc
488 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
489 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
490 * -1 we add 1 extra line from the current DC position to the starting position
491 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
496 PATH_Arc ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
,
497 INT xStart
, INT yStart
, INT xEnd
, INT yEnd
, INT lines
)
499 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
=0.0;
500 /* Initialize angleEndQuadrant to silence gcc's warning */
502 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
503 POINT centre
, pointCurPos
;
504 BOOL start
, end
, Ret
= TRUE
;
509 /* FIXME: This function should check for all possible error returns */
510 /* FIXME: Do we have to respect newStroke? */
514 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
515 if (!pPath
) return FALSE
;
517 clockwise
= ((dc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
519 /* Check that path is open */
520 if ( pPath
->state
!= PATH_Open
)
526 /* Check for zero height / width */
527 /* FIXME: Only in GM_COMPATIBLE? */
528 if ( x1
==x2
|| y1
==y2
)
533 /* Convert points to device coordinates */
534 corners
[0].x
=(FLOAT
)x1
;
535 corners
[0].y
=(FLOAT
)y1
;
536 corners
[1].x
=(FLOAT
)x2
;
537 corners
[1].y
=(FLOAT
)y2
;
538 pointStart
.x
=(FLOAT
)xStart
;
539 pointStart
.y
=(FLOAT
)yStart
;
540 pointEnd
.x
=(FLOAT
)xEnd
;
541 pointEnd
.y
=(FLOAT
)yEnd
;
542 INTERNAL_LPTODP_FLOAT(dc
, corners
);
543 INTERNAL_LPTODP_FLOAT(dc
, corners
+1);
544 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
);
545 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
);
547 /* Make sure first corner is top left and second corner is bottom right */
548 if ( corners
[0].x
> corners
[1].x
)
551 corners
[0].x
=corners
[1].x
;
554 if ( corners
[0].y
> corners
[1].y
)
557 corners
[0].y
=corners
[1].y
;
561 /* Compute start and end angle */
562 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
563 angleStart
=atan2(y
, x
);
564 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
565 angleEnd
=atan2(y
, x
);
567 /* Make sure the end angle is "on the right side" of the start angle */
570 if ( angleEnd
<= angleStart
)
573 ASSERT(angleEnd
>=angleStart
);
578 if(angleEnd
>=angleStart
)
581 ASSERT(angleEnd
<=angleStart
);
585 /* In GM_COMPATIBLE, don't include bottom and right edges */
586 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
592 /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
593 if(lines
==GdiTypeArcTo
&& pPath
->newStroke
) // -1
595 pPath
->newStroke
=FALSE
;
596 IntGetCurrentPositionEx ( dc
, &pointCurPos
);
597 CoordLPtoDP(dc
, &pointCurPos
);
598 if(!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
605 /* Add the arc to the path with one Bezier spline per quadrant that the
611 /* Determine the start and end angles for this quadrant */
614 angleStartQuadrant
=angleStart
;
616 angleEndQuadrant
=(floor(angleStart
/M_PI_2
)+1.0)*M_PI_2
;
618 angleEndQuadrant
=(ceil(angleStart
/M_PI_2
)-1.0)*M_PI_2
;
622 angleStartQuadrant
=angleEndQuadrant
;
624 angleEndQuadrant
+=M_PI_2
;
626 angleEndQuadrant
-=M_PI_2
;
629 /* Have we reached the last part of the arc? */
630 if ( (clockwise
&& angleEnd
<angleEndQuadrant
)
631 || (!clockwise
&& angleEnd
>angleEndQuadrant
)
634 /* Adjust the end angle for this quadrant */
635 angleEndQuadrant
= angleEnd
;
639 /* Add the Bezier spline to the path */
640 PATH_DoArcPart ( pPath
, corners
, angleStartQuadrant
, angleEndQuadrant
,
641 start
? (lines
==GdiTypeArcTo
? PT_LINETO
: PT_MOVETO
) : FALSE
); // -1
645 /* chord: close figure. pie: add line and close figure */
646 if (lines
==GdiTypeChord
) // 1
648 IntGdiCloseFigure(pPath
);
650 else if (lines
==GdiTypePie
) // 2
652 centre
.x
= (corners
[0].x
+corners
[1].x
)/2;
653 centre
.y
= (corners
[0].y
+corners
[1].y
)/2;
654 if(!PATH_AddEntry(pPath
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
658 PATH_UnlockPath( pPath
);
664 PATH_PolyBezierTo ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
674 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
675 if (!pPath
) return FALSE
;
677 /* Check that path is open */
678 if ( pPath
->state
!= PATH_Open
)
680 PATH_UnlockPath( pPath
);
684 /* Add a PT_MOVETO if necessary */
685 if ( pPath
->newStroke
)
687 pPath
->newStroke
=FALSE
;
688 IntGetCurrentPositionEx ( dc
, &pt
);
689 CoordLPtoDP ( dc
, &pt
);
690 if ( !PATH_AddEntry(pPath
, &pt
, PT_MOVETO
) )
692 PATH_UnlockPath( pPath
);
697 for(i
= 0; i
< cbPoints
; i
++)
700 CoordLPtoDP ( dc
, &pt
);
701 PATH_AddEntry(pPath
, &pt
, PT_BEZIERTO
);
703 PATH_UnlockPath( pPath
);
709 PATH_PolyBezier ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
719 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
720 if (!pPath
) return FALSE
;
722 /* Check that path is open */
723 if ( pPath
->state
!= PATH_Open
)
725 PATH_UnlockPath( pPath
);
729 for ( i
= 0; i
< cbPoints
; i
++ )
732 CoordLPtoDP ( dc
, &pt
);
733 PATH_AddEntry ( pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_BEZIERTO
);
735 PATH_UnlockPath( pPath
);
741 PATH_PolyDraw(PDC dc
, const POINT
*pts
, const BYTE
*types
, DWORD cbPoints
)
744 POINT lastmove
, orig_pos
;
747 BOOL State
= FALSE
, Ret
= FALSE
;
749 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
750 if (!pPath
) return FALSE
;
752 if ( pPath
->state
!= PATH_Open
)
754 PATH_UnlockPath( pPath
);
758 pdcattr
= dc
->pdcattr
;
760 lastmove
.x
= orig_pos
.x
= pdcattr
->ptlCurrent
.x
;
761 lastmove
.y
= orig_pos
.y
= pdcattr
->ptlCurrent
.y
;
763 i
= pPath
->numEntriesUsed
;
768 if (pPath
->pFlags
[i
] == PT_MOVETO
)
770 lastmove
.x
= pPath
->pPoints
[i
].x
;
771 lastmove
.y
= pPath
->pPoints
[i
].y
;
772 if (!GdiPathDPtoLP(dc
, &lastmove
, 1))
774 PATH_UnlockPath( pPath
);
781 for (i
= 0; i
< cbPoints
; i
++)
783 if (types
[i
] == PT_MOVETO
)
785 pPath
->newStroke
= TRUE
;
786 lastmove
.x
= pts
[i
].x
;
787 lastmove
.y
= pts
[i
].y
;
789 else if((types
[i
] & ~PT_CLOSEFIGURE
) == PT_LINETO
)
791 PATH_LineTo(dc
, pts
[i
].x
, pts
[i
].y
);
793 else if(types
[i
] == PT_BEZIERTO
)
795 if (!((i
+ 2 < cbPoints
) && (types
[i
+ 1] == PT_BEZIERTO
)
796 && ((types
[i
+ 2] & ~PT_CLOSEFIGURE
) == PT_BEZIERTO
)))
798 PATH_PolyBezierTo(dc
, &(pts
[i
]), 3);
804 pdcattr
->ptlCurrent
.x
= pts
[i
].x
;
805 pdcattr
->ptlCurrent
.y
= pts
[i
].y
;
808 if (types
[i
] & PT_CLOSEFIGURE
)
810 pPath
->pFlags
[pPath
->numEntriesUsed
-1] |= PT_CLOSEFIGURE
;
811 pPath
->newStroke
= TRUE
;
812 pdcattr
->ptlCurrent
.x
= lastmove
.x
;
813 pdcattr
->ptlCurrent
.y
= lastmove
.y
;
821 if ((pdcattr
->ptlCurrent
.x
!= orig_pos
.x
) || (pdcattr
->ptlCurrent
.y
!= orig_pos
.y
))
823 pPath
->newStroke
= TRUE
;
824 pdcattr
->ptlCurrent
.x
= orig_pos
.x
;
825 pdcattr
->ptlCurrent
.y
= orig_pos
.y
;
829 if (State
) // State change?
831 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
832 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
833 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
835 PATH_UnlockPath( pPath
);
841 PATH_Polyline ( 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
);
860 for ( i
= 0; i
< cbPoints
; i
++ )
863 CoordLPtoDP ( dc
, &pt
);
864 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_LINETO
);
866 PATH_UnlockPath( pPath
);
872 PATH_PolylineTo ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
882 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
883 if (!pPath
) return FALSE
;
885 /* Check that path is open */
886 if ( pPath
->state
!= PATH_Open
)
888 PATH_UnlockPath( pPath
);
892 /* Add a PT_MOVETO if necessary */
893 if ( pPath
->newStroke
)
895 pPath
->newStroke
= FALSE
;
896 IntGetCurrentPositionEx ( dc
, &pt
);
897 CoordLPtoDP ( dc
, &pt
);
898 if ( !PATH_AddEntry(pPath
, &pt
, PT_MOVETO
) )
900 PATH_UnlockPath( pPath
);
905 for(i
= 0; i
< cbPoints
; i
++)
908 CoordLPtoDP ( dc
, &pt
);
909 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
911 PATH_UnlockPath( pPath
);
918 PATH_Polygon ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
927 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
928 if (!pPath
) return FALSE
;
930 /* Check that path is open */
931 if ( pPath
->state
!= PATH_Open
)
933 PATH_UnlockPath( pPath
);
937 for(i
= 0; i
< cbPoints
; i
++)
940 CoordLPtoDP ( dc
, &pt
);
941 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
:
942 ((i
== cbPoints
-1) ? PT_LINETO
| PT_CLOSEFIGURE
:
945 PATH_UnlockPath( pPath
);
951 PATH_PolyPolygon ( PDC dc
, const POINT
* pts
, const INT
* counts
, UINT polygons
)
954 ULONG poly
, point
, i
;
962 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
963 if (!pPath
) return FALSE
;
965 /* Check that path is open */
966 if ( pPath
->state
!= PATH_Open
)
968 PATH_UnlockPath( pPath
);
972 for(i
= 0, poly
= 0; poly
< polygons
; poly
++)
974 for(point
= 0; point
< (ULONG
) counts
[poly
]; point
++, i
++)
977 CoordLPtoDP ( dc
, &pt
);
978 if(point
== 0) startpt
= pt
;
979 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
981 /* Win98 adds an extra line to close the figure for some reason */
982 PATH_AddEntry(pPath
, &startpt
, PT_LINETO
| PT_CLOSEFIGURE
);
984 PATH_UnlockPath( pPath
);
990 PATH_PolyPolyline ( PDC dc
, const POINT
* pts
, const DWORD
* counts
, DWORD polylines
)
993 ULONG poly
, point
, i
;
999 ASSERT ( polylines
);
1001 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
1002 if (!pPath
) return FALSE
;
1004 /* Check that path is open */
1005 if ( pPath
->state
!= PATH_Open
)
1007 PATH_UnlockPath( pPath
);
1011 for(i
= 0, poly
= 0; poly
< polylines
; poly
++)
1013 for(point
= 0; point
< counts
[poly
]; point
++, i
++)
1016 CoordLPtoDP ( dc
, &pt
);
1017 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1020 PATH_UnlockPath( pPath
);
1025 /* PATH_CheckCorners
1027 * Helper function for PATH_RoundRect() and PATH_Rectangle()
1029 BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
)
1032 PDC_ATTR pdcattr
= dc
->pdcattr
;
1034 /* Convert points to device coordinates */
1039 CoordLPtoDP(dc
, &corners
[0]);
1040 CoordLPtoDP(dc
, &corners
[1]);
1042 /* Make sure first corner is top left and second corner is bottom right */
1043 if(corners
[0].x
>corners
[1].x
)
1046 corners
[0].x
=corners
[1].x
;
1049 if(corners
[0].y
>corners
[1].y
)
1052 corners
[0].y
=corners
[1].y
;
1056 /* In GM_COMPATIBLE, don't include bottom and right edges */
1057 if(pdcattr
->iGraphicsMode
==GM_COMPATIBLE
)
1067 /* PATH_AddFlatBezier
1072 PATH_AddFlatBezier ( PPATH pPath
, POINT
*pt
, BOOL closed
)
1077 pts
= GDI_Bezier( pt
, 4, &no
);
1078 if ( !pts
) return FALSE
;
1080 for(i
= 1; i
< no
; i
++)
1081 PATH_AddEntry(pPath
, &pts
[i
], (i
== no
-1 && closed
) ? PT_LINETO
| PT_CLOSEFIGURE
: PT_LINETO
);
1083 ExFreePoolWithTag(pts
, TAG_BEZIER
);
1089 * Replaces Beziers with line segments
1094 PATH_FlattenPath(PPATH pPath
)
1099 RtlZeroMemory(&newPath
, sizeof(newPath
));
1100 newPath
.state
= PATH_Open
;
1101 for(srcpt
= 0; srcpt
< pPath
->numEntriesUsed
; srcpt
++) {
1102 switch(pPath
->pFlags
[srcpt
] & ~PT_CLOSEFIGURE
) {
1105 PATH_AddEntry(&newPath
, &pPath
->pPoints
[srcpt
], pPath
->pFlags
[srcpt
]);
1108 PATH_AddFlatBezier(&newPath
, &pPath
->pPoints
[srcpt
-1], pPath
->pFlags
[srcpt
+2] & PT_CLOSEFIGURE
);
1113 newPath
.state
= PATH_Closed
;
1114 PATH_AssignGdiPath(pPath
, &newPath
);
1115 PATH_EmptyPath(&newPath
);
1120 /* PATH_PathToRegion
1122 * Creates a region from the specified path using the specified polygon
1123 * filling mode. The path is left unchanged. A handle to the region that
1124 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1125 * error occurs, SetLastError is called with the appropriate value and
1126 * FALSE is returned.
1130 PATH_PathToRegion ( PPATH pPath
, INT nPolyFillMode
, HRGN
*pHrgn
)
1132 int numStrokes
, iStroke
, i
;
1133 PULONG pNumPointsInStroke
;
1136 ASSERT(pPath
!=NULL
);
1137 ASSERT(pHrgn
!=NULL
);
1139 PATH_FlattenPath ( pPath
);
1141 /* First pass: Find out how many strokes there are in the path */
1142 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1144 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1145 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1153 /* Allocate memory for number-of-points-in-stroke array */
1154 pNumPointsInStroke
= ExAllocatePoolWithTag(PagedPool
, sizeof(ULONG
) * numStrokes
, TAG_PATH
);
1155 if(!pNumPointsInStroke
)
1157 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1161 /* Second pass: remember number of points in each polygon */
1162 iStroke
=-1; /* Will get incremented to 0 at beginning of first stroke */
1163 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1165 /* Is this the beginning of a new stroke? */
1166 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1169 _PRAGMA_WARNING_SUPPRESS(6386)
1170 pNumPointsInStroke
[iStroke
]=0;
1173 _PRAGMA_WARNING_SUPPRESS(6385)
1174 pNumPointsInStroke
[iStroke
]++;
1177 /* Create a region from the strokes */
1178 hrgn
= IntCreatePolyPolygonRgn( pPath
->pPoints
,
1184 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1188 /* Free memory for number-of-points-in-stroke array */
1189 ExFreePoolWithTag(pNumPointsInStroke
, TAG_PATH
);
1198 * Removes all entries from the path and sets the path state to PATH_Null.
1202 PATH_EmptyPath ( PPATH pPath
)
1204 ASSERT(pPath
!=NULL
);
1206 pPath
->state
=PATH_Null
;
1207 pPath
->numEntriesUsed
=0;
1212 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1213 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1214 * successful, FALSE otherwise (e.g. if not enough memory was available).
1218 PATH_AddEntry ( PPATH pPath
, const POINT
*pPoint
, BYTE flags
)
1220 ASSERT(pPath
!=NULL
);
1222 /* FIXME: If newStroke is true, perhaps we want to check that we're
1223 * getting a PT_MOVETO
1226 /* Check that path is open */
1227 if ( pPath
->state
!= PATH_Open
)
1230 /* Reserve enough memory for an extra path entry */
1231 if ( !PATH_ReserveEntries(pPath
, pPath
->numEntriesUsed
+1) )
1234 /* Store information in path entry */
1235 pPath
->pPoints
[pPath
->numEntriesUsed
]=*pPoint
;
1236 pPath
->pFlags
[pPath
->numEntriesUsed
]=flags
;
1238 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1239 if((flags
& PT_CLOSEFIGURE
) == PT_CLOSEFIGURE
)
1240 pPath
->newStroke
=TRUE
;
1242 /* Increment entry count */
1243 pPath
->numEntriesUsed
++;
1248 /* PATH_ReserveEntries
1250 * Ensures that at least "numEntries" entries (for points and flags) have
1251 * been allocated; allocates larger arrays and copies the existing entries
1252 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1256 PATH_ReserveEntries ( PPATH pPath
, INT numEntries
)
1258 INT numEntriesToAllocate
;
1262 ASSERT(pPath
!=NULL
);
1263 ASSERT(numEntries
>=0);
1265 /* Do we have to allocate more memory? */
1266 if(numEntries
> pPath
->numEntriesAllocated
)
1268 /* Find number of entries to allocate. We let the size of the array
1269 * grow exponentially, since that will guarantee linear time
1271 if(pPath
->numEntriesAllocated
)
1273 numEntriesToAllocate
=pPath
->numEntriesAllocated
;
1274 while(numEntriesToAllocate
<numEntries
)
1275 numEntriesToAllocate
=numEntriesToAllocate
*GROW_FACTOR_NUMER
/GROW_FACTOR_DENOM
;
1277 numEntriesToAllocate
=numEntries
;
1279 /* Allocate new arrays */
1280 pPointsNew
=(POINT
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(POINT
), TAG_PATH
);
1283 pFlagsNew
=(BYTE
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(BYTE
), TAG_PATH
);
1286 ExFreePoolWithTag(pPointsNew
, TAG_PATH
);
1290 /* Copy old arrays to new arrays and discard old arrays */
1293 ASSERT(pPath
->pFlags
);
1295 memcpy(pPointsNew
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
1296 memcpy(pFlagsNew
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
1298 ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
1299 ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
1301 pPath
->pPoints
=pPointsNew
;
1302 pPath
->pFlags
=pFlagsNew
;
1303 pPath
->numEntriesAllocated
=numEntriesToAllocate
;
1311 * Creates a Bezier spline that corresponds to part of an arc and appends the
1312 * corresponding points to the path. The start and end angles are passed in
1313 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1314 * at most. If "startEntryType" is non-zero, an entry of that type for the first
1315 * control point is added to the path; otherwise, it is assumed that the current
1316 * position is equal to the first control point.
1320 PATH_DoArcPart ( PPATH pPath
, FLOAT_POINT corners
[],
1321 double angleStart
, double angleEnd
, BYTE startEntryType
)
1323 double halfAngle
, a
;
1324 double xNorm
[4], yNorm
[4];
1328 ASSERT(fabs(angleEnd
-angleStart
)<=M_PI_2
);
1330 /* FIXME: Is there an easier way of computing this? */
1332 /* Compute control points */
1333 halfAngle
=(angleEnd
-angleStart
)/2.0;
1334 if(fabs(halfAngle
)>1e-8)
1336 a
=4.0/3.0*(1-cos(halfAngle
))/sin(halfAngle
);
1337 xNorm
[0]=cos(angleStart
);
1338 yNorm
[0]=sin(angleStart
);
1339 xNorm
[1]=xNorm
[0] - a
*yNorm
[0];
1340 yNorm
[1]=yNorm
[0] + a
*xNorm
[0];
1341 xNorm
[3]=cos(angleEnd
);
1342 yNorm
[3]=sin(angleEnd
);
1343 xNorm
[2]=xNorm
[3] + a
*yNorm
[3];
1344 yNorm
[2]=yNorm
[3] - a
*xNorm
[3];
1348 xNorm
[i
]=cos(angleStart
);
1349 yNorm
[i
]=sin(angleStart
);
1352 /* Add starting point to path if desired */
1355 PATH_ScaleNormalizedPoint(corners
, xNorm
[0], yNorm
[0], &point
);
1356 if(!PATH_AddEntry(pPath
, &point
, startEntryType
))
1360 /* Add remaining control points */
1363 PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &point
);
1364 if(!PATH_AddEntry(pPath
, &point
, PT_BEZIERTO
))
1371 /* PATH_ScaleNormalizedPoint
1373 * Scales a normalized point (x, y) with respect to the box whose corners are
1374 * passed in "corners". The point is stored in "*pPoint". The normalized
1375 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1376 * (1.0, 1.0) correspond to corners[1].
1380 PATH_ScaleNormalizedPoint ( FLOAT_POINT corners
[], double x
,
1381 double y
, POINT
*pPoint
)
1385 pPoint
->x
=GDI_ROUND( (double)corners
[0].x
+ (double)(corners
[1].x
-corners
[0].x
)*0.5*(x
+1.0) );
1386 pPoint
->y
=GDI_ROUND( (double)corners
[0].y
+ (double)(corners
[1].y
-corners
[0].y
)*0.5*(y
+1.0) );
1389 /* PATH_NormalizePoint
1391 * Normalizes a point with respect to the box whose corners are passed in
1392 * corners. The normalized coordinates are stored in *pX and *pY.
1396 PATH_NormalizePoint ( FLOAT_POINT corners
[],
1397 const FLOAT_POINT
*pPoint
,
1398 double *pX
, double *pY
)
1404 *pX
=(double)(pPoint
->x
-corners
[0].x
)/(double)(corners
[1].x
-corners
[0].x
) * 2.0 - 1.0;
1405 *pY
=(double)(pPoint
->y
-corners
[0].y
)/(double)(corners
[1].y
-corners
[0].y
) * 2.0 - 1.0;
1409 BOOL FASTCALL
PATH_StrokePath(DC
*dc
, PPATH pPath
)
1413 INT nLinePts
, nAlloc
;
1414 POINT
*pLinePts
= NULL
;
1415 POINT ptViewportOrg
, ptWindowOrg
;
1416 SIZE szViewportExt
, szWindowExt
;
1417 DWORD mapMode
, graphicsMode
;
1419 PDC_ATTR pdcattr
= dc
->pdcattr
;
1421 DPRINT("Enter %s\n", __FUNCTION__
);
1423 if (pPath
->state
!= PATH_Closed
)
1426 /* Save the mapping mode info */
1427 mapMode
= pdcattr
->iMapMode
;
1429 szViewportExt
= *DC_pszlViewportExt(dc
);
1430 ptViewportOrg
= dc
->pdcattr
->ptlViewportOrg
;
1431 szWindowExt
= dc
->pdcattr
->szlWindowExt
;
1432 ptWindowOrg
= dc
->pdcattr
->ptlWindowOrg
;
1434 MatrixS2XForm(&xform
, &dc
->pdcattr
->mxWorldToPage
);
1437 pdcattr
->iMapMode
= MM_TEXT
;
1438 pdcattr
->ptlViewportOrg
.x
= 0;
1439 pdcattr
->ptlViewportOrg
.y
= 0;
1440 pdcattr
->ptlWindowOrg
.x
= 0;
1441 pdcattr
->ptlWindowOrg
.y
= 0;
1442 graphicsMode
= pdcattr
->iGraphicsMode
;
1443 pdcattr
->iGraphicsMode
= GM_ADVANCED
;
1444 GreModifyWorldTransform(dc
, (XFORML
*)&xform
, MWT_IDENTITY
);
1445 pdcattr
->iGraphicsMode
= graphicsMode
;
1447 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1448 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1449 * space in case we get one to keep the number of reallocations small. */
1450 nAlloc
= pPath
->numEntriesUsed
+ 1 + 300;
1451 pLinePts
= ExAllocatePoolWithTag(PagedPool
, nAlloc
* sizeof(POINT
), TAG_PATH
);
1454 DPRINT1("Can't allocate pool!\n");
1455 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1460 for(i
= 0; i
< pPath
->numEntriesUsed
; i
++)
1462 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
))
1463 && (pPath
->pFlags
[i
] != PT_MOVETO
))
1465 DPRINT1("Expected PT_MOVETO %s, got path flag %d\n",
1466 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1467 (INT
)pPath
->pFlags
[i
]);
1471 switch(pPath
->pFlags
[i
])
1474 DPRINT("Got PT_MOVETO (%ld, %ld)\n",
1475 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1476 if(nLinePts
>= 2) IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1478 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1481 case (PT_LINETO
| PT_CLOSEFIGURE
):
1482 DPRINT("Got PT_LINETO (%ld, %ld)\n",
1483 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1484 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1487 DPRINT("Got PT_BEZIERTO\n");
1488 if(pPath
->pFlags
[i
+1] != PT_BEZIERTO
||
1489 (pPath
->pFlags
[i
+2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
)
1491 DPRINT1("Path didn't contain 3 successive PT_BEZIERTOs\n");
1497 INT nBzrPts
, nMinAlloc
;
1498 POINT
*pBzrPts
= GDI_Bezier(&pPath
->pPoints
[i
-1], 4, &nBzrPts
);
1499 /* Make sure we have allocated enough memory for the lines of
1500 * this bezier and the rest of the path, assuming we won't get
1501 * another one (since we won't reallocate again then). */
1502 nMinAlloc
= nLinePts
+ (pPath
->numEntriesUsed
- i
) + nBzrPts
;
1503 if(nAlloc
< nMinAlloc
)
1505 // Reallocate memory
1507 POINT
*Realloc
= NULL
;
1508 nAlloc
= nMinAlloc
* 2;
1510 Realloc
= ExAllocatePoolWithTag(PagedPool
,
1511 nAlloc
* sizeof(POINT
),
1516 DPRINT1("Can't allocate pool!\n");
1520 memcpy(Realloc
, pLinePts
, nLinePts
*sizeof(POINT
));
1521 ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1524 memcpy(&pLinePts
[nLinePts
], &pBzrPts
[1], (nBzrPts
- 1) * sizeof(POINT
));
1525 nLinePts
+= nBzrPts
- 1;
1526 ExFreePoolWithTag(pBzrPts
, TAG_BEZIER
);
1531 DPRINT1("Got path flag %d (not supported)\n", (INT
)pPath
->pFlags
[i
]);
1535 if(pPath
->pFlags
[i
] & PT_CLOSEFIGURE
)
1537 pLinePts
[nLinePts
++] = pLinePts
[0];
1541 IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1546 if(pLinePts
) ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1548 /* Restore the old mapping mode */
1549 pdcattr
->iMapMode
= mapMode
;
1550 pdcattr
->szlWindowExt
.cx
= szWindowExt
.cx
;
1551 pdcattr
->szlWindowExt
.cy
= szWindowExt
.cy
;
1552 pdcattr
->ptlWindowOrg
.x
= ptWindowOrg
.x
;
1553 pdcattr
->ptlWindowOrg
.y
= ptWindowOrg
.y
;
1555 pdcattr
->szlViewportExt
.cx
= szViewportExt
.cx
;
1556 pdcattr
->szlViewportExt
.cy
= szViewportExt
.cy
;
1557 pdcattr
->ptlViewportOrg
.x
= ptViewportOrg
.x
;
1558 pdcattr
->ptlViewportOrg
.y
= ptViewportOrg
.y
;
1560 /* Restore the world transform */
1561 XForm2MatrixS(&dc
->pdcattr
->mxWorldToPage
, &xform
);
1563 /* If we've moved the current point then get its new position
1564 which will be in device (MM_TEXT) co-ords, convert it to
1565 logical co-ords and re-set it. This basically updates
1566 dc->CurPosX|Y so that their values are in the correct mapping
1572 IntGetCurrentPositionEx(dc
, &pt
);
1573 IntDPtoLP(dc
, &pt
, 1);
1574 IntGdiMoveToEx(dc
, pt
.x
, pt
.y
, NULL
, FALSE
);
1576 DPRINT("Leave %s, ret=%d\n", __FUNCTION__
, ret
);
1580 #define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1585 PATH_WidenPath(DC
*dc
)
1587 INT i
, j
, numStrokes
, numOldStrokes
, penWidth
, penWidthIn
, penWidthOut
, size
, penStyle
;
1589 PPATH pPath
, pNewPath
, *pStrokes
= NULL
, *pOldStrokes
, pUpPath
, pDownPath
;
1591 DWORD obj_type
, joint
, endcap
, penType
;
1592 PDC_ATTR pdcattr
= dc
->pdcattr
;
1594 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
1595 if (!pPath
) return FALSE
;
1597 if(pPath
->state
== PATH_Open
)
1599 PATH_UnlockPath( pPath
);
1600 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1604 PATH_FlattenPath(pPath
);
1606 size
= GreGetObject( pdcattr
->hpen
, 0, NULL
);
1609 PATH_UnlockPath( pPath
);
1610 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1614 elp
= ExAllocatePoolWithTag(PagedPool
, size
, TAG_PATH
);
1615 GreGetObject(pdcattr
->hpen
, size
, elp
);
1617 obj_type
= GDI_HANDLE_GET_TYPE(pdcattr
->hpen
);
1618 if(obj_type
== GDI_OBJECT_TYPE_PEN
)
1620 penStyle
= ((LOGPEN
*)elp
)->lopnStyle
;
1622 else if(obj_type
== GDI_OBJECT_TYPE_EXTPEN
)
1624 penStyle
= elp
->elpPenStyle
;
1628 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1629 ExFreePoolWithTag(elp
, TAG_PATH
);
1630 PATH_UnlockPath( pPath
);
1634 penWidth
= elp
->elpWidth
;
1635 ExFreePoolWithTag(elp
, TAG_PATH
);
1637 endcap
= (PS_ENDCAP_MASK
& penStyle
);
1638 joint
= (PS_JOIN_MASK
& penStyle
);
1639 penType
= (PS_TYPE_MASK
& penStyle
);
1641 /* The function cannot apply to cosmetic pens */
1642 if(obj_type
== GDI_OBJECT_TYPE_EXTPEN
&& penType
== PS_COSMETIC
)
1644 PATH_UnlockPath( pPath
);
1645 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1649 penWidthIn
= penWidth
/ 2;
1650 penWidthOut
= penWidth
/ 2;
1651 if(penWidthIn
+ penWidthOut
< penWidth
)
1656 for(i
= 0, j
= 0; i
< pPath
->numEntriesUsed
; i
++, j
++)
1659 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
)) &&
1660 (pPath
->pFlags
[i
] != PT_MOVETO
))
1662 DPRINT1("Expected PT_MOVETO %s, got path flag %c\n",
1663 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1667 switch(pPath
->pFlags
[i
])
1672 pStrokes
[numStrokes
- 1]->state
= PATH_Closed
;
1674 numOldStrokes
= numStrokes
;
1677 if (numStrokes
== 1)
1678 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1681 pOldStrokes
= pStrokes
; // Save old pointer.
1682 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1683 if (!pStrokes
) return FALSE
;
1684 RtlCopyMemory(pStrokes
, pOldStrokes
, numOldStrokes
* sizeof(PPATH
));
1685 ExFreePoolWithTag(pOldStrokes
, TAG_PATH
); // Free old pointer.
1687 if (!pStrokes
) return FALSE
;
1688 pStrokes
[numStrokes
- 1] = ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1689 if (!pStrokes
[numStrokes
- 1])
1691 ASSERT(FALSE
); // FIXME
1694 PATH_InitGdiPath(pStrokes
[numStrokes
- 1]);
1695 pStrokes
[numStrokes
- 1]->state
= PATH_Open
;
1697 case (PT_LINETO
| PT_CLOSEFIGURE
):
1698 point
.x
= pPath
->pPoints
[i
].x
;
1699 point
.y
= pPath
->pPoints
[i
].y
;
1700 PATH_AddEntry(pStrokes
[numStrokes
- 1], &point
, pPath
->pFlags
[i
]);
1703 /* Should never happen because of the FlattenPath call */
1704 DPRINT1("Should never happen\n");
1707 DPRINT1("Got path flag %c\n", pPath
->pFlags
[i
]);
1712 pNewPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1715 ASSERT(FALSE
); // FIXME
1717 PATH_InitGdiPath(pNewPath
);
1718 pNewPath
->state
= PATH_Open
;
1720 for(i
= 0; i
< numStrokes
; i
++)
1722 pUpPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1723 PATH_InitGdiPath(pUpPath
);
1724 pUpPath
->state
= PATH_Open
;
1725 pDownPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1726 PATH_InitGdiPath(pDownPath
);
1727 pDownPath
->state
= PATH_Open
;
1729 for(j
= 0; j
< pStrokes
[i
]->numEntriesUsed
; j
++)
1731 /* Beginning or end of the path if not closed */
1732 if((!(pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) && (j
== 0 || j
== pStrokes
[i
]->numEntriesUsed
- 1) )
1734 /* Compute segment angle */
1735 double xo
, yo
, xa
, ya
, theta
;
1737 FLOAT_POINT corners
[2];
1740 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1741 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1742 xa
= pStrokes
[i
]->pPoints
[1].x
;
1743 ya
= pStrokes
[i
]->pPoints
[1].y
;
1747 xa
= pStrokes
[i
]->pPoints
[j
- 1].x
;
1748 ya
= pStrokes
[i
]->pPoints
[j
- 1].y
;
1749 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1750 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1752 theta
= atan2( ya
- yo
, xa
- xo
);
1755 case PS_ENDCAP_SQUARE
:
1756 pt
.x
= xo
+ round(sqrt(2) * penWidthOut
* cos(M_PI_4
+ theta
));
1757 pt
.y
= yo
+ round(sqrt(2) * penWidthOut
* sin(M_PI_4
+ theta
));
1758 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
) );
1759 pt
.x
= xo
+ round(sqrt(2) * penWidthIn
* cos(- M_PI_4
+ theta
));
1760 pt
.y
= yo
+ round(sqrt(2) * penWidthIn
* sin(- M_PI_4
+ theta
));
1761 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1763 case PS_ENDCAP_FLAT
:
1764 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1765 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1766 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1767 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1768 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1769 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1771 case PS_ENDCAP_ROUND
:
1773 corners
[0].x
= xo
- penWidthIn
;
1774 corners
[0].y
= yo
- penWidthIn
;
1775 corners
[1].x
= xo
+ penWidthOut
;
1776 corners
[1].y
= yo
+ penWidthOut
;
1777 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI_2
, theta
+ 3 * M_PI_4
, (j
== 0 ? PT_MOVETO
: FALSE
));
1778 PATH_DoArcPart(pUpPath
,corners
, theta
+ 3 * M_PI_4
, theta
+ M_PI
, FALSE
);
1779 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI
, theta
+ 5 * M_PI_4
, FALSE
);
1780 PATH_DoArcPart(pUpPath
,corners
, theta
+ 5 * M_PI_4
, theta
+ 3 * M_PI_2
, FALSE
);
1784 /* Corpse of the path */
1789 double xa
, ya
, xb
, yb
, xo
, yo
;
1790 double alpha
, theta
, miterWidth
;
1791 DWORD _joint
= joint
;
1793 PPATH pInsidePath
, pOutsidePath
;
1794 if(j
> 0 && j
< pStrokes
[i
]->numEntriesUsed
- 1)
1801 previous
= pStrokes
[i
]->numEntriesUsed
- 1;
1809 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1810 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1811 xa
= pStrokes
[i
]->pPoints
[previous
].x
;
1812 ya
= pStrokes
[i
]->pPoints
[previous
].y
;
1813 xb
= pStrokes
[i
]->pPoints
[next
].x
;
1814 yb
= pStrokes
[i
]->pPoints
[next
].y
;
1815 theta
= atan2( yo
- ya
, xo
- xa
);
1816 alpha
= atan2( yb
- yo
, xb
- xo
) - theta
;
1817 if (alpha
> 0) alpha
-= M_PI
;
1819 if(_joint
== PS_JOIN_MITER
&& dc
->dclevel
.laPath
.eMiterLimit
< fabs(1 / sin(alpha
/2)))
1821 _joint
= PS_JOIN_BEVEL
;
1825 pInsidePath
= pUpPath
;
1826 pOutsidePath
= pDownPath
;
1830 pInsidePath
= pDownPath
;
1831 pOutsidePath
= pUpPath
;
1837 /* Inside angle points */
1840 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1841 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1845 pt
.x
= xo
+ round( penWidthIn
* cos(theta
+ M_PI_2
) );
1846 pt
.y
= yo
+ round( penWidthIn
* sin(theta
+ M_PI_2
) );
1848 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1851 pt
.x
= xo
+ round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1852 pt
.y
= yo
+ round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1856 pt
.x
= xo
- round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1857 pt
.y
= yo
- round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1859 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1860 /* Outside angle point */
1863 case PS_JOIN_MITER
:
1864 miterWidth
= fabs(penWidthOut
/ cos(M_PI_2
- fabs(alpha
) / 2));
1865 pt
.x
= xo
+ round( miterWidth
* cos(theta
+ alpha
/ 2) );
1866 pt
.y
= yo
+ round( miterWidth
* sin(theta
+ alpha
/ 2) );
1867 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1869 case PS_JOIN_BEVEL
:
1872 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1873 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1877 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1878 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1880 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1883 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1884 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1888 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1889 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1891 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1893 case PS_JOIN_ROUND
:
1897 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1898 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1902 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1903 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1905 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1906 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ alpha
/ 2) );
1907 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ alpha
/ 2) );
1908 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1911 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1912 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1916 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1917 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1919 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1924 for(j
= 0; j
< pUpPath
->numEntriesUsed
; j
++)
1927 pt
.x
= pUpPath
->pPoints
[j
].x
;
1928 pt
.y
= pUpPath
->pPoints
[j
].y
;
1929 PATH_AddEntry(pNewPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1931 for(j
= 0; j
< pDownPath
->numEntriesUsed
; j
++)
1934 pt
.x
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].x
;
1935 pt
.y
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].y
;
1936 PATH_AddEntry(pNewPath
, &pt
, ( (j
== 0 && (pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) ? PT_MOVETO
: PT_LINETO
));
1939 PATH_DestroyGdiPath(pStrokes
[i
]);
1940 ExFreePoolWithTag(pStrokes
[i
], TAG_PATH
);
1941 PATH_DestroyGdiPath(pUpPath
);
1942 ExFreePoolWithTag(pUpPath
, TAG_PATH
);
1943 PATH_DestroyGdiPath(pDownPath
);
1944 ExFreePoolWithTag(pDownPath
, TAG_PATH
);
1946 if (pStrokes
) ExFreePoolWithTag(pStrokes
, TAG_PATH
);
1948 pNewPath
->state
= PATH_Closed
;
1949 if (!(ret
= PATH_AssignGdiPath(pPath
, pNewPath
)))
1950 DPRINT1("Assign path failed\n");
1951 PATH_DestroyGdiPath(pNewPath
);
1952 ExFreePoolWithTag(pNewPath
, TAG_PATH
);
1953 PATH_UnlockPath(pPath
);
1957 static inline INT
int_from_fixed(FIXED f
)
1959 return (f
.fract
>= 0x8000) ? (f
.value
+ 1) : f
.value
;
1962 /**********************************************************************
1965 * Internally used by PATH_add_outline
1970 PATH_BezierTo(PPATH pPath
, POINT
*lppt
, INT n
)
1976 PATH_AddEntry(pPath
, &lppt
[1], PT_LINETO
);
1980 PATH_AddEntry(pPath
, &lppt
[0], PT_BEZIERTO
);
1981 PATH_AddEntry(pPath
, &lppt
[1], PT_BEZIERTO
);
1982 PATH_AddEntry(pPath
, &lppt
[2], PT_BEZIERTO
);
1996 pt
[2].x
= (lppt
[i
+2].x
+ lppt
[i
+1].x
) / 2;
1997 pt
[2].y
= (lppt
[i
+2].y
+ lppt
[i
+1].y
) / 2;
1998 PATH_BezierTo(pPath
, pt
, 3);
2006 PATH_BezierTo(pPath
, pt
, 3);
2013 PATH_add_outline(PDC dc
, INT x
, INT y
, TTPOLYGONHEADER
*header
, DWORD size
)
2016 TTPOLYGONHEADER
*start
;
2018 BOOL bResult
= FALSE
;
2022 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2028 while ((char *)header
< (char *)start
+ size
)
2032 if (header
->dwType
!= TT_POLYGON_TYPE
)
2034 DPRINT1("Unknown header type %lu\n", header
->dwType
);
2038 pt
.x
= x
+ int_from_fixed(header
->pfxStart
.x
);
2039 pt
.y
= y
- int_from_fixed(header
->pfxStart
.y
);
2040 PATH_AddEntry(pPath
, &pt
, PT_MOVETO
);
2042 curve
= (TTPOLYCURVE
*)(header
+ 1);
2044 while ((char *)curve
< (char *)header
+ header
->cb
)
2046 /*DPRINT1("curve->wType %d\n", curve->wType);*/
2048 switch(curve
->wType
)
2054 for (i
= 0; i
< curve
->cpfx
; i
++)
2056 pt
.x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
2057 pt
.y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
2058 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
2063 case TT_PRIM_QSPLINE
:
2064 case TT_PRIM_CSPLINE
:
2068 POINT
*pts
= ExAllocatePoolWithTag(PagedPool
, (curve
->cpfx
+ 1) * sizeof(POINT
), TAG_PATH
);
2070 if (!pts
) goto cleanup
;
2072 ptfx
= *(POINTFX
*)((char *)curve
- sizeof(POINTFX
));
2074 pts
[0].x
= x
+ int_from_fixed(ptfx
.x
);
2075 pts
[0].y
= y
- int_from_fixed(ptfx
.y
);
2077 for (i
= 0; i
< curve
->cpfx
; i
++)
2079 pts
[i
+ 1].x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
2080 pts
[i
+ 1].y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
2083 PATH_BezierTo(pPath
, pts
, curve
->cpfx
+ 1);
2085 ExFreePoolWithTag(pts
, TAG_PATH
);
2090 DPRINT1("Unknown curve type %04x\n", curve
->wType
);
2094 curve
= (TTPOLYCURVE
*)&curve
->apfx
[curve
->cpfx
];
2096 header
= (TTPOLYGONHEADER
*)((char *)header
+ header
->cb
);
2102 IntGdiCloseFigure( pPath
);
2103 PATH_UnlockPath( pPath
);
2107 /**********************************************************************
2112 PATH_ExtTextOut(PDC dc
, INT x
, INT y
, UINT flags
, const RECTL
*lprc
,
2113 LPCWSTR str
, UINT count
, const INT
*dx
)
2116 POINT offset
= {0, 0};
2118 if (!count
) return TRUE
;
2120 for (idx
= 0; idx
< count
; idx
++)
2122 MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
2127 dwSize
= ftGdiGetGlyphOutline( dc
,
2129 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2135 if (dwSize
== GDI_ERROR
) return FALSE
;
2137 /* Add outline only if char is printable */
2140 outline
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_PATH
);
2141 if (!outline
) return FALSE
;
2143 ftGdiGetGlyphOutline( dc
,
2145 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2152 PATH_add_outline(dc
, x
+ offset
.x
, y
+ offset
.y
, outline
, dwSize
);
2154 ExFreePoolWithTag(outline
, TAG_PATH
);
2159 if (flags
& ETO_PDY
)
2161 offset
.x
+= dx
[idx
* 2];
2162 offset
.y
+= dx
[idx
* 2 + 1];
2165 offset
.x
+= dx
[idx
];
2169 offset
.x
+= gm
.gmCellIncX
;
2170 offset
.y
+= gm
.gmCellIncY
;
2177 /***********************************************************************
2178 * Exported functions
2183 NtGdiAbortPath(HDC hDC
)
2186 PDC dc
= DC_LockDc ( hDC
);
2189 EngSetLastError(ERROR_INVALID_HANDLE
);
2193 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2200 PATH_EmptyPath(pPath
);
2202 PATH_UnlockPath(pPath
);
2203 dc
->dclevel
.flPath
&= ~DCPATH_ACTIVE
;
2211 NtGdiBeginPath( HDC hDC
)
2216 dc
= DC_LockDc ( hDC
);
2219 EngSetLastError(ERROR_INVALID_HANDLE
);
2223 /* If path is already open, do nothing. Check if not Save DC state */
2224 if ((dc
->dclevel
.flPath
& DCPATH_ACTIVE
) && !(dc
->dclevel
.flPath
& DCPATH_SAVE
))
2230 if ( dc
->dclevel
.hPath
)
2232 DPRINT("BeginPath 1 0x%p\n", dc
->dclevel
.hPath
);
2233 if ( !(dc
->dclevel
.flPath
& DCPATH_SAVE
) )
2234 { // Remove previous handle.
2235 if (!PATH_Delete(dc
->dclevel
.hPath
))
2242 { // Clear flags and Handle.
2243 dc
->dclevel
.flPath
&= ~(DCPATH_SAVE
|DCPATH_ACTIVE
);
2244 dc
->dclevel
.hPath
= NULL
;
2247 pPath
= PATH_AllocPathWithHandle();
2250 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2253 dc
->dclevel
.flPath
|= DCPATH_ACTIVE
; // Set active ASAP!
2255 dc
->dclevel
.hPath
= pPath
->BaseObject
.hHmgr
;
2257 DPRINT("BeginPath 2 h 0x%p p 0x%p\n", dc
->dclevel
.hPath
, pPath
);
2258 // Path handles are shared. Also due to recursion with in the same thread.
2259 GDIOBJ_vUnlockObject((POBJ
)pPath
); // Unlock
2260 pPath
= PATH_LockPath(dc
->dclevel
.hPath
); // Share Lock.
2262 /* Make sure that path is empty */
2263 PATH_EmptyPath( pPath
);
2265 /* Initialize variables for new path */
2266 pPath
->newStroke
= TRUE
;
2267 pPath
->state
= PATH_Open
;
2269 PATH_UnlockPath(pPath
);
2276 NtGdiCloseFigure(HDC hDC
)
2278 BOOL Ret
= FALSE
; // Default to failure
2282 DPRINT("Enter %s\n", __FUNCTION__
);
2284 pDc
= DC_LockDc(hDC
);
2287 EngSetLastError(ERROR_INVALID_PARAMETER
);
2290 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2297 if (pPath
->state
==PATH_Open
)
2299 IntGdiCloseFigure(pPath
);
2304 // FIXME: Check if lasterror is set correctly
2305 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2308 PATH_UnlockPath( pPath
);
2315 NtGdiEndPath(HDC hDC
)
2319 PDC dc
= DC_LockDc ( hDC
);
2323 EngSetLastError(ERROR_INVALID_HANDLE
);
2327 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2333 /* Check that path is currently being constructed */
2334 if ( (pPath
->state
!= PATH_Open
) || !(dc
->dclevel
.flPath
& DCPATH_ACTIVE
) )
2336 DPRINT1("EndPath ERROR! 0x%p\n", dc
->dclevel
.hPath
);
2337 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2340 /* Set flag to indicate that path is finished */
2343 DPRINT("EndPath 0x%p\n", dc
->dclevel
.hPath
);
2344 pPath
->state
= PATH_Closed
;
2345 dc
->dclevel
.flPath
&= ~DCPATH_ACTIVE
;
2347 PATH_UnlockPath( pPath
);
2354 NtGdiFillPath(HDC hDC
)
2361 dc
= DC_LockDc(hDC
);
2364 EngSetLastError(ERROR_INVALID_PARAMETER
);
2368 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2375 DC_vPrepareDCsForBlit(dc
, dc
->rosdc
.CombinedClip
->rclBounds
,
2376 NULL
, dc
->rosdc
.CombinedClip
->rclBounds
);
2378 pdcattr
= dc
->pdcattr
;
2380 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2381 DC_vUpdateLineBrush(dc
);
2383 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
2384 DC_vUpdateFillBrush(dc
);
2386 ret
= PATH_FillPath( dc
, pPath
);
2389 /* FIXME: Should the path be emptied even if conversion
2391 PATH_EmptyPath( pPath
);
2394 PATH_UnlockPath( pPath
);
2395 DC_vFinishBlit(dc
, NULL
);
2402 NtGdiFlattenPath(HDC hDC
)
2408 DPRINT("Enter %s\n", __FUNCTION__
);
2410 pDc
= DC_LockDc(hDC
);
2413 EngSetLastError(ERROR_INVALID_HANDLE
);
2417 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2420 DC_UnlockDc ( pDc
);
2423 if (pPath
->state
== PATH_Open
)
2424 Ret
= PATH_FlattenPath(pPath
);
2426 PATH_UnlockPath( pPath
);
2431 _Success_(return != FALSE
)
2436 _Out_ PDWORD pdwOut
)
2439 BOOL bResult
= TRUE
;
2441 if (!(pDc
= DC_LockDc(hdc
)))
2443 EngSetLastError(ERROR_INVALID_PARAMETER
);
2449 ProbeForWrite(pdwOut
, sizeof(DWORD
), 1);
2450 *pdwOut
= pDc
->dclevel
.laPath
.eMiterLimit
;
2452 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2454 SetLastNtError(_SEH2_GetExceptionCode());
2475 DC
*dc
= DC_LockDc(hDC
);
2478 DPRINT1("Can't lock dc!\n");
2479 EngSetLastError(ERROR_INVALID_PARAMETER
);
2483 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2490 if (pPath
->state
!= PATH_Closed
)
2492 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2498 ret
= pPath
->numEntriesUsed
;
2500 else if(nSize
<pPath
->numEntriesUsed
)
2502 EngSetLastError(ERROR_INVALID_PARAMETER
);
2509 memcpy(Points
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
2510 memcpy(Types
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
2512 /* Convert the points to logical coordinates */
2513 if (!GdiPathDPtoLP(dc
, Points
, pPath
->numEntriesUsed
))
2515 EngSetLastError(ERROR_ARITHMETIC_OVERFLOW
);
2519 ret
= pPath
->numEntriesUsed
;
2521 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2523 SetLastNtError(_SEH2_GetExceptionCode());
2529 PATH_UnlockPath( pPath
);
2536 NtGdiPathToRegion(HDC hDC
)
2543 DPRINT("Enter %s\n", __FUNCTION__
);
2545 pDc
= DC_LockDc(hDC
);
2548 EngSetLastError(ERROR_INVALID_PARAMETER
);
2552 pdcattr
= pDc
->pdcattr
;
2554 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2557 DC_UnlockDc ( pDc
);
2561 if (pPath
->state
!=PATH_Closed
)
2563 // FIXME: Check that setlasterror is being called correctly
2564 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2568 /* FIXME: Should we empty the path even if conversion failed? */
2569 if(PATH_PathToRegion(pPath
, pdcattr
->jFillMode
, &hrgnRval
))
2570 PATH_EmptyPath(pPath
);
2573 PATH_UnlockPath( pPath
);
2583 IN OUT OPTIONAL PDWORD pdwOut
)
2586 gxf_long worker
, worker1
;
2587 NTSTATUS Status
= STATUS_SUCCESS
;
2589 if (!(pDc
= DC_LockDc(hdc
)))
2591 EngSetLastError(ERROR_INVALID_PARAMETER
);
2596 worker1
.f
= pDc
->dclevel
.laPath
.eMiterLimit
;
2597 pDc
->dclevel
.laPath
.eMiterLimit
= worker
.f
;
2603 ProbeForWrite(pdwOut
,
2606 *pdwOut
= worker1
.l
;
2608 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2610 Status
= _SEH2_GetExceptionCode();
2613 if (!NT_SUCCESS(Status
))
2615 SetLastNtError(Status
);
2627 NtGdiStrokeAndFillPath(HDC hDC
)
2634 DPRINT1("Enter %s\n", __FUNCTION__
);
2636 if (!(pDc
= DC_LockDc(hDC
)))
2638 EngSetLastError(ERROR_INVALID_PARAMETER
);
2641 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2644 DC_UnlockDc ( pDc
);
2648 DC_vPrepareDCsForBlit(pDc
, pDc
->rosdc
.CombinedClip
->rclBounds
,
2649 NULL
, pDc
->rosdc
.CombinedClip
->rclBounds
);
2651 pdcattr
= pDc
->pdcattr
;
2653 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
2654 DC_vUpdateFillBrush(pDc
);
2656 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2657 DC_vUpdateLineBrush(pDc
);
2659 bRet
= PATH_FillPath(pDc
, pPath
);
2660 if (bRet
) bRet
= PATH_StrokePath(pDc
, pPath
);
2661 if (bRet
) PATH_EmptyPath(pPath
);
2663 PATH_UnlockPath( pPath
);
2664 DC_vFinishBlit(pDc
, NULL
);
2671 NtGdiStrokePath(HDC hDC
)
2678 DPRINT("Enter %s\n", __FUNCTION__
);
2680 if (!(pDc
= DC_LockDc(hDC
)))
2682 EngSetLastError(ERROR_INVALID_PARAMETER
);
2685 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2688 DC_UnlockDc ( pDc
);
2692 DC_vPrepareDCsForBlit(pDc
, pDc
->rosdc
.CombinedClip
->rclBounds
,
2693 NULL
, pDc
->rosdc
.CombinedClip
->rclBounds
);
2695 pdcattr
= pDc
->pdcattr
;
2697 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2698 DC_vUpdateLineBrush(pDc
);
2700 bRet
= PATH_StrokePath(pDc
, pPath
);
2702 DC_vFinishBlit(pDc
, NULL
);
2703 PATH_EmptyPath(pPath
);
2705 PATH_UnlockPath( pPath
);
2712 NtGdiWidenPath(HDC hDC
)
2715 PDC pdc
= DC_LockDc ( hDC
);
2718 EngSetLastError(ERROR_INVALID_PARAMETER
);
2721 Ret
= PATH_WidenPath(pdc
);
2722 DC_UnlockDc ( pdc
);