gdiplus: Factor out the gdi32 code of GdipFillRegion.
[wine/multimedia.git] / dlls / gdiplus / graphics.c
bloba17cbefd43bbfbcb19ad3d2117ff354579a853ee
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>
21 #include <limits.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winuser.h"
26 #include "wingdi.h"
27 #include "wine/unicode.h"
29 #define COBJMACROS
30 #include "objbase.h"
31 #include "ocidl.h"
32 #include "olectl.h"
33 #include "ole2.h"
35 #include "winreg.h"
36 #include "shlwapi.h"
38 #include "gdiplus.h"
39 #include "gdiplus_private.h"
40 #include "wine/debug.h"
41 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
45 /* looks-right constants */
46 #define ANCHOR_WIDTH (2.0)
47 #define MAX_ITERS (50)
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)
52 REAL radAngle, hypotenuse;
54 radAngle = deg2rad(angle);
55 hypotenuse = 50.0; /* arbitrary */
57 *x = x_0 + cos(radAngle) * hypotenuse;
58 *y = y_0 + sin(radAngle) * hypotenuse;
61 /* Converts from gdiplus path point type to gdi path point type. */
62 static BYTE convert_path_point_type(BYTE type)
64 BYTE ret;
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;
81 if(type & PathPointTypeCloseSubpath)
82 ret |= PT_CLOSEFIGURE;
84 return ret;
87 static REAL graphics_res(GpGraphics *graphics)
89 if (graphics->image) return graphics->image->xres;
90 else return (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
93 static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
95 HPEN gdipen;
96 REAL width;
97 INT save_state, i, numdashes;
98 GpPointF pt[2];
99 DWORD dash_array[MAX_DASHLEN];
101 save_state = SaveDC(graphics->hdc);
103 EndPath(graphics->hdc);
105 if(pen->unit == UnitPixel){
106 width = pen->width;
108 else{
109 /* Get an estimate for the amount the pen width is affected by the world
110 * transform. (This is similar to what some of the wine drivers do.) */
111 pt[0].X = 0.0;
112 pt[0].Y = 0.0;
113 pt[1].X = 1.0;
114 pt[1].Y = 1.0;
115 GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
116 width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
117 (pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
119 width *= pen->width * convert_unit(graphics_res(graphics),
120 pen->unit == UnitWorld ? graphics->unit : pen->unit);
123 if(pen->dash == DashStyleCustom){
124 numdashes = min(pen->numdashes, MAX_DASHLEN);
126 TRACE("dashes are: ");
127 for(i = 0; i < numdashes; i++){
128 dash_array[i] = roundr(width * pen->dashes[i]);
129 TRACE("%d, ", dash_array[i]);
131 TRACE("\n and the pen style is %x\n", pen->style);
133 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb,
134 numdashes, dash_array);
136 else
137 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, 0, NULL);
139 SelectObject(graphics->hdc, gdipen);
141 return save_state;
144 static void restore_dc(GpGraphics *graphics, INT state)
146 DeleteObject(SelectObject(graphics->hdc, GetStockObject(NULL_PEN)));
147 RestoreDC(graphics->hdc, state);
150 /* This helper applies all the changes that the points listed in ptf need in
151 * order to be drawn on the device context. In the end, this should include at
152 * least:
153 * -scaling by page unit
154 * -applying world transformation
155 * -converting from float to int
156 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
157 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
158 * gdi to draw, and these functions would irreparably mess with line widths.
160 static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
161 GpPointF *ptf, INT count)
163 REAL unitscale;
164 GpMatrix *matrix;
165 int i;
167 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
169 /* apply page scale */
170 if(graphics->unit != UnitDisplay)
171 unitscale *= graphics->scale;
173 GdipCloneMatrix(graphics->worldtrans, &matrix);
174 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
175 GdipTransformMatrixPoints(matrix, ptf, count);
176 GdipDeleteMatrix(matrix);
178 for(i = 0; i < count; i++){
179 pti[i].x = roundr(ptf[i].X);
180 pti[i].y = roundr(ptf[i].Y);
184 /* Draw non-premultiplied ARGB data to the given graphics object */
185 static GpStatus alpha_blend_pixels(GpGraphics *graphics, INT dst_x, INT dst_y,
186 const BYTE *src, INT src_width, INT src_height, INT src_stride)
188 if (graphics->image && graphics->image->type == ImageTypeBitmap)
190 GpBitmap *dst_bitmap = (GpBitmap*)graphics->image;
191 INT x, y;
193 for (x=0; x<src_width; x++)
195 for (y=0; y<src_height; y++)
197 ARGB dst_color, src_color;
198 GdipBitmapGetPixel(dst_bitmap, x+dst_x, y+dst_y, &dst_color);
199 src_color = ((ARGB*)(src + src_stride * y))[x];
200 GdipBitmapSetPixel(dst_bitmap, x+dst_x, y+dst_y, color_over(dst_color, src_color));
204 return Ok;
206 else
208 HDC hdc;
209 HBITMAP hbitmap, old_hbm=NULL;
210 BITMAPINFOHEADER bih;
211 BYTE *temp_bits;
212 BLENDFUNCTION bf;
214 hdc = CreateCompatibleDC(0);
216 bih.biSize = sizeof(BITMAPINFOHEADER);
217 bih.biWidth = src_width;
218 bih.biHeight = -src_height;
219 bih.biPlanes = 1;
220 bih.biBitCount = 32;
221 bih.biCompression = BI_RGB;
222 bih.biSizeImage = 0;
223 bih.biXPelsPerMeter = 0;
224 bih.biYPelsPerMeter = 0;
225 bih.biClrUsed = 0;
226 bih.biClrImportant = 0;
228 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
229 (void**)&temp_bits, NULL, 0);
231 convert_32bppARGB_to_32bppPARGB(src_width, src_height, temp_bits,
232 4 * src_width, src, src_stride);
234 old_hbm = SelectObject(hdc, hbitmap);
236 bf.BlendOp = AC_SRC_OVER;
237 bf.BlendFlags = 0;
238 bf.SourceConstantAlpha = 255;
239 bf.AlphaFormat = AC_SRC_ALPHA;
241 GdiAlphaBlend(graphics->hdc, dst_x, dst_y, src_width, src_height,
242 hdc, 0, 0, src_width, src_height, bf);
244 SelectObject(hdc, old_hbm);
245 DeleteDC(hdc);
246 DeleteObject(hbitmap);
248 return Ok;
252 static ARGB blend_colors(ARGB start, ARGB end, REAL position)
254 ARGB result=0;
255 ARGB i;
256 for (i=0xff; i<=0xff0000; i = i << 8)
257 result |= (int)((start&i)*(1.0f - position)+(end&i)*(position))&i;
258 return result;
261 static ARGB blend_line_gradient(GpLineGradient* brush, REAL position)
263 REAL blendfac;
265 /* clamp to between 0.0 and 1.0, using the wrap mode */
266 if (brush->wrap == WrapModeTile)
268 position = fmodf(position, 1.0f);
269 if (position < 0.0f) position += 1.0f;
271 else /* WrapModeFlip* */
273 position = fmodf(position, 2.0f);
274 if (position < 0.0f) position += 2.0f;
275 if (position > 1.0f) position = 2.0f - position;
278 if (brush->blendcount == 1)
279 blendfac = position;
280 else
282 int i=1;
283 REAL left_blendpos, left_blendfac, right_blendpos, right_blendfac;
284 REAL range;
286 /* locate the blend positions surrounding this position */
287 while (position > brush->blendpos[i])
288 i++;
290 /* interpolate between the blend positions */
291 left_blendpos = brush->blendpos[i-1];
292 left_blendfac = brush->blendfac[i-1];
293 right_blendpos = brush->blendpos[i];
294 right_blendfac = brush->blendfac[i];
295 range = right_blendpos - left_blendpos;
296 blendfac = (left_blendfac * (right_blendpos - position) +
297 right_blendfac * (position - left_blendpos)) / range;
300 if (brush->pblendcount == 0)
301 return blend_colors(brush->startcolor, brush->endcolor, blendfac);
302 else
304 int i=1;
305 ARGB left_blendcolor, right_blendcolor;
306 REAL left_blendpos, right_blendpos;
308 /* locate the blend colors surrounding this position */
309 while (blendfac > brush->pblendpos[i])
310 i++;
312 /* interpolate between the blend colors */
313 left_blendpos = brush->pblendpos[i-1];
314 left_blendcolor = brush->pblendcolor[i-1];
315 right_blendpos = brush->pblendpos[i];
316 right_blendcolor = brush->pblendcolor[i];
317 blendfac = (blendfac - left_blendpos) / (right_blendpos - left_blendpos);
318 return blend_colors(left_blendcolor, right_blendcolor, blendfac);
322 static void brush_fill_path(GpGraphics *graphics, GpBrush* brush)
324 switch (brush->bt)
326 case BrushTypeLinearGradient:
328 GpLineGradient *line = (GpLineGradient*)brush;
329 RECT rc;
331 SelectClipPath(graphics->hdc, RGN_AND);
332 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
334 GpPointF endpointsf[2];
335 POINT endpointsi[2];
336 POINT poly[4];
338 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
340 endpointsf[0] = line->startpoint;
341 endpointsf[1] = line->endpoint;
342 transform_and_round_points(graphics, endpointsi, endpointsf, 2);
344 if (abs(endpointsi[0].x-endpointsi[1].x) > abs(endpointsi[0].y-endpointsi[1].y))
346 /* vertical-ish gradient */
347 int startx, endx; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
348 int startbottomx; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
349 int width;
350 COLORREF col;
351 HBRUSH hbrush, hprevbrush;
352 int leftx, rightx; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
353 int x;
354 int tilt; /* horizontal distance covered by a gradient line */
356 startx = roundr((rc.top - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X);
357 endx = roundr((rc.top - endpointsf[1].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[1].X);
358 width = endx - startx;
359 startbottomx = roundr((rc.bottom - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X);
360 tilt = startx - startbottomx;
362 if (startx >= startbottomx)
364 leftx = rc.left;
365 rightx = rc.right + tilt;
367 else
369 leftx = rc.left + tilt;
370 rightx = rc.right;
373 poly[0].y = rc.bottom;
374 poly[1].y = rc.top;
375 poly[2].y = rc.top;
376 poly[3].y = rc.bottom;
378 for (x=leftx; x<=rightx; x++)
380 ARGB argb = blend_line_gradient(line, (x-startx)/(REAL)width);
381 col = ARGB2COLORREF(argb);
382 hbrush = CreateSolidBrush(col);
383 hprevbrush = SelectObject(graphics->hdc, hbrush);
384 poly[0].x = x - tilt - 1;
385 poly[1].x = x - 1;
386 poly[2].x = x;
387 poly[3].x = x - tilt;
388 Polygon(graphics->hdc, poly, 4);
389 SelectObject(graphics->hdc, hprevbrush);
390 DeleteObject(hbrush);
393 else if (endpointsi[0].y != endpointsi[1].y)
395 /* horizontal-ish gradient */
396 int starty, endy; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
397 int startrighty; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
398 int height;
399 COLORREF col;
400 HBRUSH hbrush, hprevbrush;
401 int topy, bottomy; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
402 int y;
403 int tilt; /* vertical distance covered by a gradient line */
405 starty = roundr((rc.left - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y);
406 endy = roundr((rc.left - endpointsf[1].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[1].Y);
407 height = endy - starty;
408 startrighty = roundr((rc.right - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y);
409 tilt = starty - startrighty;
411 if (starty >= startrighty)
413 topy = rc.top;
414 bottomy = rc.bottom + tilt;
416 else
418 topy = rc.top + tilt;
419 bottomy = rc.bottom;
422 poly[0].x = rc.right;
423 poly[1].x = rc.left;
424 poly[2].x = rc.left;
425 poly[3].x = rc.right;
427 for (y=topy; y<=bottomy; y++)
429 ARGB argb = blend_line_gradient(line, (y-starty)/(REAL)height);
430 col = ARGB2COLORREF(argb);
431 hbrush = CreateSolidBrush(col);
432 hprevbrush = SelectObject(graphics->hdc, hbrush);
433 poly[0].y = y - tilt - 1;
434 poly[1].y = y - 1;
435 poly[2].y = y;
436 poly[3].y = y - tilt;
437 Polygon(graphics->hdc, poly, 4);
438 SelectObject(graphics->hdc, hprevbrush);
439 DeleteObject(hbrush);
442 /* else startpoint == endpoint */
444 break;
446 case BrushTypeSolidColor:
448 GpSolidFill *fill = (GpSolidFill*)brush;
449 if (fill->bmp)
451 RECT rc;
452 /* partially transparent fill */
454 SelectClipPath(graphics->hdc, RGN_AND);
455 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
457 HDC hdc = CreateCompatibleDC(NULL);
458 HBITMAP oldbmp;
459 BLENDFUNCTION bf;
461 if (!hdc) break;
463 oldbmp = SelectObject(hdc, fill->bmp);
465 bf.BlendOp = AC_SRC_OVER;
466 bf.BlendFlags = 0;
467 bf.SourceConstantAlpha = 255;
468 bf.AlphaFormat = AC_SRC_ALPHA;
470 GdiAlphaBlend(graphics->hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdc, 0, 0, 1, 1, bf);
472 SelectObject(hdc, oldbmp);
473 DeleteDC(hdc);
476 break;
478 /* else fall through */
480 default:
481 SelectObject(graphics->hdc, brush->gdibrush);
482 FillPath(graphics->hdc);
483 break;
487 /* GdipDrawPie/GdipFillPie helper function */
488 static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width,
489 REAL height, REAL startAngle, REAL sweepAngle)
491 GpPointF ptf[4];
492 POINT pti[4];
494 ptf[0].X = x;
495 ptf[0].Y = y;
496 ptf[1].X = x + width;
497 ptf[1].Y = y + height;
499 deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y);
500 deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y);
502 transform_and_round_points(graphics, pti, ptf, 4);
504 Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x,
505 pti[2].y, pti[3].x, pti[3].y);
508 /* Draws the linecap the specified color and size on the hdc. The linecap is in
509 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
510 * should not be called on an hdc that has a path you care about. */
511 static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
512 const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
514 HGDIOBJ oldbrush = NULL, oldpen = NULL;
515 GpMatrix *matrix = NULL;
516 HBRUSH brush = NULL;
517 HPEN pen = NULL;
518 PointF ptf[4], *custptf = NULL;
519 POINT pt[4], *custpt = NULL;
520 BYTE *tp = NULL;
521 REAL theta, dsmall, dbig, dx, dy = 0.0;
522 INT i, count;
523 LOGBRUSH lb;
524 BOOL customstroke;
526 if((x1 == x2) && (y1 == y2))
527 return;
529 theta = gdiplus_atan2(y2 - y1, x2 - x1);
531 customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
532 if(!customstroke){
533 brush = CreateSolidBrush(color);
534 lb.lbStyle = BS_SOLID;
535 lb.lbColor = color;
536 lb.lbHatch = 0;
537 pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
538 PS_JOIN_MITER, 1, &lb, 0,
539 NULL);
540 oldbrush = SelectObject(graphics->hdc, brush);
541 oldpen = SelectObject(graphics->hdc, pen);
544 switch(cap){
545 case LineCapFlat:
546 break;
547 case LineCapSquare:
548 case LineCapSquareAnchor:
549 case LineCapDiamondAnchor:
550 size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0;
551 if(cap == LineCapDiamondAnchor){
552 dsmall = cos(theta + M_PI_2) * size;
553 dbig = sin(theta + M_PI_2) * size;
555 else{
556 dsmall = cos(theta + M_PI_4) * size;
557 dbig = sin(theta + M_PI_4) * size;
560 ptf[0].X = x2 - dsmall;
561 ptf[1].X = x2 + dbig;
563 ptf[0].Y = y2 - dbig;
564 ptf[3].Y = y2 + dsmall;
566 ptf[1].Y = y2 - dsmall;
567 ptf[2].Y = y2 + dbig;
569 ptf[3].X = x2 - dbig;
570 ptf[2].X = x2 + dsmall;
572 transform_and_round_points(graphics, pt, ptf, 4);
573 Polygon(graphics->hdc, pt, 4);
575 break;
576 case LineCapArrowAnchor:
577 size = size * 4.0 / sqrt(3.0);
579 dx = cos(M_PI / 6.0 + theta) * size;
580 dy = sin(M_PI / 6.0 + theta) * size;
582 ptf[0].X = x2 - dx;
583 ptf[0].Y = y2 - dy;
585 dx = cos(- M_PI / 6.0 + theta) * size;
586 dy = sin(- M_PI / 6.0 + theta) * size;
588 ptf[1].X = x2 - dx;
589 ptf[1].Y = y2 - dy;
591 ptf[2].X = x2;
592 ptf[2].Y = y2;
594 transform_and_round_points(graphics, pt, ptf, 3);
595 Polygon(graphics->hdc, pt, 3);
597 break;
598 case LineCapRoundAnchor:
599 dx = dy = ANCHOR_WIDTH * size / 2.0;
601 ptf[0].X = x2 - dx;
602 ptf[0].Y = y2 - dy;
603 ptf[1].X = x2 + dx;
604 ptf[1].Y = y2 + dy;
606 transform_and_round_points(graphics, pt, ptf, 2);
607 Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
609 break;
610 case LineCapTriangle:
611 size = size / 2.0;
612 dx = cos(M_PI_2 + theta) * size;
613 dy = sin(M_PI_2 + theta) * size;
615 ptf[0].X = x2 - dx;
616 ptf[0].Y = y2 - dy;
617 ptf[1].X = x2 + dx;
618 ptf[1].Y = y2 + dy;
620 dx = cos(theta) * size;
621 dy = sin(theta) * size;
623 ptf[2].X = x2 + dx;
624 ptf[2].Y = y2 + dy;
626 transform_and_round_points(graphics, pt, ptf, 3);
627 Polygon(graphics->hdc, pt, 3);
629 break;
630 case LineCapRound:
631 dx = dy = size / 2.0;
633 ptf[0].X = x2 - dx;
634 ptf[0].Y = y2 - dy;
635 ptf[1].X = x2 + dx;
636 ptf[1].Y = y2 + dy;
638 dx = -cos(M_PI_2 + theta) * size;
639 dy = -sin(M_PI_2 + theta) * size;
641 ptf[2].X = x2 - dx;
642 ptf[2].Y = y2 - dy;
643 ptf[3].X = x2 + dx;
644 ptf[3].Y = y2 + dy;
646 transform_and_round_points(graphics, pt, ptf, 4);
647 Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x,
648 pt[2].y, pt[3].x, pt[3].y);
650 break;
651 case LineCapCustom:
652 if(!custom)
653 break;
655 count = custom->pathdata.Count;
656 custptf = GdipAlloc(count * sizeof(PointF));
657 custpt = GdipAlloc(count * sizeof(POINT));
658 tp = GdipAlloc(count);
660 if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok))
661 goto custend;
663 memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF));
665 GdipScaleMatrix(matrix, size, size, MatrixOrderAppend);
666 GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2),
667 MatrixOrderAppend);
668 GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend);
669 GdipTransformMatrixPoints(matrix, custptf, count);
671 transform_and_round_points(graphics, custpt, custptf, count);
673 for(i = 0; i < count; i++)
674 tp[i] = convert_path_point_type(custom->pathdata.Types[i]);
676 if(custom->fill){
677 BeginPath(graphics->hdc);
678 PolyDraw(graphics->hdc, custpt, tp, count);
679 EndPath(graphics->hdc);
680 StrokeAndFillPath(graphics->hdc);
682 else
683 PolyDraw(graphics->hdc, custpt, tp, count);
685 custend:
686 GdipFree(custptf);
687 GdipFree(custpt);
688 GdipFree(tp);
689 GdipDeleteMatrix(matrix);
690 break;
691 default:
692 break;
695 if(!customstroke){
696 SelectObject(graphics->hdc, oldbrush);
697 SelectObject(graphics->hdc, oldpen);
698 DeleteObject(brush);
699 DeleteObject(pen);
703 /* Shortens the line by the given percent by changing x2, y2.
704 * If percent is > 1.0 then the line will change direction.
705 * If percent is negative it can lengthen the line. */
706 static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL percent)
708 REAL dist, theta, dx, dy;
710 if((y1 == *y2) && (x1 == *x2))
711 return;
713 dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent;
714 theta = gdiplus_atan2((*y2 - y1), (*x2 - x1));
715 dx = cos(theta) * dist;
716 dy = sin(theta) * dist;
718 *x2 = *x2 + dx;
719 *y2 = *y2 + dy;
722 /* Shortens the line by the given amount by changing x2, y2.
723 * If the amount is greater than the distance, the line will become length 0.
724 * If the amount is negative, it can lengthen the line. */
725 static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt)
727 REAL dx, dy, percent;
729 dx = *x2 - x1;
730 dy = *y2 - y1;
731 if(dx == 0 && dy == 0)
732 return;
734 percent = amt / sqrt(dx * dx + dy * dy);
735 if(percent >= 1.0){
736 *x2 = x1;
737 *y2 = y1;
738 return;
741 shorten_line_percent(x1, y1, x2, y2, percent);
744 /* Draws lines between the given points, and if caps is true then draws an endcap
745 * at the end of the last line. */
746 static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen,
747 GDIPCONST GpPointF * pt, INT count, BOOL caps)
749 POINT *pti = NULL;
750 GpPointF *ptcopy = NULL;
751 GpStatus status = GenericError;
753 if(!count)
754 return Ok;
756 pti = GdipAlloc(count * sizeof(POINT));
757 ptcopy = GdipAlloc(count * sizeof(GpPointF));
759 if(!pti || !ptcopy){
760 status = OutOfMemory;
761 goto end;
764 memcpy(ptcopy, pt, count * sizeof(GpPointF));
766 if(caps){
767 if(pen->endcap == LineCapArrowAnchor)
768 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
769 &ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width);
770 else if((pen->endcap == LineCapCustom) && pen->customend)
771 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
772 &ptcopy[count-1].X, &ptcopy[count-1].Y,
773 pen->customend->inset * pen->width);
775 if(pen->startcap == LineCapArrowAnchor)
776 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
777 &ptcopy[0].X, &ptcopy[0].Y, pen->width);
778 else if((pen->startcap == LineCapCustom) && pen->customstart)
779 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
780 &ptcopy[0].X, &ptcopy[0].Y,
781 pen->customstart->inset * pen->width);
783 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
784 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
785 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
786 pt[1].X, pt[1].Y, pt[0].X, pt[0].Y);
789 transform_and_round_points(graphics, pti, ptcopy, count);
791 if(Polyline(graphics->hdc, pti, count))
792 status = Ok;
794 end:
795 GdipFree(pti);
796 GdipFree(ptcopy);
798 return status;
801 /* Conducts a linear search to find the bezier points that will back off
802 * the endpoint of the curve by a distance of amt. Linear search works
803 * better than binary in this case because there are multiple solutions,
804 * and binary searches often find a bad one. I don't think this is what
805 * Windows does but short of rendering the bezier without GDI's help it's
806 * the best we can do. If rev then work from the start of the passed points
807 * instead of the end. */
808 static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev)
810 GpPointF origpt[4];
811 REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0;
812 INT i, first = 0, second = 1, third = 2, fourth = 3;
814 if(rev){
815 first = 3;
816 second = 2;
817 third = 1;
818 fourth = 0;
821 origx = pt[fourth].X;
822 origy = pt[fourth].Y;
823 memcpy(origpt, pt, sizeof(GpPointF) * 4);
825 for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){
826 /* reset bezier points to original values */
827 memcpy(pt, origpt, sizeof(GpPointF) * 4);
828 /* Perform magic on bezier points. Order is important here.*/
829 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
830 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
831 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
832 shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent);
833 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
834 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
836 dx = pt[fourth].X - origx;
837 dy = pt[fourth].Y - origy;
839 diff = sqrt(dx * dx + dy * dy);
840 percent += 0.0005 * amt;
844 /* Draws bezier curves between given points, and if caps is true then draws an
845 * endcap at the end of the last line. */
846 static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
847 GDIPCONST GpPointF * pt, INT count, BOOL caps)
849 POINT *pti;
850 GpPointF *ptcopy;
851 GpStatus status = GenericError;
853 if(!count)
854 return Ok;
856 pti = GdipAlloc(count * sizeof(POINT));
857 ptcopy = GdipAlloc(count * sizeof(GpPointF));
859 if(!pti || !ptcopy){
860 status = OutOfMemory;
861 goto end;
864 memcpy(ptcopy, pt, count * sizeof(GpPointF));
866 if(caps){
867 if(pen->endcap == LineCapArrowAnchor)
868 shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
869 else if((pen->endcap == LineCapCustom) && pen->customend)
870 shorten_bezier_amt(&ptcopy[count-4], pen->width * pen->customend->inset,
871 FALSE);
873 if(pen->startcap == LineCapArrowAnchor)
874 shorten_bezier_amt(ptcopy, pen->width, TRUE);
875 else if((pen->startcap == LineCapCustom) && pen->customstart)
876 shorten_bezier_amt(ptcopy, pen->width * pen->customstart->inset, TRUE);
878 /* the direction of the line cap is parallel to the direction at the
879 * end of the bezier (which, if it has been shortened, is not the same
880 * as the direction from pt[count-2] to pt[count-1]) */
881 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
882 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
883 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
884 pt[count - 1].X, pt[count - 1].Y);
886 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
887 pt[0].X - (ptcopy[0].X - ptcopy[1].X),
888 pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
891 transform_and_round_points(graphics, pti, ptcopy, count);
893 PolyBezier(graphics->hdc, pti, count);
895 status = Ok;
897 end:
898 GdipFree(pti);
899 GdipFree(ptcopy);
901 return status;
904 /* Draws a combination of bezier curves and lines between points. */
905 static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
906 GDIPCONST BYTE * types, INT count, BOOL caps)
908 POINT *pti = GdipAlloc(count * sizeof(POINT));
909 BYTE *tp = GdipAlloc(count);
910 GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
911 INT i, j;
912 GpStatus status = GenericError;
914 if(!count){
915 status = Ok;
916 goto end;
918 if(!pti || !tp || !ptcopy){
919 status = OutOfMemory;
920 goto end;
923 for(i = 1; i < count; i++){
924 if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
925 if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
926 || !(types[i + 1] & PathPointTypeBezier)){
927 ERR("Bad bezier points\n");
928 goto end;
930 i += 2;
934 memcpy(ptcopy, pt, count * sizeof(GpPointF));
936 /* If we are drawing caps, go through the points and adjust them accordingly,
937 * and draw the caps. */
938 if(caps){
939 switch(types[count - 1] & PathPointTypePathTypeMask){
940 case PathPointTypeBezier:
941 if(pen->endcap == LineCapArrowAnchor)
942 shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
943 else if((pen->endcap == LineCapCustom) && pen->customend)
944 shorten_bezier_amt(&ptcopy[count - 4],
945 pen->width * pen->customend->inset, FALSE);
947 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
948 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
949 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
950 pt[count - 1].X, pt[count - 1].Y);
952 break;
953 case PathPointTypeLine:
954 if(pen->endcap == LineCapArrowAnchor)
955 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
956 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
957 pen->width);
958 else if((pen->endcap == LineCapCustom) && pen->customend)
959 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
960 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
961 pen->customend->inset * pen->width);
963 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
964 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
965 pt[count - 1].Y);
967 break;
968 default:
969 ERR("Bad path last point\n");
970 goto end;
973 /* Find start of points */
974 for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
975 == PathPointTypeStart); j++);
977 switch(types[j] & PathPointTypePathTypeMask){
978 case PathPointTypeBezier:
979 if(pen->startcap == LineCapArrowAnchor)
980 shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
981 else if((pen->startcap == LineCapCustom) && pen->customstart)
982 shorten_bezier_amt(&ptcopy[j - 1],
983 pen->width * pen->customstart->inset, TRUE);
985 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
986 pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
987 pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
988 pt[j - 1].X, pt[j - 1].Y);
990 break;
991 case PathPointTypeLine:
992 if(pen->startcap == LineCapArrowAnchor)
993 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
994 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
995 pen->width);
996 else if((pen->startcap == LineCapCustom) && pen->customstart)
997 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
998 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
999 pen->customstart->inset * pen->width);
1001 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
1002 pt[j].X, pt[j].Y, pt[j - 1].X,
1003 pt[j - 1].Y);
1005 break;
1006 default:
1007 ERR("Bad path points\n");
1008 goto end;
1012 transform_and_round_points(graphics, pti, ptcopy, count);
1014 for(i = 0; i < count; i++){
1015 tp[i] = convert_path_point_type(types[i]);
1018 PolyDraw(graphics->hdc, pti, tp, count);
1020 status = Ok;
1022 end:
1023 GdipFree(pti);
1024 GdipFree(ptcopy);
1025 GdipFree(tp);
1027 return status;
1030 GpStatus trace_path(GpGraphics *graphics, GpPath *path)
1032 GpStatus result;
1034 BeginPath(graphics->hdc);
1035 result = draw_poly(graphics, NULL, path->pathdata.Points,
1036 path->pathdata.Types, path->pathdata.Count, FALSE);
1037 EndPath(graphics->hdc);
1038 return result;
1041 typedef struct _GraphicsContainerItem {
1042 struct list entry;
1043 GraphicsContainer contid;
1045 SmoothingMode smoothing;
1046 CompositingQuality compqual;
1047 InterpolationMode interpolation;
1048 CompositingMode compmode;
1049 TextRenderingHint texthint;
1050 REAL scale;
1051 GpUnit unit;
1052 PixelOffsetMode pixeloffset;
1053 UINT textcontrast;
1054 GpMatrix* worldtrans;
1055 GpRegion* clip;
1056 } GraphicsContainerItem;
1058 static GpStatus init_container(GraphicsContainerItem** container,
1059 GDIPCONST GpGraphics* graphics){
1060 GpStatus sts;
1062 *container = GdipAlloc(sizeof(GraphicsContainerItem));
1063 if(!(*container))
1064 return OutOfMemory;
1066 (*container)->contid = graphics->contid + 1;
1068 (*container)->smoothing = graphics->smoothing;
1069 (*container)->compqual = graphics->compqual;
1070 (*container)->interpolation = graphics->interpolation;
1071 (*container)->compmode = graphics->compmode;
1072 (*container)->texthint = graphics->texthint;
1073 (*container)->scale = graphics->scale;
1074 (*container)->unit = graphics->unit;
1075 (*container)->textcontrast = graphics->textcontrast;
1076 (*container)->pixeloffset = graphics->pixeloffset;
1078 sts = GdipCloneMatrix(graphics->worldtrans, &(*container)->worldtrans);
1079 if(sts != Ok){
1080 GdipFree(*container);
1081 *container = NULL;
1082 return sts;
1085 sts = GdipCloneRegion(graphics->clip, &(*container)->clip);
1086 if(sts != Ok){
1087 GdipDeleteMatrix((*container)->worldtrans);
1088 GdipFree(*container);
1089 *container = NULL;
1090 return sts;
1093 return Ok;
1096 static void delete_container(GraphicsContainerItem* container){
1097 GdipDeleteMatrix(container->worldtrans);
1098 GdipDeleteRegion(container->clip);
1099 GdipFree(container);
1102 static GpStatus restore_container(GpGraphics* graphics,
1103 GDIPCONST GraphicsContainerItem* container){
1104 GpStatus sts;
1105 GpMatrix *newTrans;
1106 GpRegion *newClip;
1108 sts = GdipCloneMatrix(container->worldtrans, &newTrans);
1109 if(sts != Ok)
1110 return sts;
1112 sts = GdipCloneRegion(container->clip, &newClip);
1113 if(sts != Ok){
1114 GdipDeleteMatrix(newTrans);
1115 return sts;
1118 GdipDeleteMatrix(graphics->worldtrans);
1119 graphics->worldtrans = newTrans;
1121 GdipDeleteRegion(graphics->clip);
1122 graphics->clip = newClip;
1124 graphics->contid = container->contid - 1;
1126 graphics->smoothing = container->smoothing;
1127 graphics->compqual = container->compqual;
1128 graphics->interpolation = container->interpolation;
1129 graphics->compmode = container->compmode;
1130 graphics->texthint = container->texthint;
1131 graphics->scale = container->scale;
1132 graphics->unit = container->unit;
1133 graphics->textcontrast = container->textcontrast;
1134 graphics->pixeloffset = container->pixeloffset;
1136 return Ok;
1139 static GpStatus get_graphics_bounds(GpGraphics* graphics, GpRectF* rect)
1141 RECT wnd_rect;
1142 GpStatus stat=Ok;
1143 GpUnit unit;
1145 if(graphics->hwnd) {
1146 if(!GetClientRect(graphics->hwnd, &wnd_rect))
1147 return GenericError;
1149 rect->X = wnd_rect.left;
1150 rect->Y = wnd_rect.top;
1151 rect->Width = wnd_rect.right - wnd_rect.left;
1152 rect->Height = wnd_rect.bottom - wnd_rect.top;
1153 }else if (graphics->image){
1154 stat = GdipGetImageBounds(graphics->image, rect, &unit);
1155 if (stat == Ok && unit != UnitPixel)
1156 FIXME("need to convert from unit %i\n", unit);
1157 }else{
1158 rect->X = 0;
1159 rect->Y = 0;
1160 rect->Width = GetDeviceCaps(graphics->hdc, HORZRES);
1161 rect->Height = GetDeviceCaps(graphics->hdc, VERTRES);
1164 return stat;
1167 /* on success, rgn will contain the region of the graphics object which
1168 * is visible after clipping has been applied */
1169 static GpStatus get_visible_clip_region(GpGraphics *graphics, GpRegion *rgn)
1171 GpStatus stat;
1172 GpRectF rectf;
1173 GpRegion* tmp;
1175 if((stat = get_graphics_bounds(graphics, &rectf)) != Ok)
1176 return stat;
1178 if((stat = GdipCreateRegion(&tmp)) != Ok)
1179 return stat;
1181 if((stat = GdipCombineRegionRect(tmp, &rectf, CombineModeReplace)) != Ok)
1182 goto end;
1184 if((stat = GdipCombineRegionRegion(tmp, graphics->clip, CombineModeIntersect)) != Ok)
1185 goto end;
1187 stat = GdipCombineRegionRegion(rgn, tmp, CombineModeReplace);
1189 end:
1190 GdipDeleteRegion(tmp);
1191 return stat;
1194 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
1196 TRACE("(%p, %p)\n", hdc, graphics);
1198 return GdipCreateFromHDC2(hdc, NULL, graphics);
1201 GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **graphics)
1203 GpStatus retval;
1205 TRACE("(%p, %p, %p)\n", hdc, hDevice, graphics);
1207 if(hDevice != NULL) {
1208 FIXME("Don't know how to handle parameter hDevice\n");
1209 return NotImplemented;
1212 if(hdc == NULL)
1213 return OutOfMemory;
1215 if(graphics == NULL)
1216 return InvalidParameter;
1218 *graphics = GdipAlloc(sizeof(GpGraphics));
1219 if(!*graphics) return OutOfMemory;
1221 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
1222 GdipFree(*graphics);
1223 return retval;
1226 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
1227 GdipFree((*graphics)->worldtrans);
1228 GdipFree(*graphics);
1229 return retval;
1232 (*graphics)->hdc = hdc;
1233 (*graphics)->hwnd = WindowFromDC(hdc);
1234 (*graphics)->owndc = FALSE;
1235 (*graphics)->smoothing = SmoothingModeDefault;
1236 (*graphics)->compqual = CompositingQualityDefault;
1237 (*graphics)->interpolation = InterpolationModeDefault;
1238 (*graphics)->pixeloffset = PixelOffsetModeDefault;
1239 (*graphics)->compmode = CompositingModeSourceOver;
1240 (*graphics)->unit = UnitDisplay;
1241 (*graphics)->scale = 1.0;
1242 (*graphics)->busy = FALSE;
1243 (*graphics)->textcontrast = 4;
1244 list_init(&(*graphics)->containers);
1245 (*graphics)->contid = 0;
1247 TRACE("<-- %p\n", *graphics);
1249 return Ok;
1252 GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics)
1254 GpStatus retval;
1256 *graphics = GdipAlloc(sizeof(GpGraphics));
1257 if(!*graphics) return OutOfMemory;
1259 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
1260 GdipFree(*graphics);
1261 return retval;
1264 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
1265 GdipFree((*graphics)->worldtrans);
1266 GdipFree(*graphics);
1267 return retval;
1270 (*graphics)->hdc = NULL;
1271 (*graphics)->hwnd = NULL;
1272 (*graphics)->owndc = FALSE;
1273 (*graphics)->image = image;
1274 (*graphics)->smoothing = SmoothingModeDefault;
1275 (*graphics)->compqual = CompositingQualityDefault;
1276 (*graphics)->interpolation = InterpolationModeDefault;
1277 (*graphics)->pixeloffset = PixelOffsetModeDefault;
1278 (*graphics)->compmode = CompositingModeSourceOver;
1279 (*graphics)->unit = UnitDisplay;
1280 (*graphics)->scale = 1.0;
1281 (*graphics)->busy = FALSE;
1282 (*graphics)->textcontrast = 4;
1283 list_init(&(*graphics)->containers);
1284 (*graphics)->contid = 0;
1286 TRACE("<-- %p\n", *graphics);
1288 return Ok;
1291 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
1293 GpStatus ret;
1294 HDC hdc;
1296 TRACE("(%p, %p)\n", hwnd, graphics);
1298 hdc = GetDC(hwnd);
1300 if((ret = GdipCreateFromHDC(hdc, graphics)) != Ok)
1302 ReleaseDC(hwnd, hdc);
1303 return ret;
1306 (*graphics)->hwnd = hwnd;
1307 (*graphics)->owndc = TRUE;
1309 return Ok;
1312 /* FIXME: no icm handling */
1313 GpStatus WINGDIPAPI GdipCreateFromHWNDICM(HWND hwnd, GpGraphics **graphics)
1315 TRACE("(%p, %p)\n", hwnd, graphics);
1317 return GdipCreateFromHWND(hwnd, graphics);
1320 GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
1321 GpMetafile **metafile)
1323 static int calls;
1325 TRACE("(%p,%i,%p)\n", hemf, delete, metafile);
1327 if(!hemf || !metafile)
1328 return InvalidParameter;
1330 if(!(calls++))
1331 FIXME("not implemented\n");
1333 return NotImplemented;
1336 GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
1337 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
1339 IStream *stream = NULL;
1340 UINT read;
1341 BYTE* copy;
1342 HENHMETAFILE hemf;
1343 GpStatus retval = Ok;
1345 TRACE("(%p, %d, %p, %p)\n", hwmf, delete, placeable, metafile);
1347 if(!hwmf || !metafile || !placeable)
1348 return InvalidParameter;
1350 *metafile = NULL;
1351 read = GetMetaFileBitsEx(hwmf, 0, NULL);
1352 if(!read)
1353 return GenericError;
1354 copy = GdipAlloc(read);
1355 GetMetaFileBitsEx(hwmf, read, copy);
1357 hemf = SetWinMetaFileBits(read, copy, NULL, NULL);
1358 GdipFree(copy);
1360 read = GetEnhMetaFileBits(hemf, 0, NULL);
1361 copy = GdipAlloc(read);
1362 GetEnhMetaFileBits(hemf, read, copy);
1363 DeleteEnhMetaFile(hemf);
1365 if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
1366 ERR("could not make stream\n");
1367 GdipFree(copy);
1368 retval = GenericError;
1369 goto err;
1372 *metafile = GdipAlloc(sizeof(GpMetafile));
1373 if(!*metafile){
1374 retval = OutOfMemory;
1375 goto err;
1378 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1379 (LPVOID*) &((*metafile)->image.picture)) != S_OK)
1381 retval = GenericError;
1382 goto err;
1386 (*metafile)->image.type = ImageTypeMetafile;
1387 memcpy(&(*metafile)->image.format, &ImageFormatWMF, sizeof(GUID));
1388 (*metafile)->image.palette_flags = 0;
1389 (*metafile)->image.palette_count = 0;
1390 (*metafile)->image.palette_size = 0;
1391 (*metafile)->image.palette_entries = NULL;
1392 (*metafile)->image.xres = (REAL)placeable->Inch;
1393 (*metafile)->image.yres = (REAL)placeable->Inch;
1394 (*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch);
1395 (*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Top) / ((REAL) placeable->Inch);
1396 (*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right
1397 - placeable->BoundingBox.Left));
1398 (*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom
1399 - placeable->BoundingBox.Top));
1400 (*metafile)->unit = UnitPixel;
1402 if(delete)
1403 DeleteMetaFile(hwmf);
1405 TRACE("<-- %p\n", *metafile);
1407 err:
1408 if (retval != Ok)
1409 GdipFree(*metafile);
1410 IStream_Release(stream);
1411 return retval;
1414 GpStatus WINGDIPAPI GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR *file,
1415 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
1417 HMETAFILE hmf = GetMetaFileW(file);
1419 TRACE("(%s, %p, %p)\n", debugstr_w(file), placeable, metafile);
1421 if(!hmf) return InvalidParameter;
1423 return GdipCreateMetafileFromWmf(hmf, TRUE, placeable, metafile);
1426 GpStatus WINGDIPAPI GdipCreateMetafileFromFile(GDIPCONST WCHAR *file,
1427 GpMetafile **metafile)
1429 FIXME("(%p, %p): stub\n", file, metafile);
1430 return NotImplemented;
1433 GpStatus WINGDIPAPI GdipCreateMetafileFromStream(IStream *stream,
1434 GpMetafile **metafile)
1436 FIXME("(%p, %p): stub\n", stream, metafile);
1437 return NotImplemented;
1440 GpStatus WINGDIPAPI GdipCreateStreamOnFile(GDIPCONST WCHAR * filename,
1441 UINT access, IStream **stream)
1443 DWORD dwMode;
1444 HRESULT ret;
1446 TRACE("(%s, %u, %p)\n", debugstr_w(filename), access, stream);
1448 if(!stream || !filename)
1449 return InvalidParameter;
1451 if(access & GENERIC_WRITE)
1452 dwMode = STGM_SHARE_DENY_WRITE | STGM_WRITE | STGM_CREATE;
1453 else if(access & GENERIC_READ)
1454 dwMode = STGM_SHARE_DENY_WRITE | STGM_READ | STGM_FAILIFTHERE;
1455 else
1456 return InvalidParameter;
1458 ret = SHCreateStreamOnFileW(filename, dwMode, stream);
1460 return hresult_to_status(ret);
1463 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
1465 GraphicsContainerItem *cont, *next;
1466 TRACE("(%p)\n", graphics);
1468 if(!graphics) return InvalidParameter;
1469 if(graphics->busy) return ObjectBusy;
1471 if(graphics->owndc)
1472 ReleaseDC(graphics->hwnd, graphics->hdc);
1474 LIST_FOR_EACH_ENTRY_SAFE(cont, next, &graphics->containers, GraphicsContainerItem, entry){
1475 list_remove(&cont->entry);
1476 delete_container(cont);
1479 GdipDeleteRegion(graphics->clip);
1480 GdipDeleteMatrix(graphics->worldtrans);
1481 GdipFree(graphics);
1483 return Ok;
1486 GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
1487 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1489 INT save_state, num_pts;
1490 GpPointF points[MAX_ARC_PTS];
1491 GpStatus retval;
1493 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
1494 width, height, startAngle, sweepAngle);
1496 if(!graphics || !pen || width <= 0 || height <= 0)
1497 return InvalidParameter;
1499 if(graphics->busy)
1500 return ObjectBusy;
1502 if (!graphics->hdc)
1504 FIXME("graphics object has no HDC\n");
1505 return Ok;
1508 num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
1510 save_state = prepare_dc(graphics, pen);
1512 retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
1514 restore_dc(graphics, save_state);
1516 return retval;
1519 GpStatus WINGDIPAPI GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x,
1520 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
1522 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
1523 width, height, startAngle, sweepAngle);
1525 return GdipDrawArc(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
1528 GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
1529 REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
1531 INT save_state;
1532 GpPointF pt[4];
1533 GpStatus retval;
1535 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1,
1536 x2, y2, x3, y3, x4, y4);
1538 if(!graphics || !pen)
1539 return InvalidParameter;
1541 if(graphics->busy)
1542 return ObjectBusy;
1544 if (!graphics->hdc)
1546 FIXME("graphics object has no HDC\n");
1547 return Ok;
1550 pt[0].X = x1;
1551 pt[0].Y = y1;
1552 pt[1].X = x2;
1553 pt[1].Y = y2;
1554 pt[2].X = x3;
1555 pt[2].Y = y3;
1556 pt[3].X = x4;
1557 pt[3].Y = y4;
1559 save_state = prepare_dc(graphics, pen);
1561 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
1563 restore_dc(graphics, save_state);
1565 return retval;
1568 GpStatus WINGDIPAPI GdipDrawBezierI(GpGraphics *graphics, GpPen *pen, INT x1,
1569 INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4)
1571 INT save_state;
1572 GpPointF pt[4];
1573 GpStatus retval;
1575 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics, pen, x1, y1,
1576 x2, y2, x3, y3, x4, y4);
1578 if(!graphics || !pen)
1579 return InvalidParameter;
1581 if(graphics->busy)
1582 return ObjectBusy;
1584 if (!graphics->hdc)
1586 FIXME("graphics object has no HDC\n");
1587 return Ok;
1590 pt[0].X = x1;
1591 pt[0].Y = y1;
1592 pt[1].X = x2;
1593 pt[1].Y = y2;
1594 pt[2].X = x3;
1595 pt[2].Y = y3;
1596 pt[3].X = x4;
1597 pt[3].Y = y4;
1599 save_state = prepare_dc(graphics, pen);
1601 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
1603 restore_dc(graphics, save_state);
1605 return retval;
1608 GpStatus WINGDIPAPI GdipDrawBeziers(GpGraphics *graphics, GpPen *pen,
1609 GDIPCONST GpPointF *points, INT count)
1611 INT i;
1612 GpStatus ret;
1614 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1616 if(!graphics || !pen || !points || (count <= 0))
1617 return InvalidParameter;
1619 if(graphics->busy)
1620 return ObjectBusy;
1622 for(i = 0; i < floor(count / 4); i++){
1623 ret = GdipDrawBezier(graphics, pen,
1624 points[4*i].X, points[4*i].Y,
1625 points[4*i + 1].X, points[4*i + 1].Y,
1626 points[4*i + 2].X, points[4*i + 2].Y,
1627 points[4*i + 3].X, points[4*i + 3].Y);
1628 if(ret != Ok)
1629 return ret;
1632 return Ok;
1635 GpStatus WINGDIPAPI GdipDrawBeziersI(GpGraphics *graphics, GpPen *pen,
1636 GDIPCONST GpPoint *points, INT count)
1638 GpPointF *pts;
1639 GpStatus ret;
1640 INT i;
1642 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1644 if(!graphics || !pen || !points || (count <= 0))
1645 return InvalidParameter;
1647 if(graphics->busy)
1648 return ObjectBusy;
1650 pts = GdipAlloc(sizeof(GpPointF) * count);
1651 if(!pts)
1652 return OutOfMemory;
1654 for(i = 0; i < count; i++){
1655 pts[i].X = (REAL)points[i].X;
1656 pts[i].Y = (REAL)points[i].Y;
1659 ret = GdipDrawBeziers(graphics,pen,pts,count);
1661 GdipFree(pts);
1663 return ret;
1666 GpStatus WINGDIPAPI GdipDrawClosedCurve(GpGraphics *graphics, GpPen *pen,
1667 GDIPCONST GpPointF *points, INT count)
1669 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1671 return GdipDrawClosedCurve2(graphics, pen, points, count, 1.0);
1674 GpStatus WINGDIPAPI GdipDrawClosedCurveI(GpGraphics *graphics, GpPen *pen,
1675 GDIPCONST GpPoint *points, INT count)
1677 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1679 return GdipDrawClosedCurve2I(graphics, pen, points, count, 1.0);
1682 GpStatus WINGDIPAPI GdipDrawClosedCurve2(GpGraphics *graphics, GpPen *pen,
1683 GDIPCONST GpPointF *points, INT count, REAL tension)
1685 GpPath *path;
1686 GpStatus stat;
1688 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1690 if(!graphics || !pen || !points || count <= 0)
1691 return InvalidParameter;
1693 if(graphics->busy)
1694 return ObjectBusy;
1696 if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok)
1697 return stat;
1699 stat = GdipAddPathClosedCurve2(path, points, count, tension);
1700 if(stat != Ok){
1701 GdipDeletePath(path);
1702 return stat;
1705 stat = GdipDrawPath(graphics, pen, path);
1707 GdipDeletePath(path);
1709 return stat;
1712 GpStatus WINGDIPAPI GdipDrawClosedCurve2I(GpGraphics *graphics, GpPen *pen,
1713 GDIPCONST GpPoint *points, INT count, REAL tension)
1715 GpPointF *ptf;
1716 GpStatus stat;
1717 INT i;
1719 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1721 if(!points || count <= 0)
1722 return InvalidParameter;
1724 ptf = GdipAlloc(sizeof(GpPointF)*count);
1725 if(!ptf)
1726 return OutOfMemory;
1728 for(i = 0; i < count; i++){
1729 ptf[i].X = (REAL)points[i].X;
1730 ptf[i].Y = (REAL)points[i].Y;
1733 stat = GdipDrawClosedCurve2(graphics, pen, ptf, count, tension);
1735 GdipFree(ptf);
1737 return stat;
1740 GpStatus WINGDIPAPI GdipDrawCurve(GpGraphics *graphics, GpPen *pen,
1741 GDIPCONST GpPointF *points, INT count)
1743 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1745 return GdipDrawCurve2(graphics,pen,points,count,1.0);
1748 GpStatus WINGDIPAPI GdipDrawCurveI(GpGraphics *graphics, GpPen *pen,
1749 GDIPCONST GpPoint *points, INT count)
1751 GpPointF *pointsF;
1752 GpStatus ret;
1753 INT i;
1755 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1757 if(!points)
1758 return InvalidParameter;
1760 pointsF = GdipAlloc(sizeof(GpPointF)*count);
1761 if(!pointsF)
1762 return OutOfMemory;
1764 for(i = 0; i < count; i++){
1765 pointsF[i].X = (REAL)points[i].X;
1766 pointsF[i].Y = (REAL)points[i].Y;
1769 ret = GdipDrawCurve(graphics,pen,pointsF,count);
1770 GdipFree(pointsF);
1772 return ret;
1775 /* Approximates cardinal spline with Bezier curves. */
1776 GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
1777 GDIPCONST GpPointF *points, INT count, REAL tension)
1779 /* PolyBezier expects count*3-2 points. */
1780 INT i, len_pt = count*3-2, save_state;
1781 GpPointF *pt;
1782 REAL x1, x2, y1, y2;
1783 GpStatus retval;
1785 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1787 if(!graphics || !pen)
1788 return InvalidParameter;
1790 if(graphics->busy)
1791 return ObjectBusy;
1793 if(count < 2)
1794 return InvalidParameter;
1796 if (!graphics->hdc)
1798 FIXME("graphics object has no HDC\n");
1799 return Ok;
1802 pt = GdipAlloc(len_pt * sizeof(GpPointF));
1803 if(!pt)
1804 return OutOfMemory;
1806 tension = tension * TENSION_CONST;
1808 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
1809 tension, &x1, &y1);
1811 pt[0].X = points[0].X;
1812 pt[0].Y = points[0].Y;
1813 pt[1].X = x1;
1814 pt[1].Y = y1;
1816 for(i = 0; i < count-2; i++){
1817 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
1819 pt[3*i+2].X = x1;
1820 pt[3*i+2].Y = y1;
1821 pt[3*i+3].X = points[i+1].X;
1822 pt[3*i+3].Y = points[i+1].Y;
1823 pt[3*i+4].X = x2;
1824 pt[3*i+4].Y = y2;
1827 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
1828 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
1830 pt[len_pt-2].X = x1;
1831 pt[len_pt-2].Y = y1;
1832 pt[len_pt-1].X = points[count-1].X;
1833 pt[len_pt-1].Y = points[count-1].Y;
1835 save_state = prepare_dc(graphics, pen);
1837 retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
1839 GdipFree(pt);
1840 restore_dc(graphics, save_state);
1842 return retval;
1845 GpStatus WINGDIPAPI GdipDrawCurve2I(GpGraphics *graphics, GpPen *pen,
1846 GDIPCONST GpPoint *points, INT count, REAL tension)
1848 GpPointF *pointsF;
1849 GpStatus ret;
1850 INT i;
1852 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1854 if(!points)
1855 return InvalidParameter;
1857 pointsF = GdipAlloc(sizeof(GpPointF)*count);
1858 if(!pointsF)
1859 return OutOfMemory;
1861 for(i = 0; i < count; i++){
1862 pointsF[i].X = (REAL)points[i].X;
1863 pointsF[i].Y = (REAL)points[i].Y;
1866 ret = GdipDrawCurve2(graphics,pen,pointsF,count,tension);
1867 GdipFree(pointsF);
1869 return ret;
1872 GpStatus WINGDIPAPI GdipDrawCurve3(GpGraphics *graphics, GpPen *pen,
1873 GDIPCONST GpPointF *points, INT count, INT offset, INT numberOfSegments,
1874 REAL tension)
1876 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
1878 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
1879 return InvalidParameter;
1882 return GdipDrawCurve2(graphics, pen, points + offset, numberOfSegments + 1, tension);
1885 GpStatus WINGDIPAPI GdipDrawCurve3I(GpGraphics *graphics, GpPen *pen,
1886 GDIPCONST GpPoint *points, INT count, INT offset, INT numberOfSegments,
1887 REAL tension)
1889 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
1891 if(count < 0){
1892 return OutOfMemory;
1895 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
1896 return InvalidParameter;
1899 return GdipDrawCurve2I(graphics, pen, points + offset, numberOfSegments + 1, tension);
1902 GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics *graphics, GpPen *pen, REAL x,
1903 REAL y, REAL width, REAL height)
1905 INT save_state;
1906 GpPointF ptf[2];
1907 POINT pti[2];
1909 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
1911 if(!graphics || !pen)
1912 return InvalidParameter;
1914 if(graphics->busy)
1915 return ObjectBusy;
1917 if (!graphics->hdc)
1919 FIXME("graphics object has no HDC\n");
1920 return Ok;
1923 ptf[0].X = x;
1924 ptf[0].Y = y;
1925 ptf[1].X = x + width;
1926 ptf[1].Y = y + height;
1928 save_state = prepare_dc(graphics, pen);
1929 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1931 transform_and_round_points(graphics, pti, ptf, 2);
1933 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
1935 restore_dc(graphics, save_state);
1937 return Ok;
1940 GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics *graphics, GpPen *pen, INT x,
1941 INT y, INT width, INT height)
1943 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
1945 return GdipDrawEllipse(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1949 GpStatus WINGDIPAPI GdipDrawImage(GpGraphics *graphics, GpImage *image, REAL x, REAL y)
1951 UINT width, height;
1952 GpPointF points[3];
1954 TRACE("(%p, %p, %.2f, %.2f)\n", graphics, image, x, y);
1956 if(!graphics || !image)
1957 return InvalidParameter;
1959 GdipGetImageWidth(image, &width);
1960 GdipGetImageHeight(image, &height);
1962 /* FIXME: we should use the graphics and image dpi, somehow */
1964 points[0].X = points[2].X = x;
1965 points[0].Y = points[1].Y = y;
1966 points[1].X = x + width;
1967 points[2].Y = y + height;
1969 return GdipDrawImagePointsRect(graphics, image, points, 3, 0, 0, width, height,
1970 UnitPixel, NULL, NULL, NULL);
1973 GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x,
1974 INT y)
1976 TRACE("(%p, %p, %d, %d)\n", graphics, image, x, y);
1978 return GdipDrawImage(graphics, image, (REAL)x, (REAL)y);
1981 GpStatus WINGDIPAPI GdipDrawImagePointRect(GpGraphics *graphics, GpImage *image,
1982 REAL x, REAL y, REAL srcx, REAL srcy, REAL srcwidth, REAL srcheight,
1983 GpUnit srcUnit)
1985 GpPointF points[3];
1986 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
1988 points[0].X = points[2].X = x;
1989 points[0].Y = points[1].Y = y;
1991 /* FIXME: convert image coordinates to Graphics coordinates? */
1992 points[1].X = x + srcwidth;
1993 points[2].Y = y + srcheight;
1995 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
1996 srcwidth, srcheight, srcUnit, NULL, NULL, NULL);
1999 GpStatus WINGDIPAPI GdipDrawImagePointRectI(GpGraphics *graphics, GpImage *image,
2000 INT x, INT y, INT srcx, INT srcy, INT srcwidth, INT srcheight,
2001 GpUnit srcUnit)
2003 return GdipDrawImagePointRect(graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
2006 GpStatus WINGDIPAPI GdipDrawImagePoints(GpGraphics *graphics, GpImage *image,
2007 GDIPCONST GpPointF *dstpoints, INT count)
2009 FIXME("(%p, %p, %p, %d): stub\n", graphics, image, dstpoints, count);
2010 return NotImplemented;
2013 GpStatus WINGDIPAPI GdipDrawImagePointsI(GpGraphics *graphics, GpImage *image,
2014 GDIPCONST GpPoint *dstpoints, INT count)
2016 FIXME("(%p, %p, %p, %d): stub\n", graphics, image, dstpoints, count);
2017 return NotImplemented;
2020 GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
2021 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
2022 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
2023 DrawImageAbort callback, VOID * callbackData)
2025 GpPointF ptf[4];
2026 POINT pti[4];
2027 REAL dx, dy;
2028 GpStatus stat;
2030 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics, image, points,
2031 count, srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
2032 callbackData);
2034 if(!graphics || !image || !points || count != 3)
2035 return InvalidParameter;
2037 TRACE("%s %s %s\n", debugstr_pointf(&points[0]), debugstr_pointf(&points[1]),
2038 debugstr_pointf(&points[2]));
2040 memcpy(ptf, points, 3 * sizeof(GpPointF));
2041 ptf[3].X = ptf[2].X + ptf[1].X - ptf[0].X;
2042 ptf[3].Y = ptf[2].Y + ptf[1].Y - ptf[0].Y;
2043 transform_and_round_points(graphics, pti, ptf, 4);
2045 if (image->picture)
2047 if (!graphics->hdc)
2049 FIXME("graphics object has no HDC\n");
2052 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2053 if(srcUnit == UnitInch)
2054 dx = dy = (REAL) INCH_HIMETRIC;
2055 else if(srcUnit == UnitPixel){
2056 dx = ((REAL) INCH_HIMETRIC) /
2057 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
2058 dy = ((REAL) INCH_HIMETRIC) /
2059 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
2061 else
2062 return NotImplemented;
2064 if(IPicture_Render(image->picture, graphics->hdc,
2065 pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
2066 srcx * dx, srcy * dy,
2067 srcwidth * dx, srcheight * dy,
2068 NULL) != S_OK){
2069 if(callback)
2070 callback(callbackData);
2071 return GenericError;
2074 else if (image->type == ImageTypeBitmap)
2076 GpBitmap* bitmap = (GpBitmap*)image;
2077 int use_software=0;
2079 if (srcUnit == UnitInch)
2080 dx = dy = 96.0; /* FIXME: use the image resolution */
2081 else if (srcUnit == UnitPixel)
2082 dx = dy = 1.0;
2083 else
2084 return NotImplemented;
2086 if (imageAttributes ||
2087 (graphics->image && graphics->image->type == ImageTypeBitmap) ||
2088 !((GpBitmap*)image)->hbitmap ||
2089 ptf[1].Y != ptf[0].Y || ptf[2].X != ptf[0].X)
2090 use_software = 1;
2092 if (use_software)
2094 RECT src_area, dst_area;
2095 int i, x, y, stride;
2096 GpMatrix *dst_to_src;
2097 REAL m11, m12, m21, m22, mdx, mdy;
2098 LPBYTE data;
2100 src_area.left = srcx*dx;
2101 src_area.top = srcy*dy;
2102 src_area.right = (srcx+srcwidth)*dx;
2103 src_area.bottom = (srcy+srcheight)*dy;
2105 dst_area.left = dst_area.right = pti[0].x;
2106 dst_area.top = dst_area.bottom = pti[0].y;
2107 for (i=1; i<4; i++)
2109 if (dst_area.left > pti[i].x) dst_area.left = pti[i].x;
2110 if (dst_area.right < pti[i].x) dst_area.right = pti[i].x;
2111 if (dst_area.top > pti[i].y) dst_area.top = pti[i].y;
2112 if (dst_area.bottom < pti[i].y) dst_area.bottom = pti[i].y;
2115 m11 = (ptf[1].X - ptf[0].X) / srcwidth;
2116 m21 = (ptf[2].X - ptf[0].X) / srcheight;
2117 mdx = ptf[0].X - m11 * srcx - m21 * srcy;
2118 m12 = (ptf[1].Y - ptf[0].Y) / srcwidth;
2119 m22 = (ptf[2].Y - ptf[0].Y) / srcheight;
2120 mdy = ptf[0].Y - m12 * srcx - m22 * srcy;
2122 stat = GdipCreateMatrix2(m11, m12, m21, m22, mdx, mdy, &dst_to_src);
2123 if (stat != Ok) return stat;
2125 stat = GdipInvertMatrix(dst_to_src);
2126 if (stat != Ok)
2128 GdipDeleteMatrix(dst_to_src);
2129 return stat;
2132 data = GdipAlloc(sizeof(ARGB) * (dst_area.right - dst_area.left) * (dst_area.bottom - dst_area.top));
2133 if (!data)
2135 GdipDeleteMatrix(dst_to_src);
2136 return OutOfMemory;
2139 stride = sizeof(ARGB) * (dst_area.right - dst_area.left);
2141 if (imageAttributes &&
2142 (imageAttributes->wrap != WrapModeClamp ||
2143 imageAttributes->outside_color != 0x00000000 ||
2144 imageAttributes->clamp))
2146 static int fixme;
2147 if (!fixme++)
2148 FIXME("Image wrap mode not implemented\n");
2151 for (x=dst_area.left; x<dst_area.right; x++)
2153 for (y=dst_area.top; y<dst_area.bottom; y++)
2155 GpPointF src_pointf;
2156 int src_x, src_y;
2157 ARGB *src_color;
2159 src_pointf.X = x;
2160 src_pointf.Y = y;
2162 GdipTransformMatrixPoints(dst_to_src, &src_pointf, 1);
2164 src_x = roundr(src_pointf.X);
2165 src_y = roundr(src_pointf.Y);
2167 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2169 if (src_x < src_area.left || src_x >= src_area.right ||
2170 src_y < src_area.top || src_y >= src_area.bottom)
2171 *src_color = 0;
2172 else
2173 GdipBitmapGetPixel(bitmap, src_x, src_y, src_color);
2177 GdipDeleteMatrix(dst_to_src);
2179 if (imageAttributes)
2181 if (imageAttributes->colorkeys[ColorAdjustTypeBitmap].enabled ||
2182 imageAttributes->colorkeys[ColorAdjustTypeDefault].enabled)
2184 const struct color_key *key;
2185 BYTE min_blue, min_green, min_red;
2186 BYTE max_blue, max_green, max_red;
2188 if (imageAttributes->colorkeys[ColorAdjustTypeBitmap].enabled)
2189 key = &imageAttributes->colorkeys[ColorAdjustTypeBitmap];
2190 else
2191 key = &imageAttributes->colorkeys[ColorAdjustTypeDefault];
2193 min_blue = key->low&0xff;
2194 min_green = (key->low>>8)&0xff;
2195 min_red = (key->low>>16)&0xff;
2197 max_blue = key->high&0xff;
2198 max_green = (key->high>>8)&0xff;
2199 max_red = (key->high>>16)&0xff;
2201 for (x=dst_area.left; x<dst_area.right; x++)
2202 for (y=dst_area.top; y<dst_area.bottom; y++)
2204 ARGB *src_color;
2205 BYTE blue, green, red;
2206 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2207 blue = *src_color&0xff;
2208 green = (*src_color>>8)&0xff;
2209 red = (*src_color>>16)&0xff;
2210 if (blue >= min_blue && green >= min_green && red >= min_red &&
2211 blue <= max_blue && green <= max_green && red <= max_red)
2212 *src_color = 0x00000000;
2216 if (imageAttributes->colorremaptables[ColorAdjustTypeBitmap].enabled ||
2217 imageAttributes->colorremaptables[ColorAdjustTypeDefault].enabled)
2219 const struct color_remap_table *table;
2221 if (imageAttributes->colorremaptables[ColorAdjustTypeBitmap].enabled)
2222 table = &imageAttributes->colorremaptables[ColorAdjustTypeBitmap];
2223 else
2224 table = &imageAttributes->colorremaptables[ColorAdjustTypeDefault];
2226 for (x=dst_area.left; x<dst_area.right; x++)
2227 for (y=dst_area.top; y<dst_area.bottom; y++)
2229 ARGB *src_color;
2230 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2231 for (i=0; i<table->mapsize; i++)
2233 if (*src_color == table->colormap[i].oldColor.Argb)
2235 *src_color = table->colormap[i].newColor.Argb;
2236 break;
2242 if (imageAttributes->colormatrices[ColorAdjustTypeBitmap].enabled ||
2243 imageAttributes->colormatrices[ColorAdjustTypeDefault].enabled)
2245 static int fixme;
2246 if (!fixme++)
2247 FIXME("Color transforms not implemented\n");
2250 if (imageAttributes->gamma_enabled[ColorAdjustTypeBitmap] ||
2251 imageAttributes->gamma_enabled[ColorAdjustTypeDefault])
2253 static int fixme;
2254 if (!fixme++)
2255 FIXME("Gamma adjustment not implemented\n");
2259 stat = alpha_blend_pixels(graphics, dst_area.left, dst_area.top,
2260 data, dst_area.right - dst_area.left, dst_area.bottom - dst_area.top, stride);
2262 GdipFree(data);
2264 return stat;
2266 else
2268 HDC hdc;
2269 int temp_hdc=0, temp_bitmap=0;
2270 HBITMAP hbitmap, old_hbm=NULL;
2272 if (!(bitmap->format == PixelFormat16bppRGB555 ||
2273 bitmap->format == PixelFormat24bppRGB ||
2274 bitmap->format == PixelFormat32bppRGB ||
2275 bitmap->format == PixelFormat32bppPARGB))
2277 BITMAPINFOHEADER bih;
2278 BYTE *temp_bits;
2279 PixelFormat dst_format;
2281 /* we can't draw a bitmap of this format directly */
2282 hdc = CreateCompatibleDC(0);
2283 temp_hdc = 1;
2284 temp_bitmap = 1;
2286 bih.biSize = sizeof(BITMAPINFOHEADER);
2287 bih.biWidth = bitmap->width;
2288 bih.biHeight = -bitmap->height;
2289 bih.biPlanes = 1;
2290 bih.biBitCount = 32;
2291 bih.biCompression = BI_RGB;
2292 bih.biSizeImage = 0;
2293 bih.biXPelsPerMeter = 0;
2294 bih.biYPelsPerMeter = 0;
2295 bih.biClrUsed = 0;
2296 bih.biClrImportant = 0;
2298 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
2299 (void**)&temp_bits, NULL, 0);
2301 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
2302 dst_format = PixelFormat32bppPARGB;
2303 else
2304 dst_format = PixelFormat32bppRGB;
2306 convert_pixels(bitmap->width, bitmap->height,
2307 bitmap->width*4, temp_bits, dst_format,
2308 bitmap->stride, bitmap->bits, bitmap->format, bitmap->image.palette_entries);
2310 else
2312 hbitmap = bitmap->hbitmap;
2313 hdc = bitmap->hdc;
2314 temp_hdc = (hdc == 0);
2317 if (temp_hdc)
2319 if (!hdc) hdc = CreateCompatibleDC(0);
2320 old_hbm = SelectObject(hdc, hbitmap);
2323 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
2325 BLENDFUNCTION bf;
2327 bf.BlendOp = AC_SRC_OVER;
2328 bf.BlendFlags = 0;
2329 bf.SourceConstantAlpha = 255;
2330 bf.AlphaFormat = AC_SRC_ALPHA;
2332 GdiAlphaBlend(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
2333 hdc, srcx*dx, srcy*dy, srcwidth*dx, srcheight*dy, bf);
2335 else
2337 StretchBlt(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
2338 hdc, srcx*dx, srcy*dy, srcwidth*dx, srcheight*dy, SRCCOPY);
2341 if (temp_hdc)
2343 SelectObject(hdc, old_hbm);
2344 DeleteDC(hdc);
2347 if (temp_bitmap)
2348 DeleteObject(hbitmap);
2351 else
2353 ERR("GpImage with no IPicture or HBITMAP?!\n");
2354 return NotImplemented;
2357 return Ok;
2360 GpStatus WINGDIPAPI GdipDrawImagePointsRectI(GpGraphics *graphics, GpImage *image,
2361 GDIPCONST GpPoint *points, INT count, INT srcx, INT srcy, INT srcwidth,
2362 INT srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
2363 DrawImageAbort callback, VOID * callbackData)
2365 GpPointF pointsF[3];
2366 INT i;
2368 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics, image, points, count,
2369 srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
2370 callbackData);
2372 if(!points || count!=3)
2373 return InvalidParameter;
2375 for(i = 0; i < count; i++){
2376 pointsF[i].X = (REAL)points[i].X;
2377 pointsF[i].Y = (REAL)points[i].Y;
2380 return GdipDrawImagePointsRect(graphics, image, pointsF, count, (REAL)srcx, (REAL)srcy,
2381 (REAL)srcwidth, (REAL)srcheight, srcUnit, imageAttributes,
2382 callback, callbackData);
2385 GpStatus WINGDIPAPI GdipDrawImageRectRect(GpGraphics *graphics, GpImage *image,
2386 REAL dstx, REAL dsty, REAL dstwidth, REAL dstheight, REAL srcx, REAL srcy,
2387 REAL srcwidth, REAL srcheight, GpUnit srcUnit,
2388 GDIPCONST GpImageAttributes* imageattr, DrawImageAbort callback,
2389 VOID * callbackData)
2391 GpPointF points[3];
2393 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
2394 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
2395 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
2397 points[0].X = dstx;
2398 points[0].Y = dsty;
2399 points[1].X = dstx + dstwidth;
2400 points[1].Y = dsty;
2401 points[2].X = dstx;
2402 points[2].Y = dsty + dstheight;
2404 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2405 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
2408 GpStatus WINGDIPAPI GdipDrawImageRectRectI(GpGraphics *graphics, GpImage *image,
2409 INT dstx, INT dsty, INT dstwidth, INT dstheight, INT srcx, INT srcy,
2410 INT srcwidth, INT srcheight, GpUnit srcUnit,
2411 GDIPCONST GpImageAttributes* imageAttributes, DrawImageAbort callback,
2412 VOID * callbackData)
2414 GpPointF points[3];
2416 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
2417 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
2418 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
2420 points[0].X = dstx;
2421 points[0].Y = dsty;
2422 points[1].X = dstx + dstwidth;
2423 points[1].Y = dsty;
2424 points[2].X = dstx;
2425 points[2].Y = dsty + dstheight;
2427 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2428 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
2431 GpStatus WINGDIPAPI GdipDrawImageRect(GpGraphics *graphics, GpImage *image,
2432 REAL x, REAL y, REAL width, REAL height)
2434 RectF bounds;
2435 GpUnit unit;
2436 GpStatus ret;
2438 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, image, x, y, width, height);
2440 if(!graphics || !image)
2441 return InvalidParameter;
2443 ret = GdipGetImageBounds(image, &bounds, &unit);
2444 if(ret != Ok)
2445 return ret;
2447 return GdipDrawImageRectRect(graphics, image, x, y, width, height,
2448 bounds.X, bounds.Y, bounds.Width, bounds.Height,
2449 unit, NULL, NULL, NULL);
2452 GpStatus WINGDIPAPI GdipDrawImageRectI(GpGraphics *graphics, GpImage *image,
2453 INT x, INT y, INT width, INT height)
2455 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, image, x, y, width, height);
2457 return GdipDrawImageRect(graphics, image, (REAL)x, (REAL)y, (REAL)width, (REAL)height);
2460 GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1,
2461 REAL y1, REAL x2, REAL y2)
2463 INT save_state;
2464 GpPointF pt[2];
2465 GpStatus retval;
2467 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1, x2, y2);
2469 if(!pen || !graphics)
2470 return InvalidParameter;
2472 if(graphics->busy)
2473 return ObjectBusy;
2475 if (!graphics->hdc)
2477 FIXME("graphics object has no HDC\n");
2478 return Ok;
2481 pt[0].X = x1;
2482 pt[0].Y = y1;
2483 pt[1].X = x2;
2484 pt[1].Y = y2;
2486 save_state = prepare_dc(graphics, pen);
2488 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
2490 restore_dc(graphics, save_state);
2492 return retval;
2495 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
2496 INT y1, INT x2, INT y2)
2498 INT save_state;
2499 GpPointF pt[2];
2500 GpStatus retval;
2502 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x1, y1, x2, y2);
2504 if(!pen || !graphics)
2505 return InvalidParameter;
2507 if(graphics->busy)
2508 return ObjectBusy;
2510 if (!graphics->hdc)
2512 FIXME("graphics object has no HDC\n");
2513 return Ok;
2516 pt[0].X = (REAL)x1;
2517 pt[0].Y = (REAL)y1;
2518 pt[1].X = (REAL)x2;
2519 pt[1].Y = (REAL)y2;
2521 save_state = prepare_dc(graphics, pen);
2523 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
2525 restore_dc(graphics, save_state);
2527 return retval;
2530 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
2531 GpPointF *points, INT count)
2533 INT save_state;
2534 GpStatus retval;
2536 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2538 if(!pen || !graphics || (count < 2))
2539 return InvalidParameter;
2541 if(graphics->busy)
2542 return ObjectBusy;
2544 if (!graphics->hdc)
2546 FIXME("graphics object has no HDC\n");
2547 return Ok;
2550 save_state = prepare_dc(graphics, pen);
2552 retval = draw_polyline(graphics, pen, points, count, TRUE);
2554 restore_dc(graphics, save_state);
2556 return retval;
2559 GpStatus WINGDIPAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, GDIPCONST
2560 GpPoint *points, INT count)
2562 INT save_state;
2563 GpStatus retval;
2564 GpPointF *ptf = NULL;
2565 int i;
2567 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2569 if(!pen || !graphics || (count < 2))
2570 return InvalidParameter;
2572 if(graphics->busy)
2573 return ObjectBusy;
2575 if (!graphics->hdc)
2577 FIXME("graphics object has no HDC\n");
2578 return Ok;
2581 ptf = GdipAlloc(count * sizeof(GpPointF));
2582 if(!ptf) return OutOfMemory;
2584 for(i = 0; i < count; i ++){
2585 ptf[i].X = (REAL) points[i].X;
2586 ptf[i].Y = (REAL) points[i].Y;
2589 save_state = prepare_dc(graphics, pen);
2591 retval = draw_polyline(graphics, pen, ptf, count, TRUE);
2593 restore_dc(graphics, save_state);
2595 GdipFree(ptf);
2596 return retval;
2599 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
2601 INT save_state;
2602 GpStatus retval;
2604 TRACE("(%p, %p, %p)\n", graphics, pen, path);
2606 if(!pen || !graphics)
2607 return InvalidParameter;
2609 if(graphics->busy)
2610 return ObjectBusy;
2612 if (!graphics->hdc)
2614 FIXME("graphics object has no HDC\n");
2615 return Ok;
2618 save_state = prepare_dc(graphics, pen);
2620 retval = draw_poly(graphics, pen, path->pathdata.Points,
2621 path->pathdata.Types, path->pathdata.Count, TRUE);
2623 restore_dc(graphics, save_state);
2625 return retval;
2628 GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
2629 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2631 INT save_state;
2633 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
2634 width, height, startAngle, sweepAngle);
2636 if(!graphics || !pen)
2637 return InvalidParameter;
2639 if(graphics->busy)
2640 return ObjectBusy;
2642 if (!graphics->hdc)
2644 FIXME("graphics object has no HDC\n");
2645 return Ok;
2648 save_state = prepare_dc(graphics, pen);
2649 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2651 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
2653 restore_dc(graphics, save_state);
2655 return Ok;
2658 GpStatus WINGDIPAPI GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x,
2659 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2661 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
2662 width, height, startAngle, sweepAngle);
2664 return GdipDrawPie(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2667 GpStatus WINGDIPAPI GdipDrawRectangle(GpGraphics *graphics, GpPen *pen, REAL x,
2668 REAL y, REAL width, REAL height)
2670 INT save_state;
2671 GpPointF ptf[4];
2672 POINT pti[4];
2674 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
2676 if(!pen || !graphics)
2677 return InvalidParameter;
2679 if(graphics->busy)
2680 return ObjectBusy;
2682 if (!graphics->hdc)
2684 FIXME("graphics object has no HDC\n");
2685 return Ok;
2688 ptf[0].X = x;
2689 ptf[0].Y = y;
2690 ptf[1].X = x + width;
2691 ptf[1].Y = y;
2692 ptf[2].X = x + width;
2693 ptf[2].Y = y + height;
2694 ptf[3].X = x;
2695 ptf[3].Y = y + height;
2697 save_state = prepare_dc(graphics, pen);
2698 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2700 transform_and_round_points(graphics, pti, ptf, 4);
2701 Polygon(graphics->hdc, pti, 4);
2703 restore_dc(graphics, save_state);
2705 return Ok;
2708 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
2709 INT y, INT width, INT height)
2711 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
2713 return GdipDrawRectangle(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2716 GpStatus WINGDIPAPI GdipDrawRectangles(GpGraphics *graphics, GpPen *pen,
2717 GDIPCONST GpRectF* rects, INT count)
2719 GpPointF *ptf;
2720 POINT *pti;
2721 INT save_state, i;
2723 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
2725 if(!graphics || !pen || !rects || count < 1)
2726 return InvalidParameter;
2728 if(graphics->busy)
2729 return ObjectBusy;
2731 if (!graphics->hdc)
2733 FIXME("graphics object has no HDC\n");
2734 return Ok;
2737 ptf = GdipAlloc(4 * count * sizeof(GpPointF));
2738 pti = GdipAlloc(4 * count * sizeof(POINT));
2740 if(!ptf || !pti){
2741 GdipFree(ptf);
2742 GdipFree(pti);
2743 return OutOfMemory;
2746 for(i = 0; i < count; i++){
2747 ptf[4 * i + 3].X = ptf[4 * i].X = rects[i].X;
2748 ptf[4 * i + 1].Y = ptf[4 * i].Y = rects[i].Y;
2749 ptf[4 * i + 2].X = ptf[4 * i + 1].X = rects[i].X + rects[i].Width;
2750 ptf[4 * i + 3].Y = ptf[4 * i + 2].Y = rects[i].Y + rects[i].Height;
2753 save_state = prepare_dc(graphics, pen);
2754 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2756 transform_and_round_points(graphics, pti, ptf, 4 * count);
2758 for(i = 0; i < count; i++)
2759 Polygon(graphics->hdc, &pti[4 * i], 4);
2761 restore_dc(graphics, save_state);
2763 GdipFree(ptf);
2764 GdipFree(pti);
2766 return Ok;
2769 GpStatus WINGDIPAPI GdipDrawRectanglesI(GpGraphics *graphics, GpPen *pen,
2770 GDIPCONST GpRect* rects, INT count)
2772 GpRectF *rectsF;
2773 GpStatus ret;
2774 INT i;
2776 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
2778 if(!rects || count<=0)
2779 return InvalidParameter;
2781 rectsF = GdipAlloc(sizeof(GpRectF) * count);
2782 if(!rectsF)
2783 return OutOfMemory;
2785 for(i = 0;i < count;i++){
2786 rectsF[i].X = (REAL)rects[i].X;
2787 rectsF[i].Y = (REAL)rects[i].Y;
2788 rectsF[i].Width = (REAL)rects[i].Width;
2789 rectsF[i].Height = (REAL)rects[i].Height;
2792 ret = GdipDrawRectangles(graphics, pen, rectsF, count);
2793 GdipFree(rectsF);
2795 return ret;
2798 GpStatus WINGDIPAPI GdipFillClosedCurve2(GpGraphics *graphics, GpBrush *brush,
2799 GDIPCONST GpPointF *points, INT count, REAL tension, GpFillMode fill)
2801 GpPath *path;
2802 GpStatus stat;
2804 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2805 count, tension, fill);
2807 if(!graphics || !brush || !points)
2808 return InvalidParameter;
2810 if(graphics->busy)
2811 return ObjectBusy;
2813 if(count == 1) /* Do nothing */
2814 return Ok;
2816 stat = GdipCreatePath(fill, &path);
2817 if(stat != Ok)
2818 return stat;
2820 stat = GdipAddPathClosedCurve2(path, points, count, tension);
2821 if(stat != Ok){
2822 GdipDeletePath(path);
2823 return stat;
2826 stat = GdipFillPath(graphics, brush, path);
2827 if(stat != Ok){
2828 GdipDeletePath(path);
2829 return stat;
2832 GdipDeletePath(path);
2834 return Ok;
2837 GpStatus WINGDIPAPI GdipFillClosedCurve2I(GpGraphics *graphics, GpBrush *brush,
2838 GDIPCONST GpPoint *points, INT count, REAL tension, GpFillMode fill)
2840 GpPointF *ptf;
2841 GpStatus stat;
2842 INT i;
2844 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2845 count, tension, fill);
2847 if(!points || count == 0)
2848 return InvalidParameter;
2850 if(count == 1) /* Do nothing */
2851 return Ok;
2853 ptf = GdipAlloc(sizeof(GpPointF)*count);
2854 if(!ptf)
2855 return OutOfMemory;
2857 for(i = 0;i < count;i++){
2858 ptf[i].X = (REAL)points[i].X;
2859 ptf[i].Y = (REAL)points[i].Y;
2862 stat = GdipFillClosedCurve2(graphics, brush, ptf, count, tension, fill);
2864 GdipFree(ptf);
2866 return stat;
2869 GpStatus WINGDIPAPI GdipFillClosedCurve(GpGraphics *graphics, GpBrush *brush,
2870 GDIPCONST GpPointF *points, INT count)
2872 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
2873 return GdipFillClosedCurve2(graphics, brush, points, count,
2874 0.5f, FillModeAlternate);
2877 GpStatus WINGDIPAPI GdipFillClosedCurveI(GpGraphics *graphics, GpBrush *brush,
2878 GDIPCONST GpPoint *points, INT count)
2880 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
2881 return GdipFillClosedCurve2I(graphics, brush, points, count,
2882 0.5f, FillModeAlternate);
2885 GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x,
2886 REAL y, REAL width, REAL height)
2888 INT save_state;
2889 GpPointF ptf[2];
2890 POINT pti[2];
2892 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
2894 if(!graphics || !brush)
2895 return InvalidParameter;
2897 if(graphics->busy)
2898 return ObjectBusy;
2900 if(!graphics->hdc)
2902 FIXME("graphics object has no HDC\n");
2903 return Ok;
2906 ptf[0].X = x;
2907 ptf[0].Y = y;
2908 ptf[1].X = x + width;
2909 ptf[1].Y = y + height;
2911 save_state = SaveDC(graphics->hdc);
2912 EndPath(graphics->hdc);
2914 transform_and_round_points(graphics, pti, ptf, 2);
2916 BeginPath(graphics->hdc);
2917 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
2918 EndPath(graphics->hdc);
2920 brush_fill_path(graphics, brush);
2922 RestoreDC(graphics->hdc, save_state);
2924 return Ok;
2927 GpStatus WINGDIPAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x,
2928 INT y, INT width, INT height)
2930 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
2932 return GdipFillEllipse(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2935 GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
2937 INT save_state;
2938 GpStatus retval;
2940 TRACE("(%p, %p, %p)\n", graphics, brush, path);
2942 if(!brush || !graphics || !path)
2943 return InvalidParameter;
2945 if(graphics->busy)
2946 return ObjectBusy;
2948 if(!graphics->hdc)
2950 FIXME("graphics object has no HDC\n");
2951 return Ok;
2954 save_state = SaveDC(graphics->hdc);
2955 EndPath(graphics->hdc);
2956 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
2957 : WINDING));
2959 BeginPath(graphics->hdc);
2960 retval = draw_poly(graphics, NULL, path->pathdata.Points,
2961 path->pathdata.Types, path->pathdata.Count, FALSE);
2963 if(retval != Ok)
2964 goto end;
2966 EndPath(graphics->hdc);
2967 brush_fill_path(graphics, brush);
2969 retval = Ok;
2971 end:
2972 RestoreDC(graphics->hdc, save_state);
2974 return retval;
2977 GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
2978 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2980 INT save_state;
2982 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2983 graphics, brush, x, y, width, height, startAngle, sweepAngle);
2985 if(!graphics || !brush)
2986 return InvalidParameter;
2988 if(graphics->busy)
2989 return ObjectBusy;
2991 if(!graphics->hdc)
2993 FIXME("graphics object has no HDC\n");
2994 return Ok;
2997 save_state = SaveDC(graphics->hdc);
2998 EndPath(graphics->hdc);
3000 BeginPath(graphics->hdc);
3001 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
3002 EndPath(graphics->hdc);
3004 brush_fill_path(graphics, brush);
3006 RestoreDC(graphics->hdc, save_state);
3008 return Ok;
3011 GpStatus WINGDIPAPI GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x,
3012 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
3014 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3015 graphics, brush, x, y, width, height, startAngle, sweepAngle);
3017 return GdipFillPie(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
3020 GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush,
3021 GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)
3023 INT save_state;
3024 GpPointF *ptf = NULL;
3025 POINT *pti = NULL;
3026 GpStatus retval = Ok;
3028 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
3030 if(!graphics || !brush || !points || !count)
3031 return InvalidParameter;
3033 if(graphics->busy)
3034 return ObjectBusy;
3036 if(!graphics->hdc)
3038 FIXME("graphics object has no HDC\n");
3039 return Ok;
3042 ptf = GdipAlloc(count * sizeof(GpPointF));
3043 pti = GdipAlloc(count * sizeof(POINT));
3044 if(!ptf || !pti){
3045 retval = OutOfMemory;
3046 goto end;
3049 memcpy(ptf, points, count * sizeof(GpPointF));
3051 save_state = SaveDC(graphics->hdc);
3052 EndPath(graphics->hdc);
3053 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
3054 : WINDING));
3056 transform_and_round_points(graphics, pti, ptf, count);
3058 BeginPath(graphics->hdc);
3059 Polygon(graphics->hdc, pti, count);
3060 EndPath(graphics->hdc);
3062 brush_fill_path(graphics, brush);
3064 RestoreDC(graphics->hdc, save_state);
3066 end:
3067 GdipFree(ptf);
3068 GdipFree(pti);
3070 return retval;
3073 GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
3074 GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
3076 INT save_state, i;
3077 GpPointF *ptf = NULL;
3078 POINT *pti = NULL;
3079 GpStatus retval = Ok;
3081 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
3083 if(!graphics || !brush || !points || !count)
3084 return InvalidParameter;
3086 if(graphics->busy)
3087 return ObjectBusy;
3089 if(!graphics->hdc)
3091 FIXME("graphics object has no HDC\n");
3092 return Ok;
3095 ptf = GdipAlloc(count * sizeof(GpPointF));
3096 pti = GdipAlloc(count * sizeof(POINT));
3097 if(!ptf || !pti){
3098 retval = OutOfMemory;
3099 goto end;
3102 for(i = 0; i < count; i ++){
3103 ptf[i].X = (REAL) points[i].X;
3104 ptf[i].Y = (REAL) points[i].Y;
3107 save_state = SaveDC(graphics->hdc);
3108 EndPath(graphics->hdc);
3109 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
3110 : WINDING));
3112 transform_and_round_points(graphics, pti, ptf, count);
3114 BeginPath(graphics->hdc);
3115 Polygon(graphics->hdc, pti, count);
3116 EndPath(graphics->hdc);
3118 brush_fill_path(graphics, brush);
3120 RestoreDC(graphics->hdc, save_state);
3122 end:
3123 GdipFree(ptf);
3124 GdipFree(pti);
3126 return retval;
3129 GpStatus WINGDIPAPI GdipFillPolygon2(GpGraphics *graphics, GpBrush *brush,
3130 GDIPCONST GpPointF *points, INT count)
3132 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3134 return GdipFillPolygon(graphics, brush, points, count, FillModeAlternate);
3137 GpStatus WINGDIPAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush,
3138 GDIPCONST GpPoint *points, INT count)
3140 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3142 return GdipFillPolygonI(graphics, brush, points, count, FillModeAlternate);
3145 GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics *graphics, GpBrush *brush,
3146 REAL x, REAL y, REAL width, REAL height)
3148 INT save_state;
3149 GpPointF ptf[4];
3150 POINT pti[4];
3152 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
3154 if(!graphics || !brush)
3155 return InvalidParameter;
3157 if(graphics->busy)
3158 return ObjectBusy;
3160 if(!graphics->hdc)
3162 FIXME("graphics object has no HDC\n");
3163 return Ok;
3166 ptf[0].X = x;
3167 ptf[0].Y = y;
3168 ptf[1].X = x + width;
3169 ptf[1].Y = y;
3170 ptf[2].X = x + width;
3171 ptf[2].Y = y + height;
3172 ptf[3].X = x;
3173 ptf[3].Y = y + height;
3175 save_state = SaveDC(graphics->hdc);
3176 EndPath(graphics->hdc);
3178 transform_and_round_points(graphics, pti, ptf, 4);
3180 BeginPath(graphics->hdc);
3181 Polygon(graphics->hdc, pti, 4);
3182 EndPath(graphics->hdc);
3184 brush_fill_path(graphics, brush);
3186 RestoreDC(graphics->hdc, save_state);
3188 return Ok;
3191 GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush,
3192 INT x, INT y, INT width, INT height)
3194 INT save_state;
3195 GpPointF ptf[4];
3196 POINT pti[4];
3198 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
3200 if(!graphics || !brush)
3201 return InvalidParameter;
3203 if(graphics->busy)
3204 return ObjectBusy;
3206 if(!graphics->hdc)
3208 FIXME("graphics object has no HDC\n");
3209 return Ok;
3212 ptf[0].X = x;
3213 ptf[0].Y = y;
3214 ptf[1].X = x + width;
3215 ptf[1].Y = y;
3216 ptf[2].X = x + width;
3217 ptf[2].Y = y + height;
3218 ptf[3].X = x;
3219 ptf[3].Y = y + height;
3221 save_state = SaveDC(graphics->hdc);
3222 EndPath(graphics->hdc);
3224 transform_and_round_points(graphics, pti, ptf, 4);
3226 BeginPath(graphics->hdc);
3227 Polygon(graphics->hdc, pti, 4);
3228 EndPath(graphics->hdc);
3230 brush_fill_path(graphics, brush);
3232 RestoreDC(graphics->hdc, save_state);
3234 return Ok;
3237 GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRectF *rects,
3238 INT count)
3240 GpStatus ret;
3241 INT i;
3243 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3245 if(!rects)
3246 return InvalidParameter;
3248 for(i = 0; i < count; i++){
3249 ret = GdipFillRectangle(graphics, brush, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
3250 if(ret != Ok) return ret;
3253 return Ok;
3256 GpStatus WINGDIPAPI GdipFillRectanglesI(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRect *rects,
3257 INT count)
3259 GpRectF *rectsF;
3260 GpStatus ret;
3261 INT i;
3263 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3265 if(!rects || count <= 0)
3266 return InvalidParameter;
3268 rectsF = GdipAlloc(sizeof(GpRectF)*count);
3269 if(!rectsF)
3270 return OutOfMemory;
3272 for(i = 0; i < count; i++){
3273 rectsF[i].X = (REAL)rects[i].X;
3274 rectsF[i].Y = (REAL)rects[i].Y;
3275 rectsF[i].X = (REAL)rects[i].Width;
3276 rectsF[i].Height = (REAL)rects[i].Height;
3279 ret = GdipFillRectangles(graphics,brush,rectsF,count);
3280 GdipFree(rectsF);
3282 return ret;
3285 static GpStatus GDI32_GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
3286 GpRegion* region)
3288 INT save_state;
3289 GpStatus status;
3290 HRGN hrgn;
3291 RECT rc;
3293 if(!graphics->hdc)
3294 return NotImplemented;
3296 status = GdipGetRegionHRgn(region, graphics, &hrgn);
3297 if(status != Ok)
3298 return status;
3300 save_state = SaveDC(graphics->hdc);
3301 EndPath(graphics->hdc);
3303 ExtSelectClipRgn(graphics->hdc, hrgn, RGN_AND);
3305 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
3307 BeginPath(graphics->hdc);
3308 Rectangle(graphics->hdc, rc.left, rc.top, rc.right, rc.bottom);
3309 EndPath(graphics->hdc);
3311 brush_fill_path(graphics, brush);
3314 RestoreDC(graphics->hdc, save_state);
3316 DeleteObject(hrgn);
3318 return Ok;
3321 /*****************************************************************************
3322 * GdipFillRegion [GDIPLUS.@]
3324 GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
3325 GpRegion* region)
3327 GpStatus stat;
3329 TRACE("(%p, %p, %p)\n", graphics, brush, region);
3331 if (!(graphics && brush && region))
3332 return InvalidParameter;
3334 if(graphics->busy)
3335 return ObjectBusy;
3337 stat = GDI32_GdipFillRegion(graphics, brush, region);
3339 if (stat == NotImplemented)
3341 FIXME("partially implemented\n");
3342 stat = Ok;
3345 return stat;
3348 GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention)
3350 TRACE("(%p,%u)\n", graphics, intention);
3352 if(!graphics)
3353 return InvalidParameter;
3355 if(graphics->busy)
3356 return ObjectBusy;
3358 /* We have no internal operation queue, so there's no need to clear it. */
3360 if (graphics->hdc)
3361 GdiFlush();
3363 return Ok;
3366 /*****************************************************************************
3367 * GdipGetClipBounds [GDIPLUS.@]
3369 GpStatus WINGDIPAPI GdipGetClipBounds(GpGraphics *graphics, GpRectF *rect)
3371 TRACE("(%p, %p)\n", graphics, rect);
3373 if(!graphics)
3374 return InvalidParameter;
3376 if(graphics->busy)
3377 return ObjectBusy;
3379 return GdipGetRegionBounds(graphics->clip, graphics, rect);
3382 /*****************************************************************************
3383 * GdipGetClipBoundsI [GDIPLUS.@]
3385 GpStatus WINGDIPAPI GdipGetClipBoundsI(GpGraphics *graphics, GpRect *rect)
3387 TRACE("(%p, %p)\n", graphics, rect);
3389 if(!graphics)
3390 return InvalidParameter;
3392 if(graphics->busy)
3393 return ObjectBusy;
3395 return GdipGetRegionBoundsI(graphics->clip, graphics, rect);
3398 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3399 GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics,
3400 CompositingMode *mode)
3402 TRACE("(%p, %p)\n", graphics, mode);
3404 if(!graphics || !mode)
3405 return InvalidParameter;
3407 if(graphics->busy)
3408 return ObjectBusy;
3410 *mode = graphics->compmode;
3412 return Ok;
3415 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3416 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
3417 CompositingQuality *quality)
3419 TRACE("(%p, %p)\n", graphics, quality);
3421 if(!graphics || !quality)
3422 return InvalidParameter;
3424 if(graphics->busy)
3425 return ObjectBusy;
3427 *quality = graphics->compqual;
3429 return Ok;
3432 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3433 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
3434 InterpolationMode *mode)
3436 TRACE("(%p, %p)\n", graphics, mode);
3438 if(!graphics || !mode)
3439 return InvalidParameter;
3441 if(graphics->busy)
3442 return ObjectBusy;
3444 *mode = graphics->interpolation;
3446 return Ok;
3449 /* FIXME: Need to handle color depths less than 24bpp */
3450 GpStatus WINGDIPAPI GdipGetNearestColor(GpGraphics *graphics, ARGB* argb)
3452 FIXME("(%p, %p): Passing color unmodified\n", graphics, argb);
3454 if(!graphics || !argb)
3455 return InvalidParameter;
3457 if(graphics->busy)
3458 return ObjectBusy;
3460 return Ok;
3463 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
3465 TRACE("(%p, %p)\n", graphics, scale);
3467 if(!graphics || !scale)
3468 return InvalidParameter;
3470 if(graphics->busy)
3471 return ObjectBusy;
3473 *scale = graphics->scale;
3475 return Ok;
3478 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
3480 TRACE("(%p, %p)\n", graphics, unit);
3482 if(!graphics || !unit)
3483 return InvalidParameter;
3485 if(graphics->busy)
3486 return ObjectBusy;
3488 *unit = graphics->unit;
3490 return Ok;
3493 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3494 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
3495 *mode)
3497 TRACE("(%p, %p)\n", graphics, mode);
3499 if(!graphics || !mode)
3500 return InvalidParameter;
3502 if(graphics->busy)
3503 return ObjectBusy;
3505 *mode = graphics->pixeloffset;
3507 return Ok;
3510 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3511 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
3513 TRACE("(%p, %p)\n", graphics, mode);
3515 if(!graphics || !mode)
3516 return InvalidParameter;
3518 if(graphics->busy)
3519 return ObjectBusy;
3521 *mode = graphics->smoothing;
3523 return Ok;
3526 GpStatus WINGDIPAPI GdipGetTextContrast(GpGraphics *graphics, UINT *contrast)
3528 TRACE("(%p, %p)\n", graphics, contrast);
3530 if(!graphics || !contrast)
3531 return InvalidParameter;
3533 *contrast = graphics->textcontrast;
3535 return Ok;
3538 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3539 GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics,
3540 TextRenderingHint *hint)
3542 TRACE("(%p, %p)\n", graphics, hint);
3544 if(!graphics || !hint)
3545 return InvalidParameter;
3547 if(graphics->busy)
3548 return ObjectBusy;
3550 *hint = graphics->texthint;
3552 return Ok;
3555 GpStatus WINGDIPAPI GdipGetVisibleClipBounds(GpGraphics *graphics, GpRectF *rect)
3557 GpRegion *clip_rgn;
3558 GpStatus stat;
3560 TRACE("(%p, %p)\n", graphics, rect);
3562 if(!graphics || !rect)
3563 return InvalidParameter;
3565 if(graphics->busy)
3566 return ObjectBusy;
3568 /* intersect window and graphics clipping regions */
3569 if((stat = GdipCreateRegion(&clip_rgn)) != Ok)
3570 return stat;
3572 if((stat = get_visible_clip_region(graphics, clip_rgn)) != Ok)
3573 goto cleanup;
3575 /* get bounds of the region */
3576 stat = GdipGetRegionBounds(clip_rgn, graphics, rect);
3578 cleanup:
3579 GdipDeleteRegion(clip_rgn);
3581 return stat;
3584 GpStatus WINGDIPAPI GdipGetVisibleClipBoundsI(GpGraphics *graphics, GpRect *rect)
3586 GpRectF rectf;
3587 GpStatus stat;
3589 TRACE("(%p, %p)\n", graphics, rect);
3591 if(!graphics || !rect)
3592 return InvalidParameter;
3594 if((stat = GdipGetVisibleClipBounds(graphics, &rectf)) == Ok)
3596 rect->X = roundr(rectf.X);
3597 rect->Y = roundr(rectf.Y);
3598 rect->Width = roundr(rectf.Width);
3599 rect->Height = roundr(rectf.Height);
3602 return stat;
3605 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
3607 TRACE("(%p, %p)\n", graphics, matrix);
3609 if(!graphics || !matrix)
3610 return InvalidParameter;
3612 if(graphics->busy)
3613 return ObjectBusy;
3615 *matrix = *graphics->worldtrans;
3616 return Ok;
3619 GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color)
3621 GpSolidFill *brush;
3622 GpStatus stat;
3623 GpRectF wnd_rect;
3625 TRACE("(%p, %x)\n", graphics, color);
3627 if(!graphics)
3628 return InvalidParameter;
3630 if(graphics->busy)
3631 return ObjectBusy;
3633 if((stat = GdipCreateSolidFill(color, &brush)) != Ok)
3634 return stat;
3636 if((stat = get_graphics_bounds(graphics, &wnd_rect)) != Ok){
3637 GdipDeleteBrush((GpBrush*)brush);
3638 return stat;
3641 GdipFillRectangle(graphics, (GpBrush*)brush, wnd_rect.X, wnd_rect.Y,
3642 wnd_rect.Width, wnd_rect.Height);
3644 GdipDeleteBrush((GpBrush*)brush);
3646 return Ok;
3649 GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics *graphics, BOOL *res)
3651 TRACE("(%p, %p)\n", graphics, res);
3653 if(!graphics || !res)
3654 return InvalidParameter;
3656 return GdipIsEmptyRegion(graphics->clip, graphics, res);
3659 GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics *graphics, REAL x, REAL y, BOOL *result)
3661 GpStatus stat;
3662 GpRegion* rgn;
3663 GpPointF pt;
3665 TRACE("(%p, %.2f, %.2f, %p)\n", graphics, x, y, result);
3667 if(!graphics || !result)
3668 return InvalidParameter;
3670 if(graphics->busy)
3671 return ObjectBusy;
3673 pt.X = x;
3674 pt.Y = y;
3675 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3676 CoordinateSpaceWorld, &pt, 1)) != Ok)
3677 return stat;
3679 if((stat = GdipCreateRegion(&rgn)) != Ok)
3680 return stat;
3682 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3683 goto cleanup;
3685 stat = GdipIsVisibleRegionPoint(rgn, pt.X, pt.Y, graphics, result);
3687 cleanup:
3688 GdipDeleteRegion(rgn);
3689 return stat;
3692 GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics *graphics, INT x, INT y, BOOL *result)
3694 return GdipIsVisiblePoint(graphics, (REAL)x, (REAL)y, result);
3697 GpStatus WINGDIPAPI GdipIsVisibleRect(GpGraphics *graphics, REAL x, REAL y, REAL width, REAL height, BOOL *result)
3699 GpStatus stat;
3700 GpRegion* rgn;
3701 GpPointF pts[2];
3703 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics, x, y, width, height, result);
3705 if(!graphics || !result)
3706 return InvalidParameter;
3708 if(graphics->busy)
3709 return ObjectBusy;
3711 pts[0].X = x;
3712 pts[0].Y = y;
3713 pts[1].X = x + width;
3714 pts[1].Y = y + height;
3716 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3717 CoordinateSpaceWorld, pts, 2)) != Ok)
3718 return stat;
3720 pts[1].X -= pts[0].X;
3721 pts[1].Y -= pts[0].Y;
3723 if((stat = GdipCreateRegion(&rgn)) != Ok)
3724 return stat;
3726 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3727 goto cleanup;
3729 stat = GdipIsVisibleRegionRect(rgn, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y, graphics, result);
3731 cleanup:
3732 GdipDeleteRegion(rgn);
3733 return stat;
3736 GpStatus WINGDIPAPI GdipIsVisibleRectI(GpGraphics *graphics, INT x, INT y, INT width, INT height, BOOL *result)
3738 return GdipIsVisibleRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, result);
3741 typedef GpStatus (*gdip_format_string_callback)(GpGraphics *graphics,
3742 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3743 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3744 INT lineno, const RectF *bounds, void *user_data);
3746 static GpStatus gdip_format_string(GpGraphics *graphics,
3747 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
3748 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3749 gdip_format_string_callback callback, void *user_data)
3751 WCHAR* stringdup;
3752 int sum = 0, height = 0, fit, fitcpy, i, j, lret, nwidth,
3753 nheight, lineend, lineno = 0;
3754 RectF bounds;
3755 StringAlignment halign;
3756 GpStatus stat = Ok;
3757 SIZE size;
3759 if(length == -1) length = lstrlenW(string);
3761 stringdup = GdipAlloc((length + 1) * sizeof(WCHAR));
3762 if(!stringdup) return OutOfMemory;
3764 nwidth = roundr(rect->Width);
3765 nheight = roundr(rect->Height);
3767 if (rect->Width >= INT_MAX || rect->Width < 0.5) nwidth = INT_MAX;
3768 if (rect->Height >= INT_MAX || rect->Width < 0.5) nheight = INT_MAX;
3770 for(i = 0, j = 0; i < length; i++){
3771 /* FIXME: This makes the indexes passed to callback inaccurate. */
3772 if(!isprintW(string[i]) && (string[i] != '\n'))
3773 continue;
3775 stringdup[j] = string[i];
3776 j++;
3779 length = j;
3781 if (format) halign = format->align;
3782 else halign = StringAlignmentNear;
3784 while(sum < length){
3785 GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum,
3786 nwidth, &fit, NULL, &size);
3787 fitcpy = fit;
3789 if(fit == 0)
3790 break;
3792 for(lret = 0; lret < fit; lret++)
3793 if(*(stringdup + sum + lret) == '\n')
3794 break;
3796 /* Line break code (may look strange, but it imitates windows). */
3797 if(lret < fit)
3798 lineend = fit = lret; /* this is not an off-by-one error */
3799 else if(fit < (length - sum)){
3800 if(*(stringdup + sum + fit) == ' ')
3801 while(*(stringdup + sum + fit) == ' ')
3802 fit++;
3803 else
3804 while(*(stringdup + sum + fit - 1) != ' '){
3805 fit--;
3807 if(*(stringdup + sum + fit) == '\t')
3808 break;
3810 if(fit == 0){
3811 fit = fitcpy;
3812 break;
3815 lineend = fit;
3816 while(*(stringdup + sum + lineend - 1) == ' ' ||
3817 *(stringdup + sum + lineend - 1) == '\t')
3818 lineend--;
3820 else
3821 lineend = fit;
3823 GetTextExtentExPointW(graphics->hdc, stringdup + sum, lineend,
3824 nwidth, &j, NULL, &size);
3826 bounds.Width = size.cx;
3828 if(height + size.cy > nheight)
3829 bounds.Height = nheight - (height + size.cy);
3830 else
3831 bounds.Height = size.cy;
3833 bounds.Y = rect->Y + height;
3835 switch (halign)
3837 case StringAlignmentNear:
3838 default:
3839 bounds.X = rect->X;
3840 break;
3841 case StringAlignmentCenter:
3842 bounds.X = rect->X + (rect->Width/2) - (bounds.Width/2);
3843 break;
3844 case StringAlignmentFar:
3845 bounds.X = rect->X + rect->Width - bounds.Width;
3846 break;
3849 stat = callback(graphics, stringdup, sum, lineend,
3850 font, rect, format, lineno, &bounds, user_data);
3852 if (stat != Ok)
3853 break;
3855 sum += fit + (lret < fitcpy ? 1 : 0);
3856 height += size.cy;
3857 lineno++;
3859 if(height > nheight)
3860 break;
3862 /* Stop if this was a linewrap (but not if it was a linebreak). */
3863 if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
3864 break;
3867 GdipFree(stringdup);
3869 return stat;
3872 struct measure_ranges_args {
3873 GpRegion **regions;
3876 static GpStatus measure_ranges_callback(GpGraphics *graphics,
3877 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3878 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3879 INT lineno, const RectF *bounds, void *user_data)
3881 int i;
3882 GpStatus stat = Ok;
3883 struct measure_ranges_args *args = user_data;
3885 for (i=0; i<format->range_count; i++)
3887 INT range_start = max(index, format->character_ranges[i].First);
3888 INT range_end = min(index+length, format->character_ranges[i].First+format->character_ranges[i].Length);
3889 if (range_start < range_end)
3891 GpRectF range_rect;
3892 SIZE range_size;
3894 range_rect.Y = bounds->Y;
3895 range_rect.Height = bounds->Height;
3897 GetTextExtentExPointW(graphics->hdc, string + index, range_start - index,
3898 INT_MAX, NULL, NULL, &range_size);
3899 range_rect.X = bounds->X + range_size.cx;
3901 GetTextExtentExPointW(graphics->hdc, string + index, range_end - index,
3902 INT_MAX, NULL, NULL, &range_size);
3903 range_rect.Width = (bounds->X + range_size.cx) - range_rect.X;
3905 stat = GdipCombineRegionRect(args->regions[i], &range_rect, CombineModeUnion);
3906 if (stat != Ok)
3907 break;
3911 return stat;
3914 GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,
3915 GDIPCONST WCHAR* string, INT length, GDIPCONST GpFont* font,
3916 GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat *stringFormat,
3917 INT regionCount, GpRegion** regions)
3919 GpStatus stat;
3920 int i;
3921 HFONT oldfont;
3922 struct measure_ranges_args args;
3923 HDC temp_hdc=NULL;
3925 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics, debugstr_w(string),
3926 length, font, debugstr_rectf(layoutRect), stringFormat, regionCount, regions);
3928 if (!(graphics && string && font && layoutRect && stringFormat && regions))
3929 return InvalidParameter;
3931 if (regionCount < stringFormat->range_count)
3932 return InvalidParameter;
3934 if(!graphics->hdc)
3936 temp_hdc = graphics->hdc = CreateCompatibleDC(0);
3937 if (!temp_hdc) return OutOfMemory;
3940 if (stringFormat->attr)
3941 TRACE("may be ignoring some format flags: attr %x\n", stringFormat->attr);
3943 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
3945 for (i=0; i<stringFormat->range_count; i++)
3947 stat = GdipSetEmpty(regions[i]);
3948 if (stat != Ok)
3949 return stat;
3952 args.regions = regions;
3954 stat = gdip_format_string(graphics, string, length, font, layoutRect, stringFormat,
3955 measure_ranges_callback, &args);
3957 DeleteObject(SelectObject(graphics->hdc, oldfont));
3959 if (temp_hdc)
3961 graphics->hdc = NULL;
3962 DeleteDC(temp_hdc);
3965 return stat;
3968 struct measure_string_args {
3969 RectF *bounds;
3970 INT *codepointsfitted;
3971 INT *linesfilled;
3974 static GpStatus measure_string_callback(GpGraphics *graphics,
3975 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3976 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3977 INT lineno, const RectF *bounds, void *user_data)
3979 struct measure_string_args *args = user_data;
3981 if (bounds->Width > args->bounds->Width)
3982 args->bounds->Width = bounds->Width;
3984 if (bounds->Height + bounds->Y > args->bounds->Height + args->bounds->Y)
3985 args->bounds->Height = bounds->Height + bounds->Y - args->bounds->Y;
3987 if (args->codepointsfitted)
3988 *args->codepointsfitted = index + length;
3990 if (args->linesfilled)
3991 (*args->linesfilled)++;
3993 return Ok;
3996 /* Find the smallest rectangle that bounds the text when it is printed in rect
3997 * according to the format options listed in format. If rect has 0 width and
3998 * height, then just find the smallest rectangle that bounds the text when it's
3999 * printed at location (rect->X, rect-Y). */
4000 GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
4001 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
4002 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
4003 INT *codepointsfitted, INT *linesfilled)
4005 HFONT oldfont;
4006 struct measure_string_args args;
4007 HDC temp_hdc=NULL;
4009 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics,
4010 debugstr_wn(string, length), length, font, debugstr_rectf(rect), format,
4011 bounds, codepointsfitted, linesfilled);
4013 if(!graphics || !string || !font || !rect || !bounds)
4014 return InvalidParameter;
4016 if(!graphics->hdc)
4018 temp_hdc = graphics->hdc = CreateCompatibleDC(0);
4019 if (!temp_hdc) return OutOfMemory;
4022 if(linesfilled) *linesfilled = 0;
4023 if(codepointsfitted) *codepointsfitted = 0;
4025 if(format)
4026 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4028 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
4030 bounds->X = rect->X;
4031 bounds->Y = rect->Y;
4032 bounds->Width = 0.0;
4033 bounds->Height = 0.0;
4035 args.bounds = bounds;
4036 args.codepointsfitted = codepointsfitted;
4037 args.linesfilled = linesfilled;
4039 gdip_format_string(graphics, string, length, font, rect, format,
4040 measure_string_callback, &args);
4042 DeleteObject(SelectObject(graphics->hdc, oldfont));
4044 if (temp_hdc)
4046 graphics->hdc = NULL;
4047 DeleteDC(temp_hdc);
4050 return Ok;
4053 struct draw_string_args {
4054 POINT drawbase;
4055 UINT drawflags;
4056 REAL ang_cos, ang_sin;
4059 static GpStatus draw_string_callback(GpGraphics *graphics,
4060 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4061 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4062 INT lineno, const RectF *bounds, void *user_data)
4064 struct draw_string_args *args = user_data;
4065 RECT drawcoord;
4067 drawcoord.left = drawcoord.right = args->drawbase.x + roundr(args->ang_sin * bounds->Y);
4068 drawcoord.top = drawcoord.bottom = args->drawbase.y + roundr(args->ang_cos * bounds->Y);
4070 DrawTextW(graphics->hdc, string + index, length, &drawcoord, args->drawflags);
4072 return Ok;
4075 GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string,
4076 INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect,
4077 GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush)
4079 HRGN rgn = NULL;
4080 HFONT gdifont;
4081 LOGFONTW lfw;
4082 TEXTMETRICW textmet;
4083 GpPointF pt[3], rectcpy[4];
4084 POINT corners[4];
4085 REAL angle, rel_width, rel_height;
4086 INT offsety = 0, save_state;
4087 struct draw_string_args args;
4088 RectF scaled_rect;
4090 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length),
4091 length, font, debugstr_rectf(rect), format, brush);
4093 if(!graphics || !string || !font || !brush || !rect)
4094 return InvalidParameter;
4096 if((brush->bt != BrushTypeSolidColor)){
4097 FIXME("not implemented for given parameters\n");
4098 return NotImplemented;
4101 if(!graphics->hdc)
4103 FIXME("graphics object has no HDC\n");
4104 return Ok;
4107 if(format){
4108 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4110 /* Should be no need to explicitly test for StringAlignmentNear as
4111 * that is default behavior if no alignment is passed. */
4112 if(format->vertalign != StringAlignmentNear){
4113 RectF bounds;
4114 GdipMeasureString(graphics, string, length, font, rect, format, &bounds, 0, 0);
4116 if(format->vertalign == StringAlignmentCenter)
4117 offsety = (rect->Height - bounds.Height) / 2;
4118 else if(format->vertalign == StringAlignmentFar)
4119 offsety = (rect->Height - bounds.Height);
4123 save_state = SaveDC(graphics->hdc);
4124 SetBkMode(graphics->hdc, TRANSPARENT);
4125 SetTextColor(graphics->hdc, brush->lb.lbColor);
4127 pt[0].X = 0.0;
4128 pt[0].Y = 0.0;
4129 pt[1].X = 1.0;
4130 pt[1].Y = 0.0;
4131 pt[2].X = 0.0;
4132 pt[2].Y = 1.0;
4133 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
4134 angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X));
4135 args.ang_cos = cos(angle);
4136 args.ang_sin = sin(angle);
4137 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
4138 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
4139 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
4140 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
4142 rectcpy[3].X = rectcpy[0].X = rect->X;
4143 rectcpy[1].Y = rectcpy[0].Y = rect->Y + offsety;
4144 rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width;
4145 rectcpy[3].Y = rectcpy[2].Y = rect->Y + offsety + rect->Height;
4146 transform_and_round_points(graphics, corners, rectcpy, 4);
4148 scaled_rect.X = 0.0;
4149 scaled_rect.Y = 0.0;
4150 scaled_rect.Width = rel_width * rect->Width;
4151 scaled_rect.Height = rel_height * rect->Height;
4153 if (roundr(scaled_rect.Width) != 0 && roundr(scaled_rect.Height) != 0)
4155 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4156 rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
4157 SelectClipRgn(graphics->hdc, rgn);
4160 /* Use gdi to find the font, then perform transformations on it (height,
4161 * width, angle). */
4162 SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
4163 GetTextMetricsW(graphics->hdc, &textmet);
4164 lfw = font->lfw;
4166 lfw.lfHeight = roundr(((REAL)lfw.lfHeight) * rel_height);
4167 lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width);
4169 lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0);
4171 gdifont = CreateFontIndirectW(&lfw);
4172 DeleteObject(SelectObject(graphics->hdc, CreateFontIndirectW(&lfw)));
4174 if (!format || format->align == StringAlignmentNear)
4176 args.drawbase.x = corners[0].x;
4177 args.drawbase.y = corners[0].y;
4178 args.drawflags = DT_NOCLIP | DT_EXPANDTABS;
4180 else if (format->align == StringAlignmentCenter)
4182 args.drawbase.x = (corners[0].x + corners[1].x)/2;
4183 args.drawbase.y = (corners[0].y + corners[1].y)/2;
4184 args.drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_CENTER;
4186 else /* (format->align == StringAlignmentFar) */
4188 args.drawbase.x = corners[1].x;
4189 args.drawbase.y = corners[1].y;
4190 args.drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_RIGHT;
4193 gdip_format_string(graphics, string, length, font, &scaled_rect, format,
4194 draw_string_callback, &args);
4196 DeleteObject(rgn);
4197 DeleteObject(gdifont);
4199 RestoreDC(graphics->hdc, save_state);
4201 return Ok;
4204 GpStatus WINGDIPAPI GdipResetClip(GpGraphics *graphics)
4206 TRACE("(%p)\n", graphics);
4208 if(!graphics)
4209 return InvalidParameter;
4211 if(graphics->busy)
4212 return ObjectBusy;
4214 return GdipSetInfinite(graphics->clip);
4217 GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics)
4219 TRACE("(%p)\n", graphics);
4221 if(!graphics)
4222 return InvalidParameter;
4224 if(graphics->busy)
4225 return ObjectBusy;
4227 graphics->worldtrans->matrix[0] = 1.0;
4228 graphics->worldtrans->matrix[1] = 0.0;
4229 graphics->worldtrans->matrix[2] = 0.0;
4230 graphics->worldtrans->matrix[3] = 1.0;
4231 graphics->worldtrans->matrix[4] = 0.0;
4232 graphics->worldtrans->matrix[5] = 0.0;
4234 return Ok;
4237 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
4239 return GdipEndContainer(graphics, state);
4242 GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
4243 GpMatrixOrder order)
4245 TRACE("(%p, %.2f, %d)\n", graphics, angle, order);
4247 if(!graphics)
4248 return InvalidParameter;
4250 if(graphics->busy)
4251 return ObjectBusy;
4253 return GdipRotateMatrix(graphics->worldtrans, angle, order);
4256 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
4258 return GdipBeginContainer2(graphics, state);
4261 GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics *graphics,
4262 GraphicsContainer *state)
4264 GraphicsContainerItem *container;
4265 GpStatus sts;
4267 TRACE("(%p, %p)\n", graphics, state);
4269 if(!graphics || !state)
4270 return InvalidParameter;
4272 sts = init_container(&container, graphics);
4273 if(sts != Ok)
4274 return sts;
4276 list_add_head(&graphics->containers, &container->entry);
4277 *state = graphics->contid = container->contid;
4279 return Ok;
4282 GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics *graphics, GDIPCONST GpRectF *dstrect, GDIPCONST GpRectF *srcrect, GpUnit unit, GraphicsContainer *state)
4284 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
4285 return NotImplemented;
4288 GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics *graphics, GDIPCONST GpRect *dstrect, GDIPCONST GpRect *srcrect, GpUnit unit, GraphicsContainer *state)
4290 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
4291 return NotImplemented;
4294 GpStatus WINGDIPAPI GdipComment(GpGraphics *graphics, UINT sizeData, GDIPCONST BYTE *data)
4296 FIXME("(%p, %d, %p): stub\n", graphics, sizeData, data);
4297 return NotImplemented;
4300 GpStatus WINGDIPAPI GdipEndContainer(GpGraphics *graphics, GraphicsContainer state)
4302 GpStatus sts;
4303 GraphicsContainerItem *container, *container2;
4305 TRACE("(%p, %x)\n", graphics, state);
4307 if(!graphics)
4308 return InvalidParameter;
4310 LIST_FOR_EACH_ENTRY(container, &graphics->containers, GraphicsContainerItem, entry){
4311 if(container->contid == state)
4312 break;
4315 /* did not find a matching container */
4316 if(&container->entry == &graphics->containers)
4317 return Ok;
4319 sts = restore_container(graphics, container);
4320 if(sts != Ok)
4321 return sts;
4323 /* remove all of the containers on top of the found container */
4324 LIST_FOR_EACH_ENTRY_SAFE(container, container2, &graphics->containers, GraphicsContainerItem, entry){
4325 if(container->contid == state)
4326 break;
4327 list_remove(&container->entry);
4328 delete_container(container);
4331 list_remove(&container->entry);
4332 delete_container(container);
4334 return Ok;
4337 GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
4338 REAL sy, GpMatrixOrder order)
4340 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, sx, sy, order);
4342 if(!graphics)
4343 return InvalidParameter;
4345 if(graphics->busy)
4346 return ObjectBusy;
4348 return GdipScaleMatrix(graphics->worldtrans, sx, sy, order);
4351 GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics *graphics, GpGraphics *srcgraphics,
4352 CombineMode mode)
4354 TRACE("(%p, %p, %d)\n", graphics, srcgraphics, mode);
4356 if(!graphics || !srcgraphics)
4357 return InvalidParameter;
4359 return GdipCombineRegionRegion(graphics->clip, srcgraphics->clip, mode);
4362 GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
4363 CompositingMode mode)
4365 TRACE("(%p, %d)\n", graphics, mode);
4367 if(!graphics)
4368 return InvalidParameter;
4370 if(graphics->busy)
4371 return ObjectBusy;
4373 graphics->compmode = mode;
4375 return Ok;
4378 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
4379 CompositingQuality quality)
4381 TRACE("(%p, %d)\n", graphics, quality);
4383 if(!graphics)
4384 return InvalidParameter;
4386 if(graphics->busy)
4387 return ObjectBusy;
4389 graphics->compqual = quality;
4391 return Ok;
4394 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
4395 InterpolationMode mode)
4397 TRACE("(%p, %d)\n", graphics, mode);
4399 if(!graphics)
4400 return InvalidParameter;
4402 if(graphics->busy)
4403 return ObjectBusy;
4405 graphics->interpolation = mode;
4407 return Ok;
4410 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
4412 TRACE("(%p, %.2f)\n", graphics, scale);
4414 if(!graphics || (scale <= 0.0))
4415 return InvalidParameter;
4417 if(graphics->busy)
4418 return ObjectBusy;
4420 graphics->scale = scale;
4422 return Ok;
4425 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
4427 TRACE("(%p, %d)\n", graphics, unit);
4429 if(!graphics)
4430 return InvalidParameter;
4432 if(graphics->busy)
4433 return ObjectBusy;
4435 if(unit == UnitWorld)
4436 return InvalidParameter;
4438 graphics->unit = unit;
4440 return Ok;
4443 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
4444 mode)
4446 TRACE("(%p, %d)\n", graphics, mode);
4448 if(!graphics)
4449 return InvalidParameter;
4451 if(graphics->busy)
4452 return ObjectBusy;
4454 graphics->pixeloffset = mode;
4456 return Ok;
4459 GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics *graphics, INT x, INT y)
4461 static int calls;
4463 TRACE("(%p,%i,%i)\n", graphics, x, y);
4465 if (!(calls++))
4466 FIXME("not implemented\n");
4468 return NotImplemented;
4471 GpStatus WINGDIPAPI GdipGetRenderingOrigin(GpGraphics *graphics, INT *x, INT *y)
4473 static int calls;
4475 TRACE("(%p,%p,%p)\n", graphics, x, y);
4477 if (!(calls++))
4478 FIXME("not implemented\n");
4480 *x = *y = 0;
4482 return NotImplemented;
4485 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
4487 TRACE("(%p, %d)\n", graphics, mode);
4489 if(!graphics)
4490 return InvalidParameter;
4492 if(graphics->busy)
4493 return ObjectBusy;
4495 graphics->smoothing = mode;
4497 return Ok;
4500 GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics *graphics, UINT contrast)
4502 TRACE("(%p, %d)\n", graphics, contrast);
4504 if(!graphics)
4505 return InvalidParameter;
4507 graphics->textcontrast = contrast;
4509 return Ok;
4512 GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
4513 TextRenderingHint hint)
4515 TRACE("(%p, %d)\n", graphics, hint);
4517 if(!graphics)
4518 return InvalidParameter;
4520 if(graphics->busy)
4521 return ObjectBusy;
4523 graphics->texthint = hint;
4525 return Ok;
4528 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
4530 TRACE("(%p, %p)\n", graphics, matrix);
4532 if(!graphics || !matrix)
4533 return InvalidParameter;
4535 if(graphics->busy)
4536 return ObjectBusy;
4538 GdipDeleteMatrix(graphics->worldtrans);
4539 return GdipCloneMatrix(matrix, &graphics->worldtrans);
4542 GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
4543 REAL dy, GpMatrixOrder order)
4545 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, dx, dy, order);
4547 if(!graphics)
4548 return InvalidParameter;
4550 if(graphics->busy)
4551 return ObjectBusy;
4553 return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order);
4556 /*****************************************************************************
4557 * GdipSetClipHrgn [GDIPLUS.@]
4559 GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics *graphics, HRGN hrgn, CombineMode mode)
4561 GpRegion *region;
4562 GpStatus status;
4564 TRACE("(%p, %p, %d)\n", graphics, hrgn, mode);
4566 if(!graphics)
4567 return InvalidParameter;
4569 status = GdipCreateRegionHrgn(hrgn, &region);
4570 if(status != Ok)
4571 return status;
4573 status = GdipSetClipRegion(graphics, region, mode);
4575 GdipDeleteRegion(region);
4576 return status;
4579 GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics *graphics, GpPath *path, CombineMode mode)
4581 TRACE("(%p, %p, %d)\n", graphics, path, mode);
4583 if(!graphics)
4584 return InvalidParameter;
4586 if(graphics->busy)
4587 return ObjectBusy;
4589 return GdipCombineRegionPath(graphics->clip, path, mode);
4592 GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y,
4593 REAL width, REAL height,
4594 CombineMode mode)
4596 GpRectF rect;
4598 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics, x, y, width, height, mode);
4600 if(!graphics)
4601 return InvalidParameter;
4603 if(graphics->busy)
4604 return ObjectBusy;
4606 rect.X = x;
4607 rect.Y = y;
4608 rect.Width = width;
4609 rect.Height = height;
4611 return GdipCombineRegionRect(graphics->clip, &rect, mode);
4614 GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y,
4615 INT width, INT height,
4616 CombineMode mode)
4618 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics, x, y, width, height, mode);
4620 if(!graphics)
4621 return InvalidParameter;
4623 if(graphics->busy)
4624 return ObjectBusy;
4626 return GdipSetClipRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, mode);
4629 GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
4630 CombineMode mode)
4632 TRACE("(%p, %p, %d)\n", graphics, region, mode);
4634 if(!graphics || !region)
4635 return InvalidParameter;
4637 if(graphics->busy)
4638 return ObjectBusy;
4640 return GdipCombineRegionRegion(graphics->clip, region, mode);
4643 GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile *metafile,
4644 UINT limitDpi)
4646 static int calls;
4648 TRACE("(%p,%u)\n", metafile, limitDpi);
4650 if(!(calls++))
4651 FIXME("not implemented\n");
4653 return NotImplemented;
4656 GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points,
4657 INT count)
4659 INT save_state;
4660 POINT *pti;
4662 TRACE("(%p, %p, %d)\n", graphics, points, count);
4664 if(!graphics || !pen || count<=0)
4665 return InvalidParameter;
4667 if(graphics->busy)
4668 return ObjectBusy;
4670 if (!graphics->hdc)
4672 FIXME("graphics object has no HDC\n");
4673 return Ok;
4676 pti = GdipAlloc(sizeof(POINT) * count);
4678 save_state = prepare_dc(graphics, pen);
4679 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
4681 transform_and_round_points(graphics, pti, (GpPointF*)points, count);
4682 Polygon(graphics->hdc, pti, count);
4684 restore_dc(graphics, save_state);
4685 GdipFree(pti);
4687 return Ok;
4690 GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points,
4691 INT count)
4693 GpStatus ret;
4694 GpPointF *ptf;
4695 INT i;
4697 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
4699 if(count<=0) return InvalidParameter;
4700 ptf = GdipAlloc(sizeof(GpPointF) * count);
4702 for(i = 0;i < count; i++){
4703 ptf[i].X = (REAL)points[i].X;
4704 ptf[i].Y = (REAL)points[i].Y;
4707 ret = GdipDrawPolygon(graphics,pen,ptf,count);
4708 GdipFree(ptf);
4710 return ret;
4713 GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
4715 TRACE("(%p, %p)\n", graphics, dpi);
4717 if(!graphics || !dpi)
4718 return InvalidParameter;
4720 if(graphics->busy)
4721 return ObjectBusy;
4723 if (graphics->image)
4724 *dpi = graphics->image->xres;
4725 else
4726 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
4728 return Ok;
4731 GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
4733 TRACE("(%p, %p)\n", graphics, dpi);
4735 if(!graphics || !dpi)
4736 return InvalidParameter;
4738 if(graphics->busy)
4739 return ObjectBusy;
4741 if (graphics->image)
4742 *dpi = graphics->image->yres;
4743 else
4744 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
4746 return Ok;
4749 GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix,
4750 GpMatrixOrder order)
4752 GpMatrix m;
4753 GpStatus ret;
4755 TRACE("(%p, %p, %d)\n", graphics, matrix, order);
4757 if(!graphics || !matrix)
4758 return InvalidParameter;
4760 if(graphics->busy)
4761 return ObjectBusy;
4763 m = *(graphics->worldtrans);
4765 ret = GdipMultiplyMatrix(&m, matrix, order);
4766 if(ret == Ok)
4767 *(graphics->worldtrans) = m;
4769 return ret;
4772 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
4773 static const COLORREF DC_BACKGROUND_KEY = 0x0c0b0d;
4775 GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
4777 TRACE("(%p, %p)\n", graphics, hdc);
4779 if(!graphics || !hdc)
4780 return InvalidParameter;
4782 if(graphics->busy)
4783 return ObjectBusy;
4785 if (!graphics->hdc ||
4786 (graphics->image && graphics->image->type == ImageTypeBitmap && ((GpBitmap*)graphics->image)->format & PixelFormatAlpha))
4788 /* Create a fake HDC and fill it with a constant color. */
4789 HDC temp_hdc;
4790 HBITMAP hbitmap;
4791 GpStatus stat;
4792 GpRectF bounds;
4793 BITMAPINFOHEADER bmih;
4794 int i;
4796 stat = get_graphics_bounds(graphics, &bounds);
4797 if (stat != Ok)
4798 return stat;
4800 graphics->temp_hbitmap_width = bounds.Width;
4801 graphics->temp_hbitmap_height = bounds.Height;
4803 bmih.biSize = sizeof(bmih);
4804 bmih.biWidth = graphics->temp_hbitmap_width;
4805 bmih.biHeight = -graphics->temp_hbitmap_height;
4806 bmih.biPlanes = 1;
4807 bmih.biBitCount = 32;
4808 bmih.biCompression = BI_RGB;
4809 bmih.biSizeImage = 0;
4810 bmih.biXPelsPerMeter = 0;
4811 bmih.biYPelsPerMeter = 0;
4812 bmih.biClrUsed = 0;
4813 bmih.biClrImportant = 0;
4815 hbitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
4816 (void**)&graphics->temp_bits, NULL, 0);
4817 if (!hbitmap)
4818 return GenericError;
4820 temp_hdc = CreateCompatibleDC(0);
4821 if (!temp_hdc)
4823 DeleteObject(hbitmap);
4824 return GenericError;
4827 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
4828 ((DWORD*)graphics->temp_bits)[i] = DC_BACKGROUND_KEY;
4830 SelectObject(temp_hdc, hbitmap);
4832 graphics->temp_hbitmap = hbitmap;
4833 *hdc = graphics->temp_hdc = temp_hdc;
4835 else
4837 *hdc = graphics->hdc;
4840 graphics->busy = TRUE;
4842 return Ok;
4845 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
4847 TRACE("(%p, %p)\n", graphics, hdc);
4849 if(!graphics || !hdc)
4850 return InvalidParameter;
4852 if((graphics->hdc != hdc && graphics->temp_hdc != hdc) || !(graphics->busy))
4853 return InvalidParameter;
4855 if (graphics->temp_hdc == hdc)
4857 DWORD* pos;
4858 int i;
4860 /* Find the pixels that have changed, and mark them as opaque. */
4861 pos = (DWORD*)graphics->temp_bits;
4862 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
4864 if (*pos != DC_BACKGROUND_KEY)
4866 *pos |= 0xff000000;
4868 pos++;
4871 /* Write the changed pixels to the real target. */
4872 alpha_blend_pixels(graphics, 0, 0, graphics->temp_bits,
4873 graphics->temp_hbitmap_width, graphics->temp_hbitmap_height,
4874 graphics->temp_hbitmap_width * 4);
4876 /* Clean up. */
4877 DeleteDC(graphics->temp_hdc);
4878 DeleteObject(graphics->temp_hbitmap);
4879 graphics->temp_hdc = NULL;
4880 graphics->temp_hbitmap = NULL;
4883 graphics->busy = FALSE;
4885 return Ok;
4888 GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
4890 GpRegion *clip;
4891 GpStatus status;
4893 TRACE("(%p, %p)\n", graphics, region);
4895 if(!graphics || !region)
4896 return InvalidParameter;
4898 if(graphics->busy)
4899 return ObjectBusy;
4901 if((status = GdipCloneRegion(graphics->clip, &clip)) != Ok)
4902 return status;
4904 /* free everything except root node and header */
4905 delete_element(&region->node);
4906 memcpy(region, clip, sizeof(GpRegion));
4907 GdipFree(clip);
4909 return Ok;
4912 GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space,
4913 GpCoordinateSpace src_space, GpPointF *points, INT count)
4915 GpMatrix *matrix;
4916 GpStatus stat;
4917 REAL unitscale;
4919 if(!graphics || !points || count <= 0)
4920 return InvalidParameter;
4922 if(graphics->busy)
4923 return ObjectBusy;
4925 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
4927 if (src_space == dst_space) return Ok;
4929 stat = GdipCreateMatrix(&matrix);
4930 if (stat == Ok)
4932 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
4934 if(graphics->unit != UnitDisplay)
4935 unitscale *= graphics->scale;
4937 /* transform from src_space to CoordinateSpacePage */
4938 switch (src_space)
4940 case CoordinateSpaceWorld:
4941 GdipMultiplyMatrix(matrix, graphics->worldtrans, MatrixOrderAppend);
4942 break;
4943 case CoordinateSpacePage:
4944 break;
4945 case CoordinateSpaceDevice:
4946 GdipScaleMatrix(matrix, 1.0/unitscale, 1.0/unitscale, MatrixOrderAppend);
4947 break;
4950 /* transform from CoordinateSpacePage to dst_space */
4951 switch (dst_space)
4953 case CoordinateSpaceWorld:
4955 GpMatrix *inverted_transform;
4956 stat = GdipCloneMatrix(graphics->worldtrans, &inverted_transform);
4957 if (stat == Ok)
4959 stat = GdipInvertMatrix(inverted_transform);
4960 if (stat == Ok)
4961 GdipMultiplyMatrix(matrix, inverted_transform, MatrixOrderAppend);
4962 GdipDeleteMatrix(inverted_transform);
4964 break;
4966 case CoordinateSpacePage:
4967 break;
4968 case CoordinateSpaceDevice:
4969 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
4970 break;
4973 if (stat == Ok)
4974 stat = GdipTransformMatrixPoints(matrix, points, count);
4976 GdipDeleteMatrix(matrix);
4979 return stat;
4982 GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space,
4983 GpCoordinateSpace src_space, GpPoint *points, INT count)
4985 GpPointF *pointsF;
4986 GpStatus ret;
4987 INT i;
4989 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
4991 if(count <= 0)
4992 return InvalidParameter;
4994 pointsF = GdipAlloc(sizeof(GpPointF) * count);
4995 if(!pointsF)
4996 return OutOfMemory;
4998 for(i = 0; i < count; i++){
4999 pointsF[i].X = (REAL)points[i].X;
5000 pointsF[i].Y = (REAL)points[i].Y;
5003 ret = GdipTransformPoints(graphics, dst_space, src_space, pointsF, count);
5005 if(ret == Ok)
5006 for(i = 0; i < count; i++){
5007 points[i].X = roundr(pointsF[i].X);
5008 points[i].Y = roundr(pointsF[i].Y);
5010 GdipFree(pointsF);
5012 return ret;
5015 HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void)
5017 static int calls;
5019 TRACE("\n");
5021 if (!calls++)
5022 FIXME("stub\n");
5024 return NULL;
5027 /*****************************************************************************
5028 * GdipTranslateClip [GDIPLUS.@]
5030 GpStatus WINGDIPAPI GdipTranslateClip(GpGraphics *graphics, REAL dx, REAL dy)
5032 TRACE("(%p, %.2f, %.2f)\n", graphics, dx, dy);
5034 if(!graphics)
5035 return InvalidParameter;
5037 if(graphics->busy)
5038 return ObjectBusy;
5040 return GdipTranslateRegion(graphics->clip, dx, dy);
5043 /*****************************************************************************
5044 * GdipTranslateClipI [GDIPLUS.@]
5046 GpStatus WINGDIPAPI GdipTranslateClipI(GpGraphics *graphics, INT dx, INT dy)
5048 TRACE("(%p, %d, %d)\n", graphics, dx, dy);
5050 if(!graphics)
5051 return InvalidParameter;
5053 if(graphics->busy)
5054 return ObjectBusy;
5056 return GdipTranslateRegion(graphics->clip, (REAL)dx, (REAL)dy);
5060 /*****************************************************************************
5061 * GdipMeasureDriverString [GDIPLUS.@]
5063 GpStatus WINGDIPAPI GdipMeasureDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5064 GDIPCONST GpFont *font, GDIPCONST PointF *positions,
5065 INT flags, GDIPCONST GpMatrix *matrix, RectF *boundingBox)
5067 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics, text, length, font, positions, flags, matrix, boundingBox);
5068 return NotImplemented;
5071 /*****************************************************************************
5072 * GdipDrawDriverString [GDIPLUS.@]
5074 GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5075 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
5076 GDIPCONST PointF *positions, INT flags,
5077 GDIPCONST GpMatrix *matrix )
5079 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics, text, length, font, brush, positions, flags, matrix);
5080 return NotImplemented;
5083 GpStatus WINGDIPAPI GdipRecordMetafile(HDC hdc, EmfType type, GDIPCONST GpRectF *frameRect,
5084 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
5086 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
5087 return NotImplemented;
5090 /*****************************************************************************
5091 * GdipRecordMetafileI [GDIPLUS.@]
5093 GpStatus WINGDIPAPI GdipRecordMetafileI(HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
5094 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
5096 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
5097 return NotImplemented;
5100 GpStatus WINGDIPAPI GdipRecordMetafileStream(IStream *stream, HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
5101 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
5103 FIXME("(%p %p %d %p %d %p %p): stub\n", stream, hdc, type, frameRect, frameUnit, desc, metafile);
5104 return NotImplemented;
5107 /*****************************************************************************
5108 * GdipIsVisibleClipEmpty [GDIPLUS.@]
5110 GpStatus WINGDIPAPI GdipIsVisibleClipEmpty(GpGraphics *graphics, BOOL *res)
5112 GpStatus stat;
5113 GpRegion* rgn;
5115 TRACE("(%p, %p)\n", graphics, res);
5117 if((stat = GdipCreateRegion(&rgn)) != Ok)
5118 return stat;
5120 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
5121 goto cleanup;
5123 stat = GdipIsEmptyRegion(rgn, graphics, res);
5125 cleanup:
5126 GdipDeleteRegion(rgn);
5127 return stat;