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
)
37 ASSERT(pPath
!= NULL
);
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. */
83 XFORMOBJ_vInit(&xo
, &pdc
->pdcattr
->mxDeviceToWorld
);
84 return XFORMOBJ_bApplyXform(&xo
, XF_LTOL
, count
, (PPOINTL
)ppt
, (PPOINTL
)ppt
);
97 //INT mapMode, graphicsMode;
98 //SIZE ptViewportExt, ptWindowExt;
99 //POINTL ptViewportOrg, ptWindowOrg;
102 PDC_ATTR pdcattr
= dc
->pdcattr
;
104 if (pPath
->state
!= PATH_Closed
)
106 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
110 if (PATH_PathToRegion(pPath
, pdcattr
->jFillMode
, &hrgn
))
112 /* Since PaintRgn interprets the region as being in logical coordinates
113 * but the points we store for the path are already in device
114 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
115 * Using SaveDC to save information about the mapping mode / world
116 * transform would be easier but would require more overhead, especially
117 * now that SaveDC saves the current path.
120 /* Save the information about the old mapping mode */
121 //mapMode = pdcattr->iMapMode;
122 //ptViewportExt = pdcattr->szlViewportExt;
123 //ptViewportOrg = pdcattr->ptlViewportOrg;
124 //ptWindowExt = pdcattr->szlWindowExt;
125 //ptWindowOrg = pdcattr->ptlWindowOrg;
127 /* Save world transform
128 * NB: The Windows documentation on world transforms would lead one to
129 * believe that this has to be done only in GM_ADVANCED; however, my
130 * tests show that resetting the graphics mode to GM_COMPATIBLE does
131 * not reset the world transform.
133 MatrixS2XForm(&xform
, &dc
->pdcattr
->mxWorldToPage
);
136 // IntGdiSetMapMode(dc, MM_TEXT);
137 // pdcattr->ptlViewportOrg.x = 0;
138 // pdcattr->ptlViewportOrg.y = 0;
139 // pdcattr->ptlWindowOrg.x = 0;
140 // pdcattr->ptlWindowOrg.y = 0;
142 // graphicsMode = pdcattr->iGraphicsMode;
143 // pdcattr->iGraphicsMode = GM_ADVANCED;
144 // IntGdiModifyWorldTransform(dc, &xform, MWT_IDENTITY);
145 // pdcattr->iGraphicsMode = graphicsMode;
147 /* Paint the region */
148 IntGdiPaintRgn(dc
, hrgn
);
149 GreDeleteObject(hrgn
);
150 /* Restore the old mapping mode */
151 // IntGdiSetMapMode(dc, mapMode);
152 // pdcattr->szlViewportExt = ptViewportExt;
153 // pdcattr->ptlViewportOrg = ptViewportOrg;
154 // pdcattr->szlWindowExt = ptWindowExt;
155 // pdcattr->ptlWindowOrg = ptWindowOrg;
157 /* Go to GM_ADVANCED temporarily to restore the world transform */
158 //graphicsMode = pdcattr->iGraphicsMode;
159 // pdcattr->iGraphicsMode = GM_ADVANCED;
160 // IntGdiModifyWorldTransform(dc, &xform, MWT_MAX+1);
161 // pdcattr->iGraphicsMode = graphicsMode;
169 * Initializes the GdiPath structure.
176 ASSERT(pPath
!= NULL
);
178 pPath
->state
= PATH_Null
;
179 pPath
->pPoints
= NULL
;
180 pPath
->pFlags
= NULL
;
181 pPath
->numEntriesUsed
= 0;
182 pPath
->numEntriesAllocated
= 0;
185 /* PATH_AssignGdiPath
187 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
188 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
189 * not just the pointers. Since this means that the arrays in pPathDest may
190 * need to be resized, pPathDest should have been initialized using
191 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
192 * not a copy constructor).
193 * Returns TRUE if successful, else FALSE.
199 const PPATH pPathSrc
)
201 ASSERT(pPathDest
!= NULL
&& pPathSrc
!= NULL
);
203 /* Make sure destination arrays are big enough */
204 if (!PATH_ReserveEntries(pPathDest
, pPathSrc
->numEntriesUsed
))
207 /* Perform the copy operation */
208 memcpy(pPathDest
->pPoints
, pPathSrc
->pPoints
,
209 sizeof(POINT
)*pPathSrc
->numEntriesUsed
);
210 memcpy(pPathDest
->pFlags
, pPathSrc
->pFlags
,
211 sizeof(BYTE
)*pPathSrc
->numEntriesUsed
);
213 pPathDest
->state
= pPathSrc
->state
;
214 pPathDest
->numEntriesUsed
= pPathSrc
->numEntriesUsed
;
215 pPathDest
->newStroke
= pPathSrc
->newStroke
;
221 * Should be called when a MoveTo is performed on a DC that has an
222 * open path. This starts a new stroke. Returns TRUE if successful, else
230 PPATH pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
231 if (!pPath
) return FALSE
;
233 /* Check that path is open */
234 if (pPath
->state
!= PATH_Open
)
236 PATH_UnlockPath(pPath
);
237 /* FIXME: Do we have to call SetLastError? */
240 /* Start a new stroke */
241 pPath
->newStroke
= TRUE
;
242 PATH_UnlockPath(pPath
);
248 * Should be called when a LineTo is performed on a DC that has an
249 * open path. This adds a PT_LINETO entry to the path (and possibly
250 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
251 * Returns TRUE if successful, else FALSE.
262 POINT point
, pointCurPos
;
264 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
265 if (!pPath
) return FALSE
;
267 /* Check that path is open */
268 if (pPath
->state
!= PATH_Open
)
270 PATH_UnlockPath(pPath
);
274 /* Convert point to device coordinates */
277 CoordLPtoDP(dc
, &point
);
279 /* Add a PT_MOVETO if necessary */
280 if (pPath
->newStroke
)
282 pPath
->newStroke
= FALSE
;
283 IntGetCurrentPositionEx(dc
, &pointCurPos
);
284 CoordLPtoDP(dc
, &pointCurPos
);
285 if (!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
287 PATH_UnlockPath(pPath
);
292 /* Add a PT_LINETO entry */
293 Ret
= PATH_AddEntry(pPath
, &point
, PT_LINETO
);
294 PATH_UnlockPath(pPath
);
300 * Should be called when a call to Rectangle is performed on a DC that has
301 * an open path. Returns TRUE if successful, else FALSE.
313 POINT corners
[2], pointTemp
;
316 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
317 if (!pPath
) return FALSE
;
319 /* Check that path is open */
320 if (pPath
->state
!= PATH_Open
)
322 PATH_UnlockPath(pPath
);
326 /* Convert points to device coordinates */
331 IntLPtoDP(dc
, corners
, 2);
333 /* Make sure first corner is top left and second corner is bottom right */
334 if (corners
[0].x
> corners
[1].x
)
337 corners
[0].x
= corners
[1].x
;
340 if (corners
[0].y
> corners
[1].y
)
343 corners
[0].y
= corners
[1].y
;
347 /* In GM_COMPATIBLE, don't include bottom and right edges */
348 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
354 /* Close any previous figure */
355 IntGdiCloseFigure(pPath
);
357 /* Add four points to the path */
358 pointTemp
.x
= corners
[1].x
;
359 pointTemp
.y
= corners
[0].y
;
360 if (!PATH_AddEntry(pPath
, &pointTemp
, PT_MOVETO
))
362 PATH_UnlockPath(pPath
);
365 if (!PATH_AddEntry(pPath
, corners
, PT_LINETO
))
367 PATH_UnlockPath(pPath
);
370 pointTemp
.x
= corners
[0].x
;
371 pointTemp
.y
= corners
[1].y
;
372 if (!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
374 PATH_UnlockPath(pPath
);
377 if (!PATH_AddEntry(pPath
, corners
+ 1, PT_LINETO
))
379 PATH_UnlockPath(pPath
);
383 /* Close the rectangle figure */
384 IntGdiCloseFigure(pPath
) ;
385 PATH_UnlockPath(pPath
);
391 * Should be called when a call to RoundRect is performed on a DC that has
392 * an open path. Returns TRUE if successful, else FALSE.
394 * FIXME: It adds the same entries to the path as windows does, but there
395 * is an error in the bezier drawing code so that there are small pixel-size
396 * gaps when the resulting path is drawn by StrokePath()
410 POINT corners
[2], pointTemp
;
411 FLOAT_POINT ellCorners
[2];
413 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
414 if (!pPath
) return FALSE
;
416 /* Check that path is open */
417 if (pPath
->state
!= PATH_Open
)
419 PATH_UnlockPath(pPath
);
423 if (!PATH_CheckCorners(dc
, corners
, x1
, y1
, x2
, y2
))
425 PATH_UnlockPath(pPath
);
429 /* Add points to the roundrect path */
430 ellCorners
[0].x
= corners
[1].x
- ell_width
;
431 ellCorners
[0].y
= corners
[0].y
;
432 ellCorners
[1].x
= corners
[1].x
;
433 ellCorners
[1].y
= corners
[0].y
+ ell_height
;
434 if (!PATH_DoArcPart(pPath
, ellCorners
, 0, -M_PI_2
, PT_MOVETO
))
436 PATH_UnlockPath(pPath
);
439 pointTemp
.x
= corners
[0].x
+ ell_width
/ 2;
440 pointTemp
.y
= corners
[0].y
;
441 if (!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
443 PATH_UnlockPath(pPath
);
446 ellCorners
[0].x
= corners
[0].x
;
447 ellCorners
[1].x
= corners
[0].x
+ ell_width
;
448 if (!PATH_DoArcPart(pPath
, ellCorners
, -M_PI_2
, -M_PI
, FALSE
))
450 PATH_UnlockPath(pPath
);
453 pointTemp
.x
= corners
[0].x
;
454 pointTemp
.y
= corners
[1].y
- ell_height
/ 2;
455 if (!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
457 PATH_UnlockPath(pPath
);
460 ellCorners
[0].y
= corners
[1].y
- ell_height
;
461 ellCorners
[1].y
= corners
[1].y
;
462 if (!PATH_DoArcPart(pPath
, ellCorners
, M_PI
, M_PI_2
, FALSE
))
464 PATH_UnlockPath(pPath
);
467 pointTemp
.x
= corners
[1].x
- ell_width
/ 2;
468 pointTemp
.y
= corners
[1].y
;
469 if (!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
471 PATH_UnlockPath(pPath
);
474 ellCorners
[0].x
= corners
[1].x
- ell_width
;
475 ellCorners
[1].x
= corners
[1].x
;
476 if (!PATH_DoArcPart(pPath
, ellCorners
, M_PI_2
, 0, FALSE
))
478 PATH_UnlockPath(pPath
);
482 IntGdiCloseFigure(pPath
);
483 PATH_UnlockPath(pPath
);
489 * Should be called when a call to Ellipse is performed on a DC that has
490 * an open path. This adds four Bezier splines representing the ellipse
491 * to the path. Returns TRUE if successful, else FALSE.
503 /* TODO: This should probably be revised to call PATH_AngleArc */
504 /* (once it exists) */
505 BOOL Ret
= PATH_Arc(dc
, x1
, y1
, x2
, y2
, x1
, (y1
+ y2
) / 2, x1
, (y1
+ y2
) / 2, GdiTypeArc
);
508 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
509 if (!pPath
) return FALSE
;
510 IntGdiCloseFigure(pPath
);
511 PATH_UnlockPath(pPath
);
518 * Should be called when a call to Arc is performed on a DC that has
519 * an open path. This adds up to five Bezier splines representing the arc
520 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
521 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
522 * -1 we add 1 extra line from the current DC position to the starting position
523 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
540 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
= 0.0;
541 /* Initialize angleEndQuadrant to silence gcc's warning */
543 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
544 POINT centre
, pointCurPos
;
545 BOOL start
, end
, Ret
= TRUE
;
550 /* FIXME: This function should check for all possible error returns */
551 /* FIXME: Do we have to respect newStroke? */
555 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
556 if (!pPath
) return FALSE
;
558 clockwise
= ((dc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
560 /* Check that path is open */
561 if (pPath
->state
!= PATH_Open
)
567 /* Check for zero height / width */
568 /* FIXME: Only in GM_COMPATIBLE? */
569 if (x1
== x2
|| y1
== y2
)
574 /* Convert points to device coordinates */
575 corners
[0].x
= (FLOAT
)x1
;
576 corners
[0].y
= (FLOAT
)y1
;
577 corners
[1].x
= (FLOAT
)x2
;
578 corners
[1].y
= (FLOAT
)y2
;
579 pointStart
.x
= (FLOAT
)xStart
;
580 pointStart
.y
= (FLOAT
)yStart
;
581 pointEnd
.x
= (FLOAT
)xEnd
;
582 pointEnd
.y
= (FLOAT
)yEnd
;
583 INTERNAL_LPTODP_FLOAT(dc
, corners
);
584 INTERNAL_LPTODP_FLOAT(dc
, corners
+ 1);
585 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
);
586 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
);
588 /* Make sure first corner is top left and second corner is bottom right */
589 if (corners
[0].x
> corners
[1].x
)
592 corners
[0].x
= corners
[1].x
;
595 if (corners
[0].y
> corners
[1].y
)
598 corners
[0].y
= corners
[1].y
;
602 /* Compute start and end angle */
603 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
604 angleStart
= atan2(y
, x
);
605 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
606 angleEnd
= atan2(y
, x
);
608 /* Make sure the end angle is "on the right side" of the start angle */
611 if (angleEnd
<= angleStart
)
613 angleEnd
+= 2 * M_PI
;
614 ASSERT(angleEnd
>= angleStart
);
619 if (angleEnd
>= angleStart
)
621 angleEnd
-= 2 * M_PI
;
622 ASSERT(angleEnd
<= angleStart
);
626 /* In GM_COMPATIBLE, don't include bottom and right edges */
627 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
633 /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
634 if (lines
== GdiTypeArcTo
&& pPath
->newStroke
) // -1
636 pPath
->newStroke
= FALSE
;
637 IntGetCurrentPositionEx(dc
, &pointCurPos
);
638 CoordLPtoDP(dc
, &pointCurPos
);
639 if (!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
646 /* Add the arc to the path with one Bezier spline per quadrant that the
652 /* Determine the start and end angles for this quadrant */
655 angleStartQuadrant
= angleStart
;
657 angleEndQuadrant
= (floor(angleStart
/ M_PI_2
) + 1.0) * M_PI_2
;
659 angleEndQuadrant
= (ceil(angleStart
/ M_PI_2
) - 1.0) * M_PI_2
;
663 angleStartQuadrant
= angleEndQuadrant
;
665 angleEndQuadrant
+= M_PI_2
;
667 angleEndQuadrant
-= M_PI_2
;
670 /* Have we reached the last part of the arc? */
671 if ((clockwise
&& angleEnd
< angleEndQuadrant
) ||
672 (!clockwise
&& angleEnd
> angleEndQuadrant
))
674 /* Adjust the end angle for this quadrant */
675 angleEndQuadrant
= angleEnd
;
679 /* Add the Bezier spline to the path */
680 PATH_DoArcPart(pPath
,
684 start
? (lines
== GdiTypeArcTo
? PT_LINETO
: PT_MOVETO
) : FALSE
); // -1
689 /* chord: close figure. pie: add line and close figure */
690 if (lines
== GdiTypeChord
) // 1
692 IntGdiCloseFigure(pPath
);
694 else if (lines
== GdiTypePie
) // 2
696 centre
.x
= (corners
[0].x
+ corners
[1].x
) / 2;
697 centre
.y
= (corners
[0].y
+ corners
[1].y
) / 2;
698 if (!PATH_AddEntry(pPath
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
702 PATH_UnlockPath(pPath
);
721 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
722 if (!pPath
) return FALSE
;
724 /* Check that path is open */
725 if (pPath
->state
!= PATH_Open
)
727 PATH_UnlockPath(pPath
);
731 /* Add a PT_MOVETO if necessary */
732 if (pPath
->newStroke
)
734 pPath
->newStroke
= FALSE
;
735 IntGetCurrentPositionEx(dc
, &pt
);
736 CoordLPtoDP(dc
, &pt
);
737 if (!PATH_AddEntry(pPath
, &pt
, PT_MOVETO
))
739 PATH_UnlockPath(pPath
);
744 for (i
= 0; i
< cbPoints
; i
++)
747 CoordLPtoDP(dc
, &pt
);
748 PATH_AddEntry(pPath
, &pt
, PT_BEZIERTO
);
751 PATH_UnlockPath(pPath
);
770 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
771 if (!pPath
) return FALSE
;
773 /* Check that path is open */
774 if (pPath
->state
!= PATH_Open
)
776 PATH_UnlockPath(pPath
);
780 for (i
= 0; i
< cbPoints
; i
++)
783 CoordLPtoDP(dc
, &pt
);
784 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_BEZIERTO
);
787 PATH_UnlockPath(pPath
);
800 POINT lastmove
, orig_pos
;
803 BOOL State
= FALSE
, Ret
= FALSE
;
805 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
806 if (!pPath
) return FALSE
;
808 if (pPath
->state
!= PATH_Open
)
810 PATH_UnlockPath(pPath
);
814 pdcattr
= dc
->pdcattr
;
816 lastmove
.x
= orig_pos
.x
= pdcattr
->ptlCurrent
.x
;
817 lastmove
.y
= orig_pos
.y
= pdcattr
->ptlCurrent
.y
;
819 i
= pPath
->numEntriesUsed
;
824 if (pPath
->pFlags
[i
] == PT_MOVETO
)
826 lastmove
.x
= pPath
->pPoints
[i
].x
;
827 lastmove
.y
= pPath
->pPoints
[i
].y
;
828 if (!GdiPathDPtoLP(dc
, &lastmove
, 1))
830 PATH_UnlockPath(pPath
);
837 for (i
= 0; i
< cbPoints
; i
++)
839 if (types
[i
] == PT_MOVETO
)
841 pPath
->newStroke
= TRUE
;
842 lastmove
.x
= pts
[i
].x
;
843 lastmove
.y
= pts
[i
].y
;
845 else if ((types
[i
] & ~PT_CLOSEFIGURE
) == PT_LINETO
)
847 PATH_LineTo(dc
, pts
[i
].x
, pts
[i
].y
);
849 else if (types
[i
] == PT_BEZIERTO
)
851 if (!((i
+ 2 < cbPoints
) && (types
[i
+ 1] == PT_BEZIERTO
)
852 && ((types
[i
+ 2] & ~PT_CLOSEFIGURE
) == PT_BEZIERTO
)))
854 PATH_PolyBezierTo(dc
, &(pts
[i
]), 3);
860 pdcattr
->ptlCurrent
.x
= pts
[i
].x
;
861 pdcattr
->ptlCurrent
.y
= pts
[i
].y
;
864 if (types
[i
] & PT_CLOSEFIGURE
)
866 pPath
->pFlags
[pPath
->numEntriesUsed
- 1] |= PT_CLOSEFIGURE
;
867 pPath
->newStroke
= TRUE
;
868 pdcattr
->ptlCurrent
.x
= lastmove
.x
;
869 pdcattr
->ptlCurrent
.y
= lastmove
.y
;
877 if ((pdcattr
->ptlCurrent
.x
!= orig_pos
.x
) || (pdcattr
->ptlCurrent
.y
!= orig_pos
.y
))
879 pPath
->newStroke
= TRUE
;
880 pdcattr
->ptlCurrent
.x
= orig_pos
.x
;
881 pdcattr
->ptlCurrent
.y
= orig_pos
.y
;
885 if (State
) // State change?
887 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
888 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
889 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
| DIRTY_PTFXCURRENT
| DIRTY_STYLESTATE
);
891 PATH_UnlockPath(pPath
);
910 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
911 if (!pPath
) return FALSE
;
913 /* Check that path is open */
914 if (pPath
->state
!= PATH_Open
)
916 PATH_UnlockPath(pPath
);
919 for (i
= 0; i
< cbPoints
; i
++)
922 CoordLPtoDP(dc
, &pt
);
923 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_LINETO
);
925 PATH_UnlockPath(pPath
);
944 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
945 if (!pPath
) return FALSE
;
947 /* Check that path is open */
948 if (pPath
->state
!= PATH_Open
)
950 PATH_UnlockPath(pPath
);
954 /* Add a PT_MOVETO if necessary */
955 if (pPath
->newStroke
)
957 pPath
->newStroke
= FALSE
;
958 IntGetCurrentPositionEx(dc
, &pt
);
959 CoordLPtoDP(dc
, &pt
);
960 if (!PATH_AddEntry(pPath
, &pt
, PT_MOVETO
))
962 PATH_UnlockPath(pPath
);
967 for (i
= 0; i
< cbPoints
; i
++)
970 CoordLPtoDP(dc
, &pt
);
971 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
973 PATH_UnlockPath(pPath
);
992 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
993 if (!pPath
) return FALSE
;
995 /* Check that path is open */
996 if (pPath
->state
!= PATH_Open
)
998 PATH_UnlockPath(pPath
);
1002 for (i
= 0; i
< cbPoints
; i
++)
1005 CoordLPtoDP(dc
, &pt
);
1006 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
:
1007 ((i
== cbPoints
- 1) ? PT_LINETO
| PT_CLOSEFIGURE
:
1011 PATH_UnlockPath(pPath
);
1024 ULONG poly
, point
, i
;
1032 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
1033 if (!pPath
) return FALSE
;
1035 /* Check that path is open */
1036 if (pPath
->state
!= PATH_Open
)
1038 PATH_UnlockPath(pPath
);
1042 for (i
= 0, poly
= 0; poly
< polygons
; poly
++)
1044 for (point
= 0; point
< (ULONG
) counts
[poly
]; point
++, i
++)
1047 CoordLPtoDP(dc
, &pt
);
1048 if (point
== 0) startpt
= pt
;
1049 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1052 /* Win98 adds an extra line to close the figure for some reason */
1053 PATH_AddEntry(pPath
, &startpt
, PT_LINETO
| PT_CLOSEFIGURE
);
1056 PATH_UnlockPath(pPath
);
1065 const DWORD
* counts
,
1069 ULONG poly
, point
, i
;
1077 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
1078 if (!pPath
) return FALSE
;
1080 /* Check that path is open */
1081 if (pPath
->state
!= PATH_Open
)
1083 PATH_UnlockPath(pPath
);
1087 for (i
= 0, poly
= 0; poly
< polylines
; poly
++)
1089 for (point
= 0; point
< counts
[poly
]; point
++, i
++)
1092 CoordLPtoDP(dc
, &pt
);
1093 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1097 PATH_UnlockPath(pPath
);
1102 /* PATH_CheckCorners
1104 * Helper function for PATH_RoundRect() and PATH_Rectangle()
1116 PDC_ATTR pdcattr
= dc
->pdcattr
;
1118 /* Convert points to device coordinates */
1123 CoordLPtoDP(dc
, &corners
[0]);
1124 CoordLPtoDP(dc
, &corners
[1]);
1126 /* Make sure first corner is top left and second corner is bottom right */
1127 if (corners
[0].x
> corners
[1].x
)
1129 temp
= corners
[0].x
;
1130 corners
[0].x
= corners
[1].x
;
1131 corners
[1].x
= temp
;
1134 if (corners
[0].y
> corners
[1].y
)
1136 temp
= corners
[0].y
;
1137 corners
[0].y
= corners
[1].y
;
1138 corners
[1].y
= temp
;
1141 /* In GM_COMPATIBLE, don't include bottom and right edges */
1142 if (pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
1152 /* PATH_AddFlatBezier
1165 pts
= GDI_Bezier(pt
, 4, &no
);
1166 if (!pts
) return FALSE
;
1168 for (i
= 1; i
< no
; i
++)
1169 PATH_AddEntry(pPath
, &pts
[i
], (i
== no
- 1 && closed
) ? PT_LINETO
| PT_CLOSEFIGURE
: PT_LINETO
);
1171 ExFreePoolWithTag(pts
, TAG_BEZIER
);
1177 * Replaces Beziers with line segments
1182 PATH_FlattenPath(PPATH pPath
)
1187 RtlZeroMemory(&newPath
, sizeof(newPath
));
1188 newPath
.state
= PATH_Open
;
1189 for (srcpt
= 0; srcpt
< pPath
->numEntriesUsed
; srcpt
++)
1191 switch(pPath
->pFlags
[srcpt
] & ~PT_CLOSEFIGURE
)
1195 PATH_AddEntry(&newPath
, &pPath
->pPoints
[srcpt
], pPath
->pFlags
[srcpt
]);
1198 PATH_AddFlatBezier(&newPath
, &pPath
->pPoints
[srcpt
- 1], pPath
->pFlags
[srcpt
+ 2] & PT_CLOSEFIGURE
);
1204 newPath
.state
= PATH_Closed
;
1205 PATH_AssignGdiPath(pPath
, &newPath
);
1206 PATH_EmptyPath(&newPath
);
1211 /* PATH_PathToRegion
1213 * Creates a region from the specified path using the specified polygon
1214 * filling mode. The path is left unchanged. A handle to the region that
1215 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1216 * error occurs, SetLastError is called with the appropriate value and
1217 * FALSE is returned.
1226 int numStrokes
, iStroke
, i
;
1227 PULONG pNumPointsInStroke
;
1230 ASSERT(pPath
!= NULL
);
1231 ASSERT(pHrgn
!= NULL
);
1233 PATH_FlattenPath(pPath
);
1235 /* First pass: Find out how many strokes there are in the path */
1236 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1238 for (i
= 0; i
< pPath
->numEntriesUsed
; i
++)
1239 if ((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1242 if (numStrokes
== 0)
1247 /* Allocate memory for number-of-points-in-stroke array */
1248 pNumPointsInStroke
= ExAllocatePoolWithTag(PagedPool
, sizeof(ULONG
) * numStrokes
, TAG_PATH
);
1249 if (!pNumPointsInStroke
)
1251 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1255 /* Second pass: remember number of points in each polygon */
1256 iStroke
= -1; /* Will get incremented to 0 at beginning of first stroke */
1257 for (i
= 0; i
< pPath
->numEntriesUsed
; i
++)
1259 /* Is this the beginning of a new stroke? */
1260 if ((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1263 _PRAGMA_WARNING_SUPPRESS(__WARNING_WRITE_OVERRUN
)
1264 pNumPointsInStroke
[iStroke
] = 0;
1267 _PRAGMA_WARNING_SUPPRESS(__WARNING_READ_OVERRUN
)
1268 pNumPointsInStroke
[iStroke
]++;
1271 /* Create a region from the strokes */
1272 hrgn
= IntCreatePolyPolygonRgn(pPath
->pPoints
,
1276 if (hrgn
== (HRGN
)0)
1278 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1282 /* Free memory for number-of-points-in-stroke array */
1283 ExFreePoolWithTag(pNumPointsInStroke
, TAG_PATH
);
1292 * Removes all entries from the path and sets the path state to PATH_Null.
1296 PATH_EmptyPath(PPATH pPath
)
1298 ASSERT(pPath
!= NULL
);
1300 pPath
->state
= PATH_Null
;
1301 pPath
->numEntriesUsed
= 0;
1306 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1307 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1308 * successful, FALSE otherwise (e.g. if not enough memory was available).
1314 const POINT
*pPoint
,
1317 ASSERT(pPath
!= NULL
);
1319 /* FIXME: If newStroke is true, perhaps we want to check that we're
1320 * getting a PT_MOVETO
1323 /* Check that path is open */
1324 if (pPath
->state
!= PATH_Open
)
1327 /* Reserve enough memory for an extra path entry */
1328 if (!PATH_ReserveEntries(pPath
, pPath
->numEntriesUsed
+ 1))
1331 /* Store information in path entry */
1332 pPath
->pPoints
[pPath
->numEntriesUsed
] = *pPoint
;
1333 pPath
->pFlags
[pPath
->numEntriesUsed
] = flags
;
1335 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1336 if ((flags
& PT_CLOSEFIGURE
) == PT_CLOSEFIGURE
)
1337 pPath
->newStroke
= TRUE
;
1339 /* Increment entry count */
1340 pPath
->numEntriesUsed
++;
1345 /* PATH_ReserveEntries
1347 * Ensures that at least "numEntries" entries (for points and flags) have
1348 * been allocated; allocates larger arrays and copies the existing entries
1349 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1353 PATH_ReserveEntries(
1357 INT numEntriesToAllocate
;
1361 ASSERT(pPath
!= NULL
);
1362 ASSERT(numEntries
>= 0);
1364 /* Do we have to allocate more memory? */
1365 if (numEntries
> pPath
->numEntriesAllocated
)
1367 /* Find number of entries to allocate. We let the size of the array
1368 * grow exponentially, since that will guarantee linear time
1370 if (pPath
->numEntriesAllocated
)
1372 numEntriesToAllocate
= pPath
->numEntriesAllocated
;
1373 while (numEntriesToAllocate
< numEntries
)
1374 numEntriesToAllocate
= numEntriesToAllocate
* GROW_FACTOR_NUMER
/ GROW_FACTOR_DENOM
;
1377 numEntriesToAllocate
= numEntries
;
1379 /* Allocate new arrays */
1380 pPointsNew
= (POINT
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(POINT
), TAG_PATH
);
1384 pFlagsNew
= (BYTE
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(BYTE
), TAG_PATH
);
1387 ExFreePoolWithTag(pPointsNew
, TAG_PATH
);
1391 /* Copy old arrays to new arrays and discard old arrays */
1394 ASSERT(pPath
->pFlags
);
1396 memcpy(pPointsNew
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
1397 memcpy(pFlagsNew
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
1399 ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
1400 ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
1403 pPath
->pPoints
= pPointsNew
;
1404 pPath
->pFlags
= pFlagsNew
;
1405 pPath
->numEntriesAllocated
= numEntriesToAllocate
;
1413 * Creates a Bezier spline that corresponds to part of an arc and appends the
1414 * corresponding points to the path. The start and end angles are passed in
1415 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1416 * at most. If "startEntryType" is non-zero, an entry of that type for the first
1417 * control point is added to the path; otherwise, it is assumed that the current
1418 * position is equal to the first control point.
1424 FLOAT_POINT corners
[],
1427 BYTE startEntryType
)
1429 double halfAngle
, a
;
1430 double xNorm
[4], yNorm
[4];
1434 ASSERT(fabs(angleEnd
- angleStart
) <= M_PI_2
);
1436 /* FIXME: Is there an easier way of computing this? */
1438 /* Compute control points */
1439 halfAngle
= (angleEnd
- angleStart
) / 2.0;
1440 if (fabs(halfAngle
) > 1e-8)
1442 a
= 4.0 / 3.0 * (1 - cos(halfAngle
)) / sin(halfAngle
);
1443 xNorm
[0] = cos(angleStart
);
1444 yNorm
[0] = sin(angleStart
);
1445 xNorm
[1] = xNorm
[0] - a
* yNorm
[0];
1446 yNorm
[1] = yNorm
[0] + a
* xNorm
[0];
1447 xNorm
[3] = cos(angleEnd
);
1448 yNorm
[3] = sin(angleEnd
);
1449 xNorm
[2] = xNorm
[3] + a
* yNorm
[3];
1450 yNorm
[2] = yNorm
[3] - a
* xNorm
[3];
1453 for (i
= 0; i
< 4; i
++)
1455 xNorm
[i
] = cos(angleStart
);
1456 yNorm
[i
] = sin(angleStart
);
1459 /* Add starting point to path if desired */
1462 PATH_ScaleNormalizedPoint(corners
, xNorm
[0], yNorm
[0], &point
);
1463 if (!PATH_AddEntry(pPath
, &point
, startEntryType
))
1467 /* Add remaining control points */
1468 for (i
= 1; i
< 4; i
++)
1470 PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &point
);
1471 if (!PATH_AddEntry(pPath
, &point
, PT_BEZIERTO
))
1478 /* PATH_ScaleNormalizedPoint
1480 * Scales a normalized point (x, y) with respect to the box whose corners are
1481 * passed in "corners". The point is stored in "*pPoint". The normalized
1482 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1483 * (1.0, 1.0) correspond to corners[1].
1487 PATH_ScaleNormalizedPoint(
1488 FLOAT_POINT corners
[],
1496 pPoint
->x
= GDI_ROUND((double)corners
[0].x
+ (double)(corners
[1].x
- corners
[0].x
) * 0.5 * (x
+ 1.0));
1497 pPoint
->y
= GDI_ROUND((double)corners
[0].y
+ (double)(corners
[1].y
- corners
[0].y
) * 0.5 * (y
+ 1.0));
1500 /* PATH_NormalizePoint
1502 * Normalizes a point with respect to the box whose corners are passed in
1503 * corners. The normalized coordinates are stored in *pX and *pY.
1507 PATH_NormalizePoint(
1508 FLOAT_POINT corners
[],
1509 const FLOAT_POINT
*pPoint
,
1518 *pX
= (double)(pPoint
->x
- corners
[0].x
) / (double)(corners
[1].x
- corners
[0].x
) * 2.0 - 1.0;
1519 *pY
= (double)(pPoint
->y
- corners
[0].y
) / (double)(corners
[1].y
- corners
[0].y
) * 2.0 - 1.0;
1531 INT nLinePts
, nAlloc
;
1532 POINT
*pLinePts
= NULL
;
1533 POINT ptViewportOrg
, ptWindowOrg
;
1534 SIZE szViewportExt
, szWindowExt
;
1535 DWORD mapMode
, graphicsMode
;
1537 PDC_ATTR pdcattr
= dc
->pdcattr
;
1539 DPRINT("Enter %s\n", __FUNCTION__
);
1541 if (pPath
->state
!= PATH_Closed
)
1544 /* Save the mapping mode info */
1545 mapMode
= pdcattr
->iMapMode
;
1547 szViewportExt
= *DC_pszlViewportExt(dc
);
1548 ptViewportOrg
= dc
->pdcattr
->ptlViewportOrg
;
1549 szWindowExt
= dc
->pdcattr
->szlWindowExt
;
1550 ptWindowOrg
= dc
->pdcattr
->ptlWindowOrg
;
1552 MatrixS2XForm(&xform
, &dc
->pdcattr
->mxWorldToPage
);
1555 pdcattr
->iMapMode
= MM_TEXT
;
1556 pdcattr
->ptlViewportOrg
.x
= 0;
1557 pdcattr
->ptlViewportOrg
.y
= 0;
1558 pdcattr
->ptlWindowOrg
.x
= 0;
1559 pdcattr
->ptlWindowOrg
.y
= 0;
1560 graphicsMode
= pdcattr
->iGraphicsMode
;
1561 pdcattr
->iGraphicsMode
= GM_ADVANCED
;
1562 GreModifyWorldTransform(dc
, (XFORML
*)&xform
, MWT_IDENTITY
);
1563 pdcattr
->iGraphicsMode
= graphicsMode
;
1565 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1566 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1567 * space in case we get one to keep the number of reallocations small. */
1568 nAlloc
= pPath
->numEntriesUsed
+ 1 + 300;
1569 pLinePts
= ExAllocatePoolWithTag(PagedPool
, nAlloc
* sizeof(POINT
), TAG_PATH
);
1572 DPRINT1("Can't allocate pool!\n");
1573 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1578 for (i
= 0; i
< pPath
->numEntriesUsed
; i
++)
1580 if ((i
== 0 || (pPath
->pFlags
[i
- 1] & PT_CLOSEFIGURE
))
1581 && (pPath
->pFlags
[i
] != PT_MOVETO
))
1583 DPRINT1("Expected PT_MOVETO %s, got path flag %d\n",
1584 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1585 (INT
)pPath
->pFlags
[i
]);
1589 switch(pPath
->pFlags
[i
])
1592 DPRINT("Got PT_MOVETO (%ld, %ld)\n",
1593 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1594 if (nLinePts
>= 2) IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1596 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1599 case (PT_LINETO
| PT_CLOSEFIGURE
):
1600 DPRINT("Got PT_LINETO (%ld, %ld)\n",
1601 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1602 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1605 DPRINT("Got PT_BEZIERTO\n");
1606 if (pPath
->pFlags
[i
+ 1] != PT_BEZIERTO
||
1607 (pPath
->pFlags
[i
+ 2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
)
1609 DPRINT1("Path didn't contain 3 successive PT_BEZIERTOs\n");
1615 INT nBzrPts
, nMinAlloc
;
1616 POINT
*pBzrPts
= GDI_Bezier(&pPath
->pPoints
[i
- 1], 4, &nBzrPts
);
1617 /* Make sure we have allocated enough memory for the lines of
1618 * this bezier and the rest of the path, assuming we won't get
1619 * another one (since we won't reallocate again then). */
1620 nMinAlloc
= nLinePts
+ (pPath
->numEntriesUsed
- i
) + nBzrPts
;
1621 if (nAlloc
< nMinAlloc
)
1623 // Reallocate memory
1625 POINT
*Realloc
= NULL
;
1626 nAlloc
= nMinAlloc
* 2;
1628 Realloc
= ExAllocatePoolWithTag(PagedPool
,
1629 nAlloc
* sizeof(POINT
),
1634 DPRINT1("Can't allocate pool!\n");
1638 memcpy(Realloc
, pLinePts
, nLinePts
* sizeof(POINT
));
1639 ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1642 memcpy(&pLinePts
[nLinePts
], &pBzrPts
[1], (nBzrPts
- 1) * sizeof(POINT
));
1643 nLinePts
+= nBzrPts
- 1;
1644 ExFreePoolWithTag(pBzrPts
, TAG_BEZIER
);
1649 DPRINT1("Got path flag %d (not supported)\n", (INT
)pPath
->pFlags
[i
]);
1653 if (pPath
->pFlags
[i
] & PT_CLOSEFIGURE
)
1655 pLinePts
[nLinePts
++] = pLinePts
[0];
1659 IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1664 if (pLinePts
) ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1666 /* Restore the old mapping mode */
1667 pdcattr
->iMapMode
= mapMode
;
1668 pdcattr
->szlWindowExt
.cx
= szWindowExt
.cx
;
1669 pdcattr
->szlWindowExt
.cy
= szWindowExt
.cy
;
1670 pdcattr
->ptlWindowOrg
.x
= ptWindowOrg
.x
;
1671 pdcattr
->ptlWindowOrg
.y
= ptWindowOrg
.y
;
1673 pdcattr
->szlViewportExt
.cx
= szViewportExt
.cx
;
1674 pdcattr
->szlViewportExt
.cy
= szViewportExt
.cy
;
1675 pdcattr
->ptlViewportOrg
.x
= ptViewportOrg
.x
;
1676 pdcattr
->ptlViewportOrg
.y
= ptViewportOrg
.y
;
1678 /* Restore the world transform */
1679 XForm2MatrixS(&dc
->pdcattr
->mxWorldToPage
, &xform
);
1681 /* If we've moved the current point then get its new position
1682 which will be in device (MM_TEXT) co-ords, convert it to
1683 logical co-ords and re-set it. This basically updates
1684 dc->CurPosX|Y so that their values are in the correct mapping
1690 IntGetCurrentPositionEx(dc
, &pt
);
1691 IntDPtoLP(dc
, &pt
, 1);
1692 IntGdiMoveToEx(dc
, pt
.x
, pt
.y
, NULL
, FALSE
);
1694 DPRINT("Leave %s, ret=%d\n", __FUNCTION__
, ret
);
1698 #define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1703 PATH_WidenPath(DC
*dc
)
1705 INT i
, j
, numStrokes
, numOldStrokes
, penWidth
, penWidthIn
, penWidthOut
, size
, penStyle
;
1707 PPATH pPath
, pNewPath
, *pStrokes
= NULL
, *pOldStrokes
, pUpPath
, pDownPath
;
1709 DWORD obj_type
, joint
, endcap
, penType
;
1710 PDC_ATTR pdcattr
= dc
->pdcattr
;
1712 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
1713 if (!pPath
) return FALSE
;
1715 if (pPath
->state
== PATH_Open
)
1717 PATH_UnlockPath(pPath
);
1718 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1722 PATH_FlattenPath(pPath
);
1724 size
= GreGetObject(pdcattr
->hpen
, 0, NULL
);
1727 PATH_UnlockPath(pPath
);
1728 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1732 elp
= ExAllocatePoolWithTag(PagedPool
, size
, TAG_PATH
);
1733 GreGetObject(pdcattr
->hpen
, size
, elp
);
1735 obj_type
= GDI_HANDLE_GET_TYPE(pdcattr
->hpen
);
1736 if (obj_type
== GDI_OBJECT_TYPE_PEN
)
1738 penStyle
= ((LOGPEN
*)elp
)->lopnStyle
;
1740 else if (obj_type
== GDI_OBJECT_TYPE_EXTPEN
)
1742 penStyle
= elp
->elpPenStyle
;
1746 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1747 ExFreePoolWithTag(elp
, TAG_PATH
);
1748 PATH_UnlockPath(pPath
);
1752 penWidth
= elp
->elpWidth
;
1753 ExFreePoolWithTag(elp
, TAG_PATH
);
1755 endcap
= (PS_ENDCAP_MASK
& penStyle
);
1756 joint
= (PS_JOIN_MASK
& penStyle
);
1757 penType
= (PS_TYPE_MASK
& penStyle
);
1759 /* The function cannot apply to cosmetic pens */
1760 if (obj_type
== GDI_OBJECT_TYPE_EXTPEN
&& penType
== PS_COSMETIC
)
1762 PATH_UnlockPath(pPath
);
1763 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1767 penWidthIn
= penWidth
/ 2;
1768 penWidthOut
= penWidth
/ 2;
1769 if (penWidthIn
+ penWidthOut
< penWidth
)
1774 for (i
= 0, j
= 0; i
< pPath
->numEntriesUsed
; i
++, j
++)
1777 if ((i
== 0 || (pPath
->pFlags
[i
- 1] & PT_CLOSEFIGURE
)) &&
1778 (pPath
->pFlags
[i
] != PT_MOVETO
))
1780 DPRINT1("Expected PT_MOVETO %s, got path flag %c\n",
1781 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1785 switch(pPath
->pFlags
[i
])
1790 pStrokes
[numStrokes
- 1]->state
= PATH_Closed
;
1792 numOldStrokes
= numStrokes
;
1795 if (numStrokes
== 1)
1796 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1799 pOldStrokes
= pStrokes
; // Save old pointer.
1800 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1801 if (!pStrokes
) return FALSE
;
1802 RtlCopyMemory(pStrokes
, pOldStrokes
, numOldStrokes
* sizeof(PPATH
));
1803 ExFreePoolWithTag(pOldStrokes
, TAG_PATH
); // Free old pointer.
1805 if (!pStrokes
) return FALSE
;
1806 pStrokes
[numStrokes
- 1] = ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1807 if (!pStrokes
[numStrokes
- 1])
1809 ASSERT(FALSE
); // FIXME
1812 PATH_InitGdiPath(pStrokes
[numStrokes
- 1]);
1813 pStrokes
[numStrokes
- 1]->state
= PATH_Open
;
1815 case (PT_LINETO
| PT_CLOSEFIGURE
):
1816 point
.x
= pPath
->pPoints
[i
].x
;
1817 point
.y
= pPath
->pPoints
[i
].y
;
1818 PATH_AddEntry(pStrokes
[numStrokes
- 1], &point
, pPath
->pFlags
[i
]);
1821 /* Should never happen because of the FlattenPath call */
1822 DPRINT1("Should never happen\n");
1825 DPRINT1("Got path flag %c\n", pPath
->pFlags
[i
]);
1830 pNewPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1833 ASSERT(FALSE
); // FIXME
1835 PATH_InitGdiPath(pNewPath
);
1836 pNewPath
->state
= PATH_Open
;
1838 for (i
= 0; i
< numStrokes
; i
++)
1840 pUpPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1841 PATH_InitGdiPath(pUpPath
);
1842 pUpPath
->state
= PATH_Open
;
1843 pDownPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1844 PATH_InitGdiPath(pDownPath
);
1845 pDownPath
->state
= PATH_Open
;
1847 for (j
= 0; j
< pStrokes
[i
]->numEntriesUsed
; j
++)
1849 /* Beginning or end of the path if not closed */
1850 if ((!(pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) && (j
== 0 || j
== pStrokes
[i
]->numEntriesUsed
- 1))
1852 /* Compute segment angle */
1853 double xo
, yo
, xa
, ya
, theta
;
1855 FLOAT_POINT corners
[2];
1858 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1859 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1860 xa
= pStrokes
[i
]->pPoints
[1].x
;
1861 ya
= pStrokes
[i
]->pPoints
[1].y
;
1865 xa
= pStrokes
[i
]->pPoints
[j
- 1].x
;
1866 ya
= pStrokes
[i
]->pPoints
[j
- 1].y
;
1867 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1868 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1870 theta
= atan2(ya
- yo
, xa
- xo
);
1873 case PS_ENDCAP_SQUARE
:
1874 pt
.x
= xo
+ round(sqrt(2) * penWidthOut
* cos(M_PI_4
+ theta
));
1875 pt
.y
= yo
+ round(sqrt(2) * penWidthOut
* sin(M_PI_4
+ theta
));
1876 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1877 pt
.x
= xo
+ round(sqrt(2) * penWidthIn
* cos(- M_PI_4
+ theta
));
1878 pt
.y
= yo
+ round(sqrt(2) * penWidthIn
* sin(- M_PI_4
+ theta
));
1879 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1881 case PS_ENDCAP_FLAT
:
1882 pt
.x
= xo
+ round(penWidthOut
* cos(theta
+ M_PI_2
));
1883 pt
.y
= yo
+ round(penWidthOut
* sin(theta
+ M_PI_2
));
1884 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1885 pt
.x
= xo
- round(penWidthIn
* cos(theta
+ M_PI_2
));
1886 pt
.y
= yo
- round(penWidthIn
* sin(theta
+ M_PI_2
));
1887 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1889 case PS_ENDCAP_ROUND
:
1891 corners
[0].x
= xo
- penWidthIn
;
1892 corners
[0].y
= yo
- penWidthIn
;
1893 corners
[1].x
= xo
+ penWidthOut
;
1894 corners
[1].y
= yo
+ penWidthOut
;
1895 PATH_DoArcPart(pUpPath
, corners
, theta
+ M_PI_2
, theta
+ 3 * M_PI_4
, (j
== 0 ? PT_MOVETO
: FALSE
));
1896 PATH_DoArcPart(pUpPath
, corners
, theta
+ 3 * M_PI_4
, theta
+ M_PI
, FALSE
);
1897 PATH_DoArcPart(pUpPath
, corners
, theta
+ M_PI
, theta
+ 5 * M_PI_4
, FALSE
);
1898 PATH_DoArcPart(pUpPath
, corners
, theta
+ 5 * M_PI_4
, theta
+ 3 * M_PI_2
, FALSE
);
1902 /* Corpse of the path */
1907 double xa
, ya
, xb
, yb
, xo
, yo
;
1908 double alpha
, theta
, miterWidth
;
1909 DWORD _joint
= joint
;
1911 PPATH pInsidePath
, pOutsidePath
;
1912 if (j
> 0 && j
< pStrokes
[i
]->numEntriesUsed
- 1)
1919 previous
= pStrokes
[i
]->numEntriesUsed
- 1;
1927 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1928 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1929 xa
= pStrokes
[i
]->pPoints
[previous
].x
;
1930 ya
= pStrokes
[i
]->pPoints
[previous
].y
;
1931 xb
= pStrokes
[i
]->pPoints
[next
].x
;
1932 yb
= pStrokes
[i
]->pPoints
[next
].y
;
1933 theta
= atan2(yo
- ya
, xo
- xa
);
1934 alpha
= atan2(yb
- yo
, xb
- xo
) - theta
;
1935 if (alpha
> 0) alpha
-= M_PI
;
1937 if (_joint
== PS_JOIN_MITER
&& dc
->dclevel
.laPath
.eMiterLimit
< fabs(1 / sin(alpha
/ 2)))
1939 _joint
= PS_JOIN_BEVEL
;
1943 pInsidePath
= pUpPath
;
1944 pOutsidePath
= pDownPath
;
1948 pInsidePath
= pDownPath
;
1949 pOutsidePath
= pUpPath
;
1955 /* Inside angle points */
1958 pt
.x
= xo
- round(penWidthIn
* cos(theta
+ M_PI_2
));
1959 pt
.y
= yo
- round(penWidthIn
* sin(theta
+ M_PI_2
));
1963 pt
.x
= xo
+ round(penWidthIn
* cos(theta
+ M_PI_2
));
1964 pt
.y
= yo
+ round(penWidthIn
* sin(theta
+ M_PI_2
));
1966 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1969 pt
.x
= xo
+ round(penWidthIn
* cos(M_PI_2
+ alpha
+ theta
));
1970 pt
.y
= yo
+ round(penWidthIn
* sin(M_PI_2
+ alpha
+ theta
));
1974 pt
.x
= xo
- round(penWidthIn
* cos(M_PI_2
+ alpha
+ theta
));
1975 pt
.y
= yo
- round(penWidthIn
* sin(M_PI_2
+ alpha
+ theta
));
1977 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1978 /* Outside angle point */
1981 case PS_JOIN_MITER
:
1982 miterWidth
= fabs(penWidthOut
/ cos(M_PI_2
- fabs(alpha
) / 2));
1983 pt
.x
= xo
+ round(miterWidth
* cos(theta
+ alpha
/ 2));
1984 pt
.y
= yo
+ round(miterWidth
* sin(theta
+ alpha
/ 2));
1985 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1987 case PS_JOIN_BEVEL
:
1990 pt
.x
= xo
+ round(penWidthOut
* cos(theta
+ M_PI_2
));
1991 pt
.y
= yo
+ round(penWidthOut
* sin(theta
+ M_PI_2
));
1995 pt
.x
= xo
- round(penWidthOut
* cos(theta
+ M_PI_2
));
1996 pt
.y
= yo
- round(penWidthOut
* sin(theta
+ M_PI_2
));
1998 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
2001 pt
.x
= xo
- round(penWidthOut
* cos(M_PI_2
+ alpha
+ theta
));
2002 pt
.y
= yo
- round(penWidthOut
* sin(M_PI_2
+ alpha
+ theta
));
2006 pt
.x
= xo
+ round(penWidthOut
* cos(M_PI_2
+ alpha
+ theta
));
2007 pt
.y
= yo
+ round(penWidthOut
* sin(M_PI_2
+ alpha
+ theta
));
2009 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
2011 case PS_JOIN_ROUND
:
2015 pt
.x
= xo
+ round(penWidthOut
* cos(theta
+ M_PI_2
));
2016 pt
.y
= yo
+ round(penWidthOut
* sin(theta
+ M_PI_2
));
2020 pt
.x
= xo
- round(penWidthOut
* cos(theta
+ M_PI_2
));
2021 pt
.y
= yo
- round(penWidthOut
* sin(theta
+ M_PI_2
));
2023 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
2024 pt
.x
= xo
+ round(penWidthOut
* cos(theta
+ alpha
/ 2));
2025 pt
.y
= yo
+ round(penWidthOut
* sin(theta
+ alpha
/ 2));
2026 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
2029 pt
.x
= xo
- round(penWidthOut
* cos(M_PI_2
+ alpha
+ theta
));
2030 pt
.y
= yo
- round(penWidthOut
* sin(M_PI_2
+ alpha
+ theta
));
2034 pt
.x
= xo
+ round(penWidthOut
* cos(M_PI_2
+ alpha
+ theta
));
2035 pt
.y
= yo
+ round(penWidthOut
* sin(M_PI_2
+ alpha
+ theta
));
2037 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
2042 for (j
= 0; j
< pUpPath
->numEntriesUsed
; j
++)
2045 pt
.x
= pUpPath
->pPoints
[j
].x
;
2046 pt
.y
= pUpPath
->pPoints
[j
].y
;
2047 PATH_AddEntry(pNewPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
2049 for (j
= 0; j
< pDownPath
->numEntriesUsed
; j
++)
2052 pt
.x
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].x
;
2053 pt
.y
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].y
;
2054 PATH_AddEntry(pNewPath
, &pt
, ((j
== 0 && (pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) ? PT_MOVETO
: PT_LINETO
));
2057 PATH_DestroyGdiPath(pStrokes
[i
]);
2058 ExFreePoolWithTag(pStrokes
[i
], TAG_PATH
);
2059 PATH_DestroyGdiPath(pUpPath
);
2060 ExFreePoolWithTag(pUpPath
, TAG_PATH
);
2061 PATH_DestroyGdiPath(pDownPath
);
2062 ExFreePoolWithTag(pDownPath
, TAG_PATH
);
2064 if (pStrokes
) ExFreePoolWithTag(pStrokes
, TAG_PATH
);
2066 pNewPath
->state
= PATH_Closed
;
2067 if (!(ret
= PATH_AssignGdiPath(pPath
, pNewPath
)))
2068 DPRINT1("Assign path failed\n");
2069 PATH_DestroyGdiPath(pNewPath
);
2070 ExFreePoolWithTag(pNewPath
, TAG_PATH
);
2071 PATH_UnlockPath(pPath
);
2075 static inline INT
int_from_fixed(FIXED f
)
2077 return (f
.fract
>= 0x8000) ? (f
.value
+ 1) : f
.value
;
2080 /**********************************************************************
2083 * Internally used by PATH_add_outline
2097 PATH_AddEntry(pPath
, &lppt
[1], PT_LINETO
);
2101 PATH_AddEntry(pPath
, &lppt
[0], PT_BEZIERTO
);
2102 PATH_AddEntry(pPath
, &lppt
[1], PT_BEZIERTO
);
2103 PATH_AddEntry(pPath
, &lppt
[2], PT_BEZIERTO
);
2116 pt
[1] = lppt
[i
+ 1];
2117 pt
[2].x
= (lppt
[i
+ 2].x
+ lppt
[i
+ 1].x
) / 2;
2118 pt
[2].y
= (lppt
[i
+ 2].y
+ lppt
[i
+ 1].y
) / 2;
2119 PATH_BezierTo(pPath
, pt
, 3);
2125 pt
[1] = lppt
[i
+ 1];
2126 pt
[2] = lppt
[i
+ 2];
2127 PATH_BezierTo(pPath
, pt
, 3);
2138 TTPOLYGONHEADER
*header
,
2142 TTPOLYGONHEADER
*start
;
2144 BOOL bResult
= FALSE
;
2148 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2154 while ((char *)header
< (char *)start
+ size
)
2158 if (header
->dwType
!= TT_POLYGON_TYPE
)
2160 DPRINT1("Unknown header type %lu\n", header
->dwType
);
2164 pt
.x
= x
+ int_from_fixed(header
->pfxStart
.x
);
2165 pt
.y
= y
- int_from_fixed(header
->pfxStart
.y
);
2166 PATH_AddEntry(pPath
, &pt
, PT_MOVETO
);
2168 curve
= (TTPOLYCURVE
*)(header
+ 1);
2170 while ((char *)curve
< (char *)header
+ header
->cb
)
2172 /*DPRINT1("curve->wType %d\n", curve->wType);*/
2174 switch(curve
->wType
)
2180 for (i
= 0; i
< curve
->cpfx
; i
++)
2182 pt
.x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
2183 pt
.y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
2184 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
2189 case TT_PRIM_QSPLINE
:
2190 case TT_PRIM_CSPLINE
:
2194 POINT
*pts
= ExAllocatePoolWithTag(PagedPool
, (curve
->cpfx
+ 1) * sizeof(POINT
), TAG_PATH
);
2196 if (!pts
) goto cleanup
;
2198 ptfx
= *(POINTFX
*)((char *)curve
- sizeof(POINTFX
));
2200 pts
[0].x
= x
+ int_from_fixed(ptfx
.x
);
2201 pts
[0].y
= y
- int_from_fixed(ptfx
.y
);
2203 for (i
= 0; i
< curve
->cpfx
; i
++)
2205 pts
[i
+ 1].x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
2206 pts
[i
+ 1].y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
2209 PATH_BezierTo(pPath
, pts
, curve
->cpfx
+ 1);
2211 ExFreePoolWithTag(pts
, TAG_PATH
);
2216 DPRINT1("Unknown curve type %04x\n", curve
->wType
);
2220 curve
= (TTPOLYCURVE
*)&curve
->apfx
[curve
->cpfx
];
2222 header
= (TTPOLYGONHEADER
*)((char *)header
+ header
->cb
);
2228 IntGdiCloseFigure(pPath
);
2229 PATH_UnlockPath(pPath
);
2233 /**********************************************************************
2249 POINT offset
= {0, 0};
2251 if (!count
) return TRUE
;
2253 for (idx
= 0; idx
< count
; idx
++)
2255 MAT2 identity
= { {0, 1}, {0, 0}, {0, 0}, {0, 1} };
2260 dwSize
= ftGdiGetGlyphOutline(dc
,
2262 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2268 if (dwSize
== GDI_ERROR
) return FALSE
;
2270 /* Add outline only if char is printable */
2273 outline
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_PATH
);
2274 if (!outline
) return FALSE
;
2276 ftGdiGetGlyphOutline(dc
,
2278 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2285 PATH_add_outline(dc
, x
+ offset
.x
, y
+ offset
.y
, outline
, dwSize
);
2287 ExFreePoolWithTag(outline
, TAG_PATH
);
2292 if (flags
& ETO_PDY
)
2294 offset
.x
+= dx
[idx
* 2];
2295 offset
.y
+= dx
[idx
* 2 + 1];
2298 offset
.x
+= dx
[idx
];
2302 offset
.x
+= gm
.gmCellIncX
;
2303 offset
.y
+= gm
.gmCellIncY
;
2310 /***********************************************************************
2311 * Exported functions
2316 NtGdiAbortPath(HDC hDC
)
2319 PDC dc
= DC_LockDc(hDC
);
2322 EngSetLastError(ERROR_INVALID_HANDLE
);
2326 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2333 PATH_EmptyPath(pPath
);
2335 PATH_UnlockPath(pPath
);
2336 dc
->dclevel
.flPath
&= ~DCPATH_ACTIVE
;
2344 NtGdiBeginPath(HDC hDC
)
2349 dc
= DC_LockDc(hDC
);
2352 EngSetLastError(ERROR_INVALID_HANDLE
);
2356 /* If path is already open, do nothing. Check if not Save DC state */
2357 if ((dc
->dclevel
.flPath
& DCPATH_ACTIVE
) && !(dc
->dclevel
.flPath
& DCPATH_SAVE
))
2363 if (dc
->dclevel
.hPath
)
2365 DPRINT("BeginPath 1 0x%p\n", dc
->dclevel
.hPath
);
2366 if (!(dc
->dclevel
.flPath
& DCPATH_SAVE
))
2368 // Remove previous handle.
2369 if (!PATH_Delete(dc
->dclevel
.hPath
))
2377 // Clear flags and Handle.
2378 dc
->dclevel
.flPath
&= ~(DCPATH_SAVE
| DCPATH_ACTIVE
);
2379 dc
->dclevel
.hPath
= NULL
;
2382 pPath
= PATH_AllocPathWithHandle();
2385 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2388 dc
->dclevel
.flPath
|= DCPATH_ACTIVE
; // Set active ASAP!
2390 dc
->dclevel
.hPath
= pPath
->BaseObject
.hHmgr
;
2392 DPRINT("BeginPath 2 h 0x%p p 0x%p\n", dc
->dclevel
.hPath
, pPath
);
2393 // Path handles are shared. Also due to recursion with in the same thread.
2394 GDIOBJ_vUnlockObject((POBJ
)pPath
); // Unlock
2395 pPath
= PATH_LockPath(dc
->dclevel
.hPath
); // Share Lock.
2397 /* Make sure that path is empty */
2398 PATH_EmptyPath(pPath
);
2400 /* Initialize variables for new path */
2401 pPath
->newStroke
= TRUE
;
2402 pPath
->state
= PATH_Open
;
2404 PATH_UnlockPath(pPath
);
2411 NtGdiCloseFigure(HDC hDC
)
2413 BOOL Ret
= FALSE
; // Default to failure
2417 DPRINT("Enter %s\n", __FUNCTION__
);
2419 pDc
= DC_LockDc(hDC
);
2422 EngSetLastError(ERROR_INVALID_PARAMETER
);
2426 pPath
= PATH_LockPath(pDc
->dclevel
.hPath
);
2433 if (pPath
->state
== PATH_Open
)
2435 IntGdiCloseFigure(pPath
);
2440 // FIXME: Check if lasterror is set correctly
2441 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2444 PATH_UnlockPath(pPath
);
2451 NtGdiEndPath(HDC hDC
)
2457 dc
= DC_LockDc(hDC
);
2460 EngSetLastError(ERROR_INVALID_HANDLE
);
2464 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2471 /* Check that path is currently being constructed */
2472 if ((pPath
->state
!= PATH_Open
) || !(dc
->dclevel
.flPath
& DCPATH_ACTIVE
))
2474 DPRINT1("EndPath ERROR! 0x%p\n", dc
->dclevel
.hPath
);
2475 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2478 /* Set flag to indicate that path is finished */
2481 DPRINT("EndPath 0x%p\n", dc
->dclevel
.hPath
);
2482 pPath
->state
= PATH_Closed
;
2483 dc
->dclevel
.flPath
&= ~DCPATH_ACTIVE
;
2486 PATH_UnlockPath(pPath
);
2493 NtGdiFillPath(HDC hDC
)
2500 dc
= DC_LockDc(hDC
);
2503 EngSetLastError(ERROR_INVALID_PARAMETER
);
2507 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2514 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
2516 pdcattr
= dc
->pdcattr
;
2518 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2519 DC_vUpdateLineBrush(dc
);
2521 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
2522 DC_vUpdateFillBrush(dc
);
2524 ret
= PATH_FillPath(dc
, pPath
);
2527 /* FIXME: Should the path be emptied even if conversion
2529 PATH_EmptyPath(pPath
);
2532 PATH_UnlockPath(pPath
);
2533 DC_vFinishBlit(dc
, NULL
);
2540 NtGdiFlattenPath(HDC hDC
)
2546 DPRINT("Enter %s\n", __FUNCTION__
);
2548 pDc
= DC_LockDc(hDC
);
2551 EngSetLastError(ERROR_INVALID_HANDLE
);
2555 pPath
= PATH_LockPath(pDc
->dclevel
.hPath
);
2561 if (pPath
->state
== PATH_Open
)
2562 Ret
= PATH_FlattenPath(pPath
);
2564 PATH_UnlockPath(pPath
);
2569 _Success_(return != FALSE
)
2574 _Out_ PDWORD pdwOut
)
2577 BOOL bResult
= TRUE
;
2579 if (!(pDc
= DC_LockDc(hdc
)))
2581 EngSetLastError(ERROR_INVALID_PARAMETER
);
2587 ProbeForWrite(pdwOut
, sizeof(DWORD
), 1);
2588 *pdwOut
= pDc
->dclevel
.laPath
.eMiterLimit
;
2590 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2592 SetLastNtError(_SEH2_GetExceptionCode());
2613 DC
*dc
= DC_LockDc(hDC
);
2616 DPRINT1("Can't lock dc!\n");
2617 EngSetLastError(ERROR_INVALID_PARAMETER
);
2621 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2628 if (pPath
->state
!= PATH_Closed
)
2630 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2636 ret
= pPath
->numEntriesUsed
;
2638 else if (nSize
< pPath
->numEntriesUsed
)
2640 EngSetLastError(ERROR_INVALID_PARAMETER
);
2647 memcpy(Points
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
2648 memcpy(Types
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
2650 /* Convert the points to logical coordinates */
2651 if (!GdiPathDPtoLP(dc
, Points
, pPath
->numEntriesUsed
))
2653 EngSetLastError(ERROR_ARITHMETIC_OVERFLOW
);
2657 ret
= pPath
->numEntriesUsed
;
2659 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2661 SetLastNtError(_SEH2_GetExceptionCode());
2667 PATH_UnlockPath(pPath
);
2674 NtGdiPathToRegion(HDC hDC
)
2681 DPRINT("Enter %s\n", __FUNCTION__
);
2683 pDc
= DC_LockDc(hDC
);
2686 EngSetLastError(ERROR_INVALID_PARAMETER
);
2690 pdcattr
= pDc
->pdcattr
;
2692 pPath
= PATH_LockPath(pDc
->dclevel
.hPath
);
2699 if (pPath
->state
!= PATH_Closed
)
2701 // FIXME: Check that setlasterror is being called correctly
2702 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2706 /* FIXME: Should we empty the path even if conversion failed? */
2707 if (PATH_PathToRegion(pPath
, pdcattr
->jFillMode
, &hrgnRval
))
2708 PATH_EmptyPath(pPath
);
2711 PATH_UnlockPath(pPath
);
2721 IN OUT OPTIONAL PDWORD pdwOut
)
2724 gxf_long worker
, worker1
;
2725 BOOL bResult
= TRUE
;
2727 if (!(pDc
= DC_LockDc(hdc
)))
2729 EngSetLastError(ERROR_INVALID_PARAMETER
);
2734 worker1
.f
= pDc
->dclevel
.laPath
.eMiterLimit
;
2735 pDc
->dclevel
.laPath
.eMiterLimit
= worker
.f
;
2741 ProbeForWrite(pdwOut
, sizeof(DWORD
), 1);
2742 *pdwOut
= worker1
.l
;
2744 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2746 SetLastNtError(_SEH2_GetExceptionCode());
2758 NtGdiStrokeAndFillPath(HDC hDC
)
2765 DPRINT1("Enter %s\n", __FUNCTION__
);
2767 if (!(pDc
= DC_LockDc(hDC
)))
2769 EngSetLastError(ERROR_INVALID_PARAMETER
);
2772 pPath
= PATH_LockPath(pDc
->dclevel
.hPath
);
2779 DC_vPrepareDCsForBlit(pDc
, NULL
, NULL
, NULL
);
2781 pdcattr
= pDc
->pdcattr
;
2783 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
2784 DC_vUpdateFillBrush(pDc
);
2786 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2787 DC_vUpdateLineBrush(pDc
);
2789 bRet
= PATH_FillPath(pDc
, pPath
);
2790 if (bRet
) bRet
= PATH_StrokePath(pDc
, pPath
);
2791 if (bRet
) PATH_EmptyPath(pPath
);
2793 PATH_UnlockPath(pPath
);
2794 DC_vFinishBlit(pDc
, NULL
);
2801 NtGdiStrokePath(HDC hDC
)
2808 DPRINT("Enter %s\n", __FUNCTION__
);
2810 if (!(pDc
= DC_LockDc(hDC
)))
2812 EngSetLastError(ERROR_INVALID_PARAMETER
);
2816 pPath
= PATH_LockPath(pDc
->dclevel
.hPath
);
2823 DC_vPrepareDCsForBlit(pDc
, NULL
, NULL
, NULL
);
2825 pdcattr
= pDc
->pdcattr
;
2827 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2828 DC_vUpdateLineBrush(pDc
);
2830 bRet
= PATH_StrokePath(pDc
, pPath
);
2832 DC_vFinishBlit(pDc
, NULL
);
2833 PATH_EmptyPath(pPath
);
2835 PATH_UnlockPath(pPath
);
2842 NtGdiWidenPath(HDC hDC
)
2845 PDC pdc
= DC_LockDc(hDC
);
2848 EngSetLastError(ERROR_INVALID_PARAMETER
);
2852 Ret
= PATH_WidenPath(pdc
);