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