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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "ntgdi_private.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
37 /***********************************************************************
38 * null driver fallback implementations
41 BOOL CDECL
nulldrv_AngleArc( PHYSDEV dev
, INT x
, INT y
, DWORD radius
, FLOAT start
, FLOAT sweep
)
43 INT x1
= GDI_ROUND( x
+ cos( start
* M_PI
/ 180 ) * radius
);
44 INT y1
= GDI_ROUND( y
- sin( start
* M_PI
/ 180 ) * radius
);
45 INT x2
= GDI_ROUND( x
+ cos( (start
+ sweep
) * M_PI
/ 180) * radius
);
46 INT y2
= GDI_ROUND( y
- sin( (start
+ sweep
) * M_PI
/ 180) * radius
);
47 INT arcdir
= SetArcDirection( dev
->hdc
, sweep
>= 0 ? AD_COUNTERCLOCKWISE
: AD_CLOCKWISE
);
48 BOOL ret
= ArcTo( dev
->hdc
, x
- radius
, y
- radius
, x
+ radius
, y
+ radius
, x1
, y1
, x2
, y2
);
49 SetArcDirection( dev
->hdc
, arcdir
);
53 BOOL CDECL
nulldrv_ArcTo( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
54 INT xstart
, INT ystart
, INT xend
, INT yend
)
56 INT width
= abs( right
- left
);
57 INT height
= abs( bottom
- top
);
58 double xradius
= width
/ 2.0;
59 double yradius
= height
/ 2.0;
60 double xcenter
= right
> left
? left
+ xradius
: right
+ xradius
;
61 double ycenter
= bottom
> top
? top
+ yradius
: bottom
+ yradius
;
64 if (!height
|| !width
) return FALSE
;
65 /* draw a line from the current position to the starting point of the arc, then draw the arc */
66 angle
= atan2( (ystart
- ycenter
) / height
, (xstart
- xcenter
) / width
);
67 LineTo( dev
->hdc
, GDI_ROUND( xcenter
+ cos(angle
) * xradius
),
68 GDI_ROUND( ycenter
+ sin(angle
) * yradius
));
69 return Arc( dev
->hdc
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
72 BOOL CDECL
nulldrv_FillRgn( PHYSDEV dev
, HRGN rgn
, HBRUSH brush
)
77 if ((prev
= NtGdiSelectBrush( dev
->hdc
, brush
)))
79 PHYSDEV physdev
= GET_DC_PHYSDEV( get_physdev_dc( dev
), pPaintRgn
);
80 ret
= physdev
->funcs
->pPaintRgn( physdev
, rgn
);
81 NtGdiSelectBrush( dev
->hdc
, prev
);
86 BOOL CDECL
nulldrv_FrameRgn( PHYSDEV dev
, HRGN rgn
, HBRUSH brush
, INT width
, INT height
)
89 HRGN tmp
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
93 if (REGION_FrameRgn( tmp
, rgn
, width
, height
))
94 ret
= NtGdiFillRgn( dev
->hdc
, tmp
, brush
);
100 BOOL CDECL
nulldrv_InvertRgn( PHYSDEV dev
, HRGN rgn
)
102 INT prev_rop
= SetROP2( dev
->hdc
, R2_NOT
);
103 BOOL ret
= NtGdiFillRgn( dev
->hdc
, rgn
, GetStockObject(BLACK_BRUSH
) );
104 SetROP2( dev
->hdc
, prev_rop
);
108 static BOOL
polyline( HDC hdc
, const POINT
*points
, UINT count
)
110 return NtGdiPolyPolyDraw( hdc
, points
, &count
, 1, NtGdiPolyPolyline
);
113 BOOL CDECL
nulldrv_PolyBezier( PHYSDEV dev
, const POINT
*points
, DWORD count
)
119 if ((pts
= GDI_Bezier( points
, count
, &n
)))
121 ret
= polyline( dev
->hdc
, pts
, n
);
122 HeapFree( GetProcessHeap(), 0, pts
);
127 BOOL CDECL
nulldrv_PolyBezierTo( PHYSDEV dev
, const POINT
*points
, DWORD count
)
129 DC
*dc
= get_nulldrv_dc( dev
);
131 POINT
*pts
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINT
) * (count
+ 1) );
135 pts
[0] = dc
->attr
->cur_pos
;
136 memcpy( pts
+ 1, points
, sizeof(POINT
) * count
);
138 ret
= NtGdiPolyPolyDraw( dev
->hdc
, pts
, &count
, 1, NtGdiPolyBezier
);
139 HeapFree( GetProcessHeap(), 0, pts
);
144 BOOL CDECL
nulldrv_PolyDraw( PHYSDEV dev
, const POINT
*points
, const BYTE
*types
, DWORD count
)
146 DC
*dc
= get_nulldrv_dc( dev
);
147 POINT
*line_pts
= NULL
, *bzr_pts
= NULL
, bzr
[4];
149 INT num_pts
, num_bzr_pts
, space
, size
;
151 /* check for valid point types */
152 for (i
= 0; i
< count
; i
++)
157 case PT_LINETO
| PT_CLOSEFIGURE
:
161 if (i
+ 2 >= count
) return FALSE
;
162 if (types
[i
+ 1] != PT_BEZIERTO
) return FALSE
;
163 if ((types
[i
+ 2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
) return FALSE
;
172 line_pts
= HeapAlloc( GetProcessHeap(), 0, space
* sizeof(POINT
) );
175 line_pts
[0] = dc
->attr
->cur_pos
;
176 for (i
= 0; i
< count
; i
++)
181 if (num_pts
>= 2) polyline( dev
->hdc
, line_pts
, num_pts
);
183 line_pts
[num_pts
++] = points
[i
];
186 case (PT_LINETO
| PT_CLOSEFIGURE
):
187 line_pts
[num_pts
++] = points
[i
];
190 bzr
[0].x
= line_pts
[num_pts
- 1].x
;
191 bzr
[0].y
= line_pts
[num_pts
- 1].y
;
192 memcpy( &bzr
[1], &points
[i
], 3 * sizeof(POINT
) );
194 if ((bzr_pts
= GDI_Bezier( bzr
, 4, &num_bzr_pts
)))
196 size
= num_pts
+ (count
- i
) + num_bzr_pts
;
200 line_pts
= HeapReAlloc( GetProcessHeap(), 0, line_pts
, space
* sizeof(POINT
) );
202 memcpy( &line_pts
[num_pts
], &bzr_pts
[1], (num_bzr_pts
- 1) * sizeof(POINT
) );
203 num_pts
+= num_bzr_pts
- 1;
204 HeapFree( GetProcessHeap(), 0, bzr_pts
);
209 if (types
[i
] & PT_CLOSEFIGURE
) line_pts
[num_pts
++] = line_pts
[0];
212 if (num_pts
>= 2) polyline( dev
->hdc
, line_pts
, num_pts
);
213 HeapFree( GetProcessHeap(), 0, line_pts
);
217 BOOL CDECL
nulldrv_PolylineTo( PHYSDEV dev
, const POINT
*points
, INT count
)
219 DC
*dc
= get_nulldrv_dc( dev
);
223 if (!count
) return FALSE
;
224 if ((pts
= HeapAlloc( GetProcessHeap(), 0, sizeof(POINT
) * (count
+ 1) )))
226 pts
[0] = dc
->attr
->cur_pos
;
227 memcpy( pts
+ 1, points
, sizeof(POINT
) * count
);
228 ret
= polyline( dev
->hdc
, pts
, count
+ 1 );
229 HeapFree( GetProcessHeap(), 0, pts
);
234 /***********************************************************************
235 * NtGdiLineTo (win32u.@)
237 BOOL WINAPI
NtGdiLineTo( HDC hdc
, INT x
, INT y
)
239 DC
* dc
= get_dc_ptr( hdc
);
243 if(!dc
) return FALSE
;
246 physdev
= GET_DC_PHYSDEV( dc
, pLineTo
);
247 ret
= physdev
->funcs
->pLineTo( physdev
, x
, y
);
251 dc
->attr
->cur_pos
.x
= x
;
252 dc
->attr
->cur_pos
.y
= y
;
254 release_dc_ptr( dc
);
259 /***********************************************************************
260 * NtGdiMoveTo (win32u.@)
262 BOOL WINAPI
NtGdiMoveTo( HDC hdc
, INT x
, INT y
, POINT
*pt
)
266 DC
* dc
= get_dc_ptr( hdc
);
268 if(!dc
) return FALSE
;
271 *pt
= dc
->attr
->cur_pos
;
273 dc
->attr
->cur_pos
.x
= x
;
274 dc
->attr
->cur_pos
.y
= y
;
276 physdev
= GET_DC_PHYSDEV( dc
, pMoveTo
);
277 ret
= physdev
->funcs
->pMoveTo( physdev
, x
, y
);
278 release_dc_ptr( dc
);
283 /***********************************************************************
284 * NtGdiArcInternal (win32u.@)
286 BOOL WINAPI
NtGdiArcInternal( UINT type
, HDC hdc
, INT left
, INT top
, INT right
,
287 INT bottom
, INT xstart
, INT ystart
, INT xend
, INT yend
)
293 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
299 physdev
= GET_DC_PHYSDEV( dc
, pArc
);
300 ret
= physdev
->funcs
->pArc( physdev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
);
305 double width
= abs( right
- left
);
306 double height
= abs( bottom
- top
);
307 double xradius
= width
/ 2;
308 double yradius
= height
/ 2;
309 double xcenter
= right
> left
? left
+ xradius
: right
+ xradius
;
310 double ycenter
= bottom
> top
? top
+ yradius
: bottom
+ yradius
;
312 physdev
= GET_DC_PHYSDEV( dc
, pArcTo
);
313 ret
= physdev
->funcs
->pArcTo( physdev
, left
, top
, right
, bottom
,
314 xstart
, ystart
, xend
, yend
);
317 double angle
= atan2(((yend
- ycenter
) / height
),
318 ((xend
- xcenter
) / width
));
319 dc
->attr
->cur_pos
.x
= GDI_ROUND( xcenter
+ (cos( angle
) * xradius
) );
320 dc
->attr
->cur_pos
.y
= GDI_ROUND( ycenter
+ (sin( angle
) * yradius
) );
326 physdev
= GET_DC_PHYSDEV( dc
, pChord
);
327 ret
= physdev
->funcs
->pChord( physdev
, left
, top
, right
, bottom
,
328 xstart
, ystart
, xend
, yend
);
332 physdev
= GET_DC_PHYSDEV( dc
, pPie
);
333 ret
= physdev
->funcs
->pPie( physdev
, left
, top
, right
, bottom
,
334 xstart
, ystart
, xend
, yend
);
338 WARN( "invalid arc type %u\n", type
);
342 release_dc_ptr( dc
);
347 /***********************************************************************
348 * NtGdiEllipse (win32u.@)
350 BOOL WINAPI
NtGdiEllipse( HDC hdc
, INT left
, INT top
, INT right
, INT bottom
)
354 DC
* dc
= get_dc_ptr( hdc
);
356 if (!dc
) return FALSE
;
358 physdev
= GET_DC_PHYSDEV( dc
, pEllipse
);
359 ret
= physdev
->funcs
->pEllipse( physdev
, left
, top
, right
, bottom
);
360 release_dc_ptr( dc
);
365 /***********************************************************************
366 * NtGdiRectangle (win32u.@)
368 BOOL WINAPI
NtGdiRectangle( HDC hdc
, INT left
, INT top
, INT right
, INT bottom
)
372 DC
* dc
= get_dc_ptr( hdc
);
374 if (!dc
) return FALSE
;
376 physdev
= GET_DC_PHYSDEV( dc
, pRectangle
);
377 ret
= physdev
->funcs
->pRectangle( physdev
, left
, top
, right
, bottom
);
378 release_dc_ptr( dc
);
383 /***********************************************************************
384 * NtGdiRoundRect (win32u.@)
386 BOOL WINAPI
NtGdiRoundRect( HDC hdc
, INT left
, INT top
, INT right
,
387 INT bottom
, INT ell_width
, INT ell_height
)
391 DC
*dc
= get_dc_ptr( hdc
);
393 if (!dc
) return FALSE
;
395 physdev
= GET_DC_PHYSDEV( dc
, pRoundRect
);
396 ret
= physdev
->funcs
->pRoundRect( physdev
, left
, top
, right
, bottom
, ell_width
, ell_height
);
397 release_dc_ptr( dc
);
401 /***********************************************************************
402 * NtGdiSetPixel (win32u.@)
404 COLORREF WINAPI
NtGdiSetPixel( HDC hdc
, INT x
, INT y
, COLORREF color
)
408 DC
* dc
= get_dc_ptr( hdc
);
410 if (!dc
) return CLR_INVALID
;
412 physdev
= GET_DC_PHYSDEV( dc
, pSetPixel
);
413 ret
= physdev
->funcs
->pSetPixel( physdev
, x
, y
, color
);
414 release_dc_ptr( dc
);
418 /***********************************************************************
419 * NtGdiGetPixel (win32u.@)
421 COLORREF WINAPI
NtGdiGetPixel( HDC hdc
, INT x
, INT y
)
425 DC
* dc
= get_dc_ptr( hdc
);
427 if (!dc
) return CLR_INVALID
;
429 physdev
= GET_DC_PHYSDEV( dc
, pGetPixel
);
430 ret
= physdev
->funcs
->pGetPixel( physdev
, x
, y
);
431 release_dc_ptr( dc
);
436 /******************************************************************************
437 * NtGdiSetPixelFormat (win32u.@)
439 * Probably not the correct semantics, it's supposed to be an internal backend for SetPixelFormat.
441 BOOL WINAPI
NtGdiSetPixelFormat( HDC hdc
, INT format
)
446 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
448 if (!dc
->pixel_format
) dc
->pixel_format
= format
;
449 else ret
= (dc
->pixel_format
== format
);
450 release_dc_ptr( dc
);
455 /******************************************************************************
456 * NtGdiDescribePixelFormat (win32u.@)
458 INT WINAPI
NtGdiDescribePixelFormat( HDC hdc
, INT format
, UINT size
, PIXELFORMATDESCRIPTOR
*descr
)
460 FIXME( "(%p,%d,%d,%p): stub\n", hdc
, format
, size
, descr
);
465 /******************************************************************************
466 * NtGdiSwapBuffers (win32u.@)
468 BOOL WINAPI
NtGdiSwapBuffers( HDC hdc
)
470 FIXME( "(%p): stub\n", hdc
);
475 /***********************************************************************
476 * NtGdiFillRgn (win32u.@)
478 BOOL WINAPI
NtGdiFillRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
)
482 DC
* dc
= get_dc_ptr( hdc
);
484 if (!dc
) return FALSE
;
486 physdev
= GET_DC_PHYSDEV( dc
, pFillRgn
);
487 retval
= physdev
->funcs
->pFillRgn( physdev
, hrgn
, hbrush
);
488 release_dc_ptr( dc
);
493 /***********************************************************************
494 * NtGdiFrameRgn (win32u.@)
496 BOOL WINAPI
NtGdiFrameRgn( HDC hdc
, HRGN hrgn
, HBRUSH hbrush
, INT width
, INT height
)
500 DC
*dc
= get_dc_ptr( hdc
);
502 if (!dc
) return FALSE
;
504 physdev
= GET_DC_PHYSDEV( dc
, pFrameRgn
);
505 ret
= physdev
->funcs
->pFrameRgn( physdev
, hrgn
, hbrush
, width
, height
);
506 release_dc_ptr( dc
);
511 /***********************************************************************
512 * NtGdiInvertRgn (win32u.@)
514 BOOL WINAPI
NtGdiInvertRgn( HDC hdc
, HRGN hrgn
)
518 DC
*dc
= get_dc_ptr( hdc
);
520 if (!dc
) return FALSE
;
522 physdev
= GET_DC_PHYSDEV( dc
, pInvertRgn
);
523 ret
= physdev
->funcs
->pInvertRgn( physdev
, hrgn
);
524 release_dc_ptr( dc
);
529 /**********************************************************************
530 * NtGdiPolyPolyDraw (win32u.@)
532 ULONG WINAPI
NtGdiPolyPolyDraw( HDC hdc
, const POINT
*points
, const UINT
*counts
,
533 UINT count
, UINT function
)
539 if (function
== NtGdiPolyPolygonRgn
)
540 return HandleToULong( create_polypolygon_region( points
, (const INT
*)counts
, count
,
541 HandleToULong(hdc
), NULL
));
543 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
548 case NtGdiPolyPolygon
:
549 physdev
= GET_DC_PHYSDEV( dc
, pPolyPolygon
);
550 ret
= physdev
->funcs
->pPolyPolygon( physdev
, points
, (const INT
*)counts
, count
);
553 case NtGdiPolyPolyline
:
554 physdev
= GET_DC_PHYSDEV( dc
, pPolyPolyline
);
555 ret
= physdev
->funcs
->pPolyPolyline( physdev
, points
, counts
, count
);
558 case NtGdiPolyBezier
:
559 /* *counts must be 3 * n + 1 (where n >= 1) */
560 if (count
== 1 && *counts
!= 1 && *counts
% 3 == 1)
562 physdev
= GET_DC_PHYSDEV( dc
, pPolyBezier
);
563 ret
= physdev
->funcs
->pPolyBezier( physdev
, points
, *counts
);
564 if (ret
) dc
->attr
->cur_pos
= points
[*counts
- 1];
569 case NtGdiPolyBezierTo
:
570 if (count
== 1 && *counts
&& *counts
% 3 == 0)
572 physdev
= GET_DC_PHYSDEV( dc
, pPolyBezierTo
);
573 ret
= physdev
->funcs
->pPolyBezierTo( physdev
, points
, *counts
);
574 if (ret
) dc
->attr
->cur_pos
= points
[*counts
- 1];
579 case NtGdiPolylineTo
:
582 physdev
= GET_DC_PHYSDEV( dc
, pPolylineTo
);
583 ret
= physdev
->funcs
->pPolylineTo( physdev
, points
, *counts
);
584 if (ret
&& *counts
) dc
->attr
->cur_pos
= points
[*counts
- 1];
590 WARN( "invalid function %u\n", function
);
595 release_dc_ptr( dc
);
599 /**********************************************************************
600 * NtGdiExtFloodFill (win32u.@)
602 BOOL WINAPI
NtGdiExtFloodFill( HDC hdc
, INT x
, INT y
, COLORREF color
, UINT fill_type
)
606 DC
* dc
= get_dc_ptr( hdc
);
608 if (!dc
) return FALSE
;
610 physdev
= GET_DC_PHYSDEV( dc
, pExtFloodFill
);
611 ret
= physdev
->funcs
->pExtFloodFill( physdev
, x
, y
, color
, fill_type
);
612 release_dc_ptr( dc
);
617 /***********************************************************************
618 * NtGdiAngleArc (win32u.@)
620 BOOL WINAPI
NtGdiAngleArc( HDC hdc
, INT x
, INT y
, DWORD dwRadius
, FLOAT eStartAngle
, FLOAT eSweepAngle
)
626 if( (signed int)dwRadius
< 0 )
629 dc
= get_dc_ptr( hdc
);
630 if(!dc
) return FALSE
;
633 physdev
= GET_DC_PHYSDEV( dc
, pAngleArc
);
634 result
= physdev
->funcs
->pAngleArc( physdev
, x
, y
, dwRadius
, eStartAngle
, eSweepAngle
);
638 dc
->attr
->cur_pos
.x
= GDI_ROUND( x
+ cos( (eStartAngle
+ eSweepAngle
) * M_PI
/ 180 ) * dwRadius
);
639 dc
->attr
->cur_pos
.y
= GDI_ROUND( y
- sin( (eStartAngle
+ eSweepAngle
) * M_PI
/ 180 ) * dwRadius
);
641 release_dc_ptr( dc
);
645 /***********************************************************************
646 * NtGdiPolyDraw (win32u.@)
648 BOOL WINAPI
NtGdiPolyDraw( HDC hdc
, const POINT
*points
, const BYTE
*types
, DWORD count
)
650 DC
*dc
= get_dc_ptr( hdc
);
654 if(!dc
) return FALSE
;
657 physdev
= GET_DC_PHYSDEV( dc
, pPolyDraw
);
658 result
= physdev
->funcs
->pPolyDraw( physdev
, points
, types
, count
);
660 dc
->attr
->cur_pos
= points
[count
- 1];
662 release_dc_ptr( dc
);
667 /**********************************************************************
670 BOOL WINAPI
LineDDA(INT nXStart
, INT nYStart
, INT nXEnd
, INT nYEnd
,
671 LINEDDAPROC callback
, LPARAM lParam
)
673 INT xadd
= 1, yadd
= 1;
676 INT dx
= nXEnd
- nXStart
;
677 INT dy
= nYEnd
- nYStart
;
679 TRACE( "(%d, %d), (%d, %d), %p, %lx\n", nXStart
, nYStart
, nXEnd
, nYEnd
, callback
, lParam
);
691 if (dx
> dy
) /* line is "more horizontal" */
693 err
= 2*dy
- dx
; erradd
= 2*dy
- 2*dx
;
694 for(cnt
= 0;cnt
< dx
; cnt
++)
696 callback(nXStart
,nYStart
,lParam
);
706 else /* line is "more vertical" */
708 err
= 2*dx
- dy
; erradd
= 2*dx
- 2*dy
;
709 for(cnt
= 0;cnt
< dy
; cnt
++)
711 callback(nXStart
,nYStart
,lParam
);
725 /******************************************************************
727 * *Very* simple bezier drawing code,
729 * It uses a recursive algorithm to divide the curve in a series
730 * of straight line segments. Not ideal but sufficient for me.
731 * If you are in need for something better look for some incremental
734 * 7 July 1998 Rein Klazes
738 * some macro definitions for bezier drawing
740 * to avoid truncation errors the coordinates are
741 * shifted upwards. When used in drawing they are
742 * shifted down again, including correct rounding
743 * and avoiding floating point arithmetic
744 * 4 bits should allow 27 bits coordinates which I saw
745 * somewhere in the win32 doc's
749 #define BEZIERSHIFTBITS 4
750 #define BEZIERSHIFTUP(x) ((x)<<BEZIERSHIFTBITS)
751 #define BEZIERPIXEL BEZIERSHIFTUP(1)
752 #define BEZIERSHIFTDOWN(x) (((x)+(1<<(BEZIERSHIFTBITS-1)))>>BEZIERSHIFTBITS)
753 /* maximum depth of recursion */
754 #define BEZIERMAXDEPTH 8
756 /* size of array to store points on */
757 /* enough for one curve */
758 #define BEZIER_INITBUFSIZE (150)
760 /* calculate Bezier average, in this case the middle
761 * correctly rounded...
764 #define BEZIERMIDDLE(Mid, P1, P2) \
765 (Mid).x=((P1).x+(P2).x + 1)/2;\
766 (Mid).y=((P1).y+(P2).y + 1)/2;
768 /**********************************************************
769 * BezierCheck helper function to check
770 * that recursion can be terminated
771 * Points[0] and Points[3] are begin and endpoint
772 * Points[1] and Points[2] are control points
773 * level is the recursion depth
774 * returns true if the recursion can be terminated
776 static BOOL
BezierCheck( int level
, POINT
*Points
)
779 dx
=Points
[3].x
-Points
[0].x
;
780 dy
=Points
[3].y
-Points
[0].y
;
781 if(abs(dy
)<=abs(dx
)){/* shallow line */
782 /* check that control points are between begin and end */
783 if(Points
[1].x
< Points
[0].x
){
784 if(Points
[1].x
< Points
[3].x
)
787 if(Points
[1].x
> Points
[3].x
)
789 if(Points
[2].x
< Points
[0].x
){
790 if(Points
[2].x
< Points
[3].x
)
793 if(Points
[2].x
> Points
[3].x
)
795 dx
=BEZIERSHIFTDOWN(dx
);
797 if(abs(Points
[1].y
-Points
[0].y
-(dy
/dx
)*
798 BEZIERSHIFTDOWN(Points
[1].x
-Points
[0].x
)) > BEZIERPIXEL
||
799 abs(Points
[2].y
-Points
[0].y
-(dy
/dx
)*
800 BEZIERSHIFTDOWN(Points
[2].x
-Points
[0].x
)) > BEZIERPIXEL
)
804 }else{ /* steep line */
805 /* check that control points are between begin and end */
806 if(Points
[1].y
< Points
[0].y
){
807 if(Points
[1].y
< Points
[3].y
)
810 if(Points
[1].y
> Points
[3].y
)
812 if(Points
[2].y
< Points
[0].y
){
813 if(Points
[2].y
< Points
[3].y
)
816 if(Points
[2].y
> Points
[3].y
)
818 dy
=BEZIERSHIFTDOWN(dy
);
820 if(abs(Points
[1].x
-Points
[0].x
-(dx
/dy
)*
821 BEZIERSHIFTDOWN(Points
[1].y
-Points
[0].y
)) > BEZIERPIXEL
||
822 abs(Points
[2].x
-Points
[0].x
-(dx
/dy
)*
823 BEZIERSHIFTDOWN(Points
[2].y
-Points
[0].y
)) > BEZIERPIXEL
)
830 /* Helper for GDI_Bezier.
831 * Just handles one Bezier, so Points should point to four POINTs
833 static void GDI_InternalBezier( POINT
*Points
, POINT
**PtsOut
, INT
*dwOut
,
834 INT
*nPtsOut
, INT level
)
836 if(*nPtsOut
== *dwOut
) {
838 *PtsOut
= HeapReAlloc( GetProcessHeap(), 0, *PtsOut
,
839 *dwOut
* sizeof(POINT
) );
842 if(!level
|| BezierCheck(level
, Points
)) {
844 (*PtsOut
)[0].x
= BEZIERSHIFTDOWN(Points
[0].x
);
845 (*PtsOut
)[0].y
= BEZIERSHIFTDOWN(Points
[0].y
);
848 (*PtsOut
)[*nPtsOut
].x
= BEZIERSHIFTDOWN(Points
[3].x
);
849 (*PtsOut
)[*nPtsOut
].y
= BEZIERSHIFTDOWN(Points
[3].y
);
852 POINT Points2
[4]; /* for the second recursive call */
853 Points2
[3]=Points
[3];
854 BEZIERMIDDLE(Points2
[2], Points
[2], Points
[3]);
855 BEZIERMIDDLE(Points2
[0], Points
[1], Points
[2]);
856 BEZIERMIDDLE(Points2
[1],Points2
[0],Points2
[2]);
858 BEZIERMIDDLE(Points
[1], Points
[0], Points
[1]);
859 BEZIERMIDDLE(Points
[2], Points
[1], Points2
[0]);
860 BEZIERMIDDLE(Points
[3], Points
[2], Points2
[1]);
862 Points2
[0]=Points
[3];
864 /* do the two halves */
865 GDI_InternalBezier(Points
, PtsOut
, dwOut
, nPtsOut
, level
-1);
866 GDI_InternalBezier(Points2
, PtsOut
, dwOut
, nPtsOut
, level
-1);
872 /***********************************************************************
873 * GDI_Bezier [INTERNAL]
874 * Calculate line segments that approximate -what microsoft calls- a bezier
876 * The routine recursively divides the curve in two parts until a straight
881 * Points [I] Ptr to count POINTs which are the end and control points
882 * of the set of Bezier curves to flatten.
883 * count [I] Number of Points. Must be 3n+1.
884 * nPtsOut [O] Will contain no of points that have been produced (i.e. no. of
889 * Ptr to an array of POINTs that contain the lines that approximate the
890 * Beziers. The array is allocated on the process heap and it is the caller's
891 * responsibility to HeapFree it. [this is not a particularly nice interface
892 * but since we can't know in advance how many points we will generate, the
893 * alternative would be to call the function twice, once to determine the size
894 * and a second time to do the work - I decided this was too much of a pain].
896 POINT
*GDI_Bezier( const POINT
*Points
, INT count
, INT
*nPtsOut
)
899 INT Bezier
, dwOut
= BEZIER_INITBUFSIZE
, i
;
901 if (count
== 1 || (count
- 1) % 3 != 0) {
902 ERR("Invalid no. of points %d\n", count
);
906 out
= HeapAlloc( GetProcessHeap(), 0, dwOut
* sizeof(POINT
));
907 for(Bezier
= 0; Bezier
< (count
-1)/3; Bezier
++) {
909 memcpy(ptBuf
, Points
+ Bezier
* 3, sizeof(POINT
) * 4);
910 for(i
= 0; i
< 4; i
++) {
911 ptBuf
[i
].x
= BEZIERSHIFTUP(ptBuf
[i
].x
);
912 ptBuf
[i
].y
= BEZIERSHIFTUP(ptBuf
[i
].y
);
914 GDI_InternalBezier( ptBuf
, &out
, &dwOut
, nPtsOut
, BEZIERMAXDEPTH
);
916 TRACE("Produced %d points\n", *nPtsOut
);
920 /******************************************************************************
921 * NtGdiGdiGradientFill (win32u.@)
923 BOOL WINAPI
NtGdiGradientFill( HDC hdc
, TRIVERTEX
*vert_array
, ULONG nvert
,
924 void *grad_array
, ULONG ngrad
, ULONG mode
)
931 if (!vert_array
|| !nvert
|| !grad_array
|| !ngrad
|| mode
> GRADIENT_FILL_TRIANGLE
)
933 SetLastError( ERROR_INVALID_PARAMETER
);
936 for (i
= 0; i
< ngrad
* (mode
== GRADIENT_FILL_TRIANGLE
? 3 : 2); i
++)
937 if (((ULONG
*)grad_array
)[i
] >= nvert
) return FALSE
;
939 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
941 physdev
= GET_DC_PHYSDEV( dc
, pGradientFill
);
942 ret
= physdev
->funcs
->pGradientFill( physdev
, vert_array
, nvert
, grad_array
, ngrad
, mode
);
943 release_dc_ptr( dc
);
947 /******************************************************************************
948 * NtGdiDrawStream (win32u.@)
950 BOOL WINAPI
NtGdiDrawStream( HDC hdc
, ULONG in
, void *pvin
)
952 FIXME("stub: %p, %d, %p\n", hdc
, in
, pvin
);