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
)
698 DC
* dc
= DC_GetDCUpdate( hdc
);
700 if(!dc
) return FALSE
;
702 if(PATH_IsPathOpen(dc
->path
))
703 ret
= PATH_PolyBezier(dc
, lppt
, cPoints
);
704 else if (dc
->funcs
->pPolyBezier
)
705 ret
= dc
->funcs
->pPolyBezier(dc
->physDev
, lppt
, cPoints
);
706 else /* We'll convert it into line segments and draw them using Polyline */
711 if ((Pts
= GDI_Bezier( lppt
, cPoints
, &nOut
)))
713 TRACE("Pts = %p, no = %d\n", Pts
, nOut
);
714 ret
= Polyline( dc
->hSelf
, Pts
, nOut
);
715 HeapFree( GetProcessHeap(), 0, Pts
);
719 GDI_ReleaseObj( hdc
);
723 /******************************************************************************
724 * PolyBezierTo [GDI32.@]
725 * Draws one or more Bezier curves
728 * hDc [I] Handle to device context
729 * lppt [I] Pointer to endpoints and control points
730 * cPoints [I] Count of endpoints and control points
734 BOOL WINAPI
PolyBezierTo( HDC hdc
, const POINT
* lppt
, DWORD cPoints
)
736 DC
* dc
= DC_GetDCUpdate( hdc
);
739 if(!dc
) return FALSE
;
741 if(PATH_IsPathOpen(dc
->path
))
742 ret
= PATH_PolyBezierTo(dc
, lppt
, cPoints
);
743 else if(dc
->funcs
->pPolyBezierTo
)
744 ret
= dc
->funcs
->pPolyBezierTo(dc
->physDev
, lppt
, cPoints
);
745 else { /* We'll do it using PolyBezier */
747 pt
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINT
) * (cPoints
+ 1) );
748 if(!pt
) return FALSE
;
749 pt
[0].x
= dc
->CursPosX
;
750 pt
[0].y
= dc
->CursPosY
;
751 memcpy(pt
+ 1, lppt
, sizeof(POINT
) * cPoints
);
752 ret
= PolyBezier(dc
->hSelf
, pt
, cPoints
+1);
753 HeapFree( GetProcessHeap(), 0, pt
);
756 dc
->CursPosX
= lppt
[cPoints
-1].x
;
757 dc
->CursPosY
= lppt
[cPoints
-1].y
;
759 GDI_ReleaseObj( hdc
);
763 /***********************************************************************
766 BOOL WINAPI
AngleArc(HDC hdc
, INT x
, INT y
, DWORD dwRadius
, FLOAT eStartAngle
, FLOAT eSweepAngle
)
768 INT x1
,y1
,x2
,y2
, arcdir
;
772 if( (signed int)dwRadius
< 0 )
775 dc
= DC_GetDCUpdate( hdc
);
776 if(!dc
) return FALSE
;
778 if(dc
->funcs
->pAngleArc
)
780 result
= dc
->funcs
->pAngleArc( dc
->physDev
, x
, y
, dwRadius
, eStartAngle
, eSweepAngle
);
782 GDI_ReleaseObj( hdc
);
785 GDI_ReleaseObj( hdc
);
787 /* AngleArc always works counterclockwise */
788 arcdir
= GetArcDirection( hdc
);
789 SetArcDirection( hdc
, AD_COUNTERCLOCKWISE
);
791 x1
= x
+ cos(eStartAngle
*M_PI
/180) * dwRadius
;
792 y1
= y
- sin(eStartAngle
*M_PI
/180) * dwRadius
;
793 x2
= x
+ cos((eStartAngle
+eSweepAngle
)*M_PI
/180) * dwRadius
;
794 y2
= x
- sin((eStartAngle
+eSweepAngle
)*M_PI
/180) * dwRadius
;
796 LineTo( hdc
, x1
, y1
);
797 if( eSweepAngle
>= 0 )
798 result
= Arc( hdc
, x
-dwRadius
, y
-dwRadius
, x
+dwRadius
, y
+dwRadius
,
801 result
= Arc( hdc
, x
-dwRadius
, y
-dwRadius
, x
+dwRadius
, y
+dwRadius
,
804 if( result
) MoveToEx( hdc
, x2
, y2
, NULL
);
805 SetArcDirection( hdc
, arcdir
);
809 /***********************************************************************
812 BOOL WINAPI
PolyDraw(HDC hdc
, const POINT
*lppt
, const BYTE
*lpbTypes
,
820 dc
= DC_GetDCUpdate( hdc
);
821 if(!dc
) return FALSE
;
823 if(dc
->funcs
->pPolyDraw
)
825 result
= dc
->funcs
->pPolyDraw( dc
->physDev
, lppt
, lpbTypes
, cCount
);
826 GDI_ReleaseObj( hdc
);
829 GDI_ReleaseObj( hdc
);
831 /* check for each bezierto if there are two more points */
832 for( i
= 0; i
< cCount
; i
++ )
833 if( lpbTypes
[i
] != PT_MOVETO
&&
834 lpbTypes
[i
] & PT_BEZIERTO
)
842 /* if no moveto occurs, we will close the figure here */
843 lastmove
.x
= dc
->CursPosX
;
844 lastmove
.y
= dc
->CursPosY
;
847 for( i
= 0; i
< cCount
; i
++ )
849 if( lpbTypes
[i
] == PT_MOVETO
)
851 MoveToEx( hdc
, lppt
[i
].x
, lppt
[i
].y
, NULL
);
852 lastmove
.x
= dc
->CursPosX
;
853 lastmove
.y
= dc
->CursPosY
;
855 else if( lpbTypes
[i
] & PT_LINETO
)
856 LineTo( hdc
, lppt
[i
].x
, lppt
[i
].y
);
857 else if( lpbTypes
[i
] & PT_BEZIERTO
)
859 PolyBezierTo( hdc
, &lppt
[i
], 3 );
865 if( lpbTypes
[i
] & PT_CLOSEFIGURE
)
867 if( PATH_IsPathOpen( dc
->path
) )
870 LineTo( hdc
, lastmove
.x
, lastmove
.y
);
877 /******************************************************************
879 * *Very* simple bezier drawing code,
881 * It uses a recursive algorithm to divide the curve in a series
882 * of straight line segements. Not ideal but for me sufficient.
883 * If you are in need for something better look for some incremental
886 * 7 July 1998 Rein Klazes
890 * some macro definitions for bezier drawing
892 * to avoid truncation errors the coordinates are
893 * shifted upwards. When used in drawing they are
894 * shifted down again, including correct rounding
895 * and avoiding floating point arithmetic
896 * 4 bits should allow 27 bits coordinates which I saw
897 * somewhere in the win32 doc's
901 #define BEZIERSHIFTBITS 4
902 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
903 #define BEZIERPIXEL BEZIERSHIFTUP(1)
904 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
905 /* maximum depth of recursion */
906 #define BEZIERMAXDEPTH 8
908 /* size of array to store points on */
909 /* enough for one curve */
910 #define BEZIER_INITBUFSIZE (150)
912 /* calculate Bezier average, in this case the middle
913 * correctly rounded...
916 #define BEZIERMIDDLE(Mid, P1, P2) \
917 (Mid).x=((P1).x+(P2).x + 1)/2;\
918 (Mid).y=((P1).y+(P2).y + 1)/2;
920 /**********************************************************
921 * BezierCheck helper function to check
922 * that recursion can be terminated
923 * Points[0] and Points[3] are begin and endpoint
924 * Points[1] and Points[2] are control points
925 * level is the recursion depth
926 * returns true if the recusion can be terminated
928 static BOOL
BezierCheck( int level
, POINT
*Points
)
931 dx
=Points
[3].x
-Points
[0].x
;
932 dy
=Points
[3].y
-Points
[0].y
;
933 if(abs(dy
)<=abs(dx
)){/* shallow line */
934 /* check that control points are between begin and end */
935 if(Points
[1].x
< Points
[0].x
){
936 if(Points
[1].x
< Points
[3].x
)
939 if(Points
[1].x
> Points
[3].x
)
941 if(Points
[2].x
< Points
[0].x
){
942 if(Points
[2].x
< Points
[3].x
)
945 if(Points
[2].x
> Points
[3].x
)
947 dx
=BEZIERSHIFTDOWN(dx
);
949 if(abs(Points
[1].y
-Points
[0].y
-(dy
/dx
)*
950 BEZIERSHIFTDOWN(Points
[1].x
-Points
[0].x
)) > BEZIERPIXEL
||
951 abs(Points
[2].y
-Points
[0].y
-(dy
/dx
)*
952 BEZIERSHIFTDOWN(Points
[2].x
-Points
[0].x
)) > BEZIERPIXEL
)
956 }else{ /* steep line */
957 /* check that control points are between begin and end */
958 if(Points
[1].y
< Points
[0].y
){
959 if(Points
[1].y
< Points
[3].y
)
962 if(Points
[1].y
> Points
[3].y
)
964 if(Points
[2].y
< Points
[0].y
){
965 if(Points
[2].y
< Points
[3].y
)
968 if(Points
[2].y
> Points
[3].y
)
970 dy
=BEZIERSHIFTDOWN(dy
);
972 if(abs(Points
[1].x
-Points
[0].x
-(dx
/dy
)*
973 BEZIERSHIFTDOWN(Points
[1].y
-Points
[0].y
)) > BEZIERPIXEL
||
974 abs(Points
[2].x
-Points
[0].x
-(dx
/dy
)*
975 BEZIERSHIFTDOWN(Points
[2].y
-Points
[0].y
)) > BEZIERPIXEL
)
982 /* Helper for GDI_Bezier.
983 * Just handles one Bezier, so Points should point to four POINTs
985 static void GDI_InternalBezier( POINT
*Points
, POINT
**PtsOut
, INT
*dwOut
,
986 INT
*nPtsOut
, INT level
)
988 if(*nPtsOut
== *dwOut
) {
990 *PtsOut
= HeapReAlloc( GetProcessHeap(), 0, *PtsOut
,
991 *dwOut
* sizeof(POINT
) );
994 if(!level
|| BezierCheck(level
, Points
)) {
996 (*PtsOut
)[0].x
= BEZIERSHIFTDOWN(Points
[0].x
);
997 (*PtsOut
)[0].y
= BEZIERSHIFTDOWN(Points
[0].y
);
1000 (*PtsOut
)[*nPtsOut
].x
= BEZIERSHIFTDOWN(Points
[3].x
);
1001 (*PtsOut
)[*nPtsOut
].y
= BEZIERSHIFTDOWN(Points
[3].y
);
1004 POINT Points2
[4]; /* for the second recursive call */
1005 Points2
[3]=Points
[3];
1006 BEZIERMIDDLE(Points2
[2], Points
[2], Points
[3]);
1007 BEZIERMIDDLE(Points2
[0], Points
[1], Points
[2]);
1008 BEZIERMIDDLE(Points2
[1],Points2
[0],Points2
[2]);
1010 BEZIERMIDDLE(Points
[1], Points
[0], Points
[1]);
1011 BEZIERMIDDLE(Points
[2], Points
[1], Points2
[0]);
1012 BEZIERMIDDLE(Points
[3], Points
[2], Points2
[1]);
1014 Points2
[0]=Points
[3];
1016 /* do the two halves */
1017 GDI_InternalBezier(Points
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1018 GDI_InternalBezier(Points2
, PtsOut
, dwOut
, nPtsOut
, level
-1);
1024 /***********************************************************************
1025 * GDI_Bezier [INTERNAL]
1026 * Calculate line segments that approximate -what microsoft calls- a bezier
1028 * The routine recursively divides the curve in two parts until a straight
1033 * Points [I] Ptr to count POINTs which are the end and control points
1034 * of the set of Bezier curves to flatten.
1035 * count [I] Number of Points. Must be 3n+1.
1036 * nPtsOut [O] Will contain no of points that have been produced (i.e. no. of
1041 * Ptr to an array of POINTs that contain the lines that approximinate the
1042 * Beziers. The array is allocated on the process heap and it is the caller's
1043 * responsibility to HeapFree it. [this is not a particularly nice interface
1044 * but since we can't know in advance how many points will generate, the
1045 * alternative would be to call the function twice, once to determine the size
1046 * and a second time to do the work - I decided this was too much of a pain].
1048 POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
)
1051 INT Bezier
, dwOut
= BEZIER_INITBUFSIZE
, i
;
1053 if((count
- 1) % 3 != 0) {
1054 ERR("Invalid no. of points\n");
1058 out
= HeapAlloc( GetProcessHeap(), 0, dwOut
* sizeof(POINT
));
1059 for(Bezier
= 0; Bezier
< (count
-1)/3; Bezier
++) {
1061 memcpy(ptBuf
, Points
+ Bezier
* 3, sizeof(POINT
) * 4);
1062 for(i
= 0; i
< 4; i
++) {
1063 ptBuf
[i
].x
= BEZIERSHIFTUP(ptBuf
[i
].x
);
1064 ptBuf
[i
].y
= BEZIERSHIFTUP(ptBuf
[i
].y
);
1066 GDI_InternalBezier( ptBuf
, &out
, &dwOut
, nPtsOut
, BEZIERMAXDEPTH
);
1068 TRACE("Produced %d points\n", *nPtsOut
);
1072 /******************************************************************************
1073 * GradientFill (GDI32.@)
1075 BOOL WINAPI
GdiGradientFill( HDC hdc
, TRIVERTEX
*vert_array
, ULONG nvert
,
1076 void * grad_array
, ULONG ngrad
, ULONG mode
)
1080 TRACE("vert_array:0x%08lx nvert:%ld grad_array:0x%08lx ngrad:%ld\n",
1081 (long)vert_array
, nvert
, (long)grad_array
, ngrad
);
1085 case GRADIENT_FILL_RECT_H
:
1086 for(i
= 0; i
< ngrad
; i
++)
1088 GRADIENT_RECT
*rect
= ((GRADIENT_RECT
*)grad_array
) + i
;
1089 TRIVERTEX
*v1
= vert_array
+ rect
->UpperLeft
;
1090 TRIVERTEX
*v2
= vert_array
+ rect
->LowerRight
;
1091 int y1
= v1
->y
< v2
->y
? v1
->y
: v2
->y
;
1092 int y2
= v2
->y
> v1
->y
? v2
->y
: v1
->y
;
1101 for (x
= 0; x
< dx
; x
++)
1103 for (y
= y1
; y
< y2
; y
++)
1104 SetPixel (hdc
, x
+ v1
->x
, y
, RGB(
1105 (v1
->Red
* (dx
- x
) + v2
->Red
* x
) / dx
>> 8,
1106 (v1
->Green
* (dx
- x
) + v2
->Green
* x
) / dx
>> 8,
1107 (v1
->Blue
* (dx
- x
) + v2
->Blue
* x
) / dx
>> 8));
1111 case GRADIENT_FILL_RECT_V
:
1112 for(i
= 0; i
< ngrad
; i
++)
1114 GRADIENT_RECT
*rect
= ((GRADIENT_RECT
*)grad_array
) + i
;
1115 TRIVERTEX
*v1
= vert_array
+ rect
->UpperLeft
;
1116 TRIVERTEX
*v2
= vert_array
+ rect
->LowerRight
;
1117 int x1
= v1
->x
< v2
->x
? v1
->x
: v2
->x
;
1118 int x2
= v2
->x
> v1
->x
? v2
->x
: v1
->x
;
1127 for (y
= 0; y
< dy
; y
++)
1129 for (x
= x1
; x
< x2
; x
++)
1130 SetPixel (hdc
, x
, y
+ v1
->y
, RGB(
1131 (v1
->Red
* (dy
- y
) + v2
->Red
* y
) / dy
>> 8,
1132 (v1
->Green
* (dy
- y
) + v2
->Green
* y
) / dy
>> 8,
1133 (v1
->Blue
* (dy
- y
) + v2
->Blue
* y
) / dy
>> 8));
1137 case GRADIENT_FILL_TRIANGLE
:
1138 for (i
= 0; i
< ngrad
; i
++)
1140 GRADIENT_TRIANGLE
*tri
= ((GRADIENT_TRIANGLE
*)grad_array
) + i
;
1141 TRIVERTEX
*v1
= vert_array
+ tri
->Vertex1
;
1142 TRIVERTEX
*v2
= vert_array
+ tri
->Vertex2
;
1143 TRIVERTEX
*v3
= vert_array
+ tri
->Vertex3
;
1147 { TRIVERTEX
*t
= v1
; v1
= v2
; v2
= t
; }
1150 TRIVERTEX
*t
= v2
; v2
= v3
; v3
= t
;
1152 { t
= v1
; v1
= v2
; v2
= t
; }
1154 /* v1->y <= v2->y <= v3->y */
1157 for (y
= 0; y
< dy
; y
++)
1159 /* v1->y <= y < v3->y */
1160 TRIVERTEX
*v
= y
< (v2
->y
- v1
->y
) ? v1
: v3
;
1161 /* (v->y <= y < v2->y) || (v2->y <= y < v->y) */
1162 int dy2
= v2
->y
- v
->y
;
1163 int y2
= y
+ v1
->y
- v
->y
;
1165 int x1
= (v3
->x
* y
+ v1
->x
* (dy
- y
)) / dy
;
1166 int x2
= (v2
->x
* y2
+ v
-> x
* (dy2
- y2
)) / dy2
;
1167 int r1
= (v3
->Red
* y
+ v1
->Red
* (dy
- y
)) / dy
;
1168 int r2
= (v2
->Red
* y2
+ v
-> Red
* (dy2
- y2
)) / dy2
;
1169 int g1
= (v3
->Green
* y
+ v1
->Green
* (dy
- y
)) / dy
;
1170 int g2
= (v2
->Green
* y2
+ v
-> Green
* (dy2
- y2
)) / dy2
;
1171 int b1
= (v3
->Blue
* y
+ v1
->Blue
* (dy
- y
)) / dy
;
1172 int b2
= (v2
->Blue
* y2
+ v
-> Blue
* (dy2
- y2
)) / dy2
;
1178 for (x
= 0; x
< dx
; x
++)
1179 SetPixel (hdc
, x
+ x1
, y
+ v1
->y
, RGB(
1180 (r1
* (dx
- x
) + r2
* x
) / dx
>> 8,
1181 (g1
* (dx
- x
) + g2
* x
) / dx
>> 8,
1182 (b1
* (dx
- x
) + b2
* x
) / dx
>> 8));
1187 for (x
= 0; x
< dx
; x
++)
1188 SetPixel (hdc
, x
+ x2
, y
+ v1
->y
, RGB(
1189 (r2
* (dx
- x
) + r1
* x
) / dx
>> 8,
1190 (g2
* (dx
- x
) + g1
* x
) / dx
>> 8,
1191 (b2
* (dx
- x
) + b1
* x
) / dx
>> 8));