path.c 74.3 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3
/*
 * Graphics paths (BeginPath, EndPath etc.)
 *
Alexandre Julliard's avatar
Alexandre Julliard committed
4
 * Copyright 1997, 1998 Martin Boehme
5
 *                 1999 Huw D M Davies
6
 * Copyright 2005 Dmitry Timoshkov
7
 * Copyright 2011 Alexandre Julliard
8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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
Alexandre Julliard's avatar
Alexandre Julliard committed
22 23
 */

24
#include "config.h"
25
#include "wine/port.h"
26

Alexandre Julliard's avatar
Alexandre Julliard committed
27
#include <assert.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
28
#include <math.h>
29
#include <stdarg.h>
30
#include <string.h>
31
#include <stdlib.h>
32 33 34
#if defined(HAVE_FLOAT_H)
#include <float.h>
#endif
Alexandre Julliard's avatar
Alexandre Julliard committed
35

36
#include "windef.h"
37 38
#include "winbase.h"
#include "wingdi.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
39 40
#include "winerror.h"

41
#include "gdi_private.h"
42
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
43

44
WINE_DEFAULT_DEBUG_CHANNEL(gdi);
45

Alexandre Julliard's avatar
Alexandre Julliard committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
/* Notes on the implementation
 *
 * The implementation is based on dynamically resizable arrays of points and
 * flags. I dithered for a bit before deciding on this implementation, and
 * I had even done a bit of work on a linked list version before switching
 * to arrays. It's a bit of a tradeoff. When you use linked lists, the
 * implementation of FlattenPath is easier, because you can rip the
 * PT_BEZIERTO entries out of the middle of the list and link the
 * corresponding PT_LINETO entries in. However, when you use arrays,
 * PathToRegion becomes easier, since you can essentially just pass your array
 * of points to CreatePolyPolygonRgn. Also, if I'd used linked lists, I would
 * have had the extra effort of creating a chunk-based allocation scheme
 * in order to use memory effectively. That's why I finally decided to use
 * arrays. Note by the way that the array based implementation has the same
 * linear time complexity that linked lists would have since the arrays grow
 * exponentially.
 *
 * The points are stored in the path in device coordinates. This is
 * consistent with the way Windows does things (for instance, see the Win32
 * SDK documentation for GetPath).
 *
 * The word "stroke" appears in several places (e.g. in the flag
 * GdiPath.newStroke). A stroke consists of a PT_MOVETO followed by one or
 * more PT_LINETOs or PT_BEZIERTOs, up to, but not including, the next
 * PT_MOVETO. Note that this is not the same as the definition of a figure;
 * a figure can contain several strokes.
 *
 * Martin Boehme
 */

#define NUM_ENTRIES_INITIAL 16  /* Initial size of points / flags arrays  */

78 79 80
/* A floating point version of the POINT structure */
typedef struct tagFLOAT_POINT
{
81
   double x, y;
82 83
} FLOAT_POINT;

84
struct gdi_path
85
{
86 87 88 89
    POINT       *points;
    BYTE        *flags;
    int          count;
    int          allocated;
90
    BOOL         newStroke;
91
};
Alexandre Julliard's avatar
Alexandre Julliard committed
92

93 94 95
struct path_physdev
{
    struct gdi_physdev dev;
96
    struct gdi_path   *path;
97 98 99 100 101 102 103
};

static inline struct path_physdev *get_path_physdev( PHYSDEV dev )
{
    return (struct path_physdev *)dev;
}

104
void free_gdi_path( struct gdi_path *path )
105
{
106 107
    HeapFree( GetProcessHeap(), 0, path->points );
    HeapFree( GetProcessHeap(), 0, path->flags );
108 109 110
    HeapFree( GetProcessHeap(), 0, path );
}

111
static struct gdi_path *alloc_gdi_path( int count )
112 113 114 115 116 117 118 119
{
    struct gdi_path *path = HeapAlloc( GetProcessHeap(), 0, sizeof(*path) );

    if (!path)
    {
        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
        return NULL;
    }
120 121 122
    count = max( NUM_ENTRIES_INITIAL, count );
    path->points = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*path->points) );
    path->flags = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*path->flags) );
123
    if (!path->points || !path->flags)
124 125 126 127 128
    {
        free_gdi_path( path );
        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
        return NULL;
    }
129
    path->count = 0;
130
    path->allocated = count;
131 132 133
    path->newStroke = TRUE;
    return path;
}
134

135 136 137 138 139 140 141 142 143
static struct gdi_path *copy_gdi_path( const struct gdi_path *src_path )
{
    struct gdi_path *path = HeapAlloc( GetProcessHeap(), 0, sizeof(*path) );

    if (!path)
    {
        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
        return NULL;
    }
144
    path->count = path->allocated = src_path->count;
145
    path->newStroke = src_path->newStroke;
146 147 148
    path->points = HeapAlloc( GetProcessHeap(), 0, path->count * sizeof(*path->points) );
    path->flags = HeapAlloc( GetProcessHeap(), 0, path->count * sizeof(*path->flags) );
    if (!path->points || !path->flags)
149 150 151 152 153
    {
        free_gdi_path( path );
        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
        return NULL;
    }
154 155
    memcpy( path->points, src_path->points, path->count * sizeof(*path->points) );
    memcpy( path->flags, src_path->flags, path->count * sizeof(*path->flags) );
156 157 158
    return path;
}

159 160 161
/* Performs a world-to-viewport transformation on the specified point (which
 * is in floating point format).
 */
162
static inline void INTERNAL_LPTODP_FLOAT( HDC hdc, FLOAT_POINT *point, int count )
163
{
164
    DC *dc = get_dc_ptr( hdc );
165
    double x, y;
166

167 168 169 170 171 172 173 174 175
    while (count--)
    {
        x = point->x;
        y = point->y;
        point->x = x * dc->xformWorld2Vport.eM11 + y * dc->xformWorld2Vport.eM21 + dc->xformWorld2Vport.eDx;
        point->y = x * dc->xformWorld2Vport.eM12 + y * dc->xformWorld2Vport.eM22 + dc->xformWorld2Vport.eDy;
        point++;
    }
    release_dc_ptr( dc );
176 177 178 179 180 181 182 183 184 185 186 187 188 189
}

static inline INT int_from_fixed(FIXED f)
{
    return (f.fract >= 0x8000) ? (f.value + 1) : f.value;
}


/* PATH_ReserveEntries
 *
 * Ensures that at least "numEntries" entries (for points and flags) have
 * been allocated; allocates larger arrays and copies the existing entries
 * to those arrays, if necessary. Returns TRUE if successful, else FALSE.
 */
190
static BOOL PATH_ReserveEntries(struct gdi_path *pPath, INT count)
191 192 193 194
{
    POINT *pPointsNew;
    BYTE    *pFlagsNew;

195
    assert(count>=0);
196 197

    /* Do we have to allocate more memory? */
198
    if(count > pPath->allocated)
199 200 201 202
    {
        /* Find number of entries to allocate. We let the size of the array
         * grow exponentially, since that will guarantee linear time
         * complexity. */
203
        count = max( pPath->allocated * 2, count );
204

205
        pPointsNew = HeapReAlloc( GetProcessHeap(), 0, pPath->points, count * sizeof(POINT) );
206
        if (!pPointsNew) return FALSE;
207
        pPath->points = pPointsNew;
208

209
        pFlagsNew = HeapReAlloc( GetProcessHeap(), 0, pPath->flags, count * sizeof(BYTE) );
210
        if (!pFlagsNew) return FALSE;
211
        pPath->flags = pFlagsNew;
212

213
        pPath->allocated = count;
214
    }
215 216 217 218 219 220 221 222 223
    return TRUE;
}

/* PATH_AddEntry
 *
 * Adds an entry to the path. For "flags", pass either PT_MOVETO, PT_LINETO
 * or PT_BEZIERTO, optionally ORed with PT_CLOSEFIGURE. Returns TRUE if
 * successful, FALSE otherwise (e.g. if not enough memory was available).
 */
224
static BOOL PATH_AddEntry(struct gdi_path *pPath, const POINT *pPoint, BYTE flags)
225 226 227 228 229 230 231
{
    /* FIXME: If newStroke is true, perhaps we want to check that we're
     * getting a PT_MOVETO
     */
    TRACE("(%d,%d) - %d\n", pPoint->x, pPoint->y, flags);

    /* Reserve enough memory for an extra path entry */
232
    if(!PATH_ReserveEntries(pPath, pPath->count+1))
233 234 235
        return FALSE;

    /* Store information in path entry */
236 237
    pPath->points[pPath->count]=*pPoint;
    pPath->flags[pPath->count]=flags;
238

239
    pPath->count++;
240 241 242 243

    return TRUE;
}

244 245 246 247 248
/* add a number of points, converting them to device coords */
/* return a pointer to the first type byte so it can be fixed up if necessary */
static BYTE *add_log_points( struct path_physdev *physdev, const POINT *points, DWORD count, BYTE type )
{
    BYTE *ret;
249
    struct gdi_path *path = physdev->path;
250

251
    if (!PATH_ReserveEntries( path, path->count + count )) return NULL;
252

253 254 255
    ret = &path->flags[path->count];
    memcpy( &path->points[path->count], points, count * sizeof(*points) );
    LPtoDP( physdev->dev.hdc, &path->points[path->count], count );
256
    memset( ret, type, count );
257
    path->count += count;
258 259 260
    return ret;
}

261 262 263 264
/* start a new path stroke if necessary */
static BOOL start_new_stroke( struct path_physdev *physdev )
{
    POINT pos;
265
    struct gdi_path *path = physdev->path;
266

267 268
    if (!path->newStroke && path->count &&
        !(path->flags[path->count - 1] & PT_CLOSEFIGURE))
269 270 271
        return TRUE;

    path->newStroke = FALSE;
272
    GetCurrentPositionEx( physdev->dev.hdc, &pos );
273
    return add_log_points( physdev, &pos, 1, PT_MOVETO ) != NULL;
274 275
}

276 277
/* PATH_CheckCorners
 *
278
 * Helper function for RoundRect() and Rectangle()
279
 */
280
static void PATH_CheckCorners( HDC hdc, POINT corners[], INT x1, INT y1, INT x2, INT y2 )
281 282 283 284 285 286 287 288
{
    INT temp;

    /* Convert points to device coordinates */
    corners[0].x=x1;
    corners[0].y=y1;
    corners[1].x=x2;
    corners[1].y=y2;
289
    LPtoDP( hdc, corners, 2 );
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305

    /* Make sure first corner is top left and second corner is bottom right */
    if(corners[0].x>corners[1].x)
    {
        temp=corners[0].x;
        corners[0].x=corners[1].x;
        corners[1].x=temp;
    }
    if(corners[0].y>corners[1].y)
    {
        temp=corners[0].y;
        corners[0].y=corners[1].y;
        corners[1].y=temp;
    }

    /* In GM_COMPATIBLE, don't include bottom and right edges */
306
    if (GetGraphicsMode( hdc ) == GM_COMPATIBLE)
307 308 309 310 311 312 313 314
    {
        corners[1].x--;
        corners[1].y--;
    }
}

/* PATH_AddFlatBezier
 */
315
static BOOL PATH_AddFlatBezier(struct gdi_path *pPath, POINT *pt, BOOL closed)
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
{
    POINT *pts;
    INT no, i;

    pts = GDI_Bezier( pt, 4, &no );
    if(!pts) return FALSE;

    for(i = 1; i < no; i++)
        PATH_AddEntry(pPath, &pts[i], (i == no-1 && closed) ? PT_LINETO | PT_CLOSEFIGURE : PT_LINETO);
    HeapFree( GetProcessHeap(), 0, pts );
    return TRUE;
}

/* PATH_FlattenPath
 *
 * Replaces Beziers with line segments
 *
 */
334
static struct gdi_path *PATH_FlattenPath(const struct gdi_path *pPath)
335
{
336
    struct gdi_path *new_path;
337 338
    INT srcpt;

339
    if (!(new_path = alloc_gdi_path( pPath->count ))) return NULL;
340

341 342
    for(srcpt = 0; srcpt < pPath->count; srcpt++) {
        switch(pPath->flags[srcpt] & ~PT_CLOSEFIGURE) {
343 344
	case PT_MOVETO:
	case PT_LINETO:
345
	    if (!PATH_AddEntry(new_path, &pPath->points[srcpt], pPath->flags[srcpt]))
346 347 348 349
            {
                free_gdi_path( new_path );
                return NULL;
            }
350 351
	    break;
	case PT_BEZIERTO:
352 353
            if (!PATH_AddFlatBezier(new_path, &pPath->points[srcpt-1],
                                    pPath->flags[srcpt+2] & PT_CLOSEFIGURE))
354 355 356 357
            {
                free_gdi_path( new_path );
                return NULL;
            }
358 359 360 361
	    srcpt += 2;
	    break;
	}
    }
362
    return new_path;
363 364 365 366 367
}

