2 * GDI drawing functions.
4 * Copyright 1993, 1994 Alexandre Julliard
5 * Copyright 1997 Bertho A. Stultiens
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
37 /***********************************************************************
40 BOOL16 WINAPI
LineTo16( HDC16 hdc
, INT16 x
, INT16 y
)
42 return LineTo( hdc
, x
, y
);
46 /***********************************************************************
49 BOOL WINAPI
LineTo( HDC hdc
, INT x
, INT y
)
51 DC
* dc
= DC_GetDCUpdate( hdc
);
56 if(PATH_IsPathOpen(dc
->path
))
57 ret
= PATH_LineTo(dc
, x
, y
);
59 ret
= dc
->funcs
->pLineTo
&& dc
->funcs
->pLineTo(dc
->physDev
,x
,y
);
64 GDI_ReleaseObj( hdc
);
69 /***********************************************************************
72 DWORD WINAPI
MoveTo16( HDC16 hdc
, INT16 x
, INT16 y
)
76 if (!MoveToEx( (HDC
)hdc
, x
, y
, &pt
)) return 0;
77 return MAKELONG(pt
.x
,pt
.y
);
81 /***********************************************************************
84 BOOL16 WINAPI
MoveToEx16( HDC16 hdc
, INT16 x
, INT16 y
, LPPOINT16 pt
)
88 if (!MoveToEx( (HDC
)hdc
, (INT
)x
, (INT
)y
, &pt32
)) return FALSE
;
89 if (pt
) CONV_POINT32TO16( &pt32
, pt
);
94 /***********************************************************************
97 BOOL WINAPI
MoveToEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
100 DC
* dc
= DC_GetDCPtr( hdc
);
102 if(!dc
) return FALSE
;
105 pt
->x
= dc
->CursPosX
;
106 pt
->y
= dc
->CursPosY
;
111 if(PATH_IsPathOpen(dc
->path
)) ret
= PATH_MoveTo(dc
);
112 else if (dc
->funcs
->pMoveTo
) ret
= dc
->funcs
->pMoveTo(dc
->physDev
,x
,y
);
113 GDI_ReleaseObj( hdc
);
118 /***********************************************************************
121 BOOL16 WINAPI
Arc16( HDC16 hdc
, INT16 left
, INT16 top
, INT16 right
,
122 INT16 bottom
, INT16 xstart
, INT16 ystart
,
123 INT16 xend
, INT16 yend
)
125 return Arc( (HDC
)hdc
, (INT
)left
, (INT
)top
, (INT
)right
,
126 (INT
)bottom
, (INT
)xstart
, (INT
)ystart
, (INT
)xend
,
131 /***********************************************************************
134 BOOL WINAPI
Arc( HDC hdc
, INT left
, INT top
, INT right
,
135 INT bottom
, INT xstart
, INT ystart
,
139 DC
* dc
= DC_GetDCUpdate( hdc
);
142 if(PATH_IsPathOpen(dc
->path
))
143 ret
= PATH_Arc(dc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
,0);
144 else if (dc
->funcs
->pArc
)
145 ret
= dc
->funcs
->pArc(dc
->physDev
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
);
146 GDI_ReleaseObj( hdc
);
151 /***********************************************************************
154 BOOL WINAPI
ArcTo( HDC hdc
,
156 INT right
, INT bottom
,
157 INT xstart
, INT ystart
,
161 DC
* dc
= DC_GetDCUpdate( hdc
);
162 if(!dc
) return FALSE
;
164 if(dc
->funcs
->pArcTo
)
166 result
= dc
->funcs
->pArcTo( dc
->physDev
, left
, top
, right
, bottom
,
167 xstart
, ystart
, xend
, yend
);
168 GDI_ReleaseObj( hdc
);
171 GDI_ReleaseObj( hdc
);
174 * According to the documentation, a line is drawn from the current
175 * position to the starting point of the arc.
177 LineTo(hdc
, xstart
, ystart
);
179 * Then the arc is drawn.
181 result
= Arc(hdc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
183 * If no error occurred, the current position is moved to the ending
186 if (result
) MoveToEx(hdc
, xend
, yend
, NULL
);
190 /***********************************************************************
193 BOOL16 WINAPI
Pie16( HDC16 hdc
, INT16 left
, INT16 top
,
194 INT16 right
, INT16 bottom
, INT16 xstart
, INT16 ystart
,
195 INT16 xend
, INT16 yend
)
197 return Pie( (HDC
)hdc
, (INT
)left
, (INT
)top
, (INT
)right
,
198 (INT
)bottom
, (INT
)xstart
, (INT
)ystart
, (INT
)xend
,
203 /***********************************************************************
206 BOOL WINAPI
Pie( HDC hdc
, INT left
, INT top
,
207 INT right
, INT bottom
, INT xstart
, INT ystart
,
211 DC
* dc
= DC_GetDCUpdate( hdc
);
212 if (!dc
) return FALSE
;
214 if(PATH_IsPathOpen(dc
->path
))
215 ret
= PATH_Arc(dc
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
,2);
216 else if(dc
->funcs
->pPie
)
217 ret
= dc
->funcs
->pPie(dc
->physDev
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
);
219 GDI_ReleaseObj( hdc
);
224 /***********************************************************************
227 BOOL16 WINAPI
Chord16( HDC16 hdc
, INT16 left
, INT16 top
,
228 INT16 right
, INT16 bottom
, INT16 xstart
, INT16 ystart
,
229 INT16 xend
, INT16 yend
)
231 return Chord( hdc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
235 /***********************************************************************
238 BOOL WINAPI
Chord( HDC hdc
, INT left
, INT top
,
239 INT right
, INT bottom
, INT xstart
, INT ystart
,
243 DC
* dc
= DC_GetDCUpdate( hdc
);
244 if (!dc
) return FALSE
;
246 if(PATH_IsPathOpen(dc
->path
))
247 ret
= PATH_Arc(dc
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
,1);
248 else if(dc
->funcs
->pChord
)
249 ret
= dc
->funcs
->pChord(dc
->physDev
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
);
251 GDI_ReleaseObj( hdc
);
256 /***********************************************************************
259 BOOL16 WINAPI
Ellipse16( HDC16 hdc
, INT16 left
, INT16 top
,
260 INT16 right
, INT16 bottom
)
262 return Ellipse( hdc
, left
, top
, right
, bottom
);
266 /***********************************************************************
269 BOOL WINAPI
Ellipse( HDC hdc
, INT left
, INT top
,
270 INT right
, INT bottom
)
273 DC
* dc
= DC_GetDCUpdate( hdc
);
274 if (!dc
) return FALSE
;
276 if(PATH_IsPathOpen(dc
->path
))
277 ret
= PATH_Ellipse(dc
,left
,top
,right
,bottom
);
278 else if (dc
->funcs
->pEllipse
)
279 ret
= dc
->funcs
->pEllipse(dc
->physDev
,left
,top
,right
,bottom
);
281 GDI_ReleaseObj( hdc
);
286 /***********************************************************************
289 BOOL16 WINAPI
Rectangle16( HDC16 hdc
, INT16 left
, INT16 top
,
290 INT16 right
, INT16 bottom
)
292 return Rectangle( hdc
, left
, top
, right
, bottom
);
296 /***********************************************************************
297 * Rectangle (GDI32.@)
299 BOOL WINAPI
Rectangle( HDC hdc
, INT left
, INT top
,
300 INT right
, INT bottom
)
303 DC
* dc
= DC_GetDCUpdate( hdc
);
306 if(PATH_IsPathOpen(dc
->path
))
307 ret
= PATH_Rectangle(dc
, left
, top
, right
, bottom
);
308 else if (dc
->funcs
->pRectangle
)
309 ret
= dc
->funcs
->pRectangle(dc
->physDev
,left
,top
,right
,bottom
);
310 GDI_ReleaseObj( hdc
);
316 /***********************************************************************
319 BOOL16 WINAPI
RoundRect16( HDC16 hdc
, INT16 left
, INT16 top
, INT16 right
,
320 INT16 bottom
, INT16 ell_width
, INT16 ell_height
)
322 return RoundRect( hdc
, left
, top
, right
, bottom
, ell_width
, ell_height
);
326 /***********************************************************************
327 * RoundRect (GDI32.@)
329 BOOL WINAPI
RoundRect( HDC hdc
, INT left
, INT top
, INT right
,
330 INT bottom
, INT ell_width
, INT ell_height
)
333 DC
*dc
= DC_GetDCUpdate( hdc
);
337 if(PATH_IsPathOpen(dc
->path
))
338 ret
= PATH_RoundRect(dc
,left
,top
,right
,bottom
,ell_width
,ell_height
);
339 else if (dc
->funcs
->pRoundRect
)
340 ret
= dc
->funcs
->pRoundRect(dc
->physDev
,left
,top
,right
,bottom
,ell_width
,ell_height
);
341 GDI_ReleaseObj( hdc
);
346 /***********************************************************************
349 COLORREF WINAPI
SetPixel16( HDC16 hdc
, INT16 x
, INT16 y
, COLORREF color
)
351 return SetPixel( hdc
, x
, y
, color
);
355 /***********************************************************************
358 COLORREF WINAPI
SetPixel( HDC hdc
, INT x
, INT y
, COLORREF color
)
361 DC
* dc
= DC_GetDCUpdate( hdc
);
364 if (dc
->funcs
->pSetPixel
) ret
= dc
->funcs
->pSetPixel(dc
->physDev
,x
,y
,color
);
365 GDI_ReleaseObj( hdc
);
370 /***********************************************************************
371 * SetPixelV (GDI32.@)
373 BOOL WINAPI
SetPixelV( HDC hdc
, INT x
, INT y
, COLORREF color
)
376 DC
* dc
= DC_GetDCUpdate( hdc
);
379 if (dc
->funcs
->pSetPixel
)
381 dc
->funcs
->pSetPixel(dc
->physDev
,x
,y
,color
);
384 GDI_ReleaseObj( hdc
);
389 /***********************************************************************
392 COLORREF WINAPI
GetPixel16( HDC16 hdc
, INT16 x
, INT16 y
)
394 return GetPixel( hdc
, x
, y
);
398 /***********************************************************************
401 COLORREF WINAPI
GetPixel( HDC hdc
, INT x
, INT y
)
403 COLORREF ret
= CLR_INVALID
;
404 DC
* dc
= DC_GetDCUpdate( hdc
);
408 /* FIXME: should this be in the graphics driver? */
409 if (PtVisible( hdc
, x
, y
))
411 if (dc
->funcs
->pGetPixel
) ret
= dc
->funcs
->pGetPixel(dc
->physDev
,x
,y
);
413 GDI_ReleaseObj( hdc
);
419 /******************************************************************************
420 * ChoosePixelFormat [GDI32.@]
421 * Matches a pixel format to given format
424 * hdc [I] Device context to search for best pixel match
425 * ppfd [I] Pixel format for which a match is sought
428 * Success: Pixel format index closest to given format
431 INT WINAPI
ChoosePixelFormat( HDC hdc
, const LPPIXELFORMATDESCRIPTOR ppfd
)
434 DC
* dc
= DC_GetDCPtr( hdc
);
436 TRACE("(%08x,%p)\n",hdc
,ppfd
);
440 if (!dc
->funcs
->pChoosePixelFormat
) FIXME(" :stub\n");
441 else ret
= dc
->funcs
->pChoosePixelFormat(dc
->physDev
,ppfd
);
443 GDI_ReleaseObj( hdc
);
448 /******************************************************************************
449 * SetPixelFormat [GDI32.@]
450 * Sets pixel format of device context
453 * hdc [I] Device context to search for best pixel match
454 * iPixelFormat [I] Pixel format index
455 * ppfd [I] Pixel format for which a match is sought
459 BOOL WINAPI
SetPixelFormat( HDC hdc
, INT iPixelFormat
,
460 const PIXELFORMATDESCRIPTOR
*ppfd
)
463 DC
* dc
= DC_GetDCPtr( hdc
);
465 TRACE("(%d,%d,%p)\n",hdc
,iPixelFormat
,ppfd
);
469 if (!dc
->funcs
->pSetPixelFormat
) FIXME(" :stub\n");
470 else bRet
= dc
->funcs
->pSetPixelFormat(dc
->physDev
,iPixelFormat
,ppfd
);
472 GDI_ReleaseObj( hdc
);
477 /******************************************************************************
478 * GetPixelFormat [GDI32.@]
479 * Gets index of pixel format of DC
482 * hdc [I] Device context whose pixel format index is sought
485 * Success: Currently selected pixel format
488 INT WINAPI
GetPixelFormat( HDC hdc
)
491 DC
* dc
= DC_GetDCPtr( hdc
);
493 TRACE("(%08x)\n",hdc
);
497 if (!dc
->funcs
->pGetPixelFormat
) FIXME(" :stub\n");
498 else ret
= dc
->funcs
->pGetPixelFormat(dc
->physDev
);
500 GDI_ReleaseObj( hdc
);
505 /******************************************************************************
506 * DescribePixelFormat [GDI32.@]
507 * Gets info about pixel format from DC
510 * hdc [I] Device context
511 * iPixelFormat [I] Pixel format selector
512 * nBytes [I] Size of buffer
513 * ppfd [O] Pointer to structure to receive pixel format data
516 * Success: Maximum pixel format index of the device context
519 INT WINAPI
DescribePixelFormat( HDC hdc
, INT iPixelFormat
, UINT nBytes
,
520 LPPIXELFORMATDESCRIPTOR ppfd
)
523 DC
* dc
= DC_GetDCPtr( hdc
);
525 TRACE("(%08x,%d,%d,%p): stub\n",hdc
,iPixelFormat
,nBytes
,ppfd
);
529 if (!dc
->funcs
->pDescribePixelFormat
)
532 ppfd
->nSize
= nBytes
;
536 else ret
= dc
->funcs
->pDescribePixelFormat(dc
->physDev
,iPixelFormat
,nBytes
,ppfd
);
538 GDI_ReleaseObj( hdc
);
543 /******************************************************************************
544 * SwapBuffers [GDI32.@]
545 * Exchanges front and back buffers of window
548 * hdc [I] Device context whose buffers get swapped
552 BOOL WINAPI
SwapBuffers( HDC hdc
)
555 DC
* dc
= DC_GetDCPtr( hdc
);
557 TRACE("(%08x)\n",hdc
);
559 if (!dc
) return TRUE
;
561 if (!dc
->funcs
->pSwapBuffers
)
566 else bRet
= dc
->funcs
->pSwapBuffers(dc
->physDev
);
568 GDI_ReleaseObj( hdc
);
573 /***********************************************************************
576 BOOL16 WINAPI
PaintRgn16( HDC16 hdc
, HRGN16 hrgn
)
578 return PaintRgn( hdc
, hrgn
);
582 /***********************************************************************
585 BOOL WINAPI
PaintRgn( HDC hdc
, HRGN hrgn
)
588 DC
* dc
= DC_GetDCUpdate( hdc
);
591 if (dc
->funcs
->pPaintRgn
) ret
= dc
->funcs
->pPaintRgn(dc
->physDev
,hrgn
);
592 GDI_ReleaseObj( hdc
);
598 /***********************************************************************
601 BOOL16 WINAPI
FillRgn16( HDC16 hdc
, HRGN16 hrgn
, HBRUSH16 hbrush
)
603 return FillRgn( hdc
, hrgn
, hbrush
);
607 /***********************************************************************
610 BOOL WINAPI
FillRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
)
614 DC
* dc
= DC_GetDCUpdate( hdc
);
616 if (!dc
) return FALSE
;
617 if(dc
->funcs
->pFillRgn
)
618 retval
= dc
->funcs
->pFillRgn(dc
->physDev
, hrgn
, hbrush
);
619 else if ((prevBrush
= SelectObject( hdc
, hbrush
)))
621 retval
= PaintRgn( hdc
, hrgn
);
622 SelectObject( hdc
, prevBrush
);
624 GDI_ReleaseObj( hdc
);
629 /***********************************************************************
632 BOOL16 WINAPI
FrameRgn16( HDC16 hdc
, HRGN16 hrgn
, HBRUSH16 hbrush
,
633 INT16 nWidth
, INT16 nHeight
)
635 return FrameRgn( hdc
, hrgn
, hbrush
, nWidth
, nHeight
);
639 /***********************************************************************
642 BOOL WINAPI
FrameRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
,
643 INT nWidth
, INT nHeight
)
646 DC
*dc
= DC_GetDCUpdate( hdc
);
648 if (!dc
) return FALSE
;
649 if(dc
->funcs
->pFrameRgn
)
650 ret
= dc
->funcs
->pFrameRgn( dc
->physDev
, hrgn
, hbrush
, nWidth
, nHeight
);
653 HRGN tmp
= CreateRectRgn( 0, 0, 0, 0 );
656 if (REGION_FrameRgn( tmp
, hrgn
, nWidth
, nHeight
))
658 FillRgn( hdc
, tmp
, hbrush
);
664 GDI_ReleaseObj( hdc
);
669 /***********************************************************************
672 BOOL16 WINAPI
InvertRgn16( HDC16 hdc
, HRGN16 hrgn
)
674 return InvertRgn( hdc
, hrgn
);
678 /***********************************************************************
679 * InvertRgn (GDI32.@)
681 BOOL WINAPI
InvertRgn( HDC hdc
, HRGN hrgn
)
686 DC
*dc
= DC_GetDCUpdate( hdc
);
687 if (!dc
) return FALSE
;
689 if(dc
->funcs
->pInvertRgn
)
690 retval
= dc
->funcs
->pInvertRgn( dc
->physDev
, hrgn
);
693 prevBrush
= SelectObject( hdc
, GetStockObject(BLACK_BRUSH
) );
694 prevROP
= SetROP2( hdc
, R2_NOT
);
695 retval
= PaintRgn( hdc
, hrgn
);
696 SelectObject( hdc
, prevBrush
);
697 SetROP2( hdc
, prevROP
);
699 GDI_ReleaseObj( hdc
);
703 /**********************************************************************
706 BOOL16 WINAPI
Polyline16( HDC16 hdc
, const POINT16
* pt
, INT16 count
)
710 LPPOINT pt32
= (LPPOINT
)HeapAlloc( GetProcessHeap(), 0,
711 count
*sizeof(POINT
) );
713 if (!pt32
) return FALSE
;
714 for (i
=count
;i
--;) CONV_POINT16TO32(&(pt
[i
]),&(pt32
[i
]));
715 ret
= Polyline(hdc
,pt32
,count
);
716 HeapFree( GetProcessHeap(), 0, pt32
);
721 /**********************************************************************
724 BOOL WINAPI
Polyline( HDC hdc
, const POINT
* pt
, INT count
)
727 DC
* dc
= DC_GetDCUpdate( hdc
);
730 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_Polyline(dc
, pt
, count
);
731 else if (dc
->funcs
->pPolyline
) ret
= dc
->funcs
->pPolyline(dc
->physDev
,pt
,count
);
732 GDI_ReleaseObj( hdc
);
737 /**********************************************************************
738 * PolylineTo (GDI32.@)
740 BOOL WINAPI
PolylineTo( HDC hdc
, const POINT
* pt
, DWORD cCount
)
742 DC
* dc
= DC_GetDCUpdate( hdc
);
745 if(!dc
) return FALSE
;
747 if(PATH_IsPathOpen(dc
->path
))
748 ret
= PATH_PolylineTo(dc
, pt
, cCount
);
750 else if(dc
->funcs
->pPolylineTo
)
751 ret
= dc
->funcs
->pPolylineTo(dc
->physDev
, pt
, cCount
);
753 else { /* do it using Polyline */
754 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
755 sizeof(POINT
) * (cCount
+ 1) );
758 pts
[0].x
= dc
->CursPosX
;
759 pts
[0].y
= dc
->CursPosY
;
760 memcpy( pts
+ 1, pt
, sizeof(POINT
) * cCount
);
761 ret
= Polyline( hdc
, pts
, cCount
+ 1 );
762 HeapFree( GetProcessHeap(), 0, pts
);
766 dc
->CursPosX
= pt
[cCount
-1].x
;
767 dc
->CursPosY
= pt
[cCount
-1].y
;
769 GDI_ReleaseObj( hdc
);
773 /**********************************************************************
776 BOOL16 WINAPI
Polygon16( HDC16 hdc
, const POINT16
* pt
, INT16 count
)
780 LPPOINT pt32
= (LPPOINT
)HeapAlloc( GetProcessHeap(), 0,
781 count
*sizeof(POINT
) );
783 if (!pt32
) return FALSE
;
784 for (i
=count
;i
--;) CONV_POINT16TO32(&(pt
[i
]),&(pt32
[i
]));
785 ret
= Polygon(hdc
,pt32
,count
);
786 HeapFree( GetProcessHeap(), 0, pt32
);
791 /**********************************************************************
794 BOOL WINAPI
Polygon( HDC hdc
, const POINT
* pt
, INT count
)
797 DC
* dc
= DC_GetDCUpdate( hdc
);
800 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_Polygon(dc
, pt
, count
);
801 else if (dc
->funcs
->pPolygon
) ret
= dc
->funcs
->pPolygon(dc
->physDev
,pt
,count
);
802 GDI_ReleaseObj( hdc
);
808 /**********************************************************************
809 * PolyPolygon (GDI.450)
811 BOOL16 WINAPI
PolyPolygon16( HDC16 hdc
, const POINT16
* pt
, const INT16
* counts
,
820 for (i
=polygons
;i
--;)
822 pt32
= (LPPOINT
)HeapAlloc( GetProcessHeap(), 0, sizeof(POINT
)*nrpts
);
823 if(pt32
== NULL
) return FALSE
;
825 CONV_POINT16TO32(&(pt
[i
]),&(pt32
[i
]));
826 counts32
= (LPINT
)HeapAlloc( GetProcessHeap(), 0, polygons
*sizeof(INT
) );
827 if(counts32
== NULL
) {
828 HeapFree( GetProcessHeap(), 0, pt32
);
831 for (i
=polygons
;i
--;) counts32
[i
]=counts
[i
];
833 ret
= PolyPolygon(hdc
,pt32
,counts32
,polygons
);
834 HeapFree( GetProcessHeap(), 0, counts32
);
835 HeapFree( GetProcessHeap(), 0, pt32
);
839 /**********************************************************************
840 * PolyPolygon (GDI32.@)
842 BOOL WINAPI
PolyPolygon( HDC hdc
, const POINT
* pt
, const INT
* counts
,
846 DC
* dc
= DC_GetDCUpdate( hdc
);
849 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_PolyPolygon(dc
, pt
, counts
, polygons
);
850 else if (dc
->funcs
->pPolyPolygon
) ret
= dc
->funcs
->pPolyPolygon(dc
->physDev
,pt
,counts
,polygons
);
851 GDI_ReleaseObj( hdc
);
856 /**********************************************************************
857 * PolyPolyline (GDI32.@)
859 BOOL WINAPI
PolyPolyline( HDC hdc
, const POINT
* pt
, const DWORD
* counts
,
863 DC
* dc
= DC_GetDCUpdate( hdc
);
866 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_PolyPolyline(dc
, pt
, counts
, polylines
);
867 else if (dc
->funcs
->pPolyPolyline
) ret
= dc
->funcs
->pPolyPolyline(dc
->physDev
,pt
,counts
,polylines
);
868 GDI_ReleaseObj( hdc
);
873 /**********************************************************************
874 * ExtFloodFill (GDI.372)
876 BOOL16 WINAPI
ExtFloodFill16( HDC16 hdc
, INT16 x
, INT16 y
, COLORREF color
,
879 return ExtFloodFill( hdc
, x
, y
, color
, fillType
);
883 /**********************************************************************
884 * ExtFloodFill (GDI32.@)
886 BOOL WINAPI
ExtFloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
,
890 DC
* dc
= DC_GetDCUpdate( hdc
);
893 if (dc
->funcs
->pExtFloodFill
) ret
= dc
->funcs
->pExtFloodFill(dc
->physDev
,x
,y
,color
,fillType
);
894 GDI_ReleaseObj( hdc
);
900 /**********************************************************************
903 BOOL16 WINAPI
FloodFill16( HDC16 hdc
, INT16 x
, INT16 y
, COLORREF color
)
905 return ExtFloodFill( hdc
, x
, y
, color
, FLOODFILLBORDER
);
909 /**********************************************************************
910 * FloodFill (GDI32.@)
912 BOOL WINAPI
FloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
)
914 return ExtFloodFill( hdc
, x
, y
, color
, FLOODFILLBORDER
);
918 /******************************************************************************
919 * PolyBezier [GDI.502]
921 BOOL16 WINAPI
PolyBezier16( HDC16 hDc
, const POINT16
* lppt
, INT16 cPoints
)
925 LPPOINT pt32
= (LPPOINT
)HeapAlloc( GetProcessHeap(), 0,
926 cPoints
*sizeof(POINT
) );
927 if(!pt32
) return FALSE
;
928 for (i
=cPoints
;i
--;) CONV_POINT16TO32(&(lppt
[i
]),&(pt32
[i
]));
929 ret
= PolyBezier(hDc
, pt32
, cPoints
);
930 HeapFree( GetProcessHeap(), 0, pt32
);
934 /******************************************************************************
935 * PolyBezierTo [GDI.503]
937 BOOL16 WINAPI
PolyBezierTo16( HDC16 hDc
, const POINT16
* lppt
, INT16 cPoints
)
941 LPPOINT pt32
= (LPPOINT
)HeapAlloc( GetProcessHeap(), 0,
942 cPoints
*sizeof(POINT
) );
943 if(!pt32
) return FALSE
;
944 for (i
=cPoints
;i
--;) CONV_POINT16TO32(&(lppt
[i
]),&(pt32
[i
]));
945 ret
= PolyBezierTo(hDc
, pt32
, cPoints
);
946 HeapFree( GetProcessHeap(), 0, pt32
);
950 /******************************************************************************
951 * PolyBezier [GDI32.@]
952 * Draws one or more Bezier curves
955 * hDc [I] Handle to device context
956 * lppt [I] Pointer to endpoints and control points
957 * cPoints [I] Count of endpoints and control points
961 BOOL WINAPI
PolyBezier( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
964 DC
* dc
= DC_GetDCUpdate( hdc
);
966 if(!dc
) return FALSE
;
968 if(PATH_IsPathOpen(dc
->path
))
969 ret
= PATH_PolyBezier(dc
, lppt
, cPoints
);
970 else if (dc
->funcs
->pPolyBezier
)
971 ret
= dc
->funcs
->pPolyBezier(dc
->physDev
, lppt
, cPoints
);
972 else /* We'll convert it into line segments and draw them using Polyline */
977 if ((Pts
= GDI_Bezier( lppt
, cPoints
, &nOut
)))
979 TRACE("Pts = %p, no = %d\n", Pts
, nOut
);
980 ret
= Polyline( dc
->hSelf
, Pts
, nOut
);
981 HeapFree( GetProcessHeap(), 0, Pts
);
985 GDI_ReleaseObj( hdc
);
989 /******************************************************************************
990 * PolyBezierTo [GDI32.@]
991 * Draws one or more Bezier curves
994 * hDc [I] Handle to device context
995 * lppt [I] Pointer to endpoints and control points
996 * cPoints [I] Count of endpoints and control points
1000 BOOL WINAPI
PolyBezierTo( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
1002 DC
* dc
= DC_GetDCUpdate( hdc
);
1005 if(!dc
) return FALSE
;
1007 if(PATH_IsPathOpen(dc
->path
))
1008 ret
= PATH_PolyBezierTo(dc
, lppt
, cPoints
);
1009 else if(dc
->funcs
->pPolyBezierTo
)
1010 ret
= dc
->funcs
->pPolyBezierTo(dc
->physDev
, lppt
, cPoints
);
1011 else { /* We'll do it using PolyBezier */
1013 pt
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINT
) * (cPoints
+ 1) );
1014 if(!pt
) return FALSE
;
1015 pt
[0].x
= dc
->CursPosX
;
1016 pt
[0].y
= dc
->CursPosY
;
1017 memcpy(pt
+ 1, lppt
, sizeof(POINT
) * cPoints
);
1018 ret
= PolyBezier(dc
->hSelf
, pt
, cPoints
+1);
1019 HeapFree( GetProcessHeap(), 0, pt
);
1022 dc
->CursPosX
= lppt
[cPoints
-1].x
;
1023 dc
->CursPosY
= lppt
[cPoints
-1].y
;
1025 GDI_ReleaseObj( hdc
);
1029 /***********************************************************************
1030 * AngleArc (GDI32.@)
1032 BOOL WINAPI
AngleArc(HDC hdc
, INT x
, INT y
, DWORD dwRadius
, FLOAT eStartAngle
, FLOAT eSweepAngle
)
1034 INT x1
,y1
,x2
,y2
, arcdir
;
1038 if( (signed int)dwRadius
< 0 )
1041 dc
= DC_GetDCUpdate( hdc
);
1042 if(!dc
) return FALSE
;
1044 if(dc
->funcs
->pAngleArc
)
1046 result
= dc
->funcs
->pAngleArc( dc
->physDev
, x
, y
, dwRadius
, eStartAngle
, eSweepAngle
);
1048 GDI_ReleaseObj( hdc
);
1051 GDI_ReleaseObj( hdc
);
1053 /* AngleArc always works counterclockwise */
1054 arcdir
= GetArcDirection( hdc
);
1055 SetArcDirection( hdc
, AD_COUNTERCLOCKWISE
);
1057 x1
= x
+ cos(eStartAngle
*M_PI
/180) * dwRadius
;
1058 y1
= y
- sin(eStartAngle
*M_PI
/180) * dwRadius
;
1059 x2
= x
+ cos((eStartAngle
+eSweepAngle
)*M_PI
/180) * dwRadius
;
1060 y2
= x
- sin((eStartAngle
+eSweepAngle
)*M_PI
/180) * dwRadius
;
1062 LineTo( hdc
, x1
, y1
);
1063 if( eSweepAngle
>= 0 )
1064 result
= Arc( hdc
, x
-dwRadius
, y
-dwRadius
, x
+dwRadius
, y
+dwRadius
,
1067 result
= Arc( hdc
, x
-dwRadius
, y
-dwRadius
, x
+dwRadius
, y
+dwRadius
,
1070 if( result
) MoveToEx( hdc
, x2
, y2
, NULL
);
1071 SetArcDirection( hdc
, arcdir
);
1075 /***********************************************************************
1076 * PolyDraw (GDI32.@)
1078 BOOL WINAPI
PolyDraw(HDC hdc
, const POINT
*lppt
, const BYTE
*lpbTypes
,
1086 dc
= DC_GetDCUpdate( hdc
);
1087 if(!dc
) return FALSE
;
1089 if(dc
->funcs
->pPolyDraw
)
1091 result
= dc
->funcs
->pPolyDraw( dc
->physDev
, lppt
, lpbTypes
, cCount
);
1092 GDI_ReleaseObj( hdc
);
1095 GDI_ReleaseObj( hdc
);
1097 /* check for each bezierto if there are two more points */
1098 for( i
= 0; i
< cCount
; i
++ )
1099 if( lpbTypes
[i
] != PT_MOVETO
&&
1100 lpbTypes
[i
] & PT_BEZIERTO
)
1108 /* if no moveto occurs, we will close the figure here */
1109 lastmove
.x
= dc
->CursPosX
;
1110 lastmove
.y
= dc
->CursPosY
;
1112 /* now let's draw */
1113 for( i
= 0; i
< cCount
; i
++ )
1115 if( lpbTypes
[i
] == PT_MOVETO
)
1117 MoveToEx( hdc
, lppt
[i
].x
, lppt
[i
].y
, NULL
);
1118 lastmove
.x
= dc
->CursPosX
;
1119 lastmove
.y
= dc
->CursPosY
;
1121 else if( lpbTypes
[i
] & PT_LINETO
)
1122 LineTo( hdc
, lppt
[i
].x
, lppt
[i
].y
);
1123 else if( lpbTypes
[i
] & PT_BEZIERTO
)
1125 PolyBezierTo( hdc
, &lppt
[i
], 3 );
1131 if( lpbTypes
[i
] & PT_CLOSEFIGURE
)
1133 if( PATH_IsPathOpen( dc
->path
) )
1136 LineTo( hdc
, lastmove
.x
, lastmove
.y
);
1143 /******************************************************************
1145 * *Very* simple bezier drawing code,
1147 * It uses a recursive algorithm to divide the curve in a series
1148 * of straight line segements. Not ideal but for me sufficient.
1149 * If you are in need for something better look for some incremental
1152 * 7 July 1998 Rein Klazes
1156 * some macro definitions for bezier drawing
1158 * to avoid trucation errors the coordinates are
1159 * shifted upwards. When used in drawing they are
1160 * shifted down again, including correct rounding
1161 * and avoiding floating point arithmatic
1162 * 4 bits should allow 27 bits coordinates which I saw
1163 * somewere in the win32 doc's
1167 #define BEZIERSHIFTBITS 4
1168 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
1169 #define BEZIERPIXEL BEZIERSHIFTUP(1)
1170 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
1171 /* maximum depth of recursion */
1172 #define BEZIERMAXDEPTH 8
1174 /* size of array to store points on */
1175 /* enough for one curve */
1176 #define BEZIER_INITBUFSIZE (150)
1178 /* calculate Bezier average, in this case the middle
1179 * correctly rounded...
1182 #define BEZIERMIDDLE(Mid, P1, P2) \
1183 (Mid).x=((P1).x+(P2).x + 1)/2;\
1184 (Mid).y=((P1).y+(P2).y + 1)/2;
1186 /**********************************************************
1187 * BezierCheck helper function to check
1188 * that recursion can be terminated
1189 * Points[0] and Points[3] are begin and endpoint
1190 * Points[1] and Points[2] are control points
1191 * level is the recursion depth
1192 * returns true if the recusion can be terminated
1194 static BOOL
BezierCheck( int level
, POINT
*Points
)
1197 dx
=Points
[3].x
-Points
[0].x
;
1198 dy
=Points
[3].y
-Points
[0].y
;
1199 if(abs(dy
)<=abs(dx
)){/* shallow line */
1200 /* check that control points are between begin and end */
1201 if(Points
[1].x
< Points
[0].x
){
1202 if(Points
[1].x
< Points
[3].x
)
1205 if(Points
[1].x
> Points
[3].x
)
1207 if(Points
[2].x
< Points
[0].x
){
1208 if(Points
[2].x
< Points
[3].x
)
1211 if(Points
[2].x
> Points
[3].x
)
1213 dx
=BEZIERSHIFTDOWN(dx
);
1214 if(!dx
) return TRUE
;
1215 if(abs(Points
[1].y
-Points
[0].y
-(dy
/dx
)*
1216 BEZIERSHIFTDOWN(Points
[1].x
-Points
[0].x
)) > BEZIERPIXEL
||
1217 abs(Points
[2].y
-Points
[0].y
-(dy
/dx
)*
1218 BEZIERSHIFTDOWN(Points
[2].x
-Points
[0].x
)) > BEZIERPIXEL
)
1222 }else{ /* steep line */
1223 /* check that control points are between begin and end */
1224 if(Points
[1].y
< Points
[0].y
){
1225 if(Points
[1].y
< Points
[3].y
)
1228 if(Points
[1].y
> Points
[3].y
)
1230 if(Points
[2].y
< Points
[0].y
){
1231 if(Points
[2].y
< Points
[3].y
)
1234 if(Points
[2].y
> Points
[3].y
)
1236 dy
=BEZIERSHIFTDOWN(dy
);
1237 if(!dy
) return TRUE
;
1238 if(abs(Points
[1].x
-Points
[0].x
-(dx
/dy
)*
1239 BEZIERSHIFTDOWN(Points
[1].y
-Points
[0].y
)) > BEZIERPIXEL
||
1240 abs(Points
[2].x
-Points
[0].x
-(dx
/dy
)*
1241 BEZIERSHIFTDOWN(Points
[2].y
-Points
[0].y
)) > BEZIERPIXEL
)
1248 /* Helper for GDI_Bezier.
1249 * Just handles one Bezier, so Points should point to four POINTs
1251 static void GDI_InternalBezier( POINT
*Points
, POINT
**PtsOut
, INT
*dwOut
,
1252 INT
*nPtsOut
, INT level
)
1254 if(*nPtsOut
== *dwOut
) {
1256 *PtsOut
= HeapReAlloc( GetProcessHeap(), 0, *PtsOut
,
1257 *dwOut
* sizeof(POINT
) );
1260 if(!level
|| BezierCheck(level
, Points
)) {
1262 (*PtsOut
)[0].x
= BEZIERSHIFTDOWN(Points
[0].x
);
1263 (*PtsOut
)[0].y
= BEZIERSHIFTDOWN(Points
[0].y
);
1266 (*PtsOut
)[*nPtsOut
].x
= BEZIERSHIFTDOWN(Points
[3].x
);
1267 (*PtsOut
)[*nPtsOut
].y
= BEZIERSHIFTDOWN(Points
[3].y
);
1270 POINT Points2
[4]; /* for the second recursive call */
1271 Points2
[3]=Points
[3];
1272 BEZIERMIDDLE(Points2
[2], Points
[2], Points
[3]);
1273 BEZIERMIDDLE(Points2
[0], Points
[1], Points
[2]);
1274 BEZIERMIDDLE(Points2
[1],Points2
[0],Points2
[2]);
1276 BEZIERMIDDLE(Points
[1], Points
[0], Points
[1]);
1277 BEZIERMIDDLE(Points
[2], Points
[1], Points2
[0]);
1278 BEZIERMIDDLE(Points
[3], Points
[2], Points2
[1]);
1280 Points2
[0]=Points
[3];
1282 /* do the two halves */
1283 GDI_InternalBezier(Points
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1284 GDI_InternalBezier(Points2
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1290 /***********************************************************************
1291 * GDI_Bezier [INTERNAL]
1292 * Calculate line segments that approximate -what microsoft calls- a bezier
1294 * The routine recursively divides the curve in two parts until a straight
1299 * Points [I] Ptr to count POINTs which are the end and control points
1300 * of the set of Bezier curves to flatten.
1301 * count [I] Number of Points. Must be 3n+1.
1302 * nPtsOut [O] Will contain no of points that have been produced (i.e. no. of
1307 * Ptr to an array of POINTs that contain the lines that approximinate the
1308 * Beziers. The array is allocated on the process heap and it is the caller's
1309 * responsibility to HeapFree it. [this is not a particularly nice interface
1310 * but since we can't know in advance how many points will generate, the
1311 * alternative would be to call the function twice, once to determine the size
1312 * and a second time to do the work - I decided this was too much of a pain].
1314 POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
)
1317 INT Bezier
, dwOut
= BEZIER_INITBUFSIZE
, i
;
1319 if((count
- 1) % 3 != 0) {
1320 ERR("Invalid no. of points\n");
1324 out
= HeapAlloc( GetProcessHeap(), 0, dwOut
* sizeof(POINT
));
1325 for(Bezier
= 0; Bezier
< (count
-1)/3; Bezier
++) {
1327 memcpy(ptBuf
, Points
+ Bezier
* 3, sizeof(POINT
) * 4);
1328 for(i
= 0; i
< 4; i
++) {
1329 ptBuf
[i
].x
= BEZIERSHIFTUP(ptBuf
[i
].x
);
1330 ptBuf
[i
].y
= BEZIERSHIFTUP(ptBuf
[i
].y
);
1332 GDI_InternalBezier( ptBuf
, &out
, &dwOut
, nPtsOut
, BEZIERMAXDEPTH
);
1334 TRACE("Produced %d points\n", *nPtsOut
);