gdiplus: Move some Beziers helpers to gdiplus.c to use them for graphicspath.
[wine] / dlls / gdiplus / graphics.c
1 /*
2  * Copyright (C) 2007 Google (Evan Stade)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include <stdarg.h>
20 #include <math.h>
21 #include <limits.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
27 #include "wine/unicode.h"
28
29 #define COBJMACROS
30 #include "objbase.h"
31 #include "ocidl.h"
32 #include "olectl.h"
33 #include "ole2.h"
34
35 #include "winreg.h"
36 #include "shlwapi.h"
37
38 #include "gdiplus.h"
39 #include "gdiplus_private.h"
40 #include "wine/debug.h"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
43
44 /* looks-right constants */
45 #define ANCHOR_WIDTH (2.0)
46 #define MAX_ITERS (50)
47
48 /* Converts angle (in degrees) to x/y coordinates */
49 static void deg2xy(REAL angle, REAL x_0, REAL y_0, REAL *x, REAL *y)
50 {
51     REAL radAngle, hypotenuse;
52
53     radAngle = deg2rad(angle);
54     hypotenuse = 50.0; /* arbitrary */
55
56     *x = x_0 + cos(radAngle) * hypotenuse;
57     *y = y_0 + sin(radAngle) * hypotenuse;
58 }
59
60 /* Converts from gdiplus path point type to gdi path point type. */
61 static BYTE convert_path_point_type(BYTE type)
62 {
63     BYTE ret;
64
65     switch(type & PathPointTypePathTypeMask){
66         case PathPointTypeBezier:
67             ret = PT_BEZIERTO;
68             break;
69         case PathPointTypeLine:
70             ret = PT_LINETO;
71             break;
72         case PathPointTypeStart:
73             ret = PT_MOVETO;
74             break;
75         default:
76             ERR("Bad point type\n");
77             return 0;
78     }
79
80     if(type & PathPointTypeCloseSubpath)
81         ret |= PT_CLOSEFIGURE;
82
83     return ret;
84 }
85
86 static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
87 {
88     HPEN gdipen;
89     REAL width;
90     INT save_state = SaveDC(graphics->hdc), i, numdashes;
91     GpPointF pt[2];
92     DWORD dash_array[MAX_DASHLEN];
93
94     EndPath(graphics->hdc);
95
96     if(pen->unit == UnitPixel){
97         width = pen->width;
98     }
99     else{
100         /* Get an estimate for the amount the pen width is affected by the world
101          * transform. (This is similar to what some of the wine drivers do.) */
102         pt[0].X = 0.0;
103         pt[0].Y = 0.0;
104         pt[1].X = 1.0;
105         pt[1].Y = 1.0;
106         GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
107         width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
108                      (pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
109
110         width *= pen->width * convert_unit(graphics->hdc,
111                               pen->unit == UnitWorld ? graphics->unit : pen->unit);
112     }
113
114     if(pen->dash == DashStyleCustom){
115         numdashes = min(pen->numdashes, MAX_DASHLEN);
116
117         TRACE("dashes are: ");
118         for(i = 0; i < numdashes; i++){
119             dash_array[i] = roundr(width * pen->dashes[i]);
120             TRACE("%d, ", dash_array[i]);
121         }
122         TRACE("\n and the pen style is %x\n", pen->style);
123
124         gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb,
125                               numdashes, dash_array);
126     }
127     else
128         gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, 0, NULL);
129
130     SelectObject(graphics->hdc, gdipen);
131
132     return save_state;
133 }
134
135 static void restore_dc(GpGraphics *graphics, INT state)
136 {
137     DeleteObject(SelectObject(graphics->hdc, GetStockObject(NULL_PEN)));
138     RestoreDC(graphics->hdc, state);
139 }
140
141 /* This helper applies all the changes that the points listed in ptf need in
142  * order to be drawn on the device context.  In the end, this should include at
143  * least:
144  *  -scaling by page unit
145  *  -applying world transformation
146  *  -converting from float to int
147  * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
148  * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
149  * gdi to draw, and these functions would irreparably mess with line widths.
150  */
151 static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
152     GpPointF *ptf, INT count)
153 {
154     REAL unitscale;
155     GpMatrix *matrix;
156     int i;
157
158     unitscale = convert_unit(graphics->hdc, graphics->unit);
159
160     /* apply page scale */
161     if(graphics->unit != UnitDisplay)
162         unitscale *= graphics->scale;
163
164     GdipCloneMatrix(graphics->worldtrans, &matrix);
165     GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
166     GdipTransformMatrixPoints(matrix, ptf, count);
167     GdipDeleteMatrix(matrix);
168
169     for(i = 0; i < count; i++){
170         pti[i].x = roundr(ptf[i].X);
171         pti[i].y = roundr(ptf[i].Y);
172     }
173 }
174
175 /* GdipDrawPie/GdipFillPie helper function */
176 static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width,
177     REAL height, REAL startAngle, REAL sweepAngle)
178 {
179     GpPointF ptf[4];
180     POINT pti[4];
181
182     ptf[0].X = x;
183     ptf[0].Y = y;
184     ptf[1].X = x + width;
185     ptf[1].Y = y + height;
186
187     deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y);
188     deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y);
189
190     transform_and_round_points(graphics, pti, ptf, 4);
191
192     Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x,
193         pti[2].y, pti[3].x, pti[3].y);
194 }
195
196 /* Draws the linecap the specified color and size on the hdc.  The linecap is in
197  * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
198  * should not be called on an hdc that has a path you care about. */
199 static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
200     const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
201 {
202     HGDIOBJ oldbrush = NULL, oldpen = NULL;
203     GpMatrix *matrix = NULL;
204     HBRUSH brush = NULL;
205     HPEN pen = NULL;
206     PointF ptf[4], *custptf = NULL;
207     POINT pt[4], *custpt = NULL;
208     BYTE *tp = NULL;
209     REAL theta, dsmall, dbig, dx, dy = 0.0;
210     INT i, count;
211     LOGBRUSH lb;
212     BOOL customstroke;
213
214     if((x1 == x2) && (y1 == y2))
215         return;
216
217     theta = gdiplus_atan2(y2 - y1, x2 - x1);
218
219     customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
220     if(!customstroke){
221         brush = CreateSolidBrush(color);
222         lb.lbStyle = BS_SOLID;
223         lb.lbColor = color;
224         lb.lbHatch = 0;
225         pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
226                            PS_JOIN_MITER, 1, &lb, 0,
227                            NULL);
228         oldbrush = SelectObject(graphics->hdc, brush);
229         oldpen = SelectObject(graphics->hdc, pen);
230     }
231
232     switch(cap){
233         case LineCapFlat:
234             break;
235         case LineCapSquare:
236         case LineCapSquareAnchor:
237         case LineCapDiamondAnchor:
238             size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0;
239             if(cap == LineCapDiamondAnchor){
240                 dsmall = cos(theta + M_PI_2) * size;
241                 dbig = sin(theta + M_PI_2) * size;
242             }
243             else{
244                 dsmall = cos(theta + M_PI_4) * size;
245                 dbig = sin(theta + M_PI_4) * size;
246             }
247
248             ptf[0].X = x2 - dsmall;
249             ptf[1].X = x2 + dbig;
250
251             ptf[0].Y = y2 - dbig;
252             ptf[3].Y = y2 + dsmall;
253
254             ptf[1].Y = y2 - dsmall;
255             ptf[2].Y = y2 + dbig;
256
257             ptf[3].X = x2 - dbig;
258             ptf[2].X = x2 + dsmall;
259
260             transform_and_round_points(graphics, pt, ptf, 4);
261             Polygon(graphics->hdc, pt, 4);
262
263             break;
264         case LineCapArrowAnchor:
265             size = size * 4.0 / sqrt(3.0);
266
267             dx = cos(M_PI / 6.0 + theta) * size;
268             dy = sin(M_PI / 6.0 + theta) * size;
269
270             ptf[0].X = x2 - dx;
271             ptf[0].Y = y2 - dy;
272
273             dx = cos(- M_PI / 6.0 + theta) * size;
274             dy = sin(- M_PI / 6.0 + theta) * size;
275
276             ptf[1].X = x2 - dx;
277             ptf[1].Y = y2 - dy;
278
279             ptf[2].X = x2;
280             ptf[2].Y = y2;
281
282             transform_and_round_points(graphics, pt, ptf, 3);
283             Polygon(graphics->hdc, pt, 3);
284
285             break;
286         case LineCapRoundAnchor:
287             dx = dy = ANCHOR_WIDTH * size / 2.0;
288
289             ptf[0].X = x2 - dx;
290             ptf[0].Y = y2 - dy;
291             ptf[1].X = x2 + dx;
292             ptf[1].Y = y2 + dy;
293
294             transform_and_round_points(graphics, pt, ptf, 2);
295             Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
296
297             break;
298         case LineCapTriangle:
299             size = size / 2.0;
300             dx = cos(M_PI_2 + theta) * size;
301             dy = sin(M_PI_2 + theta) * size;
302
303             ptf[0].X = x2 - dx;
304             ptf[0].Y = y2 - dy;
305             ptf[1].X = x2 + dx;
306             ptf[1].Y = y2 + dy;
307
308             dx = cos(theta) * size;
309             dy = sin(theta) * size;
310
311             ptf[2].X = x2 + dx;
312             ptf[2].Y = y2 + dy;
313
314             transform_and_round_points(graphics, pt, ptf, 3);
315             Polygon(graphics->hdc, pt, 3);
316
317             break;
318         case LineCapRound:
319             dx = dy = size / 2.0;
320
321             ptf[0].X = x2 - dx;
322             ptf[0].Y = y2 - dy;
323             ptf[1].X = x2 + dx;
324             ptf[1].Y = y2 + dy;
325
326             dx = -cos(M_PI_2 + theta) * size;
327             dy = -sin(M_PI_2 + theta) * size;
328
329             ptf[2].X = x2 - dx;
330             ptf[2].Y = y2 - dy;
331             ptf[3].X = x2 + dx;
332             ptf[3].Y = y2 + dy;
333
334             transform_and_round_points(graphics, pt, ptf, 4);
335             Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x,
336                 pt[2].y, pt[3].x, pt[3].y);
337
338             break;
339         case LineCapCustom:
340             if(!custom)
341                 break;
342
343             count = custom->pathdata.Count;
344             custptf = GdipAlloc(count * sizeof(PointF));
345             custpt = GdipAlloc(count * sizeof(POINT));
346             tp = GdipAlloc(count);
347
348             if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok))
349                 goto custend;
350
351             memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF));
352
353             GdipScaleMatrix(matrix, size, size, MatrixOrderAppend);
354             GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2),
355                              MatrixOrderAppend);
356             GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend);
357             GdipTransformMatrixPoints(matrix, custptf, count);
358
359             transform_and_round_points(graphics, custpt, custptf, count);
360
361             for(i = 0; i < count; i++)
362                 tp[i] = convert_path_point_type(custom->pathdata.Types[i]);
363
364             if(custom->fill){
365                 BeginPath(graphics->hdc);
366                 PolyDraw(graphics->hdc, custpt, tp, count);
367                 EndPath(graphics->hdc);
368                 StrokeAndFillPath(graphics->hdc);
369             }
370             else
371                 PolyDraw(graphics->hdc, custpt, tp, count);
372
373 custend:
374             GdipFree(custptf);
375             GdipFree(custpt);
376             GdipFree(tp);
377             GdipDeleteMatrix(matrix);
378             break;
379         default:
380             break;
381     }
382
383     if(!customstroke){
384         SelectObject(graphics->hdc, oldbrush);
385         SelectObject(graphics->hdc, oldpen);
386         DeleteObject(brush);
387         DeleteObject(pen);
388     }
389 }
390
391 /* Shortens the line by the given percent by changing x2, y2.
392  * If percent is > 1.0 then the line will change direction.
393  * If percent is negative it can lengthen the line. */
394 static void shorten_line_percent(REAL x1, REAL  y1, REAL *x2, REAL *y2, REAL percent)
395 {
396     REAL dist, theta, dx, dy;
397
398     if((y1 == *y2) && (x1 == *x2))
399         return;
400
401     dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent;
402     theta = gdiplus_atan2((*y2 - y1), (*x2 - x1));
403     dx = cos(theta) * dist;
404     dy = sin(theta) * dist;
405
406     *x2 = *x2 + dx;
407     *y2 = *y2 + dy;
408 }
409
410 /* Shortens the line by the given amount by changing x2, y2.
411  * If the amount is greater than the distance, the line will become length 0.
412  * If the amount is negative, it can lengthen the line. */
413 static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt)
414 {
415     REAL dx, dy, percent;
416
417     dx = *x2 - x1;
418     dy = *y2 - y1;
419     if(dx == 0 && dy == 0)
420         return;
421
422     percent = amt / sqrt(dx * dx + dy * dy);
423     if(percent >= 1.0){
424         *x2 = x1;
425         *y2 = y1;
426         return;
427     }
428
429     shorten_line_percent(x1, y1, x2, y2, percent);
430 }
431
432 /* Draws lines between the given points, and if caps is true then draws an endcap
433  * at the end of the last line. */
434 static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen,
435     GDIPCONST GpPointF * pt, INT count, BOOL caps)
436 {
437     POINT *pti = NULL;
438     GpPointF *ptcopy = NULL;
439     GpStatus status = GenericError;
440
441     if(!count)
442         return Ok;
443
444     pti = GdipAlloc(count * sizeof(POINT));
445     ptcopy = GdipAlloc(count * sizeof(GpPointF));
446
447     if(!pti || !ptcopy){
448         status = OutOfMemory;
449         goto end;
450     }
451
452     memcpy(ptcopy, pt, count * sizeof(GpPointF));
453
454     if(caps){
455         if(pen->endcap == LineCapArrowAnchor)
456             shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
457                              &ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width);
458         else if((pen->endcap == LineCapCustom) && pen->customend)
459             shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
460                              &ptcopy[count-1].X, &ptcopy[count-1].Y,
461                              pen->customend->inset * pen->width);
462
463         if(pen->startcap == LineCapArrowAnchor)
464             shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
465                              &ptcopy[0].X, &ptcopy[0].Y, pen->width);
466         else if((pen->startcap == LineCapCustom) && pen->customstart)
467             shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
468                              &ptcopy[0].X, &ptcopy[0].Y,
469                              pen->customstart->inset * pen->width);
470
471         draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
472                  pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
473         draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
474                          pt[1].X, pt[1].Y, pt[0].X, pt[0].Y);
475     }
476
477     transform_and_round_points(graphics, pti, ptcopy, count);
478
479     if(Polyline(graphics->hdc, pti, count))
480         status = Ok;
481
482 end:
483     GdipFree(pti);
484     GdipFree(ptcopy);
485
486     return status;
487 }
488
489 /* Conducts a linear search to find the bezier points that will back off
490  * the endpoint of the curve by a distance of amt. Linear search works
491  * better than binary in this case because there are multiple solutions,
492  * and binary searches often find a bad one. I don't think this is what
493  * Windows does but short of rendering the bezier without GDI's help it's
494  * the best we can do. If rev then work from the start of the passed points
495  * instead of the end. */
496 static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev)
497 {
498     GpPointF origpt[4];
499     REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0;
500     INT i, first = 0, second = 1, third = 2, fourth = 3;
501
502     if(rev){
503         first = 3;
504         second = 2;
505         third = 1;
506         fourth = 0;
507     }
508
509     origx = pt[fourth].X;
510     origy = pt[fourth].Y;
511     memcpy(origpt, pt, sizeof(GpPointF) * 4);
512
513     for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){
514         /* reset bezier points to original values */
515         memcpy(pt, origpt, sizeof(GpPointF) * 4);
516         /* Perform magic on bezier points. Order is important here.*/
517         shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
518         shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
519         shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
520         shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent);
521         shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
522         shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
523
524         dx = pt[fourth].X - origx;
525         dy = pt[fourth].Y - origy;
526
527         diff = sqrt(dx * dx + dy * dy);
528         percent += 0.0005 * amt;
529     }
530 }
531
532 /* Draws bezier curves between given points, and if caps is true then draws an
533  * endcap at the end of the last line. */
534 static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
535     GDIPCONST GpPointF * pt, INT count, BOOL caps)
536 {
537     POINT *pti;
538     GpPointF *ptcopy;
539     GpStatus status = GenericError;
540
541     if(!count)
542         return Ok;
543
544     pti = GdipAlloc(count * sizeof(POINT));
545     ptcopy = GdipAlloc(count * sizeof(GpPointF));
546
547     if(!pti || !ptcopy){
548         status = OutOfMemory;
549         goto end;
550     }
551
552     memcpy(ptcopy, pt, count * sizeof(GpPointF));
553
554     if(caps){
555         if(pen->endcap == LineCapArrowAnchor)
556             shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
557         else if((pen->endcap == LineCapCustom) && pen->customend)
558             shorten_bezier_amt(&ptcopy[count-4], pen->width * pen->customend->inset,
559                                FALSE);
560
561         if(pen->startcap == LineCapArrowAnchor)
562             shorten_bezier_amt(ptcopy, pen->width, TRUE);
563         else if((pen->startcap == LineCapCustom) && pen->customstart)
564             shorten_bezier_amt(ptcopy, pen->width * pen->customstart->inset, TRUE);
565
566         /* the direction of the line cap is parallel to the direction at the
567          * end of the bezier (which, if it has been shortened, is not the same
568          * as the direction from pt[count-2] to pt[count-1]) */
569         draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
570             pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
571             pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
572             pt[count - 1].X, pt[count - 1].Y);
573
574         draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
575             pt[0].X - (ptcopy[0].X - ptcopy[1].X),
576             pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
577     }
578
579     transform_and_round_points(graphics, pti, ptcopy, count);
580
581     PolyBezier(graphics->hdc, pti, count);
582
583     status = Ok;
584
585 end:
586     GdipFree(pti);
587     GdipFree(ptcopy);
588
589     return status;
590 }
591
592 /* Draws a combination of bezier curves and lines between points. */
593 static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
594     GDIPCONST BYTE * types, INT count, BOOL caps)
595 {
596     POINT *pti = GdipAlloc(count * sizeof(POINT));
597     BYTE *tp = GdipAlloc(count);
598     GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
599     INT i, j;
600     GpStatus status = GenericError;
601
602     if(!count){
603         status = Ok;
604         goto end;
605     }
606     if(!pti || !tp || !ptcopy){
607         status = OutOfMemory;
608         goto end;
609     }
610
611     for(i = 1; i < count; i++){
612         if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
613             if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
614                 || !(types[i + 1] & PathPointTypeBezier)){
615                 ERR("Bad bezier points\n");
616                 goto end;
617             }
618             i += 2;
619         }
620     }
621
622     memcpy(ptcopy, pt, count * sizeof(GpPointF));
623
624     /* If we are drawing caps, go through the points and adjust them accordingly,
625      * and draw the caps. */
626     if(caps){
627         switch(types[count - 1] & PathPointTypePathTypeMask){
628             case PathPointTypeBezier:
629                 if(pen->endcap == LineCapArrowAnchor)
630                     shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
631                 else if((pen->endcap == LineCapCustom) && pen->customend)
632                     shorten_bezier_amt(&ptcopy[count - 4],
633                                        pen->width * pen->customend->inset, FALSE);
634
635                 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
636                     pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
637                     pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
638                     pt[count - 1].X, pt[count - 1].Y);
639
640                 break;
641             case PathPointTypeLine:
642                 if(pen->endcap == LineCapArrowAnchor)
643                     shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
644                                      &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
645                                      pen->width);
646                 else if((pen->endcap == LineCapCustom) && pen->customend)
647                     shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
648                                      &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
649                                      pen->customend->inset * pen->width);
650
651                 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
652                          pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
653                          pt[count - 1].Y);
654
655                 break;
656             default:
657                 ERR("Bad path last point\n");
658                 goto end;
659         }
660
661         /* Find start of points */
662         for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
663             == PathPointTypeStart); j++);
664
665         switch(types[j] & PathPointTypePathTypeMask){
666             case PathPointTypeBezier:
667                 if(pen->startcap == LineCapArrowAnchor)
668                     shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
669                 else if((pen->startcap == LineCapCustom) && pen->customstart)
670                     shorten_bezier_amt(&ptcopy[j - 1],
671                                        pen->width * pen->customstart->inset, TRUE);
672
673                 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
674                     pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
675                     pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
676                     pt[j - 1].X, pt[j - 1].Y);
677
678                 break;
679             case PathPointTypeLine:
680                 if(pen->startcap == LineCapArrowAnchor)
681                     shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
682                                      &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
683                                      pen->width);
684                 else if((pen->startcap == LineCapCustom) && pen->customstart)
685                     shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
686                                      &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
687                                      pen->customstart->inset * pen->width);
688
689                 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
690                          pt[j].X, pt[j].Y, pt[j - 1].X,
691                          pt[j - 1].Y);
692
693                 break;
694             default:
695                 ERR("Bad path points\n");
696                 goto end;
697         }
698     }
699
700     transform_and_round_points(graphics, pti, ptcopy, count);
701
702     for(i = 0; i < count; i++){
703         tp[i] = convert_path_point_type(types[i]);
704     }
705
706     PolyDraw(graphics->hdc, pti, tp, count);
707
708     status = Ok;
709
710 end:
711     GdipFree(pti);
712     GdipFree(ptcopy);
713     GdipFree(tp);
714
715     return status;
716 }
717
718 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
719 {
720     return GdipCreateFromHDC2(hdc, NULL, graphics);
721 }
722
723 GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **graphics)
724 {
725     GpStatus retval;
726
727     if(hDevice != NULL) {
728         FIXME("Don't know how to hadle parameter hDevice\n");
729         return NotImplemented;
730     }
731
732     if(hdc == NULL)
733         return OutOfMemory;
734
735     if(graphics == NULL)
736         return InvalidParameter;
737
738     *graphics = GdipAlloc(sizeof(GpGraphics));
739     if(!*graphics)  return OutOfMemory;
740
741     if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
742         GdipFree(*graphics);
743         return retval;
744     }
745
746     (*graphics)->hdc = hdc;
747     (*graphics)->hwnd = NULL;
748     (*graphics)->smoothing = SmoothingModeDefault;
749     (*graphics)->compqual = CompositingQualityDefault;
750     (*graphics)->interpolation = InterpolationModeDefault;
751     (*graphics)->pixeloffset = PixelOffsetModeDefault;
752     (*graphics)->compmode = CompositingModeSourceOver;
753     (*graphics)->unit = UnitDisplay;
754     (*graphics)->scale = 1.0;
755
756     return Ok;
757 }
758
759 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
760 {
761     GpStatus ret;
762
763     if((ret = GdipCreateFromHDC(GetDC(hwnd), graphics)) != Ok)
764         return ret;
765
766     (*graphics)->hwnd = hwnd;
767
768     return Ok;
769 }
770
771 /* FIXME: no icm handling */
772 GpStatus WINGDIPAPI GdipCreateFromHWNDICM(HWND hwnd, GpGraphics **graphics)
773 {
774     return GdipCreateFromHWND(hwnd, graphics);
775 }
776
777 GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
778     GpMetafile **metafile)
779 {
780     static int calls;
781
782     if(!hemf || !metafile)
783         return InvalidParameter;
784
785     if(!(calls++))
786         FIXME("not implemented\n");
787
788     return NotImplemented;
789 }
790
791 GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
792     GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
793 {
794     IStream *stream = NULL;
795     UINT read;
796     BYTE* copy;
797     HENHMETAFILE hemf;
798     GpStatus retval = GenericError;
799
800     if(!hwmf || !metafile || !placeable)
801         return InvalidParameter;
802
803     *metafile = NULL;
804     read = GetMetaFileBitsEx(hwmf, 0, NULL);
805     if(!read)
806         return GenericError;
807     copy = GdipAlloc(read);
808     GetMetaFileBitsEx(hwmf, read, copy);
809
810     hemf = SetWinMetaFileBits(read, copy, NULL, NULL);
811     GdipFree(copy);
812
813     read = GetEnhMetaFileBits(hemf, 0, NULL);
814     copy = GdipAlloc(read);
815     GetEnhMetaFileBits(hemf, read, copy);
816     DeleteEnhMetaFile(hemf);
817
818     if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
819         ERR("could not make stream\n");
820         GdipFree(copy);
821         goto err;
822     }
823
824     *metafile = GdipAlloc(sizeof(GpMetafile));
825     if(!*metafile){
826         retval = OutOfMemory;
827         goto err;
828     }
829
830     if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
831         (LPVOID*) &((*metafile)->image.picture)) != S_OK)
832         goto err;
833
834
835     (*metafile)->image.type = ImageTypeMetafile;
836     (*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch);
837     (*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Right) / ((REAL) placeable->Inch);
838     (*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right
839                     - placeable->BoundingBox.Left)) / ((REAL) placeable->Inch);
840     (*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom
841                    - placeable->BoundingBox.Top)) / ((REAL) placeable->Inch);
842     (*metafile)->unit = UnitInch;
843
844     if(delete)
845         DeleteMetaFile(hwmf);
846
847     return Ok;
848
849 err:
850     GdipFree(*metafile);
851     IStream_Release(stream);
852     return retval;
853 }
854
855 GpStatus WINGDIPAPI GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR *file,
856     GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
857 {
858     HMETAFILE hmf = GetMetaFileW(file);
859
860     TRACE("(%s, %p, %p)\n", debugstr_w(file), placeable, metafile);
861
862     if(!hmf) return InvalidParameter;
863
864     return GdipCreateMetafileFromWmf(hmf, TRUE, placeable, metafile);
865 }
866
867 GpStatus WINGDIPAPI GdipCreateStreamOnFile(GDIPCONST WCHAR * filename,
868     UINT access, IStream **stream)
869 {
870     DWORD dwMode;
871     HRESULT ret;
872
873     if(!stream || !filename)
874         return InvalidParameter;
875
876     if(access & GENERIC_WRITE)
877         dwMode = STGM_SHARE_DENY_WRITE | STGM_WRITE | STGM_CREATE;
878     else if(access & GENERIC_READ)
879         dwMode = STGM_SHARE_DENY_WRITE | STGM_READ | STGM_FAILIFTHERE;
880     else
881         return InvalidParameter;
882
883     ret = SHCreateStreamOnFileW(filename, dwMode, stream);
884
885     return hresult_to_status(ret);
886 }
887
888 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
889 {
890     if(!graphics) return InvalidParameter;
891     if(graphics->hwnd)
892         ReleaseDC(graphics->hwnd, graphics->hdc);
893
894     GdipDeleteMatrix(graphics->worldtrans);
895     HeapFree(GetProcessHeap(), 0, graphics);
896
897     return Ok;
898 }
899
900 GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
901     REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
902 {
903     INT save_state, num_pts;
904     GpPointF points[MAX_ARC_PTS];
905     GpStatus retval;
906
907     if(!graphics || !pen || width <= 0 || height <= 0)
908         return InvalidParameter;
909
910     num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
911
912     save_state = prepare_dc(graphics, pen);
913
914     retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
915
916     restore_dc(graphics, save_state);
917
918     return retval;
919 }
920
921 GpStatus WINGDIPAPI GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x,
922     INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
923 {
924     return GdipDrawArc(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
925 }
926
927 GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
928     REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
929 {
930     INT save_state;
931     GpPointF pt[4];
932     GpStatus retval;
933
934     if(!graphics || !pen)
935         return InvalidParameter;
936
937     pt[0].X = x1;
938     pt[0].Y = y1;
939     pt[1].X = x2;
940     pt[1].Y = y2;
941     pt[2].X = x3;
942     pt[2].Y = y3;
943     pt[3].X = x4;
944     pt[3].Y = y4;
945
946     save_state = prepare_dc(graphics, pen);
947
948     retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
949
950     restore_dc(graphics, save_state);
951
952     return retval;
953 }
954
955 GpStatus WINGDIPAPI GdipDrawBezierI(GpGraphics *graphics, GpPen *pen, INT x1,
956     INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4)
957 {
958     INT save_state;
959     GpPointF pt[4];
960     GpStatus retval;
961
962     if(!graphics || !pen)
963         return InvalidParameter;
964
965     pt[0].X = x1;
966     pt[0].Y = y1;
967     pt[1].X = x2;
968     pt[1].Y = y2;
969     pt[2].X = x3;
970     pt[2].Y = y3;
971     pt[3].X = x4;
972     pt[3].Y = y4;
973
974     save_state = prepare_dc(graphics, pen);
975
976     retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
977
978     restore_dc(graphics, save_state);
979
980     return retval;
981 }
982
983 GpStatus WINGDIPAPI GdipDrawBeziers(GpGraphics *graphics, GpPen *pen,
984     GDIPCONST GpPointF *points, INT count)
985 {
986     INT i;
987     GpStatus ret;
988
989     if(!graphics || !pen || !points || (count <= 0))
990         return InvalidParameter;
991
992     for(i = 0; i < floor(count / 4); i++){
993         ret = GdipDrawBezier(graphics, pen,
994                              points[4*i].X, points[4*i].Y,
995                              points[4*i + 1].X, points[4*i + 1].Y,
996                              points[4*i + 2].X, points[4*i + 2].Y,
997                              points[4*i + 3].X, points[4*i + 3].Y);
998         if(ret != Ok)
999             return ret;
1000     }
1001
1002     return Ok;
1003 }
1004
1005 GpStatus WINGDIPAPI GdipDrawBeziersI(GpGraphics *graphics, GpPen *pen,
1006     GDIPCONST GpPoint *points, INT count)
1007 {
1008     GpPointF *pts;
1009     GpStatus ret;
1010     INT i;
1011
1012     if(!graphics || !pen || !points || (count <= 0))
1013         return InvalidParameter;
1014
1015     pts = GdipAlloc(sizeof(GpPointF) * count);
1016     if(!pts)
1017         return OutOfMemory;
1018
1019     for(i = 0; i < count; i++){
1020         pts[i].X = (REAL)points[i].X;
1021         pts[i].Y = (REAL)points[i].Y;
1022     }
1023
1024     ret = GdipDrawBeziers(graphics,pen,pts,count);
1025
1026     GdipFree(pts);
1027
1028     return ret;
1029 }
1030
1031 GpStatus WINGDIPAPI GdipDrawClosedCurve(GpGraphics *graphics, GpPen *pen,
1032     GDIPCONST GpPointF *points, INT count)
1033 {
1034     return GdipDrawClosedCurve2(graphics, pen, points, count, 1.0);
1035 }
1036
1037 GpStatus WINGDIPAPI GdipDrawClosedCurveI(GpGraphics *graphics, GpPen *pen,
1038     GDIPCONST GpPoint *points, INT count)
1039 {
1040     return GdipDrawClosedCurve2I(graphics, pen, points, count, 1.0);
1041 }
1042
1043 GpStatus WINGDIPAPI GdipDrawClosedCurve2(GpGraphics *graphics, GpPen *pen,
1044     GDIPCONST GpPointF *points, INT count, REAL tension)
1045 {
1046     GpPointF *ptf;
1047     GpStatus stat;
1048
1049     if(!graphics || !pen || !points || count <= 0)
1050         return InvalidParameter;
1051
1052     /* make a full points copy.. */
1053     ptf = GdipAlloc(sizeof(GpPointF)*(count+1));
1054     if(!ptf)
1055         return OutOfMemory;
1056     memcpy(ptf, points, sizeof(GpPointF)*count);
1057
1058     /* ..and add a first point as a last one */
1059     ptf[count] = ptf[0];
1060
1061     stat = GdipDrawCurve2(graphics, pen, ptf, count + 1, tension);
1062
1063     GdipFree(ptf);
1064
1065     return stat;
1066 }
1067
1068 GpStatus WINGDIPAPI GdipDrawClosedCurve2I(GpGraphics *graphics, GpPen *pen,
1069     GDIPCONST GpPoint *points, INT count, REAL tension)
1070 {
1071     GpPointF *ptf;
1072     GpStatus stat;
1073     INT i;
1074
1075     if(!points || count <= 0)
1076         return InvalidParameter;
1077
1078     ptf = GdipAlloc(sizeof(GpPointF)*count);
1079     if(!ptf)
1080         return OutOfMemory;
1081
1082     for(i = 0; i < count; i++){
1083         ptf[i].X = (REAL)points[i].X;
1084         ptf[i].Y = (REAL)points[i].Y;
1085     }
1086
1087     stat = GdipDrawClosedCurve2(graphics, pen, ptf, count, tension);
1088
1089     GdipFree(ptf);
1090
1091     return stat;
1092 }
1093
1094 GpStatus WINGDIPAPI GdipDrawCurve(GpGraphics *graphics, GpPen *pen,
1095     GDIPCONST GpPointF *points, INT count)
1096 {
1097     return GdipDrawCurve2(graphics,pen,points,count,1.0);
1098 }
1099
1100 GpStatus WINGDIPAPI GdipDrawCurveI(GpGraphics *graphics, GpPen *pen,
1101     GDIPCONST GpPoint *points, INT count)
1102 {
1103     GpPointF *pointsF;
1104     GpStatus ret;
1105     INT i;
1106
1107     if(!points || count <= 0)
1108         return InvalidParameter;
1109
1110     pointsF = GdipAlloc(sizeof(GpPointF)*count);
1111     if(!pointsF)
1112         return OutOfMemory;
1113
1114     for(i = 0; i < count; i++){
1115         pointsF[i].X = (REAL)points[i].X;
1116         pointsF[i].Y = (REAL)points[i].Y;
1117     }
1118
1119     ret = GdipDrawCurve(graphics,pen,pointsF,count);
1120     GdipFree(pointsF);
1121
1122     return ret;
1123 }
1124
1125 /* Approximates cardinal spline with Bezier curves. */
1126 GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
1127     GDIPCONST GpPointF *points, INT count, REAL tension)
1128 {
1129     /* PolyBezier expects count*3-2 points. */
1130     INT i, len_pt = count*3-2, save_state;
1131     GpPointF *pt;
1132     REAL x1, x2, y1, y2;
1133     GpStatus retval;
1134
1135     if(!graphics || !pen)
1136         return InvalidParameter;
1137
1138     pt = GdipAlloc(len_pt * sizeof(GpPointF));
1139     tension = tension * TENSION_CONST;
1140
1141     calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
1142         tension, &x1, &y1);
1143
1144     pt[0].X = points[0].X;
1145     pt[0].Y = points[0].Y;
1146     pt[1].X = x1;
1147     pt[1].Y = y1;
1148
1149     for(i = 0; i < count-2; i++){
1150         calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
1151
1152         pt[3*i+2].X = x1;
1153         pt[3*i+2].Y = y1;
1154         pt[3*i+3].X = points[i+1].X;
1155         pt[3*i+3].Y = points[i+1].Y;
1156         pt[3*i+4].X = x2;
1157         pt[3*i+4].Y = y2;
1158     }
1159
1160     calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
1161         points[count-2].X, points[count-2].Y, tension, &x1, &y1);
1162
1163     pt[len_pt-2].X = x1;
1164     pt[len_pt-2].Y = y1;
1165     pt[len_pt-1].X = points[count-1].X;
1166     pt[len_pt-1].Y = points[count-1].Y;
1167
1168     save_state = prepare_dc(graphics, pen);
1169
1170     retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
1171
1172     GdipFree(pt);
1173     restore_dc(graphics, save_state);
1174
1175     return retval;
1176 }
1177
1178 GpStatus WINGDIPAPI GdipDrawCurve2I(GpGraphics *graphics, GpPen *pen,
1179     GDIPCONST GpPoint *points, INT count, REAL tension)
1180 {
1181     GpPointF *pointsF;
1182     GpStatus ret;
1183     INT i;
1184
1185     if(!points || count <= 0)
1186         return InvalidParameter;
1187
1188     pointsF = GdipAlloc(sizeof(GpPointF)*count);
1189     if(!pointsF)
1190         return OutOfMemory;
1191
1192     for(i = 0; i < count; i++){
1193         pointsF[i].X = (REAL)points[i].X;
1194         pointsF[i].Y = (REAL)points[i].Y;
1195     }
1196
1197     ret = GdipDrawCurve2(graphics,pen,pointsF,count,tension);
1198     GdipFree(pointsF);
1199
1200     return ret;
1201 }
1202
1203 GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics *graphics, GpPen *pen, REAL x,
1204     REAL y, REAL width, REAL height)
1205 {
1206     INT save_state;
1207     GpPointF ptf[2];
1208     POINT pti[2];
1209
1210     if(!graphics || !pen)
1211         return InvalidParameter;
1212
1213     ptf[0].X = x;
1214     ptf[0].Y = y;
1215     ptf[1].X = x + width;
1216     ptf[1].Y = y + height;
1217
1218     save_state = prepare_dc(graphics, pen);
1219     SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1220
1221     transform_and_round_points(graphics, pti, ptf, 2);
1222
1223     Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
1224
1225     restore_dc(graphics, save_state);
1226
1227     return Ok;
1228 }
1229
1230 GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics *graphics, GpPen *pen, INT x,
1231     INT y, INT width, INT height)
1232 {
1233     return GdipDrawEllipse(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1234 }
1235
1236
1237 GpStatus WINGDIPAPI GdipDrawImage(GpGraphics *graphics, GpImage *image, REAL x, REAL y)
1238 {
1239     /* IPicture::Render uses LONG coords */
1240     return GdipDrawImageI(graphics,image,roundr(x),roundr(y));
1241 }
1242
1243 GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x,
1244     INT y)
1245 {
1246     UINT width, height, srcw, srch;
1247
1248     if(!graphics || !image)
1249         return InvalidParameter;
1250
1251     GdipGetImageWidth(image, &width);
1252     GdipGetImageHeight(image, &height);
1253
1254     srcw = width * (((REAL) INCH_HIMETRIC) /
1255             ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX)));
1256     srch = height * (((REAL) INCH_HIMETRIC) /
1257             ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY)));
1258
1259     if(image->type != ImageTypeMetafile){
1260         y += height;
1261         height *= -1;
1262     }
1263
1264     IPicture_Render(image->picture, graphics->hdc, x, y, width, height,
1265                     0, 0, srcw, srch, NULL);
1266
1267     return Ok;
1268 }
1269
1270 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1271 GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
1272      GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
1273      REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
1274      DrawImageAbort callback, VOID * callbackData)
1275 {
1276     GpPointF ptf[3];
1277     POINT pti[3];
1278     REAL dx, dy;
1279
1280     TRACE("%p %p %p %d %f %f %f %f %d %p %p %p\n", graphics, image, points, count,
1281           srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
1282           callbackData);
1283
1284     if(!graphics || !image || !points || count != 3)
1285          return InvalidParameter;
1286
1287     if(srcUnit == UnitInch)
1288         dx = dy = (REAL) INCH_HIMETRIC;
1289     else if(srcUnit == UnitPixel){
1290         dx = ((REAL) INCH_HIMETRIC) /
1291              ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
1292         dy = ((REAL) INCH_HIMETRIC) /
1293              ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
1294     }
1295     else
1296         return NotImplemented;
1297
1298     memcpy(ptf, points, 3 * sizeof(GpPointF));
1299     transform_and_round_points(graphics, pti, ptf, 3);
1300
1301     /* IPicture renders bitmaps with the y-axis reversed
1302      * FIXME: flipping for unknown image type might not be correct. */
1303     if(image->type != ImageTypeMetafile){
1304         INT temp;
1305         temp = pti[0].y;
1306         pti[0].y = pti[2].y;
1307         pti[2].y = temp;
1308     }
1309
1310     if(IPicture_Render(image->picture, graphics->hdc,
1311         pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
1312         srcx * dx, srcy * dy,
1313         srcwidth * dx, srcheight * dy,
1314         NULL) != S_OK){
1315         if(callback)
1316             callback(callbackData);
1317         return GenericError;
1318     }
1319
1320     return Ok;
1321 }
1322
1323 GpStatus WINGDIPAPI GdipDrawImagePointsRectI(GpGraphics *graphics, GpImage *image,
1324      GDIPCONST GpPoint *points, INT count, INT srcx, INT srcy, INT srcwidth,
1325      INT srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
1326      DrawImageAbort callback, VOID * callbackData)
1327 {
1328     GpPointF pointsF[3];
1329     INT i;
1330
1331     if(!points || count!=3)
1332         return InvalidParameter;
1333
1334     for(i = 0; i < count; i++){
1335         pointsF[i].X = (REAL)points[i].X;
1336         pointsF[i].Y = (REAL)points[i].Y;
1337     }
1338
1339     return GdipDrawImagePointsRect(graphics, image, pointsF, count, (REAL)srcx, (REAL)srcy,
1340                                    (REAL)srcwidth, (REAL)srcheight, srcUnit, imageAttributes,
1341                                    callback, callbackData);
1342 }
1343
1344 GpStatus WINGDIPAPI GdipDrawImageRectRect(GpGraphics *graphics, GpImage *image,
1345     REAL dstx, REAL dsty, REAL dstwidth, REAL dstheight, REAL srcx, REAL srcy,
1346     REAL srcwidth, REAL srcheight, GpUnit srcUnit,
1347     GDIPCONST GpImageAttributes* imageattr, DrawImageAbort callback,
1348     VOID * callbackData)
1349 {
1350     GpPointF points[3];
1351
1352     points[0].X = dstx;
1353     points[0].Y = dsty;
1354     points[1].X = dstx + dstwidth;
1355     points[1].Y = dsty;
1356     points[2].X = dstx;
1357     points[2].Y = dsty + dstheight;
1358
1359     return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
1360                srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
1361 }
1362
1363 GpStatus WINGDIPAPI GdipDrawImageRectRectI(GpGraphics *graphics, GpImage *image,
1364         INT dstx, INT dsty, INT dstwidth, INT dstheight, INT srcx, INT srcy,
1365         INT srcwidth, INT srcheight, GpUnit srcUnit,
1366         GDIPCONST GpImageAttributes* imageAttributes, DrawImageAbort callback,
1367         VOID * callbackData)
1368 {
1369    GpPointF points[3];
1370
1371     points[0].X = dstx;
1372     points[0].Y = dsty;
1373     points[1].X = dstx + dstwidth;
1374     points[1].Y = dsty;
1375     points[2].X = dstx;
1376     points[2].Y = dsty + dstheight;
1377
1378     return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
1379                srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
1380 }
1381
1382 GpStatus WINGDIPAPI GdipDrawImageRect(GpGraphics *graphics, GpImage *image,
1383     REAL x, REAL y, REAL width, REAL height)
1384 {
1385     RectF bounds;
1386     GpUnit unit;
1387     GpStatus ret;
1388
1389     if(!graphics || !image)
1390         return InvalidParameter;
1391
1392     ret = GdipGetImageBounds(image, &bounds, &unit);
1393     if(ret != Ok)
1394         return ret;
1395
1396     return GdipDrawImageRectRect(graphics, image, x, y, width, height,
1397                                  bounds.X, bounds.Y, bounds.Width, bounds.Height,
1398                                  unit, NULL, NULL, NULL);
1399 }
1400
1401 GpStatus WINGDIPAPI GdipDrawImageRectI(GpGraphics *graphics, GpImage *image,
1402     INT x, INT y, INT width, INT height)
1403 {
1404     return GdipDrawImageRect(graphics, image, (REAL)x, (REAL)y, (REAL)width, (REAL)height);
1405 }
1406
1407 GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1,
1408     REAL y1, REAL x2, REAL y2)
1409 {
1410     INT save_state;
1411     GpPointF pt[2];
1412     GpStatus retval;
1413
1414     if(!pen || !graphics)
1415         return InvalidParameter;
1416
1417     pt[0].X = x1;
1418     pt[0].Y = y1;
1419     pt[1].X = x2;
1420     pt[1].Y = y2;
1421
1422     save_state = prepare_dc(graphics, pen);
1423
1424     retval = draw_polyline(graphics, pen, pt, 2, TRUE);
1425
1426     restore_dc(graphics, save_state);
1427
1428     return retval;
1429 }
1430
1431 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
1432     INT y1, INT x2, INT y2)
1433 {
1434     INT save_state;
1435     GpPointF pt[2];
1436     GpStatus retval;
1437
1438     if(!pen || !graphics)
1439         return InvalidParameter;
1440
1441     pt[0].X = (REAL)x1;
1442     pt[0].Y = (REAL)y1;
1443     pt[1].X = (REAL)x2;
1444     pt[1].Y = (REAL)y2;
1445
1446     save_state = prepare_dc(graphics, pen);
1447
1448     retval = draw_polyline(graphics, pen, pt, 2, TRUE);
1449
1450     restore_dc(graphics, save_state);
1451
1452     return retval;
1453 }
1454
1455 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
1456     GpPointF *points, INT count)
1457 {
1458     INT save_state;
1459     GpStatus retval;
1460
1461     if(!pen || !graphics || (count < 2))
1462         return InvalidParameter;
1463
1464     save_state = prepare_dc(graphics, pen);
1465
1466     retval = draw_polyline(graphics, pen, points, count, TRUE);
1467
1468     restore_dc(graphics, save_state);
1469
1470     return retval;
1471 }
1472
1473 GpStatus WINGDIPAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, GDIPCONST
1474     GpPoint *points, INT count)
1475 {
1476     INT save_state;
1477     GpStatus retval;
1478     GpPointF *ptf = NULL;
1479     int i;
1480
1481     if(!pen || !graphics || (count < 2))
1482         return InvalidParameter;
1483
1484     ptf = GdipAlloc(count * sizeof(GpPointF));
1485     if(!ptf) return OutOfMemory;
1486
1487     for(i = 0; i < count; i ++){
1488         ptf[i].X = (REAL) points[i].X;
1489         ptf[i].Y = (REAL) points[i].Y;
1490     }
1491
1492     save_state = prepare_dc(graphics, pen);
1493
1494     retval = draw_polyline(graphics, pen, ptf, count, TRUE);
1495
1496     restore_dc(graphics, save_state);
1497
1498     GdipFree(ptf);
1499     return retval;
1500 }
1501
1502 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
1503 {
1504     INT save_state;
1505     GpStatus retval;
1506
1507     if(!pen || !graphics)
1508         return InvalidParameter;
1509
1510     save_state = prepare_dc(graphics, pen);
1511
1512     retval = draw_poly(graphics, pen, path->pathdata.Points,
1513                        path->pathdata.Types, path->pathdata.Count, TRUE);
1514
1515     restore_dc(graphics, save_state);
1516
1517     return retval;
1518 }
1519
1520 GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
1521     REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1522 {
1523     INT save_state;
1524
1525     if(!graphics || !pen)
1526         return InvalidParameter;
1527
1528     save_state = prepare_dc(graphics, pen);
1529     SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1530
1531     draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
1532
1533     restore_dc(graphics, save_state);
1534
1535     return Ok;
1536 }
1537
1538 GpStatus WINGDIPAPI GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x,
1539     INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
1540 {
1541     return GdipDrawPie(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
1542 }
1543
1544 GpStatus WINGDIPAPI GdipDrawRectangle(GpGraphics *graphics, GpPen *pen, REAL x,
1545     REAL y, REAL width, REAL height)
1546 {
1547     INT save_state;
1548     GpPointF ptf[4];
1549     POINT pti[4];
1550
1551     if(!pen || !graphics)
1552         return InvalidParameter;
1553
1554     ptf[0].X = x;
1555     ptf[0].Y = y;
1556     ptf[1].X = x + width;
1557     ptf[1].Y = y;
1558     ptf[2].X = x + width;
1559     ptf[2].Y = y + height;
1560     ptf[3].X = x;
1561     ptf[3].Y = y + height;
1562
1563     save_state = prepare_dc(graphics, pen);
1564     SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1565
1566     transform_and_round_points(graphics, pti, ptf, 4);
1567     Polygon(graphics->hdc, pti, 4);
1568
1569     restore_dc(graphics, save_state);
1570
1571     return Ok;
1572 }
1573
1574 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
1575     INT y, INT width, INT height)
1576 {
1577     return GdipDrawRectangle(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1578 }
1579
1580 GpStatus WINGDIPAPI GdipDrawRectangles(GpGraphics *graphics, GpPen *pen,
1581     GDIPCONST GpRectF* rects, INT count)
1582 {
1583     GpPointF *ptf;
1584     POINT *pti;
1585     INT save_state, i;
1586
1587     if(!graphics || !pen || !rects || count < 1)
1588         return InvalidParameter;
1589
1590     ptf = GdipAlloc(4 * count * sizeof(GpPointF));
1591     pti = GdipAlloc(4 * count * sizeof(POINT));
1592
1593     if(!ptf || !pti){
1594         GdipFree(ptf);
1595         GdipFree(pti);
1596         return OutOfMemory;
1597     }
1598
1599     for(i = 0; i < count; i++){
1600         ptf[4 * i + 3].X = ptf[4 * i].X = rects[i].X;
1601         ptf[4 * i + 1].Y = ptf[4 * i].Y = rects[i].Y;
1602         ptf[4 * i + 2].X = ptf[4 * i + 1].X = rects[i].X + rects[i].Width;
1603         ptf[4 * i + 3].Y = ptf[4 * i + 2].Y = rects[i].Y + rects[i].Height;
1604     }
1605
1606     save_state = prepare_dc(graphics, pen);
1607     SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1608
1609     transform_and_round_points(graphics, pti, ptf, 4 * count);
1610
1611     for(i = 0; i < count; i++)
1612         Polygon(graphics->hdc, &pti[4 * i], 4);
1613
1614     restore_dc(graphics, save_state);
1615
1616     GdipFree(ptf);
1617     GdipFree(pti);
1618
1619     return Ok;
1620 }
1621
1622 GpStatus WINGDIPAPI GdipDrawRectanglesI(GpGraphics *graphics, GpPen *pen,
1623     GDIPCONST GpRect* rects, INT count)
1624 {
1625     GpRectF *rectsF;
1626     GpStatus ret;
1627     INT i;
1628
1629     if(!rects || count<=0)
1630         return InvalidParameter;
1631
1632     rectsF = GdipAlloc(sizeof(GpRectF) * count);
1633     if(!rectsF)
1634         return OutOfMemory;
1635
1636     for(i = 0;i < count;i++){
1637         rectsF[i].X      = (REAL)rects[i].X;
1638         rectsF[i].Y      = (REAL)rects[i].Y;
1639         rectsF[i].Width  = (REAL)rects[i].Width;
1640         rectsF[i].Height = (REAL)rects[i].Height;
1641     }
1642
1643     ret = GdipDrawRectangles(graphics, pen, rectsF, count);
1644     GdipFree(rectsF);
1645
1646     return ret;
1647 }
1648
1649 GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string,
1650     INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect,
1651     GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush)
1652 {
1653     HRGN rgn = NULL;
1654     HFONT gdifont;
1655     LOGFONTW lfw;
1656     TEXTMETRICW textmet;
1657     GpPointF pt[2], rectcpy[4];
1658     POINT corners[4];
1659     WCHAR* stringdup;
1660     REAL angle, ang_cos, ang_sin, rel_width, rel_height;
1661     INT sum = 0, height = 0, fit, fitcpy, save_state, i, j, lret, nwidth,
1662         nheight;
1663     SIZE size;
1664     RECT drawcoord;
1665
1666     if(!graphics || !string || !font || !brush || !rect)
1667         return InvalidParameter;
1668
1669     if((brush->bt != BrushTypeSolidColor)){
1670         FIXME("not implemented for given parameters\n");
1671         return NotImplemented;
1672     }
1673
1674     if(format)
1675         TRACE("may be ignoring some format flags: attr %x\n", format->attr);
1676
1677     if(length == -1) length = lstrlenW(string);
1678
1679     stringdup = GdipAlloc(length * sizeof(WCHAR));
1680     if(!stringdup) return OutOfMemory;
1681
1682     save_state = SaveDC(graphics->hdc);
1683     SetBkMode(graphics->hdc, TRANSPARENT);
1684     SetTextColor(graphics->hdc, brush->lb.lbColor);
1685
1686     rectcpy[3].X = rectcpy[0].X = rect->X;
1687     rectcpy[1].Y = rectcpy[0].Y = rect->Y;
1688     rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width;
1689     rectcpy[3].Y = rectcpy[2].Y = rect->Y + rect->Height;
1690     transform_and_round_points(graphics, corners, rectcpy, 4);
1691
1692     if(roundr(rect->Width) == 0 && roundr(rect->Height) == 0){
1693         rel_width = rel_height = 1.0;
1694         nwidth = nheight = INT_MAX;
1695     }
1696     else{
1697         rel_width = sqrt((corners[1].x - corners[0].x) * (corners[1].x - corners[0].x) +
1698                          (corners[1].y - corners[0].y) * (corners[1].y - corners[0].y))
1699                          / rect->Width;
1700         rel_height = sqrt((corners[2].x - corners[1].x) * (corners[2].x - corners[1].x) +
1701                           (corners[2].y - corners[1].y) * (corners[2].y - corners[1].y))
1702                           / rect->Height;
1703
1704         nwidth = roundr(rel_width * rect->Width);
1705         nheight = roundr(rel_height * rect->Height);
1706         rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
1707         SelectClipRgn(graphics->hdc, rgn);
1708     }
1709
1710     /* Use gdi to find the font, then perform transformations on it (height,
1711      * width, angle). */
1712     SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
1713     GetTextMetricsW(graphics->hdc, &textmet);
1714     lfw = font->lfw;
1715
1716     lfw.lfHeight = roundr(((REAL)lfw.lfHeight) * rel_height);
1717     lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width);
1718
1719     pt[0].X = 0.0;
1720     pt[0].Y = 0.0;
1721     pt[1].X = 1.0;
1722     pt[1].Y = 0.0;
1723     GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
1724     angle = gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X));
1725     ang_cos = cos(angle);
1726     ang_sin = sin(angle);
1727     lfw.lfEscapement = lfw.lfOrientation = -roundr((angle / M_PI) * 1800.0);
1728
1729     gdifont = CreateFontIndirectW(&lfw);
1730     DeleteObject(SelectObject(graphics->hdc, CreateFontIndirectW(&lfw)));
1731
1732     for(i = 0, j = 0; i < length; i++){
1733         if(!isprintW(string[i]) && (string[i] != '\n'))
1734             continue;
1735
1736         stringdup[j] = string[i];
1737         j++;
1738     }
1739
1740     stringdup[j] = 0;
1741     length = j;
1742
1743     while(sum < length){
1744         drawcoord.left = corners[0].x + roundr(ang_sin * (REAL) height);
1745         drawcoord.top = corners[0].y + roundr(ang_cos * (REAL) height);
1746
1747         GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum,
1748                               nwidth, &fit, NULL, &size);
1749         fitcpy = fit;
1750
1751         if(fit == 0){
1752             DrawTextW(graphics->hdc, stringdup + sum, 1, &drawcoord, DT_NOCLIP |
1753                       DT_EXPANDTABS);
1754             break;
1755         }
1756
1757         for(lret = 0; lret < fit; lret++)
1758             if(*(stringdup + sum + lret) == '\n')
1759                 break;
1760
1761         /* Line break code (may look strange, but it imitates windows). */
1762         if(lret < fit)
1763             fit = lret;    /* this is not an off-by-one error */
1764         else if(fit < (length - sum)){
1765             if(*(stringdup + sum + fit) == ' ')
1766                 while(*(stringdup + sum + fit) == ' ')
1767                     fit++;
1768             else
1769                 while(*(stringdup + sum + fit - 1) != ' '){
1770                     fit--;
1771
1772                     if(*(stringdup + sum + fit) == '\t')
1773                         break;
1774
1775                     if(fit == 0){
1776                         fit = fitcpy;
1777                         break;
1778                     }
1779                 }
1780         }
1781         DrawTextW(graphics->hdc, stringdup + sum, min(length - sum, fit),
1782                   &drawcoord, DT_NOCLIP | DT_EXPANDTABS);
1783
1784         sum += fit + (lret < fitcpy ? 1 : 0);
1785         height += size.cy;
1786
1787         if(height > nheight)
1788             break;
1789
1790         /* Stop if this was a linewrap (but not if it was a linebreak). */
1791         if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
1792             break;
1793     }
1794
1795     GdipFree(stringdup);
1796     DeleteObject(rgn);
1797     DeleteObject(gdifont);
1798
1799     RestoreDC(graphics->hdc, save_state);
1800
1801     return Ok;
1802 }
1803
1804 GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x,
1805     REAL y, REAL width, REAL height)
1806 {
1807     INT save_state;
1808     GpPointF ptf[2];
1809     POINT pti[2];
1810
1811     if(!graphics || !brush)
1812         return InvalidParameter;
1813
1814     ptf[0].X = x;
1815     ptf[0].Y = y;
1816     ptf[1].X = x + width;
1817     ptf[1].Y = y + height;
1818
1819     save_state = SaveDC(graphics->hdc);
1820     EndPath(graphics->hdc);
1821     SelectObject(graphics->hdc, brush->gdibrush);
1822     SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
1823
1824     transform_and_round_points(graphics, pti, ptf, 2);
1825
1826     Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
1827
1828     RestoreDC(graphics->hdc, save_state);
1829
1830     return Ok;
1831 }
1832
1833 GpStatus WINGDIPAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x,
1834     INT y, INT width, INT height)
1835 {
1836     return GdipFillEllipse(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1837 }
1838
1839 GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
1840 {
1841     INT save_state;
1842     GpStatus retval;
1843
1844     if(!brush || !graphics || !path)
1845         return InvalidParameter;
1846
1847     save_state = SaveDC(graphics->hdc);
1848     EndPath(graphics->hdc);
1849     SelectObject(graphics->hdc, brush->gdibrush);
1850     SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
1851                                                                     : WINDING));
1852
1853     BeginPath(graphics->hdc);
1854     retval = draw_poly(graphics, NULL, path->pathdata.Points,
1855                        path->pathdata.Types, path->pathdata.Count, FALSE);
1856
1857     if(retval != Ok)
1858         goto end;
1859
1860     EndPath(graphics->hdc);
1861     FillPath(graphics->hdc);
1862
1863     retval = Ok;
1864
1865 end:
1866     RestoreDC(graphics->hdc, save_state);
1867
1868     return retval;
1869 }
1870
1871 GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
1872     REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1873 {
1874     INT save_state;
1875
1876     if(!graphics || !brush)
1877         return InvalidParameter;
1878
1879     save_state = SaveDC(graphics->hdc);
1880     EndPath(graphics->hdc);
1881     SelectObject(graphics->hdc, brush->gdibrush);
1882     SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
1883
1884     draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
1885
1886     RestoreDC(graphics->hdc, save_state);
1887
1888     return Ok;
1889 }
1890
1891 GpStatus WINGDIPAPI GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x,
1892     INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
1893 {
1894     return GdipFillPie(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
1895 }
1896
1897 GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush,
1898     GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)
1899 {
1900     INT save_state;
1901     GpPointF *ptf = NULL;
1902     POINT *pti = NULL;
1903     GpStatus retval = Ok;
1904
1905     if(!graphics || !brush || !points || !count)
1906         return InvalidParameter;
1907
1908     ptf = GdipAlloc(count * sizeof(GpPointF));
1909     pti = GdipAlloc(count * sizeof(POINT));
1910     if(!ptf || !pti){
1911         retval = OutOfMemory;
1912         goto end;
1913     }
1914
1915     memcpy(ptf, points, count * sizeof(GpPointF));
1916
1917     save_state = SaveDC(graphics->hdc);
1918     EndPath(graphics->hdc);
1919     SelectObject(graphics->hdc, brush->gdibrush);
1920     SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
1921     SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
1922                                                                   : WINDING));
1923
1924     transform_and_round_points(graphics, pti, ptf, count);
1925     Polygon(graphics->hdc, pti, count);
1926
1927     RestoreDC(graphics->hdc, save_state);
1928
1929 end:
1930     GdipFree(ptf);
1931     GdipFree(pti);
1932
1933     return retval;
1934 }
1935
1936 GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
1937     GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
1938 {
1939     INT save_state, i;
1940     GpPointF *ptf = NULL;
1941     POINT *pti = NULL;
1942     GpStatus retval = Ok;
1943
1944     if(!graphics || !brush || !points || !count)
1945         return InvalidParameter;
1946
1947     ptf = GdipAlloc(count * sizeof(GpPointF));
1948     pti = GdipAlloc(count * sizeof(POINT));
1949     if(!ptf || !pti){
1950         retval = OutOfMemory;
1951         goto end;
1952     }
1953
1954     for(i = 0; i < count; i ++){
1955         ptf[i].X = (REAL) points[i].X;
1956         ptf[i].Y = (REAL) points[i].Y;
1957     }
1958
1959     save_state = SaveDC(graphics->hdc);
1960     EndPath(graphics->hdc);
1961     SelectObject(graphics->hdc, brush->gdibrush);
1962     SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
1963     SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
1964                                                                   : WINDING));
1965
1966     transform_and_round_points(graphics, pti, ptf, count);
1967     Polygon(graphics->hdc, pti, count);
1968
1969     RestoreDC(graphics->hdc, save_state);
1970
1971 end:
1972     GdipFree(ptf);
1973     GdipFree(pti);
1974
1975     return retval;
1976 }
1977
1978 GpStatus WINGDIPAPI GdipFillPolygon2(GpGraphics *graphics, GpBrush *brush,
1979     GDIPCONST GpPointF *points, INT count)
1980 {
1981     return GdipFillPolygon(graphics, brush, points, count, FillModeAlternate);
1982 }
1983
1984 GpStatus WINGDIPAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush,
1985     GDIPCONST GpPoint *points, INT count)
1986 {
1987     return GdipFillPolygonI(graphics, brush, points, count, FillModeAlternate);
1988 }
1989
1990 GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics *graphics, GpBrush *brush,
1991     REAL x, REAL y, REAL width, REAL height)
1992 {
1993     INT save_state;
1994     GpPointF ptf[4];
1995     POINT pti[4];
1996
1997     if(!graphics || !brush)
1998         return InvalidParameter;
1999
2000     ptf[0].X = x;
2001     ptf[0].Y = y;
2002     ptf[1].X = x + width;
2003     ptf[1].Y = y;
2004     ptf[2].X = x + width;
2005     ptf[2].Y = y + height;
2006     ptf[3].X = x;
2007     ptf[3].Y = y + height;
2008
2009     save_state = SaveDC(graphics->hdc);
2010     EndPath(graphics->hdc);
2011     SelectObject(graphics->hdc, brush->gdibrush);
2012     SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
2013
2014     transform_and_round_points(graphics, pti, ptf, 4);
2015
2016     Polygon(graphics->hdc, pti, 4);
2017
2018     RestoreDC(graphics->hdc, save_state);
2019
2020     return Ok;
2021 }
2022
2023 GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush,
2024     INT x, INT y, INT width, INT height)
2025 {
2026     INT save_state;
2027     GpPointF ptf[4];
2028     POINT pti[4];
2029
2030     if(!graphics || !brush)
2031         return InvalidParameter;
2032
2033     ptf[0].X = x;
2034     ptf[0].Y = y;
2035     ptf[1].X = x + width;
2036     ptf[1].Y = y;
2037     ptf[2].X = x + width;
2038     ptf[2].Y = y + height;
2039     ptf[3].X = x;
2040     ptf[3].Y = y + height;
2041
2042     save_state = SaveDC(graphics->hdc);
2043     EndPath(graphics->hdc);
2044     SelectObject(graphics->hdc, brush->gdibrush);
2045     SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
2046
2047     transform_and_round_points(graphics, pti, ptf, 4);
2048
2049     Polygon(graphics->hdc, pti, 4);
2050
2051     RestoreDC(graphics->hdc, save_state);
2052
2053     return Ok;
2054 }
2055
2056 GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRectF *rects,
2057     INT count)
2058 {
2059     GpStatus ret;
2060     INT i;
2061
2062     if(!rects)
2063         return InvalidParameter;
2064
2065     for(i = 0; i < count; i++){
2066         ret = GdipFillRectangle(graphics, brush, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
2067         if(ret != Ok)   return ret;
2068     }
2069
2070     return Ok;
2071 }
2072
2073 GpStatus WINGDIPAPI GdipFillRectanglesI(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRect *rects,
2074     INT count)
2075 {
2076     GpRectF *rectsF;
2077     GpStatus ret;
2078     INT i;
2079
2080     if(!rects || count <= 0)
2081         return InvalidParameter;
2082
2083     rectsF = GdipAlloc(sizeof(GpRectF)*count);
2084     if(!rectsF)
2085         return OutOfMemory;
2086
2087     for(i = 0; i < count; i++){
2088         rectsF[i].X      = (REAL)rects[i].X;
2089         rectsF[i].Y      = (REAL)rects[i].Y;
2090         rectsF[i].X      = (REAL)rects[i].Width;
2091         rectsF[i].Height = (REAL)rects[i].Height;
2092     }
2093
2094     ret = GdipFillRectangles(graphics,brush,rectsF,count);
2095     GdipFree(rectsF);
2096
2097     return ret;
2098 }
2099
2100 GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
2101         GpRegion* region)
2102 {
2103     if (!(graphics && brush && region))
2104         return InvalidParameter;
2105
2106     FIXME("(%p, %p, %p): stub\n", graphics, brush, region);
2107
2108     return NotImplemented;
2109 }
2110
2111 GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention)
2112 {
2113     static int calls;
2114
2115     if(!graphics)
2116         return InvalidParameter;
2117
2118     if(!(calls++))
2119         FIXME("not implemented\n");
2120
2121     return NotImplemented;
2122 }
2123
2124 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
2125 GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics,
2126     CompositingMode *mode)
2127 {
2128     if(!graphics || !mode)
2129         return InvalidParameter;
2130
2131     *mode = graphics->compmode;
2132
2133     return Ok;
2134 }
2135
2136 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
2137 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
2138     CompositingQuality *quality)
2139 {
2140     if(!graphics || !quality)
2141         return InvalidParameter;
2142
2143     *quality = graphics->compqual;
2144
2145     return Ok;
2146 }
2147
2148 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
2149 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
2150     InterpolationMode *mode)
2151 {
2152     if(!graphics || !mode)
2153         return InvalidParameter;
2154
2155     *mode = graphics->interpolation;
2156
2157     return Ok;
2158 }
2159
2160 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
2161 {
2162     if(!graphics || !scale)
2163         return InvalidParameter;
2164
2165     *scale = graphics->scale;
2166
2167     return Ok;
2168 }
2169
2170 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
2171 {
2172     if(!graphics || !unit)
2173         return InvalidParameter;
2174
2175     *unit = graphics->unit;
2176
2177     return Ok;
2178 }
2179
2180 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
2181 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
2182     *mode)
2183 {
2184     if(!graphics || !mode)
2185         return InvalidParameter;
2186
2187     *mode = graphics->pixeloffset;
2188
2189     return Ok;
2190 }
2191
2192 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
2193 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
2194 {
2195     if(!graphics || !mode)
2196         return InvalidParameter;
2197
2198     *mode = graphics->smoothing;
2199
2200     return Ok;
2201 }
2202
2203 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
2204 GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics,
2205     TextRenderingHint *hint)
2206 {
2207     if(!graphics || !hint)
2208         return InvalidParameter;
2209
2210     *hint = graphics->texthint;
2211
2212     return Ok;
2213 }
2214
2215 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
2216 {
2217     if(!graphics || !matrix)
2218         return InvalidParameter;
2219
2220     *matrix = *graphics->worldtrans;
2221     return Ok;
2222 }
2223
2224 GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,
2225         GDIPCONST WCHAR* string, INT length, GDIPCONST GpFont* font,
2226         GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat *stringFormat,
2227         INT regionCount, GpRegion** regions)
2228 {
2229     if (!(graphics && string && font && layoutRect && stringFormat && regions))
2230         return InvalidParameter;
2231
2232     FIXME("stub: %p %s %d %p %p %p %d %p\n", graphics, debugstr_w(string),
2233             length, font, layoutRect, stringFormat, regionCount, regions);
2234
2235     return NotImplemented;
2236 }
2237
2238 /* Find the smallest rectangle that bounds the text when it is printed in rect
2239  * according to the format options listed in format. If rect has 0 width and
2240  * height, then just find the smallest rectangle that bounds the text when it's
2241  * printed at location (rect->X, rect-Y). */
2242 GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
2243     GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
2244     GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
2245     INT *codepointsfitted, INT *linesfilled)
2246 {
2247     HFONT oldfont;
2248     WCHAR* stringdup;
2249     INT sum = 0, height = 0, fit, fitcpy, max_width = 0, i, j, lret, nwidth,
2250         nheight;
2251     SIZE size;
2252
2253     if(!graphics || !string || !font || !rect)
2254         return InvalidParameter;
2255
2256     if(codepointsfitted || linesfilled){
2257         FIXME("not implemented for given parameters\n");
2258         return NotImplemented;
2259     }
2260
2261     if(format)
2262         TRACE("may be ignoring some format flags: attr %x\n", format->attr);
2263
2264     if(length == -1) length = lstrlenW(string);
2265
2266     stringdup = GdipAlloc(length * sizeof(WCHAR));
2267     if(!stringdup) return OutOfMemory;
2268
2269     oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
2270     nwidth = roundr(rect->Width);
2271     nheight = roundr(rect->Height);
2272
2273     if((nwidth == 0) && (nheight == 0))
2274         nwidth = nheight = INT_MAX;
2275
2276     for(i = 0, j = 0; i < length; i++){
2277         if(!isprintW(string[i]) && (string[i] != '\n'))
2278             continue;
2279
2280         stringdup[j] = string[i];
2281         j++;
2282     }
2283
2284     stringdup[j] = 0;
2285     length = j;
2286
2287     while(sum < length){
2288         GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum,
2289                               nwidth, &fit, NULL, &size);
2290         fitcpy = fit;
2291
2292         if(fit == 0)
2293             break;
2294
2295         for(lret = 0; lret < fit; lret++)
2296             if(*(stringdup + sum + lret) == '\n')
2297                 break;
2298
2299         /* Line break code (may look strange, but it imitates windows). */
2300         if(lret < fit)
2301             fit = lret;    /* this is not an off-by-one error */
2302         else if(fit < (length - sum)){
2303             if(*(stringdup + sum + fit) == ' ')
2304                 while(*(stringdup + sum + fit) == ' ')
2305                     fit++;
2306             else
2307                 while(*(stringdup + sum + fit - 1) != ' '){
2308                     fit--;
2309
2310                     if(*(stringdup + sum + fit) == '\t')
2311                         break;
2312
2313                     if(fit == 0){
2314                         fit = fitcpy;
2315                         break;
2316                     }
2317                 }
2318         }
2319
2320         GetTextExtentExPointW(graphics->hdc, stringdup + sum, fit,
2321                               nwidth, &j, NULL, &size);
2322
2323         sum += fit + (lret < fitcpy ? 1 : 0);
2324         height += size.cy;
2325         max_width = max(max_width, size.cx);
2326
2327         if(height > nheight)
2328             break;
2329
2330         /* Stop if this was a linewrap (but not if it was a linebreak). */
2331         if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
2332             break;
2333     }
2334
2335     bounds->X = rect->X;
2336     bounds->Y = rect->Y;
2337     bounds->Width = (REAL)max_width;
2338     bounds->Height = (REAL) min(height, nheight);
2339
2340     GdipFree(stringdup);
2341     DeleteObject(SelectObject(graphics->hdc, oldfont));
2342
2343     return Ok;
2344 }
2345
2346 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
2347 {
2348     static int calls;
2349
2350     if(!graphics)
2351         return InvalidParameter;
2352
2353     if(!(calls++))
2354         FIXME("graphics state not implemented\n");
2355
2356     return NotImplemented;
2357 }
2358
2359 GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
2360     GpMatrixOrder order)
2361 {
2362     if(!graphics)
2363         return InvalidParameter;
2364
2365     return GdipRotateMatrix(graphics->worldtrans, angle, order);
2366 }
2367
2368 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
2369 {
2370     static int calls;
2371
2372     if(!graphics || !state)
2373         return InvalidParameter;
2374
2375     if(!(calls++))
2376         FIXME("graphics state not implemented\n");
2377
2378     return NotImplemented;
2379 }
2380
2381 GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
2382     REAL sy, GpMatrixOrder order)
2383 {
2384     if(!graphics)
2385         return InvalidParameter;
2386
2387     return GdipScaleMatrix(graphics->worldtrans, sx, sy, order);
2388 }
2389
2390 GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
2391     CompositingMode mode)
2392 {
2393     if(!graphics)
2394         return InvalidParameter;
2395
2396     graphics->compmode = mode;
2397
2398     return Ok;
2399 }
2400
2401 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
2402     CompositingQuality quality)
2403 {
2404     if(!graphics)
2405         return InvalidParameter;
2406
2407     graphics->compqual = quality;
2408
2409     return Ok;
2410 }
2411
2412 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
2413     InterpolationMode mode)
2414 {
2415     if(!graphics)
2416         return InvalidParameter;
2417
2418     graphics->interpolation = mode;
2419
2420     return Ok;
2421 }
2422
2423 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
2424 {
2425     if(!graphics || (scale <= 0.0))
2426         return InvalidParameter;
2427
2428     graphics->scale = scale;
2429
2430     return Ok;
2431 }
2432
2433 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
2434 {
2435     if(!graphics || (unit == UnitWorld))
2436         return InvalidParameter;
2437
2438     graphics->unit = unit;
2439
2440     return Ok;
2441 }
2442
2443 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
2444     mode)
2445 {
2446     if(!graphics)
2447         return InvalidParameter;
2448
2449     graphics->pixeloffset = mode;
2450
2451     return Ok;
2452 }
2453
2454 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
2455 {
2456     if(!graphics)
2457         return InvalidParameter;
2458
2459     graphics->smoothing = mode;
2460
2461     return Ok;
2462 }
2463
2464 GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
2465     TextRenderingHint hint)
2466 {
2467     if(!graphics)
2468         return InvalidParameter;
2469
2470     graphics->texthint = hint;
2471
2472     return Ok;
2473 }
2474
2475 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
2476 {
2477     if(!graphics || !matrix)
2478         return InvalidParameter;
2479
2480     GdipDeleteMatrix(graphics->worldtrans);
2481     return GdipCloneMatrix(matrix, &graphics->worldtrans);
2482 }
2483
2484 GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
2485     REAL dy, GpMatrixOrder order)
2486 {
2487     if(!graphics)
2488         return InvalidParameter;
2489
2490     return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order);
2491 }
2492
2493 GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y,
2494                                      INT width, INT height,
2495                                      CombineMode combineMode)
2496 {
2497     static int calls;
2498
2499     if(!(calls++))
2500         FIXME("not implemented\n");
2501
2502     return NotImplemented;
2503 }
2504
2505 GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
2506                                      CombineMode combineMode)
2507 {
2508     static int calls;
2509
2510     if(!(calls++))
2511         FIXME("not implemented\n");
2512
2513     return NotImplemented;
2514 }
2515
2516 GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpGraphics *graphics,
2517     UINT limitDpi)
2518 {
2519     static int calls;
2520
2521     if(!(calls++))
2522         FIXME("not implemented\n");
2523
2524     return NotImplemented;
2525 }
2526
2527 GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points,
2528     INT count)
2529 {
2530     INT save_state;
2531     POINT *pti;
2532
2533     if(!graphics || !pen || count<=0)
2534         return InvalidParameter;
2535
2536     pti = GdipAlloc(sizeof(POINT) * count);
2537
2538     save_state = prepare_dc(graphics, pen);
2539     SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2540
2541     transform_and_round_points(graphics, pti, (GpPointF*)points, count);
2542     Polygon(graphics->hdc, pti, count);
2543
2544     restore_dc(graphics, save_state);
2545     GdipFree(pti);
2546
2547     return Ok;
2548 }
2549
2550 GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points,
2551     INT count)
2552 {
2553     GpStatus ret;
2554     GpPointF *ptf;
2555     INT i;
2556
2557     if(count<=0)    return InvalidParameter;
2558     ptf = GdipAlloc(sizeof(GpPointF) * count);
2559
2560     for(i = 0;i < count; i++){
2561         ptf[i].X = (REAL)points[i].X;
2562         ptf[i].Y = (REAL)points[i].Y;
2563     }
2564
2565     ret = GdipDrawPolygon(graphics,pen,ptf,count);
2566     GdipFree(ptf);
2567
2568     return ret;
2569 }
2570
2571 GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
2572 {
2573     if(!graphics || !dpi)
2574         return InvalidParameter;
2575
2576     *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
2577
2578     return Ok;
2579 }
2580
2581 GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
2582 {
2583     if(!graphics || !dpi)
2584         return InvalidParameter;
2585
2586     *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
2587
2588     return Ok;
2589 }
2590
2591 GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix,
2592     GpMatrixOrder order)
2593 {
2594     GpMatrix m;
2595     GpStatus ret;
2596
2597     if(!graphics || !matrix)
2598         return InvalidParameter;
2599
2600     m = *(graphics->worldtrans);
2601
2602     ret = GdipMultiplyMatrix(&m, (GpMatrix*)matrix, order);
2603     if(ret == Ok)
2604         *(graphics->worldtrans) = m;
2605
2606     return ret;
2607 }
2608
2609 GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
2610 {
2611     FIXME("(%p, %p): stub\n", graphics, hdc);
2612
2613     *hdc = NULL;
2614     return NotImplemented;
2615 }
2616
2617 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
2618 {
2619     FIXME("(%p, %p): stub\n", graphics, hdc);
2620
2621     return NotImplemented;
2622 }
2623
2624 GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
2625 {
2626    FIXME("(%p, %p): stub\n", graphics, region);
2627
2628    return NotImplemented;
2629 }
2630
2631 GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space,
2632                                         GpCoordinateSpace src_space, GpPointF *points, INT count)
2633 {
2634     FIXME("(%p, %d, %d, %p, %d): stub\n", graphics, dst_space, src_space, points, count);
2635
2636     return NotImplemented;
2637 }
2638
2639 GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space,
2640                                          GpCoordinateSpace src_space, GpPoint *points, INT count)
2641 {
2642     FIXME("(%p, %d, %d, %p, %d): stub\n", graphics, dst_space, src_space, points, count);
2643
2644     return NotImplemented;
2645 }