msxml3: Add a trailing '\n' to an ERR() call.
[wine/multimedia.git] / dlls / gdiplus / graphics.c
blobe85a8ba3614380f57762e9e4bc4820bd57718136
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 /*****************************************************************************
3286 * GdipFillRegion [GDIPLUS.@]
3288 GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
3289 GpRegion* region)
3291 INT save_state;
3292 GpStatus status;
3293 HRGN hrgn;
3294 RECT rc;
3296 TRACE("(%p, %p, %p)\n", graphics, brush, region);
3298 if (!(graphics && brush && region))
3299 return InvalidParameter;
3301 if(graphics->busy)
3302 return ObjectBusy;
3304 if(!graphics->hdc)
3306 FIXME("graphics object has no HDC\n");
3307 return Ok;
3310 status = GdipGetRegionHRgn(region, graphics, &hrgn);
3311 if(status != Ok)
3312 return status;
3314 save_state = SaveDC(graphics->hdc);
3315 EndPath(graphics->hdc);
3317 ExtSelectClipRgn(graphics->hdc, hrgn, RGN_AND);
3319 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
3321 BeginPath(graphics->hdc);
3322 Rectangle(graphics->hdc, rc.left, rc.top, rc.right, rc.bottom);
3323 EndPath(graphics->hdc);
3325 brush_fill_path(graphics, brush);
3328 RestoreDC(graphics->hdc, save_state);
3330 DeleteObject(hrgn);
3332 return Ok;
3335 GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention)
3337 TRACE("(%p,%u)\n", graphics, intention);
3339 if(!graphics)
3340 return InvalidParameter;
3342 if(graphics->busy)
3343 return ObjectBusy;
3345 /* We have no internal operation queue, so there's no need to clear it. */
3347 if (graphics->hdc)
3348 GdiFlush();
3350 return Ok;
3353 /*****************************************************************************
3354 * GdipGetClipBounds [GDIPLUS.@]
3356 GpStatus WINGDIPAPI GdipGetClipBounds(GpGraphics *graphics, GpRectF *rect)
3358 TRACE("(%p, %p)\n", graphics, rect);
3360 if(!graphics)
3361 return InvalidParameter;
3363 if(graphics->busy)
3364 return ObjectBusy;
3366 return GdipGetRegionBounds(graphics->clip, graphics, rect);
3369 /*****************************************************************************
3370 * GdipGetClipBoundsI [GDIPLUS.@]
3372 GpStatus WINGDIPAPI GdipGetClipBoundsI(GpGraphics *graphics, GpRect *rect)
3374 TRACE("(%p, %p)\n", graphics, rect);
3376 if(!graphics)
3377 return InvalidParameter;
3379 if(graphics->busy)
3380 return ObjectBusy;
3382 return GdipGetRegionBoundsI(graphics->clip, graphics, rect);
3385 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3386 GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics,
3387 CompositingMode *mode)
3389 TRACE("(%p, %p)\n", graphics, mode);
3391 if(!graphics || !mode)
3392 return InvalidParameter;
3394 if(graphics->busy)
3395 return ObjectBusy;
3397 *mode = graphics->compmode;
3399 return Ok;
3402 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3403 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
3404 CompositingQuality *quality)
3406 TRACE("(%p, %p)\n", graphics, quality);
3408 if(!graphics || !quality)
3409 return InvalidParameter;
3411 if(graphics->busy)
3412 return ObjectBusy;
3414 *quality = graphics->compqual;
3416 return Ok;
3419 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3420 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
3421 InterpolationMode *mode)
3423 TRACE("(%p, %p)\n", graphics, mode);
3425 if(!graphics || !mode)
3426 return InvalidParameter;
3428 if(graphics->busy)
3429 return ObjectBusy;
3431 *mode = graphics->interpolation;
3433 return Ok;
3436 /* FIXME: Need to handle color depths less than 24bpp */
3437 GpStatus WINGDIPAPI GdipGetNearestColor(GpGraphics *graphics, ARGB* argb)
3439 FIXME("(%p, %p): Passing color unmodified\n", graphics, argb);
3441 if(!graphics || !argb)
3442 return InvalidParameter;
3444 if(graphics->busy)
3445 return ObjectBusy;
3447 return Ok;
3450 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
3452 TRACE("(%p, %p)\n", graphics, scale);
3454 if(!graphics || !scale)
3455 return InvalidParameter;
3457 if(graphics->busy)
3458 return ObjectBusy;
3460 *scale = graphics->scale;
3462 return Ok;
3465 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
3467 TRACE("(%p, %p)\n", graphics, unit);
3469 if(!graphics || !unit)
3470 return InvalidParameter;
3472 if(graphics->busy)
3473 return ObjectBusy;
3475 *unit = graphics->unit;
3477 return Ok;
3480 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3481 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
3482 *mode)
3484 TRACE("(%p, %p)\n", graphics, mode);
3486 if(!graphics || !mode)
3487 return InvalidParameter;
3489 if(graphics->busy)
3490 return ObjectBusy;
3492 *mode = graphics->pixeloffset;
3494 return Ok;
3497 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3498 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
3500 TRACE("(%p, %p)\n", graphics, mode);
3502 if(!graphics || !mode)
3503 return InvalidParameter;
3505 if(graphics->busy)
3506 return ObjectBusy;
3508 *mode = graphics->smoothing;
3510 return Ok;
3513 GpStatus WINGDIPAPI GdipGetTextContrast(GpGraphics *graphics, UINT *contrast)
3515 TRACE("(%p, %p)\n", graphics, contrast);
3517 if(!graphics || !contrast)
3518 return InvalidParameter;
3520 *contrast = graphics->textcontrast;
3522 return Ok;
3525 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3526 GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics,
3527 TextRenderingHint *hint)
3529 TRACE("(%p, %p)\n", graphics, hint);
3531 if(!graphics || !hint)
3532 return InvalidParameter;
3534 if(graphics->busy)
3535 return ObjectBusy;
3537 *hint = graphics->texthint;
3539 return Ok;
3542 GpStatus WINGDIPAPI GdipGetVisibleClipBounds(GpGraphics *graphics, GpRectF *rect)
3544 GpRegion *clip_rgn;
3545 GpStatus stat;
3547 TRACE("(%p, %p)\n", graphics, rect);
3549 if(!graphics || !rect)
3550 return InvalidParameter;
3552 if(graphics->busy)
3553 return ObjectBusy;
3555 /* intersect window and graphics clipping regions */
3556 if((stat = GdipCreateRegion(&clip_rgn)) != Ok)
3557 return stat;
3559 if((stat = get_visible_clip_region(graphics, clip_rgn)) != Ok)
3560 goto cleanup;
3562 /* get bounds of the region */
3563 stat = GdipGetRegionBounds(clip_rgn, graphics, rect);
3565 cleanup:
3566 GdipDeleteRegion(clip_rgn);
3568 return stat;
3571 GpStatus WINGDIPAPI GdipGetVisibleClipBoundsI(GpGraphics *graphics, GpRect *rect)
3573 GpRectF rectf;
3574 GpStatus stat;
3576 TRACE("(%p, %p)\n", graphics, rect);
3578 if(!graphics || !rect)
3579 return InvalidParameter;
3581 if((stat = GdipGetVisibleClipBounds(graphics, &rectf)) == Ok)
3583 rect->X = roundr(rectf.X);
3584 rect->Y = roundr(rectf.Y);
3585 rect->Width = roundr(rectf.Width);
3586 rect->Height = roundr(rectf.Height);
3589 return stat;
3592 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
3594 TRACE("(%p, %p)\n", graphics, matrix);
3596 if(!graphics || !matrix)
3597 return InvalidParameter;
3599 if(graphics->busy)
3600 return ObjectBusy;
3602 *matrix = *graphics->worldtrans;
3603 return Ok;
3606 GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color)
3608 GpSolidFill *brush;
3609 GpStatus stat;
3610 GpRectF wnd_rect;
3612 TRACE("(%p, %x)\n", graphics, color);
3614 if(!graphics)
3615 return InvalidParameter;
3617 if(graphics->busy)
3618 return ObjectBusy;
3620 if((stat = GdipCreateSolidFill(color, &brush)) != Ok)
3621 return stat;
3623 if((stat = get_graphics_bounds(graphics, &wnd_rect)) != Ok){
3624 GdipDeleteBrush((GpBrush*)brush);
3625 return stat;
3628 GdipFillRectangle(graphics, (GpBrush*)brush, wnd_rect.X, wnd_rect.Y,
3629 wnd_rect.Width, wnd_rect.Height);
3631 GdipDeleteBrush((GpBrush*)brush);
3633 return Ok;
3636 GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics *graphics, BOOL *res)
3638 TRACE("(%p, %p)\n", graphics, res);
3640 if(!graphics || !res)
3641 return InvalidParameter;
3643 return GdipIsEmptyRegion(graphics->clip, graphics, res);
3646 GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics *graphics, REAL x, REAL y, BOOL *result)
3648 GpStatus stat;
3649 GpRegion* rgn;
3650 GpPointF pt;
3652 TRACE("(%p, %.2f, %.2f, %p)\n", graphics, x, y, result);
3654 if(!graphics || !result)
3655 return InvalidParameter;
3657 if(graphics->busy)
3658 return ObjectBusy;
3660 pt.X = x;
3661 pt.Y = y;
3662 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3663 CoordinateSpaceWorld, &pt, 1)) != Ok)
3664 return stat;
3666 if((stat = GdipCreateRegion(&rgn)) != Ok)
3667 return stat;
3669 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3670 goto cleanup;
3672 stat = GdipIsVisibleRegionPoint(rgn, pt.X, pt.Y, graphics, result);
3674 cleanup:
3675 GdipDeleteRegion(rgn);
3676 return stat;
3679 GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics *graphics, INT x, INT y, BOOL *result)
3681 return GdipIsVisiblePoint(graphics, (REAL)x, (REAL)y, result);
3684 GpStatus WINGDIPAPI GdipIsVisibleRect(GpGraphics *graphics, REAL x, REAL y, REAL width, REAL height, BOOL *result)
3686 GpStatus stat;
3687 GpRegion* rgn;
3688 GpPointF pts[2];
3690 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics, x, y, width, height, result);
3692 if(!graphics || !result)
3693 return InvalidParameter;
3695 if(graphics->busy)
3696 return ObjectBusy;
3698 pts[0].X = x;
3699 pts[0].Y = y;
3700 pts[1].X = x + width;
3701 pts[1].Y = y + height;
3703 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3704 CoordinateSpaceWorld, pts, 2)) != Ok)
3705 return stat;
3707 pts[1].X -= pts[0].X;
3708 pts[1].Y -= pts[0].Y;
3710 if((stat = GdipCreateRegion(&rgn)) != Ok)
3711 return stat;
3713 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3714 goto cleanup;
3716 stat = GdipIsVisibleRegionRect(rgn, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y, graphics, result);
3718 cleanup:
3719 GdipDeleteRegion(rgn);
3720 return stat;
3723 GpStatus WINGDIPAPI GdipIsVisibleRectI(GpGraphics *graphics, INT x, INT y, INT width, INT height, BOOL *result)
3725 return GdipIsVisibleRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, result);
3728 typedef GpStatus (*gdip_format_string_callback)(GpGraphics *graphics,
3729 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3730 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3731 INT lineno, const RectF *bounds, void *user_data);
3733 static GpStatus gdip_format_string(GpGraphics *graphics,
3734 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
3735 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3736 gdip_format_string_callback callback, void *user_data)
3738 WCHAR* stringdup;
3739 int sum = 0, height = 0, fit, fitcpy, i, j, lret, nwidth,
3740 nheight, lineend, lineno = 0;
3741 RectF bounds;
3742 StringAlignment halign;
3743 GpStatus stat = Ok;
3744 SIZE size;
3746 if(length == -1) length = lstrlenW(string);
3748 stringdup = GdipAlloc((length + 1) * sizeof(WCHAR));
3749 if(!stringdup) return OutOfMemory;
3751 nwidth = roundr(rect->Width);
3752 nheight = roundr(rect->Height);
3754 if (rect->Width >= INT_MAX || rect->Width < 0.5) nwidth = INT_MAX;
3755 if (rect->Height >= INT_MAX || rect->Width < 0.5) nheight = INT_MAX;
3757 for(i = 0, j = 0; i < length; i++){
3758 /* FIXME: This makes the indexes passed to callback inaccurate. */
3759 if(!isprintW(string[i]) && (string[i] != '\n'))
3760 continue;
3762 stringdup[j] = string[i];
3763 j++;
3766 length = j;
3768 if (format) halign = format->align;
3769 else halign = StringAlignmentNear;
3771 while(sum < length){
3772 GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum,
3773 nwidth, &fit, NULL, &size);
3774 fitcpy = fit;
3776 if(fit == 0)
3777 break;
3779 for(lret = 0; lret < fit; lret++)
3780 if(*(stringdup + sum + lret) == '\n')
3781 break;
3783 /* Line break code (may look strange, but it imitates windows). */
3784 if(lret < fit)
3785 lineend = fit = lret; /* this is not an off-by-one error */
3786 else if(fit < (length - sum)){
3787 if(*(stringdup + sum + fit) == ' ')
3788 while(*(stringdup + sum + fit) == ' ')
3789 fit++;
3790 else
3791 while(*(stringdup + sum + fit - 1) != ' '){
3792 fit--;
3794 if(*(stringdup + sum + fit) == '\t')
3795 break;
3797 if(fit == 0){
3798 fit = fitcpy;
3799 break;
3802 lineend = fit;
3803 while(*(stringdup + sum + lineend - 1) == ' ' ||
3804 *(stringdup + sum + lineend - 1) == '\t')
3805 lineend--;
3807 else
3808 lineend = fit;
3810 GetTextExtentExPointW(graphics->hdc, stringdup + sum, lineend,
3811 nwidth, &j, NULL, &size);
3813 bounds.Width = size.cx;
3815 if(height + size.cy > nheight)
3816 bounds.Height = nheight - (height + size.cy);
3817 else
3818 bounds.Height = size.cy;
3820 bounds.Y = rect->Y + height;
3822 switch (halign)
3824 case StringAlignmentNear:
3825 default:
3826 bounds.X = rect->X;
3827 break;
3828 case StringAlignmentCenter:
3829 bounds.X = rect->X + (rect->Width/2) - (bounds.Width/2);
3830 break;
3831 case StringAlignmentFar:
3832 bounds.X = rect->X + rect->Width - bounds.Width;
3833 break;
3836 stat = callback(graphics, stringdup, sum, lineend,
3837 font, rect, format, lineno, &bounds, user_data);
3839 if (stat != Ok)
3840 break;
3842 sum += fit + (lret < fitcpy ? 1 : 0);
3843 height += size.cy;
3844 lineno++;
3846 if(height > nheight)
3847 break;
3849 /* Stop if this was a linewrap (but not if it was a linebreak). */
3850 if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
3851 break;
3854 GdipFree(stringdup);
3856 return stat;
3859 struct measure_ranges_args {
3860 GpRegion **regions;
3863 static GpStatus measure_ranges_callback(GpGraphics *graphics,
3864 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3865 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3866 INT lineno, const RectF *bounds, void *user_data)
3868 int i;
3869 GpStatus stat = Ok;
3870 struct measure_ranges_args *args = user_data;
3872 for (i=0; i<format->range_count; i++)
3874 INT range_start = max(index, format->character_ranges[i].First);
3875 INT range_end = min(index+length, format->character_ranges[i].First+format->character_ranges[i].Length);
3876 if (range_start < range_end)
3878 GpRectF range_rect;
3879 SIZE range_size;
3881 range_rect.Y = bounds->Y;
3882 range_rect.Height = bounds->Height;
3884 GetTextExtentExPointW(graphics->hdc, string + index, range_start - index,
3885 INT_MAX, NULL, NULL, &range_size);
3886 range_rect.X = bounds->X + range_size.cx;
3888 GetTextExtentExPointW(graphics->hdc, string + index, range_end - index,
3889 INT_MAX, NULL, NULL, &range_size);
3890 range_rect.Width = (bounds->X + range_size.cx) - range_rect.X;
3892 stat = GdipCombineRegionRect(args->regions[i], &range_rect, CombineModeUnion);
3893 if (stat != Ok)
3894 break;
3898 return stat;
3901 GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,
3902 GDIPCONST WCHAR* string, INT length, GDIPCONST GpFont* font,
3903 GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat *stringFormat,
3904 INT regionCount, GpRegion** regions)
3906 GpStatus stat;
3907 int i;
3908 HFONT oldfont;
3909 struct measure_ranges_args args;
3910 HDC temp_hdc=NULL;
3912 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics, debugstr_w(string),
3913 length, font, debugstr_rectf(layoutRect), stringFormat, regionCount, regions);
3915 if (!(graphics && string && font && layoutRect && stringFormat && regions))
3916 return InvalidParameter;
3918 if (regionCount < stringFormat->range_count)
3919 return InvalidParameter;
3921 if(!graphics->hdc)
3923 temp_hdc = graphics->hdc = CreateCompatibleDC(0);
3924 if (!temp_hdc) return OutOfMemory;
3927 if (stringFormat->attr)
3928 TRACE("may be ignoring some format flags: attr %x\n", stringFormat->attr);
3930 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
3932 for (i=0; i<stringFormat->range_count; i++)
3934 stat = GdipSetEmpty(regions[i]);
3935 if (stat != Ok)
3936 return stat;
3939 args.regions = regions;
3941 stat = gdip_format_string(graphics, string, length, font, layoutRect, stringFormat,
3942 measure_ranges_callback, &args);
3944 DeleteObject(SelectObject(graphics->hdc, oldfont));
3946 if (temp_hdc)
3948 graphics->hdc = NULL;
3949 DeleteDC(temp_hdc);
3952 return stat;
3955 struct measure_string_args {
3956 RectF *bounds;
3957 INT *codepointsfitted;
3958 INT *linesfilled;
3961 static GpStatus measure_string_callback(GpGraphics *graphics,
3962 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3963 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3964 INT lineno, const RectF *bounds, void *user_data)
3966 struct measure_string_args *args = user_data;
3968 if (bounds->Width > args->bounds->Width)
3969 args->bounds->Width = bounds->Width;
3971 if (bounds->Height + bounds->Y > args->bounds->Height + args->bounds->Y)
3972 args->bounds->Height = bounds->Height + bounds->Y - args->bounds->Y;
3974 if (args->codepointsfitted)
3975 *args->codepointsfitted = index + length;
3977 if (args->linesfilled)
3978 (*args->linesfilled)++;
3980 return Ok;
3983 /* Find the smallest rectangle that bounds the text when it is printed in rect
3984 * according to the format options listed in format. If rect has 0 width and
3985 * height, then just find the smallest rectangle that bounds the text when it's
3986 * printed at location (rect->X, rect-Y). */
3987 GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
3988 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
3989 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
3990 INT *codepointsfitted, INT *linesfilled)
3992 HFONT oldfont;
3993 struct measure_string_args args;
3994 HDC temp_hdc=NULL;
3996 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics,
3997 debugstr_wn(string, length), length, font, debugstr_rectf(rect), format,
3998 bounds, codepointsfitted, linesfilled);
4000 if(!graphics || !string || !font || !rect || !bounds)
4001 return InvalidParameter;
4003 if(!graphics->hdc)
4005 temp_hdc = graphics->hdc = CreateCompatibleDC(0);
4006 if (!temp_hdc) return OutOfMemory;
4009 if(linesfilled) *linesfilled = 0;
4010 if(codepointsfitted) *codepointsfitted = 0;
4012 if(format)
4013 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4015 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
4017 bounds->X = rect->X;
4018 bounds->Y = rect->Y;
4019 bounds->Width = 0.0;
4020 bounds->Height = 0.0;
4022 args.bounds = bounds;
4023 args.codepointsfitted = codepointsfitted;
4024 args.linesfilled = linesfilled;
4026 gdip_format_string(graphics, string, length, font, rect, format,
4027 measure_string_callback, &args);
4029 DeleteObject(SelectObject(graphics->hdc, oldfont));
4031 if (temp_hdc)
4033 graphics->hdc = NULL;
4034 DeleteDC(temp_hdc);
4037 return Ok;
4040 struct draw_string_args {
4041 POINT drawbase;
4042 UINT drawflags;
4043 REAL ang_cos, ang_sin;
4046 static GpStatus draw_string_callback(GpGraphics *graphics,
4047 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4048 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4049 INT lineno, const RectF *bounds, void *user_data)
4051 struct draw_string_args *args = user_data;
4052 RECT drawcoord;
4054 drawcoord.left = drawcoord.right = args->drawbase.x + roundr(args->ang_sin * bounds->Y);
4055 drawcoord.top = drawcoord.bottom = args->drawbase.y + roundr(args->ang_cos * bounds->Y);
4057 DrawTextW(graphics->hdc, string + index, length, &drawcoord, args->drawflags);
4059 return Ok;
4062 GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string,
4063 INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect,
4064 GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush)
4066 HRGN rgn = NULL;
4067 HFONT gdifont;
4068 LOGFONTW lfw;
4069 TEXTMETRICW textmet;
4070 GpPointF pt[3], rectcpy[4];
4071 POINT corners[4];
4072 REAL angle, rel_width, rel_height;
4073 INT offsety = 0, save_state;
4074 struct draw_string_args args;
4075 RectF scaled_rect;
4077 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length),
4078 length, font, debugstr_rectf(rect), format, brush);
4080 if(!graphics || !string || !font || !brush || !rect)
4081 return InvalidParameter;
4083 if((brush->bt != BrushTypeSolidColor)){
4084 FIXME("not implemented for given parameters\n");
4085 return NotImplemented;
4088 if(!graphics->hdc)
4090 FIXME("graphics object has no HDC\n");
4091 return Ok;
4094 if(format){
4095 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4097 /* Should be no need to explicitly test for StringAlignmentNear as
4098 * that is default behavior if no alignment is passed. */
4099 if(format->vertalign != StringAlignmentNear){
4100 RectF bounds;
4101 GdipMeasureString(graphics, string, length, font, rect, format, &bounds, 0, 0);
4103 if(format->vertalign == StringAlignmentCenter)
4104 offsety = (rect->Height - bounds.Height) / 2;
4105 else if(format->vertalign == StringAlignmentFar)
4106 offsety = (rect->Height - bounds.Height);
4110 save_state = SaveDC(graphics->hdc);
4111 SetBkMode(graphics->hdc, TRANSPARENT);
4112 SetTextColor(graphics->hdc, brush->lb.lbColor);
4114 pt[0].X = 0.0;
4115 pt[0].Y = 0.0;
4116 pt[1].X = 1.0;
4117 pt[1].Y = 0.0;
4118 pt[2].X = 0.0;
4119 pt[2].Y = 1.0;
4120 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
4121 angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X));
4122 args.ang_cos = cos(angle);
4123 args.ang_sin = sin(angle);
4124 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
4125 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
4126 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
4127 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
4129 rectcpy[3].X = rectcpy[0].X = rect->X;
4130 rectcpy[1].Y = rectcpy[0].Y = rect->Y + offsety;
4131 rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width;
4132 rectcpy[3].Y = rectcpy[2].Y = rect->Y + offsety + rect->Height;
4133 transform_and_round_points(graphics, corners, rectcpy, 4);
4135 scaled_rect.X = 0.0;
4136 scaled_rect.Y = 0.0;
4137 scaled_rect.Width = rel_width * rect->Width;
4138 scaled_rect.Height = rel_height * rect->Height;
4140 if (roundr(scaled_rect.Width) != 0 && roundr(scaled_rect.Height) != 0)
4142 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4143 rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
4144 SelectClipRgn(graphics->hdc, rgn);
4147 /* Use gdi to find the font, then perform transformations on it (height,
4148 * width, angle). */
4149 SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
4150 GetTextMetricsW(graphics->hdc, &textmet);
4151 lfw = font->lfw;
4153 lfw.lfHeight = roundr(((REAL)lfw.lfHeight) * rel_height);
4154 lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width);
4156 lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0);
4158 gdifont = CreateFontIndirectW(&lfw);
4159 DeleteObject(SelectObject(graphics->hdc, CreateFontIndirectW(&lfw)));
4161 if (!format || format->align == StringAlignmentNear)
4163 args.drawbase.x = corners[0].x;
4164 args.drawbase.y = corners[0].y;
4165 args.drawflags = DT_NOCLIP | DT_EXPANDTABS;
4167 else if (format->align == StringAlignmentCenter)
4169 args.drawbase.x = (corners[0].x + corners[1].x)/2;
4170 args.drawbase.y = (corners[0].y + corners[1].y)/2;
4171 args.drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_CENTER;
4173 else /* (format->align == StringAlignmentFar) */
4175 args.drawbase.x = corners[1].x;
4176 args.drawbase.y = corners[1].y;
4177 args.drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_RIGHT;
4180 gdip_format_string(graphics, string, length, font, &scaled_rect, format,
4181 draw_string_callback, &args);
4183 DeleteObject(rgn);
4184 DeleteObject(gdifont);
4186 RestoreDC(graphics->hdc, save_state);
4188 return Ok;
4191 GpStatus WINGDIPAPI GdipResetClip(GpGraphics *graphics)
4193 TRACE("(%p)\n", graphics);
4195 if(!graphics)
4196 return InvalidParameter;
4198 if(graphics->busy)
4199 return ObjectBusy;
4201 return GdipSetInfinite(graphics->clip);
4204 GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics)
4206 TRACE("(%p)\n", graphics);
4208 if(!graphics)
4209 return InvalidParameter;
4211 if(graphics->busy)
4212 return ObjectBusy;
4214 graphics->worldtrans->matrix[0] = 1.0;
4215 graphics->worldtrans->matrix[1] = 0.0;
4216 graphics->worldtrans->matrix[2] = 0.0;
4217 graphics->worldtrans->matrix[3] = 1.0;
4218 graphics->worldtrans->matrix[4] = 0.0;
4219 graphics->worldtrans->matrix[5] = 0.0;
4221 return Ok;
4224 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
4226 return GdipEndContainer(graphics, state);
4229 GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
4230 GpMatrixOrder order)
4232 TRACE("(%p, %.2f, %d)\n", graphics, angle, order);
4234 if(!graphics)
4235 return InvalidParameter;
4237 if(graphics->busy)
4238 return ObjectBusy;
4240 return GdipRotateMatrix(graphics->worldtrans, angle, order);
4243 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
4245 return GdipBeginContainer2(graphics, state);
4248 GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics *graphics,
4249 GraphicsContainer *state)
4251 GraphicsContainerItem *container;
4252 GpStatus sts;
4254 TRACE("(%p, %p)\n", graphics, state);
4256 if(!graphics || !state)
4257 return InvalidParameter;
4259 sts = init_container(&container, graphics);
4260 if(sts != Ok)
4261 return sts;
4263 list_add_head(&graphics->containers, &container->entry);
4264 *state = graphics->contid = container->contid;
4266 return Ok;
4269 GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics *graphics, GDIPCONST GpRectF *dstrect, GDIPCONST GpRectF *srcrect, GpUnit unit, GraphicsContainer *state)
4271 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
4272 return NotImplemented;
4275 GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics *graphics, GDIPCONST GpRect *dstrect, GDIPCONST GpRect *srcrect, GpUnit unit, GraphicsContainer *state)
4277 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
4278 return NotImplemented;
4281 GpStatus WINGDIPAPI GdipComment(GpGraphics *graphics, UINT sizeData, GDIPCONST BYTE *data)
4283 FIXME("(%p, %d, %p): stub\n", graphics, sizeData, data);
4284 return NotImplemented;
4287 GpStatus WINGDIPAPI GdipEndContainer(GpGraphics *graphics, GraphicsContainer state)
4289 GpStatus sts;
4290 GraphicsContainerItem *container, *container2;
4292 TRACE("(%p, %x)\n", graphics, state);
4294 if(!graphics)
4295 return InvalidParameter;
4297 LIST_FOR_EACH_ENTRY(container, &graphics->containers, GraphicsContainerItem, entry){
4298 if(container->contid == state)
4299 break;
4302 /* did not find a matching container */
4303 if(&container->entry == &graphics->containers)
4304 return Ok;
4306 sts = restore_container(graphics, container);
4307 if(sts != Ok)
4308 return sts;
4310 /* remove all of the containers on top of the found container */
4311 LIST_FOR_EACH_ENTRY_SAFE(container, container2, &graphics->containers, GraphicsContainerItem, entry){
4312 if(container->contid == state)
4313 break;
4314 list_remove(&container->entry);
4315 delete_container(container);
4318 list_remove(&container->entry);
4319 delete_container(container);
4321 return Ok;
4324 GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
4325 REAL sy, GpMatrixOrder order)
4327 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, sx, sy, order);
4329 if(!graphics)
4330 return InvalidParameter;
4332 if(graphics->busy)
4333 return ObjectBusy;
4335 return GdipScaleMatrix(graphics->worldtrans, sx, sy, order);
4338 GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics *graphics, GpGraphics *srcgraphics,
4339 CombineMode mode)
4341 TRACE("(%p, %p, %d)\n", graphics, srcgraphics, mode);
4343 if(!graphics || !srcgraphics)
4344 return InvalidParameter;
4346 return GdipCombineRegionRegion(graphics->clip, srcgraphics->clip, mode);
4349 GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
4350 CompositingMode mode)
4352 TRACE("(%p, %d)\n", graphics, mode);
4354 if(!graphics)
4355 return InvalidParameter;
4357 if(graphics->busy)
4358 return ObjectBusy;
4360 graphics->compmode = mode;
4362 return Ok;
4365 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
4366 CompositingQuality quality)
4368 TRACE("(%p, %d)\n", graphics, quality);
4370 if(!graphics)
4371 return InvalidParameter;
4373 if(graphics->busy)
4374 return ObjectBusy;
4376 graphics->compqual = quality;
4378 return Ok;
4381 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
4382 InterpolationMode mode)
4384 TRACE("(%p, %d)\n", graphics, mode);
4386 if(!graphics)
4387 return InvalidParameter;
4389 if(graphics->busy)
4390 return ObjectBusy;
4392 graphics->interpolation = mode;
4394 return Ok;
4397 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
4399 TRACE("(%p, %.2f)\n", graphics, scale);
4401 if(!graphics || (scale <= 0.0))
4402 return InvalidParameter;
4404 if(graphics->busy)
4405 return ObjectBusy;
4407 graphics->scale = scale;
4409 return Ok;
4412 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
4414 TRACE("(%p, %d)\n", graphics, unit);
4416 if(!graphics)
4417 return InvalidParameter;
4419 if(graphics->busy)
4420 return ObjectBusy;
4422 if(unit == UnitWorld)
4423 return InvalidParameter;
4425 graphics->unit = unit;
4427 return Ok;
4430 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
4431 mode)
4433 TRACE("(%p, %d)\n", graphics, mode);
4435 if(!graphics)
4436 return InvalidParameter;
4438 if(graphics->busy)
4439 return ObjectBusy;
4441 graphics->pixeloffset = mode;
4443 return Ok;
4446 GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics *graphics, INT x, INT y)
4448 static int calls;
4450 TRACE("(%p,%i,%i)\n", graphics, x, y);
4452 if (!(calls++))
4453 FIXME("not implemented\n");
4455 return NotImplemented;
4458 GpStatus WINGDIPAPI GdipGetRenderingOrigin(GpGraphics *graphics, INT *x, INT *y)
4460 static int calls;
4462 TRACE("(%p,%p,%p)\n", graphics, x, y);
4464 if (!(calls++))
4465 FIXME("not implemented\n");
4467 *x = *y = 0;
4469 return NotImplemented;
4472 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
4474 TRACE("(%p, %d)\n", graphics, mode);
4476 if(!graphics)
4477 return InvalidParameter;
4479 if(graphics->busy)
4480 return ObjectBusy;
4482 graphics->smoothing = mode;
4484 return Ok;
4487 GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics *graphics, UINT contrast)
4489 TRACE("(%p, %d)\n", graphics, contrast);
4491 if(!graphics)
4492 return InvalidParameter;
4494 graphics->textcontrast = contrast;
4496 return Ok;
4499 GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
4500 TextRenderingHint hint)
4502 TRACE("(%p, %d)\n", graphics, hint);
4504 if(!graphics)
4505 return InvalidParameter;
4507 if(graphics->busy)
4508 return ObjectBusy;
4510 graphics->texthint = hint;
4512 return Ok;
4515 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
4517 TRACE("(%p, %p)\n", graphics, matrix);
4519 if(!graphics || !matrix)
4520 return InvalidParameter;
4522 if(graphics->busy)
4523 return ObjectBusy;
4525 GdipDeleteMatrix(graphics->worldtrans);
4526 return GdipCloneMatrix(matrix, &graphics->worldtrans);
4529 GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
4530 REAL dy, GpMatrixOrder order)
4532 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, dx, dy, order);
4534 if(!graphics)
4535 return InvalidParameter;
4537 if(graphics->busy)
4538 return ObjectBusy;
4540 return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order);
4543 /*****************************************************************************
4544 * GdipSetClipHrgn [GDIPLUS.@]
4546 GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics *graphics, HRGN hrgn, CombineMode mode)
4548 GpRegion *region;
4549 GpStatus status;
4551 TRACE("(%p, %p, %d)\n", graphics, hrgn, mode);
4553 if(!graphics)
4554 return InvalidParameter;
4556 status = GdipCreateRegionHrgn(hrgn, &region);
4557 if(status != Ok)
4558 return status;
4560 status = GdipSetClipRegion(graphics, region, mode);
4562 GdipDeleteRegion(region);
4563 return status;
4566 GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics *graphics, GpPath *path, CombineMode mode)
4568 TRACE("(%p, %p, %d)\n", graphics, path, mode);
4570 if(!graphics)
4571 return InvalidParameter;
4573 if(graphics->busy)
4574 return ObjectBusy;
4576 return GdipCombineRegionPath(graphics->clip, path, mode);
4579 GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y,
4580 REAL width, REAL height,
4581 CombineMode mode)
4583 GpRectF rect;
4585 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics, x, y, width, height, mode);
4587 if(!graphics)
4588 return InvalidParameter;
4590 if(graphics->busy)
4591 return ObjectBusy;
4593 rect.X = x;
4594 rect.Y = y;
4595 rect.Width = width;
4596 rect.Height = height;
4598 return GdipCombineRegionRect(graphics->clip, &rect, mode);
4601 GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y,
4602 INT width, INT height,
4603 CombineMode mode)
4605 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics, x, y, width, height, mode);
4607 if(!graphics)
4608 return InvalidParameter;
4610 if(graphics->busy)
4611 return ObjectBusy;
4613 return GdipSetClipRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, mode);
4616 GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
4617 CombineMode mode)
4619 TRACE("(%p, %p, %d)\n", graphics, region, mode);
4621 if(!graphics || !region)
4622 return InvalidParameter;
4624 if(graphics->busy)
4625 return ObjectBusy;
4627 return GdipCombineRegionRegion(graphics->clip, region, mode);
4630 GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile *metafile,
4631 UINT limitDpi)
4633 static int calls;
4635 TRACE("(%p,%u)\n", metafile, limitDpi);
4637 if(!(calls++))
4638 FIXME("not implemented\n");
4640 return NotImplemented;
4643 GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points,
4644 INT count)
4646 INT save_state;
4647 POINT *pti;
4649 TRACE("(%p, %p, %d)\n", graphics, points, count);
4651 if(!graphics || !pen || count<=0)
4652 return InvalidParameter;
4654 if(graphics->busy)
4655 return ObjectBusy;
4657 if (!graphics->hdc)
4659 FIXME("graphics object has no HDC\n");
4660 return Ok;
4663 pti = GdipAlloc(sizeof(POINT) * count);
4665 save_state = prepare_dc(graphics, pen);
4666 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
4668 transform_and_round_points(graphics, pti, (GpPointF*)points, count);
4669 Polygon(graphics->hdc, pti, count);
4671 restore_dc(graphics, save_state);
4672 GdipFree(pti);
4674 return Ok;
4677 GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points,
4678 INT count)
4680 GpStatus ret;
4681 GpPointF *ptf;
4682 INT i;
4684 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
4686 if(count<=0) return InvalidParameter;
4687 ptf = GdipAlloc(sizeof(GpPointF) * count);
4689 for(i = 0;i < count; i++){
4690 ptf[i].X = (REAL)points[i].X;
4691 ptf[i].Y = (REAL)points[i].Y;
4694 ret = GdipDrawPolygon(graphics,pen,ptf,count);
4695 GdipFree(ptf);
4697 return ret;
4700 GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
4702 TRACE("(%p, %p)\n", graphics, dpi);
4704 if(!graphics || !dpi)
4705 return InvalidParameter;
4707 if(graphics->busy)
4708 return ObjectBusy;
4710 if (graphics->image)
4711 *dpi = graphics->image->xres;
4712 else
4713 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
4715 return Ok;
4718 GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
4720 TRACE("(%p, %p)\n", graphics, dpi);
4722 if(!graphics || !dpi)
4723 return InvalidParameter;
4725 if(graphics->busy)
4726 return ObjectBusy;
4728 if (graphics->image)
4729 *dpi = graphics->image->yres;
4730 else
4731 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
4733 return Ok;
4736 GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix,
4737 GpMatrixOrder order)
4739 GpMatrix m;
4740 GpStatus ret;
4742 TRACE("(%p, %p, %d)\n", graphics, matrix, order);
4744 if(!graphics || !matrix)
4745 return InvalidParameter;
4747 if(graphics->busy)
4748 return ObjectBusy;
4750 m = *(graphics->worldtrans);
4752 ret = GdipMultiplyMatrix(&m, matrix, order);
4753 if(ret == Ok)
4754 *(graphics->worldtrans) = m;
4756 return ret;
4759 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
4760 static const COLORREF DC_BACKGROUND_KEY = 0x0c0b0d;
4762 GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
4764 TRACE("(%p, %p)\n", graphics, hdc);
4766 if(!graphics || !hdc)
4767 return InvalidParameter;
4769 if(graphics->busy)
4770 return ObjectBusy;
4772 if (!graphics->hdc ||
4773 (graphics->image && graphics->image->type == ImageTypeBitmap && ((GpBitmap*)graphics->image)->format & PixelFormatAlpha))
4775 /* Create a fake HDC and fill it with a constant color. */
4776 HDC temp_hdc;
4777 HBITMAP hbitmap;
4778 GpStatus stat;
4779 GpRectF bounds;
4780 BITMAPINFOHEADER bmih;
4781 int i;
4783 stat = get_graphics_bounds(graphics, &bounds);
4784 if (stat != Ok)
4785 return stat;
4787 graphics->temp_hbitmap_width = bounds.Width;
4788 graphics->temp_hbitmap_height = bounds.Height;
4790 bmih.biSize = sizeof(bmih);
4791 bmih.biWidth = graphics->temp_hbitmap_width;
4792 bmih.biHeight = -graphics->temp_hbitmap_height;
4793 bmih.biPlanes = 1;
4794 bmih.biBitCount = 32;
4795 bmih.biCompression = BI_RGB;
4796 bmih.biSizeImage = 0;
4797 bmih.biXPelsPerMeter = 0;
4798 bmih.biYPelsPerMeter = 0;
4799 bmih.biClrUsed = 0;
4800 bmih.biClrImportant = 0;
4802 hbitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
4803 (void**)&graphics->temp_bits, NULL, 0);
4804 if (!hbitmap)
4805 return GenericError;
4807 temp_hdc = CreateCompatibleDC(0);
4808 if (!temp_hdc)
4810 DeleteObject(hbitmap);
4811 return GenericError;
4814 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
4815 ((DWORD*)graphics->temp_bits)[i] = DC_BACKGROUND_KEY;
4817 SelectObject(temp_hdc, hbitmap);
4819 graphics->temp_hbitmap = hbitmap;
4820 *hdc = graphics->temp_hdc = temp_hdc;
4822 else
4824 *hdc = graphics->hdc;
4827 graphics->busy = TRUE;
4829 return Ok;
4832 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
4834 TRACE("(%p, %p)\n", graphics, hdc);
4836 if(!graphics || !hdc)
4837 return InvalidParameter;
4839 if((graphics->hdc != hdc && graphics->temp_hdc != hdc) || !(graphics->busy))
4840 return InvalidParameter;
4842 if (graphics->temp_hdc == hdc)
4844 DWORD* pos;
4845 int i;
4847 /* Find the pixels that have changed, and mark them as opaque. */
4848 pos = (DWORD*)graphics->temp_bits;
4849 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
4851 if (*pos != DC_BACKGROUND_KEY)
4853 *pos |= 0xff000000;
4855 pos++;
4858 /* Write the changed pixels to the real target. */
4859 alpha_blend_pixels(graphics, 0, 0, graphics->temp_bits,
4860 graphics->temp_hbitmap_width, graphics->temp_hbitmap_height,
4861 graphics->temp_hbitmap_width * 4);
4863 /* Clean up. */
4864 DeleteDC(graphics->temp_hdc);
4865 DeleteObject(graphics->temp_hbitmap);
4866 graphics->temp_hdc = NULL;
4867 graphics->temp_hbitmap = NULL;
4870 graphics->busy = FALSE;
4872 return Ok;
4875 GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
4877 GpRegion *clip;
4878 GpStatus status;
4880 TRACE("(%p, %p)\n", graphics, region);
4882 if(!graphics || !region)
4883 return InvalidParameter;
4885 if(graphics->busy)
4886 return ObjectBusy;
4888 if((status = GdipCloneRegion(graphics->clip, &clip)) != Ok)
4889 return status;
4891 /* free everything except root node and header */
4892 delete_element(&region->node);
4893 memcpy(region, clip, sizeof(GpRegion));
4894 GdipFree(clip);
4896 return Ok;
4899 GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space,
4900 GpCoordinateSpace src_space, GpPointF *points, INT count)
4902 GpMatrix *matrix;
4903 GpStatus stat;
4904 REAL unitscale;
4906 if(!graphics || !points || count <= 0)
4907 return InvalidParameter;
4909 if(graphics->busy)
4910 return ObjectBusy;
4912 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
4914 if (src_space == dst_space) return Ok;
4916 stat = GdipCreateMatrix(&matrix);
4917 if (stat == Ok)
4919 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
4921 if(graphics->unit != UnitDisplay)
4922 unitscale *= graphics->scale;
4924 /* transform from src_space to CoordinateSpacePage */
4925 switch (src_space)
4927 case CoordinateSpaceWorld:
4928 GdipMultiplyMatrix(matrix, graphics->worldtrans, MatrixOrderAppend);
4929 break;
4930 case CoordinateSpacePage:
4931 break;
4932 case CoordinateSpaceDevice:
4933 GdipScaleMatrix(matrix, 1.0/unitscale, 1.0/unitscale, MatrixOrderAppend);
4934 break;
4937 /* transform from CoordinateSpacePage to dst_space */
4938 switch (dst_space)
4940 case CoordinateSpaceWorld:
4942 GpMatrix *inverted_transform;
4943 stat = GdipCloneMatrix(graphics->worldtrans, &inverted_transform);
4944 if (stat == Ok)
4946 stat = GdipInvertMatrix(inverted_transform);
4947 if (stat == Ok)
4948 GdipMultiplyMatrix(matrix, inverted_transform, MatrixOrderAppend);
4949 GdipDeleteMatrix(inverted_transform);
4951 break;
4953 case CoordinateSpacePage:
4954 break;
4955 case CoordinateSpaceDevice:
4956 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
4957 break;
4960 if (stat == Ok)
4961 stat = GdipTransformMatrixPoints(matrix, points, count);
4963 GdipDeleteMatrix(matrix);
4966 return stat;
4969 GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space,
4970 GpCoordinateSpace src_space, GpPoint *points, INT count)
4972 GpPointF *pointsF;
4973 GpStatus ret;
4974 INT i;
4976 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
4978 if(count <= 0)
4979 return InvalidParameter;
4981 pointsF = GdipAlloc(sizeof(GpPointF) * count);
4982 if(!pointsF)
4983 return OutOfMemory;
4985 for(i = 0; i < count; i++){
4986 pointsF[i].X = (REAL)points[i].X;
4987 pointsF[i].Y = (REAL)points[i].Y;
4990 ret = GdipTransformPoints(graphics, dst_space, src_space, pointsF, count);
4992 if(ret == Ok)
4993 for(i = 0; i < count; i++){
4994 points[i].X = roundr(pointsF[i].X);
4995 points[i].Y = roundr(pointsF[i].Y);
4997 GdipFree(pointsF);
4999 return ret;
5002 HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void)
5004 static int calls;
5006 TRACE("\n");
5008 if (!calls++)
5009 FIXME("stub\n");
5011 return NULL;
5014 /*****************************************************************************
5015 * GdipTranslateClip [GDIPLUS.@]
5017 GpStatus WINGDIPAPI GdipTranslateClip(GpGraphics *graphics, REAL dx, REAL dy)
5019 TRACE("(%p, %.2f, %.2f)\n", graphics, dx, dy);
5021 if(!graphics)
5022 return InvalidParameter;
5024 if(graphics->busy)
5025 return ObjectBusy;
5027 return GdipTranslateRegion(graphics->clip, dx, dy);
5030 /*****************************************************************************
5031 * GdipTranslateClipI [GDIPLUS.@]
5033 GpStatus WINGDIPAPI GdipTranslateClipI(GpGraphics *graphics, INT dx, INT dy)
5035 TRACE("(%p, %d, %d)\n", graphics, dx, dy);
5037 if(!graphics)
5038 return InvalidParameter;
5040 if(graphics->busy)
5041 return ObjectBusy;
5043 return GdipTranslateRegion(graphics->clip, (REAL)dx, (REAL)dy);
5047 /*****************************************************************************
5048 * GdipMeasureDriverString [GDIPLUS.@]
5050 GpStatus WINGDIPAPI GdipMeasureDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5051 GDIPCONST GpFont *font, GDIPCONST PointF *positions,
5052 INT flags, GDIPCONST GpMatrix *matrix, RectF *boundingBox)
5054 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics, text, length, font, positions, flags, matrix, boundingBox);
5055 return NotImplemented;
5058 /*****************************************************************************
5059 * GdipDrawDriverString [GDIPLUS.@]
5061 GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5062 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
5063 GDIPCONST PointF *positions, INT flags,
5064 GDIPCONST GpMatrix *matrix )
5066 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics, text, length, font, brush, positions, flags, matrix);
5067 return NotImplemented;
5070 GpStatus WINGDIPAPI GdipRecordMetafile(HDC hdc, EmfType type, GDIPCONST GpRectF *frameRect,
5071 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
5073 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
5074 return NotImplemented;
5077 /*****************************************************************************
5078 * GdipRecordMetafileI [GDIPLUS.@]
5080 GpStatus WINGDIPAPI GdipRecordMetafileI(HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
5081 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
5083 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
5084 return NotImplemented;
5087 GpStatus WINGDIPAPI GdipRecordMetafileStream(IStream *stream, HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
5088 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
5090 FIXME("(%p %p %d %p %d %p %p): stub\n", stream, hdc, type, frameRect, frameUnit, desc, metafile);
5091 return NotImplemented;
5094 /*****************************************************************************
5095 * GdipIsVisibleClipEmpty [GDIPLUS.@]
5097 GpStatus WINGDIPAPI GdipIsVisibleClipEmpty(GpGraphics *graphics, BOOL *res)
5099 GpStatus stat;
5100 GpRegion* rgn;
5102 TRACE("(%p, %p)\n", graphics, res);
5104 if((stat = GdipCreateRegion(&rgn)) != Ok)
5105 return stat;
5107 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
5108 goto cleanup;
5110 stat = GdipIsEmptyRegion(rgn, graphics, res);
5112 cleanup:
5113 GdipDeleteRegion(rgn);
5114 return stat;