/* PATH_PathToRegion
 *
 * Creates a region from the specified path using the specified polygon
368
 * filling mode. The path is left unchanged.
369
 */
370
static HRGN PATH_PathToRegion(const struct gdi_path *pPath, INT nPolyFillMode)
371
{
372
    struct gdi_path *rgn_path;
373 374 375 376
    int    numStrokes, iStroke, i;
    INT  *pNumPointsInStroke;
    HRGN hrgn;

377
    if (!(rgn_path = PATH_FlattenPath( pPath ))) return 0;
378 379 380 381 382 383

    /* FIXME: What happens when number of points is zero? */

    /* First pass: Find out how many strokes there are in the path */
    /* FIXME: We could eliminate this with some bookkeeping in GdiPath */
    numStrokes=0;
384 385
    for(i=0; i<rgn_path->count; i++)
        if((rgn_path->flags[i] & ~PT_CLOSEFIGURE) == PT_MOVETO)
386 387 388 389 390 391
            numStrokes++;

    /* Allocate memory for number-of-points-in-stroke array */
    pNumPointsInStroke=HeapAlloc( GetProcessHeap(), 0, sizeof(int) * numStrokes );
    if(!pNumPointsInStroke)
    {
392
        free_gdi_path( rgn_path );
393
        SetLastError(ERROR_NOT_ENOUGH_MEMORY);
394
        return 0;
395 396 397 398
    }

    /* Second pass: remember number of points in each polygon */
    iStroke=-1;  /* Will get incremented to 0 at beginning of first stroke */
399
    for(i=0; i<rgn_path->count; i++)
400 401
    {
        /* Is this the beginning of a new stroke? */
402
        if((rgn_path->flags[i] & ~PT_CLOSEFIGURE) == PT_MOVETO)
403 404 405 406 407 408 409 410 411
        {
            iStroke++;
            pNumPointsInStroke[iStroke]=0;
        }

        pNumPointsInStroke[iStroke]++;
    }

    /* Create a region from the strokes */
412
    hrgn=CreatePolyPolygonRgn(rgn_path->points, pNumPointsInStroke,
413 414 415
                              numStrokes, nPolyFillMode);

    HeapFree( GetProcessHeap(), 0, pNumPointsInStroke );
416
    free_gdi_path( rgn_path );
417
    return hrgn;
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
}

/* PATH_ScaleNormalizedPoint
 *
 * Scales a normalized point (x, y) with respect to the box whose corners are
 * passed in "corners". The point is stored in "*pPoint". The normalized
 * coordinates (-1.0, -1.0) correspond to corners[0], the coordinates
 * (1.0, 1.0) correspond to corners[1].
 */
static void PATH_ScaleNormalizedPoint(FLOAT_POINT corners[], double x,
   double y, POINT *pPoint)
{
    pPoint->x=GDI_ROUND( (double)corners[0].x + (double)(corners[1].x-corners[0].x)*0.5*(x+1.0) );
    pPoint->y=GDI_ROUND( (double)corners[0].y + (double)(corners[1].y-corners[0].y)*0.5*(y+1.0) );
}

/* PATH_NormalizePoint
 *
 * Normalizes a point with respect to the box whose corners are passed in
 * "corners". The normalized coordinates are stored in "*pX" and "*pY".
 */
static void PATH_NormalizePoint(FLOAT_POINT corners[],
   const FLOAT_POINT *pPoint,
   double *pX, double *pY)
{
    *pX=(double)(pPoint->x-corners[0].x)/(double)(corners[1].x-corners[0].x) * 2.0 - 1.0;
    *pY=(double)(pPoint->y-corners[0].y)/(double)(corners[1].y-corners[0].y) * 2.0 - 1.0;
}

/* PATH_DoArcPart
 *
 * Creates a Bezier spline that corresponds to part of an arc and appends the
 * corresponding points to the path. The start and end angles are passed in
 * "angleStart" and "angleEnd"; these angles should span a quarter circle
 * at most. If "startEntryType" is non-zero, an entry of that type for the first
 * control point is added to the path; otherwise, it is assumed that the current
 * position is equal to the first control point.
 */
456
static BOOL PATH_DoArcPart(struct gdi_path *pPath, FLOAT_POINT corners[],
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
   double angleStart, double angleEnd, BYTE startEntryType)
{
    double  halfAngle, a;
    double  xNorm[4], yNorm[4];
    POINT point;
    int     i;

    assert(fabs(angleEnd-angleStart)<=M_PI_2);

    /* FIXME: Is there an easier way of computing this? */

    /* Compute control points */
    halfAngle=(angleEnd-angleStart)/2.0;
    if(fabs(halfAngle)>1e-8)
    {
        a=4.0/3.0*(1-cos(halfAngle))/sin(halfAngle);
        xNorm[0]=cos(angleStart);
        yNorm[0]=sin(angleStart);
        xNorm[1]=xNorm[0] - a*yNorm[0];
        yNorm[1]=yNorm[0] + a*xNorm[0];
        xNorm[3]=cos(angleEnd);
        yNorm[3]=sin(angleEnd);
        xNorm[2]=xNorm[3] + a*yNorm[3];
        yNorm[2]=yNorm[3] - a*xNorm[3];
    }
    else
        for(i=0; i<4; i++)
        {
            xNorm[i]=cos(angleStart);
            yNorm[i]=sin(angleStart);
        }

    /* Add starting point to path if desired */
    if(startEntryType)
    {
        PATH_ScaleNormalizedPoint(corners, xNorm[0], yNorm[0], &point);
        if(!PATH_AddEntry(pPath, &point, startEntryType))
            return FALSE;
    }

    /* Add remaining control points */
    for(i=1; i<4; i++)
    {
        PATH_ScaleNormalizedPoint(corners, xNorm[i], yNorm[i], &point);
        if(!PATH_AddEntry(pPath, &point, PT_BEZIERTO))
            return FALSE;
    }

    return TRUE;
506
}
Alexandre Julliard's avatar
Alexandre Julliard committed
507

508

Alexandre Julliard's avatar
Alexandre Julliard committed
509
/***********************************************************************
510
 *           BeginPath    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
511
 */
512
BOOL WINAPI BeginPath(HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
513
{
514
    BOOL ret = FALSE;
515
    DC *dc = get_dc_ptr( hdc );
516

517
    if (dc)
518
    {
519 520 521
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pBeginPath );
        ret = physdev->funcs->pBeginPath( physdev );
        release_dc_ptr( dc );
522 523
    }
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
524 525 526 527
}


/***********************************************************************
528
 *           EndPath    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
529
 */
530
BOOL WINAPI EndPath(HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
531
{
532
    BOOL ret = FALSE;
533
    DC *dc = get_dc_ptr( hdc );
534

535
    if (dc)
536
    {
537 538 539
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pEndPath );
        ret = physdev->funcs->pEndPath( physdev );
        release_dc_ptr( dc );
540 541
    }
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
542 543 544
}


Alexandre Julliard's avatar
Alexandre Julliard committed
545
/******************************************************************************
546
 * AbortPath [GDI32.@]
Alexandre Julliard's avatar
Alexandre Julliard committed
547 548 549 550 551 552 553 554
 * Closes and discards paths from device context
 *
 * NOTES
 *    Check that SetLastError is being called correctly
 *
 * PARAMS
 *    hdc [I] Handle to device context
 *
555 556 557
 * RETURNS
 *    Success: TRUE
 *    Failure: FALSE
Alexandre Julliard's avatar
Alexandre Julliard committed
558
 */
559
BOOL WINAPI AbortPath( HDC hdc )
Alexandre Julliard's avatar
Alexandre Julliard committed
560
{
561
    BOOL ret = FALSE;
562
    DC *dc = get_dc_ptr( hdc );
563

564 565 566 567 568 569
    if (dc)
    {
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pAbortPath );
        ret = physdev->funcs->pAbortPath( physdev );
        release_dc_ptr( dc );
    }
570
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
571 572 573 574
}


/***********************************************************************
575
 *           CloseFigure    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
576
 *
577
 * FIXME: Check that SetLastError is being called correctly
Alexandre Julliard's avatar
Alexandre Julliard committed
578
 */
579
BOOL WINAPI CloseFigure(HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
580
{
581
    BOOL ret = FALSE;
582
    DC *dc = get_dc_ptr( hdc );
583

584
    if (dc)
585
    {
586 587 588
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pCloseFigure );
        ret = physdev->funcs->pCloseFigure( physdev );
        release_dc_ptr( dc );
589 590
    }
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
591 592 593 594
}


/***********************************************************************
595
 *           GetPath    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
596
 */
597
INT WINAPI GetPath(HDC hdc, LPPOINT pPoints, LPBYTE pTypes, INT nSize)
Alexandre Julliard's avatar
Alexandre Julliard committed
598
{
599
   INT ret = -1;
600
   DC *dc = get_dc_ptr( hdc );
601

602
   if(!dc) return -1;
603

604
   if (!dc->path)
Alexandre Julliard's avatar
Alexandre Julliard committed
605 606
   {
      SetLastError(ERROR_CAN_NOT_COMPLETE);
607
      goto done;
Alexandre Julliard's avatar
Alexandre Julliard committed
608
   }
609

Alexandre Julliard's avatar
Alexandre Julliard committed
610
   if(nSize==0)
611 612
      ret = dc->path->count;
   else if(nSize<dc->path->count)
Alexandre Julliard's avatar
Alexandre Julliard committed
613 614
   {
      SetLastError(ERROR_INVALID_PARAMETER);
615
      goto done;
Alexandre Julliard's avatar
Alexandre Julliard committed
616 617 618
   }
   else
   {
619 620
      memcpy(pPoints, dc->path->points, sizeof(POINT)*dc->path->count);
      memcpy(pTypes, dc->path->flags, sizeof(BYTE)*dc->path->count);
Alexandre Julliard's avatar
Alexandre Julliard committed
621 622

      /* Convert the points to logical coordinates */
623
      if(!DPtoLP(hdc, pPoints, dc->path->count))
Alexandre Julliard's avatar
Alexandre Julliard committed
624 625 626
      {
	 /* FIXME: Is this the correct value? */
         SetLastError(ERROR_CAN_NOT_COMPLETE);
627
	goto done;
Alexandre Julliard's avatar
Alexandre Julliard committed
628
      }
629
     else ret = dc->path->count;
Alexandre Julliard's avatar
Alexandre Julliard committed
630
   }
631
 done:
632
   release_dc_ptr( dc );
633
   return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
634 635 636 637
}


/***********************************************************************
638
 *           PathToRegion    (GDI32.@)
Alexandre Julliard's avatar
Alexandre Julliard committed
639
 *
640 641
 * FIXME
 *   Check that SetLastError is being called correctly
Alexandre Julliard's avatar
Alexandre Julliard committed
642 643
 *
 * The documentation does not state this explicitly, but a test under Windows
Alexandre Julliard's avatar
Alexandre Julliard committed
644 645
 * shows that the region which is returned should be in device coordinates.
 */
