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
24 #include "wine/port.h"
36 #include "gdi_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
42 /***********************************************************************
45 BOOL WINAPI
LineTo( HDC hdc
, INT x
, INT y
)
47 DC
* dc
= DC_GetDCUpdate( hdc
);
52 if(PATH_IsPathOpen(dc
->path
))
53 ret
= PATH_LineTo(dc
, x
, y
);
55 ret
= dc
->funcs
->pLineTo
&& dc
->funcs
->pLineTo(dc
->physDev
,x
,y
);
60 GDI_ReleaseObj( hdc
);
65 /***********************************************************************
68 BOOL WINAPI
MoveToEx( HDC hdc
, INT x
, INT y
, LPPOINT pt
)
71 DC
* dc
= DC_GetDCPtr( hdc
);
82 if(PATH_IsPathOpen(dc
->path
)) ret
= PATH_MoveTo(dc
);
83 else if (dc
->funcs
->pMoveTo
) ret
= dc
->funcs
->pMoveTo(dc
->physDev
,x
,y
);
84 GDI_ReleaseObj( hdc
);
89 /***********************************************************************
92 BOOL WINAPI
Arc( HDC hdc
, INT left
, INT top
, INT right
,
93 INT bottom
, INT xstart
, INT ystart
,
97 DC
* dc
= DC_GetDCUpdate( hdc
);
100 if(PATH_IsPathOpen(dc
->path
))
101 ret
= PATH_Arc(dc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
,0);
102 else if (dc
->funcs
->pArc
)
103 ret
= dc
->funcs
->pArc(dc
->physDev
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
);
104 GDI_ReleaseObj( hdc
);
109 /***********************************************************************
112 BOOL WINAPI
ArcTo( HDC hdc
,
114 INT right
, INT bottom
,
115 INT xstart
, INT ystart
,
119 DC
* dc
= DC_GetDCUpdate( hdc
);
120 if(!dc
) return FALSE
;
122 if(dc
->funcs
->pArcTo
)
124 result
= dc
->funcs
->pArcTo( dc
->physDev
, left
, top
, right
, bottom
,
125 xstart
, ystart
, xend
, yend
);
126 GDI_ReleaseObj( hdc
);
129 GDI_ReleaseObj( hdc
);
132 * According to the documentation, a line is drawn from the current
133 * position to the starting point of the arc.
135 LineTo(hdc
, xstart
, ystart
);
137 * Then the arc is drawn.
139 result
= Arc(hdc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
141 * If no error occurred, the current position is moved to the ending
144 if (result
) MoveToEx(hdc
, xend
, yend
, NULL
);
149 /***********************************************************************
152 BOOL WINAPI
Pie( HDC hdc
, INT left
, INT top
,
153 INT right
, INT bottom
, INT xstart
, INT ystart
,
157 DC
* dc
= DC_GetDCUpdate( hdc
);
158 if (!dc
) return FALSE
;
160 if(PATH_IsPathOpen(dc
->path
))
161 ret
= PATH_Arc(dc
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
,2);
162 else if(dc
->funcs
->pPie
)
163 ret
= dc
->funcs
->pPie(dc
->physDev
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
);
165 GDI_ReleaseObj( hdc
);
170 /***********************************************************************
173 BOOL WINAPI
Chord( HDC hdc
, INT left
, INT top
,
174 INT right
, INT bottom
, INT xstart
, INT ystart
,
178 DC
* dc
= DC_GetDCUpdate( hdc
);
179 if (!dc
) return FALSE
;
181 if(PATH_IsPathOpen(dc
->path
))
182 ret
= PATH_Arc(dc
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
,1);
183 else if(dc
->funcs
->pChord
)
184 ret
= dc
->funcs
->pChord(dc
->physDev
,left
,top
,right
,bottom
,xstart
,ystart
,xend
,yend
);
186 GDI_ReleaseObj( hdc
);
191 /***********************************************************************
194 BOOL WINAPI
Ellipse( HDC hdc
, INT left
, INT top
,
195 INT right
, INT bottom
)
198 DC
* dc
= DC_GetDCUpdate( hdc
);
199 if (!dc
) return FALSE
;
201 if(PATH_IsPathOpen(dc
->path
))
202 ret
= PATH_Ellipse(dc
,left
,top
,right
,bottom
);
203 else if (dc
->funcs
->pEllipse
)
204 ret
= dc
->funcs
->pEllipse(dc
->physDev
,left
,top
,right
,bottom
);
206 GDI_ReleaseObj( hdc
);
211 /***********************************************************************
212 * Rectangle (GDI32.@)
214 BOOL WINAPI
Rectangle( HDC hdc
, INT left
, INT top
,
215 INT right
, INT bottom
)
218 DC
* dc
= DC_GetDCUpdate( hdc
);
221 if(PATH_IsPathOpen(dc
->path
))
222 ret
= PATH_Rectangle(dc
, left
, top
, right
, bottom
);
223 else if (dc
->funcs
->pRectangle
)
224 ret
= dc
->funcs
->pRectangle(dc
->physDev
,left
,top
,right
,bottom
);
225 GDI_ReleaseObj( hdc
);
231 /***********************************************************************
232 * RoundRect (GDI32.@)
234 BOOL WINAPI
RoundRect( HDC hdc
, INT left
, INT top
, INT right
,
235 INT bottom
, INT ell_width
, INT ell_height
)
238 DC
*dc
= DC_GetDCUpdate( hdc
);
242 if(PATH_IsPathOpen(dc
->path
))
243 ret
= PATH_RoundRect(dc
,left
,top
,right
,bottom
,ell_width
,ell_height
);
244 else if (dc
->funcs
->pRoundRect
)
245 ret
= dc
->funcs
->pRoundRect(dc
->physDev
,left
,top
,right
,bottom
,ell_width
,ell_height
);
246 GDI_ReleaseObj( hdc
);
251 /***********************************************************************
254 COLORREF WINAPI
SetPixel( HDC hdc
, INT x
, INT y
, COLORREF color
)
257 DC
* dc
= DC_GetDCUpdate( hdc
);
260 if (dc
->funcs
->pSetPixel
) ret
= dc
->funcs
->pSetPixel(dc
->physDev
,x
,y
,color
);
261 GDI_ReleaseObj( hdc
);
266 /***********************************************************************
267 * SetPixelV (GDI32.@)
269 BOOL WINAPI
SetPixelV( HDC hdc
, INT x
, INT y
, COLORREF color
)
272 DC
* dc
= DC_GetDCUpdate( hdc
);
275 if (dc
->funcs
->pSetPixel
)
277 dc
->funcs
->pSetPixel(dc
->physDev
,x
,y
,color
);
280 GDI_ReleaseObj( hdc
);
285 /***********************************************************************
288 COLORREF WINAPI
GetPixel( HDC hdc
, INT x
, INT y
)
290 COLORREF ret
= CLR_INVALID
;
291 DC
* dc
= DC_GetDCUpdate( hdc
);
295 /* FIXME: should this be in the graphics driver? */
296 if (PtVisible( hdc
, x
, y
))
298 if (dc
->funcs
->pGetPixel
) ret
= dc
->funcs
->pGetPixel(dc
->physDev
,x
,y
);
300 GDI_ReleaseObj( hdc
);
306 /******************************************************************************
307 * ChoosePixelFormat [GDI32.@]
308 * Matches a pixel format to given format
311 * hdc [I] Device context to search for best pixel match
312 * ppfd [I] Pixel format for which a match is sought
315 * Success: Pixel format index closest to given format
318 INT WINAPI
ChoosePixelFormat( HDC hdc
, const LPPIXELFORMATDESCRIPTOR ppfd
)
321 DC
* dc
= DC_GetDCPtr( hdc
);
323 TRACE("(%p,%p)\n",hdc
,ppfd
);
327 if (!dc
->funcs
->pChoosePixelFormat
) FIXME(" :stub\n");
328 else ret
= dc
->funcs
->pChoosePixelFormat(dc
->physDev
,ppfd
);
330 GDI_ReleaseObj( hdc
);
335 /******************************************************************************
336 * SetPixelFormat [GDI32.@]
337 * Sets pixel format of device context
340 * hdc [I] Device context to search for best pixel match
341 * iPixelFormat [I] Pixel format index
342 * ppfd [I] Pixel format for which a match is sought
346 BOOL WINAPI
SetPixelFormat( HDC hdc
, INT iPixelFormat
,
347 const PIXELFORMATDESCRIPTOR
*ppfd
)
350 DC
* dc
= DC_GetDCPtr( hdc
);
352 TRACE("(%p,%d,%p)\n",hdc
,iPixelFormat
,ppfd
);
356 if (!dc
->funcs
->pSetPixelFormat
) FIXME(" :stub\n");
357 else bRet
= dc
->funcs
->pSetPixelFormat(dc
->physDev
,iPixelFormat
,ppfd
);
359 GDI_ReleaseObj( hdc
);
364 /******************************************************************************
365 * GetPixelFormat [GDI32.@]
366 * Gets index of pixel format of DC
369 * hdc [I] Device context whose pixel format index is sought
372 * Success: Currently selected pixel format
375 INT WINAPI
GetPixelFormat( HDC hdc
)
378 DC
* dc
= DC_GetDCPtr( hdc
);
384 if (!dc
->funcs
->pGetPixelFormat
) FIXME(" :stub\n");
385 else ret
= dc
->funcs
->pGetPixelFormat(dc
->physDev
);
387 GDI_ReleaseObj( hdc
);
392 /******************************************************************************
393 * DescribePixelFormat [GDI32.@]
394 * Gets info about pixel format from DC
397 * hdc [I] Device context
398 * iPixelFormat [I] Pixel format selector
399 * nBytes [I] Size of buffer
400 * ppfd [O] Pointer to structure to receive pixel format data
403 * Success: Maximum pixel format index of the device context
406 INT WINAPI
DescribePixelFormat( HDC hdc
, INT iPixelFormat
, UINT nBytes
,
407 LPPIXELFORMATDESCRIPTOR ppfd
)
410 DC
* dc
= DC_GetDCPtr( hdc
);
412 TRACE("(%p,%d,%d,%p): stub\n",hdc
,iPixelFormat
,nBytes
,ppfd
);
416 if (!dc
->funcs
->pDescribePixelFormat
)
419 ppfd
->nSize
= nBytes
;
423 else ret
= dc
->funcs
->pDescribePixelFormat(dc
->physDev
,iPixelFormat
,nBytes
,ppfd
);
425 GDI_ReleaseObj( hdc
);
430 /******************************************************************************
431 * SwapBuffers [GDI32.@]
432 * Exchanges front and back buffers of window
435 * hdc [I] Device context whose buffers get swapped
439 BOOL WINAPI
SwapBuffers( HDC hdc
)
442 DC
* dc
= DC_GetDCPtr( hdc
);
446 if (!dc
) return TRUE
;
448 if (!dc
->funcs
->pSwapBuffers
)
453 else bRet
= dc
->funcs
->pSwapBuffers(dc
->physDev
);
455 GDI_ReleaseObj( hdc
);
460 /***********************************************************************
463 BOOL WINAPI
PaintRgn( HDC hdc
, HRGN hrgn
)
466 DC
* dc
= DC_GetDCUpdate( hdc
);
469 if (dc
->funcs
->pPaintRgn
) ret
= dc
->funcs
->pPaintRgn(dc
->physDev
,hrgn
);
470 GDI_ReleaseObj( hdc
);
476 /***********************************************************************
479 BOOL WINAPI
FillRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
)
483 DC
* dc
= DC_GetDCUpdate( hdc
);
485 if (!dc
) return FALSE
;
486 if(dc
->funcs
->pFillRgn
)
487 retval
= dc
->funcs
->pFillRgn(dc
->physDev
, hrgn
, hbrush
);
488 else if ((prevBrush
= SelectObject( hdc
, hbrush
)))
490 retval
= PaintRgn( hdc
, hrgn
);
491 SelectObject( hdc
, prevBrush
);
493 GDI_ReleaseObj( hdc
);
498 /***********************************************************************
501 BOOL WINAPI
FrameRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
,
502 INT nWidth
, INT nHeight
)
505 DC
*dc
= DC_GetDCUpdate( hdc
);
507 if (!dc
) return FALSE
;
508 if(dc
->funcs
->pFrameRgn
)
509 ret
= dc
->funcs
->pFrameRgn( dc
->physDev
, hrgn
, hbrush
, nWidth
, nHeight
);
512 HRGN tmp
= CreateRectRgn( 0, 0, 0, 0 );
515 if (REGION_FrameRgn( tmp
, hrgn
, nWidth
, nHeight
))
517 FillRgn( hdc
, tmp
, hbrush
);
523 GDI_ReleaseObj( hdc
);
528 /***********************************************************************
529 * InvertRgn (GDI32.@)
531 BOOL WINAPI
InvertRgn( HDC hdc
, HRGN hrgn
)
536 DC
*dc
= DC_GetDCUpdate( hdc
);
537 if (!dc
) return FALSE
;
539 if(dc
->funcs
->pInvertRgn
)
540 retval
= dc
->funcs
->pInvertRgn( dc
->physDev
, hrgn
);
543 prevBrush
= SelectObject( hdc
, GetStockObject(BLACK_BRUSH
) );
544 prevROP
= SetROP2( hdc
, R2_NOT
);
545 retval
= PaintRgn( hdc
, hrgn
);
546 SelectObject( hdc
, prevBrush
);
547 SetROP2( hdc
, prevROP
);
549 GDI_ReleaseObj( hdc
);
554 /**********************************************************************
557 BOOL WINAPI
Polyline( HDC hdc
, const POINT
* pt
, INT count
)
560 DC
* dc
= DC_GetDCUpdate( hdc
);
563 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_Polyline(dc
, pt
, count
);
564 else if (dc
->funcs
->pPolyline
) ret
= dc
->funcs
->pPolyline(dc
->physDev
,pt
,count
);
565 GDI_ReleaseObj( hdc
);
570 /**********************************************************************
571 * PolylineTo (GDI32.@)
573 BOOL WINAPI
PolylineTo( HDC hdc
, const POINT
* pt
, DWORD cCount
)
575 DC
* dc
= DC_GetDCUpdate( hdc
);
578 if(!dc
) return FALSE
;
580 if(PATH_IsPathOpen(dc
->path
))
581 ret
= PATH_PolylineTo(dc
, pt
, cCount
);
583 else if(dc
->funcs
->pPolylineTo
)
584 ret
= dc
->funcs
->pPolylineTo(dc
->physDev
, pt
, cCount
);
586 else { /* do it using Polyline */
587 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0,
588 sizeof(POINT
) * (cCount
+ 1) );
591 pts
[0].x
= dc
->CursPosX
;
592 pts
[0].y
= dc
->CursPosY
;
593 memcpy( pts
+ 1, pt
, sizeof(POINT
) * cCount
);
594 ret
= Polyline( hdc
, pts
, cCount
+ 1 );
595 HeapFree( GetProcessHeap(), 0, pts
);
599 dc
->CursPosX
= pt
[cCount
-1].x
;
600 dc
->CursPosY
= pt
[cCount
-1].y
;
602 GDI_ReleaseObj( hdc
);
607 /**********************************************************************
610 BOOL WINAPI
Polygon( HDC hdc
, const POINT
* pt
, INT count
)
613 DC
* dc
= DC_GetDCUpdate( hdc
);
616 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_Polygon(dc
, pt
, count
);
617 else if (dc
->funcs
->pPolygon
) ret
= dc
->funcs
->pPolygon(dc
->physDev
,pt
,count
);
618 GDI_ReleaseObj( hdc
);
624 /**********************************************************************
625 * PolyPolygon (GDI32.@)
627 BOOL WINAPI
PolyPolygon( HDC hdc
, const POINT
* pt
, const INT
* counts
,
631 DC
* dc
= DC_GetDCUpdate( hdc
);
634 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_PolyPolygon(dc
, pt
, counts
, polygons
);
635 else if (dc
->funcs
->pPolyPolygon
) ret
= dc
->funcs
->pPolyPolygon(dc
->physDev
,pt
,counts
,polygons
);
636 GDI_ReleaseObj( hdc
);
641 /**********************************************************************
642 * PolyPolyline (GDI32.@)
644 BOOL WINAPI
PolyPolyline( HDC hdc
, const POINT
* pt
, const DWORD
* counts
,
648 DC
* dc
= DC_GetDCUpdate( hdc
);
651 if (PATH_IsPathOpen(dc
->path
)) ret
= PATH_PolyPolyline(dc
, pt
, counts
, polylines
);
652 else if (dc
->funcs
->pPolyPolyline
) ret
= dc
->funcs
->pPolyPolyline(dc
->physDev
,pt
,counts
,polylines
);
653 GDI_ReleaseObj( hdc
);
658 /**********************************************************************
659 * ExtFloodFill (GDI32.@)
661 BOOL WINAPI
ExtFloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
,
665 DC
* dc
= DC_GetDCUpdate( hdc
);
668 if (dc
->funcs
->pExtFloodFill
) ret
= dc
->funcs
->pExtFloodFill(dc
->physDev
,x
,y
,color
,fillType
);
669 GDI_ReleaseObj( hdc
);
675 /**********************************************************************
676 * FloodFill (GDI32.@)
678 BOOL WINAPI
FloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
)
680 return ExtFloodFill( hdc
, x
, y
, color
, FLOODFILLBORDER
);
684 /******************************************************************************
685 * PolyBezier [GDI32.@]
686 * Draws one or more Bezier curves
689 * hDc [I] Handle to device context
690 * lppt [I] Pointer to endpoints and control points
691 * cPoints [I] Count of endpoints and control points
695 BOOL WINAPI
PolyBezier( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
700 /* cPoints must be 3 * n + 1 (where n>=1) */
701 if (cPoints
== 1 || (cPoints
% 3) != 1) return FALSE
;
703 dc
= DC_GetDCUpdate( hdc
);
704 if(!dc
) return FALSE
;
706 if(PATH_IsPathOpen(dc
->path
))
707 ret
= PATH_PolyBezier(dc
, lppt
, cPoints
);
708 else if (dc
->funcs
->pPolyBezier
)
709 ret
= dc
->funcs
->pPolyBezier(dc
->physDev
, lppt
, cPoints
);
710 else /* We'll convert it into line segments and draw them using Polyline */
715 if ((Pts
= GDI_Bezier( lppt
, cPoints
, &nOut
)))
717 TRACE("Pts = %p, no = %d\n", Pts
, nOut
);
718 ret
= Polyline( dc
->hSelf
, Pts
, nOut
);
719 HeapFree( GetProcessHeap(), 0, Pts
);
723 GDI_ReleaseObj( hdc
);
727 /******************************************************************************
728 * PolyBezierTo [GDI32.@]
729 * Draws one or more Bezier curves
732 * hDc [I] Handle to device context
733 * lppt [I] Pointer to endpoints and control points
734 * cPoints [I] Count of endpoints and control points
738 BOOL WINAPI
PolyBezierTo( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
740 DC
* dc
= DC_GetDCUpdate( hdc
);
743 if(!dc
) return FALSE
;
745 if(PATH_IsPathOpen(dc
->path
))
746 ret
= PATH_PolyBezierTo(dc
, lppt
, cPoints
);
747 else if(dc
->funcs
->pPolyBezierTo
)
748 ret
= dc
->funcs
->pPolyBezierTo(dc
->physDev
, lppt
, cPoints
);
749 else { /* We'll do it using PolyBezier */
751 pt
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINT
) * (cPoints
+ 1) );
752 if(!pt
) return FALSE
;
753 pt
[0].x
= dc
->CursPosX
;
754 pt
[0].y
= dc
->CursPosY
;
755 memcpy(pt
+ 1, lppt
, sizeof(POINT
) * cPoints
);
756 ret
= PolyBezier(dc
->hSelf
, pt
, cPoints
+1);
757 HeapFree( GetProcessHeap(), 0, pt
);
760 dc
->CursPosX
= lppt
[cPoints
-1].x
;
761 dc
->CursPosY
= lppt
[cPoints
-1].y
;
763 GDI_ReleaseObj( hdc
);
767 /***********************************************************************
770 BOOL WINAPI
AngleArc(HDC hdc
, INT x
, INT y
, DWORD dwRadius
, FLOAT eStartAngle
, FLOAT eSweepAngle
)
772 INT x1
,y1
,x2
,y2
, arcdir
;
776 if( (signed int)dwRadius
< 0 )
779 dc
= DC_GetDCUpdate( hdc
);
780 if(!dc
) return FALSE
;
782 if(dc
->funcs
->pAngleArc
)
784 result
= dc
->funcs
->pAngleArc( dc
->physDev
, x
, y
, dwRadius
, eStartAngle
, eSweepAngle
);
786 GDI_ReleaseObj( hdc
);
789 GDI_ReleaseObj( hdc
);
791 /* AngleArc always works counterclockwise */
792 arcdir
= GetArcDirection( hdc
);
793 SetArcDirection( hdc
, AD_COUNTERCLOCKWISE
);
795 x1
= x
+ cos(eStartAngle
*M_PI
/180) * dwRadius
;
796 y1
= y
- sin(eStartAngle
*M_PI
/180) * dwRadius
;
797 x2
= x
+ cos((eStartAngle
+eSweepAngle
)*M_PI
/180) * dwRadius
;
798 y2
= x
- sin((eStartAngle
+eSweepAngle
)*M_PI
/180) * dwRadius
;
800 LineTo( hdc
, x1
, y1
);
801 if( eSweepAngle
>= 0 )
802 result
= Arc( hdc
, x
-dwRadius
, y
-dwRadius
, x
+dwRadius
, y
+dwRadius
,
805 result
= Arc( hdc
, x
-dwRadius
, y
-dwRadius
, x
+dwRadius
, y
+dwRadius
,
808 if( result
) MoveToEx( hdc
, x2
, y2
, NULL
);
809 SetArcDirection( hdc
, arcdir
);
813 /***********************************************************************
816 BOOL WINAPI
PolyDraw(HDC hdc
, const POINT
*lppt
, const BYTE
*lpbTypes
,
824 dc
= DC_GetDCUpdate( hdc
);
825 if(!dc
) return FALSE
;
827 if(dc
->funcs
->pPolyDraw
)
829 result
= dc
->funcs
->pPolyDraw( dc
->physDev
, lppt
, lpbTypes
, cCount
);
830 GDI_ReleaseObj( hdc
);
833 GDI_ReleaseObj( hdc
);
835 /* check for each bezierto if there are two more points */
836 for( i
= 0; i
< cCount
; i
++ )
837 if( lpbTypes
[i
] != PT_MOVETO
&&
838 lpbTypes
[i
] & PT_BEZIERTO
)
846 /* if no moveto occurs, we will close the figure here */
847 lastmove
.x
= dc
->CursPosX
;
848 lastmove
.y
= dc
->CursPosY
;
851 for( i
= 0; i
< cCount
; i
++ )
853 if( lpbTypes
[i
] == PT_MOVETO
)
855 MoveToEx( hdc
, lppt
[i
].x
, lppt
[i
].y
, NULL
);
856 lastmove
.x
= dc
->CursPosX
;
857 lastmove
.y
= dc
->CursPosY
;
859 else if( lpbTypes
[i
] & PT_LINETO
)
860 LineTo( hdc
, lppt
[i
].x
, lppt
[i
].y
);
861 else if( lpbTypes
[i
] & PT_BEZIERTO
)
863 PolyBezierTo( hdc
, &lppt
[i
], 3 );
869 if( lpbTypes
[i
] & PT_CLOSEFIGURE
)
871 if( PATH_IsPathOpen( dc
->path
) )
874 LineTo( hdc
, lastmove
.x
, lastmove
.y
);
881 /******************************************************************
883 * *Very* simple bezier drawing code,
885 * It uses a recursive algorithm to divide the curve in a series
886 * of straight line segements. Not ideal but for me sufficient.
887 * If you are in need for something better look for some incremental
890 * 7 July 1998 Rein Klazes
894 * some macro definitions for bezier drawing
896 * to avoid truncation errors the coordinates are
897 * shifted upwards. When used in drawing they are
898 * shifted down again, including correct rounding
899 * and avoiding floating point arithmetic
900 * 4 bits should allow 27 bits coordinates which I saw
901 * somewhere in the win32 doc's
905 #define BEZIERSHIFTBITS 4
906 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
907 #define BEZIERPIXEL BEZIERSHIFTUP(1)
908 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
909 /* maximum depth of recursion */
910 #define BEZIERMAXDEPTH 8
912 /* size of array to store points on */
913 /* enough for one curve */
914 #define BEZIER_INITBUFSIZE (150)
916 /* calculate Bezier average, in this case the middle
917 * correctly rounded...
920 #define BEZIERMIDDLE(Mid, P1, P2) \
921 (Mid).x=((P1).x+(P2).x + 1)/2;\
922 (Mid).y=((P1).y+(P2).y + 1)/2;
924 /**********************************************************
925 * BezierCheck helper function to check
926 * that recursion can be terminated
927 * Points[0] and Points[3] are begin and endpoint
928 * Points[1] and Points[2] are control points
929 * level is the recursion depth
930 * returns true if the recusion can be terminated
932 static BOOL
BezierCheck( int level
, POINT
*Points
)
935 dx
=Points
[3].x
-Points
[0].x
;
936 dy
=Points
[3].y
-Points
[0].y
;
937 if(abs(dy
)<=abs(dx
)){/* shallow line */
938 /* check that control points are between begin and end */
939 if(Points
[1].x
< Points
[0].x
){
940 if(Points
[1].x
< Points
[3].x
)
943 if(Points
[1].x
> Points
[3].x
)
945 if(Points
[2].x
< Points
[0].x
){
946 if(Points
[2].x
< Points
[3].x
)
949 if(Points
[2].x
> Points
[3].x
)
951 dx
=BEZIERSHIFTDOWN(dx
);
953 if(abs(Points
[1].y
-Points
[0].y
-(dy
/dx
)*
954 BEZIERSHIFTDOWN(Points
[1].x
-Points
[0].x
)) > BEZIERPIXEL
||
955 abs(Points
[2].y
-Points
[0].y
-(dy
/dx
)*
956 BEZIERSHIFTDOWN(Points
[2].x
-Points
[0].x
)) > BEZIERPIXEL
)
960 }else{ /* steep line */
961 /* check that control points are between begin and end */
962 if(Points
[1].y
< Points
[0].y
){
963 if(Points
[1].y
< Points
[3].y
)
966 if(Points
[1].y
> Points
[3].y
)
968 if(Points
[2].y
< Points
[0].y
){
969 if(Points
[2].y
< Points
[3].y
)
972 if(Points
[2].y
> Points
[3].y
)
974 dy
=BEZIERSHIFTDOWN(dy
);
976 if(abs(Points
[1].x
-Points
[0].x
-(dx
/dy
)*
977 BEZIERSHIFTDOWN(Points
[1].y
-Points
[0].y
)) > BEZIERPIXEL
||
978 abs(Points
[2].x
-Points
[0].x
-(dx
/dy
)*
979 BEZIERSHIFTDOWN(Points
[2].y
-Points
[0].y
)) > BEZIERPIXEL
)
986 /* Helper for GDI_Bezier.
987 * Just handles one Bezier, so Points should point to four POINTs
989 static void GDI_InternalBezier( POINT
*Points
, POINT
**PtsOut
, INT
*dwOut
,
990 INT
*nPtsOut
, INT level
)
992 if(*nPtsOut
== *dwOut
) {
994 *PtsOut
= HeapReAlloc( GetProcessHeap(), 0, *PtsOut
,
995 *dwOut
* sizeof(POINT
) );
998 if(!level
|| BezierCheck(level
, Points
)) {
1000 (*PtsOut
)[0].x
= BEZIERSHIFTDOWN(Points
[0].x
);
1001 (*PtsOut
)[0].y
= BEZIERSHIFTDOWN(Points
[0].y
);
1004 (*PtsOut
)[*nPtsOut
].x
= BEZIERSHIFTDOWN(Points
[3].x
);
1005 (*PtsOut
)[*nPtsOut
].y
= BEZIERSHIFTDOWN(Points
[3].y
);
1008 POINT Points2
[4]; /* for the second recursive call */
1009 Points2
[3]=Points
[3];
1010 BEZIERMIDDLE(Points2
[2], Points
[2], Points
[3]);
1011 BEZIERMIDDLE(Points2
[0], Points
[1], Points
[2]);
1012 BEZIERMIDDLE(Points2
[1],Points2
[0],Points2
[2]);
1014 BEZIERMIDDLE(Points
[1], Points
[0], Points
[1]);
1015 BEZIERMIDDLE(Points
[2], Points
[1], Points2
[0]);
1016 BEZIERMIDDLE(Points
[3], Points
[2], Points2
[1]);
1018 Points2
[0]=Points
[3];
1020 /* do the two halves */
1021 GDI_InternalBezier(Points
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1022 GDI_InternalBezier(Points2
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1028 /***********************************************************************
1029 * GDI_Bezier [INTERNAL]
1030 * Calculate line segments that approximate -what microsoft calls- a bezier
1032 * The routine recursively divides the curve in two parts until a straight
1037 * Points [I] Ptr to count POINTs which are the end and control points
1038 * of the set of Bezier curves to flatten.
1039 * count [I] Number of Points. Must be 3n+1.
1040 * nPtsOut [O] Will contain no of points that have been produced (i.e. no. of
1045 * Ptr to an array of POINTs that contain the lines that approximinate the
1046 * Beziers. The array is allocated on the process heap and it is the caller's
1047 * responsibility to HeapFree it. [this is not a particularly nice interface
1048 * but since we can't know in advance how many points will generate, the
1049 * alternative would be to call the function twice, once to determine the size
1050 * and a second time to do the work - I decided this was too much of a pain].
1052 POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
)
1055 INT Bezier
, dwOut
= BEZIER_INITBUFSIZE
, i
;
1057 if((count
- 1) % 3 != 0) {
1058 ERR("Invalid no. of points\n");
1062 out
= HeapAlloc( GetProcessHeap(), 0, dwOut
* sizeof(POINT
));
1063 for(Bezier
= 0; Bezier
< (count
-1)/3; Bezier
++) {
1065 memcpy(ptBuf
, Points
+ Bezier
* 3, sizeof(POINT
) * 4);
1066 for(i
= 0; i
< 4; i
++) {
1067 ptBuf
[i
].x
= BEZIERSHIFTUP(ptBuf
[i
].x
);
1068 ptBuf
[i
].y
= BEZIERSHIFTUP(ptBuf
[i
].y
);
1070 GDI_InternalBezier( ptBuf
, &out
, &dwOut
, nPtsOut
, BEZIERMAXDEPTH
);
1072 TRACE("Produced %d points\n", *nPtsOut
);
1076 /******************************************************************************
1077 * GradientFill (GDI32.@)
1079 BOOL WINAPI
GdiGradientFill( HDC hdc
, TRIVERTEX
*vert_array
, ULONG nvert
,
1080 void * grad_array
, ULONG ngrad
, ULONG mode
)
1084 TRACE("vert_array:0x%08lx nvert:%ld grad_array:0x%08lx ngrad:%ld\n",
1085 (long)vert_array
, nvert
, (long)grad_array
, ngrad
);
1089 case GRADIENT_FILL_RECT_H
:
1090 for(i
= 0; i
< ngrad
; i
++)
1092 GRADIENT_RECT
*rect
= ((GRADIENT_RECT
*)grad_array
) + i
;
1093 TRIVERTEX
*v1
= vert_array
+ rect
->UpperLeft
;
1094 TRIVERTEX
*v2
= vert_array
+ rect
->LowerRight
;
1095 int y1
= v1
->y
< v2
->y
? v1
->y
: v2
->y
;
1096 int y2
= v2
->y
> v1
->y
? v2
->y
: v1
->y
;
1105 for (x
= 0; x
< dx
; x
++)
1107 for (y
= y1
; y
< y2
; y
++)
1108 SetPixel (hdc
, x
+ v1
->x
, y
, RGB(
1109 (v1
->Red
* (dx
- x
) + v2
->Red
* x
) / dx
>> 8,
1110 (v1
->Green
* (dx
- x
) + v2
->Green
* x
) / dx
>> 8,
1111 (v1
->Blue
* (dx
- x
) + v2
->Blue
* x
) / dx
>> 8));
1115 case GRADIENT_FILL_RECT_V
:
1116 for(i
= 0; i
< ngrad
; i
++)
1118 GRADIENT_RECT
*rect
= ((GRADIENT_RECT
*)grad_array
) + i
;
1119 TRIVERTEX
*v1
= vert_array
+ rect
->UpperLeft
;
1120 TRIVERTEX
*v2
= vert_array
+ rect
->LowerRight
;
1121 int x1
= v1
->x
< v2
->x
? v1
->x
: v2
->x
;
1122 int x2
= v2
->x
> v1
->x
? v2
->x
: v1
->x
;
1131 for (y
= 0; y
< dy
; y
++)
1133 for (x
= x1
; x
< x2
; x
++)
1134 SetPixel (hdc
, x
, y
+ v1
->y
, RGB(
1135 (v1
->Red
* (dy
- y
) + v2
->Red
* y
) / dy
>> 8,
1136 (v1
->Green
* (dy
- y
) + v2
->Green
* y
) / dy
>> 8,
1137 (v1
->Blue
* (dy
- y
) + v2
->Blue
* y
) / dy
>> 8));
1141 case GRADIENT_FILL_TRIANGLE
:
1142 for (i
= 0; i
< ngrad
; i
++)
1144 GRADIENT_TRIANGLE
*tri
= ((GRADIENT_TRIANGLE
*)grad_array
) + i
;
1145 TRIVERTEX
*v1
= vert_array
+ tri
->Vertex1
;
1146 TRIVERTEX
*v2
= vert_array
+ tri
->Vertex2
;
1147 TRIVERTEX
*v3
= vert_array
+ tri
->Vertex3
;
1151 { TRIVERTEX
*t
= v1
; v1
= v2
; v2
= t
; }
1154 TRIVERTEX
*t
= v2
; v2
= v3
; v3
= t
;
1156 { t
= v1
; v1
= v2
; v2
= t
; }
1158 /* v1->y <= v2->y <= v3->y */
1161 for (y
= 0; y
< dy
; y
++)
1163 /* v1->y <= y < v3->y */
1164 TRIVERTEX
*v
= y
< (v2
->y
- v1
->y
) ? v1
: v3
;
1165 /* (v->y <= y < v2->y) || (v2->y <= y < v->y) */
1166 int dy2
= v2
->y
- v
->y
;
1167 int y2
= y
+ v1
->y
- v
->y
;
1169 int x1
= (v3
->x
* y
+ v1
->x
* (dy
- y
)) / dy
;
1170 int x2
= (v2
->x
* y2
+ v
-> x
* (dy2
- y2
)) / dy2
;
1171 int r1
= (v3
->Red
* y
+ v1
->Red
* (dy
- y
)) / dy
;
1172 int r2
= (v2
->Red
* y2
+ v
-> Red
* (dy2
- y2
)) / dy2
;
1173 int g1
= (v3
->Green
* y
+ v1
->Green
* (dy
- y
)) / dy
;
1174 int g2
= (v2
->Green
* y2
+ v
-> Green
* (dy2
- y2
)) / dy2
;
1175 int b1
= (v3
->Blue
* y
+ v1
->Blue
* (dy
- y
)) / dy
;
1176 int b2
= (v2
->Blue
* y2
+ v
-> Blue
* (dy2
- y2
)) / dy2
;
1182 for (x
= 0; x
< dx
; x
++)
1183 SetPixel (hdc
, x
+ x1
, y
+ v1
->y
, RGB(
1184 (r1
* (dx
- x
) + r2
* x
) / dx
>> 8,
1185 (g1
* (dx
- x
) + g2
* x
) / dx
>> 8,
1186 (b1
* (dx
- x
) + b2
* x
) / dx
>> 8));
1191 for (x
= 0; x
< dx
; x
++)
1192 SetPixel (hdc
, x
+ x2
, y
+ v1
->y
, RGB(
1193 (r2
* (dx
- x
) + r1
* x
) / dx
>> 8,
1194 (g2
* (dx
- x
) + g1
* x
) / dx
>> 8,
1195 (b2
* (dx
- x
) + b1
* x
) / dx
>> 8));