2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 // Some code from the WINE project source (www.winehq.com)
27 // Should use Fx in Point
30 IntGdiMoveToEx(DC
*dc
,
36 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
37 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
40 if ( Dc_Attr
->ulDirty_
& DIRTY_PTLCURRENT
) // Double hit!
42 Point
->x
= Dc_Attr
->ptfxCurrent
.x
; // ret prev before change.
43 Point
->y
= Dc_Attr
->ptfxCurrent
.y
;
44 IntDPtoLP ( dc
, Point
, 1); // reconvert back.
48 Point
->x
= Dc_Attr
->ptlCurrent
.x
;
49 Point
->y
= Dc_Attr
->ptlCurrent
.y
;
52 Dc_Attr
->ptlCurrent
.x
= X
;
53 Dc_Attr
->ptlCurrent
.y
= Y
;
54 Dc_Attr
->ptfxCurrent
= Dc_Attr
->ptlCurrent
;
55 CoordLPtoDP(dc
, &Dc_Attr
->ptfxCurrent
); // Update fx
56 Dc_Attr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
58 PathIsOpen
= PATH_IsPathOpen(dc
->w
.path
);
61 return PATH_MoveTo ( dc
);
66 // Should use Fx in pt
69 IntGetCurrentPositionEx(PDC dc
, LPPOINT pt
)
71 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
72 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
76 if (Dc_Attr
->ulDirty_
& DIRTY_PTFXCURRENT
)
78 Dc_Attr
->ptfxCurrent
= Dc_Attr
->ptlCurrent
;
79 CoordLPtoDP(dc
, &Dc_Attr
->ptfxCurrent
); // Update fx
80 Dc_Attr
->ulDirty_
&= ~(DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
82 pt
->x
= Dc_Attr
->ptlCurrent
.x
;
83 pt
->y
= Dc_Attr
->ptlCurrent
.y
;
94 PGDIBRUSHOBJ PenBrushObj
;
95 GDIBRUSHINST PenBrushInst
;
98 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
100 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
102 if (PATH_IsPathOpen(dc
->w
.path
))
104 Ret
= PATH_LineTo(dc
, XEnd
, YEnd
);
107 // FIXME - PATH_LineTo should maybe do this...
108 Dc_Attr
->ptlCurrent
.x
= XEnd
;
109 Dc_Attr
->ptlCurrent
.y
= YEnd
;
110 Dc_Attr
->ptfxCurrent
= Dc_Attr
->ptlCurrent
;
111 CoordLPtoDP(dc
, &Dc_Attr
->ptfxCurrent
); // Update fx
112 Dc_Attr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
118 BitmapObj
= BITMAPOBJ_LockBitmap ( dc
->w
.hBitmap
);
119 if (NULL
== BitmapObj
)
121 SetLastWin32Error(ERROR_INVALID_HANDLE
);
125 Points
[0].x
= Dc_Attr
->ptlCurrent
.x
;
126 Points
[0].y
= Dc_Attr
->ptlCurrent
.y
;
130 IntLPtoDP(dc
, Points
, 2);
132 /* The DCOrg is in device coordinates */
133 Points
[0].x
+= dc
->ptlDCOrig
.x
;
134 Points
[0].y
+= dc
->ptlDCOrig
.y
;
135 Points
[1].x
+= dc
->ptlDCOrig
.x
;
136 Points
[1].y
+= dc
->ptlDCOrig
.y
;
138 Bounds
.left
= min(Points
[0].x
, Points
[1].x
);
139 Bounds
.top
= min(Points
[0].y
, Points
[1].y
);
140 Bounds
.right
= max(Points
[0].x
, Points
[1].x
);
141 Bounds
.bottom
= max(Points
[0].y
, Points
[1].y
);
143 /* get BRUSHOBJ from current pen. */
144 PenBrushObj
= PENOBJ_LockPen( Dc_Attr
->hpen
);
147 /* default to BLACK_PEN */
148 PenBrushObj
= PENOBJ_LockPen(NtGdiGetStockObject(BLACK_PEN
));
152 if (!(PenBrushObj
->flAttrs
& GDIBRUSH_IS_NULL
))
154 IntGdiInitBrushInstance(&PenBrushInst
, PenBrushObj
, dc
->XlatePen
);
155 Ret
= IntEngLineTo(&BitmapObj
->SurfObj
,
157 &PenBrushInst
.BrushObject
,
158 Points
[0].x
, Points
[0].y
,
159 Points
[1].x
, Points
[1].y
,
161 ROP2_TO_MIX(Dc_Attr
->jROP2
));
164 BITMAPOBJ_UnlockBitmap ( BitmapObj
);
165 PENOBJ_UnlockPen( PenBrushObj
);
170 Dc_Attr
->ptlCurrent
.x
= XEnd
;
171 Dc_Attr
->ptlCurrent
.y
= YEnd
;
172 Dc_Attr
->ptfxCurrent
= Dc_Attr
->ptlCurrent
;
173 CoordLPtoDP(dc
, &Dc_Attr
->ptfxCurrent
); // Update fx
174 Dc_Attr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
181 IntGdiPolyBezier(DC
*dc
,
185 BOOL ret
= FALSE
; // default to FAILURE
187 if ( PATH_IsPathOpen(dc
->w
.path
) )
189 return PATH_PolyBezier ( dc
, pt
, Count
);
192 /* We'll convert it into line segments and draw them using Polyline */
197 Pts
= GDI_Bezier ( pt
, Count
, &nOut
);
200 ret
= IntGdiPolyline(dc
, Pts
, nOut
);
209 IntGdiPolyBezierTo(DC
*dc
,
213 BOOL ret
= FALSE
; // default to failure
214 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
216 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
217 if ( PATH_IsPathOpen(dc
->w
.path
) )
218 ret
= PATH_PolyBezierTo ( dc
, pt
, Count
);
219 else /* We'll do it using PolyBezier */
222 npt
= ExAllocatePoolWithTag(PagedPool
,
223 sizeof(POINT
) * (Count
+ 1),
227 npt
[0].x
= Dc_Attr
->ptlCurrent
.x
;
228 npt
[0].y
= Dc_Attr
->ptlCurrent
.y
;
229 memcpy(npt
+ 1, pt
, sizeof(POINT
) * Count
);
230 ret
= IntGdiPolyBezier(dc
, npt
, Count
+1);
236 Dc_Attr
->ptlCurrent
.x
= pt
[Count
-1].x
;
237 Dc_Attr
->ptlCurrent
.y
= pt
[Count
-1].y
;
238 Dc_Attr
->ptfxCurrent
= Dc_Attr
->ptlCurrent
;
239 CoordLPtoDP(dc
, &Dc_Attr
->ptfxCurrent
); // Update fx
240 Dc_Attr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
247 IntGdiPolyline(DC
*dc
,
251 BITMAPOBJ
*BitmapObj
;
252 GDIBRUSHOBJ
*PenBrushObj
;
253 GDIBRUSHINST PenBrushInst
;
257 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
259 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
260 if (PATH_IsPathOpen(dc
->w
.path
))
261 return PATH_Polyline(dc
, pt
, Count
);
263 /* Get BRUSHOBJ from current pen. */
264 PenBrushObj
= PENOBJ_LockPen(Dc_Attr
->hpen
);
265 /* FIXME - PenBrushObj can be NULL! Don't assert here! */
268 if (!(PenBrushObj
->flAttrs
& GDIBRUSH_IS_NULL
))
270 Points
= EngAllocMem(0, Count
* sizeof(POINT
), TAG_COORD
);
273 BitmapObj
= BITMAPOBJ_LockBitmap(dc
->w
.hBitmap
);
274 /* FIXME - BitmapObj can be NULL!!!!
275 Don't assert but handle this case gracefully! */
278 RtlCopyMemory(Points
, pt
, Count
* sizeof(POINT
));
279 IntLPtoDP(dc
, Points
, Count
);
281 /* Offset the array of point by the dc->w.DCOrg */
282 for (i
= 0; i
< Count
; i
++)
284 Points
[i
].x
+= dc
->ptlDCOrig
.x
;
285 Points
[i
].y
+= dc
->ptlDCOrig
.y
;
288 IntGdiInitBrushInstance(&PenBrushInst
, PenBrushObj
, dc
->XlatePen
);
289 Ret
= IntEngPolyline(&BitmapObj
->SurfObj
,
291 &PenBrushInst
.BrushObject
,
294 ROP2_TO_MIX(Dc_Attr
->jROP2
));
296 BITMAPOBJ_UnlockBitmap(BitmapObj
);
305 PENOBJ_UnlockPen(PenBrushObj
);
311 IntGdiPolylineTo(DC
*dc
,
315 BOOL ret
= FALSE
; // default to failure
316 PDC_ATTR Dc_Attr
= dc
->pDc_Attr
;
318 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
319 if (PATH_IsPathOpen(dc
->w
.path
))
321 ret
= PATH_PolylineTo(dc
, pt
, Count
);
323 else /* do it using Polyline */
325 POINT
*pts
= ExAllocatePoolWithTag(PagedPool
,
326 sizeof(POINT
) * (Count
+ 1),
330 pts
[0].x
= Dc_Attr
->ptlCurrent
.x
;
331 pts
[0].y
= Dc_Attr
->ptlCurrent
.y
;
332 memcpy( pts
+ 1, pt
, sizeof(POINT
) * Count
);
333 ret
= IntGdiPolyline(dc
, pts
, Count
+ 1);
339 Dc_Attr
->ptlCurrent
.x
= pt
[Count
-1].x
;
340 Dc_Attr
->ptlCurrent
.y
= pt
[Count
-1].y
;
341 Dc_Attr
->ptfxCurrent
= Dc_Attr
->ptlCurrent
;
342 CoordLPtoDP(dc
, &Dc_Attr
->ptfxCurrent
); // Update fx
343 Dc_Attr
->ulDirty_
&= ~(DIRTY_PTLCURRENT
|DIRTY_PTFXCURRENT
|DIRTY_STYLESTATE
);
351 IntGdiPolyPolyline(DC
*dc
,
359 BOOL ret
= FALSE
; // default to failure
363 for (i
= 0; i
< Count
; i
++)
365 ret
= IntGdiPolyline ( dc
, pts
, *pc
);
376 /******************************************************************************/
390 SetLastWin32Error(ERROR_INVALID_HANDLE
);
393 if (dc
->DC_Type
== DC_TYPE_INFO
)
396 /* Yes, Windows really returns TRUE in this case */
400 Ret
= IntGdiLineTo(dc
, XEnd
, YEnd
);
418 PDC_ATTR Dc_Attr
= NULL
;
421 if (!dc
) return FALSE
;
422 Dc_Attr
= dc
->pDc_Attr
;
423 if (!Dc_Attr
) Dc_Attr
= &dc
->Dc_Attr
;
427 ProbeArrayForRead(lppt
, sizeof(POINT
), cCount
, sizeof(LONG
));
428 ProbeArrayForRead(lpbTypes
, sizeof(BYTE
), cCount
, sizeof(BYTE
));
430 /* check for each bezierto if there are two more points */
431 for ( i
= 0; i
< cCount
; i
++ )
433 if ( lpbTypes
[i
] != PT_MOVETO
&&
434 lpbTypes
[i
] & PT_BEZIERTO
)
436 if ( cCount
< i
+3 ) _SEH_LEAVE
;
441 /* if no moveto occurs, we will close the figure here */
442 lastmove
.x
= Dc_Attr
->ptlCurrent
.x
;
443 lastmove
.y
= Dc_Attr
->ptlCurrent
.y
;
446 for ( i
= 0; i
< cCount
; i
++ )
448 if ( lpbTypes
[i
] == PT_MOVETO
)
450 IntGdiMoveToEx( dc
, lppt
[i
].x
, lppt
[i
].y
, NULL
);
451 lastmove
.x
= Dc_Attr
->ptlCurrent
.x
;
452 lastmove
.y
= Dc_Attr
->ptlCurrent
.y
;
454 else if ( lpbTypes
[i
] & PT_LINETO
)
455 IntGdiLineTo( dc
, lppt
[i
].x
, lppt
[i
].y
);
456 else if ( lpbTypes
[i
] & PT_BEZIERTO
)
459 pts
[0].x
= Dc_Attr
->ptlCurrent
.x
;
460 pts
[0].y
= Dc_Attr
->ptlCurrent
.y
;
461 RtlCopyMemory(pts
+ 1, &lppt
[i
], sizeof(POINT
) * 3);
462 IntGdiPolyBezier(dc
, pts
, 4);
467 if ( lpbTypes
[i
] & PT_CLOSEFIGURE
)
469 if ( PATH_IsPathOpen(dc
->w
.path
) )
471 IntGdiCloseFigure( dc
);
473 else IntGdiLineTo( dc
, lastmove
.x
, lastmove
.y
);
481 SetLastNtError(_SEH_GetExceptionCode());