646
HRGN WINAPI PathToRegion(HDC hdc)
Alexandre Julliard's avatar
Alexandre Julliard committed
647
{
648
   HRGN  hrgnRval = 0;
649
   DC *dc = get_dc_ptr( hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
650 651

   /* Get pointer to path */
652
   if(!dc) return 0;
653

654
   if (!dc->path) SetLastError(ERROR_CAN_NOT_COMPLETE);
655
   else
Alexandre Julliard's avatar
Alexandre Julliard committed
656
   {
657 658 659 660 661 662
       if ((hrgnRval = PATH_PathToRegion(dc->path, GetPolyFillMode(hdc))))
       {
           /* FIXME: Should we empty the path even if conversion failed? */
           free_gdi_path( dc->path );
           dc->path = NULL;
       }
Alexandre Julliard's avatar
Alexandre Julliard committed
663
   }
664
   release_dc_ptr( dc );
Alexandre Julliard's avatar
Alexandre Julliard committed
665 666 667
   return hrgnRval;
}

668
static BOOL PATH_FillPath( HDC hdc, const struct gdi_path *pPath )
Alexandre Julliard's avatar
Alexandre Julliard committed
669
{
670 671 672
   INT   mapMode, graphicsMode;
   SIZE  ptViewportExt, ptWindowExt;
   POINT ptViewportOrg, ptWindowOrg;
673
   XFORM xform;
674
   HRGN  hrgn;
675

Alexandre Julliard's avatar
Alexandre Julliard committed
676
   /* Construct a region from the path and fill it */
677
   if ((hrgn = PATH_PathToRegion(pPath, GetPolyFillMode(hdc))))
Alexandre Julliard's avatar
Alexandre Julliard committed
678 679 680 681
   {
      /* Since PaintRgn interprets the region as being in logical coordinates
       * but the points we store for the path are already in device
       * coordinates, we have to set the mapping mode to MM_TEXT temporarily.
Alexandre Julliard's avatar
Alexandre Julliard committed
682 683 684
       * Using SaveDC to save information about the mapping mode / world
       * transform would be easier but would require more overhead, especially
       * now that SaveDC saves the current path.
Alexandre Julliard's avatar
Alexandre Julliard committed
685
       */
686

Alexandre Julliard's avatar
Alexandre Julliard committed
687
      /* Save the information about the old mapping mode */
688 689 690 691 692
      mapMode=GetMapMode(hdc);
      GetViewportExtEx(hdc, &ptViewportExt);
      GetViewportOrgEx(hdc, &ptViewportOrg);
      GetWindowExtEx(hdc, &ptWindowExt);
      GetWindowOrgEx(hdc, &ptWindowOrg);
693

Alexandre Julliard's avatar
Alexandre Julliard committed
694 695 696 697 698
      /* Save world transform
       * NB: The Windows documentation on world transforms would lead one to
       * believe that this has to be done only in GM_ADVANCED; however, my
       * tests show that resetting the graphics mode to GM_COMPATIBLE does
       * not reset the world transform.
Alexandre Julliard's avatar
Alexandre Julliard committed
699
       */
700
      GetWorldTransform(hdc, &xform);
701

Alexandre Julliard's avatar
Alexandre Julliard committed
702
      /* Set MM_TEXT */
703 704 705 706 707 708 709
      SetMapMode(hdc, MM_TEXT);
      SetViewportOrgEx(hdc, 0, 0, NULL);
      SetWindowOrgEx(hdc, 0, 0, NULL);
      graphicsMode=GetGraphicsMode(hdc);
      SetGraphicsMode(hdc, GM_ADVANCED);
      ModifyWorldTransform(hdc, &xform, MWT_IDENTITY);
      SetGraphicsMode(hdc, graphicsMode);
710

Alexandre Julliard's avatar
Alexandre Julliard committed
711
      /* Paint the region */
712
      PaintRgn(hdc, hrgn);
713
      DeleteObject(hrgn);
Alexandre Julliard's avatar
Alexandre Julliard committed
714
      /* Restore the old mapping mode */
715 716 717 718 719
      SetMapMode(hdc, mapMode);
      SetViewportExtEx(hdc, ptViewportExt.cx, ptViewportExt.cy, NULL);
      SetViewportOrgEx(hdc, ptViewportOrg.x, ptViewportOrg.y, NULL);
      SetWindowExtEx(hdc, ptWindowExt.cx, ptWindowExt.cy, NULL);
      SetWindowOrgEx(hdc, ptWindowOrg.x, ptWindowOrg.y, NULL);
Alexandre Julliard's avatar
Alexandre Julliard committed
720

Alexandre Julliard's avatar
Alexandre Julliard committed
721
      /* Go to GM_ADVANCED temporarily to restore the world transform */
722 723 724 725
      graphicsMode=GetGraphicsMode(hdc);
      SetGraphicsMode(hdc, GM_ADVANCED);
      SetWorldTransform(hdc, &xform);
      SetGraphicsMode(hdc, graphicsMode);
Alexandre Julliard's avatar
Alexandre Julliard committed
726 727
      return TRUE;
   }
728 729 730 731 732
   return FALSE;
}


/***********************************************************************
733
 *           FillPath    (GDI32.@)
734 735
 *
 * FIXME
736
 *    Check that SetLastError is being called correctly
737 738 739
 */
BOOL WINAPI FillPath(HDC hdc)
{
740
    BOOL ret = FALSE;
741
    DC *dc = get_dc_ptr( hdc );
742

743
    if (dc)
744
    {
745 746 747
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pFillPath );
        ret = physdev->funcs->pFillPath( physdev );
        release_dc_ptr( dc );
748
    }
749
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
750 751 752 753
}


/***********************************************************************
754
 *           SelectClipPath    (GDI32.@)
755 756
 * FIXME
 *  Check that SetLastError is being called correctly
Alexandre Julliard's avatar
Alexandre Julliard committed
757
 */
758
BOOL WINAPI SelectClipPath(HDC hdc, INT iMode)
Alexandre Julliard's avatar
Alexandre Julliard committed
759
{
760 761
    BOOL ret = FALSE;
    DC *dc = get_dc_ptr( hdc );
762

763 764 765 766 767 768 769
    if (dc)
    {
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pSelectClipPath );
        ret = physdev->funcs->pSelectClipPath( physdev, iMode );
        release_dc_ptr( dc );
    }
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
770 771 772
}


773 774 775 776 777 778 779 780 781 782
/***********************************************************************
 *           pathdrv_BeginPath
 */
static BOOL pathdrv_BeginPath( PHYSDEV dev )
{
    /* path already open, nothing to do */
    return TRUE;
}


Alexandre Julliard's avatar
Alexandre Julliard committed
783
/***********************************************************************
784 785 786 787
 *           pathdrv_AbortPath
 */
static BOOL pathdrv_AbortPath( PHYSDEV dev )
{
788
    struct path_physdev *physdev = get_path_physdev( dev );
789 790 791
    DC *dc = get_dc_ptr( dev->hdc );

    if (!dc) return FALSE;
792
    free_gdi_path( physdev->path );
793 794
    pop_dc_driver( dc, &path_driver );
    HeapFree( GetProcessHeap(), 0, physdev );
795 796 797 798 799 800 801 802 803 804
    release_dc_ptr( dc );
    return TRUE;
}


/***********************************************************************
 *           pathdrv_EndPath
 */
static BOOL pathdrv_EndPath( PHYSDEV dev )
{
805
    struct path_physdev *physdev = get_path_physdev( dev );
806 807 808
    DC *dc = get_dc_ptr( dev->hdc );

    if (!dc) return FALSE;
809
    dc->path = physdev->path;
810 811
    pop_dc_driver( dc, &path_driver );
    HeapFree( GetProcessHeap(), 0, physdev );
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835
    release_dc_ptr( dc );
    return TRUE;
}


/***********************************************************************
 *           pathdrv_CreateDC
 */
static BOOL pathdrv_CreateDC( PHYSDEV *dev, LPCWSTR driver, LPCWSTR device,
                              LPCWSTR output, const DEVMODEW *devmode )
{
    struct path_physdev *physdev = HeapAlloc( GetProcessHeap(), 0, sizeof(*physdev) );
    DC *dc;

    if (!physdev) return FALSE;
    dc = get_dc_ptr( (*dev)->hdc );
    push_dc_driver( dev, &physdev->dev, &path_driver );
    release_dc_ptr( dc );
    return TRUE;
}


/*************************************************************
 *           pathdrv_DeleteDC
Alexandre Julliard's avatar
Alexandre Julliard committed
836
 */
