2 * PROJECT: ReactOS win32 kernel mode subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/gdi/ntgdi/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 /* Allocate a temporary region */
111 Rgn
= IntSysCreateRectpRgn(0, 0, 0, 0);
114 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
118 if (!PATH_PathToRegion(pPath
, pdcattr
->jFillMode
, Rgn
))
120 /* EngSetLastError ? */
125 /* Since PaintRgn interprets the region as being in logical coordinates
126 * but the points we store for the path are already in device
127 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
128 * Using SaveDC to save information about the mapping mode / world
129 * transform would be easier but would require more overhead, especially
130 * now that SaveDC saves the current path.
133 /* Save the information about the old mapping mode */
134 //mapMode = pdcattr->iMapMode;
135 //ptViewportExt = pdcattr->szlViewportExt;
136 //ptViewportOrg = pdcattr->ptlViewportOrg;
137 //ptWindowExt = pdcattr->szlWindowExt;
138 //ptWindowOrg = pdcattr->ptlWindowOrg;
140 /* Save world transform
141 * NB: The Windows documentation on world transforms would lead one to
142 * believe that this has to be done only in GM_ADVANCED; however, my
143 * tests show that resetting the graphics mode to GM_COMPATIBLE does
144 * not reset the world transform.
146 MatrixS2XForm(&xform
, &dc
->pdcattr
->mxWorldToPage
);
149 // IntGdiSetMapMode(dc, MM_TEXT);
150 // pdcattr->ptlViewportOrg.x = 0;
151 // pdcattr->ptlViewportOrg.y = 0;
152 // pdcattr->ptlWindowOrg.x = 0;
153 // pdcattr->ptlWindowOrg.y = 0;
155 // graphicsMode = pdcattr->iGraphicsMode;
156 // pdcattr->iGraphicsMode = GM_ADVANCED;
157 // IntGdiModifyWorldTransform(dc, &xform, MWT_IDENTITY);
158 // pdcattr->iGraphicsMode = graphicsMode;
160 /* Paint the region */
161 IntGdiPaintRgn(dc
, Rgn
);
163 /* Restore the old mapping mode */
164 // IntGdiSetMapMode(dc, mapMode);
165 // pdcattr->szlViewportExt = ptViewportExt;
166 // pdcattr->ptlViewportOrg = ptViewportOrg;
167 // pdcattr->szlWindowExt = ptWindowExt;
168 // pdcattr->ptlWindowOrg = ptWindowOrg;
170 /* Go to GM_ADVANCED temporarily to restore the world transform */
171 //graphicsMode = pdcattr->iGraphicsMode;
172 // pdcattr->iGraphicsMode = GM_ADVANCED;
173 // IntGdiModifyWorldTransform(dc, &xform, MWT_MAX+1);
174 // pdcattr->iGraphicsMode = graphicsMode;
180 * Initializes the GdiPath structure.
187 ASSERT(pPath
!= NULL
);
189 pPath
->state
= PATH_Null
;
190 pPath
->pPoints
= NULL
;
191 pPath
->pFlags
= NULL
;
192 pPath
->numEntriesUsed
= 0;
193 pPath
->numEntriesAllocated
= 0;
196 /* PATH_AssignGdiPath
198 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
199 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
200 * not just the pointers. Since this means that the arrays in pPathDest may
201 * need to be resized, pPathDest should have been initialized using
202 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
203 * not a copy constructor).
204 * Returns TRUE if successful, else FALSE.
210 const PPATH pPathSrc
)
212 ASSERT(pPathDest
!= NULL
&& pPathSrc
!= NULL
);
214 /* Make sure destination arrays are big enough */
215 if (!PATH_ReserveEntries(pPathDest
, pPathSrc
->numEntriesUsed
))
218 /* Perform the copy operation */
219 memcpy(pPathDest
->pPoints
, pPathSrc
->pPoints
,
220 sizeof(POINT
)*pPathSrc
->numEntriesUsed
);
221 memcpy(pPathDest
->pFlags
, pPathSrc
->pFlags
,
222 sizeof(BYTE
)*pPathSrc
->numEntriesUsed
);
224 pPathDest
->state
= pPathSrc
->state
;
225 pPathDest
->numEntriesUsed
= pPathSrc
->numEntriesUsed
;
226 pPathDest
->newStroke
= pPathSrc
->newStroke
;
232 * Should be called when a MoveTo is performed on a DC that has an
233 * open path. This starts a new stroke. Returns TRUE if successful, else
241 PPATH pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
242 if (!pPath
) return FALSE
;
244 /* Check that path is open */
245 if (pPath
->state
!= PATH_Open
)
247 PATH_UnlockPath(pPath
);
248 /* FIXME: Do we have to call SetLastError? */
251 /* Start a new stroke */
252 pPath
->newStroke
= TRUE
;
253 PATH_UnlockPath(pPath
);
259 * Should be called when a LineTo is performed on a DC that has an
260 * open path. This adds a PT_LINETO entry to the path (and possibly
261 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
262 * Returns TRUE if successful, else FALSE.
273 POINT point
, pointCurPos
;
275 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
276 if (!pPath
) return FALSE
;
278 /* Check that path is open */
279 if (pPath
->state
!= PATH_Open
)
281 PATH_UnlockPath(pPath
);
285 /* Convert point to device coordinates */
288 CoordLPtoDP(dc
, &point
);
290 /* Add a PT_MOVETO if necessary */
291 if (pPath
->newStroke
)
293 pPath
->newStroke
= FALSE
;
294 IntGetCurrentPositionEx(dc
, &pointCurPos
);
295 CoordLPtoDP(dc
, &pointCurPos
);
296 if (!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
298 PATH_UnlockPath(pPath
);
303 /* Add a PT_LINETO entry */
304 Ret
= PATH_AddEntry(pPath
, &point
, PT_LINETO
);
305 PATH_UnlockPath(pPath
);
311 * Should be called when a call to Rectangle is performed on a DC that has
312 * an open path. Returns TRUE if successful, else FALSE.
324 POINT corners
[2], pointTemp
;
327 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
328 if (!pPath
) return FALSE
;
330 /* Check that path is open */
331 if (pPath
->state
!= PATH_Open
)
333 PATH_UnlockPath(pPath
);
337 /* Convert points to device coordinates */
342 IntLPtoDP(dc
, corners
, 2);
344 /* Make sure first corner is top left and second corner is bottom right */
345 if (corners
[0].x
> corners
[1].x
)
348 corners
[0].x
= corners
[1].x
;
351 if (corners
[0].y
> corners
[1].y
)
354 corners
[0].y
= corners
[1].y
;
358 /* In GM_COMPATIBLE, don't include bottom and right edges */
359 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
365 /* Close any previous figure */
366 IntGdiCloseFigure(pPath
);
368 /* Add four points to the path */
369 pointTemp
.x
= corners
[1].x
;
370 pointTemp
.y
= corners
[0].y
;
371 if (!PATH_AddEntry(pPath
, &pointTemp
, PT_MOVETO
))
373 PATH_UnlockPath(pPath
);
376 if (!PATH_AddEntry(pPath
, corners
, PT_LINETO
))
378 PATH_UnlockPath(pPath
);
381 pointTemp
.x
= corners
[0].x
;
382 pointTemp
.y
= corners
[1].y
;
383 if (!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
385 PATH_UnlockPath(pPath
);
388 if (!PATH_AddEntry(pPath
, corners
+ 1, PT_LINETO
))
390 PATH_UnlockPath(pPath
);
394 /* Close the rectangle figure */
395 IntGdiCloseFigure(pPath
) ;
396 PATH_UnlockPath(pPath
);
402 * Should be called when a call to RoundRect is performed on a DC that has
403 * an open path. Returns TRUE if successful, else FALSE.
405 * FIXME: It adds the same entries to the path as windows does, but there
406 * is an error in the bezier drawing code so that there are small pixel-size
407 * gaps when the resulting path is drawn by StrokePath()
421 POINT corners
[2], pointTemp
;
422 FLOAT_POINT ellCorners
[2];
424 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
425 if (!pPath
) return FALSE
;
427 /* Check that path is open */
428 if (pPath
->state
!= PATH_Open
)
430 PATH_UnlockPath(pPath
);
434 if (!PATH_CheckCorners(dc
, corners
, x1
, y1
, x2
, y2
))
436 PATH_UnlockPath(pPath
);
440 /* Add points to the roundrect path */
441 ellCorners
[0].x
= corners
[1].x
- ell_width
;
442 ellCorners
[0].y
= corners
[0].y
;
443 ellCorners
[1].x
= corners
[1].x
;
444 ellCorners
[1].y
= corners
[0].y
+ ell_height
;
445 if (!PATH_DoArcPart(pPath
, ellCorners
, 0, -M_PI_2
, PT_MOVETO
))
447 PATH_UnlockPath(pPath
);
450 pointTemp
.x
= corners
[0].x
+ ell_width
/ 2;
451 pointTemp
.y
= corners
[0].y
;
452 if (!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
454 PATH_UnlockPath(pPath
);
457 ellCorners
[0].x
= corners
[0].x
;
458 ellCorners
[1].x
= corners
[0].x
+ ell_width
;
459 if (!PATH_DoArcPart(pPath
, ellCorners
, -M_PI_2
, -M_PI
, FALSE
))
461 PATH_UnlockPath(pPath
);
464 pointTemp
.x
= corners
[0].x
;
465 pointTemp
.y
= corners
[1].y
- ell_height
/ 2;
466 if (!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
468 PATH_UnlockPath(pPath
);
471 ellCorners
[0].y
= corners
[1].y
- ell_height
;
472 ellCorners
[1].y
= corners
[1].y
;
473 if (!PATH_DoArcPart(pPath
, ellCorners
, M_PI
, M_PI_2
, FALSE
))
475 PATH_UnlockPath(pPath
);
478 pointTemp
.x
= corners
[1].x
- ell_width
/ 2;
479 pointTemp
.y
= corners
[1].y
;
480 if (!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
482 PATH_UnlockPath(pPath
);
485 ellCorners
[0].x
= corners
[1].x
- ell_width
;
486 ellCorners
[1].x
= corners
[1].x
;
487 if (!PATH_DoArcPart(pPath
, ellCorners
, M_PI_2
, 0, FALSE
))
489 PATH_UnlockPath(pPath
);
493 IntGdiCloseFigure(pPath
);
494 PATH_UnlockPath(pPath
);
500 * Should be called when a call to Ellipse is performed on a DC that has
501 * an open path. This adds four Bezier splines representing the ellipse
502 * to the path. Returns TRUE if successful, else FALSE.
514 /* TODO: This should probably be revised to call PATH_AngleArc */
515 /* (once it exists) */
516 BOOL Ret
= PATH_Arc(dc
, x1
, y1
, x2
, y2
, x1
, (y1
+ y2
) / 2, x1
, (y1
+ y2
) / 2, GdiTypeArc
);
519 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
520 if (!pPath
) return FALSE
;
521 IntGdiCloseFigure(pPath
);
522 PATH_UnlockPath(pPath
);
529 * Should be called when a call to Arc is performed on a DC that has
530 * an open path. This adds up to five Bezier splines representing the arc
531 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
532 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
533 * -1 we add 1 extra line from the current DC position to the starting position
534 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
551 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
= 0.0;
552 /* Initialize angleEndQuadrant to silence gcc's warning */
554 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
555 POINT centre
, pointCurPos
;
556 BOOL start
, end
, Ret
= TRUE
;
561 /* FIXME: This function should check for all possible error returns */
562 /* FIXME: Do we have to respect newStroke? */
566 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
567 if (!pPath
) return FALSE
;
569 clockwise
= ((dc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
571 /* Check that path is open */
572 if (pPath
->state
!= PATH_Open
)
578 /* Check for zero height / width */
579 /* FIXME: Only in GM_COMPATIBLE? */
580 if (x1
== x2
|| y1
== y2
)
585 /* Convert points to device coordinates */
586 corners
[0].x
= (FLOAT
)x1
;
587 corners
[0].y
= (FLOAT
)y1
;
588 corners
[1].x
= (FLOAT
)x2
;
589 corners
[1].y
= (FLOAT
)y2
;
590 pointStart
.x
= (FLOAT
)xStart
;
591 pointStart
.y
= (FLOAT
)yStart
;
592 pointEnd
.x
= (FLOAT
)xEnd
;
593 pointEnd
.y
= (FLOAT
)yEnd
;
594 INTERNAL_LPTODP_FLOAT(dc
, corners
);
595 INTERNAL_LPTODP_FLOAT(dc
, corners
+ 1);
596 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
);
597 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
);
599 /* Make sure first corner is top left and second corner is bottom right */
600 if (corners
[0].x
> corners
[1].x
)
603 corners
[0].x
= corners
[1].x
;
606 if (corners
[0].y
> corners
[1].y
)
609 corners
[0].y
= corners
[1].y
;
613 /* Compute start and end angle */
614 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
615 angleStart
= atan2(y
, x
);
616 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
617 angleEnd
= atan2(y
, x
);
619 /* Make sure the end angle is "on the right side" of the start angle */
622 if (angleEnd
<= angleStart
)
624 angleEnd
+= 2 * M_PI
;
625 ASSERT(angleEnd
>= angleStart
);
630 if (angleEnd
>= angleStart
)
632 angleEnd
-= 2 * M_PI
;
633 ASSERT(angleEnd
<= angleStart
);
637 /* In GM_COMPATIBLE, don't include bottom and right edges */
638 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
644 /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
645 if (lines
== GdiTypeArcTo
&& pPath
->newStroke
) // -1
647 pPath
->newStroke
= FALSE
;
648 IntGetCurrentPositionEx(dc
, &pointCurPos
);
649 CoordLPtoDP(dc
, &pointCurPos
);
650 if (!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
657 /* Add the arc to the path with one Bezier spline per quadrant that the
663 /* Determine the start and end angles for this quadrant */
666 angleStartQuadrant
= angleStart
;
668 angleEndQuadrant
= (floor(angleStart
/ M_PI_2
) + 1.0) * M_PI_2
;
670 angleEndQuadrant
= (ceil(angleStart
/ M_PI_2
) - 1.0) * M_PI_2
;
674 angleStartQuadrant
= angleEndQuadrant
;
676 angleEndQuadrant
+= M_PI_2
;
678 angleEndQuadrant
-= M_PI_2
;
681 /* Have we reached the last part of the arc? */
682 if ((clockwise
&& angleEnd
< angleEndQuadrant
) ||
683 (!clockwise
&& angleEnd
> angleEndQuadrant
))
685 /* Adjust the end angle for this quadrant */
686 angleEndQuadrant
= angleEnd
;
690 /* Add the Bezier spline to the path */
691 PATH_DoArcPart(pPath
,
695 start
? (lines
== GdiTypeArcTo
? PT_LINETO
: PT_MOVETO
) : FALSE
); // -1
700 /* chord: close figure. pie: add line and close figure */
701 if (lines
== GdiTypeChord
) // 1
703 IntGdiCloseFigure(pPath
);
705 else if (lines
== GdiTypePie
) // 2
707 centre
.x
= (corners
[0].x
+ corners
[1].x
) / 2;
708 centre
.y
= (corners
[0].y
+ corners
[1].y
) / 2;
709 if (!PATH_AddEntry(pPath
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
713 PATH_UnlockPath(pPath
);
732 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
733 if (!pPath
) return FALSE
;
735 /* Check that path is open */
736 if (pPath
->state
!= PATH_Open
)
738 PATH_UnlockPath(pPath
);
742 /* Add a PT_MOVETO if necessary */
743 if (pPath
->newStroke
)
745 pPath
->newStroke
= FALSE
;
746 IntGetCurrentPositionEx(dc
, &pt
);
747 CoordLPtoDP(dc
, &pt
);
748 if (!PATH_AddEntry(pPath
, &pt
, PT_MOVETO
))
750 PATH_UnlockPath(pPath
);
755 for (i
= 0; i
< cbPoints
; i
++)
758 CoordLPtoDP(dc
, &pt
);
759 PATH_AddEntry(pPath
, &pt
, PT_BEZIERTO
);
762 PATH_UnlockPath(pPath
);
781 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
782 if (!pPath
) return FALSE
;
784 /* Check that path is open */
785 if (pPath
->state
!= PATH_Open
)
787 PATH_UnlockPath(pPath
);
791 for (i
= 0; i
< cbPoints
; i
++)
794 CoordLPtoDP(dc
, &pt
);
795 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_BEZIERTO
);
798 PATH_UnlockPath(pPath
);
811 POINT lastmove
, orig_pos
;
814 BOOL State
= FALSE
, Ret
= FALSE
;
816 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
817 if (!pPath
) return FALSE
;
819 if (pPath
->state
!= PATH_Open
)
821 PATH_UnlockPath(pPath
);
825 pdcattr
= dc
->pdcattr
;
827 lastmove
.x
= orig_pos
.x
= pdcattr
->ptlCurrent
.x
;
828 lastmove
.y
= orig_pos
.y
= pdcattr
->ptlCurrent
.y
;
830 i
= pPath
->numEntriesUsed
;
835 if (pPath
->pFlags
[i
] == PT_MOVETO
)
837 lastmove
.x
= pPath
->pPoints
[i
].x
;
838 lastmove
.y
= pPath
->pPoints
[i
].y
;
839 if (!GdiPathDPtoLP(dc
, &lastmove
, 1))
841 PATH_UnlockPath(pPath
);
848 for (i
= 0; i
< cbPoints
; i
++)
850 if (types
[i
] == PT_MOVETO
)
852 pPath
->newStroke
= TRUE
;
853 lastmove
.x
= pts
[i
].x
;
854 lastmove
.y
= pts
[i
].y
;
856 else if ((types
[i
] & ~PT_CLOSEFIGURE
) == PT_LINETO
)
858 PATH_LineTo(dc
, pts
[i
].x
, pts
[i
].y
);
860 else if (types
[i
] == PT_BEZIERTO
)
862 if (!((i
+ 2 < cbPoints
) && (types
[i
+ 1] == PT_BEZIERTO
)
863 && ((types
[i
+ 2] & ~PT_CLOSEFIGURE
) == PT_BEZIERTO
)))
865 PATH_PolyBezierTo(dc
, &(pts
[i
]), 3);
871 pdcattr
->ptlCurrent
.x
= pts
[i
].x
;
872 pdcattr
->ptlCurrent
.y
= pts
[i
].y
;
875 if (types
[i
] & PT_CLOSEFIGURE
)
877 pPath
->pFlags
[pPath
->numEntriesUsed
- 1] |= PT_CLOSEFIGURE
;
878 pPath
->newStroke
= TRUE
;
879 pdcattr
->ptlCurrent
.x
= lastmove
.x
;
880 pdcattr
->ptlCurrent
.y
= lastmove
.y
;
888 if ((pdcattr
->ptlCurrent
.x
!= orig_pos
.x
) || (pdcattr
->ptlCurrent
.y
!= orig_pos
.y
))
890 pPath
->newStroke
= TRUE
;
891 pdcattr
->ptlCurrent
.x
= orig_pos
.x
;
892 pdcattr
->ptlCurrent
.y
= orig_pos
.y
;
896 if (State
) // State change?
898 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
899 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
900 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
| DIRTY_PTFXCURRENT
| DIRTY_STYLESTATE
);
902 PATH_UnlockPath(pPath
);
921 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
922 if (!pPath
) return FALSE
;
924 /* Check that path is open */
925 if (pPath
->state
!= PATH_Open
)
927 PATH_UnlockPath(pPath
);
930 for (i
= 0; i
< cbPoints
; i
++)
933 CoordLPtoDP(dc
, &pt
);
934 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_LINETO
);
936 PATH_UnlockPath(pPath
);
955 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
956 if (!pPath
) return FALSE
;
958 /* Check that path is open */
959 if (pPath
->state
!= PATH_Open
)
961 PATH_UnlockPath(pPath
);
965 /* Add a PT_MOVETO if necessary */
966 if (pPath
->newStroke
)
968 pPath
->newStroke
= FALSE
;
969 IntGetCurrentPositionEx(dc
, &pt
);
970 CoordLPtoDP(dc
, &pt
);
971 if (!PATH_AddEntry(pPath
, &pt
, PT_MOVETO
))
973 PATH_UnlockPath(pPath
);
978 for (i
= 0; i
< cbPoints
; i
++)
981 CoordLPtoDP(dc
, &pt
);
982 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
984 PATH_UnlockPath(pPath
);
1003 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
1004 if (!pPath
) return FALSE
;
1006 /* Check that path is open */
1007 if (pPath
->state
!= PATH_Open
)
1009 PATH_UnlockPath(pPath
);
1013 for (i
= 0; i
< cbPoints
; i
++)
1016 CoordLPtoDP(dc
, &pt
);
1017 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
:
1018 ((i
== cbPoints
- 1) ? PT_LINETO
| PT_CLOSEFIGURE
:
1022 PATH_UnlockPath(pPath
);
1035 ULONG poly
, point
, i
;
1043 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
1044 if (!pPath
) return FALSE
;
1046 /* Check that path is open */
1047 if (pPath
->state
!= PATH_Open
)
1049 PATH_UnlockPath(pPath
);
1053 for (i
= 0, poly
= 0; poly
< polygons
; poly
++)
1055 for (point
= 0; point
< (ULONG
) counts
[poly
]; point
++, i
++)
1058 CoordLPtoDP(dc
, &pt
);
1059 if (point
== 0) startpt
= pt
;
1060 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1063 /* Win98 adds an extra line to close the figure for some reason */
1064 PATH_AddEntry(pPath
, &startpt
, PT_LINETO
| PT_CLOSEFIGURE
);
1067 PATH_UnlockPath(pPath
);
1076 const DWORD
* counts
,
1080 ULONG poly
, point
, i
;
1088 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
1089 if (!pPath
) return FALSE
;
1091 /* Check that path is open */
1092 if (pPath
->state
!= PATH_Open
)
1094 PATH_UnlockPath(pPath
);
1098 for (i
= 0, poly
= 0; poly
< polylines
; poly
++)
1100 for (point
= 0; point
< counts
[poly
]; point
++, i
++)
1103 CoordLPtoDP(dc
, &pt
);
1104 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1108 PATH_UnlockPath(pPath
);
1113 /* PATH_CheckCorners
1115 * Helper function for PATH_RoundRect() and PATH_Rectangle()
1127 PDC_ATTR pdcattr
= dc
->pdcattr
;
1129 /* Convert points to device coordinates */
1134 CoordLPtoDP(dc
, &corners
[0]);
1135 CoordLPtoDP(dc
, &corners
[1]);
1137 /* Make sure first corner is top left and second corner is bottom right */
1138 if (corners
[0].x
> corners
[1].x
)
1140 temp
= corners
[0].x
;
1141 corners
[0].x
= corners
[1].x
;
1142 corners
[1].x
= temp
;
1145 if (corners
[0].y
> corners
[1].y
)
1147 temp
= corners
[0].y
;
1148 corners
[0].y
= corners
[1].y
;
1149 corners
[1].y
= temp
;
1152 /* In GM_COMPATIBLE, don't include bottom and right edges */
1153 if (pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
1163 /* PATH_AddFlatBezier
1176 pts
= GDI_Bezier(pt
, 4, &no
);
1177 if (!pts
) return FALSE
;
1179 for (i
= 1; i
< no
; i
++)
1180 PATH_AddEntry(pPath
, &pts
[i
], (i
== no
- 1 && closed
) ? PT_LINETO
| PT_CLOSEFIGURE
: PT_LINETO
);
1182 ExFreePoolWithTag(pts
, TAG_BEZIER
);
1188 * Replaces Beziers with line segments
1193 PATH_FlattenPath(PPATH pPath
)
1198 RtlZeroMemory(&newPath
, sizeof(newPath
));
1199 newPath
.state
= PATH_Open
;
1200 for (srcpt
= 0; srcpt
< pPath
->numEntriesUsed
; srcpt
++)
1202 switch(pPath
->pFlags
[srcpt
] & ~PT_CLOSEFIGURE
)
1206 PATH_AddEntry(&newPath
, &pPath
->pPoints
[srcpt
], pPath
->pFlags
[srcpt
]);
1209 PATH_AddFlatBezier(&newPath
, &pPath
->pPoints
[srcpt
- 1], pPath
->pFlags
[srcpt
+ 2] & PT_CLOSEFIGURE
);
1215 newPath
.state
= PATH_Closed
;
1216 PATH_AssignGdiPath(pPath
, &newPath
);
1217 PATH_EmptyPath(&newPath
);
1222 /* PATH_PathToRegion
1224 * Creates a region from the specified path using the specified polygon
1225 * filling mode. The path is left unchanged. A handle to the region that
1226 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1227 * error occurs, SetLastError is called with the appropriate value and
1228 * FALSE is returned.
1237 int numStrokes
, iStroke
, i
;
1238 PULONG pNumPointsInStroke
;
1241 ASSERT(pPath
!= NULL
);
1242 ASSERT(Rgn
!= NULL
);
1244 PATH_FlattenPath(pPath
);
1246 /* First pass: Find out how many strokes there are in the path */
1247 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1249 for (i
= 0; i
< pPath
->numEntriesUsed
; i
++)
1250 if ((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1253 if (numStrokes
== 0)
1255 DPRINT1("numStrokes is 0\n");
1259 /* Allocate memory for number-of-points-in-stroke array */
1260 pNumPointsInStroke
= ExAllocatePoolWithTag(PagedPool
, sizeof(ULONG
) * numStrokes
, TAG_PATH
);
1261 if (!pNumPointsInStroke
)
1263 DPRINT1("Failed to allocate %lu strokes\n", numStrokes
);
1264 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1268 /* Second pass: remember number of points in each polygon */
1269 iStroke
= -1; /* Will get incremented to 0 at beginning of first stroke */
1270 for (i
= 0; i
< pPath
->numEntriesUsed
; i
++)
1272 /* Is this the beginning of a new stroke? */
1273 if ((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1276 _PRAGMA_WARNING_SUPPRESS(__WARNING_WRITE_OVERRUN
)
1277 pNumPointsInStroke
[iStroke
] = 0;
1280 _PRAGMA_WARNING_SUPPRESS(__WARNING_READ_OVERRUN
)
1281 pNumPointsInStroke
[iStroke
]++;
1284 /* Fill the region with the strokes */
1285 Ret
= REGION_SetPolyPolygonRgn(Rgn
,
1292 DPRINT1("REGION_SetPolyPolygonRgn failed\n");
1295 /* Free memory for number-of-points-in-stroke array */
1296 ExFreePoolWithTag(pNumPointsInStroke
, TAG_PATH
);
1304 * Removes all entries from the path and sets the path state to PATH_Null.
1308 PATH_EmptyPath(PPATH pPath
)
1310 ASSERT(pPath
!= NULL
);
1312 pPath
->state
= PATH_Null
;
1313 pPath
->numEntriesUsed
= 0;
1318 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1319 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1320 * successful, FALSE otherwise (e.g. if not enough memory was available).
1326 const POINT
*pPoint
,
1329 ASSERT(pPath
!= NULL
);
1331 /* FIXME: If newStroke is true, perhaps we want to check that we're
1332 * getting a PT_MOVETO
1335 /* Check that path is open */
1336 if (pPath
->state
!= PATH_Open
)
1339 /* Reserve enough memory for an extra path entry */
1340 if (!PATH_ReserveEntries(pPath
, pPath
->numEntriesUsed
+ 1))
1343 /* Store information in path entry */
1344 pPath
->pPoints
[pPath
->numEntriesUsed
] = *pPoint
;
1345 pPath
->pFlags
[pPath
->numEntriesUsed
] = flags
;
1347 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1348 if ((flags
& PT_CLOSEFIGURE
) == PT_CLOSEFIGURE
)
1349 pPath
->newStroke
= TRUE
;
1351 /* Increment entry count */
1352 pPath
->numEntriesUsed
++;
1357 /* PATH_ReserveEntries
1359 * Ensures that at least "numEntries" entries (for points and flags) have
1360 * been allocated; allocates larger arrays and copies the existing entries
1361 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1365 PATH_ReserveEntries(
1369 INT numEntriesToAllocate
;
1373 ASSERT(pPath
!= NULL
);
1374 ASSERT(numEntries
>= 0);
1376 /* Do we have to allocate more memory? */
1377 if (numEntries
> pPath
->numEntriesAllocated
)
1379 /* Find number of entries to allocate. We let the size of the array
1380 * grow exponentially, since that will guarantee linear time
1382 if (pPath
->numEntriesAllocated
)
1384 numEntriesToAllocate
= pPath
->numEntriesAllocated
;
1385 while (numEntriesToAllocate
< numEntries
)
1386 numEntriesToAllocate
= numEntriesToAllocate
* GROW_FACTOR_NUMER
/ GROW_FACTOR_DENOM
;
1389 numEntriesToAllocate
= numEntries
;
1391 /* Allocate new arrays */
1392 pPointsNew
= (POINT
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(POINT
), TAG_PATH
);
1396 pFlagsNew
= (BYTE
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(BYTE
), TAG_PATH
);
1399 ExFreePoolWithTag(pPointsNew
, TAG_PATH
);
1403 /* Copy old arrays to new arrays and discard old arrays */
1406 ASSERT(pPath
->pFlags
);
1408 memcpy(pPointsNew
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
1409 memcpy(pFlagsNew
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
1411 ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
1412 ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
1415 pPath
->pPoints
= pPointsNew
;
1416 pPath
->pFlags
= pFlagsNew
;
1417 pPath
->numEntriesAllocated
= numEntriesToAllocate
;
1425 * Creates a Bezier spline that corresponds to part of an arc and appends the
1426 * corresponding points to the path. The start and end angles are passed in
1427 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1428 * at most. If "startEntryType" is non-zero, an entry of that type for the first
1429 * control point is added to the path; otherwise, it is assumed that the current
1430 * position is equal to the first control point.
1436 FLOAT_POINT corners
[],
1439 BYTE startEntryType
)
1441 double halfAngle
, a
;
1442 double xNorm
[4], yNorm
[4];
1446 ASSERT(fabs(angleEnd
- angleStart
) <= M_PI_2
);
1448 /* FIXME: Is there an easier way of computing this? */
1450 /* Compute control points */
1451 halfAngle
= (angleEnd
- angleStart
) / 2.0;
1452 if (fabs(halfAngle
) > 1e-8)
1454 a
= 4.0 / 3.0 * (1 - cos(halfAngle
)) / sin(halfAngle
);
1455 xNorm
[0] = cos(angleStart
);
1456 yNorm
[0] = sin(angleStart
);
1457 xNorm
[1] = xNorm
[0] - a
* yNorm
[0];
1458 yNorm
[1] = yNorm
[0] + a
* xNorm
[0];
1459 xNorm
[3] = cos(angleEnd
);
1460 yNorm
[3] = sin(angleEnd
);
1461 xNorm
[2] = xNorm
[3] + a
* yNorm
[3];
1462 yNorm
[2] = yNorm
[3] - a
* xNorm
[3];
1465 for (i
= 0; i
< 4; i
++)
1467 xNorm
[i
] = cos(angleStart
);
1468 yNorm
[i
] = sin(angleStart
);
1471 /* Add starting point to path if desired */
1474 PATH_ScaleNormalizedPoint(corners
, xNorm
[0], yNorm
[0], &point
);
1475 if (!PATH_AddEntry(pPath
, &point
, startEntryType
))
1479 /* Add remaining control points */
1480 for (i
= 1; i
< 4; i
++)
1482 PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &point
);
1483 if (!PATH_AddEntry(pPath
, &point
, PT_BEZIERTO
))
1490 /* PATH_ScaleNormalizedPoint
1492 * Scales a normalized point (x, y) with respect to the box whose corners are
1493 * passed in "corners". The point is stored in "*pPoint". The normalized
1494 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1495 * (1.0, 1.0) correspond to corners[1].
1499 PATH_ScaleNormalizedPoint(
1500 FLOAT_POINT corners
[],
1508 pPoint
->x
= GDI_ROUND((double)corners
[0].x
+ (double)(corners
[1].x
- corners
[0].x
) * 0.5 * (x
+ 1.0));
1509 pPoint
->y
= GDI_ROUND((double)corners
[0].y
+ (double)(corners
[1].y
- corners
[0].y
) * 0.5 * (y
+ 1.0));
1512 /* PATH_NormalizePoint
1514 * Normalizes a point with respect to the box whose corners are passed in
1515 * corners. The normalized coordinates are stored in *pX and *pY.
1519 PATH_NormalizePoint(
1520 FLOAT_POINT corners
[],
1521 const FLOAT_POINT
*pPoint
,
1530 *pX
= (double)(pPoint
->x
- corners
[0].x
) / (double)(corners
[1].x
- corners
[0].x
) * 2.0 - 1.0;
1531 *pY
= (double)(pPoint
->y
- corners
[0].y
) / (double)(corners
[1].y
- corners
[0].y
) * 2.0 - 1.0;
1543 INT nLinePts
, nAlloc
;
1544 POINT
*pLinePts
= NULL
;
1545 POINT ptViewportOrg
, ptWindowOrg
;
1546 SIZE szViewportExt
, szWindowExt
;
1547 DWORD mapMode
, graphicsMode
;
1549 PDC_ATTR pdcattr
= dc
->pdcattr
;
1551 DPRINT("Enter %s\n", __FUNCTION__
);
1553 if (pPath
->state
!= PATH_Closed
)
1556 /* Save the mapping mode info */
1557 mapMode
= pdcattr
->iMapMode
;
1559 szViewportExt
= *DC_pszlViewportExt(dc
);
1560 ptViewportOrg
= dc
->pdcattr
->ptlViewportOrg
;
1561 szWindowExt
= dc
->pdcattr
->szlWindowExt
;
1562 ptWindowOrg
= dc
->pdcattr
->ptlWindowOrg
;
1564 MatrixS2XForm(&xform
, &dc
->pdcattr
->mxWorldToPage
);
1567 pdcattr
->iMapMode
= MM_TEXT
;
1568 pdcattr
->ptlViewportOrg
.x
= 0;
1569 pdcattr
->ptlViewportOrg
.y
= 0;
1570 pdcattr
->ptlWindowOrg
.x
= 0;
1571 pdcattr
->ptlWindowOrg
.y
= 0;
1572 graphicsMode
= pdcattr
->iGraphicsMode
;
1573 pdcattr
->iGraphicsMode
= GM_ADVANCED
;
1574 GreModifyWorldTransform(dc
, (XFORML
*)&xform
, MWT_IDENTITY
);
1575 pdcattr
->iGraphicsMode
= graphicsMode
;
1577 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1578 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1579 * space in case we get one to keep the number of reallocations small. */
1580 nAlloc
= pPath
->numEntriesUsed
+ 1 + 300;
1581 pLinePts
= ExAllocatePoolWithTag(PagedPool
, nAlloc
* sizeof(POINT
), TAG_PATH
);
1584 DPRINT1("Can't allocate pool!\n");
1585 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1590 for (i
= 0; i
< pPath
->numEntriesUsed
; i
++)
1592 if ((i
== 0 || (pPath
->pFlags
[i
- 1] & PT_CLOSEFIGURE
))
1593 && (pPath
->pFlags
[i
] != PT_MOVETO
))
1595 DPRINT1("Expected PT_MOVETO %s, got path flag %d\n",
1596 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1597 (INT
)pPath
->pFlags
[i
]);
1601 switch(pPath
->pFlags
[i
])
1604 DPRINT("Got PT_MOVETO (%ld, %ld)\n",
1605 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1606 if (nLinePts
>= 2) IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1608 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1611 case (PT_LINETO
| PT_CLOSEFIGURE
):
1612 DPRINT("Got PT_LINETO (%ld, %ld)\n",
1613 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1614 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1617 DPRINT("Got PT_BEZIERTO\n");
1618 if (pPath
->pFlags
[i
+ 1] != PT_BEZIERTO
||
1619 (pPath
->pFlags
[i
+ 2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
)
1621 DPRINT1("Path didn't contain 3 successive PT_BEZIERTOs\n");
1627 INT nBzrPts
, nMinAlloc
;
1628 POINT
*pBzrPts
= GDI_Bezier(&pPath
->pPoints
[i
- 1], 4, &nBzrPts
);
1629 /* Make sure we have allocated enough memory for the lines of
1630 * this bezier and the rest of the path, assuming we won't get
1631 * another one (since we won't reallocate again then). */
1632 nMinAlloc
= nLinePts
+ (pPath
->numEntriesUsed
- i
) + nBzrPts
;
1633 if (nAlloc
< nMinAlloc
)
1635 // Reallocate memory
1637 POINT
*Realloc
= NULL
;
1638 nAlloc
= nMinAlloc
* 2;
1640 Realloc
= ExAllocatePoolWithTag(PagedPool
,
1641 nAlloc
* sizeof(POINT
),
1646 DPRINT1("Can't allocate pool!\n");
1647 ExFreePoolWithTag(pBzrPts
, TAG_BEZIER
);
1651 memcpy(Realloc
, pLinePts
, nLinePts
* sizeof(POINT
));
1652 ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1655 memcpy(&pLinePts
[nLinePts
], &pBzrPts
[1], (nBzrPts
- 1) * sizeof(POINT
));
1656 nLinePts
+= nBzrPts
- 1;
1657 ExFreePoolWithTag(pBzrPts
, TAG_BEZIER
);
1662 DPRINT1("Got path flag %d (not supported)\n", (INT
)pPath
->pFlags
[i
]);
1666 if (pPath
->pFlags
[i
] & PT_CLOSEFIGURE
)
1668 pLinePts
[nLinePts
++] = pLinePts
[0];
1672 IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1677 if (pLinePts
) ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1679 /* Restore the old mapping mode */
1680 pdcattr
->iMapMode
= mapMode
;
1681 pdcattr
->szlWindowExt
.cx
= szWindowExt
.cx
;
1682 pdcattr
->szlWindowExt
.cy
= szWindowExt
.cy
;
1683 pdcattr
->ptlWindowOrg
.x
= ptWindowOrg
.x
;
1684 pdcattr
->ptlWindowOrg
.y
= ptWindowOrg
.y
;
1686 pdcattr
->szlViewportExt
.cx
= szViewportExt
.cx
;
1687 pdcattr
->szlViewportExt
.cy
= szViewportExt
.cy
;
1688 pdcattr
->ptlViewportOrg
.x
= ptViewportOrg
.x
;
1689 pdcattr
->ptlViewportOrg
.y
= ptViewportOrg
.y
;
1691 /* Restore the world transform */
1692 XForm2MatrixS(&dc
->pdcattr
->mxWorldToPage
, &xform
);
1694 /* If we've moved the current point then get its new position
1695 which will be in device (MM_TEXT) co-ords, convert it to
1696 logical co-ords and re-set it. This basically updates
1697 dc->CurPosX|Y so that their values are in the correct mapping
1703 IntGetCurrentPositionEx(dc
, &pt
);
1704 IntDPtoLP(dc
, &pt
, 1);
1705 IntGdiMoveToEx(dc
, pt
.x
, pt
.y
, NULL
, FALSE
);
1707 DPRINT("Leave %s, ret=%d\n", __FUNCTION__
, ret
);
1711 #define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1716 PATH_WidenPath(DC
*dc
)
1718 INT i
, j
, numStrokes
, numOldStrokes
, penWidth
, penWidthIn
, penWidthOut
, size
, penStyle
;
1720 PPATH pPath
, pNewPath
, *pStrokes
= NULL
, *pOldStrokes
, pUpPath
, pDownPath
;
1722 DWORD obj_type
, joint
, endcap
, penType
;
1723 PDC_ATTR pdcattr
= dc
->pdcattr
;
1725 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
1726 if (!pPath
) return FALSE
;
1728 if (pPath
->state
== PATH_Open
)
1730 PATH_UnlockPath(pPath
);
1731 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1735 PATH_FlattenPath(pPath
);
1737 size
= GreGetObject(pdcattr
->hpen
, 0, NULL
);
1740 PATH_UnlockPath(pPath
);
1741 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1745 elp
= ExAllocatePoolWithTag(PagedPool
, size
, TAG_PATH
);
1748 PATH_UnlockPath(pPath
);
1749 EngSetLastError(ERROR_OUTOFMEMORY
);
1753 GreGetObject(pdcattr
->hpen
, size
, elp
);
1755 obj_type
= GDI_HANDLE_GET_TYPE(pdcattr
->hpen
);
1756 if (obj_type
== GDI_OBJECT_TYPE_PEN
)
1758 penStyle
= ((LOGPEN
*)elp
)->lopnStyle
;
1760 else if (obj_type
== GDI_OBJECT_TYPE_EXTPEN
)
1762 penStyle
= elp
->elpPenStyle
;
1766 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1767 ExFreePoolWithTag(elp
, TAG_PATH
);
1768 PATH_UnlockPath(pPath
);
1772 penWidth
= elp
->elpWidth
;
1773 ExFreePoolWithTag(elp
, TAG_PATH
);
1775 endcap
= (PS_ENDCAP_MASK
& penStyle
);
1776 joint
= (PS_JOIN_MASK
& penStyle
);
1777 penType
= (PS_TYPE_MASK
& penStyle
);
1779 /* The function cannot apply to cosmetic pens */
1780 if (obj_type
== GDI_OBJECT_TYPE_EXTPEN
&& penType
== PS_COSMETIC
)
1782 PATH_UnlockPath(pPath
);
1783 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1787 penWidthIn
= penWidth
/ 2;
1788 penWidthOut
= penWidth
/ 2;
1789 if (penWidthIn
+ penWidthOut
< penWidth
)
1794 for (i
= 0, j
= 0; i
< pPath
->numEntriesUsed
; i
++, j
++)
1797 if ((i
== 0 || (pPath
->pFlags
[i
- 1] & PT_CLOSEFIGURE
)) &&
1798 (pPath
->pFlags
[i
] != PT_MOVETO
))
1800 DPRINT1("Expected PT_MOVETO %s, got path flag %c\n",
1801 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1805 switch(pPath
->pFlags
[i
])
1810 pStrokes
[numStrokes
- 1]->state
= PATH_Closed
;
1812 numOldStrokes
= numStrokes
;
1815 if (numStrokes
== 1)
1816 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1819 pOldStrokes
= pStrokes
; // Save old pointer.
1820 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1821 if (!pStrokes
) return FALSE
;
1822 RtlCopyMemory(pStrokes
, pOldStrokes
, numOldStrokes
* sizeof(PPATH
));
1823 ExFreePoolWithTag(pOldStrokes
, TAG_PATH
); // Free old pointer.
1825 if (!pStrokes
) return FALSE
;
1826 pStrokes
[numStrokes
- 1] = ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1827 if (!pStrokes
[numStrokes
- 1])
1829 ASSERT(FALSE
); // FIXME
1832 PATH_InitGdiPath(pStrokes
[numStrokes
- 1]);
1833 pStrokes
[numStrokes
- 1]->state
= PATH_Open
;
1835 case (PT_LINETO
| PT_CLOSEFIGURE
):
1836 point
.x
= pPath
->pPoints
[i
].x
;
1837 point
.y
= pPath
->pPoints
[i
].y
;
1838 PATH_AddEntry(pStrokes
[numStrokes
- 1], &point
, pPath
->pFlags
[i
]);
1841 /* Should never happen because of the FlattenPath call */
1842 DPRINT1("Should never happen\n");
1845 DPRINT1("Got path flag %c\n", pPath
->pFlags
[i
]);
1850 pNewPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1853 ASSERT(FALSE
); // FIXME
1855 PATH_InitGdiPath(pNewPath
);
1856 pNewPath
->state
= PATH_Open
;
1858 for (i
= 0; i
< numStrokes
; i
++)
1860 pUpPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1861 PATH_InitGdiPath(pUpPath
);
1862 pUpPath
->state
= PATH_Open
;
1863 pDownPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1864 PATH_InitGdiPath(pDownPath
);
1865 pDownPath
->state
= PATH_Open
;
1867 for (j
= 0; j
< pStrokes
[i
]->numEntriesUsed
; j
++)
1869 /* Beginning or end of the path if not closed */
1870 if ((!(pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) && (j
== 0 || j
== pStrokes
[i
]->numEntriesUsed
- 1))
1872 /* Compute segment angle */
1873 double xo
, yo
, xa
, ya
, theta
;
1875 FLOAT_POINT corners
[2];
1878 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1879 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1880 xa
= pStrokes
[i
]->pPoints
[1].x
;
1881 ya
= pStrokes
[i
]->pPoints
[1].y
;
1885 xa
= pStrokes
[i
]->pPoints
[j
- 1].x
;
1886 ya
= pStrokes
[i
]->pPoints
[j
- 1].y
;
1887 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1888 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1890 theta
= atan2(ya
- yo
, xa
- xo
);
1893 case PS_ENDCAP_SQUARE
:
1894 pt
.x
= xo
+ round(sqrt(2) * penWidthOut
* cos(M_PI_4
+ theta
));
1895 pt
.y
= yo
+ round(sqrt(2) * penWidthOut
* sin(M_PI_4
+ theta
));
1896 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1897 pt
.x
= xo
+ round(sqrt(2) * penWidthIn
* cos(- M_PI_4
+ theta
));
1898 pt
.y
= yo
+ round(sqrt(2) * penWidthIn
* sin(- M_PI_4
+ theta
));
1899 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1901 case PS_ENDCAP_FLAT
:
1902 pt
.x
= xo
+ round(penWidthOut
* cos(theta
+ M_PI_2
));
1903 pt
.y
= yo
+ round(penWidthOut
* sin(theta
+ M_PI_2
));
1904 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1905 pt
.x
= xo
- round(penWidthIn
* cos(theta
+ M_PI_2
));
1906 pt
.y
= yo
- round(penWidthIn
* sin(theta
+ M_PI_2
));
1907 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1909 case PS_ENDCAP_ROUND
:
1911 corners
[0].x
= xo
- penWidthIn
;
1912 corners
[0].y
= yo
- penWidthIn
;
1913 corners
[1].x
= xo
+ penWidthOut
;
1914 corners
[1].y
= yo
+ penWidthOut
;
1915 PATH_DoArcPart(pUpPath
, corners
, theta
+ M_PI_2
, theta
+ 3 * M_PI_4
, (j
== 0 ? PT_MOVETO
: FALSE
));
1916 PATH_DoArcPart(pUpPath
, corners
, theta
+ 3 * M_PI_4
, theta
+ M_PI
, FALSE
);
1917 PATH_DoArcPart(pUpPath
, corners
, theta
+ M_PI
, theta
+ 5 * M_PI_4
, FALSE
);
1918 PATH_DoArcPart(pUpPath
, corners
, theta
+ 5 * M_PI_4
, theta
+ 3 * M_PI_2
, FALSE
);
1922 /* Corpse of the path */
1927 double xa
, ya
, xb
, yb
, xo
, yo
;
1928 double alpha
, theta
, miterWidth
;
1929 DWORD _joint
= joint
;
1931 PPATH pInsidePath
, pOutsidePath
;
1932 if (j
> 0 && j
< pStrokes
[i
]->numEntriesUsed
- 1)
1939 previous
= pStrokes
[i
]->numEntriesUsed
- 1;
1947 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1948 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1949 xa
= pStrokes
[i
]->pPoints
[previous
].x
;
1950 ya
= pStrokes
[i
]->pPoints
[previous
].y
;
1951 xb
= pStrokes
[i
]->pPoints
[next
].x
;
1952 yb
= pStrokes
[i
]->pPoints
[next
].y
;
1953 theta
= atan2(yo
- ya
, xo
- xa
);
1954 alpha
= atan2(yb
- yo
, xb
- xo
) - theta
;
1955 if (alpha
> 0) alpha
-= M_PI
;
1957 if (_joint
== PS_JOIN_MITER
&& dc
->dclevel
.laPath
.eMiterLimit
< fabs(1 / sin(alpha
/ 2)))
1959 _joint
= PS_JOIN_BEVEL
;
1963 pInsidePath
= pUpPath
;
1964 pOutsidePath
= pDownPath
;
1968 pInsidePath
= pDownPath
;
1969 pOutsidePath
= pUpPath
;
1975 /* Inside angle points */
1978 pt
.x
= xo
- round(penWidthIn
* cos(theta
+ M_PI_2
));
1979 pt
.y
= yo
- round(penWidthIn
* sin(theta
+ M_PI_2
));
1983 pt
.x
= xo
+ round(penWidthIn
* cos(theta
+ M_PI_2
));
1984 pt
.y
= yo
+ round(penWidthIn
* sin(theta
+ M_PI_2
));
1986 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1989 pt
.x
= xo
+ round(penWidthIn
* cos(M_PI_2
+ alpha
+ theta
));
1990 pt
.y
= yo
+ round(penWidthIn
* sin(M_PI_2
+ alpha
+ theta
));
1994 pt
.x
= xo
- round(penWidthIn
* cos(M_PI_2
+ alpha
+ theta
));
1995 pt
.y
= yo
- round(penWidthIn
* sin(M_PI_2
+ alpha
+ theta
));
1997 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1998 /* Outside angle point */
2001 case PS_JOIN_MITER
:
2002 miterWidth
= fabs(penWidthOut
/ cos(M_PI_2
- fabs(alpha
) / 2));
2003 pt
.x
= xo
+ round(miterWidth
* cos(theta
+ alpha
/ 2));
2004 pt
.y
= yo
+ round(miterWidth
* sin(theta
+ alpha
/ 2));
2005 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
2007 case PS_JOIN_BEVEL
:
2010 pt
.x
= xo
+ round(penWidthOut
* cos(theta
+ M_PI_2
));
2011 pt
.y
= yo
+ round(penWidthOut
* sin(theta
+ M_PI_2
));
2015 pt
.x
= xo
- round(penWidthOut
* cos(theta
+ M_PI_2
));
2016 pt
.y
= yo
- round(penWidthOut
* sin(theta
+ M_PI_2
));
2018 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
2021 pt
.x
= xo
- round(penWidthOut
* cos(M_PI_2
+ alpha
+ theta
));
2022 pt
.y
= yo
- round(penWidthOut
* sin(M_PI_2
+ alpha
+ theta
));
2026 pt
.x
= xo
+ round(penWidthOut
* cos(M_PI_2
+ alpha
+ theta
));
2027 pt
.y
= yo
+ round(penWidthOut
* sin(M_PI_2
+ alpha
+ theta
));
2029 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
2031 case PS_JOIN_ROUND
:
2035 pt
.x
= xo
+ round(penWidthOut
* cos(theta
+ M_PI_2
));
2036 pt
.y
= yo
+ round(penWidthOut
* sin(theta
+ M_PI_2
));
2040 pt
.x
= xo
- round(penWidthOut
* cos(theta
+ M_PI_2
));
2041 pt
.y
= yo
- round(penWidthOut
* sin(theta
+ M_PI_2
));
2043 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
2044 pt
.x
= xo
+ round(penWidthOut
* cos(theta
+ alpha
/ 2));
2045 pt
.y
= yo
+ round(penWidthOut
* sin(theta
+ alpha
/ 2));
2046 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
2049 pt
.x
= xo
- round(penWidthOut
* cos(M_PI_2
+ alpha
+ theta
));
2050 pt
.y
= yo
- round(penWidthOut
* sin(M_PI_2
+ alpha
+ theta
));
2054 pt
.x
= xo
+ round(penWidthOut
* cos(M_PI_2
+ alpha
+ theta
));
2055 pt
.y
= yo
+ round(penWidthOut
* sin(M_PI_2
+ alpha
+ theta
));
2057 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
2062 for (j
= 0; j
< pUpPath
->numEntriesUsed
; j
++)
2065 pt
.x
= pUpPath
->pPoints
[j
].x
;
2066 pt
.y
= pUpPath
->pPoints
[j
].y
;
2067 PATH_AddEntry(pNewPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
2069 for (j
= 0; j
< pDownPath
->numEntriesUsed
; j
++)
2072 pt
.x
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].x
;
2073 pt
.y
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].y
;
2074 PATH_AddEntry(pNewPath
, &pt
, ((j
== 0 && (pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) ? PT_MOVETO
: PT_LINETO
));
2077 PATH_DestroyGdiPath(pStrokes
[i
]);
2078 ExFreePoolWithTag(pStrokes
[i
], TAG_PATH
);
2079 PATH_DestroyGdiPath(pUpPath
);
2080 ExFreePoolWithTag(pUpPath
, TAG_PATH
);
2081 PATH_DestroyGdiPath(pDownPath
);
2082 ExFreePoolWithTag(pDownPath
, TAG_PATH
);
2084 if (pStrokes
) ExFreePoolWithTag(pStrokes
, TAG_PATH
);
2086 pNewPath
->state
= PATH_Closed
;
2087 if (!(ret
= PATH_AssignGdiPath(pPath
, pNewPath
)))
2088 DPRINT1("Assign path failed\n");
2089 PATH_DestroyGdiPath(pNewPath
);
2090 ExFreePoolWithTag(pNewPath
, TAG_PATH
);
2091 PATH_UnlockPath(pPath
);
2095 static inline INT
int_from_fixed(FIXED f
)
2097 return (f
.fract
>= 0x8000) ? (f
.value
+ 1) : f
.value
;
2100 /**********************************************************************
2103 * Internally used by PATH_add_outline
2117 PATH_AddEntry(pPath
, &lppt
[1], PT_LINETO
);
2121 PATH_AddEntry(pPath
, &lppt
[0], PT_BEZIERTO
);
2122 PATH_AddEntry(pPath
, &lppt
[1], PT_BEZIERTO
);
2123 PATH_AddEntry(pPath
, &lppt
[2], PT_BEZIERTO
);
2136 pt
[1] = lppt
[i
+ 1];
2137 pt
[2].x
= (lppt
[i
+ 2].x
+ lppt
[i
+ 1].x
) / 2;
2138 pt
[2].y
= (lppt
[i
+ 2].y
+ lppt
[i
+ 1].y
) / 2;
2139 PATH_BezierTo(pPath
, pt
, 3);
2145 pt
[1] = lppt
[i
+ 1];
2146 pt
[2] = lppt
[i
+ 2];
2147 PATH_BezierTo(pPath
, pt
, 3);
2158 TTPOLYGONHEADER
*header
,
2162 TTPOLYGONHEADER
*start
;
2164 BOOL bResult
= FALSE
;
2168 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2174 while ((char *)header
< (char *)start
+ size
)
2178 if (header
->dwType
!= TT_POLYGON_TYPE
)
2180 DPRINT1("Unknown header type %lu\n", header
->dwType
);
2184 pt
.x
= x
+ int_from_fixed(header
->pfxStart
.x
);
2185 pt
.y
= y
- int_from_fixed(header
->pfxStart
.y
);
2186 PATH_AddEntry(pPath
, &pt
, PT_MOVETO
);
2188 curve
= (TTPOLYCURVE
*)(header
+ 1);
2190 while ((char *)curve
< (char *)header
+ header
->cb
)
2192 /*DPRINT1("curve->wType %d\n", curve->wType);*/
2194 switch(curve
->wType
)
2200 for (i
= 0; i
< curve
->cpfx
; i
++)
2202 pt
.x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
2203 pt
.y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
2204 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
2209 case TT_PRIM_QSPLINE
:
2210 case TT_PRIM_CSPLINE
:
2214 POINT
*pts
= ExAllocatePoolWithTag(PagedPool
, (curve
->cpfx
+ 1) * sizeof(POINT
), TAG_PATH
);
2216 if (!pts
) goto cleanup
;
2218 ptfx
= *(POINTFX
*)((char *)curve
- sizeof(POINTFX
));
2220 pts
[0].x
= x
+ int_from_fixed(ptfx
.x
);
2221 pts
[0].y
= y
- int_from_fixed(ptfx
.y
);
2223 for (i
= 0; i
< curve
->cpfx
; i
++)
2225 pts
[i
+ 1].x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
2226 pts
[i
+ 1].y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
2229 PATH_BezierTo(pPath
, pts
, curve
->cpfx
+ 1);
2231 ExFreePoolWithTag(pts
, TAG_PATH
);
2236 DPRINT1("Unknown curve type %04x\n", curve
->wType
);
2240 curve
= (TTPOLYCURVE
*)&curve
->apfx
[curve
->cpfx
];
2242 header
= (TTPOLYGONHEADER
*)((char *)header
+ header
->cb
);
2248 IntGdiCloseFigure(pPath
);
2249 PATH_UnlockPath(pPath
);
2253 /**********************************************************************
2269 POINT offset
= {0, 0};
2271 if (!count
) return TRUE
;
2273 for (idx
= 0; idx
< count
; idx
++)
2275 MAT2 identity
= { {0, 1}, {0, 0}, {0, 0}, {0, 1} };
2280 dwSize
= ftGdiGetGlyphOutline(dc
,
2282 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2288 if (dwSize
== GDI_ERROR
) return FALSE
;
2290 /* Add outline only if char is printable */
2293 outline
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_PATH
);
2294 if (!outline
) return FALSE
;
2296 ftGdiGetGlyphOutline(dc
,
2298 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2305 PATH_add_outline(dc
, x
+ offset
.x
, y
+ offset
.y
, outline
, dwSize
);
2307 ExFreePoolWithTag(outline
, TAG_PATH
);
2312 if (flags
& ETO_PDY
)
2314 offset
.x
+= dx
[idx
* 2];
2315 offset
.y
+= dx
[idx
* 2 + 1];
2318 offset
.x
+= dx
[idx
];
2322 offset
.x
+= gm
.gmCellIncX
;
2323 offset
.y
+= gm
.gmCellIncY
;
2330 /***********************************************************************
2331 * Exported functions
2336 NtGdiAbortPath(HDC hDC
)
2339 PDC dc
= DC_LockDc(hDC
);
2342 EngSetLastError(ERROR_INVALID_HANDLE
);
2346 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2353 PATH_EmptyPath(pPath
);
2355 PATH_UnlockPath(pPath
);
2356 dc
->dclevel
.flPath
&= ~DCPATH_ACTIVE
;
2364 NtGdiBeginPath(HDC hDC
)
2369 dc
= DC_LockDc(hDC
);
2372 EngSetLastError(ERROR_INVALID_HANDLE
);
2376 /* If path is already open, do nothing. Check if not Save DC state */
2377 if ((dc
->dclevel
.flPath
& DCPATH_ACTIVE
) && !(dc
->dclevel
.flPath
& DCPATH_SAVE
))
2383 if (dc
->dclevel
.hPath
)
2385 DPRINT("BeginPath 1 0x%p\n", dc
->dclevel
.hPath
);
2386 if (!(dc
->dclevel
.flPath
& DCPATH_SAVE
))
2388 // Remove previous handle.
2389 if (!PATH_Delete(dc
->dclevel
.hPath
))
2397 // Clear flags and Handle.
2398 dc
->dclevel
.flPath
&= ~(DCPATH_SAVE
| DCPATH_ACTIVE
);
2399 dc
->dclevel
.hPath
= NULL
;
2402 pPath
= PATH_AllocPathWithHandle();
2405 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2408 dc
->dclevel
.flPath
|= DCPATH_ACTIVE
; // Set active ASAP!
2410 dc
->dclevel
.hPath
= pPath
->BaseObject
.hHmgr
;
2412 DPRINT("BeginPath 2 h 0x%p p 0x%p\n", dc
->dclevel
.hPath
, pPath
);
2413 // Path handles are shared. Also due to recursion with in the same thread.
2414 GDIOBJ_vUnlockObject((POBJ
)pPath
); // Unlock
2415 pPath
= PATH_LockPath(dc
->dclevel
.hPath
); // Share Lock.
2417 /* Make sure that path is empty */
2418 PATH_EmptyPath(pPath
);
2420 pPath
->numEntriesAllocated
= NUM_ENTRIES_INITIAL
;
2422 pPath
->pPoints
= (POINT
*)ExAllocatePoolWithTag(PagedPool
, NUM_ENTRIES_INITIAL
* sizeof(POINT
), TAG_PATH
);
2423 pPath
->pFlags
= (BYTE
*)ExAllocatePoolWithTag(PagedPool
, NUM_ENTRIES_INITIAL
* sizeof(BYTE
), TAG_PATH
);
2425 /* Initialize variables for new path */
2426 pPath
->newStroke
= TRUE
;
2427 pPath
->state
= PATH_Open
;
2429 PATH_UnlockPath(pPath
);
2436 NtGdiCloseFigure(HDC hDC
)
2438 BOOL Ret
= FALSE
; // Default to failure
2442 DPRINT("Enter %s\n", __FUNCTION__
);
2444 pDc
= DC_LockDc(hDC
);
2447 EngSetLastError(ERROR_INVALID_PARAMETER
);
2451 pPath
= PATH_LockPath(pDc
->dclevel
.hPath
);
2458 if (pPath
->state
== PATH_Open
)
2460 IntGdiCloseFigure(pPath
);
2465 // FIXME: Check if lasterror is set correctly
2466 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2469 PATH_UnlockPath(pPath
);
2476 NtGdiEndPath(HDC hDC
)
2482 dc
= DC_LockDc(hDC
);
2485 EngSetLastError(ERROR_INVALID_HANDLE
);
2489 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2496 /* Check that path is currently being constructed */
2497 if ((pPath
->state
!= PATH_Open
) || !(dc
->dclevel
.flPath
& DCPATH_ACTIVE
))
2499 DPRINT1("EndPath ERROR! 0x%p\n", dc
->dclevel
.hPath
);
2500 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2503 /* Set flag to indicate that path is finished */
2506 DPRINT("EndPath 0x%p\n", dc
->dclevel
.hPath
);
2507 pPath
->state
= PATH_Closed
;
2508 dc
->dclevel
.flPath
&= ~DCPATH_ACTIVE
;
2511 PATH_UnlockPath(pPath
);
2518 NtGdiFillPath(HDC hDC
)
2525 dc
= DC_LockDc(hDC
);
2528 EngSetLastError(ERROR_INVALID_PARAMETER
);
2532 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2539 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
2541 pdcattr
= dc
->pdcattr
;
2543 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2544 DC_vUpdateLineBrush(dc
);
2546 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
2547 DC_vUpdateFillBrush(dc
);
2549 ret
= PATH_FillPath(dc
, pPath
);
2552 /* FIXME: Should the path be emptied even if conversion
2554 PATH_EmptyPath(pPath
);
2557 PATH_UnlockPath(pPath
);
2558 DC_vFinishBlit(dc
, NULL
);
2565 NtGdiFlattenPath(HDC hDC
)
2571 DPRINT("Enter %s\n", __FUNCTION__
);
2573 pDc
= DC_LockDc(hDC
);
2576 EngSetLastError(ERROR_INVALID_HANDLE
);
2580 pPath
= PATH_LockPath(pDc
->dclevel
.hPath
);
2586 if (pPath
->state
== PATH_Open
)
2587 Ret
= PATH_FlattenPath(pPath
);
2589 PATH_UnlockPath(pPath
);
2594 _Success_(return != FALSE
)
2599 _Out_ PDWORD pdwOut
)
2602 BOOL bResult
= TRUE
;
2604 if (!(pDc
= DC_LockDc(hdc
)))
2606 EngSetLastError(ERROR_INVALID_PARAMETER
);
2612 ProbeForWrite(pdwOut
, sizeof(DWORD
), 1);
2613 *pdwOut
= pDc
->dclevel
.laPath
.eMiterLimit
;
2615 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2617 SetLastNtError(_SEH2_GetExceptionCode());
2638 DC
*dc
= DC_LockDc(hDC
);
2641 DPRINT1("Can't lock dc!\n");
2642 EngSetLastError(ERROR_INVALID_PARAMETER
);
2646 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2653 if (pPath
->state
!= PATH_Closed
)
2655 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2661 ret
= pPath
->numEntriesUsed
;
2663 else if (nSize
< pPath
->numEntriesUsed
)
2665 EngSetLastError(ERROR_INVALID_PARAMETER
);
2672 memcpy(Points
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
2673 memcpy(Types
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
2675 /* Convert the points to logical coordinates */
2676 if (!GdiPathDPtoLP(dc
, Points
, pPath
->numEntriesUsed
))
2678 EngSetLastError(ERROR_ARITHMETIC_OVERFLOW
);
2682 ret
= pPath
->numEntriesUsed
;
2684 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2686 SetLastNtError(_SEH2_GetExceptionCode());
2692 PATH_UnlockPath(pPath
);
2699 NtGdiPathToRegion(HDC hDC
)
2707 DPRINT("Enter %s\n", __FUNCTION__
);
2709 pDc
= DC_LockDc(hDC
);
2712 DPRINT1("Failed to lock DC %p\n", hDC
);
2713 EngSetLastError(ERROR_INVALID_PARAMETER
);
2717 pdcattr
= pDc
->pdcattr
;
2719 pPath
= PATH_LockPath(pDc
->dclevel
.hPath
);
2722 DPRINT1("Failed to lock DC path %p\n", pDc
->dclevel
.hPath
);
2727 if (pPath
->state
!= PATH_Closed
)
2729 // FIXME: Check that setlasterror is being called correctly
2730 DPRINT1("Path is not closed!\n");
2731 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2735 /* Create the region and fill it with the path strokes */
2736 Rgn
= REGION_AllocUserRgnWithHandle(1);
2739 DPRINT1("Failed to allocate a region\n");
2740 PATH_UnlockPath(pPath
);
2744 hrgnRval
= Rgn
->BaseObject
.hHmgr
;
2745 /* FIXME: Should we empty the path even if conversion failed? */
2746 if (PATH_PathToRegion(pPath
, pdcattr
->jFillMode
, Rgn
))
2748 PATH_EmptyPath(pPath
);
2749 REGION_UnlockRgn(Rgn
);
2753 DPRINT1("PATH_PathToRegion failed\n");
2759 PATH_UnlockPath(pPath
);
2769 IN OUT OPTIONAL PDWORD pdwOut
)
2772 gxf_long worker
, worker1
;
2773 BOOL bResult
= TRUE
;
2775 if (!(pDc
= DC_LockDc(hdc
)))
2777 EngSetLastError(ERROR_INVALID_PARAMETER
);
2782 worker1
.f
= pDc
->dclevel
.laPath
.eMiterLimit
;
2783 pDc
->dclevel
.laPath
.eMiterLimit
= worker
.f
;
2789 ProbeForWrite(pdwOut
, sizeof(DWORD
), 1);
2790 *pdwOut
= worker1
.l
;
2792 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2794 SetLastNtError(_SEH2_GetExceptionCode());
2806 NtGdiStrokeAndFillPath(HDC hDC
)
2813 DPRINT1("Enter %s\n", __FUNCTION__
);
2815 if (!(pDc
= DC_LockDc(hDC
)))
2817 EngSetLastError(ERROR_INVALID_PARAMETER
);
2820 pPath
= PATH_LockPath(pDc
->dclevel
.hPath
);
2827 DC_vPrepareDCsForBlit(pDc
, NULL
, NULL
, NULL
);
2829 pdcattr
= pDc
->pdcattr
;
2831 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
2832 DC_vUpdateFillBrush(pDc
);
2834 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2835 DC_vUpdateLineBrush(pDc
);
2837 bRet
= PATH_FillPath(pDc
, pPath
);
2838 if (bRet
) bRet
= PATH_StrokePath(pDc
, pPath
);
2839 if (bRet
) PATH_EmptyPath(pPath
);
2841 PATH_UnlockPath(pPath
);
2842 DC_vFinishBlit(pDc
, NULL
);
2849 NtGdiStrokePath(HDC hDC
)
2856 DPRINT("Enter %s\n", __FUNCTION__
);
2858 if (!(pDc
= DC_LockDc(hDC
)))
2860 EngSetLastError(ERROR_INVALID_PARAMETER
);
2864 pPath
= PATH_LockPath(pDc
->dclevel
.hPath
);
2871 DC_vPrepareDCsForBlit(pDc
, NULL
, NULL
, NULL
);
2873 pdcattr
= pDc
->pdcattr
;
2875 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2876 DC_vUpdateLineBrush(pDc
);
2878 bRet
= PATH_StrokePath(pDc
, pPath
);
2880 DC_vFinishBlit(pDc
, NULL
);
2881 PATH_EmptyPath(pPath
);
2883 PATH_UnlockPath(pPath
);
2890 NtGdiWidenPath(HDC hDC
)
2893 PDC pdc
= DC_LockDc(hDC
);
2896 EngSetLastError(ERROR_INVALID_PARAMETER
);
2900 Ret
= PATH_WidenPath(pdc
);