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
);
64 if (!(dc
= DC_LockDc(hdc
)))
66 EngSetLastError(ERROR_INVALID_HANDLE
);
69 return IntGdiMoveToEx(dc
, x
, y
, pptOut
, TRUE
);
72 // Should use Fx in pt
75 IntGetCurrentPositionEx(PDC dc
, LPPOINT pt
)
77 PDC_ATTR pdcattr
= dc
->pdcattr
;
81 if (pdcattr
->ulDirty_
& DIRTY_PTFXCURRENT
)
83 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
84 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
85 pdcattr
->ulDirty_
&= ~(DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
87 pt
->x
= pdcattr
->ptlCurrent
.x
;
88 pt
->y
= pdcattr
->ptlCurrent
.y
;
102 PDC_ATTR pdcattr
= dc
->pdcattr
;
104 if (PATH_IsPathOpen(dc
->dclevel
))
106 Ret
= PATH_LineTo(dc
, XEnd
, YEnd
);
109 // FIXME: PATH_LineTo should maybe do this? No
110 pdcattr
->ptlCurrent
.x
= XEnd
;
111 pdcattr
->ptlCurrent
.y
= YEnd
;
112 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
113 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
114 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
120 psurf
= dc
->dclevel
.pSurface
;
123 EngSetLastError(ERROR_INVALID_HANDLE
);
127 Points
[0].x
= pdcattr
->ptlCurrent
.x
;
128 Points
[0].y
= pdcattr
->ptlCurrent
.y
;
132 IntLPtoDP(dc
, Points
, 2);
134 /* The DCOrg is in device coordinates */
135 Points
[0].x
+= dc
->ptlDCOrig
.x
;
136 Points
[0].y
+= dc
->ptlDCOrig
.y
;
137 Points
[1].x
+= dc
->ptlDCOrig
.x
;
138 Points
[1].y
+= dc
->ptlDCOrig
.y
;
140 Bounds
.left
= min(Points
[0].x
, Points
[1].x
);
141 Bounds
.top
= min(Points
[0].y
, Points
[1].y
);
142 Bounds
.right
= max(Points
[0].x
, Points
[1].x
);
143 Bounds
.bottom
= max(Points
[0].y
, Points
[1].y
);
145 /* Get BRUSH from current pen. */
146 pbrLine
= dc
->dclevel
.pbrLine
;
149 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
151 Ret
= IntEngLineTo(&psurf
->SurfObj
,
153 &dc
->eboLine
.BrushObject
,
154 Points
[0].x
, Points
[0].y
,
155 Points
[1].x
, Points
[1].y
,
157 ROP2_TO_MIX(pdcattr
->jROP2
));
164 pdcattr
->ptlCurrent
.x
= XEnd
;
165 pdcattr
->ptlCurrent
.y
= YEnd
;
166 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
167 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
168 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
175 IntGdiPolyBezier(DC
*dc
,
179 BOOL ret
= FALSE
; // Default to FAILURE
181 if ( PATH_IsPathOpen(dc
->dclevel
) )
183 return PATH_PolyBezier ( dc
, pt
, Count
);
186 /* We'll convert it into line segments and draw them using Polyline */
191 Pts
= GDI_Bezier ( pt
, Count
, &nOut
);
194 ret
= IntGdiPolyline(dc
, Pts
, nOut
);
195 ExFreePoolWithTag(Pts
, TAG_BEZIER
);
203 IntGdiPolyBezierTo(DC
*dc
,
207 BOOL ret
= FALSE
; // Default to failure
208 PDC_ATTR pdcattr
= dc
->pdcattr
;
210 if ( PATH_IsPathOpen(dc
->dclevel
) )
211 ret
= PATH_PolyBezierTo ( dc
, pt
, Count
);
212 else /* We'll do it using PolyBezier */
215 npt
= ExAllocatePoolWithTag(PagedPool
,
216 sizeof(POINT
) * (Count
+ 1),
220 npt
[0].x
= pdcattr
->ptlCurrent
.x
;
221 npt
[0].y
= pdcattr
->ptlCurrent
.y
;
222 memcpy(npt
+ 1, pt
, sizeof(POINT
) * Count
);
223 ret
= IntGdiPolyBezier(dc
, npt
, Count
+1);
224 ExFreePoolWithTag(npt
, TAG_BEZIER
);
229 pdcattr
->ptlCurrent
.x
= pt
[Count
-1].x
;
230 pdcattr
->ptlCurrent
.y
= pt
[Count
-1].y
;
231 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
232 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
233 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
240 IntGdiPolyline(DC
*dc
,
249 PDC_ATTR pdcattr
= dc
->pdcattr
;
251 psurf
= dc
->dclevel
.pSurface
;
257 if (PATH_IsPathOpen(dc
->dclevel
))
258 return PATH_Polyline(dc
, pt
, Count
);
260 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
262 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
263 DC_vUpdateFillBrush(dc
);
265 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
266 DC_vUpdateLineBrush(dc
);
268 /* Get BRUSHOBJ from current pen. */
269 pbrLine
= dc
->dclevel
.pbrLine
;
272 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
274 Points
= EngAllocMem(0, Count
* sizeof(POINT
), GDITAG_TEMP
);
277 RtlCopyMemory(Points
, pt
, Count
* sizeof(POINT
));
278 IntLPtoDP(dc
, Points
, Count
);
280 /* Offset the array of points by the DC origin */
281 for (i
= 0; i
< Count
; i
++)
283 Points
[i
].x
+= dc
->ptlDCOrig
.x
;
284 Points
[i
].y
+= dc
->ptlDCOrig
.y
;
287 Ret
= IntEngPolyline(&psurf
->SurfObj
,
289 &dc
->eboLine
.BrushObject
,
292 ROP2_TO_MIX(pdcattr
->jROP2
));
302 DC_vFinishBlit(dc
, NULL
);
308 IntGdiPolylineTo(DC
*dc
,
312 BOOL ret
= FALSE
; // Default to failure
313 PDC_ATTR pdcattr
= dc
->pdcattr
;
315 if (PATH_IsPathOpen(dc
->dclevel
))
317 ret
= PATH_PolylineTo(dc
, pt
, Count
);
319 else /* Do it using Polyline */
321 POINT
*pts
= ExAllocatePoolWithTag(PagedPool
,
322 sizeof(POINT
) * (Count
+ 1),
326 pts
[0].x
= pdcattr
->ptlCurrent
.x
;
327 pts
[0].y
= pdcattr
->ptlCurrent
.y
;
328 memcpy( pts
+ 1, pt
, sizeof(POINT
) * Count
);
329 ret
= IntGdiPolyline(dc
, pts
, Count
+ 1);
330 ExFreePoolWithTag(pts
, TAG_SHAPE
);
335 pdcattr
->ptlCurrent
.x
= pt
[Count
-1].x
;
336 pdcattr
->ptlCurrent
.y
= pt
[Count
-1].y
;
337 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
338 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
339 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
347 IntGdiPolyPolyline(DC
*dc
,
355 BOOL ret
= FALSE
; // Default to failure
359 if (PATH_IsPathOpen(dc
->dclevel
))
360 return PATH_PolyPolyline( dc
, pt
, PolyPoints
, Count
);
362 for (i
= 0; i
< Count
; i
++)
364 ret
= IntGdiPolyline ( dc
, pts
, *pc
);
375 /******************************************************************************/
390 EngSetLastError(ERROR_INVALID_HANDLE
);
393 if (dc
->dctype
== DC_TYPE_INFO
)
396 /* Yes, Windows really returns TRUE in this case */
400 rcLockRect
.left
= dc
->pdcattr
->ptlCurrent
.x
;
401 rcLockRect
.top
= dc
->pdcattr
->ptlCurrent
.y
;
402 rcLockRect
.right
= XEnd
;
403 rcLockRect
.bottom
= YEnd
;
405 IntLPtoDP(dc
, &rcLockRect
, 2);
407 /* The DCOrg is in device coordinates */
408 rcLockRect
.left
+= dc
->ptlDCOrig
.x
;
409 rcLockRect
.top
+= dc
->ptlDCOrig
.y
;
410 rcLockRect
.right
+= dc
->ptlDCOrig
.x
;
411 rcLockRect
.bottom
+= dc
->ptlDCOrig
.y
;
413 DC_vPrepareDCsForBlit(dc
, &rcLockRect
, NULL
, NULL
);
415 if (dc
->pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
416 DC_vUpdateLineBrush(dc
);
418 Ret
= IntGdiLineTo(dc
, XEnd
, YEnd
);
420 DC_vFinishBlit(dc
, NULL
);
426 // FIXME: This function is completely broken
438 volatile PPOINT line_pts
, line_pts_old
, bzr_pts
;
439 INT num_pts
, num_bzr_pts
, space
, space_old
, size
;
444 if (!dc
) return FALSE
;
445 pdcattr
= dc
->pdcattr
;
447 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
448 DC_vUpdateFillBrush(dc
);
450 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
451 DC_vUpdateLineBrush(dc
);
465 ProbeArrayForRead(lppt
, sizeof(POINT
), cCount
, sizeof(LONG
));
466 ProbeArrayForRead(lpbTypes
, sizeof(BYTE
), cCount
, sizeof(BYTE
));
468 if (PATH_IsPathOpen(dc
->dclevel
))
470 result
= PATH_PolyDraw(dc
, (const POINT
*)lppt
, (const BYTE
*)lpbTypes
, cCount
);
474 /* Check for valid point types */
475 for (i
= 0; i
< cCount
; i
++)
480 case PT_LINETO
| PT_CLOSEFIGURE
:
484 if((i
+ 2 < cCount
) && (lpbTypes
[i
+ 1] == PT_BEZIERTO
) &&
485 ((lpbTypes
[i
+ 2] & ~PT_CLOSEFIGURE
) == PT_BEZIERTO
))
495 space
= cCount
+ 300;
496 line_pts
= ExAllocatePoolWithTag(PagedPool
, space
* sizeof(POINT
), TAG_SHAPE
);
497 if (line_pts
== NULL
)
505 line_pts
[0].x
= pdcattr
->ptlCurrent
.x
;
506 line_pts
[0].y
= pdcattr
->ptlCurrent
.y
;
508 for ( i
= 0; i
< cCount
; i
++ )
513 if (num_pts
>= 2) IntGdiPolyline( dc
, line_pts
, num_pts
);
515 line_pts
[num_pts
++] = lppt
[i
];
518 case (PT_LINETO
| PT_CLOSEFIGURE
):
519 line_pts
[num_pts
++] = lppt
[i
];
522 bzr
[0].x
= line_pts
[num_pts
- 1].x
;
523 bzr
[0].y
= line_pts
[num_pts
- 1].y
;
524 RtlCopyMemory( &bzr
[1], &lppt
[i
], 3 * sizeof(POINT
) );
526 if ((bzr_pts
= GDI_Bezier( bzr
, 4, &num_bzr_pts
)))
528 size
= num_pts
+ (cCount
- i
) + num_bzr_pts
;
533 line_pts_old
= line_pts
;
534 line_pts
= ExAllocatePoolWithTag(PagedPool
, space
* sizeof(POINT
), TAG_SHAPE
);
535 if (!line_pts
) _SEH2_LEAVE
;
536 RtlCopyMemory(line_pts
, line_pts_old
, space_old
* sizeof(POINT
));
537 ExFreePoolWithTag(line_pts_old
, TAG_SHAPE
);
540 RtlCopyMemory( &line_pts
[num_pts
], &bzr_pts
[1], (num_bzr_pts
- 1) * sizeof(POINT
) );
541 num_pts
+= num_bzr_pts
- 1;
542 ExFreePoolWithTag(bzr_pts
, TAG_BEZIER
);
548 if (lpbTypes
[i
] & PT_CLOSEFIGURE
) line_pts
[num_pts
++] = line_pts
[0];
551 if (num_pts
>= 2) IntGdiPolyline( dc
, line_pts
, num_pts
);
552 IntGdiMoveToEx( dc
, line_pts
[num_pts
- 1].x
, line_pts
[num_pts
- 1].y
, NULL
, TRUE
);
555 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
557 SetLastNtError(_SEH2_GetExceptionCode());
561 if (line_pts
!= NULL
)
563 ExFreePoolWithTag(line_pts
, TAG_SHAPE
);
566 if ((line_pts_old
!= NULL
) && (line_pts_old
!= line_pts
))
568 ExFreePoolWithTag(line_pts_old
, TAG_SHAPE
);
573 ExFreePoolWithTag(bzr_pts
, TAG_BEZIER
);
584 _Success_(return != FALSE
)
591 OUT OPTIONAL LPPOINT pptOut
)
597 pdc
= DC_LockDc(hdc
);
598 if (!pdc
) return FALSE
;
600 Ret
= IntGdiMoveToEx(pdc
, x
, y
, &Point
, TRUE
);
606 ProbeForWrite(pptOut
, sizeof(POINT
), 1);
607 RtlCopyMemory(pptOut
, &Point
, sizeof(POINT
));
609 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
611 SetLastNtError(_SEH2_GetExceptionCode());
612 Ret
= FALSE
; // CHECKME: is this correct?