837 838 839 840 841 842
static BOOL pathdrv_DeleteDC( PHYSDEV dev )
{
    assert( 0 );  /* should never be called */
    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
843

844
BOOL PATH_SavePath( DC *dst, DC *src )
Alexandre Julliard's avatar
Alexandre Julliard committed
845
{
846
    PHYSDEV dev;
847

848 849 850 851
    if (src->path)
    {
        if (!(dst->path = copy_gdi_path( src->path ))) return FALSE;
    }
852
    else if ((dev = find_dc_driver( src, &path_driver )))
853
    {
854
        struct path_physdev *physdev = get_path_physdev( dev );
855
        if (!(dst->path = copy_gdi_path( physdev->path ))) return FALSE;
856
        dst->path_open = TRUE;
857
    }
858 859
    else dst->path = NULL;
    return TRUE;
860
}
861

862 863
BOOL PATH_RestorePath( DC *dst, DC *src )
{
864 865
    PHYSDEV dev;
    struct path_physdev *physdev;
Alexandre Julliard's avatar
Alexandre Julliard committed
866

867
    if ((dev = pop_dc_driver( dst, &path_driver )))
868
    {
869 870 871 872
        physdev = get_path_physdev( dev );
        free_gdi_path( physdev->path );
        HeapFree( GetProcessHeap(), 0, physdev );
    }
873

874 875 876 877
    if (src->path && src->path_open)
    {
        if (!path_driver.pCreateDC( &dst->physDev, NULL, NULL, NULL, NULL )) return FALSE;
        physdev = get_path_physdev( find_dc_driver( dst, &path_driver ));
878
        physdev->path = src->path;
879
        src->path_open = FALSE;
880 881
        src->path = NULL;
    }
882

883 884 885 886
    if (dst->path) free_gdi_path( dst->path );
    dst->path = src->path;
    src->path = NULL;
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
887 888
}

889 890 891

/*************************************************************
 *           pathdrv_MoveTo
Alexandre Julliard's avatar
Alexandre Julliard committed
892
 */
893
static BOOL pathdrv_MoveTo( PHYSDEV dev, INT x, INT y )
Alexandre Julliard's avatar
Alexandre Julliard committed
894
{
895 896 897
    struct path_physdev *physdev = get_path_physdev( dev );
    physdev->path->newStroke = TRUE;
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
898 899
}

900 901 902

/*************************************************************
 *           pathdrv_LineTo
Alexandre Julliard's avatar
Alexandre Julliard committed
903
 */
904
static BOOL pathdrv_LineTo( PHYSDEV dev, INT x, INT y )
Alexandre Julliard's avatar
Alexandre Julliard committed
905
{
906
    struct path_physdev *physdev = get_path_physdev( dev );
907
    POINT point;
Alexandre Julliard's avatar
Alexandre Julliard committed
908

909
    if (!start_new_stroke( physdev )) return FALSE;
910 911
    point.x = x;
    point.y = y;
912
    return add_log_points( physdev, &point, 1, PT_LINETO ) != NULL;
Alexandre Julliard's avatar
Alexandre Julliard committed
913 914
}

915 916 917

/*************************************************************
 *           pathdrv_RoundRect
918
 *
919
 * FIXME: it adds the same entries to the path as windows does, but there
920 921 922
 * is an error in the bezier drawing code so that there are small pixel-size
 * gaps when the resulting path is drawn by StrokePath()
 */
923
static BOOL pathdrv_RoundRect( PHYSDEV dev, INT x1, INT y1, INT x2, INT y2, INT ell_width, INT ell_height )
924
{
925 926 927
    struct path_physdev *physdev = get_path_physdev( dev );
    POINT corners[2], pointTemp;
    FLOAT_POINT ellCorners[2];
928

929
    PATH_CheckCorners(dev->hdc,corners,x1,y1,x2,y2);
930

931
   /* Add points to the roundrect path */
932
   ellCorners[0].x = corners[1].x-ell_width;
933 934 935
   ellCorners[0].y = corners[0].y;
   ellCorners[1].x = corners[1].x;
   ellCorners[1].y = corners[0].y+ell_height;
936
   if(!PATH_DoArcPart(physdev->path, ellCorners, 0, -M_PI_2, PT_MOVETO))
937 938 939
      return FALSE;
   pointTemp.x = corners[0].x+ell_width/2;
   pointTemp.y = corners[0].y;
940
   if(!PATH_AddEntry(physdev->path, &pointTemp, PT_LINETO))
941 942 943
      return FALSE;
   ellCorners[0].x = corners[0].x;
   ellCorners[1].x = corners[0].x+ell_width;
944
   if(!PATH_DoArcPart(physdev->path, ellCorners, -M_PI_2, -M_PI, FALSE))
945 946 947
      return FALSE;
   pointTemp.x = corners[0].x;
   pointTemp.y = corners[1].y-ell_height/2;
948
   if(!PATH_AddEntry(physdev->path, &pointTemp, PT_LINETO))
949 950 951
      return FALSE;
   ellCorners[0].y = corners[1].y-ell_height;
   ellCorners[1].y = corners[1].y;
952
   if(!PATH_DoArcPart(physdev->path, ellCorners, M_PI, M_PI_2, FALSE))
953 954 955
      return FALSE;
   pointTemp.x = corners[1].x-ell_width/2;
   pointTemp.y = corners[1].y;
956
   if(!PATH_AddEntry(physdev->path, &pointTemp, PT_LINETO))
957 958 959
      return FALSE;
   ellCorners[0].x = corners[1].x-ell_width;
   ellCorners[1].x = corners[1].x;
960
   if(!PATH_DoArcPart(physdev->path, ellCorners, M_PI_2, 0, FALSE))
961 962
      return FALSE;

963
   /* Close the roundrect figure */
964
   return CloseFigure( dev->hdc );
965 966
}

967 968 969

/*************************************************************
 *           pathdrv_Rectangle
Alexandre Julliard's avatar
Alexandre Julliard committed
970
 */
971
static BOOL pathdrv_Rectangle( PHYSDEV dev, INT x1, INT y1, INT x2, INT y2 )
Alexandre Julliard's avatar
Alexandre Julliard committed
972
{
973 974
    struct path_physdev *physdev = get_path_physdev( dev );
    POINT corners[2], pointTemp;
Alexandre Julliard's avatar
Alexandre Julliard committed
975

976
    PATH_CheckCorners(dev->hdc,corners,x1,y1,x2,y2);
Alexandre Julliard's avatar
Alexandre Julliard committed
977 978 979 980

   /* Add four points to the path */
   pointTemp.x=corners[1].x;
   pointTemp.y=corners[0].y;
981
   if(!PATH_AddEntry(physdev->path, &pointTemp, PT_MOVETO))
Alexandre Julliard's avatar
Alexandre Julliard committed
982
      return FALSE;
983
   if(!PATH_AddEntry(physdev->path, corners, PT_LINETO))
Alexandre Julliard's avatar
Alexandre Julliard committed
984 985 986
      return FALSE;
   pointTemp.x=corners[0].x;
   pointTemp.y=corners[1].y;
987
   if(!PATH_AddEntry(physdev->path, &pointTemp, PT_LINETO))
Alexandre Julliard's avatar
Alexandre Julliard committed
988
      return FALSE;
989
   if(!PATH_AddEntry(physdev->path, corners+1, PT_LINETO))
Alexandre Julliard's avatar
Alexandre Julliard committed
990 991 992
      return FALSE;

   /* Close the rectangle figure */
993
   return CloseFigure( dev->hdc );
Alexandre Julliard's avatar
Alexandre Julliard committed
994 995
}

Alexandre Julliard's avatar
Alexandre Julliard committed
996 997 998 999 1000

/* PATH_Arc
 *
 * Should be called when a call to Arc is performed on a DC that has
 * an open path. This adds up to five Bezier splines representing the arc
1001
 * to the path. When 'lines' is 1, we add 1 extra line to get a chord,
1002 1003 1004 1005
 * when 'lines' is 2, we add 2 extra lines to get a pie, and when 'lines' is
 * -1 we add 1 extra line from the current DC position to the starting position
 * of the arc before drawing the arc itself (arcto). Returns TRUE if successful,
 * else FALSE.
Alexandre Julliard's avatar
Alexandre Julliard committed
1006
 */
1007 1008
static BOOL PATH_Arc( PHYSDEV dev, INT x1, INT y1, INT x2, INT y2,
                      INT xStart, INT yStart, INT xEnd, INT yEnd, INT lines )
Alexandre Julliard's avatar
Alexandre Julliard committed
1009
{
1010 1011
    struct path_physdev *physdev = get_path_physdev( dev );
    double angleStart, angleEnd, angleStartQuadrant, angleEndQuadrant=0.0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1012
               /* Initialize angleEndQuadrant to silence gcc's warning */
1013 1014 1015 1016 1017
    double x, y;
    FLOAT_POINT corners[2], pointStart, pointEnd;
    POINT centre;
    BOOL start, end;
    INT temp, direction = GetArcDirection(dev->hdc);
Alexandre Julliard's avatar
Alexandre Julliard committed
1018

Alexandre Julliard's avatar
Alexandre Julliard committed
1019
   /* FIXME: Do we have to respect newStroke? */
1020

Alexandre Julliard's avatar
Alexandre Julliard committed
1021
   /* Check for zero height / width */
Alexandre Julliard's avatar
Alexandre Julliard committed
1022
   /* FIXME: Only in GM_COMPATIBLE? */
Alexandre Julliard's avatar
Alexandre Julliard committed
1023 1024
   if(x1==x2 || y1==y2)
      return TRUE;
1025

Alexandre Julliard's avatar
Alexandre Julliard committed
1026
   /* Convert points to device coordinates */
1027 1028 1029 1030 1031 1032 1033 1034
   corners[0].x = x1;
   corners[0].y = y1;
   corners[1].x = x2;
   corners[1].y = y2;
   pointStart.x = xStart;
   pointStart.y = yStart;
   pointEnd.x = xEnd;
   pointEnd.y = yEnd;
1035 1036 1037
   INTERNAL_LPTODP_FLOAT(dev->hdc, corners, 2);
   INTERNAL_LPTODP_FLOAT(dev->hdc, &pointStart, 1);
   INTERNAL_LPTODP_FLOAT(dev->hdc, &pointEnd, 1);
Alexandre Julliard's avatar
Alexandre Julliard committed
1038 1039

   /* Make sure first corner is top left and second corner is bottom right */
Alexandre Julliard's avatar
Alexandre Julliard committed
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
   if(corners[0].x>corners[1].x)
   {
      temp=corners[0].x;
      corners[0].x=corners[1].x;
      corners[1].x=temp;
   }
   if(corners[0].y>corners[1].y)
   {
      temp=corners[0].y;
      corners[0].y=corners[1].y;
      corners[1].y=temp;
   }

   /* Compute start and end angle */
   PATH_NormalizePoint(corners, &pointStart, &x, &y);
   angleStart=atan2(y, x);
   PATH_NormalizePoint(corners, &pointEnd, &x, &y);
   angleEnd=atan2(y, x);

   /* Make sure the end angle is "on the right side" of the start angle */
1060
   if (direction == AD_CLOCKWISE)
Alexandre Julliard's avatar
Alexandre Julliard committed
1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
   {
      if(angleEnd<=angleStart)
      {
         angleEnd+=2*M_PI;
	 assert(angleEnd>=angleStart);
      }
   }
   else
   {
      if(angleEnd>=angleStart)
      {
         angleEnd-=2*M_PI;
	 assert(angleEnd<=angleStart);
      }
   }

Alexandre Julliard's avatar
Alexandre Julliard committed
1077
   /* In GM_COMPATIBLE, don't include bottom and right edges */
1078
   if (GetGraphicsMode(dev->hdc) == GM_COMPATIBLE)
Alexandre Julliard's avatar
Alexandre Julliard committed
1079 1080 1081 1082
   {
      corners[1].x--;
      corners[1].y--;
   }
1083

1084
   /* arcto: Add a PT_MOVETO only if this is the first entry in a stroke */
1085
   if (lines==-1 && !start_new_stroke( physdev )) return FALSE;
1086

Alexandre Julliard's avatar
Alexandre Julliard committed
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
   /* Add the arc to the path with one Bezier spline per quadrant that the
    * arc spans */
   start=TRUE;
   end=FALSE;
   do
   {
      /* Determine the start and end angles for this quadrant */
      if(start)
      {
         angleStartQuadrant=angleStart;
1097
	 if (direction == AD_CLOCKWISE)
Alexandre Julliard's avatar
Alexandre Julliard committed
1098 1099 1100 1101 1102 1103 1104
	    angleEndQuadrant=(floor(angleStart/M_PI_2)+1.0)*M_PI_2;
	 else
	    angleEndQuadrant=(ceil(angleStart/M_PI_2)-1.0)*M_PI_2;
      }
      else
      {
	 angleStartQuadrant=angleEndQuadrant;
1105
	 if (direction == AD_CLOCKWISE)
Alexandre Julliard's avatar
Alexandre Julliard committed
1106 1107 1108 1109 1110 1111
	    angleEndQuadrant+=M_PI_2;
	 else
	    angleEndQuadrant-=M_PI_2;
      }

      /* Have we reached the last part of the arc? */
1112 1113
      if((direction == AD_CLOCKWISE && angleEnd<angleEndQuadrant) ||
	 (direction == AD_COUNTERCLOCKWISE && angleEnd>angleEndQuadrant))
Alexandre Julliard's avatar
Alexandre Julliard committed
1114 1115 1116 1117 1118 1119 1120
      {
	 /* Adjust the end angle for this quadrant */
         angleEndQuadrant=angleEnd;
	 end=TRUE;
      }

      /* Add the Bezier spline to the path */
1121
      PATH_DoArcPart(physdev->path, corners, angleStartQuadrant, angleEndQuadrant,
1122
         start ? (lines==-1 ? PT_LINETO : PT_MOVETO) : FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1123 1124 1125
      start=FALSE;
   }  while(!end);

1126 1127 1128
   /* chord: close figure. pie: add line and close figure */
   if(lines==1)
   {
1129
      return CloseFigure(dev->hdc);
1130 1131 1132
   }
   else if(lines==2)
   {
1133
      centre.x = (corners[0].x+corners[1].x)/2;
1134
      centre.y = (corners[0].y+corners[1].y)/2;
1135
      if(!PATH_AddEntry(physdev->path, &centre, PT_LINETO | PT_CLOSEFIGURE))
1136 1137
         return FALSE;
   }
1138

Alexandre Julliard's avatar
Alexandre Julliard committed
1139 1140
   return TRUE;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1141

1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210

/*************************************************************
 *           pathdrv_AngleArc
 */
static BOOL pathdrv_AngleArc( PHYSDEV dev, INT x, INT y, DWORD radius, FLOAT eStartAngle, FLOAT eSweepAngle)
{
    INT x1, y1, x2, y2, arcdir;
    BOOL ret;

    x1 = GDI_ROUND( x + cos(eStartAngle*M_PI/180) * radius );
    y1 = GDI_ROUND( y - sin(eStartAngle*M_PI/180) * radius );
    x2 = GDI_ROUND( x + cos((eStartAngle+eSweepAngle)*M_PI/180) * radius );
    y2 = GDI_ROUND( y - sin((eStartAngle+eSweepAngle)*M_PI/180) * radius );
    arcdir = SetArcDirection( dev->hdc, eSweepAngle >= 0 ? AD_COUNTERCLOCKWISE : AD_CLOCKWISE);
    ret = PATH_Arc( dev, x-radius, y-radius, x+radius, y+radius, x1, y1, x2, y2, -1 );
    SetArcDirection( dev->hdc, arcdir );
    return ret;
}


/*************************************************************
 *           pathdrv_Arc
 */
static BOOL pathdrv_Arc( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                         INT xstart, INT ystart, INT xend, INT yend )
{
    return PATH_Arc( dev, left, top, right, bottom, xstart, ystart, xend, yend, 0 );
}


/*************************************************************
 *           pathdrv_ArcTo
 */
static BOOL pathdrv_ArcTo( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                           INT xstart, INT ystart, INT xend, INT yend )
{
    return PATH_Arc( dev, left, top, right, bottom, xstart, ystart, xend, yend, -1 );
}


/*************************************************************
 *           pathdrv_Chord
 */
static BOOL pathdrv_Chord( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                           INT xstart, INT ystart, INT xend, INT yend )
{
    return PATH_Arc( dev, left, top, right, bottom, xstart, ystart, xend, yend, 1);
}


/*************************************************************
 *           pathdrv_Pie
 */
static BOOL pathdrv_Pie( PHYSDEV dev, INT left, INT top, INT right, INT bottom,
                         INT xstart, INT ystart, INT xend, INT yend )
{
    return PATH_Arc( dev, left, top, right, bottom, xstart, ystart, xend, yend, 2 );
}


/*************************************************************
 *           pathdrv_Ellipse
 */
static BOOL pathdrv_Ellipse( PHYSDEV dev, INT x1, INT y1, INT x2, INT y2 )
{
    return PATH_Arc( dev, x1, y1, x2, y2, x1, (y1+y2)/2, x1, (y1+y2)/2, 0 ) && CloseFigure( dev->hdc );
}


1211 1212 1213 1214
/*************************************************************
 *           pathdrv_PolyBezierTo
 */
static BOOL pathdrv_PolyBezierTo( PHYSDEV dev, const POINT *pts, DWORD cbPoints )
1215
{
1216
    struct path_physdev *physdev = get_path_physdev( dev );
1217

1218
    if (!start_new_stroke( physdev )) return FALSE;
1219
    return add_log_points( physdev, pts, cbPoints, PT_BEZIERTO ) != NULL;
1220
}
1221

1222

1223 1224 1225 1226 1227 1228
/*************************************************************
 *           pathdrv_PolyBezier
 */
static BOOL pathdrv_PolyBezier( PHYSDEV dev, const POINT *pts, DWORD cbPoints )
{
    struct path_physdev *physdev = get_path_physdev( dev );
1229
    BYTE *type = add_log_points( physdev, pts, cbPoints, PT_BEZIERTO );
1230

1231 1232
    if (!type) return FALSE;
    type[0] = PT_MOVETO;
1233
    return TRUE;
1234 1235
}

1236 1237 1238

/*************************************************************
 *           pathdrv_PolyDraw
Evan Stade's avatar
Evan Stade committed
1239
 */
1240
static BOOL pathdrv_PolyDraw( PHYSDEV dev, const POINT *pts, const BYTE *types, DWORD cbPoints )
Evan Stade's avatar
Evan Stade committed
1241
{
1242
    struct path_physdev *physdev = get_path_physdev( dev );
1243 1244 1245
    POINT lastmove, orig_pos;
    INT i;

1246
    GetCurrentPositionEx( dev->hdc, &orig_pos );
1247 1248
    lastmove = orig_pos;

1249 1250 1251
    for(i = physdev->path->count - 1; i >= 0; i--){
        if(physdev->path->flags[i] == PT_MOVETO){
            lastmove = physdev->path->points[i];
1252
            DPtoLP(dev->hdc, &lastmove, 1);
1253
            break;
Evan Stade's avatar
Evan Stade committed
1254
        }
1255
    }
Evan Stade's avatar
Evan Stade committed
1256

1257 1258 1259 1260 1261
    for(i = 0; i < cbPoints; i++)
    {
        switch (types[i])
        {
        case PT_MOVETO:
1262
            MoveToEx( dev->hdc, pts[i].x, pts[i].y, NULL );
1263 1264 1265
            break;
        case PT_LINETO:
        case PT_LINETO | PT_CLOSEFIGURE:
1266
            LineTo( dev->hdc, pts[i].x, pts[i].y );
1267 1268 1269 1270 1271
            break;
        case PT_BEZIERTO:
            if ((i + 2 < cbPoints) && (types[i + 1] == PT_BEZIERTO) &&
                (types[i + 2] & ~PT_CLOSEFIGURE) == PT_BEZIERTO)
            {
1272
                PolyBezierTo( dev->hdc, &pts[i], 3 );
Evan Stade's avatar
Evan Stade committed
1273
                i += 2;
1274
                break;
Evan Stade's avatar
Evan Stade committed
1275
            }
1276 1277 1278 1279 1280 1281
            /* fall through */
        default:
            if (i)  /* restore original position */
            {
                if (!(types[i - 1] & PT_CLOSEFIGURE)) lastmove = pts[i - 1];
                if (lastmove.x != orig_pos.x || lastmove.y != orig_pos.y)
1282
                    MoveToEx( dev->hdc, orig_pos.x, orig_pos.y, NULL );
Evan Stade's avatar
Evan Stade committed
1283
            }
1284
            return FALSE;
Evan Stade's avatar
Evan Stade committed
1285 1286
        }

1287
        if(types[i] & PT_CLOSEFIGURE){
1288
            physdev->path->flags[physdev->path->count-1] |= PT_CLOSEFIGURE;
1289
            MoveToEx( dev->hdc, lastmove.x, lastmove.y, NULL );
Evan Stade's avatar
Evan Stade committed
1290
        }
1291
    }
Evan Stade's avatar
Evan Stade committed
1292

1293
    return TRUE;
Evan Stade's avatar
Evan Stade committed
1294 1295
}

1296

1297 1298 1299 1300 1301 1302
/*************************************************************
 *           pathdrv_Polyline
 */
static BOOL pathdrv_Polyline( PHYSDEV dev, const POINT *pts, INT cbPoints )
{
    struct path_physdev *physdev = get_path_physdev( dev );
1303
    BYTE *type = add_log_points( physdev, pts, cbPoints, PT_LINETO );
1304

1305 1306
    if (!type) return FALSE;
    if (cbPoints) type[0] = PT_MOVETO;
1307
    return TRUE;
1308
}
1309

1310

1311 1312 1313 1314 1315 1316
/*************************************************************
 *           pathdrv_PolylineTo
 */
static BOOL pathdrv_PolylineTo( PHYSDEV dev, const POINT *pts, INT cbPoints )
{
    struct path_physdev *physdev = get_path_physdev( dev );
1317

1318
    if (!start_new_stroke( physdev )) return FALSE;
1319
    return add_log_points( physdev, pts, cbPoints, PT_LINETO ) != NULL;
1320 1321 1322
}


1323 1324 1325 1326
/*************************************************************
 *           pathdrv_Polygon
 */
static BOOL pathdrv_Polygon( PHYSDEV dev, const POINT *pts, INT cbPoints )
1327
{
1328
    struct path_physdev *physdev = get_path_physdev( dev );
1329
    BYTE *type = add_log_points( physdev, pts, cbPoints, PT_LINETO );
1330

1331 1332 1333
    if (!type) return FALSE;
    if (cbPoints) type[0] = PT_MOVETO;
    if (cbPoints > 1) type[cbPoints - 1] = PT_LINETO | PT_CLOSEFIGURE;
1334
    return TRUE;
1335 1336 1337
}


1338 1339 1340 1341 1342 1343
/*************************************************************
 *           pathdrv_PolyPolygon
 */
static BOOL pathdrv_PolyPolygon( PHYSDEV dev, const POINT* pts, const INT* counts, UINT polygons )
{
    struct path_physdev *physdev = get_path_physdev( dev );
1344 1345 1346 1347 1348 1349 1350
    UINT poly;
    BYTE *type;

    for(poly = 0; poly < polygons; poly++) {
        type = add_log_points( physdev, pts, counts[poly], PT_LINETO );
        if (!type) return FALSE;
        type[0] = PT_MOVETO;
1351
        /* win98 adds an extra line to close the figure for some reason */
1352 1353
        add_log_points( physdev, pts, 1, PT_LINETO | PT_CLOSEFIGURE );
        pts += counts[poly];
1354 1355
    }
    return TRUE;
1356 1357 1358
}


1359 1360 1361 1362 1363 1364
/*************************************************************
 *           pathdrv_PolyPolyline
 */
static BOOL pathdrv_PolyPolyline( PHYSDEV dev, const POINT* pts, const DWORD* counts, DWORD polylines )
{
    struct path_physdev *physdev = get_path_physdev( dev );
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374
    UINT poly, count;
    BYTE *type;

    for (poly = count = 0; poly < polylines; poly++) count += counts[poly];

    type = add_log_points( physdev, pts, count, PT_LINETO );
    if (!type) return FALSE;

    /* make the first point of each polyline a PT_MOVETO */
    for (poly = 0; poly < polylines; poly++, type += counts[poly]) *type = PT_MOVETO;
1375
    return TRUE;
1376
}
1377

1378 1379 1380 1381 1382 1383

/**********************************************************************
 *      PATH_BezierTo
 *
 * internally used by PATH_add_outline
 */
1384
static void PATH_BezierTo(struct gdi_path *pPath, POINT *lppt, INT n)
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423
{
    if (n < 2) return;

    if (n == 2)
    {
        PATH_AddEntry(pPath, &lppt[1], PT_LINETO);
    }
    else if (n == 3)
    {
        PATH_AddEntry(pPath, &lppt[0], PT_BEZIERTO);
        PATH_AddEntry(pPath, &lppt[1], PT_BEZIERTO);
        PATH_AddEntry(pPath, &lppt[2], PT_BEZIERTO);
    }
    else
    {
        POINT pt[3];
        INT i = 0;

        pt[2] = lppt[0];
        n--;

        while (n > 2)
        {
            pt[0] = pt[2];
            pt[1] = lppt[i+1];
            pt[2].x = (lppt[i+2].x + lppt[i+1].x) / 2;
            pt[2].y = (lppt[i+2].y + lppt[i+1].y) / 2;
            PATH_BezierTo(pPath, pt, 3);
            n--;
            i++;
        }

        pt[0] = pt[2];
        pt[1] = lppt[i+1];
        pt[2] = lppt[i+2];
        PATH_BezierTo(pPath, pt, 3);
    }
}

1424 1425
static BOOL PATH_add_outline(struct path_physdev *physdev, INT x, INT y,
                             TTPOLYGONHEADER *header, DWORD size)
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437
{
    TTPOLYGONHEADER *start;
    POINT pt;

    start = header;

    while ((char *)header < (char *)start + size)
    {
        TTPOLYCURVE *curve;

        if (header->dwType != TT_POLYGON_TYPE)
        {
1438
            FIXME("Unknown header type %d\n", header->dwType);
1439 1440 1441 1442 1443
            return FALSE;
        }

        pt.x = x + int_from_fixed(header->pfxStart.x);
        pt.y = y - int_from_fixed(header->pfxStart.y);
1444
        PATH_AddEntry(physdev->path, &pt, PT_MOVETO);
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461

        curve = (TTPOLYCURVE *)(header + 1);

        while ((char *)curve < (char *)header + header->cb)
        {
            /*TRACE("curve->wType %d\n", curve->wType);*/

            switch(curve->wType)
            {
            case TT_PRIM_LINE:
            {
                WORD i;

                for (i = 0; i < curve->cpfx; i++)
                {
                    pt.x = x + int_from_fixed(curve->apfx[i].x);
                    pt.y = y - int_from_fixed(curve->apfx[i].y);
1462
                    PATH_AddEntry(physdev->path, &pt, PT_LINETO);
1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486
                }
                break;
            }

            case TT_PRIM_QSPLINE:
            case TT_PRIM_CSPLINE:
            {
                WORD i;
                POINTFX ptfx;
                POINT *pts = HeapAlloc(GetProcessHeap(), 0, (curve->cpfx + 1) * sizeof(POINT));

                if (!pts) return FALSE;

                ptfx = *(POINTFX *)((char *)curve - sizeof(POINTFX));

                pts[0].x = x + int_from_fixed(ptfx.x);
                pts[0].y = y - int_from_fixed(ptfx.y);

                for(i = 0; i < curve->cpfx; i++)
                {
                    pts[i + 1].x = x + int_from_fixed(curve->apfx[i].x);
                    pts[i + 1].y = y - int_from_fixed(curve->apfx[i].y);
                }

1487
                PATH_BezierTo(physdev->path, pts, curve->cpfx + 1);
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503

                HeapFree(GetProcessHeap(), 0, pts);
                break;
            }

            default:
                FIXME("Unknown curve type %04x\n", curve->wType);
                return FALSE;
            }

            curve = (TTPOLYCURVE *)&curve->apfx[curve->cpfx];
        }

        header = (TTPOLYGONHEADER *)((char *)header + header->cb);
    }

1504
    return CloseFigure(physdev->dev.hdc);
1505 1506
}

1507 1508
/*************************************************************
 *           pathdrv_ExtTextOut
1509
 */
1510 1511
static BOOL pathdrv_ExtTextOut( PHYSDEV dev, INT x, INT y, UINT flags, const RECT *lprc,
                                LPCWSTR str, UINT count, const INT *dx )
1512
{
1513
    struct path_physdev *physdev = get_path_physdev( dev );
1514
    unsigned int idx;
1515
    POINT offset = {0, 0};
1516 1517 1518 1519 1520

    if (!count) return TRUE;

    for (idx = 0; idx < count; idx++)
    {
1521
        static const MAT2 identity = { {0,1},{0,0},{0,0},{0,1} };
1522 1523 1524 1525
        GLYPHMETRICS gm;
        DWORD dwSize;
        void *outline;

1526 1527
        dwSize = GetGlyphOutlineW(dev->hdc, str[idx], GGO_GLYPH_INDEX | GGO_NATIVE,
                                  &gm, 0, NULL, &identity);
1528
        if (dwSize == GDI_ERROR) return FALSE;
1529

1530 1531 1532 1533 1534
        /* add outline only if char is printable */
        if(dwSize)
        {
            outline = HeapAlloc(GetProcessHeap(), 0, dwSize);
            if (!outline) return FALSE;
1535

1536 1537
            GetGlyphOutlineW(dev->hdc, str[idx], GGO_GLYPH_INDEX | GGO_NATIVE,
                             &gm, dwSize, outline, &identity);
1538

1539
            PATH_add_outline(physdev, x + offset.x, y + offset.y, outline, dwSize);
1540

1541 1542
            HeapFree(GetProcessHeap(), 0, outline);
        }
1543 1544 1545

        if (dx)
        {
1546 1547 1548 1549 1550 1551 1552
            if(flags & ETO_PDY)
            {
                offset.x += dx[idx * 2];
                offset.y += dx[idx * 2 + 1];
            }
            else
                offset.x += dx[idx];
1553 1554 1555
        }
        else
        {
1556 1557
            offset.x += gm.gmCellIncX;
            offset.y += gm.gmCellIncY;
1558 1559 1560 1561 1562
        }
    }
    return TRUE;
}

1563

1564 1565 1566 1567 1568 1569 1570 1571 1572
/*************************************************************
 *           pathdrv_CloseFigure
 */
static BOOL pathdrv_CloseFigure( PHYSDEV dev )
{
    struct path_physdev *physdev = get_path_physdev( dev );

    /* Set PT_CLOSEFIGURE on the last entry and start a new stroke */
    /* It is not necessary to draw a line, PT_CLOSEFIGURE is a virtual closing line itself */
1573 1574
    if (physdev->path->count)
        physdev->path->flags[physdev->path->count - 1] |= PT_CLOSEFIGURE;
1575 1576 1577 1578
    return TRUE;
}


1579
/*******************************************************************
1580
 *      FlattenPath [GDI32.@]
1581 1582 1583
 *
 *
 */
1584
BOOL WINAPI FlattenPath(HDC hdc)
1585
{
1586
    BOOL ret = FALSE;
1587
    DC *dc = get_dc_ptr( hdc );
1588

1589
    if (dc)
1590
    {
1591 1592 1593
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pFlattenPath );
        ret = physdev->funcs->pFlattenPath( physdev );
        release_dc_ptr( dc );
1594 1595
    }
    return ret;
1596 1597
}

1598

1599
static BOOL PATH_StrokePath( HDC hdc, const struct gdi_path *pPath )
1600
{
1601 1602
    INT i, nLinePts, nAlloc;
    POINT *pLinePts;
1603 1604 1605 1606 1607
    POINT ptViewportOrg, ptWindowOrg;
    SIZE szViewportExt, szWindowExt;
    DWORD mapMode, graphicsMode;
    XFORM xform;
    BOOL ret = TRUE;
1608

1609
    /* Save the mapping mode info */
1610 1611 1612 1613 1614 1615
    mapMode=GetMapMode(hdc);
    GetViewportExtEx(hdc, &szViewportExt);
    GetViewportOrgEx(hdc, &ptViewportOrg);
    GetWindowExtEx(hdc, &szWindowExt);
    GetWindowOrgEx(hdc, &ptWindowOrg);
    GetWorldTransform(hdc, &xform);
1616

1617
    /* Set MM_TEXT */
1618 1619 1620 1621 1622 1623 1624
    SetMapMode(hdc, MM_TEXT);
    SetViewportOrgEx(hdc, 0, 0, NULL);
    SetWindowOrgEx(hdc, 0, 0, NULL);
    graphicsMode=GetGraphicsMode(hdc);
    SetGraphicsMode(hdc, GM_ADVANCED);
    ModifyWorldTransform(hdc, &xform, MWT_IDENTITY);
    SetGraphicsMode(hdc, graphicsMode);
1625

1626 1627 1628
    /* Allocate enough memory for the worst case without beziers (one PT_MOVETO
     * and the rest PT_LINETO with PT_CLOSEFIGURE at the end) plus some buffer 
     * space in case we get one to keep the number of reallocations small. */
1629
    nAlloc = pPath->count + 1 + 300;
1630 1631 1632
    pLinePts = HeapAlloc(GetProcessHeap(), 0, nAlloc * sizeof(POINT));
    nLinePts = 0;
    
1633 1634 1635
    for(i = 0; i < pPath->count; i++) {
        if((i == 0 || (pPath->flags[i-1] & PT_CLOSEFIGURE)) &&
	   (pPath->flags[i] != PT_MOVETO)) {
1636 1637
	    ERR("Expected PT_MOVETO %s, got path flag %d\n", 
	        i == 0 ? "as first point" : "after PT_CLOSEFIGURE",
1638
		pPath->flags[i]);
1639 1640 1641
	    ret = FALSE;
	    goto end;
	}
1642
        switch(pPath->flags[i]) {
1643
	case PT_MOVETO:
1644
            TRACE("Got PT_MOVETO (%d, %d)\n",
1645
		  pPath->points[i].x, pPath->points[i].y);
1646
	    if(nLinePts >= 2)
1647
	        Polyline(hdc, pLinePts, nLinePts);
1648
	    nLinePts = 0;
1649
	    pLinePts[nLinePts++] = pPath->points[i];
1650 1651 1652
	    break;
	case PT_LINETO:
	case (PT_LINETO | PT_CLOSEFIGURE):
1653
            TRACE("Got PT_LINETO (%d, %d)\n",
1654 1655
		  pPath->points[i].x, pPath->points[i].y);
	    pLinePts[nLinePts++] = pPath->points[i];
1656 1657 1658
	    break;
	case PT_BEZIERTO:
	    TRACE("Got PT_BEZIERTO\n");
1659 1660
	    if(pPath->flags[i+1] != PT_BEZIERTO ||
	       (pPath->flags[i+2] & ~PT_CLOSEFIGURE) != PT_BEZIERTO) {
1661
	        ERR("Path didn't contain 3 successive PT_BEZIERTOs\n");
1662 1663
		ret = FALSE;
		goto end;
1664 1665
	    } else {
	        INT nBzrPts, nMinAlloc;
1666
	        POINT *pBzrPts = GDI_Bezier(&pPath->points[i-1], 4, &nBzrPts);
1667 1668 1669
		/* Make sure we have allocated enough memory for the lines of 
		 * this bezier and the rest of the path, assuming we won't get
		 * another one (since we won't reallocate again then). */
1670
		nMinAlloc = nLinePts + (pPath->count - i) + nBzrPts;
1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681
		if(nAlloc < nMinAlloc)
		{
		    nAlloc = nMinAlloc * 2;
		    pLinePts = HeapReAlloc(GetProcessHeap(), 0, pLinePts,
		                           nAlloc * sizeof(POINT));
		}
		memcpy(&pLinePts[nLinePts], &pBzrPts[1],
		       (nBzrPts - 1) * sizeof(POINT));
		nLinePts += nBzrPts - 1;
		HeapFree(GetProcessHeap(), 0, pBzrPts);
		i += 2;
1682 1683 1684
	    }
	    break;
	default:
1685
	    ERR("Got path flag %d\n", pPath->flags[i]);
1686 1687
	    ret = FALSE;
	    goto end;
1688
	}
1689
	if(pPath->flags[i] & PT_CLOSEFIGURE)
1690
	    pLinePts[nLinePts++] = pLinePts[0];
1691
    }
1692
    if(nLinePts >= 2)
1693
        Polyline(hdc, pLinePts, nLinePts);
1694 1695

 end:
1696
    HeapFree(GetProcessHeap(), 0, pLinePts);
1697 1698

    /* Restore the old mapping mode */
1699 1700 1701 1702 1703
    SetMapMode(hdc, mapMode);
    SetWindowExtEx(hdc, szWindowExt.cx, szWindowExt.cy, NULL);
    SetWindowOrgEx(hdc, ptWindowOrg.x, ptWindowOrg.y, NULL);
    SetViewportExtEx(hdc, szViewportExt.cx, szViewportExt.cy, NULL);
    SetViewportOrgEx(hdc, ptViewportOrg.x, ptViewportOrg.y, NULL);
1704 1705

    /* Go to GM_ADVANCED temporarily to restore the world transform */
1706 1707 1708 1709
    graphicsMode=GetGraphicsMode(hdc);
    SetGraphicsMode(hdc, GM_ADVANCED);
    SetWorldTransform(hdc, &xform);
    SetGraphicsMode(hdc, graphicsMode);
1710 1711 1712 1713 1714 1715 1716 1717 1718

    /* If we've moved the current point then get its new position
       which will be in device (MM_TEXT) co-ords, convert it to
       logical co-ords and re-set it.  This basically updates
       dc->CurPosX|Y so that their values are in the correct mapping
       mode.
    */
    if(i > 0) {
        POINT pt;
1719 1720 1721
        GetCurrentPositionEx(hdc, &pt);
        DPtoLP(hdc, &pt, 1);
        MoveToEx(hdc, pt.x, pt.y, NULL);
1722
    }
1723

1724
    return ret;
1725 1726
}

1727
#define round(x) ((int)((x)>0?(x)+0.5:(x)-0.5))
1728

1729
static struct gdi_path *PATH_WidenPath(DC *dc)
1730
{
1731
    INT i, j, numStrokes, penWidth, penWidthIn, penWidthOut, size, penStyle;
1732
    struct gdi_path *flat_path, *pNewPath, **pStrokes = NULL, *pUpPath, *pDownPath;
1733
    EXTLOGPEN *elp;
1734
    DWORD obj_type, joint, endcap, penType;
1735 1736

    size = GetObjectW( dc->hPen, 0, NULL );
1737 1738
    if (!size) {
        SetLastError(ERROR_CAN_NOT_COMPLETE);
1739
        return NULL;
1740
    }
1741 1742 1743

    elp = HeapAlloc( GetProcessHeap(), 0, size );
    GetObjectW( dc->hPen, size, elp );
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754

    obj_type = GetObjectType(dc->hPen);
    if(obj_type == OBJ_PEN) {
        penStyle = ((LOGPEN*)elp)->lopnStyle;
    }
    else if(obj_type == OBJ_EXTPEN) {
        penStyle = elp->elpPenStyle;
    }
    else {
        SetLastError(ERROR_CAN_NOT_COMPLETE);
        HeapFree( GetProcessHeap(), 0, elp );
1755
        return NULL;
1756 1757
    }

1758 1759 1760
    penWidth = elp->elpWidth;
    HeapFree( GetProcessHeap(), 0, elp );

1761 1762 1763 1764 1765 1766 1767
    endcap = (PS_ENDCAP_MASK & penStyle);
    joint = (PS_JOIN_MASK & penStyle);
    penType = (PS_TYPE_MASK & penStyle);

    /* The function cannot apply to cosmetic pens */
    if(obj_type == OBJ_EXTPEN && penType == PS_COSMETIC) {
        SetLastError(ERROR_CAN_NOT_COMPLETE);
1768
        return NULL;
1769 1770
    }

1771
    if (!(flat_path = PATH_FlattenPath( dc->path ))) return NULL;
1772

1773 1774 1775 1776 1777 1778 1779
    penWidthIn = penWidth / 2;
    penWidthOut = penWidth / 2;
    if(penWidthIn + penWidthOut < penWidth)
        penWidthOut++;

    numStrokes = 0;

1780
    for(i = 0, j = 0; i < flat_path->count; i++, j++) {
1781
        POINT point;
1782 1783
        if((i == 0 || (flat_path->flags[i-1] & PT_CLOSEFIGURE)) &&
            (flat_path->flags[i] != PT_MOVETO)) {
1784 1785
            ERR("Expected PT_MOVETO %s, got path flag %c\n",
                i == 0 ? "as first point" : "after PT_CLOSEFIGURE",
1786
                flat_path->flags[i]);
1787
            free_gdi_path( flat_path );
1788
            return NULL;
1789
        }
1790
        switch(flat_path->flags[i]) {
1791 1792 1793
            case PT_MOVETO:
                numStrokes++;
                j = 0;
1794
                if(numStrokes == 1)
1795
                    pStrokes = HeapAlloc(GetProcessHeap(), 0, sizeof(*pStrokes));
1796
                else
1797
                    pStrokes = HeapReAlloc(GetProcessHeap(), 0, pStrokes, numStrokes * sizeof(*pStrokes));
1798
                if(!pStrokes) return NULL;
1799
                pStrokes[numStrokes - 1] = alloc_gdi_path(0);
1800
                /* fall through */
1801 1802
            case PT_LINETO:
            case (PT_LINETO | PT_CLOSEFIGURE):
1803 1804 1805
                point.x = flat_path->points[i].x;
                point.y = flat_path->points[i].y;
                PATH_AddEntry(pStrokes[numStrokes - 1], &point, flat_path->flags[i]);
1806 1807 1808
                break;
            case PT_BEZIERTO:
                /* should never happen because of the FlattenPath call */
1809
                ERR("Should never happen\n");
1810 1811
                break;
            default:
1812
                ERR("Got path flag %c\n", flat_path->flags[i]);
1813
                return NULL;
1814 1815 1816
        }
    }

1817
    pNewPath = alloc_gdi_path( flat_path->count );
1818 1819

    for(i = 0; i < numStrokes; i++) {
1820 1821
        pUpPath = alloc_gdi_path( pStrokes[i]->count );
        pDownPath = alloc_gdi_path( pStrokes[i]->count );
1822

1823
        for(j = 0; j < pStrokes[i]->count; j++) {
1824
            /* Beginning or end of the path if not closed */
1825
            if((!(pStrokes[i]->flags[pStrokes[i]->count - 1] & PT_CLOSEFIGURE)) && (j == 0 || j == pStrokes[i]->count - 1) ) {
1826
                /* Compute segment angle */
1827
                double xo, yo, xa, ya, theta;
1828 1829 1830
                POINT pt;
                FLOAT_POINT corners[2];
                if(j == 0) {
1831 1832 1833 1834
                    xo = pStrokes[i]->points[j].x;
                    yo = pStrokes[i]->points[j].y;
                    xa = pStrokes[i]->points[1].x;
                    ya = pStrokes[i]->points[1].y;
1835 1836
                }
                else {
1837 1838 1839 1840
                    xa = pStrokes[i]->points[j - 1].x;
                    ya = pStrokes[i]->points[j - 1].y;
                    xo = pStrokes[i]->points[j].x;
                    yo = pStrokes[i]->points[j].y;
1841
                }
1842
                theta = atan2( ya - yo, xa - xo );
1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865
                switch(endcap) {
                    case PS_ENDCAP_SQUARE :
                        pt.x = xo + round(sqrt(2) * penWidthOut * cos(M_PI_4 + theta));
                        pt.y = yo + round(sqrt(2) * penWidthOut * sin(M_PI_4 + theta));
                        PATH_AddEntry(pUpPath, &pt, (j == 0 ? PT_MOVETO : PT_LINETO) );
                        pt.x = xo + round(sqrt(2) * penWidthIn * cos(- M_PI_4 + theta));
                        pt.y = yo + round(sqrt(2) * penWidthIn * sin(- M_PI_4 + theta));
                        PATH_AddEntry(pUpPath, &pt, PT_LINETO);
                        break;
                    case PS_ENDCAP_FLAT :
                        pt.x = xo + round( penWidthOut * cos(theta + M_PI_2) );
                        pt.y = yo + round( penWidthOut * sin(theta + M_PI_2) );
                        PATH_AddEntry(pUpPath, &pt, (j == 0 ? PT_MOVETO : PT_LINETO));
                        pt.x = xo - round( penWidthIn * cos(theta + M_PI_2) );
                        pt.y = yo - round( penWidthIn * sin(theta + M_PI_2) );
                        PATH_AddEntry(pUpPath, &pt, PT_LINETO);
                        break;
                    case PS_ENDCAP_ROUND :
                    default :
                        corners[0].x = xo - penWidthIn;
                        corners[0].y = yo - penWidthIn;
                        corners[1].x = xo + penWidthOut;
                        corners[1].y = yo + penWidthOut;
1866
                        PATH_DoArcPart(pUpPath ,corners, theta + M_PI_2 , theta + 3 * M_PI_4, (j == 0 ? PT_MOVETO : FALSE));
1867 1868 1869 1870 1871
                        PATH_DoArcPart(pUpPath ,corners, theta + 3 * M_PI_4 , theta + M_PI, FALSE);
                        PATH_DoArcPart(pUpPath ,corners, theta + M_PI, theta +  5 * M_PI_4, FALSE);
                        PATH_DoArcPart(pUpPath ,corners, theta + 5 * M_PI_4 , theta + 3 * M_PI_2, FALSE);
                        break;
                }
1872
            }
1873
            /* Corpse of the path */
1874
            else {
1875 1876
                /* Compute angle */
                INT previous, next;
1877
                double xa, ya, xb, yb, xo, yo;
1878
                double alpha, theta, miterWidth;
1879 1880
                DWORD _joint = joint;
                POINT pt;
1881
		struct gdi_path *pInsidePath, *pOutsidePath;
1882
                if(j > 0 && j < pStrokes[i]->count - 1) {
1883 1884 1885 1886
                    previous = j - 1;
                    next = j + 1;
                }
                else if (j == 0) {
1887
                    previous = pStrokes[i]->count - 1;
1888 1889 1890 1891 1892 1893
                    next = j + 1;
                }
                else {
                    previous = j - 1;
                    next = 0;
                }
1894 1895 1896 1897 1898 1899
                xo = pStrokes[i]->points[j].x;
                yo = pStrokes[i]->points[j].y;
                xa = pStrokes[i]->points[previous].x;
                ya = pStrokes[i]->points[previous].y;
                xb = pStrokes[i]->points[next].x;
                yb = pStrokes[i]->points[next].y;
1900 1901 1902 1903
                theta = atan2( yo - ya, xo - xa );
                alpha = atan2( yb - yo, xb - xo ) - theta;
                if (alpha > 0) alpha -= M_PI;
                else alpha += M_PI;
1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989
                if(_joint == PS_JOIN_MITER && dc->miterLimit < fabs(1 / sin(alpha/2))) {
                    _joint = PS_JOIN_BEVEL;
                }
                if(alpha > 0) {
                    pInsidePath = pUpPath;
                    pOutsidePath = pDownPath;
                }
                else if(alpha < 0) {
                    pInsidePath = pDownPath;
                    pOutsidePath = pUpPath;
                }
                else {
                    continue;
                }
                /* Inside angle points */
                if(alpha > 0) {
                    pt.x = xo - round( penWidthIn * cos(theta + M_PI_2) );
                    pt.y = yo - round( penWidthIn * sin(theta + M_PI_2) );
                }
                else {
                    pt.x = xo + round( penWidthIn * cos(theta + M_PI_2) );
                    pt.y = yo + round( penWidthIn * sin(theta + M_PI_2) );
                }
                PATH_AddEntry(pInsidePath, &pt, PT_LINETO);
                if(alpha > 0) {
                    pt.x = xo + round( penWidthIn * cos(M_PI_2 + alpha + theta) );
                    pt.y = yo + round( penWidthIn * sin(M_PI_2 + alpha + theta) );
                }
                else {
                    pt.x = xo - round( penWidthIn * cos(M_PI_2 + alpha + theta) );
                    pt.y = yo - round( penWidthIn * sin(M_PI_2 + alpha + theta) );
                }
                PATH_AddEntry(pInsidePath, &pt, PT_LINETO);
                /* Outside angle point */
                switch(_joint) {
                     case PS_JOIN_MITER :
                        miterWidth = fabs(penWidthOut / cos(M_PI_2 - fabs(alpha) / 2));
                        pt.x = xo + round( miterWidth * cos(theta + alpha / 2) );
                        pt.y = yo + round( miterWidth * sin(theta + alpha / 2) );
                        PATH_AddEntry(pOutsidePath, &pt, PT_LINETO);
                        break;
                    case PS_JOIN_BEVEL :
                        if(alpha > 0) {
                            pt.x = xo + round( penWidthOut * cos(theta + M_PI_2) );
                            pt.y = yo + round( penWidthOut * sin(theta + M_PI_2) );
                        }
                        else {
                            pt.x = xo - round( penWidthOut * cos(theta + M_PI_2) );
                            pt.y = yo - round( penWidthOut * sin(theta + M_PI_2) );
                        }
                        PATH_AddEntry(pOutsidePath, &pt, PT_LINETO);
                        if(alpha > 0) {
                            pt.x = xo - round( penWidthOut * cos(M_PI_2 + alpha + theta) );
                            pt.y = yo - round( penWidthOut * sin(M_PI_2 + alpha + theta) );
                        }
                        else {
                            pt.x = xo + round( penWidthOut * cos(M_PI_2 + alpha + theta) );
                            pt.y = yo + round( penWidthOut * sin(M_PI_2 + alpha + theta) );
                        }
                        PATH_AddEntry(pOutsidePath, &pt, PT_LINETO);
                        break;
                    case PS_JOIN_ROUND :
                    default :
                        if(alpha > 0) {
                            pt.x = xo + round( penWidthOut * cos(theta + M_PI_2) );
                            pt.y = yo + round( penWidthOut * sin(theta + M_PI_2) );
                        }
                        else {
                            pt.x = xo - round( penWidthOut * cos(theta + M_PI_2) );
                            pt.y = yo - round( penWidthOut * sin(theta + M_PI_2) );
                        }
                        PATH_AddEntry(pOutsidePath, &pt, PT_BEZIERTO);
                        pt.x = xo + round( penWidthOut * cos(theta + alpha / 2) );
                        pt.y = yo + round( penWidthOut * sin(theta + alpha / 2) );
                        PATH_AddEntry(pOutsidePath, &pt, PT_BEZIERTO);
                        if(alpha > 0) {
                            pt.x = xo - round( penWidthOut * cos(M_PI_2 + alpha + theta) );
                            pt.y = yo - round( penWidthOut * sin(M_PI_2 + alpha + theta) );
                        }
                        else {
                            pt.x = xo + round( penWidthOut * cos(M_PI_2 + alpha + theta) );
                            pt.y = yo + round( penWidthOut * sin(M_PI_2 + alpha + theta) );
                        }
                        PATH_AddEntry(pOutsidePath, &pt, PT_BEZIERTO);
                        break;
                }
1990 1991
            }
        }
1992
        for(j = 0; j < pUpPath->count; j++) {
1993
            POINT pt;
1994 1995
            pt.x = pUpPath->points[j].x;
            pt.y = pUpPath->points[j].y;
1996 1997
            PATH_AddEntry(pNewPath, &pt, (j == 0 ? PT_MOVETO : PT_LINETO));
        }
1998
        for(j = 0; j < pDownPath->count; j++) {
1999
            POINT pt;
2000 2001 2002
            pt.x = pDownPath->points[pDownPath->count - j - 1].x;
            pt.y = pDownPath->points[pDownPath->count - j - 1].y;
            PATH_AddEntry(pNewPath, &pt, ( (j == 0 && (pStrokes[i]->flags[pStrokes[i]->count - 1] & PT_CLOSEFIGURE)) ? PT_MOVETO : PT_LINETO));
2003 2004
        }

2005 2006 2007
        free_gdi_path( pStrokes[i] );
        free_gdi_path( pUpPath );
        free_gdi_path( pDownPath );
2008 2009
    }
    HeapFree(GetProcessHeap(), 0, pStrokes);
2010
    free_gdi_path( flat_path );
2011
    return pNewPath;
2012 2013 2014
}


2015
/*******************************************************************
2016
 *      StrokeAndFillPath [GDI32.@]
2017 2018 2019
 *
 *
 */
2020
BOOL WINAPI StrokeAndFillPath(HDC hdc)
2021
{
2022 2023
    BOOL ret = FALSE;
    DC *dc = get_dc_ptr( hdc );
2024

2025 2026 2027 2028 2029 2030 2031
    if (dc)
    {
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pStrokeAndFillPath );
        ret = physdev->funcs->pStrokeAndFillPath( physdev );
        release_dc_ptr( dc );
    }
    return ret;
2032 2033
}

2034

2035
/*******************************************************************
2036
 *      StrokePath [GDI32.@]
2037 2038 2039
 *
 *
 */
2040
BOOL WINAPI StrokePath(HDC hdc)
2041
{
2042
    BOOL ret = FALSE;
2043
    DC *dc = get_dc_ptr( hdc );
2044

2045
    if (dc)
2046
    {
2047 2048 2049
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pStrokePath );
        ret = physdev->funcs->pStrokePath( physdev );
        release_dc_ptr( dc );
2050
    }
2051
    return ret;
2052 2053
}

