2 * PROJECT: ReactOS Win32k Subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32k/objects/line.c
5 * PURPOSE: Line functions
14 // Some code from the WINE project source (www.winehq.com)
16 // Should use Fx in Point
19 IntGdiMoveToEx(DC
*dc
,
26 PDC_ATTR pdcattr
= dc
->pdcattr
;
29 if ( pdcattr
->ulDirty_
& DIRTY_PTLCURRENT
) // Double hit!
31 Point
->x
= pdcattr
->ptfxCurrent
.x
; // ret prev before change.
32 Point
->y
= pdcattr
->ptfxCurrent
.y
;
33 IntDPtoLP ( dc
, Point
, 1); // Reconvert back.
37 Point
->x
= pdcattr
->ptlCurrent
.x
;
38 Point
->y
= pdcattr
->ptlCurrent
.y
;
41 pdcattr
->ptlCurrent
.x
= X
;
42 pdcattr
->ptlCurrent
.y
= Y
;
43 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
44 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
45 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
47 if (BypassPath
) return TRUE
;
49 PathIsOpen
= PATH_IsPathOpen(dc
->dclevel
);
52 return PATH_MoveTo ( dc
);
57 // Should use Fx in pt
60 IntGetCurrentPositionEx(PDC dc
, LPPOINT pt
)
62 PDC_ATTR pdcattr
= dc
->pdcattr
;
66 if (pdcattr
->ulDirty_
& DIRTY_PTFXCURRENT
)
68 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
69 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
70 pdcattr
->ulDirty_
&= ~(DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
72 pt
->x
= pdcattr
->ptlCurrent
.x
;
73 pt
->y
= pdcattr
->ptlCurrent
.y
;
87 PDC_ATTR pdcattr
= dc
->pdcattr
;
89 if (PATH_IsPathOpen(dc
->dclevel
))
91 Ret
= PATH_LineTo(dc
, XEnd
, YEnd
);
94 // FIXME: PATH_LineTo should maybe do this? No
95 pdcattr
->ptlCurrent
.x
= XEnd
;
96 pdcattr
->ptlCurrent
.y
= YEnd
;
97 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
98 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
99 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
105 psurf
= dc
->dclevel
.pSurface
;
108 EngSetLastError(ERROR_INVALID_HANDLE
);
112 Points
[0].x
= pdcattr
->ptlCurrent
.x
;
113 Points
[0].y
= pdcattr
->ptlCurrent
.y
;
117 IntLPtoDP(dc
, Points
, 2);
119 /* The DCOrg is in device coordinates */
120 Points
[0].x
+= dc
->ptlDCOrig
.x
;
121 Points
[0].y
+= dc
->ptlDCOrig
.y
;
122 Points
[1].x
+= dc
->ptlDCOrig
.x
;
123 Points
[1].y
+= dc
->ptlDCOrig
.y
;
125 Bounds
.left
= min(Points
[0].x
, Points
[1].x
);
126 Bounds
.top
= min(Points
[0].y
, Points
[1].y
);
127 Bounds
.right
= max(Points
[0].x
, Points
[1].x
);
128 Bounds
.bottom
= max(Points
[0].y
, Points
[1].y
);
130 /* Get BRUSH from current pen. */
131 pbrLine
= dc
->dclevel
.pbrLine
;
134 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
136 Ret
= IntEngLineTo(&psurf
->SurfObj
,
137 dc
->rosdc
.CombinedClip
,
138 &dc
->eboLine
.BrushObject
,
139 Points
[0].x
, Points
[0].y
,
140 Points
[1].x
, Points
[1].y
,
142 ROP2_TO_MIX(pdcattr
->jROP2
));
149 pdcattr
->ptlCurrent
.x
= XEnd
;
150 pdcattr
->ptlCurrent
.y
= YEnd
;
151 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
152 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
153 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
160 IntGdiPolyBezier(DC
*dc
,
164 BOOL ret
= FALSE
; // Default to FAILURE
166 if ( PATH_IsPathOpen(dc
->dclevel
) )
168 return PATH_PolyBezier ( dc
, pt
, Count
);
171 /* We'll convert it into line segments and draw them using Polyline */
176 Pts
= GDI_Bezier ( pt
, Count
, &nOut
);
179 ret
= IntGdiPolyline(dc
, Pts
, nOut
);
180 ExFreePoolWithTag(Pts
, TAG_BEZIER
);
188 IntGdiPolyBezierTo(DC
*dc
,
192 BOOL ret
= FALSE
; // Default to failure
193 PDC_ATTR pdcattr
= dc
->pdcattr
;
195 if ( PATH_IsPathOpen(dc
->dclevel
) )
196 ret
= PATH_PolyBezierTo ( dc
, pt
, Count
);
197 else /* We'll do it using PolyBezier */
200 npt
= ExAllocatePoolWithTag(PagedPool
,
201 sizeof(POINT
) * (Count
+ 1),
205 npt
[0].x
= pdcattr
->ptlCurrent
.x
;
206 npt
[0].y
= pdcattr
->ptlCurrent
.y
;
207 memcpy(npt
+ 1, pt
, sizeof(POINT
) * Count
);
208 ret
= IntGdiPolyBezier(dc
, npt
, Count
+1);
209 ExFreePoolWithTag(npt
, TAG_BEZIER
);
214 pdcattr
->ptlCurrent
.x
= pt
[Count
-1].x
;
215 pdcattr
->ptlCurrent
.y
= pt
[Count
-1].y
;
216 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
217 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
218 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
225 IntGdiPolyline(DC
*dc
,
234 PDC_ATTR pdcattr
= dc
->pdcattr
;
236 psurf
= dc
->dclevel
.pSurface
;
242 if (PATH_IsPathOpen(dc
->dclevel
))
243 return PATH_Polyline(dc
, pt
, Count
);
245 DC_vPrepareDCsForBlit(dc
, dc
->rosdc
.CombinedClip
->rclBounds
,
246 NULL
, dc
->rosdc
.CombinedClip
->rclBounds
);
248 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
249 DC_vUpdateFillBrush(dc
);
251 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
252 DC_vUpdateLineBrush(dc
);
254 /* Get BRUSHOBJ from current pen. */
255 pbrLine
= dc
->dclevel
.pbrLine
;
258 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
260 Points
= EngAllocMem(0, Count
* sizeof(POINT
), GDITAG_TEMP
);
263 RtlCopyMemory(Points
, pt
, Count
* sizeof(POINT
));
264 IntLPtoDP(dc
, Points
, Count
);
266 /* Offset the array of points by the DC origin */
267 for (i
= 0; i
< Count
; i
++)
269 Points
[i
].x
+= dc
->ptlDCOrig
.x
;
270 Points
[i
].y
+= dc
->ptlDCOrig
.y
;
273 Ret
= IntEngPolyline(&psurf
->SurfObj
,
274 dc
->rosdc
.CombinedClip
,
275 &dc
->eboLine
.BrushObject
,
278 ROP2_TO_MIX(pdcattr
->jROP2
));
288 DC_vFinishBlit(dc
, NULL
);
294 IntGdiPolylineTo(DC
*dc
,
298 BOOL ret
= FALSE
; // Default to failure
299 PDC_ATTR pdcattr
= dc
->pdcattr
;
301 if (PATH_IsPathOpen(dc
->dclevel
))
303 ret
= PATH_PolylineTo(dc
, pt
, Count
);
305 else /* Do it using Polyline */
307 POINT
*pts
= ExAllocatePoolWithTag(PagedPool
,
308 sizeof(POINT
) * (Count
+ 1),
312 pts
[0].x
= pdcattr
->ptlCurrent
.x
;
313 pts
[0].y
= pdcattr
->ptlCurrent
.y
;
314 memcpy( pts
+ 1, pt
, sizeof(POINT
) * Count
);
315 ret
= IntGdiPolyline(dc
, pts
, Count
+ 1);
316 ExFreePoolWithTag(pts
, TAG_SHAPE
);
321 pdcattr
->ptlCurrent
.x
= pt
[Count
-1].x
;
322 pdcattr
->ptlCurrent
.y
= pt
[Count
-1].y
;
323 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
324 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
325 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
333 IntGdiPolyPolyline(DC
*dc
,
341 BOOL ret
= FALSE
; // Default to failure
345 if (PATH_IsPathOpen(dc
->dclevel
))
346 return PATH_PolyPolyline( dc
, pt
, PolyPoints
, Count
);
348 for (i
= 0; i
< Count
; i
++)
350 ret
= IntGdiPolyline ( dc
, pts
, *pc
);
361 /******************************************************************************/
376 EngSetLastError(ERROR_INVALID_HANDLE
);
379 if (dc
->dctype
== DC_TYPE_INFO
)
382 /* Yes, Windows really returns TRUE in this case */
386 rcLockRect
.left
= dc
->pdcattr
->ptlCurrent
.x
;
387 rcLockRect
.top
= dc
->pdcattr
->ptlCurrent
.y
;
388 rcLockRect
.right
= XEnd
;
389 rcLockRect
.bottom
= YEnd
;
391 IntLPtoDP(dc
, &rcLockRect
, 2);
393 /* The DCOrg is in device coordinates */
394 rcLockRect
.left
+= dc
->ptlDCOrig
.x
;
395 rcLockRect
.top
+= dc
->ptlDCOrig
.y
;
396 rcLockRect
.right
+= dc
->ptlDCOrig
.x
;
397 rcLockRect
.bottom
+= dc
->ptlDCOrig
.y
;
399 DC_vPrepareDCsForBlit(dc
, rcLockRect
, NULL
, rcLockRect
);
401 if (dc
->pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
402 DC_vUpdateLineBrush(dc
);
404 Ret
= IntGdiLineTo(dc
, XEnd
, YEnd
);
406 DC_vFinishBlit(dc
, NULL
);
412 // FIXME: This function is completely broken
423 POINT
*line_pts
= NULL
, *line_pts_old
, *bzr_pts
= NULL
, bzr
[4];
424 INT num_pts
, num_bzr_pts
, space
, space_old
, size
;
429 if (!dc
) return FALSE
;
430 pdcattr
= dc
->pdcattr
;
432 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
433 DC_vUpdateFillBrush(dc
);
435 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
436 DC_vUpdateLineBrush(dc
);
446 ProbeArrayForRead(lppt
, sizeof(POINT
), cCount
, sizeof(LONG
));
447 ProbeArrayForRead(lpbTypes
, sizeof(BYTE
), cCount
, sizeof(BYTE
));
449 if (PATH_IsPathOpen(dc
->dclevel
))
451 result
= PATH_PolyDraw(dc
, (const POINT
*)lppt
, (const BYTE
*)lpbTypes
, cCount
);
455 /* Check for valid point types */
456 for (i
= 0; i
< cCount
; i
++)
461 case PT_LINETO
| PT_CLOSEFIGURE
:
465 if((i
+ 2 < cCount
) && (lpbTypes
[i
+ 1] == PT_BEZIERTO
) &&
466 ((lpbTypes
[i
+ 2] & ~PT_CLOSEFIGURE
) == PT_BEZIERTO
))
476 space
= cCount
+ 300;
477 line_pts
= ExAllocatePoolWithTag(PagedPool
, space
* sizeof(POINT
), TAG_SHAPE
);
480 line_pts
[0].x
= pdcattr
->ptlCurrent
.x
;
481 line_pts
[0].y
= pdcattr
->ptlCurrent
.y
;
483 for ( i
= 0; i
< cCount
; i
++ )
488 if (num_pts
>= 2) IntGdiPolyline( dc
, line_pts
, num_pts
);
490 line_pts
[num_pts
++] = lppt
[i
];
493 case (PT_LINETO
| PT_CLOSEFIGURE
):
494 line_pts
[num_pts
++] = lppt
[i
];
497 bzr
[0].x
= line_pts
[num_pts
- 1].x
;
498 bzr
[0].y
= line_pts
[num_pts
- 1].y
;
499 RtlCopyMemory( &bzr
[1], &lppt
[i
], 3 * sizeof(POINT
) );
501 if ((bzr_pts
= GDI_Bezier( bzr
, 4, &num_bzr_pts
)))
503 size
= num_pts
+ (cCount
- i
) + num_bzr_pts
;
508 line_pts_old
= line_pts
;
509 line_pts
= ExAllocatePoolWithTag(PagedPool
, space
* sizeof(POINT
), TAG_SHAPE
);
510 if (!line_pts
) _SEH2_LEAVE
;
511 RtlCopyMemory(line_pts
, line_pts_old
, space_old
* sizeof(POINT
));
512 ExFreePoolWithTag(line_pts_old
, TAG_SHAPE
);
514 RtlCopyMemory( &line_pts
[num_pts
], &bzr_pts
[1], (num_bzr_pts
- 1) * sizeof(POINT
) );
515 num_pts
+= num_bzr_pts
- 1;
516 ExFreePoolWithTag(bzr_pts
, TAG_BEZIER
);
521 if (lpbTypes
[i
] & PT_CLOSEFIGURE
) line_pts
[num_pts
++] = line_pts
[0];
524 if (num_pts
>= 2) IntGdiPolyline( dc
, line_pts
, num_pts
);
525 IntGdiMoveToEx( dc
, line_pts
[num_pts
- 1].x
, line_pts
[num_pts
- 1].y
, NULL
, TRUE
);
526 ExFreePoolWithTag(line_pts
, TAG_SHAPE
);
529 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
531 SetLastNtError(_SEH2_GetExceptionCode());
543 _Success_(return != FALSE
)
550 OUT OPTIONAL LPPOINT pptOut
)
556 pdc
= DC_LockDc(hdc
);
557 if (!pdc
) return FALSE
;
559 Ret
= IntGdiMoveToEx(pdc
, x
, y
, &Point
, TRUE
);
565 ProbeForWrite(pptOut
, sizeof(POINT
), 1);
566 RtlCopyMemory(pptOut
, &Point
, sizeof(POINT
));
568 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
570 SetLastNtError(_SEH2_GetExceptionCode());
571 Ret
= FALSE
; // CHECKME: is this correct?