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
25 #include "wine/port.h"
32 #if defined(HAVE_FLOAT_H)
41 #include "gdi_private.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(gdi
);
46 /* Notes on the implementation
48 * The implementation is based on dynamically resizable arrays of points and
49 * flags. I dithered for a bit before deciding on this implementation, and
50 * I had even done a bit of work on a linked list version before switching
51 * to arrays. It's a bit of a tradeoff. When you use linked lists, the
52 * implementation of FlattenPath is easier, because you can rip the
53 * PT_BEZIERTO entries out of the middle of the list and link the
54 * corresponding PT_LINETO entries in. However, when you use arrays,
55 * PathToRegion becomes easier, since you can essentially just pass your array
56 * of points to CreatePolyPolygonRgn. Also, if I'd used linked lists, I would
57 * have had the extra effort of creating a chunk-based allocation scheme
58 * in order to use memory effectively. That's why I finally decided to use
59 * arrays. Note by the way that the array based implementation has the same
60 * linear time complexity that linked lists would have since the arrays grow
63 * The points are stored in the path in device coordinates. This is
64 * consistent with the way Windows does things (for instance, see the Win32
65 * SDK documentation for GetPath).
67 * The word "stroke" appears in several places (e.g. in the flag
68 * GdiPath.newStroke). A stroke consists of a PT_MOVETO followed by one or
69 * more PT_LINETOs or PT_BEZIERTOs, up to, but not including, the next
70 * PT_MOVETO. Note that this is not the same as the definition of a figure;
71 * a figure can contain several strokes.
76 #define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
77 #define GROW_FACTOR_NUMER 2 /* Numerator of grow factor for the array */
78 #define GROW_FACTOR_DENOM 1 /* Denominator of grow factor */
80 /* A floating point version of the POINT structure */
81 typedef struct tagFLOAT_POINT
89 struct gdi_physdev dev
;
93 static inline struct path_physdev
*get_path_physdev( PHYSDEV dev
)
95 return (struct path_physdev
*)dev
;
98 static inline void pop_path_driver( DC
*dc
)
100 PHYSDEV dev
= pop_dc_driver( &dc
->physDev
);
101 assert( dev
->funcs
== &path_driver
);
102 HeapFree( GetProcessHeap(), 0, dev
);
106 /* Performs a world-to-viewport transformation on the specified point (which
107 * is in floating point format).
109 static inline void INTERNAL_LPTODP_FLOAT(DC
*dc
, FLOAT_POINT
*point
)
113 /* Perform the transformation */
116 point
->x
= x
* dc
->xformWorld2Vport
.eM11
+ y
* dc
->xformWorld2Vport
.eM21
+ dc
->xformWorld2Vport
.eDx
;
117 point
->y
= x
* dc
->xformWorld2Vport
.eM12
+ y
* dc
->xformWorld2Vport
.eM22
+ dc
->xformWorld2Vport
.eDy
;
120 static inline INT
int_from_fixed(FIXED f
)
122 return (f
.fract
>= 0x8000) ? (f
.value
+ 1) : f
.value
;
128 * Removes all entries from the path and sets the path state to PATH_Null.
130 static void PATH_EmptyPath(GdiPath
*pPath
)
132 pPath
->state
=PATH_Null
;
133 pPath
->numEntriesUsed
=0;
136 /* PATH_ReserveEntries
138 * Ensures that at least "numEntries" entries (for points and flags) have
139 * been allocated; allocates larger arrays and copies the existing entries
140 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
142 static BOOL
PATH_ReserveEntries(GdiPath
*pPath
, INT numEntries
)
144 INT numEntriesToAllocate
;
148 assert(numEntries
>=0);
150 /* Do we have to allocate more memory? */
151 if(numEntries
> pPath
->numEntriesAllocated
)
153 /* Find number of entries to allocate. We let the size of the array
154 * grow exponentially, since that will guarantee linear time
156 if(pPath
->numEntriesAllocated
)
158 numEntriesToAllocate
=pPath
->numEntriesAllocated
;
159 while(numEntriesToAllocate
<numEntries
)
160 numEntriesToAllocate
=numEntriesToAllocate
*GROW_FACTOR_NUMER
/
164 numEntriesToAllocate
=numEntries
;
166 /* Allocate new arrays */
167 pPointsNew
=HeapAlloc( GetProcessHeap(), 0, numEntriesToAllocate
* sizeof(POINT
) );
170 pFlagsNew
=HeapAlloc( GetProcessHeap(), 0, numEntriesToAllocate
* sizeof(BYTE
) );
173 HeapFree( GetProcessHeap(), 0, pPointsNew
);
177 /* Copy old arrays to new arrays and discard old arrays */
180 assert(pPath
->pFlags
);
182 memcpy(pPointsNew
, pPath
->pPoints
,
183 sizeof(POINT
)*pPath
->numEntriesUsed
);
184 memcpy(pFlagsNew
, pPath
->pFlags
,
185 sizeof(BYTE
)*pPath
->numEntriesUsed
);
187 HeapFree( GetProcessHeap(), 0, pPath
->pPoints
);
188 HeapFree( GetProcessHeap(), 0, pPath
->pFlags
);
190 pPath
->pPoints
=pPointsNew
;
191 pPath
->pFlags
=pFlagsNew
;
192 pPath
->numEntriesAllocated
=numEntriesToAllocate
;
200 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
201 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
202 * successful, FALSE otherwise (e.g. if not enough memory was available).
204 static BOOL
PATH_AddEntry(GdiPath
*pPath
, const POINT
*pPoint
, BYTE flags
)
206 /* FIXME: If newStroke is true, perhaps we want to check that we're
207 * getting a PT_MOVETO
209 TRACE("(%d,%d) - %d\n", pPoint
->x
, pPoint
->y
, flags
);
211 /* Check that path is open */
212 if(pPath
->state
!=PATH_Open
)
215 /* Reserve enough memory for an extra path entry */
216 if(!PATH_ReserveEntries(pPath
, pPath
->numEntriesUsed
+1))
219 /* Store information in path entry */
220 pPath
->pPoints
[pPath
->numEntriesUsed
]=*pPoint
;
221 pPath
->pFlags
[pPath
->numEntriesUsed
]=flags
;
223 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
224 if((flags
& PT_CLOSEFIGURE
) == PT_CLOSEFIGURE
)
225 pPath
->newStroke
=TRUE
;
227 /* Increment entry count */
228 pPath
->numEntriesUsed
++;
233 /* start a new path stroke if necessary */
234 static BOOL
start_new_stroke( struct path_physdev
*physdev
)
238 if (!physdev
->path
->newStroke
) return TRUE
;
239 physdev
->path
->newStroke
= FALSE
;
240 GetCurrentPositionEx( physdev
->dev
.hdc
, &pos
);
241 LPtoDP( physdev
->dev
.hdc
, &pos
, 1 );
242 return PATH_AddEntry( physdev
->path
, &pos
, PT_MOVETO
);
245 /* PATH_AssignGdiPath
247 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
248 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
249 * not just the pointers. Since this means that the arrays in pPathDest may
250 * need to be resized, pPathDest should have been initialized using
251 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
252 * not a copy constructor).
253 * Returns TRUE if successful, else FALSE.
255 static BOOL
PATH_AssignGdiPath(GdiPath
*pPathDest
, const GdiPath
*pPathSrc
)
257 /* Make sure destination arrays are big enough */
258 if(!PATH_ReserveEntries(pPathDest
, pPathSrc
->numEntriesUsed
))
261 /* Perform the copy operation */
262 memcpy(pPathDest
->pPoints
, pPathSrc
->pPoints
,
263 sizeof(POINT
)*pPathSrc
->numEntriesUsed
);
264 memcpy(pPathDest
->pFlags
, pPathSrc
->pFlags
,
265 sizeof(BYTE
)*pPathSrc
->numEntriesUsed
);
267 pPathDest
->state
=pPathSrc
->state
;
268 pPathDest
->numEntriesUsed
=pPathSrc
->numEntriesUsed
;
269 pPathDest
->newStroke
=pPathSrc
->newStroke
;
276 * Helper function for PATH_RoundRect() and PATH_Rectangle()
278 static BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
)
282 /* Convert points to device coordinates */
287 if(!LPtoDP(dc
->hSelf
, corners
, 2))
290 /* Make sure first corner is top left and second corner is bottom right */
291 if(corners
[0].x
>corners
[1].x
)
294 corners
[0].x
=corners
[1].x
;
297 if(corners
[0].y
>corners
[1].y
)
300 corners
[0].y
=corners
[1].y
;
304 /* In GM_COMPATIBLE, don't include bottom and right edges */
305 if(dc
->GraphicsMode
==GM_COMPATIBLE
)
314 /* PATH_AddFlatBezier
316 static BOOL
PATH_AddFlatBezier(GdiPath
*pPath
, POINT
*pt
, BOOL closed
)
321 pts
= GDI_Bezier( pt
, 4, &no
);
322 if(!pts
) return FALSE
;
324 for(i
= 1; i
< no
; i
++)
325 PATH_AddEntry(pPath
, &pts
[i
], (i
== no
-1 && closed
) ? PT_LINETO
| PT_CLOSEFIGURE
: PT_LINETO
);
326 HeapFree( GetProcessHeap(), 0, pts
);
332 * Replaces Beziers with line segments
335 static BOOL
PATH_FlattenPath(GdiPath
*pPath
)
340 memset(&newPath
, 0, sizeof(newPath
));
341 newPath
.state
= PATH_Open
;
342 for(srcpt
= 0; srcpt
< pPath
->numEntriesUsed
; srcpt
++) {
343 switch(pPath
->pFlags
[srcpt
] & ~PT_CLOSEFIGURE
) {
346 PATH_AddEntry(&newPath
, &pPath
->pPoints
[srcpt
],
347 pPath
->pFlags
[srcpt
]);
350 PATH_AddFlatBezier(&newPath
, &pPath
->pPoints
[srcpt
-1],
351 pPath
->pFlags
[srcpt
+2] & PT_CLOSEFIGURE
);
356 newPath
.state
= PATH_Closed
;
357 PATH_AssignGdiPath(pPath
, &newPath
);
358 PATH_DestroyGdiPath(&newPath
);
364 * Creates a region from the specified path using the specified polygon
365 * filling mode. The path is left unchanged. A handle to the region that
366 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
367 * error occurs, SetLastError is called with the appropriate value and
370 static BOOL
PATH_PathToRegion(GdiPath
*pPath
, INT nPolyFillMode
,
373 int numStrokes
, iStroke
, i
;
374 INT
*pNumPointsInStroke
;
377 PATH_FlattenPath(pPath
);
379 /* FIXME: What happens when number of points is zero? */
381 /* First pass: Find out how many strokes there are in the path */
382 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
384 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
385 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
388 /* Allocate memory for number-of-points-in-stroke array */
389 pNumPointsInStroke
=HeapAlloc( GetProcessHeap(), 0, sizeof(int) * numStrokes
);
390 if(!pNumPointsInStroke
)
392 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
396 /* Second pass: remember number of points in each polygon */
397 iStroke
=-1; /* Will get incremented to 0 at beginning of first stroke */
398 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
400 /* Is this the beginning of a new stroke? */
401 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
404 pNumPointsInStroke
[iStroke
]=0;
407 pNumPointsInStroke
[iStroke
]++;
410 /* Create a region from the strokes */
411 hrgn
=CreatePolyPolygonRgn(pPath
->pPoints
, pNumPointsInStroke
,
412 numStrokes
, nPolyFillMode
);
414 /* Free memory for number-of-points-in-stroke array */
415 HeapFree( GetProcessHeap(), 0, pNumPointsInStroke
);
419 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
428 /* PATH_ScaleNormalizedPoint
430 * Scales a normalized point (x, y) with respect to the box whose corners are
431 * passed in "corners". The point is stored in "*pPoint". The normalized
432 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
433 * (1.0, 1.0) correspond to corners[1].
435 static void PATH_ScaleNormalizedPoint(FLOAT_POINT corners
[], double x
,
436 double y
, POINT
*pPoint
)
438 pPoint
->x
=GDI_ROUND( (double)corners
[0].x
+ (double)(corners
[1].x
-corners
[0].x
)*0.5*(x
+1.0) );
439 pPoint
->y
=GDI_ROUND( (double)corners
[0].y
+ (double)(corners
[1].y
-corners
[0].y
)*0.5*(y
+1.0) );
442 /* PATH_NormalizePoint
444 * Normalizes a point with respect to the box whose corners are passed in
445 * "corners". The normalized coordinates are stored in "*pX" and "*pY".
447 static void PATH_NormalizePoint(FLOAT_POINT corners
[],
448 const FLOAT_POINT
*pPoint
,
449 double *pX
, double *pY
)
451 *pX
=(double)(pPoint
->x
-corners
[0].x
)/(double)(corners
[1].x
-corners
[0].x
) * 2.0 - 1.0;
452 *pY
=(double)(pPoint
->y
-corners
[0].y
)/(double)(corners
[1].y
-corners
[0].y
) * 2.0 - 1.0;
457 * Creates a Bezier spline that corresponds to part of an arc and appends the
458 * corresponding points to the path. The start and end angles are passed in
459 * "angleStart" and "angleEnd"; these angles should span a quarter circle
460 * at most. If "startEntryType" is non-zero, an entry of that type for the first
461 * control point is added to the path; otherwise, it is assumed that the current
462 * position is equal to the first control point.
464 static BOOL
PATH_DoArcPart(GdiPath
*pPath
, FLOAT_POINT corners
[],
465 double angleStart
, double angleEnd
, BYTE startEntryType
)
468 double xNorm
[4], yNorm
[4];
472 assert(fabs(angleEnd
-angleStart
)<=M_PI_2
);
474 /* FIXME: Is there an easier way of computing this? */
476 /* Compute control points */
477 halfAngle
=(angleEnd
-angleStart
)/2.0;
478 if(fabs(halfAngle
)>1e-8)
480 a
=4.0/3.0*(1-cos(halfAngle
))/sin(halfAngle
);
481 xNorm
[0]=cos(angleStart
);
482 yNorm
[0]=sin(angleStart
);
483 xNorm
[1]=xNorm
[0] - a
*yNorm
[0];
484 yNorm
[1]=yNorm
[0] + a
*xNorm
[0];
485 xNorm
[3]=cos(angleEnd
);
486 yNorm
[3]=sin(angleEnd
);
487 xNorm
[2]=xNorm
[3] + a
*yNorm
[3];
488 yNorm
[2]=yNorm
[3] - a
*xNorm
[3];
493 xNorm
[i
]=cos(angleStart
);
494 yNorm
[i
]=sin(angleStart
);
497 /* Add starting point to path if desired */
500 PATH_ScaleNormalizedPoint(corners
, xNorm
[0], yNorm
[0], &point
);
501 if(!PATH_AddEntry(pPath
, &point
, startEntryType
))
505 /* Add remaining control points */
508 PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &point
);
509 if(!PATH_AddEntry(pPath
, &point
, PT_BEZIERTO
))
517 /***********************************************************************
518 * BeginPath (GDI32.@)
520 BOOL WINAPI
BeginPath(HDC hdc
)
523 DC
*dc
= get_dc_ptr( hdc
);
527 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pBeginPath
);
528 ret
= physdev
->funcs
->pBeginPath( physdev
);
529 release_dc_ptr( dc
);
535 /***********************************************************************
538 BOOL WINAPI
EndPath(HDC hdc
)
541 DC
*dc
= get_dc_ptr( hdc
);
545 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pEndPath
);
546 ret
= physdev
->funcs
->pEndPath( physdev
);
547 release_dc_ptr( dc
);
553 /******************************************************************************
554 * AbortPath [GDI32.@]
555 * Closes and discards paths from device context
558 * Check that SetLastError is being called correctly
561 * hdc [I] Handle to device context
567 BOOL WINAPI
AbortPath( HDC hdc
)
570 DC
*dc
= get_dc_ptr( hdc
);
574 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pAbortPath
);
575 ret
= physdev
->funcs
->pAbortPath( physdev
);
576 release_dc_ptr( dc
);
582 /***********************************************************************
583 * CloseFigure (GDI32.@)
585 * FIXME: Check that SetLastError is being called correctly
587 BOOL WINAPI
CloseFigure(HDC hdc
)
590 DC
*dc
= get_dc_ptr( hdc
);
594 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pCloseFigure
);
595 ret
= physdev
->funcs
->pCloseFigure( physdev
);
596 release_dc_ptr( dc
);
602 /***********************************************************************
605 INT WINAPI
GetPath(HDC hdc
, LPPOINT pPoints
, LPBYTE pTypes
,
610 DC
*dc
= get_dc_ptr( hdc
);
616 /* Check that path is closed */
617 if(pPath
->state
!=PATH_Closed
)
619 SetLastError(ERROR_CAN_NOT_COMPLETE
);
624 ret
= pPath
->numEntriesUsed
;
625 else if(nSize
<pPath
->numEntriesUsed
)
627 SetLastError(ERROR_INVALID_PARAMETER
);
632 memcpy(pPoints
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
633 memcpy(pTypes
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
635 /* Convert the points to logical coordinates */
636 if(!DPtoLP(hdc
, pPoints
, pPath
->numEntriesUsed
))
638 /* FIXME: Is this the correct value? */
639 SetLastError(ERROR_CAN_NOT_COMPLETE
);
642 else ret
= pPath
->numEntriesUsed
;
645 release_dc_ptr( dc
);
650 /***********************************************************************
651 * PathToRegion (GDI32.@)
654 * Check that SetLastError is being called correctly
656 * The documentation does not state this explicitly, but a test under Windows
657 * shows that the region which is returned should be in device coordinates.
659 HRGN WINAPI
PathToRegion(HDC hdc
)
663 DC
*dc
= get_dc_ptr( hdc
);
665 /* Get pointer to path */
670 /* Check that path is closed */
671 if(pPath
->state
!=PATH_Closed
) SetLastError(ERROR_CAN_NOT_COMPLETE
);
674 /* FIXME: Should we empty the path even if conversion failed? */
675 if(PATH_PathToRegion(pPath
, GetPolyFillMode(hdc
), &hrgnRval
))
676 PATH_EmptyPath(pPath
);
680 release_dc_ptr( dc
);
684 static BOOL
PATH_FillPath(DC
*dc
, GdiPath
*pPath
)
686 INT mapMode
, graphicsMode
;
687 SIZE ptViewportExt
, ptWindowExt
;
688 POINT ptViewportOrg
, ptWindowOrg
;
692 /* Construct a region from the path and fill it */
693 if(PATH_PathToRegion(pPath
, dc
->polyFillMode
, &hrgn
))
695 /* Since PaintRgn interprets the region as being in logical coordinates
696 * but the points we store for the path are already in device
697 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
698 * Using SaveDC to save information about the mapping mode / world
699 * transform would be easier but would require more overhead, especially
700 * now that SaveDC saves the current path.
703 /* Save the information about the old mapping mode */
704 mapMode
=GetMapMode(dc
->hSelf
);
705 GetViewportExtEx(dc
->hSelf
, &ptViewportExt
);
706 GetViewportOrgEx(dc
->hSelf
, &ptViewportOrg
);
707 GetWindowExtEx(dc
->hSelf
, &ptWindowExt
);
708 GetWindowOrgEx(dc
->hSelf
, &ptWindowOrg
);
710 /* Save world transform
711 * NB: The Windows documentation on world transforms would lead one to
712 * believe that this has to be done only in GM_ADVANCED; however, my
713 * tests show that resetting the graphics mode to GM_COMPATIBLE does
714 * not reset the world transform.
716 GetWorldTransform(dc
->hSelf
, &xform
);
719 SetMapMode(dc
->hSelf
, MM_TEXT
);
720 SetViewportOrgEx(dc
->hSelf
, 0, 0, NULL
);
721 SetWindowOrgEx(dc
->hSelf
, 0, 0, NULL
);
722 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
723 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
724 ModifyWorldTransform(dc
->hSelf
, &xform
, MWT_IDENTITY
);
725 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
727 /* Paint the region */
728 PaintRgn(dc
->hSelf
, hrgn
);
730 /* Restore the old mapping mode */
731 SetMapMode(dc
->hSelf
, mapMode
);
732 SetViewportExtEx(dc
->hSelf
, ptViewportExt
.cx
, ptViewportExt
.cy
, NULL
);
733 SetViewportOrgEx(dc
->hSelf
, ptViewportOrg
.x
, ptViewportOrg
.y
, NULL
);
734 SetWindowExtEx(dc
->hSelf
, ptWindowExt
.cx
, ptWindowExt
.cy
, NULL
);
735 SetWindowOrgEx(dc
->hSelf
, ptWindowOrg
.x
, ptWindowOrg
.y
, NULL
);
737 /* Go to GM_ADVANCED temporarily to restore the world transform */
738 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
739 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
740 SetWorldTransform(dc
->hSelf
, &xform
);
741 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
748 /***********************************************************************
752 * Check that SetLastError is being called correctly
754 BOOL WINAPI
FillPath(HDC hdc
)
757 DC
*dc
= get_dc_ptr( hdc
);
761 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pFillPath
);
762 ret
= physdev
->funcs
->pFillPath( physdev
);
763 release_dc_ptr( dc
);
769 /***********************************************************************
770 * SelectClipPath (GDI32.@)
772 * Check that SetLastError is being called correctly
774 BOOL WINAPI
SelectClipPath(HDC hdc
, INT iMode
)
777 DC
*dc
= get_dc_ptr( hdc
);
781 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pSelectClipPath
);
782 ret
= physdev
->funcs
->pSelectClipPath( physdev
, iMode
);
783 release_dc_ptr( dc
);
789 /***********************************************************************
792 static BOOL
pathdrv_AbortPath( PHYSDEV dev
)
794 DC
*dc
= get_dc_ptr( dev
->hdc
);
796 if (!dc
) return FALSE
;
797 PATH_EmptyPath( &dc
->path
);
798 pop_path_driver( dc
);
799 release_dc_ptr( dc
);
804 /***********************************************************************
807 static BOOL
pathdrv_EndPath( PHYSDEV dev
)
809 DC
*dc
= get_dc_ptr( dev
->hdc
);
811 if (!dc
) return FALSE
;
812 dc
->path
.state
= PATH_Closed
;
813 pop_path_driver( dc
);
814 release_dc_ptr( dc
);
819 /***********************************************************************
822 static BOOL
pathdrv_CreateDC( PHYSDEV
*dev
, LPCWSTR driver
, LPCWSTR device
,
823 LPCWSTR output
, const DEVMODEW
*devmode
)
825 struct path_physdev
*physdev
= HeapAlloc( GetProcessHeap(), 0, sizeof(*physdev
) );
828 if (!physdev
) return FALSE
;
829 dc
= get_dc_ptr( (*dev
)->hdc
);
830 physdev
->path
= &dc
->path
;
831 push_dc_driver( dev
, &physdev
->dev
, &path_driver
);
832 release_dc_ptr( dc
);
837 /*************************************************************
840 static BOOL
pathdrv_DeleteDC( PHYSDEV dev
)
842 assert( 0 ); /* should never be called */
849 * Initializes the GdiPath structure.
851 void PATH_InitGdiPath(GdiPath
*pPath
)
855 pPath
->state
=PATH_Null
;
858 pPath
->numEntriesUsed
=0;
859 pPath
->numEntriesAllocated
=0;
862 /* PATH_DestroyGdiPath
864 * Destroys a GdiPath structure (frees the memory in the arrays).
866 void PATH_DestroyGdiPath(GdiPath
*pPath
)
870 HeapFree( GetProcessHeap(), 0, pPath
->pPoints
);
871 HeapFree( GetProcessHeap(), 0, pPath
->pFlags
);
874 BOOL
PATH_SavePath( DC
*dst
, DC
*src
)
876 PATH_InitGdiPath( &dst
->path
);
877 return PATH_AssignGdiPath( &dst
->path
, &src
->path
);
880 BOOL
PATH_RestorePath( DC
*dst
, DC
*src
)
884 if (src
->path
.state
== PATH_Open
&& dst
->path
.state
!= PATH_Open
)
886 if (!path_driver
.pCreateDC( &dst
->physDev
, NULL
, NULL
, NULL
, NULL
)) return FALSE
;
887 ret
= PATH_AssignGdiPath( &dst
->path
, &src
->path
);
888 if (!ret
) pop_path_driver( dst
);
890 else if (src
->path
.state
!= PATH_Open
&& dst
->path
.state
== PATH_Open
)
892 ret
= PATH_AssignGdiPath( &dst
->path
, &src
->path
);
893 if (ret
) pop_path_driver( dst
);
895 else ret
= PATH_AssignGdiPath( &dst
->path
, &src
->path
);
900 /*************************************************************
903 static BOOL
pathdrv_MoveTo( PHYSDEV dev
, INT x
, INT y
)
905 struct path_physdev
*physdev
= get_path_physdev( dev
);
906 physdev
->path
->newStroke
= TRUE
;
911 /*************************************************************
914 static BOOL
pathdrv_LineTo( PHYSDEV dev
, INT x
, INT y
)
916 struct path_physdev
*physdev
= get_path_physdev( dev
);
919 /* Convert point to device coordinates */
922 LPtoDP( dev
->hdc
, &point
, 1 );
924 if (!start_new_stroke( physdev
)) return FALSE
;
926 return PATH_AddEntry(physdev
->path
, &point
, PT_LINETO
);
931 * Should be called when a call to RoundRect is performed on a DC that has
932 * an open path. Returns TRUE if successful, else FALSE.
934 * FIXME: it adds the same entries to the path as windows does, but there
935 * is an error in the bezier drawing code so that there are small pixel-size
936 * gaps when the resulting path is drawn by StrokePath()
938 BOOL
PATH_RoundRect(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
, INT ell_width
, INT ell_height
)
940 GdiPath
*pPath
= &dc
->path
;
941 POINT corners
[2], pointTemp
;
942 FLOAT_POINT ellCorners
[2];
944 /* Check that path is open */
945 if(pPath
->state
!=PATH_Open
)
948 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
951 /* Add points to the roundrect path */
952 ellCorners
[0].x
= corners
[1].x
-ell_width
;
953 ellCorners
[0].y
= corners
[0].y
;
954 ellCorners
[1].x
= corners
[1].x
;
955 ellCorners
[1].y
= corners
[0].y
+ell_height
;
956 if(!PATH_DoArcPart(pPath
, ellCorners
, 0, -M_PI_2
, PT_MOVETO
))
958 pointTemp
.x
= corners
[0].x
+ell_width
/2;
959 pointTemp
.y
= corners
[0].y
;
960 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
962 ellCorners
[0].x
= corners
[0].x
;
963 ellCorners
[1].x
= corners
[0].x
+ell_width
;
964 if(!PATH_DoArcPart(pPath
, ellCorners
, -M_PI_2
, -M_PI
, FALSE
))
966 pointTemp
.x
= corners
[0].x
;
967 pointTemp
.y
= corners
[1].y
-ell_height
/2;
968 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
970 ellCorners
[0].y
= corners
[1].y
-ell_height
;
971 ellCorners
[1].y
= corners
[1].y
;
972 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI
, M_PI_2
, FALSE
))
974 pointTemp
.x
= corners
[1].x
-ell_width
/2;
975 pointTemp
.y
= corners
[1].y
;
976 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
978 ellCorners
[0].x
= corners
[1].x
-ell_width
;
979 ellCorners
[1].x
= corners
[1].x
;
980 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI_2
, 0, FALSE
))
983 /* Close the roundrect figure */
984 if(!CloseFigure(dc
->hSelf
))
992 * Should be called when a call to Rectangle is performed on a DC that has
993 * an open path. Returns TRUE if successful, else FALSE.
995 BOOL
PATH_Rectangle(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
)
997 GdiPath
*pPath
= &dc
->path
;
998 POINT corners
[2], pointTemp
;
1000 /* Check that path is open */
1001 if(pPath
->state
!=PATH_Open
)
1004 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
1007 /* Close any previous figure */
1008 if(!CloseFigure(dc
->hSelf
))
1010 /* The CloseFigure call shouldn't have failed */
1015 /* Add four points to the path */
1016 pointTemp
.x
=corners
[1].x
;
1017 pointTemp
.y
=corners
[0].y
;
1018 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_MOVETO
))
1020 if(!PATH_AddEntry(pPath
, corners
, PT_LINETO
))
1022 pointTemp
.x
=corners
[0].x
;
1023 pointTemp
.y
=corners
[1].y
;
1024 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
1026 if(!PATH_AddEntry(pPath
, corners
+1, PT_LINETO
))
1029 /* Close the rectangle figure */
1030 if(!CloseFigure(dc
->hSelf
))
1032 /* The CloseFigure call shouldn't have failed */
1042 * Should be called when a call to Ellipse is performed on a DC that has
1043 * an open path. This adds four Bezier splines representing the ellipse
1044 * to the path. Returns TRUE if successful, else FALSE.
1046 BOOL
PATH_Ellipse(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
)
1048 return( PATH_Arc(dc
, x1
, y1
, x2
, y2
, x1
, (y1
+y2
)/2, x1
, (y1
+y2
)/2,0) &&
1049 CloseFigure(dc
->hSelf
) );
1054 * Should be called when a call to Arc is performed on a DC that has
1055 * an open path. This adds up to five Bezier splines representing the arc
1056 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
1057 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
1058 * -1 we add 1 extra line from the current DC position to the starting position
1059 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
1062 BOOL
PATH_Arc(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
,
1063 INT xStart
, INT yStart
, INT xEnd
, INT yEnd
, INT lines
)
1065 GdiPath
*pPath
= &dc
->path
;
1066 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
=0.0;
1067 /* Initialize angleEndQuadrant to silence gcc's warning */
1069 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
1070 POINT centre
, pointCurPos
;
1074 /* FIXME: This function should check for all possible error returns */
1075 /* FIXME: Do we have to respect newStroke? */
1077 /* Check that path is open */
1078 if(pPath
->state
!=PATH_Open
)
1081 /* Check for zero height / width */
1082 /* FIXME: Only in GM_COMPATIBLE? */
1083 if(x1
==x2
|| y1
==y2
)
1086 /* Convert points to device coordinates */
1091 pointStart
.x
= xStart
;
1092 pointStart
.y
= yStart
;
1095 INTERNAL_LPTODP_FLOAT(dc
, corners
);
1096 INTERNAL_LPTODP_FLOAT(dc
, corners
+1);
1097 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
);
1098 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
);
1100 /* Make sure first corner is top left and second corner is bottom right */
1101 if(corners
[0].x
>corners
[1].x
)
1104 corners
[0].x
=corners
[1].x
;
1107 if(corners
[0].y
>corners
[1].y
)
1110 corners
[0].y
=corners
[1].y
;
1114 /* Compute start and end angle */
1115 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
1116 angleStart
=atan2(y
, x
);
1117 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
1118 angleEnd
=atan2(y
, x
);
1120 /* Make sure the end angle is "on the right side" of the start angle */
1121 if(dc
->ArcDirection
==AD_CLOCKWISE
)
1123 if(angleEnd
<=angleStart
)
1126 assert(angleEnd
>=angleStart
);
1131 if(angleEnd
>=angleStart
)
1134 assert(angleEnd
<=angleStart
);
1138 /* In GM_COMPATIBLE, don't include bottom and right edges */
1139 if(dc
->GraphicsMode
==GM_COMPATIBLE
)
1145 /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
1146 if(lines
==-1 && pPath
->newStroke
)
1148 pPath
->newStroke
=FALSE
;
1149 pointCurPos
.x
= dc
->CursPosX
;
1150 pointCurPos
.y
= dc
->CursPosY
;
1151 if(!LPtoDP(dc
->hSelf
, &pointCurPos
, 1))
1153 if(!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
1157 /* Add the arc to the path with one Bezier spline per quadrant that the
1163 /* Determine the start and end angles for this quadrant */
1166 angleStartQuadrant
=angleStart
;
1167 if(dc
->ArcDirection
==AD_CLOCKWISE
)
1168 angleEndQuadrant
=(floor(angleStart
/M_PI_2
)+1.0)*M_PI_2
;
1170 angleEndQuadrant
=(ceil(angleStart
/M_PI_2
)-1.0)*M_PI_2
;
1174 angleStartQuadrant
=angleEndQuadrant
;
1175 if(dc
->ArcDirection
==AD_CLOCKWISE
)
1176 angleEndQuadrant
+=M_PI_2
;
1178 angleEndQuadrant
-=M_PI_2
;
1181 /* Have we reached the last part of the arc? */
1182 if((dc
->ArcDirection
==AD_CLOCKWISE
&&
1183 angleEnd
<angleEndQuadrant
) ||
1184 (dc
->ArcDirection
==AD_COUNTERCLOCKWISE
&&
1185 angleEnd
>angleEndQuadrant
))
1187 /* Adjust the end angle for this quadrant */
1188 angleEndQuadrant
=angleEnd
;
1192 /* Add the Bezier spline to the path */
1193 PATH_DoArcPart(pPath
, corners
, angleStartQuadrant
, angleEndQuadrant
,
1194 start
? (lines
==-1 ? PT_LINETO
: PT_MOVETO
) : FALSE
);
1198 /* chord: close figure. pie: add line and close figure */
1201 if(!CloseFigure(dc
->hSelf
))
1206 centre
.x
= (corners
[0].x
+corners
[1].x
)/2;
1207 centre
.y
= (corners
[0].y
+corners
[1].y
)/2;
1208 if(!PATH_AddEntry(pPath
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
1215 BOOL
PATH_PolyBezierTo(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
1217 GdiPath
*pPath
= &dc
->path
;
1221 /* Check that path is open */
1222 if(pPath
->state
!=PATH_Open
)
1225 /* Add a PT_MOVETO if necessary */
1226 if(pPath
->newStroke
)
1228 pPath
->newStroke
=FALSE
;
1229 pt
.x
= dc
->CursPosX
;
1230 pt
.y
= dc
->CursPosY
;
1231 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1233 if(!PATH_AddEntry(pPath
, &pt
, PT_MOVETO
))
1237 for(i
= 0; i
< cbPoints
; i
++) {
1239 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1241 PATH_AddEntry(pPath
, &pt
, PT_BEZIERTO
);
1246 BOOL
PATH_PolyBezier(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
1248 GdiPath
*pPath
= &dc
->path
;
1252 /* Check that path is open */
1253 if(pPath
->state
!=PATH_Open
)
1256 for(i
= 0; i
< cbPoints
; i
++) {
1258 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1260 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_BEZIERTO
);
1267 * Should be called when a call to PolyDraw is performed on a DC that has
1268 * an open path. Returns TRUE if successful, else FALSE.
1270 BOOL
PATH_PolyDraw(DC
*dc
, const POINT
*pts
, const BYTE
*types
,
1273 GdiPath
*pPath
= &dc
->path
;
1274 POINT lastmove
, orig_pos
;
1277 GetCurrentPositionEx( dc
->hSelf
, &orig_pos
);
1278 lastmove
= orig_pos
;
1280 for(i
= pPath
->numEntriesUsed
- 1; i
>= 0; i
--){
1281 if(pPath
->pFlags
[i
] == PT_MOVETO
){
1282 lastmove
= pPath
->pPoints
[i
];
1283 DPtoLP(dc
->hSelf
, &lastmove
, 1);
1288 for(i
= 0; i
< cbPoints
; i
++)
1293 MoveToEx( dc
->hSelf
, pts
[i
].x
, pts
[i
].y
, NULL
);
1296 case PT_LINETO
| PT_CLOSEFIGURE
:
1297 LineTo( dc
->hSelf
, pts
[i
].x
, pts
[i
].y
);
1300 if ((i
+ 2 < cbPoints
) && (types
[i
+ 1] == PT_BEZIERTO
) &&
1301 (types
[i
+ 2] & ~PT_CLOSEFIGURE
) == PT_BEZIERTO
)
1303 PolyBezierTo( dc
->hSelf
, &pts
[i
], 3 );
1309 if (i
) /* restore original position */
1311 if (!(types
[i
- 1] & PT_CLOSEFIGURE
)) lastmove
= pts
[i
- 1];
1312 if (lastmove
.x
!= orig_pos
.x
|| lastmove
.y
!= orig_pos
.y
)
1313 MoveToEx( dc
->hSelf
, orig_pos
.x
, orig_pos
.y
, NULL
);
1318 if(types
[i
] & PT_CLOSEFIGURE
){
1319 pPath
->pFlags
[pPath
->numEntriesUsed
-1] |= PT_CLOSEFIGURE
;
1320 MoveToEx( dc
->hSelf
, lastmove
.x
, lastmove
.y
, NULL
);
1327 BOOL
PATH_Polyline(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
1329 GdiPath
*pPath
= &dc
->path
;
1333 /* Check that path is open */
1334 if(pPath
->state
!=PATH_Open
)
1337 for(i
= 0; i
< cbPoints
; i
++) {
1339 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1341 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_LINETO
);
1346 BOOL
PATH_PolylineTo(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
1348 GdiPath
*pPath
= &dc
->path
;
1352 /* Check that path is open */
1353 if(pPath
->state
!=PATH_Open
)
1356 /* Add a PT_MOVETO if necessary */
1357 if(pPath
->newStroke
)
1359 pPath
->newStroke
=FALSE
;
1360 pt
.x
= dc
->CursPosX
;
1361 pt
.y
= dc
->CursPosY
;
1362 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1364 if(!PATH_AddEntry(pPath
, &pt
, PT_MOVETO
))
1368 for(i
= 0; i
< cbPoints
; i
++) {
1370 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1372 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
1379 BOOL
PATH_Polygon(DC
*dc
, const POINT
*pts
, DWORD cbPoints
)
1381 GdiPath
*pPath
= &dc
->path
;
1385 /* Check that path is open */
1386 if(pPath
->state
!=PATH_Open
)
1389 for(i
= 0; i
< cbPoints
; i
++) {
1391 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1393 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
:
1394 ((i
== cbPoints
-1) ? PT_LINETO
| PT_CLOSEFIGURE
:
1400 BOOL
PATH_PolyPolygon( DC
*dc
, const POINT
* pts
, const INT
* counts
,
1403 GdiPath
*pPath
= &dc
->path
;
1408 /* Check that path is open */
1409 if(pPath
->state
!=PATH_Open
)
1412 for(i
= 0, poly
= 0; poly
< polygons
; poly
++) {
1413 for(point
= 0; point
< counts
[poly
]; point
++, i
++) {
1415 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1417 if(point
== 0) startpt
= pt
;
1418 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1420 /* win98 adds an extra line to close the figure for some reason */
1421 PATH_AddEntry(pPath
, &startpt
, PT_LINETO
| PT_CLOSEFIGURE
);
1426 BOOL
PATH_PolyPolyline( DC
*dc
, const POINT
* pts
, const DWORD
* counts
,
1429 GdiPath
*pPath
= &dc
->path
;
1431 UINT poly
, point
, i
;
1433 /* Check that path is open */
1434 if(pPath
->state
!=PATH_Open
)
1437 for(i
= 0, poly
= 0; poly
< polylines
; poly
++) {
1438 for(point
= 0; point
< counts
[poly
]; point
++, i
++) {
1440 if(!LPtoDP(dc
->hSelf
, &pt
, 1))
1442 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
1449 /**********************************************************************
1452 * internally used by PATH_add_outline
1454 static void PATH_BezierTo(GdiPath
*pPath
, POINT
*lppt
, INT n
)
1460 PATH_AddEntry(pPath
, &lppt
[1], PT_LINETO
);
1464 PATH_AddEntry(pPath
, &lppt
[0], PT_BEZIERTO
);
1465 PATH_AddEntry(pPath
, &lppt
[1], PT_BEZIERTO
);
1466 PATH_AddEntry(pPath
, &lppt
[2], PT_BEZIERTO
);
1480 pt
[2].x
= (lppt
[i
+2].x
+ lppt
[i
+1].x
) / 2;
1481 pt
[2].y
= (lppt
[i
+2].y
+ lppt
[i
+1].y
) / 2;
1482 PATH_BezierTo(pPath
, pt
, 3);
1490 PATH_BezierTo(pPath
, pt
, 3);
1494 static BOOL
PATH_add_outline(DC
*dc
, INT x
, INT y
, TTPOLYGONHEADER
*header
, DWORD size
)
1496 GdiPath
*pPath
= &dc
->path
;
1497 TTPOLYGONHEADER
*start
;
1502 while ((char *)header
< (char *)start
+ size
)
1506 if (header
->dwType
!= TT_POLYGON_TYPE
)
1508 FIXME("Unknown header type %d\n", header
->dwType
);
1512 pt
.x
= x
+ int_from_fixed(header
->pfxStart
.x
);
1513 pt
.y
= y
- int_from_fixed(header
->pfxStart
.y
);
1514 PATH_AddEntry(pPath
, &pt
, PT_MOVETO
);
1516 curve
= (TTPOLYCURVE
*)(header
+ 1);
1518 while ((char *)curve
< (char *)header
+ header
->cb
)
1520 /*TRACE("curve->wType %d\n", curve->wType);*/
1522 switch(curve
->wType
)
1528 for (i
= 0; i
< curve
->cpfx
; i
++)
1530 pt
.x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1531 pt
.y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1532 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
1537 case TT_PRIM_QSPLINE
:
1538 case TT_PRIM_CSPLINE
:
1542 POINT
*pts
= HeapAlloc(GetProcessHeap(), 0, (curve
->cpfx
+ 1) * sizeof(POINT
));
1544 if (!pts
) return FALSE
;
1546 ptfx
= *(POINTFX
*)((char *)curve
- sizeof(POINTFX
));
1548 pts
[0].x
= x
+ int_from_fixed(ptfx
.x
);
1549 pts
[0].y
= y
- int_from_fixed(ptfx
.y
);
1551 for(i
= 0; i
< curve
->cpfx
; i
++)
1553 pts
[i
+ 1].x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1554 pts
[i
+ 1].y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1557 PATH_BezierTo(pPath
, pts
, curve
->cpfx
+ 1);
1559 HeapFree(GetProcessHeap(), 0, pts
);
1564 FIXME("Unknown curve type %04x\n", curve
->wType
);
1568 curve
= (TTPOLYCURVE
*)&curve
->apfx
[curve
->cpfx
];
1571 header
= (TTPOLYGONHEADER
*)((char *)header
+ header
->cb
);
1574 return CloseFigure(dc
->hSelf
);
1577 /**********************************************************************
1580 BOOL
PATH_ExtTextOut(DC
*dc
, INT x
, INT y
, UINT flags
, const RECT
*lprc
,
1581 LPCWSTR str
, UINT count
, const INT
*dx
)
1584 HDC hdc
= dc
->hSelf
;
1585 POINT offset
= {0, 0};
1587 TRACE("%p, %d, %d, %08x, %s, %s, %d, %p)\n", hdc
, x
, y
, flags
,
1588 wine_dbgstr_rect(lprc
), debugstr_wn(str
, count
), count
, dx
);
1590 if (!count
) return TRUE
;
1592 for (idx
= 0; idx
< count
; idx
++)
1594 static const MAT2 identity
= { {0,1},{0,0},{0,0},{0,1} };
1599 dwSize
= GetGlyphOutlineW(hdc
, str
[idx
], GGO_GLYPH_INDEX
| GGO_NATIVE
, &gm
, 0, NULL
, &identity
);
1600 if (dwSize
== GDI_ERROR
) return FALSE
;
1602 /* add outline only if char is printable */
1605 outline
= HeapAlloc(GetProcessHeap(), 0, dwSize
);
1606 if (!outline
) return FALSE
;
1608 GetGlyphOutlineW(hdc
, str
[idx
], GGO_GLYPH_INDEX
| GGO_NATIVE
, &gm
, dwSize
, outline
, &identity
);
1610 PATH_add_outline(dc
, x
+ offset
.x
, y
+ offset
.y
, outline
, dwSize
);
1612 HeapFree(GetProcessHeap(), 0, outline
);
1619 offset
.x
+= dx
[idx
* 2];
1620 offset
.y
+= dx
[idx
* 2 + 1];
1623 offset
.x
+= dx
[idx
];
1627 offset
.x
+= gm
.gmCellIncX
;
1628 offset
.y
+= gm
.gmCellIncY
;
1635 /*******************************************************************
1636 * FlattenPath [GDI32.@]
1640 BOOL WINAPI
FlattenPath(HDC hdc
)
1643 DC
*dc
= get_dc_ptr( hdc
);
1647 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pFlattenPath
);
1648 ret
= physdev
->funcs
->pFlattenPath( physdev
);
1649 release_dc_ptr( dc
);
1655 static BOOL
PATH_StrokePath(DC
*dc
, GdiPath
*pPath
)
1657 INT i
, nLinePts
, nAlloc
;
1659 POINT ptViewportOrg
, ptWindowOrg
;
1660 SIZE szViewportExt
, szWindowExt
;
1661 DWORD mapMode
, graphicsMode
;
1665 /* Save the mapping mode info */
1666 mapMode
=GetMapMode(dc
->hSelf
);
1667 GetViewportExtEx(dc
->hSelf
, &szViewportExt
);
1668 GetViewportOrgEx(dc
->hSelf
, &ptViewportOrg
);
1669 GetWindowExtEx(dc
->hSelf
, &szWindowExt
);
1670 GetWindowOrgEx(dc
->hSelf
, &ptWindowOrg
);
1671 GetWorldTransform(dc
->hSelf
, &xform
);
1674 SetMapMode(dc
->hSelf
, MM_TEXT
);
1675 SetViewportOrgEx(dc
->hSelf
, 0, 0, NULL
);
1676 SetWindowOrgEx(dc
->hSelf
, 0, 0, NULL
);
1677 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
1678 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
1679 ModifyWorldTransform(dc
->hSelf
, &xform
, MWT_IDENTITY
);
1680 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
1682 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1683 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1684 * space in case we get one to keep the number of reallocations small. */
1685 nAlloc
= pPath
->numEntriesUsed
+ 1 + 300;
1686 pLinePts
= HeapAlloc(GetProcessHeap(), 0, nAlloc
* sizeof(POINT
));
1689 for(i
= 0; i
< pPath
->numEntriesUsed
; i
++) {
1690 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
)) &&
1691 (pPath
->pFlags
[i
] != PT_MOVETO
)) {
1692 ERR("Expected PT_MOVETO %s, got path flag %d\n",
1693 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1694 (INT
)pPath
->pFlags
[i
]);
1698 switch(pPath
->pFlags
[i
]) {
1700 TRACE("Got PT_MOVETO (%d, %d)\n",
1701 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1703 Polyline(dc
->hSelf
, pLinePts
, nLinePts
);
1705 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1708 case (PT_LINETO
| PT_CLOSEFIGURE
):
1709 TRACE("Got PT_LINETO (%d, %d)\n",
1710 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1711 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1714 TRACE("Got PT_BEZIERTO\n");
1715 if(pPath
->pFlags
[i
+1] != PT_BEZIERTO
||
1716 (pPath
->pFlags
[i
+2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
) {
1717 ERR("Path didn't contain 3 successive PT_BEZIERTOs\n");
1721 INT nBzrPts
, nMinAlloc
;
1722 POINT
*pBzrPts
= GDI_Bezier(&pPath
->pPoints
[i
-1], 4, &nBzrPts
);
1723 /* Make sure we have allocated enough memory for the lines of
1724 * this bezier and the rest of the path, assuming we won't get
1725 * another one (since we won't reallocate again then). */
1726 nMinAlloc
= nLinePts
+ (pPath
->numEntriesUsed
- i
) + nBzrPts
;
1727 if(nAlloc
< nMinAlloc
)
1729 nAlloc
= nMinAlloc
* 2;
1730 pLinePts
= HeapReAlloc(GetProcessHeap(), 0, pLinePts
,
1731 nAlloc
* sizeof(POINT
));
1733 memcpy(&pLinePts
[nLinePts
], &pBzrPts
[1],
1734 (nBzrPts
- 1) * sizeof(POINT
));
1735 nLinePts
+= nBzrPts
- 1;
1736 HeapFree(GetProcessHeap(), 0, pBzrPts
);
1741 ERR("Got path flag %d\n", (INT
)pPath
->pFlags
[i
]);
1745 if(pPath
->pFlags
[i
] & PT_CLOSEFIGURE
)
1746 pLinePts
[nLinePts
++] = pLinePts
[0];
1749 Polyline(dc
->hSelf
, pLinePts
, nLinePts
);
1752 HeapFree(GetProcessHeap(), 0, pLinePts
);
1754 /* Restore the old mapping mode */
1755 SetMapMode(dc
->hSelf
, mapMode
);
1756 SetWindowExtEx(dc
->hSelf
, szWindowExt
.cx
, szWindowExt
.cy
, NULL
);
1757 SetWindowOrgEx(dc
->hSelf
, ptWindowOrg
.x
, ptWindowOrg
.y
, NULL
);
1758 SetViewportExtEx(dc
->hSelf
, szViewportExt
.cx
, szViewportExt
.cy
, NULL
);
1759 SetViewportOrgEx(dc
->hSelf
, ptViewportOrg
.x
, ptViewportOrg
.y
, NULL
);
1761 /* Go to GM_ADVANCED temporarily to restore the world transform */
1762 graphicsMode
=GetGraphicsMode(dc
->hSelf
);
1763 SetGraphicsMode(dc
->hSelf
, GM_ADVANCED
);
1764 SetWorldTransform(dc
->hSelf
, &xform
);
1765 SetGraphicsMode(dc
->hSelf
, graphicsMode
);
1767 /* If we've moved the current point then get its new position
1768 which will be in device (MM_TEXT) co-ords, convert it to
1769 logical co-ords and re-set it. This basically updates
1770 dc->CurPosX|Y so that their values are in the correct mapping
1775 GetCurrentPositionEx(dc
->hSelf
, &pt
);
1776 DPtoLP(dc
->hSelf
, &pt
, 1);
1777 MoveToEx(dc
->hSelf
, pt
.x
, pt
.y
, NULL
);
1783 #define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1785 static BOOL
PATH_WidenPath(DC
*dc
)
1787 INT i
, j
, numStrokes
, penWidth
, penWidthIn
, penWidthOut
, size
, penStyle
;
1789 GdiPath
*pPath
, *pNewPath
, **pStrokes
= NULL
, *pUpPath
, *pDownPath
;
1791 DWORD obj_type
, joint
, endcap
, penType
;
1795 PATH_FlattenPath(pPath
);
1797 size
= GetObjectW( dc
->hPen
, 0, NULL
);
1799 SetLastError(ERROR_CAN_NOT_COMPLETE
);
1803 elp
= HeapAlloc( GetProcessHeap(), 0, size
);
1804 GetObjectW( dc
->hPen
, size
, elp
);
1806 obj_type
= GetObjectType(dc
->hPen
);
1807 if(obj_type
== OBJ_PEN
) {
1808 penStyle
= ((LOGPEN
*)elp
)->lopnStyle
;
1810 else if(obj_type
== OBJ_EXTPEN
) {
1811 penStyle
= elp
->elpPenStyle
;
1814 SetLastError(ERROR_CAN_NOT_COMPLETE
);
1815 HeapFree( GetProcessHeap(), 0, elp
);
1819 penWidth
= elp
->elpWidth
;
1820 HeapFree( GetProcessHeap(), 0, elp
);
1822 endcap
= (PS_ENDCAP_MASK
& penStyle
);
1823 joint
= (PS_JOIN_MASK
& penStyle
);
1824 penType
= (PS_TYPE_MASK
& penStyle
);
1826 /* The function cannot apply to cosmetic pens */
1827 if(obj_type
== OBJ_EXTPEN
&& penType
== PS_COSMETIC
) {
1828 SetLastError(ERROR_CAN_NOT_COMPLETE
);
1832 penWidthIn
= penWidth
/ 2;
1833 penWidthOut
= penWidth
/ 2;
1834 if(penWidthIn
+ penWidthOut
< penWidth
)
1839 for(i
= 0, j
= 0; i
< pPath
->numEntriesUsed
; i
++, j
++) {
1841 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
)) &&
1842 (pPath
->pFlags
[i
] != PT_MOVETO
)) {
1843 ERR("Expected PT_MOVETO %s, got path flag %c\n",
1844 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1848 switch(pPath
->pFlags
[i
]) {
1850 if(numStrokes
> 0) {
1851 pStrokes
[numStrokes
- 1]->state
= PATH_Closed
;
1856 pStrokes
= HeapAlloc(GetProcessHeap(), 0, sizeof(GdiPath
*));
1858 pStrokes
= HeapReAlloc(GetProcessHeap(), 0, pStrokes
, numStrokes
* sizeof(GdiPath
*));
1859 if(!pStrokes
) return FALSE
;
1860 pStrokes
[numStrokes
- 1] = HeapAlloc(GetProcessHeap(), 0, sizeof(GdiPath
));
1861 PATH_InitGdiPath(pStrokes
[numStrokes
- 1]);
1862 pStrokes
[numStrokes
- 1]->state
= PATH_Open
;
1865 case (PT_LINETO
| PT_CLOSEFIGURE
):
1866 point
.x
= pPath
->pPoints
[i
].x
;
1867 point
.y
= pPath
->pPoints
[i
].y
;
1868 PATH_AddEntry(pStrokes
[numStrokes
- 1], &point
, pPath
->pFlags
[i
]);
1871 /* should never happen because of the FlattenPath call */
1872 ERR("Should never happen\n");
1875 ERR("Got path flag %c\n", pPath
->pFlags
[i
]);
1880 pNewPath
= HeapAlloc(GetProcessHeap(), 0, sizeof(GdiPath
));
1881 PATH_InitGdiPath(pNewPath
);
1882 pNewPath
->state
= PATH_Open
;
1884 for(i
= 0; i
< numStrokes
; i
++) {
1885 pUpPath
= HeapAlloc(GetProcessHeap(), 0, sizeof(GdiPath
));
1886 PATH_InitGdiPath(pUpPath
);
1887 pUpPath
->state
= PATH_Open
;
1888 pDownPath
= HeapAlloc(GetProcessHeap(), 0, sizeof(GdiPath
));
1889 PATH_InitGdiPath(pDownPath
);
1890 pDownPath
->state
= PATH_Open
;
1892 for(j
= 0; j
< pStrokes
[i
]->numEntriesUsed
; j
++) {
1893 /* Beginning or end of the path if not closed */
1894 if((!(pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) && (j
== 0 || j
== pStrokes
[i
]->numEntriesUsed
- 1) ) {
1895 /* Compute segment angle */
1896 double xo
, yo
, xa
, ya
, theta
;
1898 FLOAT_POINT corners
[2];
1900 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1901 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1902 xa
= pStrokes
[i
]->pPoints
[1].x
;
1903 ya
= pStrokes
[i
]->pPoints
[1].y
;
1906 xa
= pStrokes
[i
]->pPoints
[j
- 1].x
;
1907 ya
= pStrokes
[i
]->pPoints
[j
- 1].y
;
1908 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1909 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1911 theta
= atan2( ya
- yo
, xa
- xo
);
1913 case PS_ENDCAP_SQUARE
:
1914 pt
.x
= xo
+ round(sqrt(2) * penWidthOut
* cos(M_PI_4
+ theta
));
1915 pt
.y
= yo
+ round(sqrt(2) * penWidthOut
* sin(M_PI_4
+ theta
));
1916 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
) );
1917 pt
.x
= xo
+ round(sqrt(2) * penWidthIn
* cos(- M_PI_4
+ theta
));
1918 pt
.y
= yo
+ round(sqrt(2) * penWidthIn
* sin(- M_PI_4
+ theta
));
1919 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1921 case PS_ENDCAP_FLAT
:
1922 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1923 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1924 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1925 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1926 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1927 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1929 case PS_ENDCAP_ROUND
:
1931 corners
[0].x
= xo
- penWidthIn
;
1932 corners
[0].y
= yo
- penWidthIn
;
1933 corners
[1].x
= xo
+ penWidthOut
;
1934 corners
[1].y
= yo
+ penWidthOut
;
1935 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI_2
, theta
+ 3 * M_PI_4
, (j
== 0 ? PT_MOVETO
: FALSE
));
1936 PATH_DoArcPart(pUpPath
,corners
, theta
+ 3 * M_PI_4
, theta
+ M_PI
, FALSE
);
1937 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI
, theta
+ 5 * M_PI_4
, FALSE
);
1938 PATH_DoArcPart(pUpPath
,corners
, theta
+ 5 * M_PI_4
, theta
+ 3 * M_PI_2
, FALSE
);
1942 /* Corpse of the path */
1946 double xa
, ya
, xb
, yb
, xo
, yo
;
1947 double alpha
, theta
, miterWidth
;
1948 DWORD _joint
= joint
;
1950 GdiPath
*pInsidePath
, *pOutsidePath
;
1951 if(j
> 0 && j
< pStrokes
[i
]->numEntriesUsed
- 1) {
1956 previous
= pStrokes
[i
]->numEntriesUsed
- 1;
1963 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1964 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1965 xa
= pStrokes
[i
]->pPoints
[previous
].x
;
1966 ya
= pStrokes
[i
]->pPoints
[previous
].y
;
1967 xb
= pStrokes
[i
]->pPoints
[next
].x
;
1968 yb
= pStrokes
[i
]->pPoints
[next
].y
;
1969 theta
= atan2( yo
- ya
, xo
- xa
);
1970 alpha
= atan2( yb
- yo
, xb
- xo
) - theta
;
1971 if (alpha
> 0) alpha
-= M_PI
;
1973 if(_joint
== PS_JOIN_MITER
&& dc
->miterLimit
< fabs(1 / sin(alpha
/2))) {
1974 _joint
= PS_JOIN_BEVEL
;
1977 pInsidePath
= pUpPath
;
1978 pOutsidePath
= pDownPath
;
1980 else if(alpha
< 0) {
1981 pInsidePath
= pDownPath
;
1982 pOutsidePath
= pUpPath
;
1987 /* Inside angle points */
1989 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1990 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1993 pt
.x
= xo
+ round( penWidthIn
* cos(theta
+ M_PI_2
) );
1994 pt
.y
= yo
+ round( penWidthIn
* sin(theta
+ M_PI_2
) );
1996 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1998 pt
.x
= xo
+ round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1999 pt
.y
= yo
+ round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
2002 pt
.x
= xo
- round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
2003 pt
.y
= yo
- round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
2005 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
2006 /* Outside angle point */
2008 case PS_JOIN_MITER
:
2009 miterWidth
= fabs(penWidthOut
/ cos(M_PI_2
- fabs(alpha
) / 2));
2010 pt
.x
= xo
+ round( miterWidth
* cos(theta
+ alpha
/ 2) );
2011 pt
.y
= yo
+ round( miterWidth
* sin(theta
+ alpha
/ 2) );
2012 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
2014 case PS_JOIN_BEVEL
:
2016 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
2017 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
2020 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
2021 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
2023 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
2025 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
2026 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
2029 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
2030 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
2032 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
2034 case PS_JOIN_ROUND
:
2037 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
2038 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
2041 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
2042 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
2044 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
2045 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ alpha
/ 2) );
2046 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ alpha
/ 2) );
2047 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
2049 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
2050 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
2053 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
2054 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
2056 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
2061 for(j
= 0; j
< pUpPath
->numEntriesUsed
; j
++) {
2063 pt
.x
= pUpPath
->pPoints
[j
].x
;
2064 pt
.y
= pUpPath
->pPoints
[j
].y
;
2065 PATH_AddEntry(pNewPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
2067 for(j
= 0; j
< pDownPath
->numEntriesUsed
; j
++) {
2069 pt
.x
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].x
;
2070 pt
.y
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].y
;
2071 PATH_AddEntry(pNewPath
, &pt
, ( (j
== 0 && (pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) ? PT_MOVETO
: PT_LINETO
));
2074 PATH_DestroyGdiPath(pStrokes
[i
]);
2075 HeapFree(GetProcessHeap(), 0, pStrokes
[i
]);
2076 PATH_DestroyGdiPath(pUpPath
);
2077 HeapFree(GetProcessHeap(), 0, pUpPath
);
2078 PATH_DestroyGdiPath(pDownPath
);
2079 HeapFree(GetProcessHeap(), 0, pDownPath
);
2081 HeapFree(GetProcessHeap(), 0, pStrokes
);
2083 pNewPath
->state
= PATH_Closed
;
2084 if (!(ret
= PATH_AssignGdiPath(pPath
, pNewPath
)))
2085 ERR("Assign path failed\n");
2086 PATH_DestroyGdiPath(pNewPath
);
2087 HeapFree(GetProcessHeap(), 0, pNewPath
);
2092 /*******************************************************************
2093 * StrokeAndFillPath [GDI32.@]
2097 BOOL WINAPI
StrokeAndFillPath(HDC hdc
)
2100 DC
*dc
= get_dc_ptr( hdc
);
2104 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pStrokeAndFillPath
);
2105 ret
= physdev
->funcs
->pStrokeAndFillPath( physdev
);
2106 release_dc_ptr( dc
);
2112 /*******************************************************************
2113 * StrokePath [GDI32.@]
2117 BOOL WINAPI
StrokePath(HDC hdc
)
2120 DC
*dc
= get_dc_ptr( hdc
);
2124 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pStrokePath
);
2125 ret
= physdev
->funcs
->pStrokePath( physdev
);
2126 release_dc_ptr( dc
);
2132 /*******************************************************************
2133 * WidenPath [GDI32.@]
2137 BOOL WINAPI
WidenPath(HDC hdc
)
2140 DC
*dc
= get_dc_ptr( hdc
);
2144 PHYSDEV physdev
= GET_DC_PHYSDEV( dc
, pWidenPath
);
2145 ret
= physdev
->funcs
->pWidenPath( physdev
);
2146 release_dc_ptr( dc
);
2152 /***********************************************************************
2153 * null driver fallback implementations
2156 BOOL
nulldrv_BeginPath( PHYSDEV dev
)
2158 DC
*dc
= get_nulldrv_dc( dev
);
2160 /* If path is already open, do nothing */
2161 if (dc
->path
.state
!= PATH_Open
)
2163 if (!path_driver
.pCreateDC( &dc
->physDev
, NULL
, NULL
, NULL
, NULL
)) return FALSE
;
2164 PATH_EmptyPath(&dc
->path
);
2165 dc
->path
.newStroke
= TRUE
;
2166 dc
->path
.state
= PATH_Open
;
2171 BOOL
nulldrv_EndPath( PHYSDEV dev
)
2173 SetLastError( ERROR_CAN_NOT_COMPLETE
);
2177 BOOL
nulldrv_AbortPath( PHYSDEV dev
)
2179 DC
*dc
= get_nulldrv_dc( dev
);
2181 PATH_EmptyPath( &dc
->path
);
2185 BOOL
nulldrv_CloseFigure( PHYSDEV dev
)
2187 DC
*dc
= get_nulldrv_dc( dev
);
2189 if (dc
->path
.state
!= PATH_Open
)
2191 SetLastError( ERROR_CAN_NOT_COMPLETE
);
2194 /* Set PT_CLOSEFIGURE on the last entry and start a new stroke */
2195 /* It is not necessary to draw a line, PT_CLOSEFIGURE is a virtual closing line itself */
2196 if (dc
->path
.numEntriesUsed
)
2198 dc
->path
.pFlags
[dc
->path
.numEntriesUsed
- 1] |= PT_CLOSEFIGURE
;
2199 dc
->path
.newStroke
= TRUE
;
2204 BOOL
nulldrv_SelectClipPath( PHYSDEV dev
, INT mode
)
2208 DC
*dc
= get_nulldrv_dc( dev
);
2210 if (dc
->path
.state
!= PATH_Closed
)
2212 SetLastError( ERROR_CAN_NOT_COMPLETE
);
2215 if (!PATH_PathToRegion( &dc
->path
, GetPolyFillMode(dev
->hdc
), &hrgn
)) return FALSE
;
2216 ret
= ExtSelectClipRgn( dev
->hdc
, hrgn
, mode
) != ERROR
;
2217 if (ret
) PATH_EmptyPath( &dc
->path
);
2218 /* FIXME: Should this function delete the path even if it failed? */
2219 DeleteObject( hrgn
);
2223 BOOL
nulldrv_FillPath( PHYSDEV dev
)
2225 DC
*dc
= get_nulldrv_dc( dev
);
2227 if (dc
->path
.state
!= PATH_Closed
)
2229 SetLastError( ERROR_CAN_NOT_COMPLETE
);
2232 if (!PATH_FillPath( dc
, &dc
->path
)) return FALSE
;
2233 /* FIXME: Should the path be emptied even if conversion failed? */
2234 PATH_EmptyPath( &dc
->path
);
2238 BOOL
nulldrv_StrokeAndFillPath( PHYSDEV dev
)
2240 DC
*dc
= get_nulldrv_dc( dev
);
2242 if (dc
->path
.state
!= PATH_Closed
)
2244 SetLastError( ERROR_CAN_NOT_COMPLETE
);
2247 if (!PATH_FillPath( dc
, &dc
->path
)) return FALSE
;
2248 if (!PATH_StrokePath( dc
, &dc
->path
)) return FALSE
;
2249 PATH_EmptyPath( &dc
->path
);
2253 BOOL
nulldrv_StrokePath( PHYSDEV dev
)
2255 DC
*dc
= get_nulldrv_dc( dev
);
2257 if (dc
->path
.state
!= PATH_Closed
)
2259 SetLastError( ERROR_CAN_NOT_COMPLETE
);
2262 if (!PATH_StrokePath( dc
, &dc
->path
)) return FALSE
;
2263 PATH_EmptyPath( &dc
->path
);
2267 BOOL
nulldrv_FlattenPath( PHYSDEV dev
)
2269 DC
*dc
= get_nulldrv_dc( dev
);
2271 if (dc
->path
.state
!= PATH_Closed
)
2273 SetLastError( ERROR_CAN_NOT_COMPLETE
);
2276 return PATH_FlattenPath( &dc
->path
);
2279 BOOL
nulldrv_WidenPath( PHYSDEV dev
)
2281 DC
*dc
= get_nulldrv_dc( dev
);
2283 if (dc
->path
.state
!= PATH_Closed
)
2285 SetLastError( ERROR_CAN_NOT_COMPLETE
);
2288 return PATH_WidenPath( dc
);
2291 const struct gdi_dc_funcs path_driver
=
2293 NULL
, /* pAbortDoc */
2294 pathdrv_AbortPath
, /* pAbortPath */
2295 NULL
, /* pAlphaBlend */
2296 NULL
, /* pAngleArc */
2299 NULL
, /* pBeginPath */
2300 NULL
, /* pBlendImage */
2301 NULL
, /* pChoosePixelFormat */
2303 NULL
, /* pCloseFigure */
2304 NULL
, /* pCreateBitmap */
2305 NULL
, /* pCreateCompatibleDC */
2306 pathdrv_CreateDC
, /* pCreateDC */
2307 NULL
, /* pCreateDIBSection */
2308 NULL
, /* pDeleteBitmap */
2309 pathdrv_DeleteDC
, /* pDeleteDC */
2310 NULL
, /* pDeleteObject */
2311 NULL
, /* pDescribePixelFormat */
2312 NULL
, /* pDeviceCapabilities */
2313 NULL
, /* pEllipse */
2315 NULL
, /* pEndPage */
2316 pathdrv_EndPath
, /* pEndPath */
2317 NULL
, /* pEnumFonts */
2318 NULL
, /* pEnumICMProfiles */
2319 NULL
, /* pExcludeClipRect */
2320 NULL
, /* pExtDeviceMode */
2321 NULL
, /* pExtEscape */
2322 NULL
, /* pExtFloodFill */
2323 NULL
, /* pExtSelectClipRgn */
2324 NULL
, /* pExtTextOut */
2325 NULL
, /* pFillPath */
2326 NULL
, /* pFillRgn */
2327 NULL
, /* pFlattenPath */
2328 NULL
, /* pFontIsLinked */
2329 NULL
, /* pFrameRgn */
2330 NULL
, /* pGdiComment */
2331 NULL
, /* pGdiRealizationInfo */
2332 NULL
, /* pGetCharABCWidths */
2333 NULL
, /* pGetCharABCWidthsI */
2334 NULL
, /* pGetCharWidth */
2335 NULL
, /* pGetDeviceCaps */
2336 NULL
, /* pGetDeviceGammaRamp */
2337 NULL
, /* pGetFontData */
2338 NULL
, /* pGetFontUnicodeRanges */
2339 NULL
, /* pGetGlyphIndices */
2340 NULL
, /* pGetGlyphOutline */
2341 NULL
, /* pGetICMProfile */
2342 NULL
, /* pGetImage */
2343 NULL
, /* pGetKerningPairs */
2344 NULL
, /* pGetNearestColor */
2345 NULL
, /* pGetOutlineTextMetrics */
2346 NULL
, /* pGetPixel */
2347 NULL
, /* pGetPixelFormat */
2348 NULL
, /* pGetSystemPaletteEntries */
2349 NULL
, /* pGetTextCharsetInfo */
2350 NULL
, /* pGetTextExtentExPoint */
2351 NULL
, /* pGetTextExtentExPointI */
2352 NULL
, /* pGetTextFace */
2353 NULL
, /* pGetTextMetrics */
2354 NULL
, /* pIntersectClipRect */
2355 NULL
, /* pInvertRgn */
2356 pathdrv_LineTo
, /* pLineTo */
2357 NULL
, /* pModifyWorldTransform */
2358 pathdrv_MoveTo
, /* pMoveTo */
2359 NULL
, /* pOffsetClipRgn */
2360 NULL
, /* pOffsetViewportOrg */
2361 NULL
, /* pOffsetWindowOrg */
2362 NULL
, /* pPaintRgn */
2365 NULL
, /* pPolyBezier */
2366 NULL
, /* pPolyBezierTo */
2367 NULL
, /* pPolyDraw */
2368 NULL
, /* pPolyPolygon */
2369 NULL
, /* pPolyPolyline */
2370 NULL
, /* pPolygon */
2371 NULL
, /* pPolyline */
2372 NULL
, /* pPolylineTo */
2373 NULL
, /* pPutImage */
2374 NULL
, /* pRealizeDefaultPalette */
2375 NULL
, /* pRealizePalette */
2376 NULL
, /* pRectangle */
2377 NULL
, /* pResetDC */
2378 NULL
, /* pRestoreDC */
2379 NULL
, /* pRoundRect */
2381 NULL
, /* pScaleViewportExt */
2382 NULL
, /* pScaleWindowExt */
2383 NULL
, /* pSelectBitmap */
2384 NULL
, /* pSelectBrush */
2385 NULL
, /* pSelectClipPath */
2386 NULL
, /* pSelectFont */
2387 NULL
, /* pSelectPalette */
2388 NULL
, /* pSelectPen */
2389 NULL
, /* pSetArcDirection */
2390 NULL
, /* pSetBkColor */
2391 NULL
, /* pSetBkMode */
2392 NULL
, /* pSetDCBrushColor */
2393 NULL
, /* pSetDCPenColor */
2394 NULL
, /* pSetDIBColorTable */
2395 NULL
, /* pSetDIBitsToDevice */
2396 NULL
, /* pSetDeviceClipping */
2397 NULL
, /* pSetDeviceGammaRamp */
2398 NULL
, /* pSetLayout */
2399 NULL
, /* pSetMapMode */
2400 NULL
, /* pSetMapperFlags */
2401 NULL
, /* pSetPixel */
2402 NULL
, /* pSetPixelFormat */
2403 NULL
, /* pSetPolyFillMode */
2404 NULL
, /* pSetROP2 */
2405 NULL
, /* pSetRelAbs */
2406 NULL
, /* pSetStretchBltMode */
2407 NULL
, /* pSetTextAlign */
2408 NULL
, /* pSetTextCharacterExtra */
2409 NULL
, /* pSetTextColor */
2410 NULL
, /* pSetTextJustification */
2411 NULL
, /* pSetViewportExt */
2412 NULL
, /* pSetViewportOrg */
2413 NULL
, /* pSetWindowExt */
2414 NULL
, /* pSetWindowOrg */
2415 NULL
, /* pSetWorldTransform */
2416 NULL
, /* pStartDoc */
2417 NULL
, /* pStartPage */
2418 NULL
, /* pStretchBlt */
2419 NULL
, /* pStretchDIBits */
2420 NULL
, /* pStrokeAndFillPath */
2421 NULL
, /* pStrokePath */
2422 NULL
, /* pSwapBuffers */
2423 NULL
, /* pUnrealizePalette */
2424 NULL
, /* pWidenPath */
2425 /* OpenGL not supported */