2054

2055
/*******************************************************************
2056
 *      WidenPath [GDI32.@]
2057 2058 2059
 *
 *
 */
2060
BOOL WINAPI WidenPath(HDC hdc)
2061
{
2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072
    BOOL ret = FALSE;
    DC *dc = get_dc_ptr( hdc );

    if (dc)
    {
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pWidenPath );
        ret = physdev->funcs->pWidenPath( physdev );
        release_dc_ptr( dc );
    }
    return ret;
}
2073

2074

2075 2076 2077 2078
/***********************************************************************
 *           null driver fallback implementations
 */

2079
BOOL nulldrv_BeginPath( PHYSDEV dev )
2080 2081
{
    DC *dc = get_nulldrv_dc( dev );
2082
    struct path_physdev *physdev;
2083
    struct gdi_path *path = alloc_gdi_path(0);
2084

2085 2086 2087 2088 2089 2090
    if (!path) return FALSE;
    if (!path_driver.pCreateDC( &dc->physDev, NULL, NULL, NULL, NULL ))
    {
        free_gdi_path( path );
        return FALSE;
    }
2091
    physdev = get_path_physdev( find_dc_driver( dc, &path_driver ));
2092 2093
    physdev->path = path;
    if (dc->path) free_gdi_path( dc->path );
2094
    dc->path = NULL;
2095 2096 2097
    return TRUE;
}

