push 0c258732cb75565633c2f709ca58b227c9f8ae60
[wine/hacks.git] / dlls / gdiplus / graphics.c
blobc21e8916db59e74509a22e39a4a0c6f794b85567
1 /*
2 * Copyright (C) 2007 Google (Evan Stade)
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.
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.
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
19 #include <stdarg.h>
20 #include <math.h>
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winuser.h"
25 #include "wingdi.h"
27 #define COBJMACROS
28 #include "objbase.h"
29 #include "ocidl.h"
30 #include "olectl.h"
31 #include "ole2.h"
33 #include "gdiplus.h"
34 #include "gdiplus_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
39 /* looks-right constants */
40 #define TENSION_CONST (0.3)
41 #define ANCHOR_WIDTH (2.0)
42 #define MAX_ITERS (50)
44 /* Converts angle (in degrees) to x/y coordinates */
45 static void deg2xy(REAL angle, REAL x_0, REAL y_0, REAL *x, REAL *y)
47 REAL radAngle, hypotenuse;
49 radAngle = deg2rad(angle);
50 hypotenuse = 50.0; /* arbitrary */
52 *x = x_0 + cos(radAngle) * hypotenuse;
53 *y = y_0 + sin(radAngle) * hypotenuse;
56 /* Converts from gdiplus path point type to gdi path point type. */
57 static BYTE convert_path_point_type(BYTE type)
59 BYTE ret;
61 switch(type & PathPointTypePathTypeMask){
62 case PathPointTypeBezier:
63 ret = PT_BEZIERTO;
64 break;
65 case PathPointTypeLine:
66 ret = PT_LINETO;
67 break;
68 case PathPointTypeStart:
69 ret = PT_MOVETO;
70 break;
71 default:
72 ERR("Bad point type\n");
73 return 0;
76 if(type & PathPointTypeCloseSubpath)
77 ret |= PT_CLOSEFIGURE;
79 return ret;
82 static REAL convert_unit(HDC hdc, GpUnit unit)
84 switch(unit)
86 case UnitInch:
87 return (REAL) GetDeviceCaps(hdc, LOGPIXELSX);
88 case UnitPoint:
89 return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 72.0;
90 case UnitDocument:
91 return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 300.0;
92 case UnitMillimeter:
93 return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 25.4;
94 case UnitWorld:
95 ERR("cannot convert UnitWorld\n");
96 return 0.0;
97 case UnitPixel:
98 case UnitDisplay:
99 default:
100 return 1.0;
104 static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
106 HPEN gdipen;
107 REAL width;
108 INT save_state = SaveDC(graphics->hdc), i, numdashes;
109 GpPointF pt[2];
110 DWORD dash_array[MAX_DASHLEN];
112 EndPath(graphics->hdc);
114 /* Get an estimate for the amount the pen width is affected by the world
115 * transform. (This is similar to what some of the wine drivers do.) */
116 pt[0].X = 0.0;
117 pt[0].Y = 0.0;
118 pt[1].X = 1.0;
119 pt[1].Y = 1.0;
120 GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
121 width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
122 (pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
124 width *= pen->width * convert_unit(graphics->hdc,
125 pen->unit == UnitWorld ? graphics->unit : pen->unit);
127 if(pen->dash == DashStyleCustom){
128 numdashes = min(pen->numdashes, MAX_DASHLEN);
130 TRACE("dashes are: ");
131 for(i = 0; i < numdashes; i++){
132 dash_array[i] = roundr(width * pen->dashes[i]);
133 TRACE("%d, ", dash_array[i]);
135 TRACE("\n and the pen style is %x\n", pen->style);
137 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb,
138 numdashes, dash_array);
140 else
141 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, 0, NULL);
143 SelectObject(graphics->hdc, gdipen);
145 return save_state;
148 static void restore_dc(GpGraphics *graphics, INT state)
150 DeleteObject(SelectObject(graphics->hdc, GetStockObject(NULL_PEN)));
151 RestoreDC(graphics->hdc, state);
154 /* This helper applies all the changes that the points listed in ptf need in
155 * order to be drawn on the device context. In the end, this should include at
156 * least:
157 * -scaling by page unit
158 * -applying world transformation
159 * -converting from float to int
160 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
161 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
162 * gdi to draw, and these functions would irreparably mess with line widths.
164 static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
165 GpPointF *ptf, INT count)
167 REAL unitscale;
168 GpMatrix *matrix;
169 int i;
171 unitscale = convert_unit(graphics->hdc, graphics->unit);
173 /* apply page scale */
174 if(graphics->unit != UnitDisplay)
175 unitscale *= graphics->scale;
177 GdipCloneMatrix(graphics->worldtrans, &matrix);
178 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
179 GdipTransformMatrixPoints(matrix, ptf, count);
180 GdipDeleteMatrix(matrix);
182 for(i = 0; i < count; i++){
183 pti[i].x = roundr(ptf[i].X);
184 pti[i].y = roundr(ptf[i].Y);
188 /* GdipDrawPie/GdipFillPie helper function */
189 static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width,
190 REAL height, REAL startAngle, REAL sweepAngle)
192 GpPointF ptf[4];
193 POINT pti[4];
195 ptf[0].X = x;
196 ptf[0].Y = y;
197 ptf[1].X = x + width;
198 ptf[1].Y = y + height;
200 deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y);
201 deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y);
203 transform_and_round_points(graphics, pti, ptf, 4);
205 Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x,
206 pti[2].y, pti[3].x, pti[3].y);
209 /* GdipDrawCurve helper function.
210 * Calculates Bezier points from cardinal spline points. */
211 static void calc_curve_bezier(CONST GpPointF *pts, REAL tension, REAL *x1,
212 REAL *y1, REAL *x2, REAL *y2)
214 REAL xdiff, ydiff;
216 /* calculate tangent */
217 xdiff = pts[2].X - pts[0].X;
218 ydiff = pts[2].Y - pts[0].Y;
220 /* apply tangent to get control points */
221 *x1 = pts[1].X - tension * xdiff;
222 *y1 = pts[1].Y - tension * ydiff;
223 *x2 = pts[1].X + tension * xdiff;
224 *y2 = pts[1].Y + tension * ydiff;
227 /* GdipDrawCurve helper function.
228 * Calculates Bezier points from cardinal spline endpoints. */
229 static void calc_curve_bezier_endp(REAL xend, REAL yend, REAL xadj, REAL yadj,
230 REAL tension, REAL *x, REAL *y)
232 /* tangent at endpoints is the line from the endpoint to the adjacent point */
233 *x = roundr(tension * (xadj - xend) + xend);
234 *y = roundr(tension * (yadj - yend) + yend);
237 /* Draws the linecap the specified color and size on the hdc. The linecap is in
238 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
239 * should not be called on an hdc that has a path you care about. */
240 static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
241 const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
243 HGDIOBJ oldbrush = NULL, oldpen = NULL;
244 GpMatrix *matrix = NULL;
245 HBRUSH brush = NULL;
246 HPEN pen = NULL;
247 PointF ptf[4], *custptf = NULL;
248 POINT pt[4], *custpt = NULL;
249 BYTE *tp = NULL;
250 REAL theta, dsmall, dbig, dx, dy = 0.0;
251 INT i, count;
252 LOGBRUSH lb;
253 BOOL customstroke;
255 if((x1 == x2) && (y1 == y2))
256 return;
258 theta = gdiplus_atan2(y2 - y1, x2 - x1);
260 customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
261 if(!customstroke){
262 brush = CreateSolidBrush(color);
263 lb.lbStyle = BS_SOLID;
264 lb.lbColor = color;
265 lb.lbHatch = 0;
266 pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
267 PS_JOIN_MITER, 1, &lb, 0,
268 NULL);
269 oldbrush = SelectObject(graphics->hdc, brush);
270 oldpen = SelectObject(graphics->hdc, pen);
273 switch(cap){
274 case LineCapFlat:
275 break;
276 case LineCapSquare:
277 case LineCapSquareAnchor:
278 case LineCapDiamondAnchor:
279 size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0;
280 if(cap == LineCapDiamondAnchor){
281 dsmall = cos(theta + M_PI_2) * size;
282 dbig = sin(theta + M_PI_2) * size;
284 else{
285 dsmall = cos(theta + M_PI_4) * size;
286 dbig = sin(theta + M_PI_4) * size;
289 ptf[0].X = x2 - dsmall;
290 ptf[1].X = x2 + dbig;
292 ptf[0].Y = y2 - dbig;
293 ptf[3].Y = y2 + dsmall;
295 ptf[1].Y = y2 - dsmall;
296 ptf[2].Y = y2 + dbig;
298 ptf[3].X = x2 - dbig;
299 ptf[2].X = x2 + dsmall;
301 transform_and_round_points(graphics, pt, ptf, 4);
302 Polygon(graphics->hdc, pt, 4);
304 break;
305 case LineCapArrowAnchor:
306 size = size * 4.0 / sqrt(3.0);
308 dx = cos(M_PI / 6.0 + theta) * size;
309 dy = sin(M_PI / 6.0 + theta) * size;
311 ptf[0].X = x2 - dx;
312 ptf[0].Y = y2 - dy;
314 dx = cos(- M_PI / 6.0 + theta) * size;
315 dy = sin(- M_PI / 6.0 + theta) * size;
317 ptf[1].X = x2 - dx;
318 ptf[1].Y = y2 - dy;
320 ptf[2].X = x2;
321 ptf[2].Y = y2;
323 transform_and_round_points(graphics, pt, ptf, 3);
324 Polygon(graphics->hdc, pt, 3);
326 break;
327 case LineCapRoundAnchor:
328 dx = dy = ANCHOR_WIDTH * size / 2.0;
330 ptf[0].X = x2 - dx;
331 ptf[0].Y = y2 - dy;
332 ptf[1].X = x2 + dx;
333 ptf[1].Y = y2 + dy;
335 transform_and_round_points(graphics, pt, ptf, 2);
336 Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
338 break;
339 case LineCapTriangle:
340 size = size / 2.0;
341 dx = cos(M_PI_2 + theta) * size;
342 dy = sin(M_PI_2 + theta) * size;
344 ptf[0].X = x2 - dx;
345 ptf[0].Y = y2 - dy;
346 ptf[1].X = x2 + dx;
347 ptf[1].Y = y2 + dy;
349 dx = cos(theta) * size;
350 dy = sin(theta) * size;
352 ptf[2].X = x2 + dx;
353 ptf[2].Y = y2 + dy;
355 transform_and_round_points(graphics, pt, ptf, 3);
356 Polygon(graphics->hdc, pt, 3);
358 break;
359 case LineCapRound:
360 dx = dy = size / 2.0;
362 ptf[0].X = x2 - dx;
363 ptf[0].Y = y2 - dy;
364 ptf[1].X = x2 + dx;
365 ptf[1].Y = y2 + dy;
367 dx = -cos(M_PI_2 + theta) * size;
368 dy = -sin(M_PI_2 + theta) * size;
370 ptf[2].X = x2 - dx;
371 ptf[2].Y = y2 - dy;
372 ptf[3].X = x2 + dx;
373 ptf[3].Y = y2 + dy;
375 transform_and_round_points(graphics, pt, ptf, 4);
376 Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x,
377 pt[2].y, pt[3].x, pt[3].y);
379 break;
380 case LineCapCustom:
381 if(!custom)
382 break;
384 count = custom->pathdata.Count;
385 custptf = GdipAlloc(count * sizeof(PointF));
386 custpt = GdipAlloc(count * sizeof(POINT));
387 tp = GdipAlloc(count);
389 if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok))
390 goto custend;
392 memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF));
394 GdipScaleMatrix(matrix, size, size, MatrixOrderAppend);
395 GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2),
396 MatrixOrderAppend);
397 GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend);
398 GdipTransformMatrixPoints(matrix, custptf, count);
400 transform_and_round_points(graphics, custpt, custptf, count);
402 for(i = 0; i < count; i++)
403 tp[i] = convert_path_point_type(custom->pathdata.Types[i]);
405 if(custom->fill){
406 BeginPath(graphics->hdc);
407 PolyDraw(graphics->hdc, custpt, tp, count);
408 EndPath(graphics->hdc);
409 StrokeAndFillPath(graphics->hdc);
411 else
412 PolyDraw(graphics->hdc, custpt, tp, count);
414 custend:
415 GdipFree(custptf);
416 GdipFree(custpt);
417 GdipFree(tp);
418 GdipDeleteMatrix(matrix);
419 break;
420 default:
421 break;
424 if(!customstroke){
425 SelectObject(graphics->hdc, oldbrush);
426 SelectObject(graphics->hdc, oldpen);
427 DeleteObject(brush);
428 DeleteObject(pen);
432 /* Shortens the line by the given percent by changing x2, y2.
433 * If percent is > 1.0 then the line will change direction.
434 * If percent is negative it can lengthen the line. */
435 static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL percent)
437 REAL dist, theta, dx, dy;
439 if((y1 == *y2) && (x1 == *x2))
440 return;
442 dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent;
443 theta = gdiplus_atan2((*y2 - y1), (*x2 - x1));
444 dx = cos(theta) * dist;
445 dy = sin(theta) * dist;
447 *x2 = *x2 + dx;
448 *y2 = *y2 + dy;
451 /* Shortens the line by the given amount by changing x2, y2.
452 * If the amount is greater than the distance, the line will become length 0.
453 * If the amount is negative, it can lengthen the line. */
454 static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt)
456 REAL dx, dy, percent;
458 dx = *x2 - x1;
459 dy = *y2 - y1;
460 if(dx == 0 && dy == 0)
461 return;
463 percent = amt / sqrt(dx * dx + dy * dy);
464 if(percent >= 1.0){
465 *x2 = x1;
466 *y2 = y1;
467 return;
470 shorten_line_percent(x1, y1, x2, y2, percent);
473 /* Draws lines between the given points, and if caps is true then draws an endcap
474 * at the end of the last line. */
475 static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen,
476 GDIPCONST GpPointF * pt, INT count, BOOL caps)
478 POINT *pti = NULL;
479 GpPointF *ptcopy = NULL;
480 GpStatus status = GenericError;
482 if(!count)
483 return Ok;
485 pti = GdipAlloc(count * sizeof(POINT));
486 ptcopy = GdipAlloc(count * sizeof(GpPointF));
488 if(!pti || !ptcopy){
489 status = OutOfMemory;
490 goto end;
493 memcpy(ptcopy, pt, count * sizeof(GpPointF));
495 if(caps){
496 if(pen->endcap == LineCapArrowAnchor)
497 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
498 &ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width);
499 else if((pen->endcap == LineCapCustom) && pen->customend)
500 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
501 &ptcopy[count-1].X, &ptcopy[count-1].Y,
502 pen->customend->inset * pen->width);
504 if(pen->startcap == LineCapArrowAnchor)
505 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
506 &ptcopy[0].X, &ptcopy[0].Y, pen->width);
507 else if((pen->startcap == LineCapCustom) && pen->customstart)
508 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
509 &ptcopy[0].X, &ptcopy[0].Y,
510 pen->customend->inset * pen->width);
512 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
513 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
514 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
515 pt[1].X, pt[1].Y, pt[0].X, pt[0].Y);\
518 transform_and_round_points(graphics, pti, ptcopy, count);
520 Polyline(graphics->hdc, pti, count);
522 end:
523 GdipFree(pti);
524 GdipFree(ptcopy);
526 return status;
529 /* Conducts a linear search to find the bezier points that will back off
530 * the endpoint of the curve by a distance of amt. Linear search works
531 * better than binary in this case because there are multiple solutions,
532 * and binary searches often find a bad one. I don't think this is what
533 * Windows does but short of rendering the bezier without GDI's help it's
534 * the best we can do. If rev then work from the start of the passed points
535 * instead of the end. */
536 static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev)
538 GpPointF origpt[4];
539 REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0;
540 INT i, first = 0, second = 1, third = 2, fourth = 3;
542 if(rev){
543 first = 3;
544 second = 2;
545 third = 1;
546 fourth = 0;
549 origx = pt[fourth].X;
550 origy = pt[fourth].Y;
551 memcpy(origpt, pt, sizeof(GpPointF) * 4);
553 for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){
554 /* reset bezier points to original values */
555 memcpy(pt, origpt, sizeof(GpPointF) * 4);
556 /* Perform magic on bezier points. Order is important here.*/
557 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
558 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
559 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
560 shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent);
561 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
562 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
564 dx = pt[fourth].X - origx;
565 dy = pt[fourth].Y - origy;
567 diff = sqrt(dx * dx + dy * dy);
568 percent += 0.0005 * amt;
572 /* Draws bezier curves between given points, and if caps is true then draws an
573 * endcap at the end of the last line. */
574 static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
575 GDIPCONST GpPointF * pt, INT count, BOOL caps)
577 POINT *pti;
578 GpPointF *ptcopy;
579 GpStatus status = GenericError;
581 if(!count)
582 return Ok;
584 pti = GdipAlloc(count * sizeof(POINT));
585 ptcopy = GdipAlloc(count * sizeof(GpPointF));
587 if(!pti || !ptcopy){
588 status = OutOfMemory;
589 goto end;
592 memcpy(ptcopy, pt, count * sizeof(GpPointF));
594 if(caps){
595 if(pen->endcap == LineCapArrowAnchor)
596 shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
597 else if((pen->endcap == LineCapCustom) && pen->customend)
598 shorten_bezier_amt(&ptcopy[count-4], pen->width * pen->customend->inset,
599 FALSE);
601 if(pen->startcap == LineCapArrowAnchor)
602 shorten_bezier_amt(ptcopy, pen->width, TRUE);
603 else if((pen->startcap == LineCapCustom) && pen->customstart)
604 shorten_bezier_amt(ptcopy, pen->width * pen->customend->inset, TRUE);
606 /* the direction of the line cap is parallel to the direction at the
607 * end of the bezier (which, if it has been shortened, is not the same
608 * as the direction from pt[count-2] to pt[count-1]) */
609 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
610 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
611 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
612 pt[count - 1].X, pt[count - 1].Y);
614 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
615 pt[0].X - (ptcopy[0].X - ptcopy[1].X),
616 pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
619 transform_and_round_points(graphics, pti, ptcopy, count);
621 PolyBezier(graphics->hdc, pti, count);
623 status = Ok;
625 end:
626 GdipFree(pti);
627 GdipFree(ptcopy);
629 return status;
632 /* Draws a combination of bezier curves and lines between points. */
633 static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
634 GDIPCONST BYTE * types, INT count, BOOL caps)
636 POINT *pti = GdipAlloc(count * sizeof(POINT));
637 BYTE *tp = GdipAlloc(count);
638 GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
639 INT i, j;
640 GpStatus status = GenericError;
642 if(!count){
643 status = Ok;
644 goto end;
646 if(!pti || !tp || !ptcopy){
647 status = OutOfMemory;
648 goto end;
651 for(i = 1; i < count; i++){
652 if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
653 if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
654 || !(types[i + 1] & PathPointTypeBezier)){
655 ERR("Bad bezier points\n");
656 goto end;
658 i += 2;
662 memcpy(ptcopy, pt, count * sizeof(GpPointF));
664 /* If we are drawing caps, go through the points and adjust them accordingly,
665 * and draw the caps. */
666 if(caps){
667 switch(types[count - 1] & PathPointTypePathTypeMask){
668 case PathPointTypeBezier:
669 if(pen->endcap == LineCapArrowAnchor)
670 shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
671 else if((pen->endcap == LineCapCustom) && pen->customend)
672 shorten_bezier_amt(&ptcopy[count - 4],
673 pen->width * pen->customend->inset, FALSE);
675 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
676 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
677 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
678 pt[count - 1].X, pt[count - 1].Y);
680 break;
681 case PathPointTypeLine:
682 if(pen->endcap == LineCapArrowAnchor)
683 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
684 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
685 pen->width);
686 else if((pen->endcap == LineCapCustom) && pen->customend)
687 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
688 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
689 pen->customend->inset * pen->width);
691 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
692 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
693 pt[count - 1].Y);
695 break;
696 default:
697 ERR("Bad path last point\n");
698 goto end;
701 /* Find start of points */
702 for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
703 == PathPointTypeStart); j++);
705 switch(types[j] & PathPointTypePathTypeMask){
706 case PathPointTypeBezier:
707 if(pen->startcap == LineCapArrowAnchor)
708 shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
709 else if((pen->startcap == LineCapCustom) && pen->customstart)
710 shorten_bezier_amt(&ptcopy[j - 1],
711 pen->width * pen->customend->inset, TRUE);
713 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
714 pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
715 pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
716 pt[j - 1].X, pt[j - 1].Y);
718 break;
719 case PathPointTypeLine:
720 if(pen->startcap == LineCapArrowAnchor)
721 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
722 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
723 pen->width);
724 else if((pen->startcap == LineCapCustom) && pen->customstart)
725 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
726 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
727 pen->customstart->inset * pen->width);
729 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
730 pt[j].X, pt[j].Y, pt[j - 1].X,
731 pt[j - 1].Y);
733 break;
734 default:
735 ERR("Bad path points\n");
736 goto end;
740 transform_and_round_points(graphics, pti, ptcopy, count);
742 for(i = 0; i < count; i++){
743 tp[i] = convert_path_point_type(types[i]);
746 PolyDraw(graphics->hdc, pti, tp, count);
748 status = Ok;
750 end:
751 GdipFree(pti);
752 GdipFree(ptcopy);
753 GdipFree(tp);
755 return status;
758 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
760 GpStatus retval;
762 if(hdc == NULL)
763 return OutOfMemory;
765 if(graphics == NULL)
766 return InvalidParameter;
768 *graphics = GdipAlloc(sizeof(GpGraphics));
769 if(!*graphics) return OutOfMemory;
771 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
772 GdipFree(*graphics);
773 return retval;
776 (*graphics)->hdc = hdc;
777 (*graphics)->hwnd = NULL;
778 (*graphics)->smoothing = SmoothingModeDefault;
779 (*graphics)->compqual = CompositingQualityDefault;
780 (*graphics)->interpolation = InterpolationModeDefault;
781 (*graphics)->pixeloffset = PixelOffsetModeDefault;
782 (*graphics)->unit = UnitDisplay;
783 (*graphics)->scale = 1.0;
785 return Ok;
788 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
790 GpStatus ret;
792 if((ret = GdipCreateFromHDC(GetDC(hwnd), graphics)) != Ok)
793 return ret;
795 (*graphics)->hwnd = hwnd;
797 return Ok;
800 GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
801 GpMetafile **metafile)
803 static int calls;
805 if(!hemf || !metafile)
806 return InvalidParameter;
808 if(!(calls++))
809 FIXME("not implemented\n");
811 return NotImplemented;
814 GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
815 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
817 IStream *stream = NULL;
818 UINT read;
819 BYTE* copy;
820 HENHMETAFILE hemf;
821 GpStatus retval = GenericError;
823 if(!hwmf || !metafile || !placeable)
824 return InvalidParameter;
825 read = GetMetaFileBitsEx(hwmf, 0, NULL);
826 if(!read)
827 return GenericError;
828 copy = GdipAlloc(read);
829 GetMetaFileBitsEx(hwmf, read, copy);
831 hemf = SetWinMetaFileBits(read, copy, NULL, NULL);
832 GdipFree(copy);
834 read = GetEnhMetaFileBits(hemf, 0, NULL);
835 copy = GdipAlloc(read);
836 GetEnhMetaFileBits(hemf, read, copy);
837 DeleteEnhMetaFile(hemf);
839 if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
840 ERR("could not make stream\n");
841 goto end;
844 *metafile = GdipAlloc(sizeof(GpMetafile));
845 if(!*metafile){
846 retval = OutOfMemory;
847 goto end;
850 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
851 (LPVOID*) &((*metafile)->image.picture)) != S_OK){
852 GdipFree(*metafile);
853 goto end;
856 (*metafile)->image.type = ImageTypeMetafile;
857 (*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch);
858 (*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Right) / ((REAL) placeable->Inch);
859 (*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right
860 - placeable->BoundingBox.Left)) / ((REAL) placeable->Inch);
861 (*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom
862 - placeable->BoundingBox.Top)) / ((REAL) placeable->Inch);
863 (*metafile)->unit = UnitInch;
865 if(delete)
866 DeleteMetaFile(hwmf);
868 retval = Ok;
870 end:
871 IStream_Release(stream);
872 GdipFree(copy);
873 return retval;
876 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
878 if(!graphics) return InvalidParameter;
879 if(graphics->hwnd)
880 ReleaseDC(graphics->hwnd, graphics->hdc);
882 GdipDeleteMatrix(graphics->worldtrans);
883 HeapFree(GetProcessHeap(), 0, graphics);
885 return Ok;
888 GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
889 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
891 INT save_state, num_pts;
892 GpPointF points[MAX_ARC_PTS];
893 GpStatus retval;
895 if(!graphics || !pen)
896 return InvalidParameter;
898 num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
900 save_state = prepare_dc(graphics, pen);
902 retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
904 restore_dc(graphics, save_state);
906 return retval;
909 GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
910 REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
912 INT save_state;
913 GpPointF pt[4];
914 GpStatus retval;
916 if(!graphics || !pen)
917 return InvalidParameter;
919 pt[0].X = x1;
920 pt[0].Y = y1;
921 pt[1].X = x2;
922 pt[1].Y = y2;
923 pt[2].X = x3;
924 pt[2].Y = y3;
925 pt[3].X = x4;
926 pt[3].Y = y4;
928 save_state = prepare_dc(graphics, pen);
930 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
932 restore_dc(graphics, save_state);
934 return retval;
937 /* Approximates cardinal spline with Bezier curves. */
938 GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
939 GDIPCONST GpPointF *points, INT count, REAL tension)
941 /* PolyBezier expects count*3-2 points. */
942 INT i, len_pt = count*3-2, save_state;
943 GpPointF *pt;
944 REAL x1, x2, y1, y2;
945 GpStatus retval;
947 if(!graphics || !pen)
948 return InvalidParameter;
950 pt = GdipAlloc(len_pt * sizeof(GpPointF));
951 tension = tension * TENSION_CONST;
953 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
954 tension, &x1, &y1);
956 pt[0].X = points[0].X;
957 pt[0].Y = points[0].Y;
958 pt[1].X = x1;
959 pt[1].Y = y1;
961 for(i = 0; i < count-2; i++){
962 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
964 pt[3*i+2].X = x1;
965 pt[3*i+2].Y = y1;
966 pt[3*i+3].X = points[i+1].X;
967 pt[3*i+3].Y = points[i+1].Y;
968 pt[3*i+4].X = x2;
969 pt[3*i+4].Y = y2;
972 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
973 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
975 pt[len_pt-2].X = x1;
976 pt[len_pt-2].Y = y1;
977 pt[len_pt-1].X = points[count-1].X;
978 pt[len_pt-1].Y = points[count-1].Y;
980 save_state = prepare_dc(graphics, pen);
982 retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
984 GdipFree(pt);
985 restore_dc(graphics, save_state);
987 return retval;
990 /* FIXME: partially implemented */
991 GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
992 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
993 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
994 DrawImageAbort callback, VOID * callbackData)
996 GpPointF ptf[3];
997 POINT pti[3];
998 REAL dx, dy;
1000 TRACE("%p %p %p %d %f %f %f %f %d %p %p %p\n", graphics, image, points, count,
1001 srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
1002 callbackData);
1004 if(!graphics || !image || !points || !imageAttributes || count != 3)
1005 return InvalidParameter;
1007 if(srcUnit == UnitInch)
1008 dx = dy = (REAL) INCH_HIMETRIC;
1009 else if(srcUnit == UnitPixel){
1010 dx = ((REAL) INCH_HIMETRIC) /
1011 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
1012 dy = ((REAL) INCH_HIMETRIC) /
1013 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
1015 else
1016 return NotImplemented;
1018 memcpy(ptf, points, 3 * sizeof(GpPointF));
1019 transform_and_round_points(graphics, pti, ptf, 3);
1021 /* IPicture renders bitmaps with the y-axis reversed
1022 * FIXME: flipping for unknown image type might not be correct. */
1023 if(image->type != ImageTypeMetafile){
1024 INT temp;
1025 temp = pti[0].y;
1026 pti[0].y = pti[2].y;
1027 pti[2].y = temp;
1030 if(IPicture_Render(image->picture, graphics->hdc,
1031 pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
1032 srcx * dx, srcy * dy,
1033 srcwidth * dx, srcheight * dy,
1034 NULL) != S_OK){
1035 if(callback)
1036 callback(callbackData);
1037 return GenericError;
1040 return Ok;
1043 GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1,
1044 REAL y1, REAL x2, REAL y2)
1046 INT save_state;
1047 GpPointF pt[2];
1048 GpStatus retval;
1050 if(!pen || !graphics)
1051 return InvalidParameter;
1053 pt[0].X = x1;
1054 pt[0].Y = y1;
1055 pt[1].X = x2;
1056 pt[1].Y = y2;
1058 save_state = prepare_dc(graphics, pen);
1060 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
1062 restore_dc(graphics, save_state);
1064 return retval;
1067 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
1068 INT y1, INT x2, INT y2)
1070 INT save_state;
1071 GpPointF pt[2];
1072 GpStatus retval;
1074 if(!pen || !graphics)
1075 return InvalidParameter;
1077 pt[0].X = (REAL)x1;
1078 pt[0].Y = (REAL)y1;
1079 pt[1].X = (REAL)x2;
1080 pt[1].Y = (REAL)y2;
1082 save_state = prepare_dc(graphics, pen);
1084 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
1086 restore_dc(graphics, save_state);
1088 return retval;
1091 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
1092 GpPointF *points, INT count)
1094 INT save_state;
1095 GpStatus retval;
1097 if(!pen || !graphics || (count < 2))
1098 return InvalidParameter;
1100 save_state = prepare_dc(graphics, pen);
1102 retval = draw_polyline(graphics, pen, points, count, TRUE);
1104 restore_dc(graphics, save_state);
1106 return retval;
1109 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
1111 INT save_state;
1112 GpStatus retval;
1114 if(!pen || !graphics)
1115 return InvalidParameter;
1117 save_state = prepare_dc(graphics, pen);
1119 retval = draw_poly(graphics, pen, path->pathdata.Points,
1120 path->pathdata.Types, path->pathdata.Count, TRUE);
1122 restore_dc(graphics, save_state);
1124 return retval;
1127 GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
1128 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1130 INT save_state;
1132 if(!graphics || !pen)
1133 return InvalidParameter;
1135 save_state = prepare_dc(graphics, pen);
1136 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1138 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
1140 restore_dc(graphics, save_state);
1142 return Ok;
1145 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
1146 INT y, INT width, INT height)
1148 INT save_state;
1150 if(!pen || !graphics)
1151 return InvalidParameter;
1153 save_state = prepare_dc(graphics, pen);
1154 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1156 Rectangle(graphics->hdc, x, y, x + width, y + height);
1158 restore_dc(graphics, save_state);
1160 return Ok;
1163 GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
1165 INT save_state;
1166 GpStatus retval;
1168 if(!brush || !graphics || !path)
1169 return InvalidParameter;
1171 save_state = SaveDC(graphics->hdc);
1172 EndPath(graphics->hdc);
1173 SelectObject(graphics->hdc, brush->gdibrush);
1174 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
1175 : WINDING));
1177 BeginPath(graphics->hdc);
1178 retval = draw_poly(graphics, NULL, path->pathdata.Points,
1179 path->pathdata.Types, path->pathdata.Count, FALSE);
1181 if(retval != Ok)
1182 goto end;
1184 EndPath(graphics->hdc);
1185 FillPath(graphics->hdc);
1187 retval = Ok;
1189 end:
1190 RestoreDC(graphics->hdc, save_state);
1192 return retval;
1195 GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
1196 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1198 INT save_state;
1200 if(!graphics || !brush)
1201 return InvalidParameter;
1203 save_state = SaveDC(graphics->hdc);
1204 EndPath(graphics->hdc);
1205 SelectObject(graphics->hdc, brush->gdibrush);
1206 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
1208 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
1210 RestoreDC(graphics->hdc, save_state);
1212 return Ok;
1215 GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush,
1216 GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)
1218 INT save_state;
1219 GpPointF *ptf = NULL;
1220 POINT *pti = NULL;
1221 GpStatus retval = Ok;
1223 if(!graphics || !brush || !points || !count)
1224 return InvalidParameter;
1226 ptf = GdipAlloc(count * sizeof(GpPointF));
1227 pti = GdipAlloc(count * sizeof(POINT));
1228 if(!ptf || !pti){
1229 retval = OutOfMemory;
1230 goto end;
1233 memcpy(ptf, points, count * sizeof(GpPointF));
1235 save_state = SaveDC(graphics->hdc);
1236 EndPath(graphics->hdc);
1237 SelectObject(graphics->hdc, brush->gdibrush);
1238 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
1239 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
1240 : WINDING));
1242 transform_and_round_points(graphics, pti, ptf, count);
1243 Polygon(graphics->hdc, pti, count);
1245 RestoreDC(graphics->hdc, save_state);
1247 end:
1248 GdipFree(ptf);
1249 GdipFree(pti);
1251 return retval;
1254 GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
1255 GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
1257 INT save_state, i;
1258 GpPointF *ptf = NULL;
1259 POINT *pti = NULL;
1260 GpStatus retval = Ok;
1262 if(!graphics || !brush || !points || !count)
1263 return InvalidParameter;
1265 ptf = GdipAlloc(count * sizeof(GpPointF));
1266 pti = GdipAlloc(count * sizeof(POINT));
1267 if(!ptf || !pti){
1268 retval = OutOfMemory;
1269 goto end;
1272 for(i = 0; i < count; i ++){
1273 ptf[i].X = (REAL) points[i].X;
1274 ptf[i].Y = (REAL) points[i].Y;
1277 save_state = SaveDC(graphics->hdc);
1278 EndPath(graphics->hdc);
1279 SelectObject(graphics->hdc, brush->gdibrush);
1280 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
1281 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
1282 : WINDING));
1284 transform_and_round_points(graphics, pti, ptf, count);
1285 Polygon(graphics->hdc, pti, count);
1287 RestoreDC(graphics->hdc, save_state);
1289 end:
1290 GdipFree(ptf);
1291 GdipFree(pti);
1293 return retval;
1296 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
1297 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
1298 CompositingQuality *quality)
1300 if(!graphics || !quality)
1301 return InvalidParameter;
1303 *quality = graphics->compqual;
1305 return Ok;
1308 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
1309 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
1310 InterpolationMode *mode)
1312 if(!graphics || !mode)
1313 return InvalidParameter;
1315 *mode = graphics->interpolation;
1317 return Ok;
1320 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
1322 if(!graphics || !scale)
1323 return InvalidParameter;
1325 *scale = graphics->scale;
1327 return Ok;
1330 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
1332 if(!graphics || !unit)
1333 return InvalidParameter;
1335 *unit = graphics->unit;
1337 return Ok;
1340 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
1341 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
1342 *mode)
1344 if(!graphics || !mode)
1345 return InvalidParameter;
1347 *mode = graphics->pixeloffset;
1349 return Ok;
1352 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
1353 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
1355 if(!graphics || !mode)
1356 return InvalidParameter;
1358 *mode = graphics->smoothing;
1360 return Ok;
1363 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
1365 if(!graphics || !matrix)
1366 return InvalidParameter;
1368 memcpy(matrix, graphics->worldtrans, sizeof(GpMatrix));
1369 return Ok;
1372 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
1374 static int calls;
1376 if(!graphics)
1377 return InvalidParameter;
1379 if(!(calls++))
1380 FIXME("graphics state not implemented\n");
1382 return NotImplemented;
1385 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
1387 static int calls;
1389 if(!graphics || !state)
1390 return InvalidParameter;
1392 if(!(calls++))
1393 FIXME("graphics state not implemented\n");
1395 return NotImplemented;
1398 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
1399 CompositingQuality quality)
1401 if(!graphics)
1402 return InvalidParameter;
1404 graphics->compqual = quality;
1406 return Ok;
1409 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
1410 InterpolationMode mode)
1412 if(!graphics)
1413 return InvalidParameter;
1415 graphics->interpolation = mode;
1417 return Ok;
1420 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
1422 if(!graphics || (scale <= 0.0))
1423 return InvalidParameter;
1425 graphics->scale = scale;
1427 return Ok;
1430 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
1432 if(!graphics || (unit == UnitWorld))
1433 return InvalidParameter;
1435 graphics->unit = unit;
1437 return Ok;
1440 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
1441 mode)
1443 if(!graphics)
1444 return InvalidParameter;
1446 graphics->pixeloffset = mode;
1448 return Ok;
1451 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
1453 if(!graphics)
1454 return InvalidParameter;
1456 graphics->smoothing = mode;
1458 return Ok;
1461 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
1463 if(!graphics || !matrix)
1464 return InvalidParameter;
1466 GdipDeleteMatrix(graphics->worldtrans);
1467 return GdipCloneMatrix(matrix, &graphics->worldtrans);