gdiplus: Extend GdipDrawImagePointsRect.
[wine/testsucceed.git] / dlls / gdiplus / graphics.c
blob7ba2d52bf268d3f5e8e6ea9ebbdabf158ab8340d
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. FIXME: Startcaps not implemented. */
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. FIXME: Startcaps not implemented. */
574 static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
575 GDIPCONST GpPointF * pt, INT count, BOOL caps)
577 POINT *pti, curpos;
578 GpPointF *ptcopy;
579 REAL x, y;
580 GpStatus status = GenericError;
582 if(!count)
583 return Ok;
585 pti = GdipAlloc(count * sizeof(POINT));
586 ptcopy = GdipAlloc(count * sizeof(GpPointF));
588 if(!pti || !ptcopy){
589 status = OutOfMemory;
590 goto end;
593 memcpy(ptcopy, pt, count * sizeof(GpPointF));
595 if(caps){
596 if(pen->endcap == LineCapArrowAnchor)
597 shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
598 /* FIXME The following is seemingly correct only for baseinset < 0 or
599 * baseinset > ~3. With smaller baseinsets, windows actually
600 * lengthens the bezier line instead of shortening it. */
601 else if((pen->endcap == LineCapCustom) && pen->customend){
602 x = pt[count - 1].X;
603 y = pt[count - 1].Y;
604 shorten_line_amt(pt[count - 2].X, pt[count - 2].Y, &x, &y,
605 pen->width * pen->customend->inset);
606 MoveToEx(graphics->hdc, roundr(pt[count - 1].X), roundr(pt[count - 1].Y), &curpos);
607 LineTo(graphics->hdc, roundr(x), roundr(y));
608 MoveToEx(graphics->hdc, curpos.x, curpos.y, NULL);
611 if(pen->startcap == LineCapArrowAnchor)
612 shorten_bezier_amt(ptcopy, pen->width, TRUE);
613 else if((pen->startcap == LineCapCustom) && pen->customstart){
614 x = ptcopy[0].X;
615 y = ptcopy[0].Y;
616 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y, &x, &y,
617 pen->width * pen->customend->inset);
618 MoveToEx(graphics->hdc, roundr(pt[0].X), roundr(pt[0].Y), &curpos);
619 LineTo(graphics->hdc, roundr(x), roundr(y));
620 MoveToEx(graphics->hdc, curpos.x, curpos.y, NULL);
623 /* the direction of the line cap is parallel to the direction at the
624 * end of the bezier (which, if it has been shortened, is not the same
625 * as the direction from pt[count-2] to pt[count-1]) */
626 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
627 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
628 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
629 pt[count - 1].X, pt[count - 1].Y);
631 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
632 pt[0].X - (ptcopy[0].X - ptcopy[1].X),
633 pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
636 transform_and_round_points(graphics, pti, ptcopy, count);
638 PolyBezier(graphics->hdc, pti, count);
640 status = Ok;
642 end:
643 GdipFree(pti);
644 GdipFree(ptcopy);
646 return status;
649 /* Draws a combination of bezier curves and lines between points. */
650 static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
651 GDIPCONST BYTE * types, INT count, BOOL caps)
653 POINT *pti = GdipAlloc(count * sizeof(POINT)), curpos;
654 BYTE *tp = GdipAlloc(count);
655 GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
656 REAL x = pt[count - 1].X, y = pt[count - 1].Y;
657 INT i, j;
658 GpStatus status = GenericError;
660 if(!count){
661 status = Ok;
662 goto end;
664 if(!pti || !tp || !ptcopy){
665 status = OutOfMemory;
666 goto end;
669 for(i = 1; i < count; i++){
670 if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
671 if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
672 || !(types[i + 1] & PathPointTypeBezier)){
673 ERR("Bad bezier points\n");
674 goto end;
676 i += 2;
680 memcpy(ptcopy, pt, count * sizeof(GpPointF));
682 /* If we are drawing caps, go through the points and adjust them accordingly,
683 * and draw the caps. */
684 if(caps){
685 switch(types[count - 1] & PathPointTypePathTypeMask){
686 case PathPointTypeBezier:
687 if(pen->endcap == LineCapArrowAnchor)
688 shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
689 else if((pen->endcap == LineCapCustom) && pen->customend){
690 x = pt[count - 1].X;
691 y = pt[count - 1].Y;
692 shorten_line_amt(pt[count - 2].X, pt[count - 2].Y, &x, &y,
693 pen->width * pen->customend->inset);
694 MoveToEx(graphics->hdc, roundr(pt[count - 1].X),
695 roundr(pt[count - 1].Y), &curpos);
696 LineTo(graphics->hdc, roundr(x), roundr(y));
697 MoveToEx(graphics->hdc, curpos.x, curpos.y, NULL);
700 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
701 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
702 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
703 pt[count - 1].X, pt[count - 1].Y);
705 break;
706 case PathPointTypeLine:
707 if(pen->endcap == LineCapArrowAnchor)
708 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
709 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
710 pen->width);
711 else if((pen->endcap == LineCapCustom) && pen->customend)
712 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
713 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
714 pen->customend->inset * pen->width);
716 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
717 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
718 pt[count - 1].Y);
720 break;
721 default:
722 ERR("Bad path last point\n");
723 goto end;
726 /* Find start of points */
727 for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
728 == PathPointTypeStart); j++);
730 switch(types[j] & PathPointTypePathTypeMask){
731 case PathPointTypeBezier:
732 if(pen->startcap == LineCapArrowAnchor)
733 shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
734 else if((pen->startcap == LineCapCustom) && pen->customstart){
735 x = pt[j - 1].X;
736 y = pt[j - 1].Y;
737 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y, &x, &y,
738 pen->width * pen->customstart->inset);
739 MoveToEx(graphics->hdc, roundr(pt[j - 1].X), roundr(pt[j - 1].Y), &curpos);
740 LineTo(graphics->hdc, roundr(x), roundr(y));
741 MoveToEx(graphics->hdc, curpos.x, curpos.y, NULL);
744 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
745 pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
746 pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
747 pt[j - 1].X, pt[j - 1].Y);
749 break;
750 case PathPointTypeLine:
751 if(pen->startcap == LineCapArrowAnchor)
752 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
753 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
754 pen->width);
755 else if((pen->startcap == LineCapCustom) && pen->customstart)
756 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
757 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
758 pen->customstart->inset * pen->width);
760 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
761 pt[j].X, pt[j].Y, pt[j - 1].X,
762 pt[j - 1].Y);
764 break;
765 default:
766 ERR("Bad path points\n");
767 goto end;
771 transform_and_round_points(graphics, pti, ptcopy, count);
773 for(i = 0; i < count; i++){
774 tp[i] = convert_path_point_type(types[i]);
777 PolyDraw(graphics->hdc, pti, tp, count);
779 status = Ok;
781 end:
782 GdipFree(pti);
783 GdipFree(ptcopy);
784 GdipFree(tp);
786 return status;
789 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
791 GpStatus retval;
793 if(hdc == NULL)
794 return OutOfMemory;
796 if(graphics == NULL)
797 return InvalidParameter;
799 *graphics = GdipAlloc(sizeof(GpGraphics));
800 if(!*graphics) return OutOfMemory;
802 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
803 GdipFree(*graphics);
804 return retval;
807 (*graphics)->hdc = hdc;
808 (*graphics)->hwnd = NULL;
809 (*graphics)->smoothing = SmoothingModeDefault;
810 (*graphics)->compqual = CompositingQualityDefault;
811 (*graphics)->interpolation = InterpolationModeDefault;
812 (*graphics)->pixeloffset = PixelOffsetModeDefault;
813 (*graphics)->unit = UnitDisplay;
814 (*graphics)->scale = 1.0;
816 return Ok;
819 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
821 GpStatus ret;
823 if((ret = GdipCreateFromHDC(GetDC(hwnd), graphics)) != Ok)
824 return ret;
826 (*graphics)->hwnd = hwnd;
828 return Ok;
831 GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
832 GpMetafile **metafile)
834 static int calls;
836 if(!hemf || !metafile)
837 return InvalidParameter;
839 if(!(calls++))
840 FIXME("not implemented\n");
842 return NotImplemented;
845 GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
846 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
848 static int calls;
849 IStream *stream = NULL;
850 UINT read;
851 BYTE* copy;
852 METAFILEPICT mfp;
853 HENHMETAFILE hemf;
854 GpStatus retval = GenericError;
856 if(!hwmf || !metafile || !placeable)
857 return InvalidParameter;
859 if(!(calls++))
860 FIXME("partially implemented\n");
862 if(placeable->Inch != INCH_HIMETRIC)
863 return NotImplemented;
865 mfp.mm = MM_HIMETRIC;
866 mfp.xExt = placeable->BoundingBox.Right - placeable->BoundingBox.Left;
867 mfp.yExt = placeable->BoundingBox.Bottom - placeable->BoundingBox.Top;
868 mfp.hMF = NULL;
870 read = GetMetaFileBitsEx(hwmf, 0, NULL);
871 if(!read)
872 return GenericError;
873 copy = GdipAlloc(read);
874 GetMetaFileBitsEx(hwmf, read, copy);
876 hemf = SetWinMetaFileBits(read, copy, NULL, &mfp);
877 GdipFree(copy);
879 read = GetEnhMetaFileBits(hemf, 0, NULL);
880 copy = GdipAlloc(read);
881 GetEnhMetaFileBits(hemf, read, copy);
882 DeleteEnhMetaFile(hemf);
884 if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
885 ERR("could not make stream\n");
886 goto end;
889 *metafile = GdipAlloc(sizeof(GpMetafile));
890 if(!*metafile){
891 retval = OutOfMemory;
892 goto end;
895 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
896 (LPVOID*) &((*metafile)->image.picture)) != S_OK){
897 GdipFree(*metafile);
898 goto end;
901 (*metafile)->image.type = ImageTypeMetafile;
902 (*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch);
903 (*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Right) / ((REAL) placeable->Inch);
904 (*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right
905 - placeable->BoundingBox.Left)) / ((REAL) placeable->Inch);
906 (*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom
907 - placeable->BoundingBox.Top)) / ((REAL) placeable->Inch);
908 (*metafile)->unit = UnitInch;
910 if(delete)
911 DeleteMetaFile(hwmf);
913 retval = Ok;
915 end:
916 IStream_Release(stream);
917 GdipFree(copy);
918 return retval;
921 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
923 if(!graphics) return InvalidParameter;
924 if(graphics->hwnd)
925 ReleaseDC(graphics->hwnd, graphics->hdc);
927 GdipDeleteMatrix(graphics->worldtrans);
928 HeapFree(GetProcessHeap(), 0, graphics);
930 return Ok;
933 GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
934 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
936 INT save_state, num_pts;
937 GpPointF points[MAX_ARC_PTS];
938 GpStatus retval;
940 if(!graphics || !pen)
941 return InvalidParameter;
943 num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
945 save_state = prepare_dc(graphics, pen);
947 retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
949 restore_dc(graphics, save_state);
951 return retval;
954 GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
955 REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
957 INT save_state;
958 GpPointF pt[4];
959 GpStatus retval;
961 if(!graphics || !pen)
962 return InvalidParameter;
964 pt[0].X = x1;
965 pt[0].Y = y1;
966 pt[1].X = x2;
967 pt[1].Y = y2;
968 pt[2].X = x3;
969 pt[2].Y = y3;
970 pt[3].X = x4;
971 pt[3].Y = y4;
973 save_state = prepare_dc(graphics, pen);
975 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
977 restore_dc(graphics, save_state);
979 return retval;
982 /* Approximates cardinal spline with Bezier curves. */
983 GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
984 GDIPCONST GpPointF *points, INT count, REAL tension)
986 /* PolyBezier expects count*3-2 points. */
987 INT i, len_pt = count*3-2, save_state;
988 GpPointF *pt;
989 REAL x1, x2, y1, y2;
990 GpStatus retval;
992 if(!graphics || !pen)
993 return InvalidParameter;
995 pt = GdipAlloc(len_pt * sizeof(GpPointF));
996 tension = tension * TENSION_CONST;
998 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
999 tension, &x1, &y1);
1001 pt[0].X = points[0].X;
1002 pt[0].Y = points[0].Y;
1003 pt[1].X = x1;
1004 pt[1].Y = y1;
1006 for(i = 0; i < count-2; i++){
1007 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
1009 pt[3*i+2].X = x1;
1010 pt[3*i+2].Y = y1;
1011 pt[3*i+3].X = points[i+1].X;
1012 pt[3*i+3].Y = points[i+1].Y;
1013 pt[3*i+4].X = x2;
1014 pt[3*i+4].Y = y2;
1017 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
1018 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
1020 pt[len_pt-2].X = x1;
1021 pt[len_pt-2].Y = y1;
1022 pt[len_pt-1].X = points[count-1].X;
1023 pt[len_pt-1].Y = points[count-1].Y;
1025 save_state = prepare_dc(graphics, pen);
1027 retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
1029 GdipFree(pt);
1030 restore_dc(graphics, save_state);
1032 return retval;
1035 /* FIXME: partially implemented */
1036 GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
1037 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
1038 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
1039 DrawImageAbort callback, VOID * callbackData)
1041 GpPointF ptf[3];
1042 POINT pti[3];
1043 REAL dx, dy;
1045 TRACE("%p %p %p %d %f %f %f %f %d %p %p %p\n", graphics, image, points, count,
1046 srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
1047 callbackData);
1049 if(!graphics || !image || !points || !imageAttributes || count != 3)
1050 return InvalidParameter;
1052 if(srcUnit == UnitInch)
1053 dx = dy = (REAL) INCH_HIMETRIC;
1054 else if(srcUnit == UnitPixel){
1055 dx = ((REAL) INCH_HIMETRIC) /
1056 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
1057 dy = ((REAL) INCH_HIMETRIC) /
1058 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
1060 else
1061 return NotImplemented;
1063 memcpy(ptf, points, 3 * sizeof(GpPointF));
1064 transform_and_round_points(graphics, pti, ptf, 3);
1066 /* IPicture renders bitmaps with the y-axis reversed
1067 * FIXME: flipping for unknown image type might not be correct. */
1068 if(image->type != ImageTypeMetafile){
1069 INT temp;
1070 temp = pti[0].y;
1071 pti[0].y = pti[2].y;
1072 pti[2].y = temp;
1075 if(IPicture_Render(image->picture, graphics->hdc,
1076 pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
1077 srcx * dx, srcy * dy,
1078 srcwidth * dx, srcheight * dy,
1079 NULL) != S_OK){
1080 if(callback)
1081 callback(callbackData);
1082 return GenericError;
1085 return Ok;
1088 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
1089 INT y1, INT x2, INT y2)
1091 INT save_state;
1092 GpPointF pt[2];
1093 GpStatus retval;
1095 if(!pen || !graphics)
1096 return InvalidParameter;
1098 pt[0].X = (REAL)x1;
1099 pt[0].Y = (REAL)y1;
1100 pt[1].X = (REAL)x2;
1101 pt[1].Y = (REAL)y2;
1103 save_state = prepare_dc(graphics, pen);
1105 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
1107 restore_dc(graphics, save_state);
1109 return retval;
1112 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
1113 GpPointF *points, INT count)
1115 INT save_state;
1116 GpStatus retval;
1118 if(!pen || !graphics || (count < 2))
1119 return InvalidParameter;
1121 save_state = prepare_dc(graphics, pen);
1123 retval = draw_polyline(graphics, pen, points, count, TRUE);
1125 restore_dc(graphics, save_state);
1127 return retval;
1130 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
1132 INT save_state;
1133 GpStatus retval;
1135 if(!pen || !graphics)
1136 return InvalidParameter;
1138 save_state = prepare_dc(graphics, pen);
1140 retval = draw_poly(graphics, pen, path->pathdata.Points,
1141 path->pathdata.Types, path->pathdata.Count, TRUE);
1143 restore_dc(graphics, save_state);
1145 return retval;
1148 GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
1149 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1151 INT save_state;
1153 if(!graphics || !pen)
1154 return InvalidParameter;
1156 save_state = prepare_dc(graphics, pen);
1157 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1159 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
1161 restore_dc(graphics, save_state);
1163 return Ok;
1166 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
1167 INT y, INT width, INT height)
1169 INT save_state;
1171 if(!pen || !graphics)
1172 return InvalidParameter;
1174 save_state = prepare_dc(graphics, pen);
1175 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1177 Rectangle(graphics->hdc, x, y, x + width, y + height);
1179 restore_dc(graphics, save_state);
1181 return Ok;
1184 GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
1186 INT save_state;
1187 GpStatus retval;
1189 if(!brush || !graphics || !path)
1190 return InvalidParameter;
1192 save_state = SaveDC(graphics->hdc);
1193 EndPath(graphics->hdc);
1194 SelectObject(graphics->hdc, brush->gdibrush);
1195 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
1196 : WINDING));
1198 BeginPath(graphics->hdc);
1199 retval = draw_poly(graphics, NULL, path->pathdata.Points,
1200 path->pathdata.Types, path->pathdata.Count, FALSE);
1202 if(retval != Ok)
1203 goto end;
1205 EndPath(graphics->hdc);
1206 FillPath(graphics->hdc);
1208 retval = Ok;
1210 end:
1211 RestoreDC(graphics->hdc, save_state);
1213 return retval;
1216 GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
1217 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1219 INT save_state;
1221 if(!graphics || !brush)
1222 return InvalidParameter;
1224 save_state = SaveDC(graphics->hdc);
1225 EndPath(graphics->hdc);
1226 SelectObject(graphics->hdc, brush->gdibrush);
1227 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
1229 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
1231 RestoreDC(graphics->hdc, save_state);
1233 return Ok;
1236 GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
1237 GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
1239 INT save_state, i;
1240 GpPointF *ptf = NULL;
1241 POINT *pti = NULL;
1242 GpStatus retval = Ok;
1244 if(!graphics || !brush || !points || !count)
1245 return InvalidParameter;
1247 ptf = GdipAlloc(count * sizeof(GpPointF));
1248 pti = GdipAlloc(count * sizeof(POINT));
1249 if(!ptf || !pti){
1250 retval = OutOfMemory;
1251 goto end;
1254 for(i = 0; i < count; i ++){
1255 ptf[i].X = (REAL) points[i].X;
1256 ptf[i].Y = (REAL) points[i].Y;
1259 save_state = SaveDC(graphics->hdc);
1260 EndPath(graphics->hdc);
1261 SelectObject(graphics->hdc, brush->gdibrush);
1262 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
1263 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
1264 : WINDING));
1266 transform_and_round_points(graphics, pti, ptf, count);
1267 Polygon(graphics->hdc, pti, count);
1269 RestoreDC(graphics->hdc, save_state);
1271 end:
1272 GdipFree(ptf);
1273 GdipFree(pti);
1275 return retval;
1278 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
1279 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
1280 CompositingQuality *quality)
1282 if(!graphics || !quality)
1283 return InvalidParameter;
1285 *quality = graphics->compqual;
1287 return Ok;
1290 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
1291 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
1292 InterpolationMode *mode)
1294 if(!graphics || !mode)
1295 return InvalidParameter;
1297 *mode = graphics->interpolation;
1299 return Ok;
1302 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
1304 if(!graphics || !scale)
1305 return InvalidParameter;
1307 *scale = graphics->scale;
1309 return Ok;
1312 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
1314 if(!graphics || !unit)
1315 return InvalidParameter;
1317 *unit = graphics->unit;
1319 return Ok;
1322 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
1323 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
1324 *mode)
1326 if(!graphics || !mode)
1327 return InvalidParameter;
1329 *mode = graphics->pixeloffset;
1331 return Ok;
1334 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
1335 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
1337 if(!graphics || !mode)
1338 return InvalidParameter;
1340 *mode = graphics->smoothing;
1342 return Ok;
1345 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
1347 if(!graphics || !matrix)
1348 return InvalidParameter;
1350 memcpy(matrix, graphics->worldtrans, sizeof(GpMatrix));
1351 return Ok;
1354 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
1356 static int calls;
1358 if(!graphics)
1359 return InvalidParameter;
1361 if(!(calls++))
1362 FIXME("graphics state not implemented\n");
1364 return NotImplemented;
1367 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
1369 static int calls;
1371 if(!graphics || !state)
1372 return InvalidParameter;
1374 if(!(calls++))
1375 FIXME("graphics state not implemented\n");
1377 return NotImplemented;
1380 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
1381 CompositingQuality quality)
1383 if(!graphics)
1384 return InvalidParameter;
1386 graphics->compqual = quality;
1388 return Ok;
1391 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
1392 InterpolationMode mode)
1394 if(!graphics)
1395 return InvalidParameter;
1397 graphics->interpolation = mode;
1399 return Ok;
1402 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
1404 if(!graphics || (scale <= 0.0))
1405 return InvalidParameter;
1407 graphics->scale = scale;
1409 return Ok;
1412 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
1414 if(!graphics || (unit == UnitWorld))
1415 return InvalidParameter;
1417 graphics->unit = unit;
1419 return Ok;
1422 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
1423 mode)
1425 if(!graphics)
1426 return InvalidParameter;
1428 graphics->pixeloffset = mode;
1430 return Ok;
1433 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
1435 if(!graphics)
1436 return InvalidParameter;
1438 graphics->smoothing = mode;
1440 return Ok;
1443 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
1445 if(!graphics || !matrix)
1446 return InvalidParameter;
1448 GdipDeleteMatrix(graphics->worldtrans);
1449 return GdipCloneMatrix(matrix, &graphics->worldtrans);