2098
BOOL nulldrv_EndPath( PHYSDEV dev )
2099
{
2100 2101
    SetLastError( ERROR_CAN_NOT_COMPLETE );
    return FALSE;
2102 2103
}

2104
BOOL nulldrv_AbortPath( PHYSDEV dev )
2105 2106 2107
{
    DC *dc = get_nulldrv_dc( dev );

2108 2109
    if (dc->path) free_gdi_path( dc->path );
    dc->path = NULL;
2110 2111 2112
    return TRUE;
}

2113
BOOL nulldrv_CloseFigure( PHYSDEV dev )
2114
{
2115 2116
    SetLastError( ERROR_CAN_NOT_COMPLETE );
    return FALSE;
2117 2118
}

2119
BOOL nulldrv_SelectClipPath( PHYSDEV dev, INT mode )
2120 2121 2122 2123 2124
{
    BOOL ret;
    HRGN hrgn;
    DC *dc = get_nulldrv_dc( dev );

2125
    if (!dc->path)
2126 2127 2128 2129
    {
        SetLastError( ERROR_CAN_NOT_COMPLETE );
        return FALSE;
    }
2130
    if (!(hrgn = PATH_PathToRegion( dc->path, GetPolyFillMode(dev->hdc)))) return FALSE;
2131
    ret = ExtSelectClipRgn( dev->hdc, hrgn, mode ) != ERROR;
2132 2133 2134 2135 2136
    if (ret)
    {
        free_gdi_path( dc->path );
        dc->path = NULL;
    }
2137 2138 2139 2140 2141
    /* FIXME: Should this function delete the path even if it failed? */
    DeleteObject( hrgn );
    return ret;
}

