msi: Don't create all directories in the CreateFolders action.
[wine/hacks.git] / dlls / gdiplus / graphics.c
blob39ab18c2674d00630fec3554351981f7c90b066b
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 INT prepare_dc(GpGraphics *graphics, GpPen *pen)
89 HPEN gdipen;
90 REAL width;
91 INT save_state = SaveDC(graphics->hdc), i, numdashes;
92 GpPointF pt[2];
93 DWORD dash_array[MAX_DASHLEN];
95 EndPath(graphics->hdc);
97 if(pen->unit == UnitPixel){
98 width = pen->width;
100 else{
101 /* Get an estimate for the amount the pen width is affected by the world
102 * transform. (This is similar to what some of the wine drivers do.) */
103 pt[0].X = 0.0;
104 pt[0].Y = 0.0;
105 pt[1].X = 1.0;
106 pt[1].Y = 1.0;
107 GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
108 width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
109 (pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
111 width *= pen->width * convert_unit(graphics->hdc,
112 pen->unit == UnitWorld ? graphics->unit : pen->unit);
115 if(pen->dash == DashStyleCustom){
116 numdashes = min(pen->numdashes, MAX_DASHLEN);
118 TRACE("dashes are: ");
119 for(i = 0; i < numdashes; i++){
120 dash_array[i] = roundr(width * pen->dashes[i]);
121 TRACE("%d, ", dash_array[i]);
123 TRACE("\n and the pen style is %x\n", pen->style);
125 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb,
126 numdashes, dash_array);
128 else
129 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, 0, NULL);
131 SelectObject(graphics->hdc, gdipen);
133 return save_state;
136 static void restore_dc(GpGraphics *graphics, INT state)
138 DeleteObject(SelectObject(graphics->hdc, GetStockObject(NULL_PEN)));
139 RestoreDC(graphics->hdc, state);
142 /* This helper applies all the changes that the points listed in ptf need in
143 * order to be drawn on the device context. In the end, this should include at
144 * least:
145 * -scaling by page unit
146 * -applying world transformation
147 * -converting from float to int
148 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
149 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
150 * gdi to draw, and these functions would irreparably mess with line widths.
152 static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
153 GpPointF *ptf, INT count)
155 REAL unitscale;
156 GpMatrix *matrix;
157 int i;
159 unitscale = convert_unit(graphics->hdc, graphics->unit);
161 /* apply page scale */
162 if(graphics->unit != UnitDisplay)
163 unitscale *= graphics->scale;
165 GdipCloneMatrix(graphics->worldtrans, &matrix);
166 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
167 GdipTransformMatrixPoints(matrix, ptf, count);
168 GdipDeleteMatrix(matrix);
170 for(i = 0; i < count; i++){
171 pti[i].x = roundr(ptf[i].X);
172 pti[i].y = roundr(ptf[i].Y);
176 static ARGB blend_colors(ARGB start, ARGB end, REAL position)
178 ARGB result=0;
179 ARGB i;
180 for (i=0xff; i<=0xff0000; i = i << 8)
181 result |= (int)((start&i)*(1.0f - position)+(end&i)*(position))&i;
182 return result;
185 static ARGB blend_line_gradient(GpLineGradient* brush, REAL position)
187 REAL blendfac;
189 /* clamp to between 0.0 and 1.0, using the wrap mode */
190 if (brush->wrap == WrapModeTile)
192 position = fmodf(position, 1.0f);
193 if (position < 0.0f) position += 1.0f;
195 else /* WrapModeFlip* */
197 position = fmodf(position, 2.0f);
198 if (position < 0.0f) position += 2.0f;
199 if (position > 1.0f) position = 2.0f - position;
202 if (brush->blendcount == 1)
203 blendfac = position;
204 else
206 int i=1;
207 REAL left_blendpos, left_blendfac, right_blendpos, right_blendfac;
208 REAL range;
210 /* locate the blend positions surrounding this position */
211 while (position > brush->blendpos[i])
212 i++;
214 /* interpolate between the blend positions */
215 left_blendpos = brush->blendpos[i-1];
216 left_blendfac = brush->blendfac[i-1];
217 right_blendpos = brush->blendpos[i];
218 right_blendfac = brush->blendfac[i];
219 range = right_blendpos - left_blendpos;
220 blendfac = (left_blendfac * (right_blendpos - position) +
221 right_blendfac * (position - left_blendpos)) / range;
224 if (brush->pblendcount == 0)
225 return blend_colors(brush->startcolor, brush->endcolor, blendfac);
226 else
228 int i=1;
229 ARGB left_blendcolor, right_blendcolor;
230 REAL left_blendpos, right_blendpos;
232 /* locate the blend colors surrounding this position */
233 while (blendfac > brush->pblendpos[i])
234 i++;
236 /* interpolate between the blend colors */
237 left_blendpos = brush->pblendpos[i-1];
238 left_blendcolor = brush->pblendcolor[i-1];
239 right_blendpos = brush->pblendpos[i];
240 right_blendcolor = brush->pblendcolor[i];
241 blendfac = (blendfac - left_blendpos) / (right_blendpos - left_blendpos);
242 return blend_colors(left_blendcolor, right_blendcolor, blendfac);
246 static void brush_fill_path(GpGraphics *graphics, GpBrush* brush)
248 switch (brush->bt)
250 case BrushTypeLinearGradient:
252 GpLineGradient *line = (GpLineGradient*)brush;
253 RECT rc;
255 SelectClipPath(graphics->hdc, RGN_AND);
256 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
258 GpPointF endpointsf[2];
259 POINT endpointsi[2];
260 POINT poly[4];
262 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
264 endpointsf[0] = line->startpoint;
265 endpointsf[1] = line->endpoint;
266 transform_and_round_points(graphics, endpointsi, endpointsf, 2);
268 if (abs(endpointsi[0].x-endpointsi[1].x) > abs(endpointsi[0].y-endpointsi[1].y))
270 /* vertical-ish gradient */
271 int startx, endx; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
272 int startbottomx; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
273 int width;
274 COLORREF col;
275 HBRUSH hbrush, hprevbrush;
276 int leftx, rightx; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
277 int x;
278 int tilt; /* horizontal distance covered by a gradient line */
280 startx = roundr((rc.top - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X);
281 endx = roundr((rc.top - endpointsf[1].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[1].X);
282 width = endx - startx;
283 startbottomx = roundr((rc.bottom - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X);
284 tilt = startx - startbottomx;
286 if (startx >= startbottomx)
288 leftx = rc.left;
289 rightx = rc.right + tilt;
291 else
293 leftx = rc.left + tilt;
294 rightx = rc.right;
297 poly[0].y = rc.bottom;
298 poly[1].y = rc.top;
299 poly[2].y = rc.top;
300 poly[3].y = rc.bottom;
302 for (x=leftx; x<=rightx; x++)
304 ARGB argb = blend_line_gradient(line, (x-startx)/(REAL)width);
305 col = ARGB2COLORREF(argb);
306 hbrush = CreateSolidBrush(col);
307 hprevbrush = SelectObject(graphics->hdc, hbrush);
308 poly[0].x = x - tilt - 1;
309 poly[1].x = x - 1;
310 poly[2].x = x;
311 poly[3].x = x - tilt;
312 Polygon(graphics->hdc, poly, 4);
313 SelectObject(graphics->hdc, hprevbrush);
314 DeleteObject(hbrush);
317 else if (endpointsi[0].y != endpointsi[1].y)
319 /* horizontal-ish gradient */
320 int starty, endy; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
321 int startrighty; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
322 int height;
323 COLORREF col;
324 HBRUSH hbrush, hprevbrush;
325 int topy, bottomy; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
326 int y;
327 int tilt; /* vertical distance covered by a gradient line */
329 starty = roundr((rc.left - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y);
330 endy = roundr((rc.left - endpointsf[1].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[1].Y);
331 height = endy - starty;
332 startrighty = roundr((rc.right - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y);
333 tilt = starty - startrighty;
335 if (starty >= startrighty)
337 topy = rc.top;
338 bottomy = rc.bottom + tilt;
340 else
342 topy = rc.top + tilt;
343 bottomy = rc.bottom;
346 poly[0].x = rc.right;
347 poly[1].x = rc.left;
348 poly[2].x = rc.left;
349 poly[3].x = rc.right;
351 for (y=topy; y<=bottomy; y++)
353 ARGB argb = blend_line_gradient(line, (y-starty)/(REAL)height);
354 col = ARGB2COLORREF(argb);
355 hbrush = CreateSolidBrush(col);
356 hprevbrush = SelectObject(graphics->hdc, hbrush);
357 poly[0].y = y - tilt - 1;
358 poly[1].y = y - 1;
359 poly[2].y = y;
360 poly[3].y = y - tilt;
361 Polygon(graphics->hdc, poly, 4);
362 SelectObject(graphics->hdc, hprevbrush);
363 DeleteObject(hbrush);
366 /* else startpoint == endpoint */
368 break;
370 case BrushTypeSolidColor:
372 GpSolidFill *fill = (GpSolidFill*)brush;
373 if (fill->bmp)
375 RECT rc;
376 /* partially transparent fill */
378 SelectClipPath(graphics->hdc, RGN_AND);
379 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
381 HDC hdc = CreateCompatibleDC(NULL);
382 HBITMAP oldbmp;
383 BLENDFUNCTION bf;
385 if (!hdc) break;
387 oldbmp = SelectObject(hdc, fill->bmp);
389 bf.BlendOp = AC_SRC_OVER;
390 bf.BlendFlags = 0;
391 bf.SourceConstantAlpha = 255;
392 bf.AlphaFormat = AC_SRC_ALPHA;
394 GdiAlphaBlend(graphics->hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdc, 0, 0, 1, 1, bf);
396 SelectObject(hdc, oldbmp);
397 DeleteDC(hdc);
400 break;
402 /* else fall through */
404 default:
405 SelectObject(graphics->hdc, brush->gdibrush);
406 FillPath(graphics->hdc);
407 break;
411 /* GdipDrawPie/GdipFillPie helper function */
412 static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width,
413 REAL height, REAL startAngle, REAL sweepAngle)
415 GpPointF ptf[4];
416 POINT pti[4];
418 ptf[0].X = x;
419 ptf[0].Y = y;
420 ptf[1].X = x + width;
421 ptf[1].Y = y + height;
423 deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y);
424 deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y);
426 transform_and_round_points(graphics, pti, ptf, 4);
428 Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x,
429 pti[2].y, pti[3].x, pti[3].y);
432 /* Draws the linecap the specified color and size on the hdc. The linecap is in
433 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
434 * should not be called on an hdc that has a path you care about. */
435 static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
436 const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
438 HGDIOBJ oldbrush = NULL, oldpen = NULL;
439 GpMatrix *matrix = NULL;
440 HBRUSH brush = NULL;
441 HPEN pen = NULL;
442 PointF ptf[4], *custptf = NULL;
443 POINT pt[4], *custpt = NULL;
444 BYTE *tp = NULL;
445 REAL theta, dsmall, dbig, dx, dy = 0.0;
446 INT i, count;
447 LOGBRUSH lb;
448 BOOL customstroke;
450 if((x1 == x2) && (y1 == y2))
451 return;
453 theta = gdiplus_atan2(y2 - y1, x2 - x1);
455 customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
456 if(!customstroke){
457 brush = CreateSolidBrush(color);
458 lb.lbStyle = BS_SOLID;
459 lb.lbColor = color;
460 lb.lbHatch = 0;
461 pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
462 PS_JOIN_MITER, 1, &lb, 0,
463 NULL);
464 oldbrush = SelectObject(graphics->hdc, brush);
465 oldpen = SelectObject(graphics->hdc, pen);
468 switch(cap){
469 case LineCapFlat:
470 break;
471 case LineCapSquare:
472 case LineCapSquareAnchor:
473 case LineCapDiamondAnchor:
474 size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0;
475 if(cap == LineCapDiamondAnchor){
476 dsmall = cos(theta + M_PI_2) * size;
477 dbig = sin(theta + M_PI_2) * size;
479 else{
480 dsmall = cos(theta + M_PI_4) * size;
481 dbig = sin(theta + M_PI_4) * size;
484 ptf[0].X = x2 - dsmall;
485 ptf[1].X = x2 + dbig;
487 ptf[0].Y = y2 - dbig;
488 ptf[3].Y = y2 + dsmall;
490 ptf[1].Y = y2 - dsmall;
491 ptf[2].Y = y2 + dbig;
493 ptf[3].X = x2 - dbig;
494 ptf[2].X = x2 + dsmall;
496 transform_and_round_points(graphics, pt, ptf, 4);
497 Polygon(graphics->hdc, pt, 4);
499 break;
500 case LineCapArrowAnchor:
501 size = size * 4.0 / sqrt(3.0);
503 dx = cos(M_PI / 6.0 + theta) * size;
504 dy = sin(M_PI / 6.0 + theta) * size;
506 ptf[0].X = x2 - dx;
507 ptf[0].Y = y2 - dy;
509 dx = cos(- M_PI / 6.0 + theta) * size;
510 dy = sin(- M_PI / 6.0 + theta) * size;
512 ptf[1].X = x2 - dx;
513 ptf[1].Y = y2 - dy;
515 ptf[2].X = x2;
516 ptf[2].Y = y2;
518 transform_and_round_points(graphics, pt, ptf, 3);
519 Polygon(graphics->hdc, pt, 3);
521 break;
522 case LineCapRoundAnchor:
523 dx = dy = ANCHOR_WIDTH * size / 2.0;
525 ptf[0].X = x2 - dx;
526 ptf[0].Y = y2 - dy;
527 ptf[1].X = x2 + dx;
528 ptf[1].Y = y2 + dy;
530 transform_and_round_points(graphics, pt, ptf, 2);
531 Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
533 break;
534 case LineCapTriangle:
535 size = size / 2.0;
536 dx = cos(M_PI_2 + theta) * size;
537 dy = sin(M_PI_2 + theta) * size;
539 ptf[0].X = x2 - dx;
540 ptf[0].Y = y2 - dy;
541 ptf[1].X = x2 + dx;
542 ptf[1].Y = y2 + dy;
544 dx = cos(theta) * size;
545 dy = sin(theta) * size;
547 ptf[2].X = x2 + dx;
548 ptf[2].Y = y2 + dy;
550 transform_and_round_points(graphics, pt, ptf, 3);
551 Polygon(graphics->hdc, pt, 3);
553 break;
554 case LineCapRound:
555 dx = dy = size / 2.0;
557 ptf[0].X = x2 - dx;
558 ptf[0].Y = y2 - dy;
559 ptf[1].X = x2 + dx;
560 ptf[1].Y = y2 + dy;
562 dx = -cos(M_PI_2 + theta) * size;
563 dy = -sin(M_PI_2 + theta) * size;
565 ptf[2].X = x2 - dx;
566 ptf[2].Y = y2 - dy;
567 ptf[3].X = x2 + dx;
568 ptf[3].Y = y2 + dy;
570 transform_and_round_points(graphics, pt, ptf, 4);
571 Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x,
572 pt[2].y, pt[3].x, pt[3].y);
574 break;
575 case LineCapCustom:
576 if(!custom)
577 break;
579 count = custom->pathdata.Count;
580 custptf = GdipAlloc(count * sizeof(PointF));
581 custpt = GdipAlloc(count * sizeof(POINT));
582 tp = GdipAlloc(count);
584 if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok))
585 goto custend;
587 memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF));
589 GdipScaleMatrix(matrix, size, size, MatrixOrderAppend);
590 GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2),
591 MatrixOrderAppend);
592 GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend);
593 GdipTransformMatrixPoints(matrix, custptf, count);
595 transform_and_round_points(graphics, custpt, custptf, count);
597 for(i = 0; i < count; i++)
598 tp[i] = convert_path_point_type(custom->pathdata.Types[i]);
600 if(custom->fill){
601 BeginPath(graphics->hdc);
602 PolyDraw(graphics->hdc, custpt, tp, count);
603 EndPath(graphics->hdc);
604 StrokeAndFillPath(graphics->hdc);
606 else
607 PolyDraw(graphics->hdc, custpt, tp, count);
609 custend:
610 GdipFree(custptf);
611 GdipFree(custpt);
612 GdipFree(tp);
613 GdipDeleteMatrix(matrix);
614 break;
615 default:
616 break;
619 if(!customstroke){
620 SelectObject(graphics->hdc, oldbrush);
621 SelectObject(graphics->hdc, oldpen);
622 DeleteObject(brush);
623 DeleteObject(pen);
627 /* Shortens the line by the given percent by changing x2, y2.
628 * If percent is > 1.0 then the line will change direction.
629 * If percent is negative it can lengthen the line. */
630 static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL percent)
632 REAL dist, theta, dx, dy;
634 if((y1 == *y2) && (x1 == *x2))
635 return;
637 dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent;
638 theta = gdiplus_atan2((*y2 - y1), (*x2 - x1));
639 dx = cos(theta) * dist;
640 dy = sin(theta) * dist;
642 *x2 = *x2 + dx;
643 *y2 = *y2 + dy;
646 /* Shortens the line by the given amount by changing x2, y2.
647 * If the amount is greater than the distance, the line will become length 0.
648 * If the amount is negative, it can lengthen the line. */
649 static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt)
651 REAL dx, dy, percent;
653 dx = *x2 - x1;
654 dy = *y2 - y1;
655 if(dx == 0 && dy == 0)
656 return;
658 percent = amt / sqrt(dx * dx + dy * dy);
659 if(percent >= 1.0){
660 *x2 = x1;
661 *y2 = y1;
662 return;
665 shorten_line_percent(x1, y1, x2, y2, percent);
668 /* Draws lines between the given points, and if caps is true then draws an endcap
669 * at the end of the last line. */
670 static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen,
671 GDIPCONST GpPointF * pt, INT count, BOOL caps)
673 POINT *pti = NULL;
674 GpPointF *ptcopy = NULL;
675 GpStatus status = GenericError;
677 if(!count)
678 return Ok;
680 pti = GdipAlloc(count * sizeof(POINT));
681 ptcopy = GdipAlloc(count * sizeof(GpPointF));
683 if(!pti || !ptcopy){
684 status = OutOfMemory;
685 goto end;
688 memcpy(ptcopy, pt, count * sizeof(GpPointF));
690 if(caps){
691 if(pen->endcap == LineCapArrowAnchor)
692 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
693 &ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width);
694 else if((pen->endcap == LineCapCustom) && pen->customend)
695 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
696 &ptcopy[count-1].X, &ptcopy[count-1].Y,
697 pen->customend->inset * pen->width);
699 if(pen->startcap == LineCapArrowAnchor)
700 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
701 &ptcopy[0].X, &ptcopy[0].Y, pen->width);
702 else if((pen->startcap == LineCapCustom) && pen->customstart)
703 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
704 &ptcopy[0].X, &ptcopy[0].Y,
705 pen->customstart->inset * pen->width);
707 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
708 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
709 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
710 pt[1].X, pt[1].Y, pt[0].X, pt[0].Y);
713 transform_and_round_points(graphics, pti, ptcopy, count);
715 if(Polyline(graphics->hdc, pti, count))
716 status = Ok;
718 end:
719 GdipFree(pti);
720 GdipFree(ptcopy);
722 return status;
725 /* Conducts a linear search to find the bezier points that will back off
726 * the endpoint of the curve by a distance of amt. Linear search works
727 * better than binary in this case because there are multiple solutions,
728 * and binary searches often find a bad one. I don't think this is what
729 * Windows does but short of rendering the bezier without GDI's help it's
730 * the best we can do. If rev then work from the start of the passed points
731 * instead of the end. */
732 static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev)
734 GpPointF origpt[4];
735 REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0;
736 INT i, first = 0, second = 1, third = 2, fourth = 3;
738 if(rev){
739 first = 3;
740 second = 2;
741 third = 1;
742 fourth = 0;
745 origx = pt[fourth].X;
746 origy = pt[fourth].Y;
747 memcpy(origpt, pt, sizeof(GpPointF) * 4);
749 for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){
750 /* reset bezier points to original values */
751 memcpy(pt, origpt, sizeof(GpPointF) * 4);
752 /* Perform magic on bezier points. Order is important here.*/
753 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
754 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
755 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
756 shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent);
757 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
758 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
760 dx = pt[fourth].X - origx;
761 dy = pt[fourth].Y - origy;
763 diff = sqrt(dx * dx + dy * dy);
764 percent += 0.0005 * amt;
768 /* Draws bezier curves between given points, and if caps is true then draws an
769 * endcap at the end of the last line. */
770 static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
771 GDIPCONST GpPointF * pt, INT count, BOOL caps)
773 POINT *pti;
774 GpPointF *ptcopy;
775 GpStatus status = GenericError;
777 if(!count)
778 return Ok;
780 pti = GdipAlloc(count * sizeof(POINT));
781 ptcopy = GdipAlloc(count * sizeof(GpPointF));
783 if(!pti || !ptcopy){
784 status = OutOfMemory;
785 goto end;
788 memcpy(ptcopy, pt, count * sizeof(GpPointF));
790 if(caps){
791 if(pen->endcap == LineCapArrowAnchor)
792 shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
793 else if((pen->endcap == LineCapCustom) && pen->customend)
794 shorten_bezier_amt(&ptcopy[count-4], pen->width * pen->customend->inset,
795 FALSE);
797 if(pen->startcap == LineCapArrowAnchor)
798 shorten_bezier_amt(ptcopy, pen->width, TRUE);
799 else if((pen->startcap == LineCapCustom) && pen->customstart)
800 shorten_bezier_amt(ptcopy, pen->width * pen->customstart->inset, TRUE);
802 /* the direction of the line cap is parallel to the direction at the
803 * end of the bezier (which, if it has been shortened, is not the same
804 * as the direction from pt[count-2] to pt[count-1]) */
805 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
806 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
807 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
808 pt[count - 1].X, pt[count - 1].Y);
810 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
811 pt[0].X - (ptcopy[0].X - ptcopy[1].X),
812 pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
815 transform_and_round_points(graphics, pti, ptcopy, count);
817 PolyBezier(graphics->hdc, pti, count);
819 status = Ok;
821 end:
822 GdipFree(pti);
823 GdipFree(ptcopy);
825 return status;
828 /* Draws a combination of bezier curves and lines between points. */
829 static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
830 GDIPCONST BYTE * types, INT count, BOOL caps)
832 POINT *pti = GdipAlloc(count * sizeof(POINT));
833 BYTE *tp = GdipAlloc(count);
834 GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
835 INT i, j;
836 GpStatus status = GenericError;
838 if(!count){
839 status = Ok;
840 goto end;
842 if(!pti || !tp || !ptcopy){
843 status = OutOfMemory;
844 goto end;
847 for(i = 1; i < count; i++){
848 if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
849 if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
850 || !(types[i + 1] & PathPointTypeBezier)){
851 ERR("Bad bezier points\n");
852 goto end;
854 i += 2;
858 memcpy(ptcopy, pt, count * sizeof(GpPointF));
860 /* If we are drawing caps, go through the points and adjust them accordingly,
861 * and draw the caps. */
862 if(caps){
863 switch(types[count - 1] & PathPointTypePathTypeMask){
864 case PathPointTypeBezier:
865 if(pen->endcap == LineCapArrowAnchor)
866 shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
867 else if((pen->endcap == LineCapCustom) && pen->customend)
868 shorten_bezier_amt(&ptcopy[count - 4],
869 pen->width * pen->customend->inset, FALSE);
871 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
872 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
873 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
874 pt[count - 1].X, pt[count - 1].Y);
876 break;
877 case PathPointTypeLine:
878 if(pen->endcap == LineCapArrowAnchor)
879 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
880 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
881 pen->width);
882 else if((pen->endcap == LineCapCustom) && pen->customend)
883 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
884 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
885 pen->customend->inset * pen->width);
887 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
888 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
889 pt[count - 1].Y);
891 break;
892 default:
893 ERR("Bad path last point\n");
894 goto end;
897 /* Find start of points */
898 for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
899 == PathPointTypeStart); j++);
901 switch(types[j] & PathPointTypePathTypeMask){
902 case PathPointTypeBezier:
903 if(pen->startcap == LineCapArrowAnchor)
904 shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
905 else if((pen->startcap == LineCapCustom) && pen->customstart)
906 shorten_bezier_amt(&ptcopy[j - 1],
907 pen->width * pen->customstart->inset, TRUE);
909 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
910 pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
911 pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
912 pt[j - 1].X, pt[j - 1].Y);
914 break;
915 case PathPointTypeLine:
916 if(pen->startcap == LineCapArrowAnchor)
917 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
918 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
919 pen->width);
920 else if((pen->startcap == LineCapCustom) && pen->customstart)
921 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
922 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
923 pen->customstart->inset * pen->width);
925 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
926 pt[j].X, pt[j].Y, pt[j - 1].X,
927 pt[j - 1].Y);
929 break;
930 default:
931 ERR("Bad path points\n");
932 goto end;
936 transform_and_round_points(graphics, pti, ptcopy, count);
938 for(i = 0; i < count; i++){
939 tp[i] = convert_path_point_type(types[i]);
942 PolyDraw(graphics->hdc, pti, tp, count);
944 status = Ok;
946 end:
947 GdipFree(pti);
948 GdipFree(ptcopy);
949 GdipFree(tp);
951 return status;
954 GpStatus trace_path(GpGraphics *graphics, GpPath *path)
956 GpStatus result;
958 BeginPath(graphics->hdc);
959 result = draw_poly(graphics, NULL, path->pathdata.Points,
960 path->pathdata.Types, path->pathdata.Count, FALSE);
961 EndPath(graphics->hdc);
962 return result;
965 typedef struct _GraphicsContainerItem {
966 struct list entry;
967 GraphicsContainer contid;
969 SmoothingMode smoothing;
970 CompositingQuality compqual;
971 InterpolationMode interpolation;
972 CompositingMode compmode;
973 TextRenderingHint texthint;
974 REAL scale;
975 GpUnit unit;
976 PixelOffsetMode pixeloffset;
977 UINT textcontrast;
978 GpMatrix* worldtrans;
979 GpRegion* clip;
980 } GraphicsContainerItem;
982 static GpStatus init_container(GraphicsContainerItem** container,
983 GDIPCONST GpGraphics* graphics){
984 GpStatus sts;
986 *container = GdipAlloc(sizeof(GraphicsContainerItem));
987 if(!(*container))
988 return OutOfMemory;
990 (*container)->contid = graphics->contid + 1;
992 (*container)->smoothing = graphics->smoothing;
993 (*container)->compqual = graphics->compqual;
994 (*container)->interpolation = graphics->interpolation;
995 (*container)->compmode = graphics->compmode;
996 (*container)->texthint = graphics->texthint;
997 (*container)->scale = graphics->scale;
998 (*container)->unit = graphics->unit;
999 (*container)->textcontrast = graphics->textcontrast;
1000 (*container)->pixeloffset = graphics->pixeloffset;
1002 sts = GdipCloneMatrix(graphics->worldtrans, &(*container)->worldtrans);
1003 if(sts != Ok){
1004 GdipFree(*container);
1005 *container = NULL;
1006 return sts;
1009 sts = GdipCloneRegion(graphics->clip, &(*container)->clip);
1010 if(sts != Ok){
1011 GdipDeleteMatrix((*container)->worldtrans);
1012 GdipFree(*container);
1013 *container = NULL;
1014 return sts;
1017 return Ok;
1020 static void delete_container(GraphicsContainerItem* container){
1021 GdipDeleteMatrix(container->worldtrans);
1022 GdipDeleteRegion(container->clip);
1023 GdipFree(container);
1026 static GpStatus restore_container(GpGraphics* graphics,
1027 GDIPCONST GraphicsContainerItem* container){
1028 GpStatus sts;
1029 GpMatrix *newTrans;
1030 GpRegion *newClip;
1032 sts = GdipCloneMatrix(container->worldtrans, &newTrans);
1033 if(sts != Ok)
1034 return sts;
1036 sts = GdipCloneRegion(container->clip, &newClip);
1037 if(sts != Ok){
1038 GdipDeleteMatrix(newTrans);
1039 return sts;
1042 GdipDeleteMatrix(graphics->worldtrans);
1043 graphics->worldtrans = newTrans;
1045 GdipDeleteRegion(graphics->clip);
1046 graphics->clip = newClip;
1048 graphics->contid = container->contid - 1;
1050 graphics->smoothing = container->smoothing;
1051 graphics->compqual = container->compqual;
1052 graphics->interpolation = container->interpolation;
1053 graphics->compmode = container->compmode;
1054 graphics->texthint = container->texthint;
1055 graphics->scale = container->scale;
1056 graphics->unit = container->unit;
1057 graphics->textcontrast = container->textcontrast;
1058 graphics->pixeloffset = container->pixeloffset;
1060 return Ok;
1063 static GpStatus get_graphics_bounds(GpGraphics* graphics, GpRectF* rect)
1065 RECT wnd_rect;
1067 if(graphics->hwnd) {
1068 if(!GetClientRect(graphics->hwnd, &wnd_rect))
1069 return GenericError;
1071 rect->X = wnd_rect.left;
1072 rect->Y = wnd_rect.top;
1073 rect->Width = wnd_rect.right - wnd_rect.left;
1074 rect->Height = wnd_rect.bottom - wnd_rect.top;
1075 }else{
1076 rect->X = 0;
1077 rect->Y = 0;
1078 rect->Width = GetDeviceCaps(graphics->hdc, HORZRES);
1079 rect->Height = GetDeviceCaps(graphics->hdc, VERTRES);
1082 return Ok;
1085 /* on success, rgn will contain the region of the graphics object which
1086 * is visible after clipping has been applied */
1087 static GpStatus get_visible_clip_region(GpGraphics *graphics, GpRegion *rgn)
1089 GpStatus stat;
1090 GpRectF rectf;
1091 GpRegion* tmp;
1093 if((stat = get_graphics_bounds(graphics, &rectf)) != Ok)
1094 return stat;
1096 if((stat = GdipCreateRegion(&tmp)) != Ok)
1097 return stat;
1099 if((stat = GdipCombineRegionRect(tmp, &rectf, CombineModeReplace)) != Ok)
1100 goto end;
1102 if((stat = GdipCombineRegionRegion(tmp, graphics->clip, CombineModeIntersect)) != Ok)
1103 goto end;
1105 stat = GdipCombineRegionRegion(rgn, tmp, CombineModeReplace);
1107 end:
1108 GdipDeleteRegion(tmp);
1109 return stat;
1112 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
1114 TRACE("(%p, %p)\n", hdc, graphics);
1116 return GdipCreateFromHDC2(hdc, NULL, graphics);
1119 GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **graphics)
1121 GpStatus retval;
1123 TRACE("(%p, %p, %p)\n", hdc, hDevice, graphics);
1125 if(hDevice != NULL) {
1126 FIXME("Don't know how to handle parameter hDevice\n");
1127 return NotImplemented;
1130 if(hdc == NULL)
1131 return OutOfMemory;
1133 if(graphics == NULL)
1134 return InvalidParameter;
1136 *graphics = GdipAlloc(sizeof(GpGraphics));
1137 if(!*graphics) return OutOfMemory;
1139 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
1140 GdipFree(*graphics);
1141 return retval;
1144 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
1145 GdipFree((*graphics)->worldtrans);
1146 GdipFree(*graphics);
1147 return retval;
1150 (*graphics)->hdc = hdc;
1151 (*graphics)->hwnd = WindowFromDC(hdc);
1152 (*graphics)->owndc = FALSE;
1153 (*graphics)->smoothing = SmoothingModeDefault;
1154 (*graphics)->compqual = CompositingQualityDefault;
1155 (*graphics)->interpolation = InterpolationModeDefault;
1156 (*graphics)->pixeloffset = PixelOffsetModeDefault;
1157 (*graphics)->compmode = CompositingModeSourceOver;
1158 (*graphics)->unit = UnitDisplay;
1159 (*graphics)->scale = 1.0;
1160 (*graphics)->busy = FALSE;
1161 (*graphics)->textcontrast = 4;
1162 list_init(&(*graphics)->containers);
1163 (*graphics)->contid = 0;
1165 TRACE("<-- %p\n", *graphics);
1167 return Ok;
1170 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
1172 GpStatus ret;
1173 HDC hdc;
1175 TRACE("(%p, %p)\n", hwnd, graphics);
1177 hdc = GetDC(hwnd);
1179 if((ret = GdipCreateFromHDC(hdc, graphics)) != Ok)
1181 ReleaseDC(hwnd, hdc);
1182 return ret;
1185 (*graphics)->hwnd = hwnd;
1186 (*graphics)->owndc = TRUE;
1188 return Ok;
1191 /* FIXME: no icm handling */
1192 GpStatus WINGDIPAPI GdipCreateFromHWNDICM(HWND hwnd, GpGraphics **graphics)
1194 TRACE("(%p, %p)\n", hwnd, graphics);
1196 return GdipCreateFromHWND(hwnd, graphics);
1199 GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
1200 GpMetafile **metafile)
1202 static int calls;
1204 TRACE("(%p,%i,%p)\n", hemf, delete, metafile);
1206 if(!hemf || !metafile)
1207 return InvalidParameter;
1209 if(!(calls++))
1210 FIXME("not implemented\n");
1212 return NotImplemented;
1215 GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
1216 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
1218 IStream *stream = NULL;
1219 UINT read;
1220 BYTE* copy;
1221 HENHMETAFILE hemf;
1222 GpStatus retval = Ok;
1224 TRACE("(%p, %d, %p, %p)\n", hwmf, delete, placeable, metafile);
1226 if(!hwmf || !metafile || !placeable)
1227 return InvalidParameter;
1229 *metafile = NULL;
1230 read = GetMetaFileBitsEx(hwmf, 0, NULL);
1231 if(!read)
1232 return GenericError;
1233 copy = GdipAlloc(read);
1234 GetMetaFileBitsEx(hwmf, read, copy);
1236 hemf = SetWinMetaFileBits(read, copy, NULL, NULL);
1237 GdipFree(copy);
1239 read = GetEnhMetaFileBits(hemf, 0, NULL);
1240 copy = GdipAlloc(read);
1241 GetEnhMetaFileBits(hemf, read, copy);
1242 DeleteEnhMetaFile(hemf);
1244 if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
1245 ERR("could not make stream\n");
1246 GdipFree(copy);
1247 retval = GenericError;
1248 goto err;
1251 *metafile = GdipAlloc(sizeof(GpMetafile));
1252 if(!*metafile){
1253 retval = OutOfMemory;
1254 goto err;
1257 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1258 (LPVOID*) &((*metafile)->image.picture)) != S_OK)
1260 retval = GenericError;
1261 goto err;
1265 (*metafile)->image.type = ImageTypeMetafile;
1266 memcpy(&(*metafile)->image.format, &ImageFormatWMF, sizeof(GUID));
1267 (*metafile)->image.palette_flags = 0;
1268 (*metafile)->image.palette_count = 0;
1269 (*metafile)->image.palette_size = 0;
1270 (*metafile)->image.palette_entries = NULL;
1271 (*metafile)->image.xres = (REAL)placeable->Inch;
1272 (*metafile)->image.yres = (REAL)placeable->Inch;
1273 (*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch);
1274 (*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Top) / ((REAL) placeable->Inch);
1275 (*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right
1276 - placeable->BoundingBox.Left)) / ((REAL) placeable->Inch);
1277 (*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom
1278 - placeable->BoundingBox.Top)) / ((REAL) placeable->Inch);
1279 (*metafile)->unit = UnitInch;
1281 if(delete)
1282 DeleteMetaFile(hwmf);
1284 TRACE("<-- %p\n", *metafile);
1286 err:
1287 if (retval != Ok)
1288 GdipFree(*metafile);
1289 IStream_Release(stream);
1290 return retval;
1293 GpStatus WINGDIPAPI GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR *file,
1294 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
1296 HMETAFILE hmf = GetMetaFileW(file);
1298 TRACE("(%s, %p, %p)\n", debugstr_w(file), placeable, metafile);
1300 if(!hmf) return InvalidParameter;
1302 return GdipCreateMetafileFromWmf(hmf, TRUE, placeable, metafile);
1305 GpStatus WINGDIPAPI GdipCreateMetafileFromFile(GDIPCONST WCHAR *file,
1306 GpMetafile **metafile)
1308 FIXME("(%p, %p): stub\n", file, metafile);
1309 return NotImplemented;
1312 GpStatus WINGDIPAPI GdipCreateMetafileFromStream(IStream *stream,
1313 GpMetafile **metafile)
1315 FIXME("(%p, %p): stub\n", stream, metafile);
1316 return NotImplemented;
1319 GpStatus WINGDIPAPI GdipCreateStreamOnFile(GDIPCONST WCHAR * filename,
1320 UINT access, IStream **stream)
1322 DWORD dwMode;
1323 HRESULT ret;
1325 TRACE("(%s, %u, %p)\n", debugstr_w(filename), access, stream);
1327 if(!stream || !filename)
1328 return InvalidParameter;
1330 if(access & GENERIC_WRITE)
1331 dwMode = STGM_SHARE_DENY_WRITE | STGM_WRITE | STGM_CREATE;
1332 else if(access & GENERIC_READ)
1333 dwMode = STGM_SHARE_DENY_WRITE | STGM_READ | STGM_FAILIFTHERE;
1334 else
1335 return InvalidParameter;
1337 ret = SHCreateStreamOnFileW(filename, dwMode, stream);
1339 return hresult_to_status(ret);
1342 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
1344 GraphicsContainerItem *cont, *next;
1345 TRACE("(%p)\n", graphics);
1347 if(!graphics) return InvalidParameter;
1348 if(graphics->busy) return ObjectBusy;
1350 if(graphics->owndc)
1351 ReleaseDC(graphics->hwnd, graphics->hdc);
1353 LIST_FOR_EACH_ENTRY_SAFE(cont, next, &graphics->containers, GraphicsContainerItem, entry){
1354 list_remove(&cont->entry);
1355 delete_container(cont);
1358 GdipDeleteRegion(graphics->clip);
1359 GdipDeleteMatrix(graphics->worldtrans);
1360 GdipFree(graphics);
1362 return Ok;
1365 GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
1366 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1368 INT save_state, num_pts;
1369 GpPointF points[MAX_ARC_PTS];
1370 GpStatus retval;
1372 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
1373 width, height, startAngle, sweepAngle);
1375 if(!graphics || !pen || width <= 0 || height <= 0)
1376 return InvalidParameter;
1378 if(graphics->busy)
1379 return ObjectBusy;
1381 num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
1383 save_state = prepare_dc(graphics, pen);
1385 retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
1387 restore_dc(graphics, save_state);
1389 return retval;
1392 GpStatus WINGDIPAPI GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x,
1393 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
1395 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
1396 width, height, startAngle, sweepAngle);
1398 return GdipDrawArc(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
1401 GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
1402 REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
1404 INT save_state;
1405 GpPointF pt[4];
1406 GpStatus retval;
1408 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1,
1409 x2, y2, x3, y3, x4, y4);
1411 if(!graphics || !pen)
1412 return InvalidParameter;
1414 if(graphics->busy)
1415 return ObjectBusy;
1417 pt[0].X = x1;
1418 pt[0].Y = y1;
1419 pt[1].X = x2;
1420 pt[1].Y = y2;
1421 pt[2].X = x3;
1422 pt[2].Y = y3;
1423 pt[3].X = x4;
1424 pt[3].Y = y4;
1426 save_state = prepare_dc(graphics, pen);
1428 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
1430 restore_dc(graphics, save_state);
1432 return retval;
1435 GpStatus WINGDIPAPI GdipDrawBezierI(GpGraphics *graphics, GpPen *pen, INT x1,
1436 INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4)
1438 INT save_state;
1439 GpPointF pt[4];
1440 GpStatus retval;
1442 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics, pen, x1, y1,
1443 x2, y2, x3, y3, x4, y4);
1445 if(!graphics || !pen)
1446 return InvalidParameter;
1448 if(graphics->busy)
1449 return ObjectBusy;
1451 pt[0].X = x1;
1452 pt[0].Y = y1;
1453 pt[1].X = x2;
1454 pt[1].Y = y2;
1455 pt[2].X = x3;
1456 pt[2].Y = y3;
1457 pt[3].X = x4;
1458 pt[3].Y = y4;
1460 save_state = prepare_dc(graphics, pen);
1462 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
1464 restore_dc(graphics, save_state);
1466 return retval;
1469 GpStatus WINGDIPAPI GdipDrawBeziers(GpGraphics *graphics, GpPen *pen,
1470 GDIPCONST GpPointF *points, INT count)
1472 INT i;
1473 GpStatus ret;
1475 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1477 if(!graphics || !pen || !points || (count <= 0))
1478 return InvalidParameter;
1480 if(graphics->busy)
1481 return ObjectBusy;
1483 for(i = 0; i < floor(count / 4); i++){
1484 ret = GdipDrawBezier(graphics, pen,
1485 points[4*i].X, points[4*i].Y,
1486 points[4*i + 1].X, points[4*i + 1].Y,
1487 points[4*i + 2].X, points[4*i + 2].Y,
1488 points[4*i + 3].X, points[4*i + 3].Y);
1489 if(ret != Ok)
1490 return ret;
1493 return Ok;
1496 GpStatus WINGDIPAPI GdipDrawBeziersI(GpGraphics *graphics, GpPen *pen,
1497 GDIPCONST GpPoint *points, INT count)
1499 GpPointF *pts;
1500 GpStatus ret;
1501 INT i;
1503 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1505 if(!graphics || !pen || !points || (count <= 0))
1506 return InvalidParameter;
1508 if(graphics->busy)
1509 return ObjectBusy;
1511 pts = GdipAlloc(sizeof(GpPointF) * count);
1512 if(!pts)
1513 return OutOfMemory;
1515 for(i = 0; i < count; i++){
1516 pts[i].X = (REAL)points[i].X;
1517 pts[i].Y = (REAL)points[i].Y;
1520 ret = GdipDrawBeziers(graphics,pen,pts,count);
1522 GdipFree(pts);
1524 return ret;
1527 GpStatus WINGDIPAPI GdipDrawClosedCurve(GpGraphics *graphics, GpPen *pen,
1528 GDIPCONST GpPointF *points, INT count)
1530 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1532 return GdipDrawClosedCurve2(graphics, pen, points, count, 1.0);
1535 GpStatus WINGDIPAPI GdipDrawClosedCurveI(GpGraphics *graphics, GpPen *pen,
1536 GDIPCONST GpPoint *points, INT count)
1538 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1540 return GdipDrawClosedCurve2I(graphics, pen, points, count, 1.0);
1543 GpStatus WINGDIPAPI GdipDrawClosedCurve2(GpGraphics *graphics, GpPen *pen,
1544 GDIPCONST GpPointF *points, INT count, REAL tension)
1546 GpPath *path;
1547 GpStatus stat;
1549 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1551 if(!graphics || !pen || !points || count <= 0)
1552 return InvalidParameter;
1554 if(graphics->busy)
1555 return ObjectBusy;
1557 if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok)
1558 return stat;
1560 stat = GdipAddPathClosedCurve2(path, points, count, tension);
1561 if(stat != Ok){
1562 GdipDeletePath(path);
1563 return stat;
1566 stat = GdipDrawPath(graphics, pen, path);
1568 GdipDeletePath(path);
1570 return stat;
1573 GpStatus WINGDIPAPI GdipDrawClosedCurve2I(GpGraphics *graphics, GpPen *pen,
1574 GDIPCONST GpPoint *points, INT count, REAL tension)
1576 GpPointF *ptf;
1577 GpStatus stat;
1578 INT i;
1580 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1582 if(!points || count <= 0)
1583 return InvalidParameter;
1585 ptf = GdipAlloc(sizeof(GpPointF)*count);
1586 if(!ptf)
1587 return OutOfMemory;
1589 for(i = 0; i < count; i++){
1590 ptf[i].X = (REAL)points[i].X;
1591 ptf[i].Y = (REAL)points[i].Y;
1594 stat = GdipDrawClosedCurve2(graphics, pen, ptf, count, tension);
1596 GdipFree(ptf);
1598 return stat;
1601 GpStatus WINGDIPAPI GdipDrawCurve(GpGraphics *graphics, GpPen *pen,
1602 GDIPCONST GpPointF *points, INT count)
1604 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1606 return GdipDrawCurve2(graphics,pen,points,count,1.0);
1609 GpStatus WINGDIPAPI GdipDrawCurveI(GpGraphics *graphics, GpPen *pen,
1610 GDIPCONST GpPoint *points, INT count)
1612 GpPointF *pointsF;
1613 GpStatus ret;
1614 INT i;
1616 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1618 if(!points)
1619 return InvalidParameter;
1621 pointsF = GdipAlloc(sizeof(GpPointF)*count);
1622 if(!pointsF)
1623 return OutOfMemory;
1625 for(i = 0; i < count; i++){
1626 pointsF[i].X = (REAL)points[i].X;
1627 pointsF[i].Y = (REAL)points[i].Y;
1630 ret = GdipDrawCurve(graphics,pen,pointsF,count);
1631 GdipFree(pointsF);
1633 return ret;
1636 /* Approximates cardinal spline with Bezier curves. */
1637 GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
1638 GDIPCONST GpPointF *points, INT count, REAL tension)
1640 /* PolyBezier expects count*3-2 points. */
1641 INT i, len_pt = count*3-2, save_state;
1642 GpPointF *pt;
1643 REAL x1, x2, y1, y2;
1644 GpStatus retval;
1646 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1648 if(!graphics || !pen)
1649 return InvalidParameter;
1651 if(graphics->busy)
1652 return ObjectBusy;
1654 if(count < 2)
1655 return InvalidParameter;
1657 pt = GdipAlloc(len_pt * sizeof(GpPointF));
1658 if(!pt)
1659 return OutOfMemory;
1661 tension = tension * TENSION_CONST;
1663 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
1664 tension, &x1, &y1);
1666 pt[0].X = points[0].X;
1667 pt[0].Y = points[0].Y;
1668 pt[1].X = x1;
1669 pt[1].Y = y1;
1671 for(i = 0; i < count-2; i++){
1672 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
1674 pt[3*i+2].X = x1;
1675 pt[3*i+2].Y = y1;
1676 pt[3*i+3].X = points[i+1].X;
1677 pt[3*i+3].Y = points[i+1].Y;
1678 pt[3*i+4].X = x2;
1679 pt[3*i+4].Y = y2;
1682 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
1683 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
1685 pt[len_pt-2].X = x1;
1686 pt[len_pt-2].Y = y1;
1687 pt[len_pt-1].X = points[count-1].X;
1688 pt[len_pt-1].Y = points[count-1].Y;
1690 save_state = prepare_dc(graphics, pen);
1692 retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
1694 GdipFree(pt);
1695 restore_dc(graphics, save_state);
1697 return retval;
1700 GpStatus WINGDIPAPI GdipDrawCurve2I(GpGraphics *graphics, GpPen *pen,
1701 GDIPCONST GpPoint *points, INT count, REAL tension)
1703 GpPointF *pointsF;
1704 GpStatus ret;
1705 INT i;
1707 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1709 if(!points)
1710 return InvalidParameter;
1712 pointsF = GdipAlloc(sizeof(GpPointF)*count);
1713 if(!pointsF)
1714 return OutOfMemory;
1716 for(i = 0; i < count; i++){
1717 pointsF[i].X = (REAL)points[i].X;
1718 pointsF[i].Y = (REAL)points[i].Y;
1721 ret = GdipDrawCurve2(graphics,pen,pointsF,count,tension);
1722 GdipFree(pointsF);
1724 return ret;
1727 GpStatus WINGDIPAPI GdipDrawCurve3(GpGraphics *graphics, GpPen *pen,
1728 GDIPCONST GpPointF *points, INT count, INT offset, INT numberOfSegments,
1729 REAL tension)
1731 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
1733 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
1734 return InvalidParameter;
1737 return GdipDrawCurve2(graphics, pen, points + offset, numberOfSegments + 1, tension);
1740 GpStatus WINGDIPAPI GdipDrawCurve3I(GpGraphics *graphics, GpPen *pen,
1741 GDIPCONST GpPoint *points, INT count, INT offset, INT numberOfSegments,
1742 REAL tension)
1744 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
1746 if(count < 0){
1747 return OutOfMemory;
1750 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
1751 return InvalidParameter;
1754 return GdipDrawCurve2I(graphics, pen, points + offset, numberOfSegments + 1, tension);
1757 GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics *graphics, GpPen *pen, REAL x,
1758 REAL y, REAL width, REAL height)
1760 INT save_state;
1761 GpPointF ptf[2];
1762 POINT pti[2];
1764 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
1766 if(!graphics || !pen)
1767 return InvalidParameter;
1769 if(graphics->busy)
1770 return ObjectBusy;
1772 ptf[0].X = x;
1773 ptf[0].Y = y;
1774 ptf[1].X = x + width;
1775 ptf[1].Y = y + height;
1777 save_state = prepare_dc(graphics, pen);
1778 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1780 transform_and_round_points(graphics, pti, ptf, 2);
1782 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
1784 restore_dc(graphics, save_state);
1786 return Ok;
1789 GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics *graphics, GpPen *pen, INT x,
1790 INT y, INT width, INT height)
1792 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
1794 return GdipDrawEllipse(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1798 GpStatus WINGDIPAPI GdipDrawImage(GpGraphics *graphics, GpImage *image, REAL x, REAL y)
1800 UINT width, height;
1801 GpPointF points[3];
1803 TRACE("(%p, %p, %.2f, %.2f)\n", graphics, image, x, y);
1805 if(!graphics || !image)
1806 return InvalidParameter;
1808 GdipGetImageWidth(image, &width);
1809 GdipGetImageHeight(image, &height);
1811 /* FIXME: we should use the graphics and image dpi, somehow */
1813 points[0].X = points[2].X = x;
1814 points[0].Y = points[1].Y = y;
1815 points[1].X = x + width;
1816 points[2].Y = y + height;
1818 return GdipDrawImagePointsRect(graphics, image, points, 3, 0, 0, width, height,
1819 UnitPixel, NULL, NULL, NULL);
1822 GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x,
1823 INT y)
1825 TRACE("(%p, %p, %d, %d)\n", graphics, image, x, y);
1827 return GdipDrawImage(graphics, image, (REAL)x, (REAL)y);
1830 GpStatus WINGDIPAPI GdipDrawImagePointRect(GpGraphics *graphics, GpImage *image,
1831 REAL x, REAL y, REAL srcx, REAL srcy, REAL srcwidth, REAL srcheight,
1832 GpUnit srcUnit)
1834 GpPointF points[3];
1835 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
1837 points[0].X = points[2].X = x;
1838 points[0].Y = points[1].Y = y;
1840 /* FIXME: convert image coordinates to Graphics coordinates? */
1841 points[1].X = x + srcwidth;
1842 points[2].Y = y + srcheight;
1844 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
1845 srcwidth, srcheight, srcUnit, NULL, NULL, NULL);
1848 GpStatus WINGDIPAPI GdipDrawImagePointRectI(GpGraphics *graphics, GpImage *image,
1849 INT x, INT y, INT srcx, INT srcy, INT srcwidth, INT srcheight,
1850 GpUnit srcUnit)
1852 return GdipDrawImagePointRect(graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
1855 GpStatus WINGDIPAPI GdipDrawImagePoints(GpGraphics *graphics, GpImage *image,
1856 GDIPCONST GpPointF *dstpoints, INT count)
1858 FIXME("(%p, %p, %p, %d): stub\n", graphics, image, dstpoints, count);
1859 return NotImplemented;
1862 GpStatus WINGDIPAPI GdipDrawImagePointsI(GpGraphics *graphics, GpImage *image,
1863 GDIPCONST GpPoint *dstpoints, INT count)
1865 FIXME("(%p, %p, %p, %d): stub\n", graphics, image, dstpoints, count);
1866 return NotImplemented;
1869 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1870 GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
1871 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
1872 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
1873 DrawImageAbort callback, VOID * callbackData)
1875 GpPointF ptf[3];
1876 POINT pti[3];
1877 REAL dx, dy;
1879 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics, image, points,
1880 count, srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
1881 callbackData);
1883 if(!graphics || !image || !points || count != 3)
1884 return InvalidParameter;
1886 TRACE("%s %s %s\n", debugstr_pointf(&points[0]), debugstr_pointf(&points[1]),
1887 debugstr_pointf(&points[2]));
1889 memcpy(ptf, points, 3 * sizeof(GpPointF));
1890 transform_and_round_points(graphics, pti, ptf, 3);
1892 if (image->picture)
1894 if(srcUnit == UnitInch)
1895 dx = dy = (REAL) INCH_HIMETRIC;
1896 else if(srcUnit == UnitPixel){
1897 dx = ((REAL) INCH_HIMETRIC) /
1898 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
1899 dy = ((REAL) INCH_HIMETRIC) /
1900 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
1902 else
1903 return NotImplemented;
1905 if(IPicture_Render(image->picture, graphics->hdc,
1906 pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
1907 srcx * dx, srcy * dy,
1908 srcwidth * dx, srcheight * dy,
1909 NULL) != S_OK){
1910 if(callback)
1911 callback(callbackData);
1912 return GenericError;
1915 else if (image->type == ImageTypeBitmap && ((GpBitmap*)image)->hbitmap)
1917 HDC hdc;
1918 GpBitmap* bitmap = (GpBitmap*)image;
1919 int temp_hdc=0, temp_bitmap=0;
1920 HBITMAP hbitmap, old_hbm=NULL;
1922 if (srcUnit == UnitInch)
1923 dx = dy = 96.0; /* FIXME: use the image resolution */
1924 else if (srcUnit == UnitPixel)
1925 dx = dy = 1.0;
1926 else
1927 return NotImplemented;
1929 if (bitmap->format == PixelFormat32bppARGB)
1931 BITMAPINFOHEADER bih;
1932 BYTE *temp_bits;
1934 /* we need a bitmap with premultiplied alpha */
1935 hdc = CreateCompatibleDC(0);
1936 temp_hdc = 1;
1937 temp_bitmap = 1;
1939 bih.biSize = sizeof(BITMAPINFOHEADER);
1940 bih.biWidth = bitmap->width;
1941 bih.biHeight = -bitmap->height;
1942 bih.biPlanes = 1;
1943 bih.biBitCount = 32;
1944 bih.biCompression = BI_RGB;
1945 bih.biSizeImage = 0;
1946 bih.biXPelsPerMeter = 0;
1947 bih.biYPelsPerMeter = 0;
1948 bih.biClrUsed = 0;
1949 bih.biClrImportant = 0;
1951 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
1952 (void**)&temp_bits, NULL, 0);
1954 convert_32bppARGB_to_32bppPARGB(bitmap->width, bitmap->height,
1955 temp_bits, bitmap->width*4, bitmap->bits, bitmap->stride);
1957 else
1959 hbitmap = bitmap->hbitmap;
1960 hdc = bitmap->hdc;
1961 temp_hdc = (hdc == 0);
1964 if (temp_hdc)
1966 if (!hdc) hdc = CreateCompatibleDC(0);
1967 old_hbm = SelectObject(hdc, hbitmap);
1970 if (bitmap->format == PixelFormat32bppARGB || bitmap->format == PixelFormat32bppPARGB)
1972 BLENDFUNCTION bf;
1974 bf.BlendOp = AC_SRC_OVER;
1975 bf.BlendFlags = 0;
1976 bf.SourceConstantAlpha = 255;
1977 bf.AlphaFormat = AC_SRC_ALPHA;
1979 GdiAlphaBlend(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
1980 hdc, srcx*dx, srcy*dy, srcwidth*dx, srcheight*dy, bf);
1982 else
1984 StretchBlt(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
1985 hdc, srcx*dx, srcy*dy, srcwidth*dx, srcheight*dy, SRCCOPY);
1988 if (temp_hdc)
1990 SelectObject(hdc, old_hbm);
1991 DeleteDC(hdc);
1994 if (temp_bitmap)
1995 DeleteObject(hbitmap);
1997 else
1999 ERR("GpImage with no IPicture or HBITMAP?!\n");
2000 return NotImplemented;
2003 return Ok;
2006 GpStatus WINGDIPAPI GdipDrawImagePointsRectI(GpGraphics *graphics, GpImage *image,
2007 GDIPCONST GpPoint *points, INT count, INT srcx, INT srcy, INT srcwidth,
2008 INT srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
2009 DrawImageAbort callback, VOID * callbackData)
2011 GpPointF pointsF[3];
2012 INT i;
2014 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics, image, points, count,
2015 srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
2016 callbackData);
2018 if(!points || count!=3)
2019 return InvalidParameter;
2021 for(i = 0; i < count; i++){
2022 pointsF[i].X = (REAL)points[i].X;
2023 pointsF[i].Y = (REAL)points[i].Y;
2026 return GdipDrawImagePointsRect(graphics, image, pointsF, count, (REAL)srcx, (REAL)srcy,
2027 (REAL)srcwidth, (REAL)srcheight, srcUnit, imageAttributes,
2028 callback, callbackData);
2031 GpStatus WINGDIPAPI GdipDrawImageRectRect(GpGraphics *graphics, GpImage *image,
2032 REAL dstx, REAL dsty, REAL dstwidth, REAL dstheight, REAL srcx, REAL srcy,
2033 REAL srcwidth, REAL srcheight, GpUnit srcUnit,
2034 GDIPCONST GpImageAttributes* imageattr, DrawImageAbort callback,
2035 VOID * callbackData)
2037 GpPointF points[3];
2039 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
2040 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
2041 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
2043 points[0].X = dstx;
2044 points[0].Y = dsty;
2045 points[1].X = dstx + dstwidth;
2046 points[1].Y = dsty;
2047 points[2].X = dstx;
2048 points[2].Y = dsty + dstheight;
2050 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2051 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
2054 GpStatus WINGDIPAPI GdipDrawImageRectRectI(GpGraphics *graphics, GpImage *image,
2055 INT dstx, INT dsty, INT dstwidth, INT dstheight, INT srcx, INT srcy,
2056 INT srcwidth, INT srcheight, GpUnit srcUnit,
2057 GDIPCONST GpImageAttributes* imageAttributes, DrawImageAbort callback,
2058 VOID * callbackData)
2060 GpPointF points[3];
2062 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
2063 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
2064 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
2066 points[0].X = dstx;
2067 points[0].Y = dsty;
2068 points[1].X = dstx + dstwidth;
2069 points[1].Y = dsty;
2070 points[2].X = dstx;
2071 points[2].Y = dsty + dstheight;
2073 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2074 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
2077 GpStatus WINGDIPAPI GdipDrawImageRect(GpGraphics *graphics, GpImage *image,
2078 REAL x, REAL y, REAL width, REAL height)
2080 RectF bounds;
2081 GpUnit unit;
2082 GpStatus ret;
2084 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, image, x, y, width, height);
2086 if(!graphics || !image)
2087 return InvalidParameter;
2089 ret = GdipGetImageBounds(image, &bounds, &unit);
2090 if(ret != Ok)
2091 return ret;
2093 return GdipDrawImageRectRect(graphics, image, x, y, width, height,
2094 bounds.X, bounds.Y, bounds.Width, bounds.Height,
2095 unit, NULL, NULL, NULL);
2098 GpStatus WINGDIPAPI GdipDrawImageRectI(GpGraphics *graphics, GpImage *image,
2099 INT x, INT y, INT width, INT height)
2101 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, image, x, y, width, height);
2103 return GdipDrawImageRect(graphics, image, (REAL)x, (REAL)y, (REAL)width, (REAL)height);
2106 GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1,
2107 REAL y1, REAL x2, REAL y2)
2109 INT save_state;
2110 GpPointF pt[2];
2111 GpStatus retval;
2113 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1, x2, y2);
2115 if(!pen || !graphics)
2116 return InvalidParameter;
2118 if(graphics->busy)
2119 return ObjectBusy;
2121 pt[0].X = x1;
2122 pt[0].Y = y1;
2123 pt[1].X = x2;
2124 pt[1].Y = y2;
2126 save_state = prepare_dc(graphics, pen);
2128 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
2130 restore_dc(graphics, save_state);
2132 return retval;
2135 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
2136 INT y1, INT x2, INT y2)
2138 INT save_state;
2139 GpPointF pt[2];
2140 GpStatus retval;
2142 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x1, y1, x2, y2);
2144 if(!pen || !graphics)
2145 return InvalidParameter;
2147 if(graphics->busy)
2148 return ObjectBusy;
2150 pt[0].X = (REAL)x1;
2151 pt[0].Y = (REAL)y1;
2152 pt[1].X = (REAL)x2;
2153 pt[1].Y = (REAL)y2;
2155 save_state = prepare_dc(graphics, pen);
2157 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
2159 restore_dc(graphics, save_state);
2161 return retval;
2164 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
2165 GpPointF *points, INT count)
2167 INT save_state;
2168 GpStatus retval;
2170 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2172 if(!pen || !graphics || (count < 2))
2173 return InvalidParameter;
2175 if(graphics->busy)
2176 return ObjectBusy;
2178 save_state = prepare_dc(graphics, pen);
2180 retval = draw_polyline(graphics, pen, points, count, TRUE);
2182 restore_dc(graphics, save_state);
2184 return retval;
2187 GpStatus WINGDIPAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, GDIPCONST
2188 GpPoint *points, INT count)
2190 INT save_state;
2191 GpStatus retval;
2192 GpPointF *ptf = NULL;
2193 int i;
2195 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2197 if(!pen || !graphics || (count < 2))
2198 return InvalidParameter;
2200 if(graphics->busy)
2201 return ObjectBusy;
2203 ptf = GdipAlloc(count * sizeof(GpPointF));
2204 if(!ptf) return OutOfMemory;
2206 for(i = 0; i < count; i ++){
2207 ptf[i].X = (REAL) points[i].X;
2208 ptf[i].Y = (REAL) points[i].Y;
2211 save_state = prepare_dc(graphics, pen);
2213 retval = draw_polyline(graphics, pen, ptf, count, TRUE);
2215 restore_dc(graphics, save_state);
2217 GdipFree(ptf);
2218 return retval;
2221 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
2223 INT save_state;
2224 GpStatus retval;
2226 TRACE("(%p, %p, %p)\n", graphics, pen, path);
2228 if(!pen || !graphics)
2229 return InvalidParameter;
2231 if(graphics->busy)
2232 return ObjectBusy;
2234 save_state = prepare_dc(graphics, pen);
2236 retval = draw_poly(graphics, pen, path->pathdata.Points,
2237 path->pathdata.Types, path->pathdata.Count, TRUE);
2239 restore_dc(graphics, save_state);
2241 return retval;
2244 GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
2245 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2247 INT save_state;
2249 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
2250 width, height, startAngle, sweepAngle);
2252 if(!graphics || !pen)
2253 return InvalidParameter;
2255 if(graphics->busy)
2256 return ObjectBusy;
2258 save_state = prepare_dc(graphics, pen);
2259 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2261 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
2263 restore_dc(graphics, save_state);
2265 return Ok;
2268 GpStatus WINGDIPAPI GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x,
2269 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2271 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
2272 width, height, startAngle, sweepAngle);
2274 return GdipDrawPie(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2277 GpStatus WINGDIPAPI GdipDrawRectangle(GpGraphics *graphics, GpPen *pen, REAL x,
2278 REAL y, REAL width, REAL height)
2280 INT save_state;
2281 GpPointF ptf[4];
2282 POINT pti[4];
2284 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
2286 if(!pen || !graphics)
2287 return InvalidParameter;
2289 if(graphics->busy)
2290 return ObjectBusy;
2292 ptf[0].X = x;
2293 ptf[0].Y = y;
2294 ptf[1].X = x + width;
2295 ptf[1].Y = y;
2296 ptf[2].X = x + width;
2297 ptf[2].Y = y + height;
2298 ptf[3].X = x;
2299 ptf[3].Y = y + height;
2301 save_state = prepare_dc(graphics, pen);
2302 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2304 transform_and_round_points(graphics, pti, ptf, 4);
2305 Polygon(graphics->hdc, pti, 4);
2307 restore_dc(graphics, save_state);
2309 return Ok;
2312 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
2313 INT y, INT width, INT height)
2315 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
2317 return GdipDrawRectangle(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2320 GpStatus WINGDIPAPI GdipDrawRectangles(GpGraphics *graphics, GpPen *pen,
2321 GDIPCONST GpRectF* rects, INT count)
2323 GpPointF *ptf;
2324 POINT *pti;
2325 INT save_state, i;
2327 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
2329 if(!graphics || !pen || !rects || count < 1)
2330 return InvalidParameter;
2332 if(graphics->busy)
2333 return ObjectBusy;
2335 ptf = GdipAlloc(4 * count * sizeof(GpPointF));
2336 pti = GdipAlloc(4 * count * sizeof(POINT));
2338 if(!ptf || !pti){
2339 GdipFree(ptf);
2340 GdipFree(pti);
2341 return OutOfMemory;
2344 for(i = 0; i < count; i++){
2345 ptf[4 * i + 3].X = ptf[4 * i].X = rects[i].X;
2346 ptf[4 * i + 1].Y = ptf[4 * i].Y = rects[i].Y;
2347 ptf[4 * i + 2].X = ptf[4 * i + 1].X = rects[i].X + rects[i].Width;
2348 ptf[4 * i + 3].Y = ptf[4 * i + 2].Y = rects[i].Y + rects[i].Height;
2351 save_state = prepare_dc(graphics, pen);
2352 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2354 transform_and_round_points(graphics, pti, ptf, 4 * count);
2356 for(i = 0; i < count; i++)
2357 Polygon(graphics->hdc, &pti[4 * i], 4);
2359 restore_dc(graphics, save_state);
2361 GdipFree(ptf);
2362 GdipFree(pti);
2364 return Ok;
2367 GpStatus WINGDIPAPI GdipDrawRectanglesI(GpGraphics *graphics, GpPen *pen,
2368 GDIPCONST GpRect* rects, INT count)
2370 GpRectF *rectsF;
2371 GpStatus ret;
2372 INT i;
2374 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
2376 if(!rects || count<=0)
2377 return InvalidParameter;
2379 rectsF = GdipAlloc(sizeof(GpRectF) * count);
2380 if(!rectsF)
2381 return OutOfMemory;
2383 for(i = 0;i < count;i++){
2384 rectsF[i].X = (REAL)rects[i].X;
2385 rectsF[i].Y = (REAL)rects[i].Y;
2386 rectsF[i].Width = (REAL)rects[i].Width;
2387 rectsF[i].Height = (REAL)rects[i].Height;
2390 ret = GdipDrawRectangles(graphics, pen, rectsF, count);
2391 GdipFree(rectsF);
2393 return ret;
2396 GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string,
2397 INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect,
2398 GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush)
2400 HRGN rgn = NULL;
2401 HFONT gdifont;
2402 LOGFONTW lfw;
2403 TEXTMETRICW textmet;
2404 GpPointF pt[3], rectcpy[4];
2405 POINT corners[4];
2406 WCHAR* stringdup;
2407 REAL angle, ang_cos, ang_sin, rel_width, rel_height;
2408 INT sum = 0, height = 0, offsety = 0, fit, fitcpy, save_state, i, j, lret, nwidth,
2409 nheight, lineend;
2410 SIZE size;
2411 POINT drawbase;
2412 UINT drawflags;
2413 RECT drawcoord;
2415 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length),
2416 length, font, debugstr_rectf(rect), format, brush);
2418 if(!graphics || !string || !font || !brush || !rect)
2419 return InvalidParameter;
2421 if((brush->bt != BrushTypeSolidColor)){
2422 FIXME("not implemented for given parameters\n");
2423 return NotImplemented;
2426 if(format){
2427 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
2429 /* Should be no need to explicitly test for StringAlignmentNear as
2430 * that is default behavior if no alignment is passed. */
2431 if(format->vertalign != StringAlignmentNear){
2432 RectF bounds;
2433 GdipMeasureString(graphics, string, length, font, rect, format, &bounds, 0, 0);
2435 if(format->vertalign == StringAlignmentCenter)
2436 offsety = (rect->Height - bounds.Height) / 2;
2437 else if(format->vertalign == StringAlignmentFar)
2438 offsety = (rect->Height - bounds.Height);
2442 if(length == -1) length = lstrlenW(string);
2444 stringdup = GdipAlloc(length * sizeof(WCHAR));
2445 if(!stringdup) return OutOfMemory;
2447 save_state = SaveDC(graphics->hdc);
2448 SetBkMode(graphics->hdc, TRANSPARENT);
2449 SetTextColor(graphics->hdc, brush->lb.lbColor);
2451 pt[0].X = 0.0;
2452 pt[0].Y = 0.0;
2453 pt[1].X = 1.0;
2454 pt[1].Y = 0.0;
2455 pt[2].X = 0.0;
2456 pt[2].Y = 1.0;
2457 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
2458 angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X));
2459 ang_cos = cos(angle);
2460 ang_sin = sin(angle);
2461 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
2462 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
2463 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
2464 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
2466 rectcpy[3].X = rectcpy[0].X = rect->X;
2467 rectcpy[1].Y = rectcpy[0].Y = rect->Y + offsety;
2468 rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width;
2469 rectcpy[3].Y = rectcpy[2].Y = rect->Y + offsety + rect->Height;
2470 transform_and_round_points(graphics, corners, rectcpy, 4);
2472 if (roundr(rect->Width) == 0)
2473 nwidth = INT_MAX;
2474 else
2475 nwidth = roundr(rel_width * rect->Width);
2477 if (roundr(rect->Height) == 0)
2478 nheight = INT_MAX;
2479 else
2480 nheight = roundr(rel_height * rect->Height);
2482 if (roundr(rect->Width) != 0 && roundr(rect->Height) != 0)
2484 /* FIXME: If only the width or only the height is 0, we should probably still clip */
2485 rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
2486 SelectClipRgn(graphics->hdc, rgn);
2489 /* Use gdi to find the font, then perform transformations on it (height,
2490 * width, angle). */
2491 SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
2492 GetTextMetricsW(graphics->hdc, &textmet);
2493 lfw = font->lfw;
2495 lfw.lfHeight = roundr(((REAL)lfw.lfHeight) * rel_height);
2496 lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width);
2498 lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0);
2500 gdifont = CreateFontIndirectW(&lfw);
2501 DeleteObject(SelectObject(graphics->hdc, CreateFontIndirectW(&lfw)));
2503 for(i = 0, j = 0; i < length; i++){
2504 if(!isprintW(string[i]) && (string[i] != '\n'))
2505 continue;
2507 stringdup[j] = string[i];
2508 j++;
2511 length = j;
2513 if (!format || format->align == StringAlignmentNear)
2515 drawbase.x = corners[0].x;
2516 drawbase.y = corners[0].y;
2517 drawflags = DT_NOCLIP | DT_EXPANDTABS;
2519 else if (format->align == StringAlignmentCenter)
2521 drawbase.x = (corners[0].x + corners[1].x)/2;
2522 drawbase.y = (corners[0].y + corners[1].y)/2;
2523 drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_CENTER;
2525 else /* (format->align == StringAlignmentFar) */
2527 drawbase.x = corners[1].x;
2528 drawbase.y = corners[1].y;
2529 drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_RIGHT;
2532 while(sum < length){
2533 drawcoord.left = drawcoord.right = drawbase.x + roundr(ang_sin * (REAL) height);
2534 drawcoord.top = drawcoord.bottom = drawbase.y + roundr(ang_cos * (REAL) height);
2536 GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum,
2537 nwidth, &fit, NULL, &size);
2538 fitcpy = fit;
2540 if(fit == 0){
2541 DrawTextW(graphics->hdc, stringdup + sum, 1, &drawcoord, drawflags);
2542 break;
2545 for(lret = 0; lret < fit; lret++)
2546 if(*(stringdup + sum + lret) == '\n')
2547 break;
2549 /* Line break code (may look strange, but it imitates windows). */
2550 if(lret < fit)
2551 lineend = fit = lret; /* this is not an off-by-one error */
2552 else if(fit < (length - sum)){
2553 if(*(stringdup + sum + fit) == ' ')
2554 while(*(stringdup + sum + fit) == ' ')
2555 fit++;
2556 else
2557 while(*(stringdup + sum + fit - 1) != ' '){
2558 fit--;
2560 if(*(stringdup + sum + fit) == '\t')
2561 break;
2563 if(fit == 0){
2564 fit = fitcpy;
2565 break;
2568 lineend = fit;
2569 while(*(stringdup + sum + lineend - 1) == ' ' ||
2570 *(stringdup + sum + lineend - 1) == '\t')
2571 lineend--;
2573 else
2574 lineend = fit;
2575 DrawTextW(graphics->hdc, stringdup + sum, min(length - sum, lineend),
2576 &drawcoord, drawflags);
2578 sum += fit + (lret < fitcpy ? 1 : 0);
2579 height += size.cy;
2581 if(height > nheight)
2582 break;
2584 /* Stop if this was a linewrap (but not if it was a linebreak). */
2585 if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
2586 break;
2589 GdipFree(stringdup);
2590 DeleteObject(rgn);
2591 DeleteObject(gdifont);
2593 RestoreDC(graphics->hdc, save_state);
2595 return Ok;
2598 GpStatus WINGDIPAPI GdipFillClosedCurve2(GpGraphics *graphics, GpBrush *brush,
2599 GDIPCONST GpPointF *points, INT count, REAL tension, GpFillMode fill)
2601 GpPath *path;
2602 GpStatus stat;
2604 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2605 count, tension, fill);
2607 if(!graphics || !brush || !points)
2608 return InvalidParameter;
2610 if(graphics->busy)
2611 return ObjectBusy;
2613 stat = GdipCreatePath(fill, &path);
2614 if(stat != Ok)
2615 return stat;
2617 stat = GdipAddPathClosedCurve2(path, points, count, tension);
2618 if(stat != Ok){
2619 GdipDeletePath(path);
2620 return stat;
2623 stat = GdipFillPath(graphics, brush, path);
2624 if(stat != Ok){
2625 GdipDeletePath(path);
2626 return stat;
2629 GdipDeletePath(path);
2631 return Ok;
2634 GpStatus WINGDIPAPI GdipFillClosedCurve2I(GpGraphics *graphics, GpBrush *brush,
2635 GDIPCONST GpPoint *points, INT count, REAL tension, GpFillMode fill)
2637 GpPointF *ptf;
2638 GpStatus stat;
2639 INT i;
2641 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2642 count, tension, fill);
2644 if(!points || count <= 0)
2645 return InvalidParameter;
2647 ptf = GdipAlloc(sizeof(GpPointF)*count);
2648 if(!ptf)
2649 return OutOfMemory;
2651 for(i = 0;i < count;i++){
2652 ptf[i].X = (REAL)points[i].X;
2653 ptf[i].Y = (REAL)points[i].Y;
2656 stat = GdipFillClosedCurve2(graphics, brush, ptf, count, tension, fill);
2658 GdipFree(ptf);
2660 return stat;
2663 GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x,
2664 REAL y, REAL width, REAL height)
2666 INT save_state;
2667 GpPointF ptf[2];
2668 POINT pti[2];
2670 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
2672 if(!graphics || !brush)
2673 return InvalidParameter;
2675 if(graphics->busy)
2676 return ObjectBusy;
2678 ptf[0].X = x;
2679 ptf[0].Y = y;
2680 ptf[1].X = x + width;
2681 ptf[1].Y = y + height;
2683 save_state = SaveDC(graphics->hdc);
2684 EndPath(graphics->hdc);
2686 transform_and_round_points(graphics, pti, ptf, 2);
2688 BeginPath(graphics->hdc);
2689 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
2690 EndPath(graphics->hdc);
2692 brush_fill_path(graphics, brush);
2694 RestoreDC(graphics->hdc, save_state);
2696 return Ok;
2699 GpStatus WINGDIPAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x,
2700 INT y, INT width, INT height)
2702 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
2704 return GdipFillEllipse(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2707 GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
2709 INT save_state;
2710 GpStatus retval;
2712 TRACE("(%p, %p, %p)\n", graphics, brush, path);
2714 if(!brush || !graphics || !path)
2715 return InvalidParameter;
2717 if(graphics->busy)
2718 return ObjectBusy;
2720 save_state = SaveDC(graphics->hdc);
2721 EndPath(graphics->hdc);
2722 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
2723 : WINDING));
2725 BeginPath(graphics->hdc);
2726 retval = draw_poly(graphics, NULL, path->pathdata.Points,
2727 path->pathdata.Types, path->pathdata.Count, FALSE);
2729 if(retval != Ok)
2730 goto end;
2732 EndPath(graphics->hdc);
2733 brush_fill_path(graphics, brush);
2735 retval = Ok;
2737 end:
2738 RestoreDC(graphics->hdc, save_state);
2740 return retval;
2743 GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
2744 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2746 INT save_state;
2748 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2749 graphics, brush, x, y, width, height, startAngle, sweepAngle);
2751 if(!graphics || !brush)
2752 return InvalidParameter;
2754 if(graphics->busy)
2755 return ObjectBusy;
2757 save_state = SaveDC(graphics->hdc);
2758 EndPath(graphics->hdc);
2760 BeginPath(graphics->hdc);
2761 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
2762 EndPath(graphics->hdc);
2764 brush_fill_path(graphics, brush);
2766 RestoreDC(graphics->hdc, save_state);
2768 return Ok;
2771 GpStatus WINGDIPAPI GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x,
2772 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2774 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2775 graphics, brush, x, y, width, height, startAngle, sweepAngle);
2777 return GdipFillPie(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2780 GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush,
2781 GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)
2783 INT save_state;
2784 GpPointF *ptf = NULL;
2785 POINT *pti = NULL;
2786 GpStatus retval = Ok;
2788 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
2790 if(!graphics || !brush || !points || !count)
2791 return InvalidParameter;
2793 if(graphics->busy)
2794 return ObjectBusy;
2796 ptf = GdipAlloc(count * sizeof(GpPointF));
2797 pti = GdipAlloc(count * sizeof(POINT));
2798 if(!ptf || !pti){
2799 retval = OutOfMemory;
2800 goto end;
2803 memcpy(ptf, points, count * sizeof(GpPointF));
2805 save_state = SaveDC(graphics->hdc);
2806 EndPath(graphics->hdc);
2807 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
2808 : WINDING));
2810 transform_and_round_points(graphics, pti, ptf, count);
2812 BeginPath(graphics->hdc);
2813 Polygon(graphics->hdc, pti, count);
2814 EndPath(graphics->hdc);
2816 brush_fill_path(graphics, brush);
2818 RestoreDC(graphics->hdc, save_state);
2820 end:
2821 GdipFree(ptf);
2822 GdipFree(pti);
2824 return retval;
2827 GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
2828 GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
2830 INT save_state, i;
2831 GpPointF *ptf = NULL;
2832 POINT *pti = NULL;
2833 GpStatus retval = Ok;
2835 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
2837 if(!graphics || !brush || !points || !count)
2838 return InvalidParameter;
2840 if(graphics->busy)
2841 return ObjectBusy;
2843 ptf = GdipAlloc(count * sizeof(GpPointF));
2844 pti = GdipAlloc(count * sizeof(POINT));
2845 if(!ptf || !pti){
2846 retval = OutOfMemory;
2847 goto end;
2850 for(i = 0; i < count; i ++){
2851 ptf[i].X = (REAL) points[i].X;
2852 ptf[i].Y = (REAL) points[i].Y;
2855 save_state = SaveDC(graphics->hdc);
2856 EndPath(graphics->hdc);
2857 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
2858 : WINDING));
2860 transform_and_round_points(graphics, pti, ptf, count);
2862 BeginPath(graphics->hdc);
2863 Polygon(graphics->hdc, pti, count);
2864 EndPath(graphics->hdc);
2866 brush_fill_path(graphics, brush);
2868 RestoreDC(graphics->hdc, save_state);
2870 end:
2871 GdipFree(ptf);
2872 GdipFree(pti);
2874 return retval;
2877 GpStatus WINGDIPAPI GdipFillPolygon2(GpGraphics *graphics, GpBrush *brush,
2878 GDIPCONST GpPointF *points, INT count)
2880 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
2882 return GdipFillPolygon(graphics, brush, points, count, FillModeAlternate);
2885 GpStatus WINGDIPAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush,
2886 GDIPCONST GpPoint *points, INT count)
2888 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
2890 return GdipFillPolygonI(graphics, brush, points, count, FillModeAlternate);
2893 GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics *graphics, GpBrush *brush,
2894 REAL x, REAL y, REAL width, REAL height)
2896 INT save_state;
2897 GpPointF ptf[4];
2898 POINT pti[4];
2900 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
2902 if(!graphics || !brush)
2903 return InvalidParameter;
2905 if(graphics->busy)
2906 return ObjectBusy;
2908 ptf[0].X = x;
2909 ptf[0].Y = y;
2910 ptf[1].X = x + width;
2911 ptf[1].Y = y;
2912 ptf[2].X = x + width;
2913 ptf[2].Y = y + height;
2914 ptf[3].X = x;
2915 ptf[3].Y = y + height;
2917 save_state = SaveDC(graphics->hdc);
2918 EndPath(graphics->hdc);
2920 transform_and_round_points(graphics, pti, ptf, 4);
2922 BeginPath(graphics->hdc);
2923 Polygon(graphics->hdc, pti, 4);
2924 EndPath(graphics->hdc);
2926 brush_fill_path(graphics, brush);
2928 RestoreDC(graphics->hdc, save_state);
2930 return Ok;
2933 GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush,
2934 INT x, INT y, INT width, INT height)
2936 INT save_state;
2937 GpPointF ptf[4];
2938 POINT pti[4];
2940 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
2942 if(!graphics || !brush)
2943 return InvalidParameter;
2945 if(graphics->busy)
2946 return ObjectBusy;
2948 ptf[0].X = x;
2949 ptf[0].Y = y;
2950 ptf[1].X = x + width;
2951 ptf[1].Y = y;
2952 ptf[2].X = x + width;
2953 ptf[2].Y = y + height;
2954 ptf[3].X = x;
2955 ptf[3].Y = y + height;
2957 save_state = SaveDC(graphics->hdc);
2958 EndPath(graphics->hdc);
2960 transform_and_round_points(graphics, pti, ptf, 4);
2962 BeginPath(graphics->hdc);
2963 Polygon(graphics->hdc, pti, 4);
2964 EndPath(graphics->hdc);
2966 brush_fill_path(graphics, brush);
2968 RestoreDC(graphics->hdc, save_state);
2970 return Ok;
2973 GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRectF *rects,
2974 INT count)
2976 GpStatus ret;
2977 INT i;
2979 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
2981 if(!rects)
2982 return InvalidParameter;
2984 for(i = 0; i < count; i++){
2985 ret = GdipFillRectangle(graphics, brush, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
2986 if(ret != Ok) return ret;
2989 return Ok;
2992 GpStatus WINGDIPAPI GdipFillRectanglesI(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRect *rects,
2993 INT count)
2995 GpRectF *rectsF;
2996 GpStatus ret;
2997 INT i;
2999 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3001 if(!rects || count <= 0)
3002 return InvalidParameter;
3004 rectsF = GdipAlloc(sizeof(GpRectF)*count);
3005 if(!rectsF)
3006 return OutOfMemory;
3008 for(i = 0; i < count; i++){
3009 rectsF[i].X = (REAL)rects[i].X;
3010 rectsF[i].Y = (REAL)rects[i].Y;
3011 rectsF[i].X = (REAL)rects[i].Width;
3012 rectsF[i].Height = (REAL)rects[i].Height;
3015 ret = GdipFillRectangles(graphics,brush,rectsF,count);
3016 GdipFree(rectsF);
3018 return ret;
3021 /*****************************************************************************
3022 * GdipFillRegion [GDIPLUS.@]
3024 GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
3025 GpRegion* region)
3027 INT save_state;
3028 GpStatus status;
3029 HRGN hrgn;
3030 RECT rc;
3032 TRACE("(%p, %p, %p)\n", graphics, brush, region);
3034 if (!(graphics && brush && region))
3035 return InvalidParameter;
3037 if(graphics->busy)
3038 return ObjectBusy;
3040 status = GdipGetRegionHRgn(region, graphics, &hrgn);
3041 if(status != Ok)
3042 return status;
3044 save_state = SaveDC(graphics->hdc);
3045 EndPath(graphics->hdc);
3047 ExtSelectClipRgn(graphics->hdc, hrgn, RGN_AND);
3049 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
3051 BeginPath(graphics->hdc);
3052 Rectangle(graphics->hdc, rc.left, rc.top, rc.right, rc.bottom);
3053 EndPath(graphics->hdc);
3055 brush_fill_path(graphics, brush);
3058 RestoreDC(graphics->hdc, save_state);
3060 DeleteObject(hrgn);
3062 return Ok;
3065 GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention)
3067 static int calls;
3069 TRACE("(%p,%u)\n", graphics, intention);
3071 if(!graphics)
3072 return InvalidParameter;
3074 if(graphics->busy)
3075 return ObjectBusy;
3077 if(!(calls++))
3078 FIXME("not implemented\n");
3080 return NotImplemented;
3083 /*****************************************************************************
3084 * GdipGetClipBounds [GDIPLUS.@]
3086 GpStatus WINGDIPAPI GdipGetClipBounds(GpGraphics *graphics, GpRectF *rect)
3088 TRACE("(%p, %p)\n", graphics, rect);
3090 if(!graphics)
3091 return InvalidParameter;
3093 if(graphics->busy)
3094 return ObjectBusy;
3096 return GdipGetRegionBounds(graphics->clip, graphics, rect);
3099 /*****************************************************************************
3100 * GdipGetClipBoundsI [GDIPLUS.@]
3102 GpStatus WINGDIPAPI GdipGetClipBoundsI(GpGraphics *graphics, GpRect *rect)
3104 TRACE("(%p, %p)\n", graphics, rect);
3106 if(!graphics)
3107 return InvalidParameter;
3109 if(graphics->busy)
3110 return ObjectBusy;
3112 return GdipGetRegionBoundsI(graphics->clip, graphics, rect);
3115 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3116 GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics,
3117 CompositingMode *mode)
3119 TRACE("(%p, %p)\n", graphics, mode);
3121 if(!graphics || !mode)
3122 return InvalidParameter;
3124 if(graphics->busy)
3125 return ObjectBusy;
3127 *mode = graphics->compmode;
3129 return Ok;
3132 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3133 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
3134 CompositingQuality *quality)
3136 TRACE("(%p, %p)\n", graphics, quality);
3138 if(!graphics || !quality)
3139 return InvalidParameter;
3141 if(graphics->busy)
3142 return ObjectBusy;
3144 *quality = graphics->compqual;
3146 return Ok;
3149 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3150 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
3151 InterpolationMode *mode)
3153 TRACE("(%p, %p)\n", graphics, mode);
3155 if(!graphics || !mode)
3156 return InvalidParameter;
3158 if(graphics->busy)
3159 return ObjectBusy;
3161 *mode = graphics->interpolation;
3163 return Ok;
3166 GpStatus WINGDIPAPI GdipGetNearestColor(GpGraphics *graphics, ARGB* argb)
3168 FIXME("(%p, %p): stub\n", graphics, argb);
3170 if(!graphics || !argb)
3171 return InvalidParameter;
3173 if(graphics->busy)
3174 return ObjectBusy;
3176 return NotImplemented;
3179 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
3181 TRACE("(%p, %p)\n", graphics, scale);
3183 if(!graphics || !scale)
3184 return InvalidParameter;
3186 if(graphics->busy)
3187 return ObjectBusy;
3189 *scale = graphics->scale;
3191 return Ok;
3194 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
3196 TRACE("(%p, %p)\n", graphics, unit);
3198 if(!graphics || !unit)
3199 return InvalidParameter;
3201 if(graphics->busy)
3202 return ObjectBusy;
3204 *unit = graphics->unit;
3206 return Ok;
3209 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3210 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
3211 *mode)
3213 TRACE("(%p, %p)\n", graphics, mode);
3215 if(!graphics || !mode)
3216 return InvalidParameter;
3218 if(graphics->busy)
3219 return ObjectBusy;
3221 *mode = graphics->pixeloffset;
3223 return Ok;
3226 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3227 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
3229 TRACE("(%p, %p)\n", graphics, mode);
3231 if(!graphics || !mode)
3232 return InvalidParameter;
3234 if(graphics->busy)
3235 return ObjectBusy;
3237 *mode = graphics->smoothing;
3239 return Ok;
3242 GpStatus WINGDIPAPI GdipGetTextContrast(GpGraphics *graphics, UINT *contrast)
3244 TRACE("(%p, %p)\n", graphics, contrast);
3246 if(!graphics || !contrast)
3247 return InvalidParameter;
3249 *contrast = graphics->textcontrast;
3251 return Ok;
3254 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3255 GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics,
3256 TextRenderingHint *hint)
3258 TRACE("(%p, %p)\n", graphics, hint);
3260 if(!graphics || !hint)
3261 return InvalidParameter;
3263 if(graphics->busy)
3264 return ObjectBusy;
3266 *hint = graphics->texthint;
3268 return Ok;
3271 GpStatus WINGDIPAPI GdipGetVisibleClipBounds(GpGraphics *graphics, GpRectF *rect)
3273 GpRegion *clip_rgn;
3274 GpStatus stat;
3276 TRACE("(%p, %p)\n", graphics, rect);
3278 if(!graphics || !rect)
3279 return InvalidParameter;
3281 if(graphics->busy)
3282 return ObjectBusy;
3284 /* intersect window and graphics clipping regions */
3285 if((stat = GdipCreateRegion(&clip_rgn)) != Ok)
3286 return stat;
3288 if((stat = get_visible_clip_region(graphics, clip_rgn)) != Ok)
3289 goto cleanup;
3291 /* get bounds of the region */
3292 stat = GdipGetRegionBounds(clip_rgn, graphics, rect);
3294 cleanup:
3295 GdipDeleteRegion(clip_rgn);
3297 return stat;
3300 GpStatus WINGDIPAPI GdipGetVisibleClipBoundsI(GpGraphics *graphics, GpRect *rect)
3302 GpRectF rectf;
3303 GpStatus stat;
3305 TRACE("(%p, %p)\n", graphics, rect);
3307 if(!graphics || !rect)
3308 return InvalidParameter;
3310 if((stat = GdipGetVisibleClipBounds(graphics, &rectf)) == Ok)
3312 rect->X = roundr(rectf.X);
3313 rect->Y = roundr(rectf.Y);
3314 rect->Width = roundr(rectf.Width);
3315 rect->Height = roundr(rectf.Height);
3318 return stat;
3321 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
3323 TRACE("(%p, %p)\n", graphics, matrix);
3325 if(!graphics || !matrix)
3326 return InvalidParameter;
3328 if(graphics->busy)
3329 return ObjectBusy;
3331 *matrix = *graphics->worldtrans;
3332 return Ok;
3335 GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color)
3337 GpSolidFill *brush;
3338 GpStatus stat;
3339 GpRectF wnd_rect;
3341 TRACE("(%p, %x)\n", graphics, color);
3343 if(!graphics)
3344 return InvalidParameter;
3346 if(graphics->busy)
3347 return ObjectBusy;
3349 if((stat = GdipCreateSolidFill(color, &brush)) != Ok)
3350 return stat;
3352 if((stat = get_graphics_bounds(graphics, &wnd_rect)) != Ok){
3353 GdipDeleteBrush((GpBrush*)brush);
3354 return stat;
3357 GdipFillRectangle(graphics, (GpBrush*)brush, wnd_rect.X, wnd_rect.Y,
3358 wnd_rect.Width, wnd_rect.Height);
3360 GdipDeleteBrush((GpBrush*)brush);
3362 return Ok;
3365 GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics *graphics, BOOL *res)
3367 TRACE("(%p, %p)\n", graphics, res);
3369 if(!graphics || !res)
3370 return InvalidParameter;
3372 return GdipIsEmptyRegion(graphics->clip, graphics, res);
3375 GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics *graphics, REAL x, REAL y, BOOL *result)
3377 GpStatus stat;
3378 GpRegion* rgn;
3379 GpPointF pt;
3381 TRACE("(%p, %.2f, %.2f, %p)\n", graphics, x, y, result);
3383 if(!graphics || !result)
3384 return InvalidParameter;
3386 if(graphics->busy)
3387 return ObjectBusy;
3389 pt.X = x;
3390 pt.Y = y;
3391 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3392 CoordinateSpaceWorld, &pt, 1)) != Ok)
3393 return stat;
3395 if((stat = GdipCreateRegion(&rgn)) != Ok)
3396 return stat;
3398 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3399 goto cleanup;
3401 stat = GdipIsVisibleRegionPoint(rgn, pt.X, pt.Y, graphics, result);
3403 cleanup:
3404 GdipDeleteRegion(rgn);
3405 return stat;
3408 GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics *graphics, INT x, INT y, BOOL *result)
3410 return GdipIsVisiblePoint(graphics, (REAL)x, (REAL)y, result);
3413 GpStatus WINGDIPAPI GdipIsVisibleRect(GpGraphics *graphics, REAL x, REAL y, REAL width, REAL height, BOOL *result)
3415 GpStatus stat;
3416 GpRegion* rgn;
3417 GpPointF pts[2];
3419 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics, x, y, width, height, result);
3421 if(!graphics || !result)
3422 return InvalidParameter;
3424 if(graphics->busy)
3425 return ObjectBusy;
3427 pts[0].X = x;
3428 pts[0].Y = y;
3429 pts[1].X = x + width;
3430 pts[1].Y = y + height;
3432 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3433 CoordinateSpaceWorld, pts, 2)) != Ok)
3434 return stat;
3436 pts[1].X -= pts[0].X;
3437 pts[1].Y -= pts[0].Y;
3439 if((stat = GdipCreateRegion(&rgn)) != Ok)
3440 return stat;
3442 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3443 goto cleanup;
3445 stat = GdipIsVisibleRegionRect(rgn, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y, graphics, result);
3447 cleanup:
3448 GdipDeleteRegion(rgn);
3449 return stat;
3452 GpStatus WINGDIPAPI GdipIsVisibleRectI(GpGraphics *graphics, INT x, INT y, INT width, INT height, BOOL *result)
3454 return GdipIsVisibleRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, result);
3457 GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,
3458 GDIPCONST WCHAR* string, INT length, GDIPCONST GpFont* font,
3459 GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat *stringFormat,
3460 INT regionCount, GpRegion** regions)
3462 FIXME("stub: %p %s %d %p %p %p %d %p\n", graphics, debugstr_w(string),
3463 length, font, layoutRect, stringFormat, regionCount, regions);
3465 if (!(graphics && string && font && layoutRect && stringFormat && regions))
3466 return InvalidParameter;
3468 return NotImplemented;
3471 /* Find the smallest rectangle that bounds the text when it is printed in rect
3472 * according to the format options listed in format. If rect has 0 width and
3473 * height, then just find the smallest rectangle that bounds the text when it's
3474 * printed at location (rect->X, rect-Y). */
3475 GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
3476 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
3477 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
3478 INT *codepointsfitted, INT *linesfilled)
3480 HFONT oldfont;
3481 WCHAR* stringdup;
3482 INT sum = 0, height = 0, fit, fitcpy, max_width = 0, i, j, lret, nwidth,
3483 nheight, lineend;
3484 SIZE size;
3486 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics,
3487 debugstr_wn(string, length), length, font, debugstr_rectf(rect), format,
3488 bounds, codepointsfitted, linesfilled);
3490 if(!graphics || !string || !font || !rect)
3491 return InvalidParameter;
3493 if(linesfilled) *linesfilled = 0;
3494 if(codepointsfitted) *codepointsfitted = 0;
3496 if(format)
3497 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
3499 if(length == -1) length = lstrlenW(string);
3501 stringdup = GdipAlloc((length + 1) * sizeof(WCHAR));
3502 if(!stringdup) return OutOfMemory;
3504 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
3505 nwidth = roundr(rect->Width);
3506 nheight = roundr(rect->Height);
3508 if((nwidth == 0) && (nheight == 0))
3509 nwidth = nheight = INT_MAX;
3511 for(i = 0, j = 0; i < length; i++){
3512 if(!isprintW(string[i]) && (string[i] != '\n'))
3513 continue;
3515 stringdup[j] = string[i];
3516 j++;
3519 stringdup[j] = 0;
3520 length = j;
3522 while(sum < length){
3523 GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum,
3524 nwidth, &fit, NULL, &size);
3525 fitcpy = fit;
3527 if(fit == 0)
3528 break;
3530 for(lret = 0; lret < fit; lret++)
3531 if(*(stringdup + sum + lret) == '\n')
3532 break;
3534 /* Line break code (may look strange, but it imitates windows). */
3535 if(lret < fit)
3536 lineend = fit = lret; /* this is not an off-by-one error */
3537 else if(fit < (length - sum)){
3538 if(*(stringdup + sum + fit) == ' ')
3539 while(*(stringdup + sum + fit) == ' ')
3540 fit++;
3541 else
3542 while(*(stringdup + sum + fit - 1) != ' '){
3543 fit--;
3545 if(*(stringdup + sum + fit) == '\t')
3546 break;
3548 if(fit == 0){
3549 fit = fitcpy;
3550 break;
3553 lineend = fit;
3554 while(*(stringdup + sum + lineend - 1) == ' ' ||
3555 *(stringdup + sum + lineend - 1) == '\t')
3556 lineend--;
3558 else
3559 lineend = fit;
3561 GetTextExtentExPointW(graphics->hdc, stringdup + sum, lineend,
3562 nwidth, &j, NULL, &size);
3564 sum += fit + (lret < fitcpy ? 1 : 0);
3565 if(codepointsfitted) *codepointsfitted = sum;
3567 height += size.cy;
3568 if(linesfilled) *linesfilled += size.cy;
3569 max_width = max(max_width, size.cx);
3571 if(height > nheight)
3572 break;
3574 /* Stop if this was a linewrap (but not if it was a linebreak). */
3575 if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
3576 break;
3579 bounds->X = rect->X;
3580 bounds->Y = rect->Y;
3581 bounds->Width = (REAL)max_width;
3582 bounds->Height = (REAL) min(height, nheight);
3584 GdipFree(stringdup);
3585 DeleteObject(SelectObject(graphics->hdc, oldfont));
3587 return Ok;
3590 GpStatus WINGDIPAPI GdipResetClip(GpGraphics *graphics)
3592 TRACE("(%p)\n", graphics);
3594 if(!graphics)
3595 return InvalidParameter;
3597 if(graphics->busy)
3598 return ObjectBusy;
3600 return GdipSetInfinite(graphics->clip);
3603 GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics)
3605 TRACE("(%p)\n", graphics);
3607 if(!graphics)
3608 return InvalidParameter;
3610 if(graphics->busy)
3611 return ObjectBusy;
3613 graphics->worldtrans->matrix[0] = 1.0;
3614 graphics->worldtrans->matrix[1] = 0.0;
3615 graphics->worldtrans->matrix[2] = 0.0;
3616 graphics->worldtrans->matrix[3] = 1.0;
3617 graphics->worldtrans->matrix[4] = 0.0;
3618 graphics->worldtrans->matrix[5] = 0.0;
3620 return Ok;
3623 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
3625 return GdipEndContainer(graphics, state);
3628 GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
3629 GpMatrixOrder order)
3631 TRACE("(%p, %.2f, %d)\n", graphics, angle, order);
3633 if(!graphics)
3634 return InvalidParameter;
3636 if(graphics->busy)
3637 return ObjectBusy;
3639 return GdipRotateMatrix(graphics->worldtrans, angle, order);
3642 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
3644 return GdipBeginContainer2(graphics, state);
3647 GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics *graphics,
3648 GraphicsContainer *state)
3650 GraphicsContainerItem *container;
3651 GpStatus sts;
3653 TRACE("(%p, %p)\n", graphics, state);
3655 if(!graphics || !state)
3656 return InvalidParameter;
3658 sts = init_container(&container, graphics);
3659 if(sts != Ok)
3660 return sts;
3662 list_add_head(&graphics->containers, &container->entry);
3663 *state = graphics->contid = container->contid;
3665 return Ok;
3668 GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics *graphics, GDIPCONST GpRectF *dstrect, GDIPCONST GpRectF *srcrect, GpUnit unit, GraphicsContainer *state)
3670 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
3671 return NotImplemented;
3674 GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics *graphics, GDIPCONST GpRect *dstrect, GDIPCONST GpRect *srcrect, GpUnit unit, GraphicsContainer *state)
3676 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
3677 return NotImplemented;
3680 GpStatus WINGDIPAPI GdipComment(GpGraphics *graphics, UINT sizeData, GDIPCONST BYTE *data)
3682 FIXME("(%p, %d, %p): stub\n", graphics, sizeData, data);
3683 return NotImplemented;
3686 GpStatus WINGDIPAPI GdipEndContainer(GpGraphics *graphics, GraphicsContainer state)
3688 GpStatus sts;
3689 GraphicsContainerItem *container, *container2;
3691 TRACE("(%p, %x)\n", graphics, state);
3693 if(!graphics)
3694 return InvalidParameter;
3696 LIST_FOR_EACH_ENTRY(container, &graphics->containers, GraphicsContainerItem, entry){
3697 if(container->contid == state)
3698 break;
3701 /* did not find a matching container */
3702 if(&container->entry == &graphics->containers)
3703 return Ok;
3705 sts = restore_container(graphics, container);
3706 if(sts != Ok)
3707 return sts;
3709 /* remove all of the containers on top of the found container */
3710 LIST_FOR_EACH_ENTRY_SAFE(container, container2, &graphics->containers, GraphicsContainerItem, entry){
3711 if(container->contid == state)
3712 break;
3713 list_remove(&container->entry);
3714 delete_container(container);
3717 list_remove(&container->entry);
3718 delete_container(container);
3720 return Ok;
3723 GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
3724 REAL sy, GpMatrixOrder order)
3726 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, sx, sy, order);
3728 if(!graphics)
3729 return InvalidParameter;
3731 if(graphics->busy)
3732 return ObjectBusy;
3734 return GdipScaleMatrix(graphics->worldtrans, sx, sy, order);
3737 GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics *graphics, GpGraphics *srcgraphics,
3738 CombineMode mode)
3740 TRACE("(%p, %p, %d)\n", graphics, srcgraphics, mode);
3742 if(!graphics || !srcgraphics)
3743 return InvalidParameter;
3745 return GdipCombineRegionRegion(graphics->clip, srcgraphics->clip, mode);
3748 GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
3749 CompositingMode mode)
3751 TRACE("(%p, %d)\n", graphics, mode);
3753 if(!graphics)
3754 return InvalidParameter;
3756 if(graphics->busy)
3757 return ObjectBusy;
3759 graphics->compmode = mode;
3761 return Ok;
3764 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
3765 CompositingQuality quality)
3767 TRACE("(%p, %d)\n", graphics, quality);
3769 if(!graphics)
3770 return InvalidParameter;
3772 if(graphics->busy)
3773 return ObjectBusy;
3775 graphics->compqual = quality;
3777 return Ok;
3780 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
3781 InterpolationMode mode)
3783 TRACE("(%p, %d)\n", graphics, mode);
3785 if(!graphics)
3786 return InvalidParameter;
3788 if(graphics->busy)
3789 return ObjectBusy;
3791 graphics->interpolation = mode;
3793 return Ok;
3796 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
3798 TRACE("(%p, %.2f)\n", graphics, scale);
3800 if(!graphics || (scale <= 0.0))
3801 return InvalidParameter;
3803 if(graphics->busy)
3804 return ObjectBusy;
3806 graphics->scale = scale;
3808 return Ok;
3811 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
3813 TRACE("(%p, %d)\n", graphics, unit);
3815 if(!graphics)
3816 return InvalidParameter;
3818 if(graphics->busy)
3819 return ObjectBusy;
3821 if(unit == UnitWorld)
3822 return InvalidParameter;
3824 graphics->unit = unit;
3826 return Ok;
3829 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
3830 mode)
3832 TRACE("(%p, %d)\n", graphics, mode);
3834 if(!graphics)
3835 return InvalidParameter;
3837 if(graphics->busy)
3838 return ObjectBusy;
3840 graphics->pixeloffset = mode;
3842 return Ok;
3845 GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics *graphics, INT x, INT y)
3847 static int calls;
3849 TRACE("(%p,%i,%i)\n", graphics, x, y);
3851 if (!(calls++))
3852 FIXME("not implemented\n");
3854 return NotImplemented;
3857 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
3859 TRACE("(%p, %d)\n", graphics, mode);
3861 if(!graphics)
3862 return InvalidParameter;
3864 if(graphics->busy)
3865 return ObjectBusy;
3867 graphics->smoothing = mode;
3869 return Ok;
3872 GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics *graphics, UINT contrast)
3874 TRACE("(%p, %d)\n", graphics, contrast);
3876 if(!graphics)
3877 return InvalidParameter;
3879 graphics->textcontrast = contrast;
3881 return Ok;
3884 GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
3885 TextRenderingHint hint)
3887 TRACE("(%p, %d)\n", graphics, hint);
3889 if(!graphics)
3890 return InvalidParameter;
3892 if(graphics->busy)
3893 return ObjectBusy;
3895 graphics->texthint = hint;
3897 return Ok;
3900 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
3902 TRACE("(%p, %p)\n", graphics, matrix);
3904 if(!graphics || !matrix)
3905 return InvalidParameter;
3907 if(graphics->busy)
3908 return ObjectBusy;
3910 GdipDeleteMatrix(graphics->worldtrans);
3911 return GdipCloneMatrix(matrix, &graphics->worldtrans);
3914 GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
3915 REAL dy, GpMatrixOrder order)
3917 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, dx, dy, order);
3919 if(!graphics)
3920 return InvalidParameter;
3922 if(graphics->busy)
3923 return ObjectBusy;
3925 return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order);
3928 /*****************************************************************************
3929 * GdipSetClipHrgn [GDIPLUS.@]
3931 GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics *graphics, HRGN hrgn, CombineMode mode)
3933 GpRegion *region;
3934 GpStatus status;
3936 TRACE("(%p, %p, %d)\n", graphics, hrgn, mode);
3938 if(!graphics)
3939 return InvalidParameter;
3941 status = GdipCreateRegionHrgn(hrgn, &region);
3942 if(status != Ok)
3943 return status;
3945 status = GdipSetClipRegion(graphics, region, mode);
3947 GdipDeleteRegion(region);
3948 return status;
3951 GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics *graphics, GpPath *path, CombineMode mode)
3953 TRACE("(%p, %p, %d)\n", graphics, path, mode);
3955 if(!graphics)
3956 return InvalidParameter;
3958 if(graphics->busy)
3959 return ObjectBusy;
3961 return GdipCombineRegionPath(graphics->clip, path, mode);
3964 GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y,
3965 REAL width, REAL height,
3966 CombineMode mode)
3968 GpRectF rect;
3970 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics, x, y, width, height, mode);
3972 if(!graphics)
3973 return InvalidParameter;
3975 if(graphics->busy)
3976 return ObjectBusy;
3978 rect.X = x;
3979 rect.Y = y;
3980 rect.Width = width;
3981 rect.Height = height;
3983 return GdipCombineRegionRect(graphics->clip, &rect, mode);
3986 GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y,
3987 INT width, INT height,
3988 CombineMode mode)
3990 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics, x, y, width, height, mode);
3992 if(!graphics)
3993 return InvalidParameter;
3995 if(graphics->busy)
3996 return ObjectBusy;
3998 return GdipSetClipRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, mode);
4001 GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
4002 CombineMode mode)
4004 TRACE("(%p, %p, %d)\n", graphics, region, mode);
4006 if(!graphics || !region)
4007 return InvalidParameter;
4009 if(graphics->busy)
4010 return ObjectBusy;
4012 return GdipCombineRegionRegion(graphics->clip, region, mode);
4015 GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile *metafile,
4016 UINT limitDpi)
4018 static int calls;
4020 TRACE("(%p,%u)\n", metafile, limitDpi);
4022 if(!(calls++))
4023 FIXME("not implemented\n");
4025 return NotImplemented;
4028 GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points,
4029 INT count)
4031 INT save_state;
4032 POINT *pti;
4034 TRACE("(%p, %p, %d)\n", graphics, points, count);
4036 if(!graphics || !pen || count<=0)
4037 return InvalidParameter;
4039 if(graphics->busy)
4040 return ObjectBusy;
4042 pti = GdipAlloc(sizeof(POINT) * count);
4044 save_state = prepare_dc(graphics, pen);
4045 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
4047 transform_and_round_points(graphics, pti, (GpPointF*)points, count);
4048 Polygon(graphics->hdc, pti, count);
4050 restore_dc(graphics, save_state);
4051 GdipFree(pti);
4053 return Ok;
4056 GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points,
4057 INT count)
4059 GpStatus ret;
4060 GpPointF *ptf;
4061 INT i;
4063 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
4065 if(count<=0) return InvalidParameter;
4066 ptf = GdipAlloc(sizeof(GpPointF) * count);
4068 for(i = 0;i < count; i++){
4069 ptf[i].X = (REAL)points[i].X;
4070 ptf[i].Y = (REAL)points[i].Y;
4073 ret = GdipDrawPolygon(graphics,pen,ptf,count);
4074 GdipFree(ptf);
4076 return ret;
4079 GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
4081 TRACE("(%p, %p)\n", graphics, dpi);
4083 if(!graphics || !dpi)
4084 return InvalidParameter;
4086 if(graphics->busy)
4087 return ObjectBusy;
4089 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
4091 return Ok;
4094 GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
4096 TRACE("(%p, %p)\n", graphics, dpi);
4098 if(!graphics || !dpi)
4099 return InvalidParameter;
4101 if(graphics->busy)
4102 return ObjectBusy;
4104 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
4106 return Ok;
4109 GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix,
4110 GpMatrixOrder order)
4112 GpMatrix m;
4113 GpStatus ret;
4115 TRACE("(%p, %p, %d)\n", graphics, matrix, order);
4117 if(!graphics || !matrix)
4118 return InvalidParameter;
4120 if(graphics->busy)
4121 return ObjectBusy;
4123 m = *(graphics->worldtrans);
4125 ret = GdipMultiplyMatrix(&m, matrix, order);
4126 if(ret == Ok)
4127 *(graphics->worldtrans) = m;
4129 return ret;
4132 GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
4134 TRACE("(%p, %p)\n", graphics, hdc);
4136 if(!graphics || !hdc)
4137 return InvalidParameter;
4139 if(graphics->busy)
4140 return ObjectBusy;
4142 *hdc = graphics->hdc;
4143 graphics->busy = TRUE;
4145 return Ok;
4148 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
4150 TRACE("(%p, %p)\n", graphics, hdc);
4152 if(!graphics)
4153 return InvalidParameter;
4155 if(graphics->hdc != hdc || !(graphics->busy))
4156 return InvalidParameter;
4158 graphics->busy = FALSE;
4160 return Ok;
4163 GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
4165 GpRegion *clip;
4166 GpStatus status;
4168 TRACE("(%p, %p)\n", graphics, region);
4170 if(!graphics || !region)
4171 return InvalidParameter;
4173 if(graphics->busy)
4174 return ObjectBusy;
4176 if((status = GdipCloneRegion(graphics->clip, &clip)) != Ok)
4177 return status;
4179 /* free everything except root node and header */
4180 delete_element(&region->node);
4181 memcpy(region, clip, sizeof(GpRegion));
4182 GdipFree(clip);
4184 return Ok;
4187 GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space,
4188 GpCoordinateSpace src_space, GpPointF *points, INT count)
4190 GpMatrix *matrix;
4191 GpStatus stat;
4192 REAL unitscale;
4194 if(!graphics || !points || count <= 0)
4195 return InvalidParameter;
4197 if(graphics->busy)
4198 return ObjectBusy;
4200 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
4202 if (src_space == dst_space) return Ok;
4204 stat = GdipCreateMatrix(&matrix);
4205 if (stat == Ok)
4207 unitscale = convert_unit(graphics->hdc, graphics->unit);
4209 if(graphics->unit != UnitDisplay)
4210 unitscale *= graphics->scale;
4212 /* transform from src_space to CoordinateSpacePage */
4213 switch (src_space)
4215 case CoordinateSpaceWorld:
4216 GdipMultiplyMatrix(matrix, graphics->worldtrans, MatrixOrderAppend);
4217 break;
4218 case CoordinateSpacePage:
4219 break;
4220 case CoordinateSpaceDevice:
4221 GdipScaleMatrix(matrix, 1.0/unitscale, 1.0/unitscale, MatrixOrderAppend);
4222 break;
4225 /* transform from CoordinateSpacePage to dst_space */
4226 switch (dst_space)
4228 case CoordinateSpaceWorld:
4230 GpMatrix *inverted_transform;
4231 stat = GdipCloneMatrix(graphics->worldtrans, &inverted_transform);
4232 if (stat == Ok)
4234 stat = GdipInvertMatrix(inverted_transform);
4235 if (stat == Ok)
4236 GdipMultiplyMatrix(matrix, inverted_transform, MatrixOrderAppend);
4237 GdipDeleteMatrix(inverted_transform);
4239 break;
4241 case CoordinateSpacePage:
4242 break;
4243 case CoordinateSpaceDevice:
4244 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
4245 break;
4248 if (stat == Ok)
4249 stat = GdipTransformMatrixPoints(matrix, points, count);
4251 GdipDeleteMatrix(matrix);
4254 return stat;
4257 GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space,
4258 GpCoordinateSpace src_space, GpPoint *points, INT count)
4260 GpPointF *pointsF;
4261 GpStatus ret;
4262 INT i;
4264 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
4266 if(count <= 0)
4267 return InvalidParameter;
4269 pointsF = GdipAlloc(sizeof(GpPointF) * count);
4270 if(!pointsF)
4271 return OutOfMemory;
4273 for(i = 0; i < count; i++){
4274 pointsF[i].X = (REAL)points[i].X;
4275 pointsF[i].Y = (REAL)points[i].Y;
4278 ret = GdipTransformPoints(graphics, dst_space, src_space, pointsF, count);
4280 if(ret == Ok)
4281 for(i = 0; i < count; i++){
4282 points[i].X = roundr(pointsF[i].X);
4283 points[i].Y = roundr(pointsF[i].Y);
4285 GdipFree(pointsF);
4287 return ret;
4290 HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void)
4292 FIXME("\n");
4294 return NULL;
4297 /*****************************************************************************
4298 * GdipTranslateClip [GDIPLUS.@]
4300 GpStatus WINGDIPAPI GdipTranslateClip(GpGraphics *graphics, REAL dx, REAL dy)
4302 TRACE("(%p, %.2f, %.2f)\n", graphics, dx, dy);
4304 if(!graphics)
4305 return InvalidParameter;
4307 if(graphics->busy)
4308 return ObjectBusy;
4310 return GdipTranslateRegion(graphics->clip, dx, dy);
4313 /*****************************************************************************
4314 * GdipTranslateClipI [GDIPLUS.@]
4316 GpStatus WINGDIPAPI GdipTranslateClipI(GpGraphics *graphics, INT dx, INT dy)
4318 TRACE("(%p, %d, %d)\n", graphics, dx, dy);
4320 if(!graphics)
4321 return InvalidParameter;
4323 if(graphics->busy)
4324 return ObjectBusy;
4326 return GdipTranslateRegion(graphics->clip, (REAL)dx, (REAL)dy);
4330 /*****************************************************************************
4331 * GdipMeasureDriverString [GDIPLUS.@]
4333 GpStatus WINGDIPAPI GdipMeasureDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
4334 GDIPCONST GpFont *font, GDIPCONST PointF *positions,
4335 INT flags, GDIPCONST GpMatrix *matrix, RectF *boundingBox)
4337 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics, text, length, font, positions, flags, matrix, boundingBox);
4338 return NotImplemented;
4341 /*****************************************************************************
4342 * GdipDrawDriverString [GDIPLUS.@]
4344 GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
4345 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
4346 GDIPCONST PointF *positions, INT flags,
4347 GDIPCONST GpMatrix *matrix )
4349 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics, text, length, font, brush, positions, flags, matrix);
4350 return NotImplemented;
4353 /*****************************************************************************
4354 * GdipRecordMetafileI [GDIPLUS.@]
4356 GpStatus WINGDIPAPI GdipRecordMetafileI(HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
4357 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
4359 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
4360 return NotImplemented;
4363 /*****************************************************************************
4364 * GdipIsVisibleClipEmpty [GDIPLUS.@]
4366 GpStatus WINGDIPAPI GdipIsVisibleClipEmpty(GpGraphics *graphics, BOOL *res)
4368 GpStatus stat;
4369 GpRegion* rgn;
4371 TRACE("(%p, %p)\n", graphics, res);
4373 if((stat = GdipCreateRegion(&rgn)) != Ok)
4374 return stat;
4376 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
4377 goto cleanup;
4379 stat = GdipIsEmptyRegion(rgn, graphics, res);
4381 cleanup:
4382 GdipDeleteRegion(rgn);
4383 return stat;