2 * PROJECT: ReactOS Win32k Subsystem
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: win32ss/gdi/ntgdi/line.c
5 * PURPOSE: Line functions
14 // Some code from the WINE project source (www.winehq.com)
17 AddPenLinesBounds(PDC dc
, int count
, POINT
*points
)
24 /* Get BRUSH from current pen. */
25 pbrLine
= dc
->dclevel
.pbrLine
;
28 lWidth
= pbrLine
->lWidth
;
31 bounds
.left
= bounds
.top
= INT_MAX
;
32 bounds
.right
= bounds
.bottom
= INT_MIN
;
34 if (((pbrLine
->ulPenStyle
& PS_TYPE_MASK
) & PS_GEOMETRIC
) || lWidth
> 1)
36 /* Windows uses some heuristics to estimate the distance from the point that will be painted */
38 endcap
= (PS_ENDCAP_MASK
& pbrLine
->ulPenStyle
);
39 join
= (PS_JOIN_MASK
& pbrLine
->ulPenStyle
);
40 if (join
== PS_JOIN_MITER
)
43 if (endcap
== PS_ENDCAP_SQUARE
) lWidth
= (lWidth
* 3 + 1) / 2;
47 if (endcap
== PS_ENDCAP_SQUARE
) lWidth
-= lWidth
/ 4;
48 else lWidth
= (lWidth
+ 1) / 2;
54 rect
.left
= points
->x
- lWidth
;
55 rect
.top
= points
->y
- lWidth
;
56 rect
.right
= points
->x
+ lWidth
+ 1;
57 rect
.bottom
= points
->y
+ lWidth
+ 1;
58 RECTL_bUnionRect(&bounds
, &bounds
, &rect
);
62 DPRINT("APLB dc %p l %d t %d\n",dc
,rect
.left
,rect
.top
);
63 DPRINT(" r %d b %d\n",rect
.right
,rect
.bottom
);
67 if (dc
->fs
& DC_FLAG_DIRTY_RAO
) CLIPPING_UpdateGCRegion(dc
);
68 if (REGION_GetRgnBox(dc
->prgnRao
, &rcRgn
))
70 if (RECTL_bIntersectRect( &rcRgn
, &rcRgn
, &bounds
)) IntUpdateBoundsRect(dc
, &rcRgn
);
73 IntUpdateBoundsRect(dc
, &bounds
);
77 // Should use Fx in Point
80 IntGdiMoveToEx(DC
*dc
,
85 PDC_ATTR pdcattr
= dc
->pdcattr
;
88 if ( pdcattr
->ulDirty_
& DIRTY_PTLCURRENT
) // Double hit!
90 Point
->x
= pdcattr
->ptfxCurrent
.x
; // ret prev before change.
91 Point
->y
= pdcattr
->ptfxCurrent
.y
;
92 IntDPtoLP ( dc
, Point
, 1); // Reconvert back.
96 Point
->x
= pdcattr
->ptlCurrent
.x
;
97 Point
->y
= pdcattr
->ptlCurrent
.y
;
100 pdcattr
->ptlCurrent
.x
= X
;
101 pdcattr
->ptlCurrent
.y
= Y
;
102 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
103 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
104 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
117 if (!(dc
= DC_LockDc(hdc
)))
119 EngSetLastError(ERROR_INVALID_HANDLE
);
122 Ret
= IntGdiMoveToEx(dc
, x
, y
, pptOut
);
127 // Should use Fx in pt
130 IntGetCurrentPositionEx(PDC dc
, LPPOINT pt
)
132 PDC_ATTR pdcattr
= dc
->pdcattr
;
136 if (pdcattr
->ulDirty_
& DIRTY_PTFXCURRENT
)
138 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
139 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
140 pdcattr
->ulDirty_
&= ~(DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
142 pt
->x
= pdcattr
->ptlCurrent
.x
;
143 pt
->y
= pdcattr
->ptlCurrent
.y
;
157 PDC_ATTR pdcattr
= dc
->pdcattr
;
158 ASSERT_DC_PREPARED(dc
);
160 if (PATH_IsPathOpen(dc
->dclevel
))
162 Ret
= PATH_LineTo(dc
, XEnd
, YEnd
);
166 psurf
= dc
->dclevel
.pSurface
;
169 EngSetLastError(ERROR_INVALID_HANDLE
);
173 Points
[0].x
= pdcattr
->ptlCurrent
.x
;
174 Points
[0].y
= pdcattr
->ptlCurrent
.y
;
178 IntLPtoDP(dc
, Points
, 2);
180 /* The DCOrg is in device coordinates */
181 Points
[0].x
+= dc
->ptlDCOrig
.x
;
182 Points
[0].y
+= dc
->ptlDCOrig
.y
;
183 Points
[1].x
+= dc
->ptlDCOrig
.x
;
184 Points
[1].y
+= dc
->ptlDCOrig
.y
;
186 Bounds
.left
= min(Points
[0].x
, Points
[1].x
);
187 Bounds
.top
= min(Points
[0].y
, Points
[1].y
);
188 Bounds
.right
= max(Points
[0].x
, Points
[1].x
);
189 Bounds
.bottom
= max(Points
[0].y
, Points
[1].y
);
191 /* Get BRUSH from current pen. */
192 pbrLine
= dc
->dclevel
.pbrLine
;
195 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
197 DPRINT("Bounds dc %p l %d t %d\n",dc
,Bounds
.left
,Bounds
.top
);
198 DPRINT(" r %d b %d\n",Bounds
.right
,Bounds
.bottom
);
199 AddPenLinesBounds(dc
, 2, Points
);
202 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
204 Ret
= IntEngLineTo(&psurf
->SurfObj
,
206 &dc
->eboLine
.BrushObject
,
207 Points
[0].x
, Points
[0].y
,
208 Points
[1].x
, Points
[1].y
,
210 ROP2_TO_MIX(pdcattr
->jROP2
));
217 pdcattr
->ptlCurrent
.x
= XEnd
;
218 pdcattr
->ptlCurrent
.y
= YEnd
;
219 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
220 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
221 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
228 IntGdiPolyBezier(DC
*dc
,
232 BOOL ret
= FALSE
; // Default to FAILURE
234 if ( PATH_IsPathOpen(dc
->dclevel
) )
236 return PATH_PolyBezier ( dc
, pt
, Count
);
239 /* We'll convert it into line segments and draw them using Polyline */
244 Pts
= GDI_Bezier ( pt
, Count
, &nOut
);
247 ret
= IntGdiPolyline(dc
, Pts
, nOut
);
248 ExFreePoolWithTag(Pts
, TAG_BEZIER
);
256 IntGdiPolyBezierTo(DC
*dc
,
260 BOOL ret
= FALSE
; // Default to failure
261 PDC_ATTR pdcattr
= dc
->pdcattr
;
263 if ( PATH_IsPathOpen(dc
->dclevel
) )
264 ret
= PATH_PolyBezierTo ( dc
, pt
, Count
);
265 else /* We'll do it using PolyBezier */
268 npt
= ExAllocatePoolWithTag(PagedPool
,
269 sizeof(POINT
) * (Count
+ 1),
273 npt
[0].x
= pdcattr
->ptlCurrent
.x
;
274 npt
[0].y
= pdcattr
->ptlCurrent
.y
;
275 memcpy(npt
+ 1, pt
, sizeof(POINT
) * Count
);
276 ret
= IntGdiPolyBezier(dc
, npt
, Count
+1);
277 ExFreePoolWithTag(npt
, TAG_BEZIER
);
282 pdcattr
->ptlCurrent
.x
= pt
[Count
-1].x
;
283 pdcattr
->ptlCurrent
.y
= pt
[Count
-1].y
;
284 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
285 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
286 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
293 IntGdiPolyline(DC
*dc
,
302 PDC_ATTR pdcattr
= dc
->pdcattr
;
304 if (!dc
->dclevel
.pSurface
)
309 DC_vPrepareDCsForBlit(dc
, NULL
, NULL
, NULL
);
310 psurf
= dc
->dclevel
.pSurface
;
312 /* Get BRUSHOBJ from current pen. */
313 pbrLine
= dc
->dclevel
.pbrLine
;
316 if (!(pbrLine
->flAttrs
& BR_IS_NULL
))
318 Points
= EngAllocMem(0, Count
* sizeof(POINT
), GDITAG_TEMP
);
321 RtlCopyMemory(Points
, pt
, Count
* sizeof(POINT
));
322 IntLPtoDP(dc
, Points
, Count
);
324 /* Offset the array of points by the DC origin */
325 for (i
= 0; i
< Count
; i
++)
327 Points
[i
].x
+= dc
->ptlDCOrig
.x
;
328 Points
[i
].y
+= dc
->ptlDCOrig
.y
;
331 if (dc
->fs
& (DC_ACCUM_APP
|DC_ACCUM_WMGR
))
333 AddPenLinesBounds(dc
, Count
, Points
);
336 Ret
= IntEngPolyline(&psurf
->SurfObj
,
338 &dc
->eboLine
.BrushObject
,
341 ROP2_TO_MIX(pdcattr
->jROP2
));
351 DC_vFinishBlit(dc
, NULL
);
357 IntGdiPolylineTo(DC
*dc
,
361 BOOL ret
= FALSE
; // Default to failure
362 PDC_ATTR pdcattr
= dc
->pdcattr
;
364 if (PATH_IsPathOpen(dc
->dclevel
))
366 ret
= PATH_PolylineTo(dc
, pt
, Count
);
368 else /* Do it using Polyline */
370 POINT
*pts
= ExAllocatePoolWithTag(PagedPool
,
371 sizeof(POINT
) * (Count
+ 1),
375 pts
[0].x
= pdcattr
->ptlCurrent
.x
;
376 pts
[0].y
= pdcattr
->ptlCurrent
.y
;
377 memcpy( pts
+ 1, pt
, sizeof(POINT
) * Count
);
378 ret
= IntGdiPolyline(dc
, pts
, Count
+ 1);
379 ExFreePoolWithTag(pts
, TAG_SHAPE
);
384 pdcattr
->ptlCurrent
.x
= pt
[Count
-1].x
;
385 pdcattr
->ptlCurrent
.y
= pt
[Count
-1].y
;
386 pdcattr
->ptfxCurrent
= pdcattr
->ptlCurrent
;
387 CoordLPtoDP(dc
, &pdcattr
->ptfxCurrent
); // Update fx
388 pdcattr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
396 IntGdiPolyPolyline(DC
*dc
,
404 BOOL ret
= FALSE
; // Default to failure
408 if (PATH_IsPathOpen(dc
->dclevel
))
410 return PATH_PolyPolyline( dc
, pt
, PolyPoints
, Count
);
412 for (i
= 0; i
< Count
; i
++)
414 ret
= IntGdiPolyline ( dc
, pts
, *pc
);
425 /******************************************************************************/
440 EngSetLastError(ERROR_INVALID_HANDLE
);
444 rcLockRect
.left
= dc
->pdcattr
->ptlCurrent
.x
;
445 rcLockRect
.top
= dc
->pdcattr
->ptlCurrent
.y
;
446 rcLockRect
.right
= XEnd
;
447 rcLockRect
.bottom
= YEnd
;
449 IntLPtoDP(dc
, &rcLockRect
, 2);
451 /* The DCOrg is in device coordinates */
452 rcLockRect
.left
+= dc
->ptlDCOrig
.x
;
453 rcLockRect
.top
+= dc
->ptlDCOrig
.y
;
454 rcLockRect
.right
+= dc
->ptlDCOrig
.x
;
455 rcLockRect
.bottom
+= dc
->ptlDCOrig
.y
;
457 DC_vPrepareDCsForBlit(dc
, &rcLockRect
, NULL
, NULL
);
459 Ret
= IntGdiLineTo(dc
, XEnd
, YEnd
);
461 DC_vFinishBlit(dc
, NULL
);
467 // FIXME: This function is completely broken
479 volatile PPOINT line_pts
, line_pts_old
, bzr_pts
;
480 INT num_pts
, num_bzr_pts
, space
, space_old
, size
;
485 if (!dc
) return FALSE
;
486 pdcattr
= dc
->pdcattr
;
488 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
489 DC_vUpdateFillBrush(dc
);
491 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
492 DC_vUpdateLineBrush(dc
);
506 ProbeArrayForRead(lppt
, sizeof(POINT
), cCount
, sizeof(LONG
));
507 ProbeArrayForRead(lpbTypes
, sizeof(BYTE
), cCount
, sizeof(BYTE
));
509 if (PATH_IsPathOpen(dc
->dclevel
))
511 result
= PATH_PolyDraw(dc
, (const POINT
*)lppt
, (const BYTE
*)lpbTypes
, cCount
);
515 /* Check for valid point types */
516 for (i
= 0; i
< cCount
; i
++)
521 case PT_LINETO
| PT_CLOSEFIGURE
:
525 if((i
+ 2 < cCount
) && (lpbTypes
[i
+ 1] == PT_BEZIERTO
) &&
526 ((lpbTypes
[i
+ 2] & ~PT_CLOSEFIGURE
) == PT_BEZIERTO
))
536 space
= cCount
+ 300;
537 line_pts
= ExAllocatePoolWithTag(PagedPool
, space
* sizeof(POINT
), TAG_SHAPE
);
538 if (line_pts
== NULL
)
546 line_pts
[0].x
= pdcattr
->ptlCurrent
.x
;
547 line_pts
[0].y
= pdcattr
->ptlCurrent
.y
;
549 for ( i
= 0; i
< cCount
; i
++ )
554 if (num_pts
>= 2) IntGdiPolyline( dc
, line_pts
, num_pts
);
556 line_pts
[num_pts
++] = lppt
[i
];
559 case (PT_LINETO
| PT_CLOSEFIGURE
):
560 line_pts
[num_pts
++] = lppt
[i
];
563 bzr
[0].x
= line_pts
[num_pts
- 1].x
;
564 bzr
[0].y
= line_pts
[num_pts
- 1].y
;
565 RtlCopyMemory( &bzr
[1], &lppt
[i
], 3 * sizeof(POINT
) );
567 if ((bzr_pts
= GDI_Bezier( bzr
, 4, &num_bzr_pts
)))
569 size
= num_pts
+ (cCount
- i
) + num_bzr_pts
;
574 line_pts_old
= line_pts
;
575 line_pts
= ExAllocatePoolWithTag(PagedPool
, space
* sizeof(POINT
), TAG_SHAPE
);
576 if (!line_pts
) _SEH2_LEAVE
;
577 RtlCopyMemory(line_pts
, line_pts_old
, space_old
* sizeof(POINT
));
578 ExFreePoolWithTag(line_pts_old
, TAG_SHAPE
);
581 RtlCopyMemory( &line_pts
[num_pts
], &bzr_pts
[1], (num_bzr_pts
- 1) * sizeof(POINT
) );
582 num_pts
+= num_bzr_pts
- 1;
583 ExFreePoolWithTag(bzr_pts
, TAG_BEZIER
);
589 if (lpbTypes
[i
] & PT_CLOSEFIGURE
) line_pts
[num_pts
++] = line_pts
[0];
592 if (num_pts
>= 2) IntGdiPolyline( dc
, line_pts
, num_pts
);
593 IntGdiMoveToEx( dc
, line_pts
[num_pts
- 1].x
, line_pts
[num_pts
- 1].y
, NULL
);
596 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
598 SetLastNtError(_SEH2_GetExceptionCode());
602 if (line_pts
!= NULL
)
604 ExFreePoolWithTag(line_pts
, TAG_SHAPE
);
607 if ((line_pts_old
!= NULL
) && (line_pts_old
!= line_pts
))
609 ExFreePoolWithTag(line_pts_old
, TAG_SHAPE
);
614 ExFreePoolWithTag(bzr_pts
, TAG_BEZIER
);
625 _Success_(return != FALSE
)
632 OUT OPTIONAL LPPOINT pptOut
)
638 pdc
= DC_LockDc(hdc
);
639 if (!pdc
) return FALSE
;
641 Ret
= IntGdiMoveToEx(pdc
, x
, y
, &Point
);
647 ProbeForWrite(pptOut
, sizeof(POINT
), 1);
648 RtlCopyMemory(pptOut
, &Point
, sizeof(POINT
));
650 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
652 SetLastNtError(_SEH2_GetExceptionCode());
653 Ret
= FALSE
; // CHECKME: is this correct?