2142
BOOL nulldrv_FillPath( PHYSDEV dev )
2143 2144 2145
{
    DC *dc = get_nulldrv_dc( dev );

2146
    if (!dc->path)
2147 2148 2149 2150
    {
        SetLastError( ERROR_CAN_NOT_COMPLETE );
        return FALSE;
    }
2151
    if (!PATH_FillPath( dev->hdc, dc->path )) return FALSE;
2152
    /* FIXME: Should the path be emptied even if conversion failed? */
2153 2154
    free_gdi_path( dc->path );
    dc->path = NULL;
2155 2156 2157
    return TRUE;
}

2158
BOOL nulldrv_StrokeAndFillPath( PHYSDEV dev )
2159 2160 2161
{
    DC *dc = get_nulldrv_dc( dev );

2162
    if (!dc->path)
2163 2164 2165 2166
    {
        SetLastError( ERROR_CAN_NOT_COMPLETE );
        return FALSE;
    }
2167 2168 2169 2170
    if (!PATH_FillPath( dev->hdc, dc->path )) return FALSE;
    if (!PATH_StrokePath( dev->hdc, dc->path )) return FALSE;
    free_gdi_path( dc->path );
    dc->path = NULL;
2171 2172 2173
    return TRUE;
}

2174
BOOL nulldrv_StrokePath( PHYSDEV dev )
2175 2176 2177
{
    DC *dc = get_nulldrv_dc( dev );

2178
    if (!dc->path)
2179 2180 2181 2182
    {
        SetLastError( ERROR_CAN_NOT_COMPLETE );
        return FALSE;
    }
2183 2184 2185
    if (!PATH_StrokePath( dev->hdc, dc->path )) return FALSE;
    free_gdi_path( dc->path );
    dc->path = NULL;
2186 2187 2188
    return TRUE;
}

