2 * Graphics paths (BeginPath, EndPath etc.)
4 * Copyright 1997, 1998 Martin Boehme
6 * Copyright 2005 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * Addaped for the use in ReactOS.
28 * PROJECT: ReactOS win32 kernel mode subsystem
29 * LICENSE: GPL - See COPYING in the top level directory
30 * FILE: subsystems/win32/win32k/objects/path.c
31 * PURPOSE: Path support
36 #define _USE_MATH_DEFINES
42 #define NUM_ENTRIES_INITIAL 16 /* Initial size of points / flags arrays */
43 #define GROW_FACTOR_NUMER 2 /* Numerator of grow factor for the array */
44 #define GROW_FACTOR_DENOM 1 /* Denominator of grow factor */
46 BOOL FASTCALL
PATH_AddEntry (PPATH pPath
, const POINT
*pPoint
, BYTE flags
);
47 BOOL FASTCALL
PATH_AddFlatBezier (PPATH pPath
, POINT
*pt
, BOOL closed
);
48 BOOL FASTCALL
PATH_DoArcPart (PPATH pPath
, FLOAT_POINT corners
[], double angleStart
, double angleEnd
, BYTE startEntryType
);
49 BOOL FASTCALL
PATH_FillPath( PDC dc
, PPATH pPath
);
50 BOOL FASTCALL
PATH_FlattenPath (PPATH pPath
);
51 VOID FASTCALL
PATH_NormalizePoint (FLOAT_POINT corners
[], const FLOAT_POINT
*pPoint
, double *pX
, double *pY
);
53 BOOL FASTCALL
PATH_ReserveEntries (PPATH pPath
, INT numEntries
);
54 VOID FASTCALL
PATH_ScaleNormalizedPoint (FLOAT_POINT corners
[], double x
, double y
, POINT
*pPoint
);
55 BOOL FASTCALL
PATH_StrokePath(DC
*dc
, PPATH pPath
);
56 BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
);
58 VOID FASTCALL
IntGetCurrentPositionEx(PDC dc
, LPPOINT pt
);
60 /***********************************************************************
66 PATH_Delete(HPATH hPath
)
69 if (!hPath
) return FALSE
;
70 pPath
= PATH_LockPath( hPath
);
71 if (!pPath
) return FALSE
;
72 PATH_DestroyGdiPath( pPath
);
73 PATH_UnlockPath( pPath
);
74 PATH_FreeExtPathByHandle(hPath
);
81 IntGdiCloseFigure(PPATH pPath
)
83 ASSERT(pPath
->state
== PATH_Open
);
85 // FIXME: Shouldn't we draw a line to the beginning of the figure?
86 // Set PT_CLOSEFIGURE on the last entry and start a new stroke
87 if(pPath
->numEntriesUsed
)
89 pPath
->pFlags
[pPath
->numEntriesUsed
-1]|=PT_CLOSEFIGURE
;
90 pPath
->newStroke
=TRUE
;
100 PATH_FillPath( PDC dc
, PPATH pPath
)
102 //INT mapMode, graphicsMode;
103 //SIZE ptViewportExt, ptWindowExt;
104 //POINTL ptViewportOrg, ptWindowOrg;
107 PDC_ATTR pdcattr
= dc
->pdcattr
;
109 if( pPath
->state
!= PATH_Closed
)
111 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
115 if( PATH_PathToRegion( pPath
, pdcattr
->jFillMode
, &hrgn
))
117 /* Since PaintRgn interprets the region as being in logical coordinates
118 * but the points we store for the path are already in device
119 * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
120 * Using SaveDC to save information about the mapping mode / world
121 * transform would be easier but would require more overhead, especially
122 * now that SaveDC saves the current path.
125 /* Save the information about the old mapping mode */
126 //mapMode = pdcattr->iMapMode;
127 //ptViewportExt = pdcattr->szlViewportExt;
128 //ptViewportOrg = pdcattr->ptlViewportOrg;
129 //ptWindowExt = pdcattr->szlWindowExt;
130 //ptWindowOrg = pdcattr->ptlWindowOrg;
132 /* Save world transform
133 * NB: The Windows documentation on world transforms would lead one to
134 * believe that this has to be done only in GM_ADVANCED; however, my
135 * tests show that resetting the graphics mode to GM_COMPATIBLE does
136 * not reset the world transform.
138 MatrixS2XForm(&xform
, &dc
->dclevel
.mxWorldToPage
);
141 // IntGdiSetMapMode( dc, MM_TEXT );
142 // pdcattr->ptlViewportOrg.x = 0;
143 // pdcattr->ptlViewportOrg.y = 0;
144 // pdcattr->ptlWindowOrg.x = 0;
145 // pdcattr->ptlWindowOrg.y = 0;
147 // graphicsMode = pdcattr->iGraphicsMode;
148 // pdcattr->iGraphicsMode = GM_ADVANCED;
149 // IntGdiModifyWorldTransform( dc, &xform, MWT_IDENTITY );
150 // pdcattr->iGraphicsMode = graphicsMode;
152 /* Paint the region */
153 IntGdiPaintRgn( dc
, hrgn
);
154 GreDeleteObject( hrgn
);
155 /* Restore the old mapping mode */
156 // IntGdiSetMapMode( dc, mapMode );
157 // pdcattr->szlViewportExt = ptViewportExt;
158 // pdcattr->ptlViewportOrg = ptViewportOrg;
159 // pdcattr->szlWindowExt = ptWindowExt;
160 // pdcattr->ptlWindowOrg = ptWindowOrg;
162 /* Go to GM_ADVANCED temporarily to restore the world transform */
163 //graphicsMode = pdcattr->iGraphicsMode;
164 // pdcattr->iGraphicsMode = GM_ADVANCED;
165 // IntGdiModifyWorldTransform( dc, &xform, MWT_MAX+1 );
166 // pdcattr->iGraphicsMode = graphicsMode;
174 * Initializes the GdiPath structure.
178 PATH_InitGdiPath ( PPATH pPath
)
182 pPath
->state
=PATH_Null
;
185 pPath
->numEntriesUsed
=0;
186 pPath
->numEntriesAllocated
=0;
189 /* PATH_DestroyGdiPath
191 * Destroys a GdiPath structure (frees the memory in the arrays).
195 PATH_DestroyGdiPath ( PPATH pPath
)
199 if (pPath
->pPoints
) ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
200 if (pPath
->pFlags
) ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
203 /* PATH_AssignGdiPath
205 * Copies the GdiPath structure "pPathSrc" to "pPathDest". A deep copy is
206 * performed, i.e. the contents of the pPoints and pFlags arrays are copied,
207 * not just the pointers. Since this means that the arrays in pPathDest may
208 * need to be resized, pPathDest should have been initialized using
209 * PATH_InitGdiPath (in C++, this function would be an assignment operator,
210 * not a copy constructor).
211 * Returns TRUE if successful, else FALSE.
215 PATH_AssignGdiPath ( PPATH pPathDest
, const PPATH pPathSrc
)
217 ASSERT(pPathDest
!=NULL
&& pPathSrc
!=NULL
);
219 /* Make sure destination arrays are big enough */
220 if ( !PATH_ReserveEntries(pPathDest
, pPathSrc
->numEntriesUsed
) )
223 /* Perform the copy operation */
224 memcpy(pPathDest
->pPoints
, pPathSrc
->pPoints
,
225 sizeof(POINT
)*pPathSrc
->numEntriesUsed
);
226 memcpy(pPathDest
->pFlags
, pPathSrc
->pFlags
,
227 sizeof(BYTE
)*pPathSrc
->numEntriesUsed
);
229 pPathDest
->state
=pPathSrc
->state
;
230 pPathDest
->numEntriesUsed
=pPathSrc
->numEntriesUsed
;
231 pPathDest
->newStroke
=pPathSrc
->newStroke
;
237 * Should be called when a MoveTo is performed on a DC that has an
238 * open path. This starts a new stroke. Returns TRUE if successful, else
243 PATH_MoveTo ( PDC dc
)
245 PPATH pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
246 if (!pPath
) return FALSE
;
248 /* Check that path is open */
249 if ( pPath
->state
!= PATH_Open
)
251 PATH_UnlockPath( pPath
);
252 /* FIXME: Do we have to call SetLastError? */
255 /* Start a new stroke */
256 pPath
->newStroke
= TRUE
;
257 PATH_UnlockPath( pPath
);
263 * Should be called when a LineTo is performed on a DC that has an
264 * open path. This adds a PT_LINETO entry to the path (and possibly
265 * a PT_MOVETO entry, if this is the first LineTo in a stroke).
266 * Returns TRUE if successful, else FALSE.
270 PATH_LineTo ( PDC dc
, INT x
, INT y
)
274 POINT point
, pointCurPos
;
276 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
277 if (!pPath
) return FALSE
;
279 /* Check that path is open */
280 if ( pPath
->state
!= PATH_Open
)
282 PATH_UnlockPath( pPath
);
286 /* Convert point to device coordinates */
289 CoordLPtoDP ( dc
, &point
);
291 /* Add a PT_MOVETO if necessary */
292 if ( pPath
->newStroke
)
294 pPath
->newStroke
= FALSE
;
295 IntGetCurrentPositionEx ( dc
, &pointCurPos
);
296 CoordLPtoDP ( dc
, &pointCurPos
);
297 if ( !PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
) )
299 PATH_UnlockPath( pPath
);
304 /* Add a PT_LINETO entry */
305 Ret
= PATH_AddEntry(pPath
, &point
, PT_LINETO
);
306 PATH_UnlockPath( pPath
);
312 * Should be called when a call to Rectangle is performed on a DC that has
313 * an open path. Returns TRUE if successful, else FALSE.
317 PATH_Rectangle ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
)
320 POINT corners
[2], pointTemp
;
323 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
324 if (!pPath
) return FALSE
;
326 /* Check that path is open */
327 if ( pPath
->state
!= PATH_Open
)
329 PATH_UnlockPath( pPath
);
333 /* Convert points to device coordinates */
338 IntLPtoDP ( dc
, corners
, 2 );
340 /* Make sure first corner is top left and second corner is bottom right */
341 if ( corners
[0].x
> corners
[1].x
)
344 corners
[0].x
=corners
[1].x
;
347 if ( corners
[0].y
> corners
[1].y
)
350 corners
[0].y
=corners
[1].y
;
354 /* In GM_COMPATIBLE, don't include bottom and right edges */
355 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
361 /* Close any previous figure */
362 IntGdiCloseFigure(pPath
);
364 /* Add four points to the path */
365 pointTemp
.x
=corners
[1].x
;
366 pointTemp
.y
=corners
[0].y
;
367 if ( !PATH_AddEntry(pPath
, &pointTemp
, PT_MOVETO
) )
369 PATH_UnlockPath( pPath
);
372 if ( !PATH_AddEntry(pPath
, corners
, PT_LINETO
) )
374 PATH_UnlockPath( pPath
);
377 pointTemp
.x
=corners
[0].x
;
378 pointTemp
.y
=corners
[1].y
;
379 if ( !PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
) )
381 PATH_UnlockPath( pPath
);
384 if ( !PATH_AddEntry(pPath
, corners
+1, PT_LINETO
) )
386 PATH_UnlockPath( pPath
);
390 /* Close the rectangle figure */
391 IntGdiCloseFigure(pPath
) ;
392 PATH_UnlockPath( pPath
);
398 * Should be called when a call to RoundRect is performed on a DC that has
399 * an open path. Returns TRUE if successful, else FALSE.
401 * FIXME: it adds the same entries to the path as windows does, but there
402 * is an error in the bezier drawing code so that there are small pixel-size
403 * gaps when the resulting path is drawn by StrokePath()
405 BOOL FASTCALL
PATH_RoundRect(DC
*dc
, INT x1
, INT y1
, INT x2
, INT y2
, INT ell_width
, INT ell_height
)
408 POINT corners
[2], pointTemp
;
409 FLOAT_POINT ellCorners
[2];
411 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
412 if (!pPath
) return FALSE
;
414 /* Check that path is open */
415 if(pPath
->state
!=PATH_Open
)
417 PATH_UnlockPath( pPath
);
421 if(!PATH_CheckCorners(dc
,corners
,x1
,y1
,x2
,y2
))
423 PATH_UnlockPath( pPath
);
427 /* Add points to the roundrect path */
428 ellCorners
[0].x
= corners
[1].x
-ell_width
;
429 ellCorners
[0].y
= corners
[0].y
;
430 ellCorners
[1].x
= corners
[1].x
;
431 ellCorners
[1].y
= corners
[0].y
+ell_height
;
432 if(!PATH_DoArcPart(pPath
, ellCorners
, 0, -M_PI_2
, PT_MOVETO
))
434 PATH_UnlockPath( pPath
);
437 pointTemp
.x
= corners
[0].x
+ell_width
/2;
438 pointTemp
.y
= corners
[0].y
;
439 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
441 PATH_UnlockPath( pPath
);
444 ellCorners
[0].x
= corners
[0].x
;
445 ellCorners
[1].x
= corners
[0].x
+ell_width
;
446 if(!PATH_DoArcPart(pPath
, ellCorners
, -M_PI_2
, -M_PI
, FALSE
))
448 PATH_UnlockPath( pPath
);
451 pointTemp
.x
= corners
[0].x
;
452 pointTemp
.y
= corners
[1].y
-ell_height
/2;
453 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
455 PATH_UnlockPath( pPath
);
458 ellCorners
[0].y
= corners
[1].y
-ell_height
;
459 ellCorners
[1].y
= corners
[1].y
;
460 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI
, M_PI_2
, FALSE
))
462 PATH_UnlockPath( pPath
);
465 pointTemp
.x
= corners
[1].x
-ell_width
/2;
466 pointTemp
.y
= corners
[1].y
;
467 if(!PATH_AddEntry(pPath
, &pointTemp
, PT_LINETO
))
469 PATH_UnlockPath( pPath
);
472 ellCorners
[0].x
= corners
[1].x
-ell_width
;
473 ellCorners
[1].x
= corners
[1].x
;
474 if(!PATH_DoArcPart(pPath
, ellCorners
, M_PI_2
, 0, FALSE
))
476 PATH_UnlockPath( pPath
);
480 IntGdiCloseFigure(pPath
);
481 PATH_UnlockPath( pPath
);
487 * Should be called when a call to Ellipse is performed on a DC that has
488 * an open path. This adds four Bezier splines representing the ellipse
489 * to the path. Returns TRUE if successful, else FALSE.
493 PATH_Ellipse ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
)
496 /* TODO: This should probably be revised to call PATH_AngleArc */
497 /* (once it exists) */
498 BOOL Ret
= PATH_Arc ( dc
, x1
, y1
, x2
, y2
, x1
, (y1
+y2
)/2, x1
, (y1
+y2
)/2, GdiTypeArc
);
501 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
502 if (!pPath
) return FALSE
;
503 IntGdiCloseFigure(pPath
);
504 PATH_UnlockPath( pPath
);
511 * Should be called when a call to Arc is performed on a DC that has
512 * an open path. This adds up to five Bezier splines representing the arc
513 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
514 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
515 * -1 we add 1 extra line from the current DC position to the starting position
516 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
521 PATH_Arc ( PDC dc
, INT x1
, INT y1
, INT x2
, INT y2
,
522 INT xStart
, INT yStart
, INT xEnd
, INT yEnd
, INT lines
)
524 double angleStart
, angleEnd
, angleStartQuadrant
, angleEndQuadrant
=0.0;
525 /* Initialize angleEndQuadrant to silence gcc's warning */
527 FLOAT_POINT corners
[2], pointStart
, pointEnd
;
528 POINT centre
, pointCurPos
;
529 BOOL start
, end
, Ret
= TRUE
;
534 /* FIXME: This function should check for all possible error returns */
535 /* FIXME: Do we have to respect newStroke? */
539 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
540 if (!pPath
) return FALSE
;
542 clockwise
= ((dc
->dclevel
.flPath
& DCPATH_CLOCKWISE
) != 0);
544 /* Check that path is open */
545 if ( pPath
->state
!= PATH_Open
)
551 /* Check for zero height / width */
552 /* FIXME: Only in GM_COMPATIBLE? */
553 if ( x1
==x2
|| y1
==y2
)
558 /* Convert points to device coordinates */
559 corners
[0].x
=(FLOAT
)x1
;
560 corners
[0].y
=(FLOAT
)y1
;
561 corners
[1].x
=(FLOAT
)x2
;
562 corners
[1].y
=(FLOAT
)y2
;
563 pointStart
.x
=(FLOAT
)xStart
;
564 pointStart
.y
=(FLOAT
)yStart
;
565 pointEnd
.x
=(FLOAT
)xEnd
;
566 pointEnd
.y
=(FLOAT
)yEnd
;
567 INTERNAL_LPTODP_FLOAT(dc
, corners
);
568 INTERNAL_LPTODP_FLOAT(dc
, corners
+1);
569 INTERNAL_LPTODP_FLOAT(dc
, &pointStart
);
570 INTERNAL_LPTODP_FLOAT(dc
, &pointEnd
);
572 /* Make sure first corner is top left and second corner is bottom right */
573 if ( corners
[0].x
> corners
[1].x
)
576 corners
[0].x
=corners
[1].x
;
579 if ( corners
[0].y
> corners
[1].y
)
582 corners
[0].y
=corners
[1].y
;
586 /* Compute start and end angle */
587 PATH_NormalizePoint(corners
, &pointStart
, &x
, &y
);
588 angleStart
=atan2(y
, x
);
589 PATH_NormalizePoint(corners
, &pointEnd
, &x
, &y
);
590 angleEnd
=atan2(y
, x
);
592 /* Make sure the end angle is "on the right side" of the start angle */
595 if ( angleEnd
<= angleStart
)
598 ASSERT(angleEnd
>=angleStart
);
603 if(angleEnd
>=angleStart
)
606 ASSERT(angleEnd
<=angleStart
);
610 /* In GM_COMPATIBLE, don't include bottom and right edges */
611 if (dc
->pdcattr
->iGraphicsMode
== GM_COMPATIBLE
)
617 /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
618 if(lines
==GdiTypeArcTo
&& pPath
->newStroke
) // -1
620 pPath
->newStroke
=FALSE
;
621 IntGetCurrentPositionEx ( dc
, &pointCurPos
);
622 CoordLPtoDP(dc
, &pointCurPos
);
623 if(!PATH_AddEntry(pPath
, &pointCurPos
, PT_MOVETO
))
630 /* Add the arc to the path with one Bezier spline per quadrant that the
636 /* Determine the start and end angles for this quadrant */
639 angleStartQuadrant
=angleStart
;
641 angleEndQuadrant
=(floor(angleStart
/M_PI_2
)+1.0)*M_PI_2
;
643 angleEndQuadrant
=(ceil(angleStart
/M_PI_2
)-1.0)*M_PI_2
;
647 angleStartQuadrant
=angleEndQuadrant
;
649 angleEndQuadrant
+=M_PI_2
;
651 angleEndQuadrant
-=M_PI_2
;
654 /* Have we reached the last part of the arc? */
655 if ( (clockwise
&& angleEnd
<angleEndQuadrant
)
656 || (!clockwise
&& angleEnd
>angleEndQuadrant
)
659 /* Adjust the end angle for this quadrant */
660 angleEndQuadrant
= angleEnd
;
664 /* Add the Bezier spline to the path */
665 PATH_DoArcPart ( pPath
, corners
, angleStartQuadrant
, angleEndQuadrant
,
666 start
? (lines
==GdiTypeArcTo
? PT_LINETO
: PT_MOVETO
) : FALSE
); // -1
670 /* chord: close figure. pie: add line and close figure */
671 if (lines
==GdiTypeChord
) // 1
673 IntGdiCloseFigure(pPath
);
675 else if (lines
==GdiTypePie
) // 2
677 centre
.x
= (corners
[0].x
+corners
[1].x
)/2;
678 centre
.y
= (corners
[0].y
+corners
[1].y
)/2;
679 if(!PATH_AddEntry(pPath
, ¢re
, PT_LINETO
| PT_CLOSEFIGURE
))
683 PATH_UnlockPath( pPath
);
689 PATH_PolyBezierTo ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
699 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
700 if (!pPath
) return FALSE
;
702 /* Check that path is open */
703 if ( pPath
->state
!= PATH_Open
)
705 PATH_UnlockPath( pPath
);
709 /* Add a PT_MOVETO if necessary */
710 if ( pPath
->newStroke
)
712 pPath
->newStroke
=FALSE
;
713 IntGetCurrentPositionEx ( dc
, &pt
);
714 CoordLPtoDP ( dc
, &pt
);
715 if ( !PATH_AddEntry(pPath
, &pt
, PT_MOVETO
) )
717 PATH_UnlockPath( pPath
);
722 for(i
= 0; i
< cbPoints
; i
++)
725 CoordLPtoDP ( dc
, &pt
);
726 PATH_AddEntry(pPath
, &pt
, PT_BEZIERTO
);
728 PATH_UnlockPath( pPath
);
734 PATH_PolyBezier ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
744 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
745 if (!pPath
) return FALSE
;
747 /* Check that path is open */
748 if ( pPath
->state
!= PATH_Open
)
750 PATH_UnlockPath( pPath
);
754 for ( i
= 0; i
< cbPoints
; i
++ )
757 CoordLPtoDP ( dc
, &pt
);
758 PATH_AddEntry ( pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_BEZIERTO
);
760 PATH_UnlockPath( pPath
);
766 PATH_Polyline ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
776 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
777 if (!pPath
) return FALSE
;
779 /* Check that path is open */
780 if ( pPath
->state
!= PATH_Open
)
782 PATH_UnlockPath( pPath
);
785 for ( i
= 0; i
< cbPoints
; i
++ )
788 CoordLPtoDP ( dc
, &pt
);
789 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
: PT_LINETO
);
791 PATH_UnlockPath( pPath
);
797 PATH_PolylineTo ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
807 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
808 if (!pPath
) return FALSE
;
810 /* Check that path is open */
811 if ( pPath
->state
!= PATH_Open
)
813 PATH_UnlockPath( pPath
);
817 /* Add a PT_MOVETO if necessary */
818 if ( pPath
->newStroke
)
820 pPath
->newStroke
= FALSE
;
821 IntGetCurrentPositionEx ( dc
, &pt
);
822 CoordLPtoDP ( dc
, &pt
);
823 if ( !PATH_AddEntry(pPath
, &pt
, PT_MOVETO
) )
825 PATH_UnlockPath( pPath
);
830 for(i
= 0; i
< cbPoints
; i
++)
833 CoordLPtoDP ( dc
, &pt
);
834 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
836 PATH_UnlockPath( pPath
);
843 PATH_Polygon ( PDC dc
, const POINT
*pts
, DWORD cbPoints
)
852 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
853 if (!pPath
) return FALSE
;
855 /* Check that path is open */
856 if ( pPath
->state
!= PATH_Open
)
858 PATH_UnlockPath( pPath
);
862 for(i
= 0; i
< cbPoints
; i
++)
865 CoordLPtoDP ( dc
, &pt
);
866 PATH_AddEntry(pPath
, &pt
, (i
== 0) ? PT_MOVETO
:
867 ((i
== cbPoints
-1) ? PT_LINETO
| PT_CLOSEFIGURE
:
870 PATH_UnlockPath( pPath
);
876 PATH_PolyPolygon ( PDC dc
, const POINT
* pts
, const INT
* counts
, UINT polygons
)
879 ULONG poly
, point
, i
;
887 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
888 if (!pPath
) return FALSE
;
890 /* Check that path is open */
891 if ( pPath
->state
!= PATH_Open
)
893 PATH_UnlockPath( pPath
);
897 for(i
= 0, poly
= 0; poly
< polygons
; poly
++)
899 for(point
= 0; point
< (ULONG
) counts
[poly
]; point
++, i
++)
902 CoordLPtoDP ( dc
, &pt
);
903 if(point
== 0) startpt
= pt
;
904 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
906 /* win98 adds an extra line to close the figure for some reason */
907 PATH_AddEntry(pPath
, &startpt
, PT_LINETO
| PT_CLOSEFIGURE
);
909 PATH_UnlockPath( pPath
);
915 PATH_PolyPolyline ( PDC dc
, const POINT
* pts
, const DWORD
* counts
, DWORD polylines
)
918 ULONG poly
, point
, i
;
924 ASSERT ( polylines
);
926 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
927 if (!pPath
) return FALSE
;
929 /* Check that path is open */
930 if ( pPath
->state
!= PATH_Open
)
932 PATH_UnlockPath( pPath
);
936 for(i
= 0, poly
= 0; poly
< polylines
; poly
++)
938 for(point
= 0; point
< counts
[poly
]; point
++, i
++)
941 CoordLPtoDP ( dc
, &pt
);
942 PATH_AddEntry(pPath
, &pt
, (point
== 0) ? PT_MOVETO
: PT_LINETO
);
945 PATH_UnlockPath( pPath
);
952 * Helper function for PATH_RoundRect() and PATH_Rectangle()
954 BOOL
PATH_CheckCorners(DC
*dc
, POINT corners
[], INT x1
, INT y1
, INT x2
, INT y2
)
957 PDC_ATTR pdcattr
= dc
->pdcattr
;
959 /* Convert points to device coordinates */
964 CoordLPtoDP(dc
, &corners
[0]);
965 CoordLPtoDP(dc
, &corners
[1]);
967 /* Make sure first corner is top left and second corner is bottom right */
968 if(corners
[0].x
>corners
[1].x
)
971 corners
[0].x
=corners
[1].x
;
974 if(corners
[0].y
>corners
[1].y
)
977 corners
[0].y
=corners
[1].y
;
981 /* In GM_COMPATIBLE, don't include bottom and right edges */
982 if(pdcattr
->iGraphicsMode
==GM_COMPATIBLE
)
992 /* PATH_AddFlatBezier
997 PATH_AddFlatBezier ( PPATH pPath
, POINT
*pt
, BOOL closed
)
1002 pts
= GDI_Bezier( pt
, 4, &no
);
1003 if ( !pts
) return FALSE
;
1005 for(i
= 1; i
< no
; i
++)
1006 PATH_AddEntry(pPath
, &pts
[i
], (i
== no
-1 && closed
) ? PT_LINETO
| PT_CLOSEFIGURE
: PT_LINETO
);
1008 ExFreePoolWithTag(pts
, TAG_BEZIER
);
1014 * Replaces Beziers with line segments
1019 PATH_FlattenPath(PPATH pPath
)
1024 RtlZeroMemory(&newPath
, sizeof(newPath
));
1025 newPath
.state
= PATH_Open
;
1026 for(srcpt
= 0; srcpt
< pPath
->numEntriesUsed
; srcpt
++) {
1027 switch(pPath
->pFlags
[srcpt
] & ~PT_CLOSEFIGURE
) {
1030 PATH_AddEntry(&newPath
, &pPath
->pPoints
[srcpt
], pPath
->pFlags
[srcpt
]);
1033 PATH_AddFlatBezier(&newPath
, &pPath
->pPoints
[srcpt
-1], pPath
->pFlags
[srcpt
+2] & PT_CLOSEFIGURE
);
1038 newPath
.state
= PATH_Closed
;
1039 PATH_AssignGdiPath(pPath
, &newPath
);
1040 PATH_EmptyPath(&newPath
);
1045 /* PATH_PathToRegion
1047 * Creates a region from the specified path using the specified polygon
1048 * filling mode. The path is left unchanged. A handle to the region that
1049 * was created is stored in *pHrgn. If successful, TRUE is returned; if an
1050 * error occurs, SetLastError is called with the appropriate value and
1051 * FALSE is returned.
1055 PATH_PathToRegion ( PPATH pPath
, INT nPolyFillMode
, HRGN
*pHrgn
)
1057 int numStrokes
, iStroke
, i
;
1058 PULONG pNumPointsInStroke
;
1061 ASSERT(pPath
!=NULL
);
1062 ASSERT(pHrgn
!=NULL
);
1064 PATH_FlattenPath ( pPath
);
1066 /* First pass: Find out how many strokes there are in the path */
1067 /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
1069 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1070 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1078 /* Allocate memory for number-of-points-in-stroke array */
1079 pNumPointsInStroke
= ExAllocatePoolWithTag(PagedPool
, sizeof(ULONG
) * numStrokes
, TAG_PATH
);
1080 if(!pNumPointsInStroke
)
1082 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1086 /* Second pass: remember number of points in each polygon */
1087 iStroke
=-1; /* Will get incremented to 0 at beginning of first stroke */
1088 for(i
=0; i
<pPath
->numEntriesUsed
; i
++)
1090 /* Is this the beginning of a new stroke? */
1091 if((pPath
->pFlags
[i
] & ~PT_CLOSEFIGURE
) == PT_MOVETO
)
1094 pNumPointsInStroke
[iStroke
]=0;
1097 pNumPointsInStroke
[iStroke
]++;
1100 /* Create a region from the strokes */
1101 hrgn
= IntCreatePolyPolygonRgn( pPath
->pPoints
,
1107 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1111 /* Free memory for number-of-points-in-stroke array */
1112 ExFreePoolWithTag(pNumPointsInStroke
, TAG_PATH
);
1121 * Removes all entries from the path and sets the path state to PATH_Null.
1125 PATH_EmptyPath ( PPATH pPath
)
1127 ASSERT(pPath
!=NULL
);
1129 pPath
->state
=PATH_Null
;
1130 pPath
->numEntriesUsed
=0;
1135 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
1136 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
1137 * successful, FALSE otherwise (e.g. if not enough memory was available).
1141 PATH_AddEntry ( PPATH pPath
, const POINT
*pPoint
, BYTE flags
)
1143 ASSERT(pPath
!=NULL
);
1145 /* FIXME: If newStroke is true, perhaps we want to check that we're
1146 * getting a PT_MOVETO
1149 /* Check that path is open */
1150 if ( pPath
->state
!= PATH_Open
)
1153 /* Reserve enough memory for an extra path entry */
1154 if ( !PATH_ReserveEntries(pPath
, pPath
->numEntriesUsed
+1) )
1157 /* Store information in path entry */
1158 pPath
->pPoints
[pPath
->numEntriesUsed
]=*pPoint
;
1159 pPath
->pFlags
[pPath
->numEntriesUsed
]=flags
;
1161 /* If this is PT_CLOSEFIGURE, we have to start a new stroke next time */
1162 if((flags
& PT_CLOSEFIGURE
) == PT_CLOSEFIGURE
)
1163 pPath
->newStroke
=TRUE
;
1165 /* Increment entry count */
1166 pPath
->numEntriesUsed
++;
1171 /* PATH_ReserveEntries
1173 * Ensures that at least "numEntries" entries (for points and flags) have
1174 * been allocated; allocates larger arrays and copies the existing entries
1175 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
1179 PATH_ReserveEntries ( PPATH pPath
, INT numEntries
)
1181 INT numEntriesToAllocate
;
1185 ASSERT(pPath
!=NULL
);
1186 ASSERT(numEntries
>=0);
1188 /* Do we have to allocate more memory? */
1189 if(numEntries
> pPath
->numEntriesAllocated
)
1191 /* Find number of entries to allocate. We let the size of the array
1192 * grow exponentially, since that will guarantee linear time
1194 if(pPath
->numEntriesAllocated
)
1196 numEntriesToAllocate
=pPath
->numEntriesAllocated
;
1197 while(numEntriesToAllocate
<numEntries
)
1198 numEntriesToAllocate
=numEntriesToAllocate
*GROW_FACTOR_NUMER
/GROW_FACTOR_DENOM
;
1200 numEntriesToAllocate
=numEntries
;
1202 /* Allocate new arrays */
1203 pPointsNew
=(POINT
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(POINT
), TAG_PATH
);
1206 pFlagsNew
=(BYTE
*)ExAllocatePoolWithTag(PagedPool
, numEntriesToAllocate
* sizeof(BYTE
), TAG_PATH
);
1209 ExFreePoolWithTag(pPointsNew
, TAG_PATH
);
1213 /* Copy old arrays to new arrays and discard old arrays */
1216 ASSERT(pPath
->pFlags
);
1218 memcpy(pPointsNew
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
1219 memcpy(pFlagsNew
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
1221 ExFreePoolWithTag(pPath
->pPoints
, TAG_PATH
);
1222 ExFreePoolWithTag(pPath
->pFlags
, TAG_PATH
);
1224 pPath
->pPoints
=pPointsNew
;
1225 pPath
->pFlags
=pFlagsNew
;
1226 pPath
->numEntriesAllocated
=numEntriesToAllocate
;
1234 * Creates a Bezier spline that corresponds to part of an arc and appends the
1235 * corresponding points to the path. The start and end angles are passed in
1236 * "angleStart" and "angleEnd"; these angles should span a quarter circle
1237 * at most. If "startEntryType" is non-zero, an entry of that type for the first
1238 * control point is added to the path; otherwise, it is assumed that the current
1239 * position is equal to the first control point.
1243 PATH_DoArcPart ( PPATH pPath
, FLOAT_POINT corners
[],
1244 double angleStart
, double angleEnd
, BYTE startEntryType
)
1246 double halfAngle
, a
;
1247 double xNorm
[4], yNorm
[4];
1251 ASSERT(fabs(angleEnd
-angleStart
)<=M_PI_2
);
1253 /* FIXME: Is there an easier way of computing this? */
1255 /* Compute control points */
1256 halfAngle
=(angleEnd
-angleStart
)/2.0;
1257 if(fabs(halfAngle
)>1e-8)
1259 a
=4.0/3.0*(1-cos(halfAngle
))/sin(halfAngle
);
1260 xNorm
[0]=cos(angleStart
);
1261 yNorm
[0]=sin(angleStart
);
1262 xNorm
[1]=xNorm
[0] - a
*yNorm
[0];
1263 yNorm
[1]=yNorm
[0] + a
*xNorm
[0];
1264 xNorm
[3]=cos(angleEnd
);
1265 yNorm
[3]=sin(angleEnd
);
1266 xNorm
[2]=xNorm
[3] + a
*yNorm
[3];
1267 yNorm
[2]=yNorm
[3] - a
*xNorm
[3];
1271 xNorm
[i
]=cos(angleStart
);
1272 yNorm
[i
]=sin(angleStart
);
1275 /* Add starting point to path if desired */
1278 PATH_ScaleNormalizedPoint(corners
, xNorm
[0], yNorm
[0], &point
);
1279 if(!PATH_AddEntry(pPath
, &point
, startEntryType
))
1283 /* Add remaining control points */
1286 PATH_ScaleNormalizedPoint(corners
, xNorm
[i
], yNorm
[i
], &point
);
1287 if(!PATH_AddEntry(pPath
, &point
, PT_BEZIERTO
))
1294 /* PATH_ScaleNormalizedPoint
1296 * Scales a normalized point (x, y) with respect to the box whose corners are
1297 * passed in "corners". The point is stored in "*pPoint". The normalized
1298 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
1299 * (1.0, 1.0) correspond to corners[1].
1303 PATH_ScaleNormalizedPoint ( FLOAT_POINT corners
[], double x
,
1304 double y
, POINT
*pPoint
)
1308 pPoint
->x
=GDI_ROUND( (double)corners
[0].x
+ (double)(corners
[1].x
-corners
[0].x
)*0.5*(x
+1.0) );
1309 pPoint
->y
=GDI_ROUND( (double)corners
[0].y
+ (double)(corners
[1].y
-corners
[0].y
)*0.5*(y
+1.0) );
1312 /* PATH_NormalizePoint
1314 * Normalizes a point with respect to the box whose corners are passed in
1315 * corners. The normalized coordinates are stored in *pX and *pY.
1319 PATH_NormalizePoint ( FLOAT_POINT corners
[],
1320 const FLOAT_POINT
*pPoint
,
1321 double *pX
, double *pY
)
1327 *pX
=(double)(pPoint
->x
-corners
[0].x
)/(double)(corners
[1].x
-corners
[0].x
) * 2.0 - 1.0;
1328 *pY
=(double)(pPoint
->y
-corners
[0].y
)/(double)(corners
[1].y
-corners
[0].y
) * 2.0 - 1.0;
1332 BOOL FASTCALL
PATH_StrokePath(DC
*dc
, PPATH pPath
)
1336 INT nLinePts
, nAlloc
;
1337 POINT
*pLinePts
= NULL
;
1338 POINT ptViewportOrg
, ptWindowOrg
;
1339 SIZE szViewportExt
, szWindowExt
;
1340 DWORD mapMode
, graphicsMode
;
1342 PDC_ATTR pdcattr
= dc
->pdcattr
;
1344 DPRINT("Enter %s\n", __FUNCTION__
);
1346 if (pPath
->state
!= PATH_Closed
)
1349 /* Save the mapping mode info */
1350 mapMode
= pdcattr
->iMapMode
;
1352 DC_vUpdateViewportExt(dc
);
1353 szViewportExt
= dc
->pdcattr
->szlViewportExt
;
1354 ptViewportOrg
= dc
->pdcattr
->ptlViewportOrg
;
1355 szWindowExt
= dc
->pdcattr
->szlWindowExt
;
1356 ptWindowOrg
= dc
->pdcattr
->ptlWindowOrg
;
1358 MatrixS2XForm(&xform
, &dc
->dclevel
.mxWorldToPage
);
1361 pdcattr
->iMapMode
= MM_TEXT
;
1362 pdcattr
->ptlViewportOrg
.x
= 0;
1363 pdcattr
->ptlViewportOrg
.y
= 0;
1364 pdcattr
->ptlWindowOrg
.x
= 0;
1365 pdcattr
->ptlWindowOrg
.y
= 0;
1366 graphicsMode
= pdcattr
->iGraphicsMode
;
1367 pdcattr
->iGraphicsMode
= GM_ADVANCED
;
1368 IntGdiModifyWorldTransform(dc
, &xform
, MWT_IDENTITY
);
1369 pdcattr
->iGraphicsMode
= graphicsMode
;
1371 /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
1372 * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer
1373 * space in case we get one to keep the number of reallocations small. */
1374 nAlloc
= pPath
->numEntriesUsed
+ 1 + 300;
1375 pLinePts
= ExAllocatePoolWithTag(PagedPool
, nAlloc
* sizeof(POINT
), TAG_PATH
);
1378 DPRINT1("Can't allocate pool!\n");
1379 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1384 for(i
= 0; i
< pPath
->numEntriesUsed
; i
++)
1386 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
))
1387 && (pPath
->pFlags
[i
] != PT_MOVETO
))
1389 DPRINT1("Expected PT_MOVETO %s, got path flag %d\n",
1390 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1391 (INT
)pPath
->pFlags
[i
]);
1395 switch(pPath
->pFlags
[i
])
1398 DPRINT("Got PT_MOVETO (%ld, %ld)\n",
1399 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1400 if(nLinePts
>= 2) IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1402 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1405 case (PT_LINETO
| PT_CLOSEFIGURE
):
1406 DPRINT("Got PT_LINETO (%ld, %ld)\n",
1407 pPath
->pPoints
[i
].x
, pPath
->pPoints
[i
].y
);
1408 pLinePts
[nLinePts
++] = pPath
->pPoints
[i
];
1411 DPRINT("Got PT_BEZIERTO\n");
1412 if(pPath
->pFlags
[i
+1] != PT_BEZIERTO
||
1413 (pPath
->pFlags
[i
+2] & ~PT_CLOSEFIGURE
) != PT_BEZIERTO
)
1415 DPRINT1("Path didn't contain 3 successive PT_BEZIERTOs\n");
1421 INT nBzrPts
, nMinAlloc
;
1422 POINT
*pBzrPts
= GDI_Bezier(&pPath
->pPoints
[i
-1], 4, &nBzrPts
);
1423 /* Make sure we have allocated enough memory for the lines of
1424 * this bezier and the rest of the path, assuming we won't get
1425 * another one (since we won't reallocate again then). */
1426 nMinAlloc
= nLinePts
+ (pPath
->numEntriesUsed
- i
) + nBzrPts
;
1427 if(nAlloc
< nMinAlloc
)
1429 // Reallocate memory
1431 POINT
*Realloc
= NULL
;
1432 nAlloc
= nMinAlloc
* 2;
1434 Realloc
= ExAllocatePoolWithTag(PagedPool
,
1435 nAlloc
* sizeof(POINT
),
1440 DPRINT1("Can't allocate pool!\n");
1444 memcpy(Realloc
, pLinePts
, nLinePts
*sizeof(POINT
));
1445 ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1448 memcpy(&pLinePts
[nLinePts
], &pBzrPts
[1], (nBzrPts
- 1) * sizeof(POINT
));
1449 nLinePts
+= nBzrPts
- 1;
1450 ExFreePoolWithTag(pBzrPts
, TAG_BEZIER
);
1455 DPRINT1("Got path flag %d (not supported)\n", (INT
)pPath
->pFlags
[i
]);
1459 if(pPath
->pFlags
[i
] & PT_CLOSEFIGURE
)
1461 pLinePts
[nLinePts
++] = pLinePts
[0];
1465 IntGdiPolyline(dc
, pLinePts
, nLinePts
);
1470 if(pLinePts
) ExFreePoolWithTag(pLinePts
, TAG_PATH
);
1472 /* Restore the old mapping mode */
1473 pdcattr
->iMapMode
= mapMode
;
1474 pdcattr
->szlWindowExt
.cx
= szWindowExt
.cx
;
1475 pdcattr
->szlWindowExt
.cy
= szWindowExt
.cy
;
1476 pdcattr
->ptlWindowOrg
.x
= ptWindowOrg
.x
;
1477 pdcattr
->ptlWindowOrg
.y
= ptWindowOrg
.y
;
1479 pdcattr
->szlViewportExt
.cx
= szViewportExt
.cx
;
1480 pdcattr
->szlViewportExt
.cy
= szViewportExt
.cy
;
1481 pdcattr
->ptlViewportOrg
.x
= ptViewportOrg
.x
;
1482 pdcattr
->ptlViewportOrg
.y
= ptViewportOrg
.y
;
1484 /* Restore the world transform */
1485 XForm2MatrixS(&dc
->dclevel
.mxWorldToPage
, &xform
);
1487 /* If we've moved the current point then get its new position
1488 which will be in device (MM_TEXT) co-ords, convert it to
1489 logical co-ords and re-set it. This basically updates
1490 dc->CurPosX|Y so that their values are in the correct mapping
1496 IntGetCurrentPositionEx(dc
, &pt
);
1497 IntDPtoLP(dc
, &pt
, 1);
1498 IntGdiMoveToEx(dc
, pt
.x
, pt
.y
, NULL
, FALSE
);
1500 DPRINT("Leave %s, ret=%d\n", __FUNCTION__
, ret
);
1504 #define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1509 PATH_WidenPath(DC
*dc
)
1511 INT i
, j
, numStrokes
, penWidth
, penWidthIn
, penWidthOut
, size
, penStyle
;
1513 PPATH pPath
, pNewPath
, *pStrokes
= NULL
, *pOldStrokes
, pUpPath
, pDownPath
;
1515 DWORD obj_type
, joint
, endcap
, penType
;
1516 PDC_ATTR pdcattr
= dc
->pdcattr
;
1518 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
1519 if (!pPath
) return FALSE
;
1521 if(pPath
->state
== PATH_Open
)
1523 PATH_UnlockPath( pPath
);
1524 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1528 PATH_FlattenPath(pPath
);
1530 size
= IntGdiGetObject( pdcattr
->hpen
, 0, NULL
);
1533 PATH_UnlockPath( pPath
);
1534 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1538 elp
= ExAllocatePoolWithTag(PagedPool
, size
, TAG_PATH
);
1539 (VOID
) IntGdiGetObject( pdcattr
->hpen
, size
, elp
);
1541 obj_type
= GDIOBJ_GetObjectType(pdcattr
->hpen
);
1542 if(obj_type
== GDI_OBJECT_TYPE_PEN
)
1544 penStyle
= ((LOGPEN
*)elp
)->lopnStyle
;
1546 else if(obj_type
== GDI_OBJECT_TYPE_EXTPEN
)
1548 penStyle
= elp
->elpPenStyle
;
1552 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1553 ExFreePoolWithTag(elp
, TAG_PATH
);
1554 PATH_UnlockPath( pPath
);
1558 penWidth
= elp
->elpWidth
;
1559 ExFreePoolWithTag(elp
, TAG_PATH
);
1561 endcap
= (PS_ENDCAP_MASK
& penStyle
);
1562 joint
= (PS_JOIN_MASK
& penStyle
);
1563 penType
= (PS_TYPE_MASK
& penStyle
);
1565 /* The function cannot apply to cosmetic pens */
1566 if(obj_type
== GDI_OBJECT_TYPE_EXTPEN
&& penType
== PS_COSMETIC
)
1568 PATH_UnlockPath( pPath
);
1569 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
1573 penWidthIn
= penWidth
/ 2;
1574 penWidthOut
= penWidth
/ 2;
1575 if(penWidthIn
+ penWidthOut
< penWidth
)
1580 for(i
= 0, j
= 0; i
< pPath
->numEntriesUsed
; i
++, j
++)
1583 if((i
== 0 || (pPath
->pFlags
[i
-1] & PT_CLOSEFIGURE
)) &&
1584 (pPath
->pFlags
[i
] != PT_MOVETO
))
1586 DPRINT1("Expected PT_MOVETO %s, got path flag %c\n",
1587 i
== 0 ? "as first point" : "after PT_CLOSEFIGURE",
1591 switch(pPath
->pFlags
[i
])
1596 pStrokes
[numStrokes
- 1]->state
= PATH_Closed
;
1600 if (numStrokes
== 1)
1601 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1604 pOldStrokes
= pStrokes
; // Save old pointer.
1605 pStrokes
= ExAllocatePoolWithTag(PagedPool
, numStrokes
* sizeof(PPATH
), TAG_PATH
);
1606 if (!pStrokes
) return FALSE
;
1607 RtlCopyMemory(pStrokes
, pOldStrokes
, numStrokes
* sizeof(PPATH
));
1608 ExFreePoolWithTag(pOldStrokes
, TAG_PATH
); // Free old pointer.
1610 if (!pStrokes
) return FALSE
;
1611 pStrokes
[numStrokes
- 1] = ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1613 PATH_InitGdiPath(pStrokes
[numStrokes
- 1]);
1614 pStrokes
[numStrokes
- 1]->state
= PATH_Open
;
1616 case (PT_LINETO
| PT_CLOSEFIGURE
):
1617 point
.x
= pPath
->pPoints
[i
].x
;
1618 point
.y
= pPath
->pPoints
[i
].y
;
1619 PATH_AddEntry(pStrokes
[numStrokes
- 1], &point
, pPath
->pFlags
[i
]);
1622 /* should never happen because of the FlattenPath call */
1623 DPRINT1("Should never happen\n");
1626 DPRINT1("Got path flag %c\n", pPath
->pFlags
[i
]);
1631 pNewPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1632 PATH_InitGdiPath(pNewPath
);
1633 pNewPath
->state
= PATH_Open
;
1635 for(i
= 0; i
< numStrokes
; i
++)
1637 pUpPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1638 PATH_InitGdiPath(pUpPath
);
1639 pUpPath
->state
= PATH_Open
;
1640 pDownPath
= ExAllocatePoolWithTag(PagedPool
, sizeof(PATH
), TAG_PATH
);
1641 PATH_InitGdiPath(pDownPath
);
1642 pDownPath
->state
= PATH_Open
;
1644 for(j
= 0; j
< pStrokes
[i
]->numEntriesUsed
; j
++)
1646 /* Beginning or end of the path if not closed */
1647 if((!(pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) && (j
== 0 || j
== pStrokes
[i
]->numEntriesUsed
- 1) )
1649 /* Compute segment angle */
1650 double xo
, yo
, xa
, ya
, theta
;
1652 FLOAT_POINT corners
[2];
1655 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1656 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1657 xa
= pStrokes
[i
]->pPoints
[1].x
;
1658 ya
= pStrokes
[i
]->pPoints
[1].y
;
1662 xa
= pStrokes
[i
]->pPoints
[j
- 1].x
;
1663 ya
= pStrokes
[i
]->pPoints
[j
- 1].y
;
1664 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1665 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1667 theta
= atan2( ya
- yo
, xa
- xo
);
1670 case PS_ENDCAP_SQUARE
:
1671 pt
.x
= xo
+ round(sqrt(2) * penWidthOut
* cos(M_PI_4
+ theta
));
1672 pt
.y
= yo
+ round(sqrt(2) * penWidthOut
* sin(M_PI_4
+ theta
));
1673 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
) );
1674 pt
.x
= xo
+ round(sqrt(2) * penWidthIn
* cos(- M_PI_4
+ theta
));
1675 pt
.y
= yo
+ round(sqrt(2) * penWidthIn
* sin(- M_PI_4
+ theta
));
1676 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1678 case PS_ENDCAP_FLAT
:
1679 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1680 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1681 PATH_AddEntry(pUpPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1682 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1683 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1684 PATH_AddEntry(pUpPath
, &pt
, PT_LINETO
);
1686 case PS_ENDCAP_ROUND
:
1688 corners
[0].x
= xo
- penWidthIn
;
1689 corners
[0].y
= yo
- penWidthIn
;
1690 corners
[1].x
= xo
+ penWidthOut
;
1691 corners
[1].y
= yo
+ penWidthOut
;
1692 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI_2
, theta
+ 3 * M_PI_4
, (j
== 0 ? PT_MOVETO
: FALSE
));
1693 PATH_DoArcPart(pUpPath
,corners
, theta
+ 3 * M_PI_4
, theta
+ M_PI
, FALSE
);
1694 PATH_DoArcPart(pUpPath
,corners
, theta
+ M_PI
, theta
+ 5 * M_PI_4
, FALSE
);
1695 PATH_DoArcPart(pUpPath
,corners
, theta
+ 5 * M_PI_4
, theta
+ 3 * M_PI_2
, FALSE
);
1699 /* Corpse of the path */
1704 double xa
, ya
, xb
, yb
, xo
, yo
;
1705 double alpha
, theta
, miterWidth
;
1706 DWORD _joint
= joint
;
1708 PPATH pInsidePath
, pOutsidePath
;
1709 if(j
> 0 && j
< pStrokes
[i
]->numEntriesUsed
- 1)
1716 previous
= pStrokes
[i
]->numEntriesUsed
- 1;
1724 xo
= pStrokes
[i
]->pPoints
[j
].x
;
1725 yo
= pStrokes
[i
]->pPoints
[j
].y
;
1726 xa
= pStrokes
[i
]->pPoints
[previous
].x
;
1727 ya
= pStrokes
[i
]->pPoints
[previous
].y
;
1728 xb
= pStrokes
[i
]->pPoints
[next
].x
;
1729 yb
= pStrokes
[i
]->pPoints
[next
].y
;
1730 theta
= atan2( yo
- ya
, xo
- xa
);
1731 alpha
= atan2( yb
- yo
, xb
- xo
) - theta
;
1732 if (alpha
> 0) alpha
-= M_PI
;
1734 if(_joint
== PS_JOIN_MITER
&& dc
->dclevel
.laPath
.eMiterLimit
< fabs(1 / sin(alpha
/2)))
1736 _joint
= PS_JOIN_BEVEL
;
1740 pInsidePath
= pUpPath
;
1741 pOutsidePath
= pDownPath
;
1745 pInsidePath
= pDownPath
;
1746 pOutsidePath
= pUpPath
;
1752 /* Inside angle points */
1755 pt
.x
= xo
- round( penWidthIn
* cos(theta
+ M_PI_2
) );
1756 pt
.y
= yo
- round( penWidthIn
* sin(theta
+ M_PI_2
) );
1760 pt
.x
= xo
+ round( penWidthIn
* cos(theta
+ M_PI_2
) );
1761 pt
.y
= yo
+ round( penWidthIn
* sin(theta
+ M_PI_2
) );
1763 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1766 pt
.x
= xo
+ round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1767 pt
.y
= yo
+ round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1771 pt
.x
= xo
- round( penWidthIn
* cos(M_PI_2
+ alpha
+ theta
) );
1772 pt
.y
= yo
- round( penWidthIn
* sin(M_PI_2
+ alpha
+ theta
) );
1774 PATH_AddEntry(pInsidePath
, &pt
, PT_LINETO
);
1775 /* Outside angle point */
1778 case PS_JOIN_MITER
:
1779 miterWidth
= fabs(penWidthOut
/ cos(M_PI_2
- fabs(alpha
) / 2));
1780 pt
.x
= xo
+ round( miterWidth
* cos(theta
+ alpha
/ 2) );
1781 pt
.y
= yo
+ round( miterWidth
* sin(theta
+ alpha
/ 2) );
1782 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1784 case PS_JOIN_BEVEL
:
1787 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1788 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1792 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1793 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1795 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1798 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1799 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1803 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1804 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1806 PATH_AddEntry(pOutsidePath
, &pt
, PT_LINETO
);
1808 case PS_JOIN_ROUND
:
1812 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ M_PI_2
) );
1813 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ M_PI_2
) );
1817 pt
.x
= xo
- round( penWidthOut
* cos(theta
+ M_PI_2
) );
1818 pt
.y
= yo
- round( penWidthOut
* sin(theta
+ M_PI_2
) );
1820 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1821 pt
.x
= xo
+ round( penWidthOut
* cos(theta
+ alpha
/ 2) );
1822 pt
.y
= yo
+ round( penWidthOut
* sin(theta
+ alpha
/ 2) );
1823 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1826 pt
.x
= xo
- round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1827 pt
.y
= yo
- round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1831 pt
.x
= xo
+ round( penWidthOut
* cos(M_PI_2
+ alpha
+ theta
) );
1832 pt
.y
= yo
+ round( penWidthOut
* sin(M_PI_2
+ alpha
+ theta
) );
1834 PATH_AddEntry(pOutsidePath
, &pt
, PT_BEZIERTO
);
1839 for(j
= 0; j
< pUpPath
->numEntriesUsed
; j
++)
1842 pt
.x
= pUpPath
->pPoints
[j
].x
;
1843 pt
.y
= pUpPath
->pPoints
[j
].y
;
1844 PATH_AddEntry(pNewPath
, &pt
, (j
== 0 ? PT_MOVETO
: PT_LINETO
));
1846 for(j
= 0; j
< pDownPath
->numEntriesUsed
; j
++)
1849 pt
.x
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].x
;
1850 pt
.y
= pDownPath
->pPoints
[pDownPath
->numEntriesUsed
- j
- 1].y
;
1851 PATH_AddEntry(pNewPath
, &pt
, ( (j
== 0 && (pStrokes
[i
]->pFlags
[pStrokes
[i
]->numEntriesUsed
- 1] & PT_CLOSEFIGURE
)) ? PT_MOVETO
: PT_LINETO
));
1854 PATH_DestroyGdiPath(pStrokes
[i
]);
1855 ExFreePoolWithTag(pStrokes
[i
], TAG_PATH
);
1856 PATH_DestroyGdiPath(pUpPath
);
1857 ExFreePoolWithTag(pUpPath
, TAG_PATH
);
1858 PATH_DestroyGdiPath(pDownPath
);
1859 ExFreePoolWithTag(pDownPath
, TAG_PATH
);
1861 ExFreePoolWithTag(pStrokes
, TAG_PATH
);
1863 pNewPath
->state
= PATH_Closed
;
1864 if (!(ret
= PATH_AssignGdiPath(pPath
, pNewPath
)))
1865 DPRINT1("Assign path failed\n");
1866 PATH_DestroyGdiPath(pNewPath
);
1867 ExFreePoolWithTag(pNewPath
, TAG_PATH
);
1871 static inline INT
int_from_fixed(FIXED f
)
1873 return (f
.fract
>= 0x8000) ? (f
.value
+ 1) : f
.value
;
1876 /**********************************************************************
1879 * internally used by PATH_add_outline
1884 PATH_BezierTo(PPATH pPath
, POINT
*lppt
, INT n
)
1890 PATH_AddEntry(pPath
, &lppt
[1], PT_LINETO
);
1894 PATH_AddEntry(pPath
, &lppt
[0], PT_BEZIERTO
);
1895 PATH_AddEntry(pPath
, &lppt
[1], PT_BEZIERTO
);
1896 PATH_AddEntry(pPath
, &lppt
[2], PT_BEZIERTO
);
1910 pt
[2].x
= (lppt
[i
+2].x
+ lppt
[i
+1].x
) / 2;
1911 pt
[2].y
= (lppt
[i
+2].y
+ lppt
[i
+1].y
) / 2;
1912 PATH_BezierTo(pPath
, pt
, 3);
1920 PATH_BezierTo(pPath
, pt
, 3);
1927 PATH_add_outline(PDC dc
, INT x
, INT y
, TTPOLYGONHEADER
*header
, DWORD size
)
1930 TTPOLYGONHEADER
*start
;
1935 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
1940 while ((char *)header
< (char *)start
+ size
)
1944 if (header
->dwType
!= TT_POLYGON_TYPE
)
1946 DPRINT1("Unknown header type %d\n", header
->dwType
);
1950 pt
.x
= x
+ int_from_fixed(header
->pfxStart
.x
);
1951 pt
.y
= y
- int_from_fixed(header
->pfxStart
.y
);
1952 IntLPtoDP(dc
, &pt
, 1);
1953 PATH_AddEntry(pPath
, &pt
, PT_MOVETO
);
1955 curve
= (TTPOLYCURVE
*)(header
+ 1);
1957 while ((char *)curve
< (char *)header
+ header
->cb
)
1959 /*DPRINT1("curve->wType %d\n", curve->wType);*/
1961 switch(curve
->wType
)
1967 for (i
= 0; i
< curve
->cpfx
; i
++)
1969 pt
.x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1970 pt
.y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1971 IntLPtoDP(dc
, &pt
, 1);
1972 PATH_AddEntry(pPath
, &pt
, PT_LINETO
);
1977 case TT_PRIM_QSPLINE
:
1978 case TT_PRIM_CSPLINE
:
1982 POINT
*pts
= ExAllocatePoolWithTag(PagedPool
, (curve
->cpfx
+ 1) * sizeof(POINT
), TAG_PATH
);
1984 if (!pts
) return FALSE
;
1986 ptfx
= *(POINTFX
*)((char *)curve
- sizeof(POINTFX
));
1988 pts
[0].x
= x
+ int_from_fixed(ptfx
.x
);
1989 pts
[0].y
= y
- int_from_fixed(ptfx
.y
);
1990 IntLPtoDP(dc
, &pts
[0], 1);
1992 for (i
= 0; i
< curve
->cpfx
; i
++)
1994 pts
[i
+ 1].x
= x
+ int_from_fixed(curve
->apfx
[i
].x
);
1995 pts
[i
+ 1].y
= y
- int_from_fixed(curve
->apfx
[i
].y
);
1996 IntLPtoDP(dc
, &pts
[i
+ 1], 1);
1999 PATH_BezierTo(pPath
, pts
, curve
->cpfx
+ 1);
2001 ExFreePoolWithTag(pts
, TAG_PATH
);
2006 DPRINT1("Unknown curve type %04x\n", curve
->wType
);
2010 curve
= (TTPOLYCURVE
*)&curve
->apfx
[curve
->cpfx
];
2012 header
= (TTPOLYGONHEADER
*)((char *)header
+ header
->cb
);
2015 IntGdiCloseFigure( pPath
);
2016 PATH_UnlockPath( pPath
);
2020 /**********************************************************************
2025 PATH_ExtTextOut(PDC dc
, INT x
, INT y
, UINT flags
, const RECTL
*lprc
,
2026 LPCWSTR str
, UINT count
, const INT
*dx
)
2029 double cosEsc
, sinEsc
;
2034 INT offset
= 0, xoff
= 0, yoff
= 0;
2036 if (!count
) return TRUE
;
2038 pdcattr
= dc
->pdcattr
;
2040 TextObj
= RealizeFontInit( pdcattr
->hlfntNew
);
2041 if ( !TextObj
) return FALSE
;
2043 FontGetObject( TextObj
, sizeof(lf
), &lf
);
2045 if (lf
.lfEscapement
!= 0)
2047 cosEsc
= cos(lf
.lfEscapement
* M_PI
/ 1800);
2048 sinEsc
= sin(lf
.lfEscapement
* M_PI
/ 1800);
2055 org
= dc
->ptlDCOrig
;
2057 for (idx
= 0; idx
< count
; idx
++)
2063 dwSize
= ftGdiGetGlyphOutline( dc
,
2065 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2071 if (!dwSize
) return FALSE
;
2073 outline
= ExAllocatePoolWithTag(PagedPool
, dwSize
, TAG_PATH
);
2074 if (!outline
) return FALSE
;
2076 ftGdiGetGlyphOutline( dc
,
2078 GGO_GLYPH_INDEX
| GGO_NATIVE
,
2085 PATH_add_outline(dc
, org
.x
+ x
+ xoff
, org
.x
+ y
+ yoff
, outline
, dwSize
);
2087 ExFreePoolWithTag(outline
, TAG_PATH
);
2092 xoff
= offset
* cosEsc
;
2093 yoff
= offset
* -sinEsc
;
2097 xoff
+= gm
.gmCellIncX
;
2098 yoff
+= gm
.gmCellIncY
;
2105 /***********************************************************************
2106 * Exported functions
2111 NtGdiAbortPath(HDC hDC
)
2114 PDC dc
= DC_LockDc ( hDC
);
2117 EngSetLastError(ERROR_INVALID_HANDLE
);
2121 pPath
= PATH_LockPath(dc
->dclevel
.hPath
);
2127 PATH_EmptyPath(pPath
);
2129 PATH_UnlockPath(pPath
);
2136 NtGdiBeginPath( HDC hDC
)
2141 dc
= DC_LockDc ( hDC
);
2144 EngSetLastError(ERROR_INVALID_HANDLE
);
2148 /* If path is already open, do nothing. Check if not Save DC state */
2149 if ((dc
->dclevel
.flPath
& DCPATH_ACTIVE
) && !(dc
->dclevel
.flPath
& DCPATH_SAVE
))
2155 if ( dc
->dclevel
.hPath
)
2157 DPRINT1("BeginPath 1 0x%x\n", dc
->dclevel
.hPath
);
2158 if ( !(dc
->dclevel
.flPath
& DCPATH_SAVE
) )
2159 { // Remove previous handle.
2160 if (!PATH_Delete(dc
->dclevel
.hPath
))
2167 { // Clear flags and Handle.
2168 dc
->dclevel
.flPath
&= ~(DCPATH_SAVE
|DCPATH_ACTIVE
);
2169 dc
->dclevel
.hPath
= NULL
;
2172 pPath
= PATH_AllocPathWithHandle();
2175 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2178 dc
->dclevel
.flPath
|= DCPATH_ACTIVE
; // Set active ASAP!
2180 dc
->dclevel
.hPath
= pPath
->BaseObject
.hHmgr
;
2182 DPRINT1("BeginPath 2 h 0x%x p 0x%x\n", dc
->dclevel
.hPath
, pPath
);
2183 // Path handles are shared. Also due to recursion with in the same thread.
2184 GDIOBJ_UnlockObjByPtr((POBJ
)pPath
); // Unlock
2185 pPath
= PATH_LockPath(dc
->dclevel
.hPath
); // Share Lock.
2187 /* Make sure that path is empty */
2188 PATH_EmptyPath( pPath
);
2190 /* Initialize variables for new path */
2191 pPath
->newStroke
= TRUE
;
2192 pPath
->state
= PATH_Open
;
2194 PATH_UnlockPath(pPath
);
2201 NtGdiCloseFigure(HDC hDC
)
2203 BOOL Ret
= FALSE
; // default to failure
2207 DPRINT("Enter %s\n", __FUNCTION__
);
2209 pDc
= DC_LockDc(hDC
);
2212 EngSetLastError(ERROR_INVALID_PARAMETER
);
2215 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2222 if (pPath
->state
==PATH_Open
)
2224 IntGdiCloseFigure(pPath
);
2229 // FIXME: check if lasterror is set correctly
2230 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2233 PATH_UnlockPath( pPath
);
2240 NtGdiEndPath(HDC hDC
)
2244 PDC dc
= DC_LockDc ( hDC
);
2248 EngSetLastError(ERROR_INVALID_HANDLE
);
2252 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2258 /* Check that path is currently being constructed */
2259 if ( (pPath
->state
!= PATH_Open
) || !(dc
->dclevel
.flPath
& DCPATH_ACTIVE
) )
2261 DPRINT1("EndPath ERROR! 0x%x\n", dc
->dclevel
.hPath
);
2262 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2265 /* Set flag to indicate that path is finished */
2268 DPRINT1("EndPath 0x%x\n", dc
->dclevel
.hPath
);
2269 pPath
->state
= PATH_Closed
;
2270 dc
->dclevel
.flPath
&= ~DCPATH_ACTIVE
;
2272 PATH_UnlockPath( pPath
);
2279 NtGdiFillPath(HDC hDC
)
2284 PDC dc
= DC_LockDc ( hDC
);
2288 EngSetLastError(ERROR_INVALID_PARAMETER
);
2291 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2298 DC_vPrepareDCsForBlit(dc
, dc
->rosdc
.CombinedClip
->rclBounds
,
2299 NULL
, dc
->rosdc
.CombinedClip
->rclBounds
);
2301 pdcattr
= dc
->pdcattr
;
2303 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2304 DC_vUpdateLineBrush(dc
);
2306 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
2307 DC_vUpdateFillBrush(dc
);
2309 ret
= PATH_FillPath( dc
, pPath
);
2312 /* FIXME: Should the path be emptied even if conversion
2314 PATH_EmptyPath( pPath
);
2317 PATH_UnlockPath( pPath
);
2318 DC_vFinishBlit(dc
, NULL
);
2325 NtGdiFlattenPath(HDC hDC
)
2331 DPRINT("Enter %s\n", __FUNCTION__
);
2333 pDc
= DC_LockDc(hDC
);
2336 EngSetLastError(ERROR_INVALID_HANDLE
);
2340 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2343 DC_UnlockDc ( pDc
);
2346 if (pPath
->state
== PATH_Open
)
2347 Ret
= PATH_FlattenPath(pPath
);
2349 PATH_UnlockPath( pPath
);
2363 NTSTATUS Status
= STATUS_SUCCESS
;
2365 if (!(pDc
= DC_LockDc(hdc
)))
2367 EngSetLastError(ERROR_INVALID_PARAMETER
);
2371 worker
.f
= pDc
->dclevel
.laPath
.eMiterLimit
;
2377 ProbeForWrite(pdwOut
,
2382 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2384 Status
= _SEH2_GetExceptionCode();
2387 if (!NT_SUCCESS(Status
))
2389 SetLastNtError(Status
);
2411 DC
*dc
= DC_LockDc(hDC
);
2414 DPRINT1("Can't lock dc!\n");
2415 EngSetLastError(ERROR_INVALID_PARAMETER
);
2419 pPath
= PATH_LockPath( dc
->dclevel
.hPath
);
2426 if (pPath
->state
!= PATH_Closed
)
2428 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2434 ret
= pPath
->numEntriesUsed
;
2436 else if(nSize
<pPath
->numEntriesUsed
)
2438 EngSetLastError(ERROR_INVALID_PARAMETER
);
2445 memcpy(Points
, pPath
->pPoints
, sizeof(POINT
)*pPath
->numEntriesUsed
);
2446 memcpy(Types
, pPath
->pFlags
, sizeof(BYTE
)*pPath
->numEntriesUsed
);
2448 /* Convert the points to logical coordinates */
2449 IntDPtoLP(dc
, Points
, pPath
->numEntriesUsed
);
2451 ret
= pPath
->numEntriesUsed
;
2453 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2455 SetLastNtError(_SEH2_GetExceptionCode());
2461 PATH_UnlockPath( pPath
);
2468 NtGdiPathToRegion(HDC hDC
)
2475 DPRINT("Enter %s\n", __FUNCTION__
);
2477 pDc
= DC_LockDc(hDC
);
2480 EngSetLastError(ERROR_INVALID_PARAMETER
);
2484 pdcattr
= pDc
->pdcattr
;
2486 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2489 DC_UnlockDc ( pDc
);
2493 if (pPath
->state
!=PATH_Closed
)
2495 //FIXME: check that setlasterror is being called correctly
2496 EngSetLastError(ERROR_CAN_NOT_COMPLETE
);
2500 /* FIXME: Should we empty the path even if conversion failed? */
2501 if(PATH_PathToRegion(pPath
, pdcattr
->jFillMode
, &hrgnRval
))
2502 PATH_EmptyPath(pPath
);
2505 PATH_UnlockPath( pPath
);
2515 IN OUT OPTIONAL PDWORD pdwOut
)
2518 gxf_long worker
, worker1
;
2519 NTSTATUS Status
= STATUS_SUCCESS
;
2521 if (!(pDc
= DC_LockDc(hdc
)))
2523 EngSetLastError(ERROR_INVALID_PARAMETER
);
2528 worker1
.f
= pDc
->dclevel
.laPath
.eMiterLimit
;
2529 pDc
->dclevel
.laPath
.eMiterLimit
= worker
.f
;
2535 ProbeForWrite(pdwOut
,
2538 *pdwOut
= worker1
.l
;
2540 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2542 Status
= _SEH2_GetExceptionCode();
2545 if (!NT_SUCCESS(Status
))
2547 SetLastNtError(Status
);
2559 NtGdiStrokeAndFillPath(HDC hDC
)
2566 DPRINT1("Enter %s\n", __FUNCTION__
);
2568 if (!(pDc
= DC_LockDc(hDC
)))
2570 EngSetLastError(ERROR_INVALID_PARAMETER
);
2573 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2576 DC_UnlockDc ( pDc
);
2580 DC_vPrepareDCsForBlit(pDc
, pDc
->rosdc
.CombinedClip
->rclBounds
,
2581 NULL
, pDc
->rosdc
.CombinedClip
->rclBounds
);
2583 pdcattr
= pDc
->pdcattr
;
2585 if (pdcattr
->ulDirty_
& (DIRTY_FILL
| DC_BRUSH_DIRTY
))
2586 DC_vUpdateFillBrush(pDc
);
2588 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2589 DC_vUpdateLineBrush(pDc
);
2591 bRet
= PATH_FillPath(pDc
, pPath
);
2592 if (bRet
) bRet
= PATH_StrokePath(pDc
, pPath
);
2593 if (bRet
) PATH_EmptyPath(pPath
);
2595 PATH_UnlockPath( pPath
);
2596 DC_vFinishBlit(pDc
, NULL
);
2603 NtGdiStrokePath(HDC hDC
)
2610 DPRINT("Enter %s\n", __FUNCTION__
);
2612 if (!(pDc
= DC_LockDc(hDC
)))
2614 EngSetLastError(ERROR_INVALID_PARAMETER
);
2617 pPath
= PATH_LockPath( pDc
->dclevel
.hPath
);
2620 DC_UnlockDc ( pDc
);
2624 DC_vPrepareDCsForBlit(pDc
, pDc
->rosdc
.CombinedClip
->rclBounds
,
2625 NULL
, pDc
->rosdc
.CombinedClip
->rclBounds
);
2627 pdcattr
= pDc
->pdcattr
;
2629 if (pdcattr
->ulDirty_
& (DIRTY_LINE
| DC_PEN_DIRTY
))
2630 DC_vUpdateLineBrush(pDc
);
2632 bRet
= PATH_StrokePath(pDc
, pPath
);
2634 DC_vFinishBlit(pDc
, NULL
);
2635 PATH_EmptyPath(pPath
);
2637 PATH_UnlockPath( pPath
);
2644 NtGdiWidenPath(HDC hDC
)
2647 PDC pdc
= DC_LockDc ( hDC
);
2650 EngSetLastError(ERROR_INVALID_PARAMETER
);
2653 Ret
= PATH_WidenPath(pdc
);
2654 DC_UnlockDc ( pdc
);