2 * Graphics paths (BeginPath, EndPath etc.)
4 * Copyright 1997, 1998 Martin Boehme
6 * Copyright 2005 Dmitry Timoshkov
7 * Copyright 2011 Alexandre Julliard
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
40 #include "ntgdi_private.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
45 /* Notes on the implementation
47 * The implementation is based on dynamically resizable arrays of points and
48 * flags. I dithered for a bit before deciding on this implementation, and
49 * I had even done a bit of work on a linked list version before switching
50 * to arrays. It's a bit of a tradeoff. When you use linked lists, the
51 * implementation of FlattenPath is easier, because you can rip the
52 * PT_BEZIERTO entries out of the middle of the list and link the
53 * corresponding PT_LINETO entries in. However, when you use arrays,
54 * PathToRegion becomes easier, since you can essentially just pass your array
55 * of points to CreatePolyPolygonRgn. Also, if I'd used linked lists, I would
56 * have had the extra effort of creating a chunk-based allocation scheme
57 * in order to use memory effectively. That's why I finally decided to use
58 * arrays. Note by the way that the array based implementation has the same
59 * linear time complexity that linked lists would have since the arrays grow
62 * The points are stored in the path in device coordinates. This is
63 * consistent with the way Windows does things (for instance, see the Win32
64 * SDK documentation for GetPath).
66 * The word "stroke" appears in several places (e.g. in the flag
67 * GdiPath.newStroke). A stroke consists of a PT_MOVETO followed by one or
68 * more PT_LINETOs or PT_BEZIERTOs, up to, but not including, the next
69 * PT_MOVETO. Note that this is not the same as the definition of a figure;
70 * a figure can contain several strokes.
75 #define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
77 /* A floating point version of the POINT structure */
78 typedef struct tagFLOAT_POINT
90 POINT pos
; /* current cursor position */
91 POINT points_buf
[NUM_ENTRIES_INITIAL
];
92 BYTE flags_buf
[NUM_ENTRIES_INITIAL
];
97 struct gdi_physdev dev
;
98 struct gdi_path
*path
;
101 static inline struct path_physdev
*get_path_physdev( PHYSDEV dev
)
103 return CONTAINING_RECORD( dev
, struct path_physdev
, dev
);
106 void free_gdi_path( struct gdi_path
*path
)
108 if (path
->points
!= path
->points_buf
)
109 free( path
->points
);
113 static struct gdi_path
*alloc_gdi_path( int count
)
115 struct gdi_path
*path
= malloc( sizeof(*path
) );
119 RtlSetLastWin32Error( ERROR_NOT_ENOUGH_MEMORY
);
122 count
= max( NUM_ENTRIES_INITIAL
, count
);
123 if (count
> NUM_ENTRIES_INITIAL
)
125 path
->points
= malloc( count
* (sizeof(path
->points
[0]) + sizeof(path
->flags
[0])) );
129 RtlSetLastWin32Error( ERROR_NOT_ENOUGH_MEMORY
);
132 path
->flags
= (BYTE
*)(path
->points
+ count
);
136 path
->points
= path
->points_buf
;
137 path
->flags
= path
->flags_buf
;
140 path
->allocated
= count
;
141 path
->newStroke
= TRUE
;
142 path
->pos
.x
= path
->pos
.y
= 0;
146 static struct gdi_path
*copy_gdi_path( const struct gdi_path
*src_path
)
148 struct gdi_path
*path
= alloc_gdi_path( src_path
->count
);
150 if (!path
) return NULL
;
152 path
->count
= src_path
->count
;
153 path
->newStroke
= src_path
->newStroke
;
154 path
->pos
= src_path
->pos
;
155 memcpy( path
->points
, src_path
->points
, path
->count
* sizeof(*path
->points
) );
156 memcpy( path
->flags
, src_path
->flags
, path
->count
* sizeof(*path
->flags
) );
160 /* Performs a world-to-viewport transformation on the specified point (which
161 * is in floating point format).
163 static inline void INTERNAL_LPTODP_FLOAT( DC
*dc
, FLOAT_POINT
*point
, int count
)
171 point
->x
= x
* dc
->xformWorld2Vport
.eM11
+ y
* dc
->xformWorld2Vport
.eM21
+ dc
->xformWorld2Vport
.eDx
;
172 point
->y
= x
* dc
->xformWorld2Vport
.eM12
+ y
* dc
->xformWorld2Vport
.eM22
+ dc
->xformWorld2Vport
.eDy
;
177 static inline INT
int_from_fixed(FIXED f
)
179 return (f
.fract
>= 0x8000) ? (f
.value
+ 1) : f
.value
;
183 /* PATH_ReserveEntries
185 * Ensures that at least "numEntries" entries (for points and flags) have
186 * been allocated; allocates larger arrays and copies the existing entries
187 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
189 static BOOL
PATH_ReserveEntries(struct gdi_path
*path
, INT count
)
196 /* Do we have to allocate more memory? */
197 if (count
> path
->allocated
)
199 /* Find number of entries to allocate. We let the size of the array
200 * grow exponentially, since that will guarantee linear time
202 count
= max( path
->allocated
* 2, count
);
203 size
= count
* (sizeof(path
->points
[0]) + sizeof(path
->flags
[0]));
205 if (path
->points
== path
->points_buf
)
207 pts_new
= malloc( size
);
208 if (!pts_new
) return FALSE
;
209 memcpy( pts_new
, path
->points
, path
->count
* sizeof(path
->points
[0]) );
210 memcpy( pts_new
+ count
, path
->flags
, path
->count
* sizeof(path
->flags
[0]) );
214 pts_new
= realloc( path
->points
, size
);
215 if (!pts_new
) return FALSE
;
216 memmove( pts_new
+ count
, pts_new
+ path
->allocated
, path
->count
* sizeof(path
->flags
[0]) );
219 path
->points
= pts_new
;
220 path
->flags
= (BYTE
*)(pts_new
+ count
);
221 path
->allocated
= count
;
228 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
229 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
230 * successful, FALSE otherwise (e.g. if not enough memory was available).
232 static BOOL
PATH_AddEntry(struct gdi_path
*pPath
, const POINT
*pPoint
, BYTE flags
)
234 /* FIXME: If newStroke is true, perhaps we want to check that we're
235 * getting a PT_MOVETO
237 TRACE("(%d,%d) - %d\n", (int)pPoint
->x
, (int)pPoint
->y
, flags
);
239 /* Reserve enough memory for an extra path entry */
240 if(!PATH_ReserveEntries(pPath
, pPath
->count
+1))
243 /* Store information in path entry */
244 pPath
->points
[pPath
->count
]=*pPoint
;
245 pPath
->flags
[pPath
->count
]=flags
;
252 /* add a number of points, converting them to device coords */
253 /* return a pointer to the first type byte so it can be fixed up if necessary */
254 static BYTE
*add_log_points( DC
*dc
, struct gdi_path
*path
, const POINT
*points
,
255 DWORD count
, BYTE type
)
259 if (!PATH_ReserveEntries( path
, path
->count
+ count
)) return NULL
;
261 ret
= &path
->flags
[path
->count
];
262 memcpy( &path
->points
[path
->count
], points
, count
* sizeof(*points
) );
263 lp_to_dp( dc
, &path
->points
[path
->count
], count
);
264 memset( ret
, type
, count
);
265 path
->count
+= count
;
269 /* add a number of points that are already in device coords */
270 /* return a pointer to the first type byte so it can be fixed up if necessary */
271 static BYTE
*add_points( struct gdi_path
*path
, const POINT
*points
, DWORD count
, BYTE type
)
275 if (!PATH_ReserveEntries( path
, path
->count
+ count
)) return NULL
;
277 ret
= &path
->flags
[path
->count
];
278 memcpy( &path
->points
[path
->count
], points
, count
* sizeof(*points
) );
279 memset( ret
, type
, count
);
280 path
->count
+= count
;
284 /* reverse the order of an array of points */
285 static void reverse_points( POINT
*points
, UINT count
)
288 for (i
= 0; i
< count
/ 2; i
++)
290 POINT pt
= points
[i
];
291 points
[i
] = points
[count
- i
- 1];
292 points
[count
- i
- 1] = pt
;
296 /* start a new path stroke if necessary */
297 static BOOL
start_new_stroke( struct gdi_path
*path
)
299 if (!path
->newStroke
&& path
->count
&&
300 !(path
->flags
[path
->count
- 1] & PT_CLOSEFIGURE
) &&
301 path
->points
[path
->count
- 1].x
== path
->pos
.x
&&
302 path
->points
[path
->count
- 1].y
== path
->pos
.y
)
305 path
->newStroke
= FALSE
;
306 return add_points( path
, &path
->pos
, 1, PT_MOVETO
) != NULL
;
309 /* set current position to the last point that was added to the path */
310 static void update_current_pos( struct gdi_path
*path
)
312 assert( path
->count
);
313 path
->pos
= path
->points
[path
->count
- 1];
316 /* close the current figure */
317 static void close_figure( struct gdi_path
*path
)
319 assert( path
->count
);
320 path
->flags
[path
->count
- 1] |= PT_CLOSEFIGURE
;
323 /* add a number of points, starting a new stroke if necessary */
324 static BOOL
add_log_points_new_stroke( DC
*dc
, struct gdi_path
*path
, const POINT
*points
,
325 DWORD count
, BYTE type
)
327 if (!start_new_stroke( path
)) return FALSE
;
328 if (!add_log_points( dc
, path
, points
, count
, type
)) return FALSE
;
329 update_current_pos( path
);
333 /* convert a (flattened) path to a region */
334 static HRGN
path_to_region( const struct gdi_path
*path
, int mode
)
336 int i
, pos
, polygons
, *counts
;
339 if (!path
->count
) return 0;
341 if (!(counts
= malloc( (path
->count
/ 2) * sizeof(*counts
) ))) return 0;
344 assert( path
->flags
[0] == PT_MOVETO
);
345 for (i
= 1; i
< path
->count
; i
++)
347 if (path
->flags
[i
] != PT_MOVETO
) continue;
348 counts
[polygons
++] = i
- pos
;
351 if (i
> pos
+ 1) counts
[polygons
++] = i
- pos
;
353 assert( polygons
<= path
->count
/ 2 );
354 hrgn
= create_polypolygon_region( path
->points
, counts
, polygons
, mode
, NULL
);
361 * Helper function for RoundRect() and Rectangle()
363 static BOOL
PATH_CheckCorners( DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
)
367 /* Convert points to device coordinates */
372 lp_to_dp( dc
, corners
, 2 );
374 /* Make sure first corner is top left and second corner is bottom right */
375 if(corners
[0].x
>corners
[1].x
)
378 corners
[0].x
=corners
[1].x
;
381 if(corners
[0].y
>corners
[1].y
)
384 corners
[0].y
=corners
[1].y
;
388 /* In GM_COMPATIBLE, don't include bottom and right edges */
389 if (dc
->attr
->graphics_mode
== GM_COMPATIBLE
)
391 if (corners
[0].x
== corners
[1].x
) return FALSE
;
392 if (corners
[0].y
== corners
[1].y
) return FALSE
;
399 /* PATH_AddFlatBezier
401 static BOOL
PATH_AddFlatBezier(struct gdi_path
*pPath
, POINT
*pt
, BOOL closed
)
407 pts
= GDI_Bezier( pt
, 4, &no
);
408 if(!pts
) return FALSE
;
410 ret
= (add_points( pPath
, pts
+ 1, no
- 1, PT_LINETO
) != NULL
);
411 if (ret
&& closed
) close_figure( pPath
);
418 * Replaces Beziers with line segments
421 static struct gdi_path
*PATH_FlattenPath(const struct gdi_path
*pPath
)
423 struct gdi_path
*new_path
;
426 if (!(new_path
= alloc_gdi_path( pPath
->count
))) return NULL
;
428 for(srcpt
= 0; srcpt
< pPath
->count
; srcpt
++) {
429 switch(pPath
->flags
[srcpt
] & ~PT_CLOSEFIGURE
) {
432 if (!PATH_AddEntry(new_path
, &pPath
->points
[srcpt
], pPath
->flags
[srcpt
]))
434 free_gdi_path( new_path
);
439 if (!PATH_AddFlatBezier(new_path
, &pPath
->points
[srcpt
-1],
440 pPath
->flags
[srcpt
+2] & PT_CLOSEFIGURE
))
442 free_gdi_path( new_path
);
452 /* PATH_ScaleNormalizedPoint
454 * Scales a normalized point (x, y) with respect to the box whose corners are
455 * passed in "corners". The point is stored in "*pPoint". The normalized
456 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
457 * (1.0, 1.0) correspond to corners[1].
459 static void PATH_ScaleNormalizedPoint(FLOAT_POINT corners
[], double x
,
460 double y
, POINT
*pPoint
)
462 pPoint
->x
= GDI_ROUND( corners
[0].x
+ (corners
[1].x
-corners
[0].x
)*0.5*(x
+1.0) );
463 pPoint
->y
= GDI_ROUND( corners
[0].y
+ (corners
[1].y
-corners
[0].y
)*0.5*(y
+1.0) );
466 /* PATH_NormalizePoint
468 * Normalizes a point with respect to the box whose corners are passed in
469 * "corners". The normalized coordinates are stored in "*pX" and "*pY".
471 static void PATH_NormalizePoint(FLOAT_POINT corners
[],
472 const FLOAT_POINT
*pPoint
,
473 double *pX
, double *pY
)
475 *pX
= (pPoint
->x
-corners
[0].x
)/(corners
[1].x
-corners
[0].x
) * 2.0 - 1.0;
476 *pY
= (pPoint
->y
-corners
[0].y
)/(corners
[1].y
-corners
[0].y
) * 2.0 - 1.0;
481 * Creates a Bezier spline that corresponds to part of an arc and appends the
482 * corresponding points to the path. The start and end angles are passed in
483 * "angleStart" and "angleEnd"; these angles should span a quarter circle
484 * at most. If "startEntryType" is non-zero, an entry of that type for the first
485 * control point is added to the path; otherwise, it is assumed that the current
486 * position is equal to the first control point.
488 static BOOL
PATH_DoArcPart(struct gdi_path
*pPath
, FLOAT_POINT corners
[],
489 double angleStart
, double angleEnd
, BYTE startEntryType
)
492 double xNorm
[4], yNorm
[4];
497 assert(fabs(angleEnd
-angleStart
)<=M_PI_2
);
499 /* FIXME: Is there an easier way of computing this? */
501 /* Compute control points */
502 halfAngle
=(angleEnd
-angleStart
)/2.0;
503 if(fabs(halfAngle
)>1e-8)
505 a
=4.0/3.0*(1-cos(halfAngle
))/sin(halfAngle
);
506 xNorm
[0]=cos(angleStart
);
507 yNorm
[0]=sin(angleStart
);
508 xNorm
[1]=xNorm
[0] - a
*yNorm
[0];
509 yNorm
[1]=yNorm
[0] + a
*xNorm
[0];
510 xNorm
[3]=cos(angleEnd
);
511 yNorm
[3]=sin(angleEnd
);
512 xNorm
[2]=xNorm
[3] + a
*yNorm
[3];
513 yNorm
[2]=yNorm
[3] - a
*xNorm
[3];
518 xNorm
[i
]=cos(angleStart
);
519 yNorm
[i
]=sin(angleStart
);
522 /* Add starting point to path if desired */
523 start
= !startEntryType
;
524 for (i
= start
; i
< 4; i
++) PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &points
[i
]);
525 if (!(type
= add_points( pPath
, points
+ start
, 4 - start
, PT_BEZIERTO
))) return FALSE
;
526 if (!start
) type
[0] = startEntryType
;
530 /* retrieve a flattened path in device coordinates, and optionally its region */
531 /* the DC path is deleted; the returned data must be freed by caller using free_gdi_path() */
532 /* helper for stroke_and_fill_path in the DIB driver */
533 struct gdi_path
*get_gdi_flat_path( DC
*dc
, HRGN
*rgn
)
535 struct gdi_path
*ret
= NULL
;
539 ret
= PATH_FlattenPath( dc
->path
);
541 free_gdi_path( dc
->path
);
543 if (ret
&& rgn
) *rgn
= path_to_region( ret
, dc
->attr
->poly_fill_mode
);
545 else RtlSetLastWin32Error( ERROR_CAN_NOT_COMPLETE
);
550 int get_gdi_path_data( struct gdi_path
*path
, POINT
**pts
, BYTE
**flags
)
553 *flags
= path
->flags
;
557 /***********************************************************************
558 * NtGdiBeginPath (win32u.@)
560 BOOL WINAPI
NtGdiBeginPath( HDC hdc
)
563 DC
*dc
= get_dc_ptr( hdc
);
567 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pBeginPath
);
568 ret
= physdev
->funcs
->pBeginPath( physdev
);
569 release_dc_ptr( dc
);
575 /***********************************************************************
576 * NtGdiEndPath (win32u.@)
578 BOOL WINAPI
NtGdiEndPath( HDC hdc
)
581 DC
*dc
= get_dc_ptr( hdc
);
585 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pEndPath
);
586 ret
= physdev
->funcs
->pEndPath( physdev
);
587 release_dc_ptr( dc
);
593 /******************************************************************************
594 * NtGdiAbortPath (win32u.@)
596 BOOL WINAPI
NtGdiAbortPath( HDC hdc
)
599 DC
*dc
= get_dc_ptr( hdc
);
603 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pAbortPath
);
604 ret
= physdev
->funcs
->pAbortPath( physdev
);
605 release_dc_ptr( dc
);
611 /***********************************************************************
612 * NtGdiCloseFigure (win32u.@)
614 BOOL WINAPI
NtGdiCloseFigure( HDC hdc
)
617 DC
*dc
= get_dc_ptr( hdc
);
621 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pCloseFigure
);
622 ret
= physdev
->funcs
->pCloseFigure( physdev
);
623 release_dc_ptr( dc
);
629 /***********************************************************************
630 * NtGdiGetPath (win32u.@)
632 INT WINAPI
NtGdiGetPath( HDC hdc
, POINT
*points
, BYTE
*types
, INT size
)
635 DC
*dc
= get_dc_ptr( hdc
);
641 RtlSetLastWin32Error( ERROR_CAN_NOT_COMPLETE
);
645 ret
= dc
->path
->count
;
647 else if (size
< dc
->path
->count
)
649 RtlSetLastWin32Error( ERROR_INVALID_PARAMETER
);
653 memcpy( points
, dc
->path
->points
, sizeof(POINT
) * dc
->path
->count
);
654 memcpy( types
, dc
->path
->flags
, sizeof(BYTE
) * dc
->path
->count
);
656 /* Convert the points to logical coordinates */
657 if (dp_to_lp( dc
, points
, dc
->path
->count
))
658 ret
= dc
->path
->count
;
660 /* FIXME: Is this the correct value? */
661 RtlSetLastWin32Error( ERROR_CAN_NOT_COMPLETE
);
664 release_dc_ptr( dc
);
669 /***********************************************************************
670 * NtGdiPathToRegion (win32u.@)
672 HRGN WINAPI
NtGdiPathToRegion( HDC hdc
)
675 DC
*dc
= get_dc_ptr( hdc
);
681 struct gdi_path
*path
= PATH_FlattenPath( dc
->path
);
683 free_gdi_path( dc
->path
);
687 ret
= path_to_region( path
, dc
->attr
->poly_fill_mode
);
688 free_gdi_path( path
);
691 else RtlSetLastWin32Error( ERROR_CAN_NOT_COMPLETE
);
693 release_dc_ptr( dc
);
698 /***********************************************************************
699 * NtGdiFillPath (win32u.@)
701 BOOL WINAPI
NtGdiFillPath( HDC hdc
)
704 DC
*dc
= get_dc_ptr( hdc
);
708 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pFillPath
);
709 ret
= physdev
->funcs
->pFillPath( physdev
);
710 release_dc_ptr( dc
);
716 /***********************************************************************
717 * NtGdiSelectClipPath (win32u.@)
719 BOOL WINAPI
NtGdiSelectClipPath( HDC hdc
, INT mode
)
724 if ((rgn
= NtGdiPathToRegion( hdc
)))
726 ret
= NtGdiExtSelectClipRgn( hdc
, rgn
, mode
) != ERROR
;
727 NtGdiDeleteObjectApp( rgn
);
733 /***********************************************************************
736 static BOOL
pathdrv_BeginPath( PHYSDEV dev
)
738 /* path already open, nothing to do */
743 /***********************************************************************
746 static BOOL
pathdrv_AbortPath( PHYSDEV dev
)
748 DC
*dc
= get_physdev_dc( dev
);
750 path_driver
.pDeleteDC( pop_dc_driver( dc
, &path_driver
));
755 /***********************************************************************
758 static BOOL
pathdrv_EndPath( PHYSDEV dev
)
760 struct path_physdev
*physdev
= get_path_physdev( dev
);
761 DC
*dc
= get_physdev_dc( dev
);
763 dc
->path
= physdev
->path
;
764 pop_dc_driver( dc
, &path_driver
);
770 /***********************************************************************
773 static BOOL
pathdrv_CreateDC( PHYSDEV
*dev
, LPCWSTR device
, LPCWSTR output
, const DEVMODEW
*devmode
)
775 struct path_physdev
*physdev
= malloc( sizeof(*physdev
) );
777 if (!physdev
) return FALSE
;
778 push_dc_driver( dev
, &physdev
->dev
, &path_driver
);
783 /*************************************************************
786 static BOOL
pathdrv_DeleteDC( PHYSDEV dev
)
788 struct path_physdev
*physdev
= get_path_physdev( dev
);
790 free_gdi_path( physdev
->path
);
796 BOOL
PATH_SavePath( DC
*dst
, DC
*src
)
802 if (!(dst
->path
= copy_gdi_path( src
->path
))) return FALSE
;
804 else if ((dev
= find_dc_driver( src
, &path_driver
)))
806 struct path_physdev
*physdev
= get_path_physdev( dev
);
807 if (!(dst
->path
= copy_gdi_path( physdev
->path
))) return FALSE
;
808 dst
->path_open
= TRUE
;
810 else dst
->path
= NULL
;
814 BOOL
PATH_RestorePath( DC
*dst
, DC
*src
)
817 struct path_physdev
*physdev
;
819 if ((dev
= pop_dc_driver( dst
, &path_driver
)))
821 physdev
= get_path_physdev( dev
);
822 free_gdi_path( physdev
->path
);
826 if (src
->path
&& src
->path_open
)
828 if (!path_driver
.pCreateDC( &dst
->physDev
, NULL
, NULL
, NULL
)) return FALSE
;
829 physdev
= get_path_physdev( find_dc_driver( dst
, &path_driver
));
830 physdev
->path
= src
->path
;
831 src
->path_open
= FALSE
;
835 if (dst
->path
) free_gdi_path( dst
->path
);
836 dst
->path
= src
->path
;
842 /*************************************************************
845 static BOOL
pathdrv_MoveTo( PHYSDEV dev
, INT x
, INT y
)
847 struct path_physdev
*physdev
= get_path_physdev( dev
);
848 DC
*dc
= get_physdev_dc( dev
);
850 physdev
->path
->newStroke
= TRUE
;
851 physdev
->path
->pos
.x
= x
;
852 physdev
->path
->pos
.y
= y
;
853 lp_to_dp( dc
, &physdev
->path
->pos
, 1 );
858 /*************************************************************
861 static BOOL
pathdrv_LineTo( PHYSDEV dev
, INT x
, INT y
)
863 struct path_physdev
*physdev
= get_path_physdev( dev
);
864 DC
*dc
= get_physdev_dc( dev
);
869 return add_log_points_new_stroke( dc
, physdev
->path
, &point
, 1, PT_LINETO
);
873 /*************************************************************
876 static BOOL
pathdrv_Rectangle( PHYSDEV dev
, INT x1
, INT y1
, INT x2
, INT y2
)
878 struct path_physdev
*physdev
= get_path_physdev( dev
);
879 DC
*dc
= get_physdev_dc( dev
);
880 POINT corners
[2], points
[4];
883 if (!PATH_CheckCorners( dc
, corners
, x1
, y1
, x2
, y2
)) return TRUE
;
885 points
[0].x
= corners
[1].x
;
886 points
[0].y
= corners
[0].y
;
887 points
[1] = corners
[0];
888 points
[2].x
= corners
[0].x
;
889 points
[2].y
= corners
[1].y
;
890 points
[3] = corners
[1];
891 if (dc
->attr
->arc_direction
== AD_CLOCKWISE
) reverse_points( points
, 4 );
893 if (!(type
= add_points( physdev
->path
, points
, 4, PT_LINETO
))) return FALSE
;
895 close_figure( physdev
->path
);
900 /*************************************************************
903 static BOOL
pathdrv_RoundRect( PHYSDEV dev
, INT x1
, INT y1
, INT x2
, INT y2
, INT ell_width
, INT ell_height
)
905 const double factor
= 0.55428475; /* 4 / 3 * (sqrt(2) - 1) */
906 struct path_physdev
*physdev
= get_path_physdev( dev
);
907 DC
*dc
= get_physdev_dc( dev
);
908 POINT corners
[2], ellipse
[2], points
[16];
910 double width
, height
;
912 if (!ell_width
|| !ell_height
) return pathdrv_Rectangle( dev
, x1
, y1
, x2
, y2
);
914 if (!PATH_CheckCorners( dc
, corners
, x1
, y1
, x2
, y2
)) return TRUE
;
916 ellipse
[0].x
= ellipse
[0].y
= 0;
917 ellipse
[1].x
= ell_width
;
918 ellipse
[1].y
= ell_height
;
919 lp_to_dp( dc
, (POINT
*)&ellipse
, 2 );
920 ell_width
= min( abs( ellipse
[1].x
- ellipse
[0].x
), corners
[1].x
- corners
[0].x
);
921 ell_height
= min( abs( ellipse
[1].y
- ellipse
[0].y
), corners
[1].y
- corners
[0].y
);
922 width
= ell_width
/ 2.0;
923 height
= ell_height
/ 2.0;
926 points
[0].x
= corners
[1].x
;
927 points
[0].y
= corners
[0].y
+ GDI_ROUND( height
);
929 points
[1].x
= corners
[1].x
;
930 points
[1].y
= corners
[0].y
+ GDI_ROUND( height
* (1 - factor
) );
931 points
[2].x
= corners
[1].x
- GDI_ROUND( width
* (1 - factor
) );
932 points
[2].y
= corners
[0].y
;
933 points
[3].x
= corners
[1].x
- GDI_ROUND( width
);
934 points
[3].y
= corners
[0].y
;
935 /* horizontal line */
936 points
[4].x
= corners
[0].x
+ GDI_ROUND( width
);
937 points
[4].y
= corners
[0].y
;
939 points
[5].x
= corners
[0].x
+ GDI_ROUND( width
* (1 - factor
) );
940 points
[5].y
= corners
[0].y
;
941 points
[6].x
= corners
[0].x
;
942 points
[6].y
= corners
[0].y
+ GDI_ROUND( height
* (1 - factor
) );
943 points
[7].x
= corners
[0].x
;
944 points
[7].y
= corners
[0].y
+ GDI_ROUND( height
);
946 points
[8].x
= corners
[0].x
;
947 points
[8].y
= corners
[1].y
- GDI_ROUND( height
);
949 points
[9].x
= corners
[0].x
;
950 points
[9].y
= corners
[1].y
- GDI_ROUND( height
* (1 - factor
) );
951 points
[10].x
= corners
[0].x
+ GDI_ROUND( width
* (1 - factor
) );
952 points
[10].y
= corners
[1].y
;
953 points
[11].x
= corners
[0].x
+ GDI_ROUND( width
);
954 points
[11].y
= corners
[1].y
;
955 /* horizontal line */
956 points
[12].x
= corners
[1].x
- GDI_ROUND( width
);
957 points
[12].y
= corners
[1].y
;
959 points
[13].x
= corners
[1].x
- GDI_ROUND( width
* (1 - factor
) );
960 points
[13].y
= corners
[1].y
;
961 points
[14].x
= corners
[1].x
;
962 points
[14].y
= corners
[1].y
- GDI_ROUND( height
* (1 - factor
) );
963 points
[15].x
= corners
[1].x
;
964 points
[15].y
= corners
[1].y
- GDI_ROUND( height
);
966 if (dc
->attr
->arc_direction
== AD_CLOCKWISE
) reverse_points( points
, 16 );
967 if (!(type
= add_points( physdev
->path
, points
, 16, PT_BEZIERTO
))) return FALSE
;
969 type
[4] = type
[8] = type
[12] = PT_LINETO
;
970 close_figure( physdev
->path
);
975 /*************************************************************
978 static BOOL
pathdrv_Ellipse( PHYSDEV dev
, INT x1
, INT y1
, INT x2
, INT y2
)
980 const double factor
= 0.55428475; /* 4 / 3 * (sqrt(2) - 1) */
981 struct path_physdev
*physdev
= get_path_physdev( dev
);
982 DC
*dc
= get_physdev_dc( dev
);
983 POINT corners
[2], points
[13];
985 double width
, height
;
987 if (!PATH_CheckCorners( dc
, corners
, x1
, y1
, x2
, y2
)) return TRUE
;
989 width
= (corners
[1].x
- corners
[0].x
) / 2.0;
990 height
= (corners
[1].y
- corners
[0].y
) / 2.0;
993 points
[0].x
= corners
[1].x
;
994 points
[0].y
= corners
[0].y
+ GDI_ROUND( height
);
996 points
[1].x
= corners
[1].x
;
997 points
[1].y
= corners
[0].y
+ GDI_ROUND( height
* (1 - factor
) );
998 points
[2].x
= corners
[1].x
- GDI_ROUND( width
* (1 - factor
) );
999 points
[2].y
= corners
[0].y
;
1000 points
[3].x
= corners
[0].x
+ GDI_ROUND( width
);
1001 points
[3].y
= corners
[0].y
;
1003 points
[4].x
= corners
[0].x
+ GDI_ROUND( width
* (1 - factor
) );
1004 points
[4].y
= corners
[0].y
;
1005 points
[5].x
= corners
[0].x
;
1006 points
[5].y
= corners
[0].y
+ GDI_ROUND( height
* (1 - factor
) );
1007 points
[6].x
= corners
[0].x
;
1008 points
[6].y
= corners
[0].y
+ GDI_ROUND( height
);
1010 points
[7].x
= corners
[0].x
;
1011 points
[7].y
= corners
[1].y
- GDI_ROUND( height
* (1 - factor
) );
1012 points
[8].x
= corners
[0].x
+ GDI_ROUND( width
* (1 - factor
) );
1013 points
[8].y
= corners
[1].y
;
1014 points
[9].x
= corners
[0].x
+ GDI_ROUND( width
);
1015 points
[9].y
= corners
[1].y
;
1017 points
[10].x
= corners
[1].x
- GDI_ROUND( width
* (1 - factor
) );
1018 points
[10].y
= corners
[1].y
;
1019 points
[11].x
= corners
[1].x
;
1020 points
[11].y
= corners
[1].y
- GDI_ROUND( height
* (1 - factor
) );
1021 points
[12].x
= corners
[1].x
;
1022 points
[12].y
= corners
[1].y
- GDI_ROUND( height
);
1024 if (dc
->attr
->arc_direction
== AD_CLOCKWISE
) reverse_points( points
, 13 );
1025 if (!(type
= add_points( physdev
->path
, points
, 13, PT_BEZIERTO
))) return FALSE
;
1026 type
[0] = PT_MOVETO
;
1027 close_figure( physdev
->path
);
1034 * Should be called when a call to Arc is performed on a DC that has
1035 * an open path. This adds up to five Bezier splines representing the arc
1036 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
1037 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
1038 * -1 we add 1 extra line from the current DC position to the starting position
1039 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
1042 static BOOL
PATH_Arc( PHYSDEV dev
, INT x1
, INT y1
, INT x2
, INT y2
,
1043 INT xStart
, INT yStart
, INT xEnd
, INT yEnd
, int direction
, int lines
)
1045 DC
*dc
= get_physdev_dc( dev
);
1046 struct path_physdev
*physdev
= get_path_physdev( dev
);
1047 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
=0.0;
1048 /* Initialize angleEndQuadrant to silence gcc's warning */
1050 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
1055 /* FIXME: Do we have to respect newStroke? */
1057 /* Check for zero height / width */
1058 /* FIXME: Only in GM_COMPATIBLE? */
1059 if(x1
==x2
|| y1
==y2
)
1062 /* Convert points to device coordinates */
1067 pointStart
.x
= xStart
;
1068 pointStart
.y
= yStart
;
1071 INTERNAL_LPTODP_FLOAT(dc
, corners
, 2);
1072 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
, 1);
1073 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
, 1);
1075 /* Make sure first corner is top left and second corner is bottom right */
1076 if(corners
[0].x
>corners
[1].x
)
1079 corners
[0].x
=corners
[1].x
;
1082 if(corners
[0].y
>corners
[1].y
)
1085 corners
[0].y
=corners
[1].y
;
1089 /* Compute start and end angle */
1090 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
1091 angleStart
=atan2(y
, x
);
1092 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
1093 angleEnd
=atan2(y
, x
);
1095 /* Make sure the end angle is "on the right side" of the start angle */
1096 if (direction
== AD_CLOCKWISE
)
1098 if(angleEnd
<=angleStart
)
1101 assert(angleEnd
>=angleStart
);
1106 if(angleEnd
>=angleStart
)
1109 assert(angleEnd
<=angleStart
);
1113 /* In GM_COMPATIBLE, don't include bottom and right edges */
1114 if (dc
->attr
->graphics_mode
== GM_COMPATIBLE
)
1120 /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
1121 if (lines
== -1 && !start_new_stroke( physdev
->path
)) return FALSE
;
1123 /* Add the arc to the path with one Bezier spline per quadrant that the
1129 /* Determine the start and end angles for this quadrant */
1132 angleStartQuadrant
=angleStart
;
1133 if (direction
== AD_CLOCKWISE
)
1134 angleEndQuadrant
=(floor(angleStart
/M_PI_2
)+1.0)*M_PI_2
;
1136 angleEndQuadrant
=(ceil(angleStart
/M_PI_2
)-1.0)*M_PI_2
;
1140 angleStartQuadrant
=angleEndQuadrant
;
1141 if (direction
== AD_CLOCKWISE
)
1142 angleEndQuadrant
+=M_PI_2
;
1144 angleEndQuadrant
-=M_PI_2
;
1147 /* Have we reached the last part of the arc? */
1148 if((direction
== AD_CLOCKWISE
&& angleEnd
<angleEndQuadrant
) ||
1149 (direction
== AD_COUNTERCLOCKWISE
&& angleEnd
>angleEndQuadrant
))
1151 /* Adjust the end angle for this quadrant */
1152 angleEndQuadrant
=angleEnd
;
1156 /* Add the Bezier spline to the path */
1157 PATH_DoArcPart(physdev
->path
, corners
, angleStartQuadrant
, angleEndQuadrant
,
1158 start
? (lines
==-1 ? PT_LINETO
: PT_MOVETO
) : 0);
1162 /* chord: close figure. pie: add line and close figure */
1166 update_current_pos( physdev
->path
);
1169 close_figure( physdev
->path
);
1172 centre
.x
= (corners
[0].x
+corners
[1].x
)/2;
1173 centre
.y
= (corners
[0].y
+corners
[1].y
)/2;
1174 if(!PATH_AddEntry(physdev
->path
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
1182 /*************************************************************
1185 static BOOL
pathdrv_AngleArc( PHYSDEV dev
, INT x
, INT y
, DWORD radius
, FLOAT eStartAngle
, FLOAT eSweepAngle
)
1187 int x1
= GDI_ROUND( x
+ cos(eStartAngle
*M_PI
/180) * radius
);
1188 int y1
= GDI_ROUND( y
- sin(eStartAngle
*M_PI
/180) * radius
);
1189 int x2
= GDI_ROUND( x
+ cos((eStartAngle
+eSweepAngle
)*M_PI
/180) * radius
);
1190 int y2
= GDI_ROUND( y
- sin((eStartAngle
+eSweepAngle
)*M_PI
/180) * radius
);
1191 return PATH_Arc( dev
, x
-radius
, y
-radius
, x
+radius
, y
+radius
, x1
, y1
, x2
, y2
,
1192 eSweepAngle
>= 0 ? AD_COUNTERCLOCKWISE
: AD_CLOCKWISE
, -1 );
1196 /*************************************************************
1199 static BOOL
pathdrv_Arc( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
1200 INT xstart
, INT ystart
, INT xend
, INT yend
)
1202 DC
*dc
= get_physdev_dc( dev
);
1203 return PATH_Arc( dev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
,
1204 dc
->attr
->arc_direction
, 0 );
1208 /*************************************************************
1211 static BOOL
pathdrv_ArcTo( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
1212 INT xstart
, INT ystart
, INT xend
, INT yend
)
1214 DC
*dc
= get_physdev_dc( dev
);
1215 return PATH_Arc( dev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
,
1216 dc
->attr
->arc_direction
, -1 );
1220 /*************************************************************
1223 static BOOL
pathdrv_Chord( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
1224 INT xstart
, INT ystart
, INT xend
, INT yend
)
1226 DC
*dc
= get_physdev_dc( dev
);
1227 return PATH_Arc( dev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
,
1228 dc
->attr
->arc_direction
, 1 );
1232 /*************************************************************
1235 static BOOL
pathdrv_Pie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
1236 INT xstart
, INT ystart
, INT xend
, INT yend
)
1238 DC
*dc
= get_physdev_dc( dev
);
1239 return PATH_Arc( dev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
,
1240 dc
->attr
->arc_direction
, 2 );
1244 /*************************************************************
1245 * pathdrv_PolyBezierTo
1247 static BOOL
pathdrv_PolyBezierTo( PHYSDEV dev
, const POINT
*pts
, DWORD cbPoints
)
1249 struct path_physdev
*physdev
= get_path_physdev( dev
);
1250 DC
*dc
= get_physdev_dc( dev
);
1252 return add_log_points_new_stroke( dc
, physdev
->path
, pts
, cbPoints
, PT_BEZIERTO
);
1256 /*************************************************************
1257 * pathdrv_PolyBezier
1259 static BOOL
pathdrv_PolyBezier( PHYSDEV dev
, const POINT
*pts
, DWORD cbPoints
)
1261 struct path_physdev
*physdev
= get_path_physdev( dev
);
1262 DC
*dc
= get_physdev_dc( dev
);
1263 BYTE
*type
= add_log_points( dc
, physdev
->path
, pts
, cbPoints
, PT_BEZIERTO
);
1265 if (!type
) return FALSE
;
1266 type
[0] = PT_MOVETO
;
1271 /*************************************************************
1274 static BOOL
pathdrv_PolyDraw( PHYSDEV dev
, const POINT
*pts
, const BYTE
*types
, DWORD cbPoints
)
1276 struct path_physdev
*physdev
= get_path_physdev( dev
);
1277 struct gdi_path
*path
= physdev
->path
;
1278 DC
*dc
= get_physdev_dc( dev
);
1280 INT i
, lastmove
= 0;
1282 for (i
= 0; i
< path
->count
; i
++) if (path
->flags
[i
] == PT_MOVETO
) lastmove
= i
;
1283 orig_pos
= path
->pos
;
1285 for(i
= 0; i
< cbPoints
; i
++)
1290 path
->newStroke
= TRUE
;
1292 lp_to_dp( dc
, &path
->pos
, 1 );
1293 lastmove
= path
->count
;
1296 case PT_LINETO
| PT_CLOSEFIGURE
:
1297 if (!add_log_points_new_stroke( dc
, path
, &pts
[i
], 1, PT_LINETO
)) return FALSE
;
1300 if ((i
+ 2 < cbPoints
) && (types
[i
+ 1] == PT_BEZIERTO
) &&
1301 (types
[i
+ 2] & ~PT_CLOSEFIGURE
) == PT_BEZIERTO
)
1303 if (!add_log_points_new_stroke( dc
, path
, &pts
[i
], 3, PT_BEZIERTO
)) return FALSE
;
1309 /* restore original position */
1310 path
->pos
= orig_pos
;
1314 if (types
[i
] & PT_CLOSEFIGURE
)
1316 close_figure( path
);
1317 path
->pos
= path
->points
[lastmove
];
1324 /*************************************************************
1325 * pathdrv_PolylineTo
1327 static BOOL
pathdrv_PolylineTo( PHYSDEV dev
, const POINT
*pts
, INT count
)
1329 struct path_physdev
*physdev
= get_path_physdev( dev
);
1330 DC
*dc
= get_physdev_dc( dev
);
1332 if (count
< 1) return FALSE
;
1333 return add_log_points_new_stroke( dc
, physdev
->path
, pts
, count
, PT_LINETO
);
1337 /*************************************************************
1338 * pathdrv_PolyPolygon
1340 static BOOL
pathdrv_PolyPolygon( PHYSDEV dev
, const POINT
* pts
, const INT
* counts
, UINT polygons
)
1342 struct path_physdev
*physdev
= get_path_physdev( dev
);
1343 DC
*dc
= get_physdev_dc( dev
);
1347 if (!polygons
) return FALSE
;
1348 for (poly
= count
= 0; poly
< polygons
; poly
++)
1350 if (counts
[poly
] < 2) return FALSE
;
1351 count
+= counts
[poly
];
1354 type
= add_log_points( dc
, physdev
->path
, pts
, count
, PT_LINETO
);
1355 if (!type
) return FALSE
;
1357 /* make the first point of each polyline a PT_MOVETO, and close the last one */
1358 for (poly
= 0; poly
< polygons
; type
+= counts
[poly
++])
1360 type
[0] = PT_MOVETO
;
1361 type
[counts
[poly
] - 1] = PT_LINETO
| PT_CLOSEFIGURE
;
1367 /*************************************************************
1368 * pathdrv_PolyPolyline
1370 static BOOL
pathdrv_PolyPolyline( PHYSDEV dev
, const POINT
* pts
, const DWORD
* counts
, DWORD polylines
)
1372 struct path_physdev
*physdev
= get_path_physdev( dev
);
1373 DC
*dc
= get_physdev_dc( dev
);
1377 if (!polylines
) return FALSE
;
1378 for (poly
= count
= 0; poly
< polylines
; poly
++)
1380 if (counts
[poly
] < 2) return FALSE
;
1381 count
+= counts
[poly
];
1384 type
= add_log_points( dc
, physdev
->path
, pts
, count
, PT_LINETO
);
1385 if (!type
) return FALSE
;
1387 /* make the first point of each polyline a PT_MOVETO */
1388 for (poly
= 0; poly
< polylines
; type
+= counts
[poly
++]) *type
= PT_MOVETO
;
1393 /**********************************************************************
1396 * internally used by PATH_add_outline
1398 static void PATH_BezierTo(struct gdi_path
*pPath
, POINT
*lppt
, INT n
)
1404 PATH_AddEntry(pPath
, &lppt
[1], PT_LINETO
);
1408 add_points( pPath
, lppt
, 3, PT_BEZIERTO
);
1422 pt
[2].x
= (lppt
[i
+2].x
+ lppt
[i
+1].x
) / 2;
1423 pt
[2].y
= (lppt
[i
+2].y
+ lppt
[i
+1].y
) / 2;
1424 add_points( pPath
, pt
, 3, PT_BEZIERTO
);
1432 add_points( pPath
, pt
, 3, PT_BEZIERTO
);
1436 static BOOL
PATH_add_outline(struct path_physdev
*physdev
, INT x
, INT y
,
1437 TTPOLYGONHEADER
*header
, DWORD size
)
1439 TTPOLYGONHEADER
*start
;
1444 while ((char *)header
< (char *)start
+ size
)
1448 if (header
->dwType
!= TT_POLYGON_TYPE
)
1450 FIXME("Unknown header type %d\n", (int)header
->dwType
);
1454 pt
.x
= x
+ int_from_fixed(header
->pfxStart
.x
);
1455 pt
.y
= y
- int_from_fixed(header
->pfxStart
.y
);
1456 PATH_AddEntry(physdev
->path
, &pt
, PT_MOVETO
);
1458 curve
= (TTPOLYCURVE
*)(header
+ 1);
1460 while ((char *)curve
< (char *)header
+ header
->cb
)
1462 /*TRACE("curve->wType %d\n", curve->wType);*/
1464 switch(curve
->wType
)
1470 for (i
= 0; i
< curve
->cpfx
; i
++)
1472 pt
.x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1473 pt
.y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1474 PATH_AddEntry(physdev
->path
, &pt
, PT_LINETO
);
1479 case TT_PRIM_QSPLINE
:
1480 case TT_PRIM_CSPLINE
:
1484 POINT
*pts
= malloc( (curve
->cpfx
+ 1) * sizeof(POINT
) );
1486 if (!pts
) return FALSE
;
1488 ptfx
= *(POINTFX
*)((char *)curve
- sizeof(POINTFX
));
1490 pts
[0].x
= x
+ int_from_fixed(ptfx
.x
);
1491 pts
[0].y
= y
- int_from_fixed(ptfx
.y
);
1493 for(i
= 0; i
< curve
->cpfx
; i
++)
1495 pts
[i
+ 1].x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1496 pts
[i
+ 1].y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1499 PATH_BezierTo(physdev
->path
, pts
, curve
->cpfx
+ 1);
1506 FIXME("Unknown curve type %04x\n", curve
->wType
);
1510 curve
= (TTPOLYCURVE
*)&curve
->apfx
[curve
->cpfx
];
1513 header
= (TTPOLYGONHEADER
*)((char *)header
+ header
->cb
);
1516 close_figure( physdev
->path
);
1520 /*************************************************************
1521 * pathdrv_ExtTextOut
1523 static BOOL
pathdrv_ExtTextOut( PHYSDEV dev
, INT x
, INT y
, UINT flags
, const RECT
*lprc
,
1524 LPCWSTR str
, UINT count
, const INT
*dx
)
1526 struct path_physdev
*physdev
= get_path_physdev( dev
);
1527 unsigned int idx
, ggo_flags
= GGO_NATIVE
;
1528 POINT offset
= {0, 0};
1530 if (!count
) return TRUE
;
1531 if (flags
& ETO_GLYPH_INDEX
) ggo_flags
|= GGO_GLYPH_INDEX
;
1533 for (idx
= 0; idx
< count
; idx
++)
1535 static const MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
1540 dwSize
= NtGdiGetGlyphOutline( dev
->hdc
, str
[idx
], ggo_flags
, &gm
, 0, NULL
, &identity
, FALSE
);
1541 if (dwSize
== GDI_ERROR
) continue;
1543 /* add outline only if char is printable */
1546 outline
= malloc( dwSize
);
1547 if (!outline
) return FALSE
;
1549 NtGdiGetGlyphOutline( dev
->hdc
, str
[idx
], ggo_flags
, &gm
, dwSize
, outline
, &identity
, FALSE
);
1550 PATH_add_outline(physdev
, x
+ offset
.x
, y
+ offset
.y
, outline
, dwSize
);
1559 offset
.x
+= dx
[idx
* 2];
1560 offset
.y
+= dx
[idx
* 2 + 1];
1563 offset
.x
+= dx
[idx
];
1567 offset
.x
+= gm
.gmCellIncX
;
1568 offset
.y
+= gm
.gmCellIncY
;
1575 /*************************************************************
1576 * pathdrv_CloseFigure
1578 static BOOL
pathdrv_CloseFigure( PHYSDEV dev
)
1580 struct path_physdev
*physdev
= get_path_physdev( dev
);
1582 /* Set PT_CLOSEFIGURE on the last entry and start a new stroke */
1583 /* It is not necessary to draw a line, PT_CLOSEFIGURE is a virtual closing line itself */
1584 if (physdev
->path
->count
) close_figure( physdev
->path
);
1589 /*******************************************************************
1590 * NtGdiFlattenPath (win32u.@)
1592 BOOL WINAPI
NtGdiFlattenPath( HDC hdc
)
1594 struct gdi_path
*path
;
1598 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1600 if (!dc
->path
) RtlSetLastWin32Error( ERROR_CAN_NOT_COMPLETE
);
1601 else if ((path
= PATH_FlattenPath( dc
->path
)))
1603 free_gdi_path( dc
->path
);
1608 release_dc_ptr( dc
);
1613 #define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1615 static struct gdi_path
*PATH_WidenPath(DC
*dc
)
1617 INT i
, j
, numStrokes
, penWidth
, penWidthIn
, penWidthOut
, size
, penStyle
;
1618 struct gdi_path
*flat_path
, *pNewPath
, **pStrokes
= NULL
, **new_strokes
, *pUpPath
, *pDownPath
;
1621 DWORD obj_type
, joint
, endcap
, penType
;
1623 size
= NtGdiExtGetObjectW( dc
->hPen
, 0, NULL
);
1625 RtlSetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1629 elp
= malloc( size
);
1630 NtGdiExtGetObjectW( dc
->hPen
, size
, elp
);
1632 obj_type
= get_gdi_object_type(dc
->hPen
);
1636 penStyle
= ((LOGPEN
*)elp
)->lopnStyle
;
1638 case NTGDI_OBJ_EXTPEN
:
1639 penStyle
= elp
->elpPenStyle
;
1642 RtlSetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1647 penWidth
= elp
->elpWidth
;
1650 endcap
= (PS_ENDCAP_MASK
& penStyle
);
1651 joint
= (PS_JOIN_MASK
& penStyle
);
1652 penType
= (PS_TYPE_MASK
& penStyle
);
1654 /* The function cannot apply to cosmetic pens */
1655 if(obj_type
== OBJ_EXTPEN
&& penType
== PS_COSMETIC
) {
1656 RtlSetLastWin32Error(ERROR_CAN_NOT_COMPLETE
);
1660 if (!(flat_path
= PATH_FlattenPath( dc
->path
))) return NULL
;
1662 penWidthIn
= penWidth
/ 2;
1663 penWidthOut
= penWidth
/ 2;
1664 if(penWidthIn
+ penWidthOut
< penWidth
)
1669 for(i
= 0, j
= 0; i
< flat_path
->count
; i
++, j
++) {
1671 if((i
== 0 || (flat_path
->flags
[i
-1] & PT_CLOSEFIGURE
)) &&
1672 (flat_path
->flags
[i
] != PT_MOVETO
)) {
1673 ERR("Expected PT_MOVETO %s, got path flag %c\n",
1674 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1675 flat_path
->flags
[i
]);
1676 free_gdi_path( flat_path
);
1679 switch(flat_path
->flags
[i
]) {
1683 new_strokes
= realloc( pStrokes
, numStrokes
* sizeof(*pStrokes
) );
1686 free_gdi_path(flat_path
);
1690 pStrokes
= new_strokes
;
1691 pStrokes
[numStrokes
- 1] = alloc_gdi_path(0);
1694 case (PT_LINETO
| PT_CLOSEFIGURE
):
1695 point
.x
= flat_path
->points
[i
].x
;
1696 point
.y
= flat_path
->points
[i
].y
;
1697 PATH_AddEntry(pStrokes
[numStrokes
- 1], &point
, flat_path
->flags
[i
]);
1700 /* should never happen because of the FlattenPath call */
1701 ERR("Should never happen\n");
1704 ERR("Got path flag %c\n", flat_path
->flags
[i
]);
1705 for(i
= 0; i
< numStrokes
; i
++) free_gdi_path(pStrokes
[i
]);
1707 free_gdi_path(flat_path
);
1712 pNewPath
= alloc_gdi_path( flat_path
->count
);
1714 for(i
= 0; i
< numStrokes
; i
++) {
1715 pUpPath
= alloc_gdi_path( pStrokes
[i
]->count
);
1716 pDownPath
= alloc_gdi_path( pStrokes
[i
]->count
);
1718 for(j
= 0; j
< pStrokes
[i
]->count
; j
++) {
1719 /* Beginning or end of the path if not closed */
1720 if((!(pStrokes
[i
]->flags
[pStrokes
[i
]->count
- 1] & PT_CLOSEFIGURE
)) && (j
== 0 || j
== pStrokes
[i
]->count
- 1) ) {
1721 /* Compute segment angle */
1722 double xo
, yo
, xa
, ya
, theta
;
1724 FLOAT_POINT corners
[2];
1726 xo
= pStrokes
[i
]->points
[j
].x
;
1727 yo
= pStrokes
[i
]->points
[j
].y
;
1728 xa
= pStrokes
[i
]->points
[1].x
;
1729 ya
= pStrokes
[i
]->points
[1].y
;
1732 xa
= pStrokes
[i
]->points
[j
- 1].x
;
1733 ya
= pStrokes
[i
]->points
[j
- 1].y
;
1734 xo
= pStrokes
[i
]->points
[j
].x
;
1735 yo
= pStrokes
[i
]->points
[j
].y
;
1737 theta
= atan2( ya
- yo
, xa
- xo
);
1739 case PS_ENDCAP_SQUARE
:
1740 pt
.x
= xo
+ round(sqrt(2) * penWidthOut
* cos(M_PI_4
+ theta
));
1741 pt
.y
= yo
+ round(sqrt(2) * penWidthOut
* sin(M_PI_4
+ theta
));
1742 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
) );
1743 pt
.x
= xo
+ round(sqrt(2) * penWidthIn
* cos(- M_PI_4
+ theta
));
1744 pt
.y
= yo
+ round(sqrt(2) * penWidthIn
* sin(- M_PI_4
+ theta
));
1745 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1747 case PS_ENDCAP_FLAT
:
1748 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1749 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1750 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1751 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1752 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1753 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1755 case PS_ENDCAP_ROUND
:
1757 corners
[0].x
= xo
- penWidthIn
;
1758 corners
[0].y
= yo
- penWidthIn
;
1759 corners
[1].x
= xo
+ penWidthOut
;
1760 corners
[1].y
= yo
+ penWidthOut
;
1761 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI_2
, theta
+ 3 * M_PI_4
, (j
== 0 ? PT_MOVETO
: 0));
1762 PATH_DoArcPart(pUpPath
,corners
, theta
+ 3 * M_PI_4
, theta
+ M_PI
, 0);
1763 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI
, theta
+ 5 * M_PI_4
, 0);
1764 PATH_DoArcPart(pUpPath
,corners
, theta
+ 5 * M_PI_4
, theta
+ 3 * M_PI_2
, 0);
1768 /* Corpse of the path */
1772 double xa
, ya
, xb
, yb
, xo
, yo
;
1773 double alpha
, theta
, miterWidth
;
1774 DWORD _joint
= joint
;
1776 struct gdi_path
*pInsidePath
, *pOutsidePath
;
1777 if(j
> 0 && j
< pStrokes
[i
]->count
- 1) {
1782 previous
= pStrokes
[i
]->count
- 1;
1789 xo
= pStrokes
[i
]->points
[j
].x
;
1790 yo
= pStrokes
[i
]->points
[j
].y
;
1791 xa
= pStrokes
[i
]->points
[previous
].x
;
1792 ya
= pStrokes
[i
]->points
[previous
].y
;
1793 xb
= pStrokes
[i
]->points
[next
].x
;
1794 yb
= pStrokes
[i
]->points
[next
].y
;
1795 theta
= atan2( yo
- ya
, xo
- xa
);
1796 alpha
= atan2( yb
- yo
, xb
- xo
) - theta
;
1797 if (alpha
> 0) alpha
-= M_PI
;
1799 if(_joint
== PS_JOIN_MITER
&& dc
->attr
->miter_limit
< fabs(1 / sin(alpha
/2))) {
1800 _joint
= PS_JOIN_BEVEL
;
1803 pInsidePath
= pUpPath
;
1804 pOutsidePath
= pDownPath
;
1806 else if(alpha
< 0) {
1807 pInsidePath
= pDownPath
;
1808 pOutsidePath
= pUpPath
;
1813 /* Inside angle points */
1815 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1816 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1819 pt
.x
= xo
+ round( penWidthIn
* cos(theta
+ M_PI_2
) );
1820 pt
.y
= yo
+ round( penWidthIn
* sin(theta
+ M_PI_2
) );
1822 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1824 pt
.x
= xo
+ round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1825 pt
.y
= yo
+ round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1828 pt
.x
= xo
- round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1829 pt
.y
= yo
- round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1831 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1832 /* Outside angle point */
1834 case PS_JOIN_MITER
:
1835 miterWidth
= fabs(penWidthOut
/ cos(M_PI_2
- fabs(alpha
) / 2));
1836 pt
.x
= xo
+ round( miterWidth
* cos(theta
+ alpha
/ 2) );
1837 pt
.y
= yo
+ round( miterWidth
* sin(theta
+ alpha
/ 2) );
1838 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1840 case PS_JOIN_BEVEL
:
1842 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1843 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1846 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1847 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1849 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1851 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1852 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1855 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1856 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1858 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1860 case PS_JOIN_ROUND
:
1863 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1864 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1867 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1868 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1870 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1871 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ alpha
/ 2) );
1872 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ alpha
/ 2) );
1873 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1875 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1876 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1879 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1880 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1882 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1887 type
= add_points( pNewPath
, pUpPath
->points
, pUpPath
->count
, PT_LINETO
);
1888 type
[0] = PT_MOVETO
;
1889 reverse_points( pDownPath
->points
, pDownPath
->count
);
1890 type
= add_points( pNewPath
, pDownPath
->points
, pDownPath
->count
, PT_LINETO
);
1891 if (pStrokes
[i
]->flags
[pStrokes
[i
]->count
- 1] & PT_CLOSEFIGURE
) type
[0] = PT_MOVETO
;
1893 free_gdi_path( pStrokes
[i
] );
1894 free_gdi_path( pUpPath
);
1895 free_gdi_path( pDownPath
);
1898 free_gdi_path( flat_path
);
1903 /*******************************************************************
1904 * NtGdiStrokeAndFillPath (win32u.@)
1906 BOOL WINAPI
NtGdiStrokeAndFillPath( HDC hdc
)
1909 DC
*dc
= get_dc_ptr( hdc
);
1913 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pStrokeAndFillPath
);
1914 ret
= physdev
->funcs
->pStrokeAndFillPath( physdev
);
1915 release_dc_ptr( dc
);
1921 /*******************************************************************
1922 * NtGdiStrokePath (win32u.@)
1924 BOOL WINAPI
NtGdiStrokePath( HDC hdc
)
1927 DC
*dc
= get_dc_ptr( hdc
);
1931 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pStrokePath
);
1932 ret
= physdev
->funcs
->pStrokePath( physdev
);
1933 release_dc_ptr( dc
);
1939 /*******************************************************************
1940 * NtGdiWidenPath (win32u.@)
1942 BOOL WINAPI
NtGdiWidenPath( HDC hdc
)
1944 struct gdi_path
*path
;
1948 if (!(dc
= get_dc_ptr( hdc
))) return FALSE
;
1950 if (!dc
->path
) RtlSetLastWin32Error( ERROR_CAN_NOT_COMPLETE
);
1951 else if ((path
= PATH_WidenPath( dc
)))
1953 free_gdi_path( dc
->path
);
1958 release_dc_ptr( dc
);
1963 /***********************************************************************
1964 * null driver fallback implementations
1967 BOOL
nulldrv_BeginPath( PHYSDEV dev
)
1969 DC
*dc
= get_nulldrv_dc( dev
);
1970 struct path_physdev
*physdev
;
1971 struct gdi_path
*path
= alloc_gdi_path(0);
1973 if (!path
) return FALSE
;
1974 if (!path_driver
.pCreateDC( &dc
->physDev
, NULL
, NULL
, NULL
))
1976 free_gdi_path( path
);
1979 physdev
= get_path_physdev( find_dc_driver( dc
, &path_driver
));
1980 physdev
->path
= path
;
1981 path
->pos
= dc
->attr
->cur_pos
;
1982 lp_to_dp( dc
, &path
->pos
, 1 );
1983 if (dc
->path
) free_gdi_path( dc
->path
);
1988 BOOL
nulldrv_EndPath( PHYSDEV dev
)
1990 RtlSetLastWin32Error( ERROR_CAN_NOT_COMPLETE
);
1994 BOOL
nulldrv_AbortPath( PHYSDEV dev
)
1996 DC
*dc
= get_nulldrv_dc( dev
);
1998 if (dc
->path
) free_gdi_path( dc
->path
);
2003 BOOL
nulldrv_CloseFigure( PHYSDEV dev
)
2005 RtlSetLastWin32Error( ERROR_CAN_NOT_COMPLETE
);
2009 BOOL
nulldrv_FillPath( PHYSDEV dev
)
2011 if (NtGdiGetPath( dev
->hdc
, NULL
, NULL
, 0 ) == -1) return FALSE
;
2012 NtGdiAbortPath( dev
->hdc
);
2016 BOOL
nulldrv_StrokeAndFillPath( PHYSDEV dev
)
2018 if (NtGdiGetPath( dev
->hdc
, NULL
, NULL
, 0 ) == -1) return FALSE
;
2019 NtGdiAbortPath( dev
->hdc
);
2023 BOOL
nulldrv_StrokePath( PHYSDEV dev
)
2025 if (NtGdiGetPath( dev
->hdc
, NULL
, NULL
, 0 ) == -1) return FALSE
;
2026 NtGdiAbortPath( dev
->hdc
);
2030 const struct gdi_dc_funcs path_driver
=
2032 NULL
, /* pAbortDoc */
2033 pathdrv_AbortPath
, /* pAbortPath */
2034 NULL
, /* pAlphaBlend */
2035 pathdrv_AngleArc
, /* pAngleArc */
2036 pathdrv_Arc
, /* pArc */
2037 pathdrv_ArcTo
, /* pArcTo */
2038 pathdrv_BeginPath
, /* pBeginPath */
2039 NULL
, /* pBlendImage */
2040 pathdrv_Chord
, /* pChord */
2041 pathdrv_CloseFigure
, /* pCloseFigure */
2042 NULL
, /* pCreateCompatibleDC */
2043 pathdrv_CreateDC
, /* pCreateDC */
2044 pathdrv_DeleteDC
, /* pDeleteDC */
2045 NULL
, /* pDeleteObject */
2046 pathdrv_Ellipse
, /* pEllipse */
2048 NULL
, /* pEndPage */
2049 pathdrv_EndPath
, /* pEndPath */
2050 NULL
, /* pEnumFonts */
2051 NULL
, /* pExtEscape */
2052 NULL
, /* pExtFloodFill */
2053 pathdrv_ExtTextOut
, /* pExtTextOut */
2054 NULL
, /* pFillPath */
2055 NULL
, /* pFillRgn */
2056 NULL
, /* pFontIsLinked */
2057 NULL
, /* pFrameRgn */
2058 NULL
, /* pGetBoundsRect */
2059 NULL
, /* pGetCharABCWidths */
2060 NULL
, /* pGetCharABCWidthsI */
2061 NULL
, /* pGetCharWidth */
2062 NULL
, /* pGetCharWidthInfo */
2063 NULL
, /* pGetDeviceCaps */
2064 NULL
, /* pGetDeviceGammaRamp */
2065 NULL
, /* pGetFontData */
2066 NULL
, /* pGetFontRealizationInfo */
2067 NULL
, /* pGetFontUnicodeRanges */
2068 NULL
, /* pGetGlyphIndices */
2069 NULL
, /* pGetGlyphOutline */
2070 NULL
, /* pGetICMProfile */
2071 NULL
, /* pGetImage */
2072 NULL
, /* pGetKerningPairs */
2073 NULL
, /* pGetNearestColor */
2074 NULL
, /* pGetOutlineTextMetrics */
2075 NULL
, /* pGetPixel */
2076 NULL
, /* pGetSystemPaletteEntries */
2077 NULL
, /* pGetTextCharsetInfo */
2078 NULL
, /* pGetTextExtentExPoint */
2079 NULL
, /* pGetTextExtentExPointI */
2080 NULL
, /* pGetTextFace */
2081 NULL
, /* pGetTextMetrics */
2082 NULL
, /* pGradientFill */
2083 NULL
, /* pInvertRgn */
2084 pathdrv_LineTo
, /* pLineTo */
2085 pathdrv_MoveTo
, /* pMoveTo */
2086 NULL
, /* pPaintRgn */
2088 pathdrv_Pie
, /* pPie */
2089 pathdrv_PolyBezier
, /* pPolyBezier */
2090 pathdrv_PolyBezierTo
, /* pPolyBezierTo */
2091 pathdrv_PolyDraw
, /* pPolyDraw */
2092 pathdrv_PolyPolygon
, /* pPolyPolygon */
2093 pathdrv_PolyPolyline
, /* pPolyPolyline */
2094 pathdrv_PolylineTo
, /* pPolylineTo */
2095 NULL
, /* pPutImage */
2096 NULL
, /* pRealizeDefaultPalette */
2097 NULL
, /* pRealizePalette */
2098 pathdrv_Rectangle
, /* pRectangle */
2099 NULL
, /* pResetDC */
2100 pathdrv_RoundRect
, /* pRoundRect */
2101 NULL
, /* pSelectBitmap */
2102 NULL
, /* pSelectBrush */
2103 NULL
, /* pSelectFont */
2104 NULL
, /* pSelectPen */
2105 NULL
, /* pSetBkColor */
2106 NULL
, /* pSetBoundsRect */
2107 NULL
, /* pSetDCBrushColor */
2108 NULL
, /* pSetDCPenColor */
2109 NULL
, /* pSetDIBitsToDevice */
2110 NULL
, /* pSetDeviceClipping */
2111 NULL
, /* pSetDeviceGammaRamp */
2112 NULL
, /* pSetPixel */
2113 NULL
, /* pSetTextColor */
2114 NULL
, /* pStartDoc */
2115 NULL
, /* pStartPage */
2116 NULL
, /* pStretchBlt */
2117 NULL
, /* pStretchDIBits */
2118 NULL
, /* pStrokeAndFillPath */
2119 NULL
, /* pStrokePath */
2120 NULL
, /* pUnrealizePalette */
2121 NULL
, /* pD3DKMTCheckVidPnExclusiveOwnership */
2122 NULL
, /* pD3DKMTCloseAdapter */
2123 NULL
, /* pD3DKMTOpenAdapterFromLuid */
2124 NULL
, /* pD3DKMTQueryVideoMemoryInfo */
2125 NULL
, /* pD3DKMTSetVidPnSourceOwner */
2126 GDI_PRIORITY_PATH_DRV
/* priority */