2189
BOOL nulldrv_FlattenPath( PHYSDEV dev )
2190 2191
{
    DC *dc = get_nulldrv_dc( dev );
2192
    struct gdi_path *path;
2193

2194
    if (!dc->path)
2195 2196 2197 2198
    {
        SetLastError( ERROR_CAN_NOT_COMPLETE );
        return FALSE;
    }
2199 2200 2201
    if (!(path = PATH_FlattenPath( dc->path ))) return FALSE;
    free_gdi_path( dc->path );
    dc->path = path;
2202
    return TRUE;
2203 2204
}

2205
BOOL nulldrv_WidenPath( PHYSDEV dev )
2206 2207
{
    DC *dc = get_nulldrv_dc( dev );
2208
    struct gdi_path *path;
2209

2210
    if (!dc->path)
2211 2212 2213 2214
    {
        SetLastError( ERROR_CAN_NOT_COMPLETE );
        return FALSE;
    }
2215
    if (!(path = PATH_WidenPath( dc ))) return FALSE;
2216 2217
    free_gdi_path( dc->path );
    dc->path = path;
2218
    return TRUE;
2219
}
2220 2221 2222 2223 2224 2225

const struct gdi_dc_funcs path_driver =
{
    NULL,                               /* pAbortDoc */
    pathdrv_AbortPath,                  /* pAbortPath */
    NULL,                               /* pAlphaBlend */
2226 2227 2228
    pathdrv_AngleArc,                   /* pAngleArc */
    pathdrv_Arc,                        /* pArc */
    pathdrv_ArcTo,                      /* pArcTo */
2229
    pathdrv_BeginPath,                  /* pBeginPath */
2230
    NULL,                               /* pBlendImage */
2231
    pathdrv_Chord,                      /* pChord */
2232
    pathdrv_CloseFigure,                /* pCloseFigure */
2233 2234 2235 2236 2237
    NULL,                               /* pCreateCompatibleDC */
    pathdrv_CreateDC,                   /* pCreateDC */
    pathdrv_DeleteDC,                   /* pDeleteDC */
    NULL,                               /* pDeleteObject */
    NULL,                               /* pDeviceCapabilities */
2238
    pathdrv_Ellipse,                    /* pEllipse */
2239 2240 2241 2242 2243 2244 2245 2246 2247 2248
    NULL,                               /* pEndDoc */
    NULL,                               /* pEndPage */
    pathdrv_EndPath,                    /* pEndPath */
    NULL,                               /* pEnumFonts */
    NULL,                               /* pEnumICMProfiles */
    NULL,                               /* pExcludeClipRect */
    NULL,                               /* pExtDeviceMode */
    NULL,                               /* pExtEscape */
    NULL,                               /* pExtFloodFill */
    NULL,                               /* pExtSelectClipRgn */
2249
    pathdrv_ExtTextOut,                 /* pExtTextOut */
2250 2251 2252 2253 2254 2255 2256
    NULL,                               /* pFillPath */
    NULL,                               /* pFillRgn */
    NULL,                               /* pFlattenPath */
    NULL,                               /* pFontIsLinked */
    NULL,                               /* pFrameRgn */
    NULL,                               /* pGdiComment */
    NULL,                               /* pGdiRealizationInfo */
2257
    NULL,                               /* pGetBoundsRect */
2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278
    NULL,                               /* pGetCharABCWidths */
    NULL,                               /* pGetCharABCWidthsI */
    NULL,                               /* pGetCharWidth */
    NULL,                               /* pGetDeviceCaps */
    NULL,                               /* pGetDeviceGammaRamp */
    NULL,                               /* pGetFontData */
    NULL,                               /* pGetFontUnicodeRanges */
    NULL,                               /* pGetGlyphIndices */
    NULL,                               /* pGetGlyphOutline */
    NULL,                               /* pGetICMProfile */
    NULL,                               /* pGetImage */
    NULL,                               /* pGetKerningPairs */
    NULL,                               /* pGetNearestColor */
    NULL,                               /* pGetOutlineTextMetrics */
    NULL,                               /* pGetPixel */
    NULL,                               /* pGetSystemPaletteEntries */
    NULL,                               /* pGetTextCharsetInfo */
    NULL,                               /* pGetTextExtentExPoint */
    NULL,                               /* pGetTextExtentExPointI */
    NULL,                               /* pGetTextFace */
    NULL,                               /* pGetTextMetrics */
2279
    NULL,                               /* pGradientFill */
2280 2281
    NULL,                               /* pIntersectClipRect */
    NULL,                               /* pInvertRgn */
2282
    pathdrv_LineTo,                     /* pLineTo */
2283
    NULL,                               /* pModifyWorldTransform */
2284
    pathdrv_MoveTo,                     /* pMoveTo */
2285 2286 2287 2288 2289
    NULL,                               /* pOffsetClipRgn */
    NULL,                               /* pOffsetViewportOrg */
    NULL,                               /* pOffsetWindowOrg */
    NULL,                               /* pPaintRgn */
    NULL,                               /* pPatBlt */
2290
    pathdrv_Pie,                        /* pPie */
2291 2292 2293
    pathdrv_PolyBezier,                 /* pPolyBezier */
    pathdrv_PolyBezierTo,               /* pPolyBezierTo */
    pathdrv_PolyDraw,                   /* pPolyDraw */
2294
    pathdrv_PolyPolygon,                /* pPolyPolygon */
2295
    pathdrv_PolyPolyline,               /* pPolyPolyline */
2296
    pathdrv_Polygon,                    /* pPolygon */
2297 2298
    pathdrv_Polyline,                   /* pPolyline */
    pathdrv_PolylineTo,                 /* pPolylineTo */
2299 2300 2301
    NULL,                               /* pPutImage */
    NULL,                               /* pRealizeDefaultPalette */
    NULL,                               /* pRealizePalette */
2302
    pathdrv_Rectangle,                  /* pRectangle */
2303 2304
    NULL,                               /* pResetDC */
    NULL,                               /* pRestoreDC */
2305
    pathdrv_RoundRect,                  /* pRoundRect */
2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348
    NULL,                               /* pSaveDC */
    NULL,                               /* pScaleViewportExt */
    NULL,                               /* pScaleWindowExt */
    NULL,                               /* pSelectBitmap */
    NULL,                               /* pSelectBrush */
    NULL,                               /* pSelectClipPath */
    NULL,                               /* pSelectFont */
    NULL,                               /* pSelectPalette */
    NULL,                               /* pSelectPen */
    NULL,                               /* pSetArcDirection */
    NULL,                               /* pSetBkColor */
    NULL,                               /* pSetBkMode */
    NULL,                               /* pSetDCBrushColor */
    NULL,                               /* pSetDCPenColor */
    NULL,                               /* pSetDIBColorTable */
    NULL,                               /* pSetDIBitsToDevice */
    NULL,                               /* pSetDeviceClipping */
    NULL,                               /* pSetDeviceGammaRamp */
    NULL,                               /* pSetLayout */
    NULL,                               /* pSetMapMode */
    NULL,                               /* pSetMapperFlags */
    NULL,                               /* pSetPixel */
    NULL,                               /* pSetPolyFillMode */
    NULL,                               /* pSetROP2 */
    NULL,                               /* pSetRelAbs */
    NULL,                               /* pSetStretchBltMode */
    NULL,                               /* pSetTextAlign */
    NULL,                               /* pSetTextCharacterExtra */
    NULL,                               /* pSetTextColor */
    NULL,                               /* pSetTextJustification */
    NULL,                               /* pSetViewportExt */
    NULL,                               /* pSetViewportOrg */
    NULL,                               /* pSetWindowExt */
    NULL,                               /* pSetWindowOrg */
    NULL,                               /* pSetWorldTransform */
    NULL,                               /* pStartDoc */
    NULL,                               /* pStartPage */
    NULL,                               /* pStretchBlt */
    NULL,                               /* pStretchDIBits */
    NULL,                               /* pStrokeAndFillPath */
    NULL,                               /* pStrokePath */
    NULL,                               /* pUnrealizePalette */
    NULL,                               /* pWidenPath */
2349
    NULL,                               /* wine_get_wgl_driver */
2350
    GDI_PRIORITY_PATH_DRV               /* priority */
2351
};