push 7bb4e6a724086e39bb3a77eb03fa4dcdb495b071
[wine/hacks.git] / dlls / gdiplus / graphics.c
blob5e5883f88ebf31d1999ecc117a16e23afcfd9ca7
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"
42 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
44 /* looks-right constants */
45 #define ANCHOR_WIDTH (2.0)
46 #define MAX_ITERS (50)
48 /* Converts angle (in degrees) to x/y coordinates */
49 static void deg2xy(REAL angle, REAL x_0, REAL y_0, REAL *x, REAL *y)
51 REAL radAngle, hypotenuse;
53 radAngle = deg2rad(angle);
54 hypotenuse = 50.0; /* arbitrary */
56 *x = x_0 + cos(radAngle) * hypotenuse;
57 *y = y_0 + sin(radAngle) * hypotenuse;
60 /* Converts from gdiplus path point type to gdi path point type. */
61 static BYTE convert_path_point_type(BYTE type)
63 BYTE ret;
65 switch(type & PathPointTypePathTypeMask){
66 case PathPointTypeBezier:
67 ret = PT_BEZIERTO;
68 break;
69 case PathPointTypeLine:
70 ret = PT_LINETO;
71 break;
72 case PathPointTypeStart:
73 ret = PT_MOVETO;
74 break;
75 default:
76 ERR("Bad point type\n");
77 return 0;
80 if(type & PathPointTypeCloseSubpath)
81 ret |= PT_CLOSEFIGURE;
83 return ret;
86 static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
88 HPEN gdipen;
89 REAL width;
90 INT save_state = SaveDC(graphics->hdc), i, numdashes;
91 GpPointF pt[2];
92 DWORD dash_array[MAX_DASHLEN];
94 EndPath(graphics->hdc);
96 if(pen->unit == UnitPixel){
97 width = pen->width;
99 else{
100 /* Get an estimate for the amount the pen width is affected by the world
101 * transform. (This is similar to what some of the wine drivers do.) */
102 pt[0].X = 0.0;
103 pt[0].Y = 0.0;
104 pt[1].X = 1.0;
105 pt[1].Y = 1.0;
106 GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
107 width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
108 (pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
110 width *= pen->width * convert_unit(graphics->hdc,
111 pen->unit == UnitWorld ? graphics->unit : pen->unit);
114 if(pen->dash == DashStyleCustom){
115 numdashes = min(pen->numdashes, MAX_DASHLEN);
117 TRACE("dashes are: ");
118 for(i = 0; i < numdashes; i++){
119 dash_array[i] = roundr(width * pen->dashes[i]);
120 TRACE("%d, ", dash_array[i]);
122 TRACE("\n and the pen style is %x\n", pen->style);
124 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb,
125 numdashes, dash_array);
127 else
128 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, 0, NULL);
130 SelectObject(graphics->hdc, gdipen);
132 return save_state;
135 static void restore_dc(GpGraphics *graphics, INT state)
137 DeleteObject(SelectObject(graphics->hdc, GetStockObject(NULL_PEN)));
138 RestoreDC(graphics->hdc, state);
141 /* This helper applies all the changes that the points listed in ptf need in
142 * order to be drawn on the device context. In the end, this should include at
143 * least:
144 * -scaling by page unit
145 * -applying world transformation
146 * -converting from float to int
147 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
148 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
149 * gdi to draw, and these functions would irreparably mess with line widths.
151 static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
152 GpPointF *ptf, INT count)
154 REAL unitscale;
155 GpMatrix *matrix;
156 int i;
158 unitscale = convert_unit(graphics->hdc, graphics->unit);
160 /* apply page scale */
161 if(graphics->unit != UnitDisplay)
162 unitscale *= graphics->scale;
164 GdipCloneMatrix(graphics->worldtrans, &matrix);
165 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
166 GdipTransformMatrixPoints(matrix, ptf, count);
167 GdipDeleteMatrix(matrix);
169 for(i = 0; i < count; i++){
170 pti[i].x = roundr(ptf[i].X);
171 pti[i].y = roundr(ptf[i].Y);
175 static ARGB blend_colors(ARGB start, ARGB end, REAL position)
177 ARGB result=0;
178 ARGB i;
179 for (i=0xff; i<=0xff0000; i = i << 8)
180 result |= (int)((start&i)*(1.0f - position)+(end&i)*(position))&i;
181 return result;
184 static ARGB blend_line_gradient(GpLineGradient* brush, REAL position)
186 REAL blendfac;
188 /* clamp to between 0.0 and 1.0, using the wrap mode */
189 if (brush->wrap == WrapModeTile)
191 position = fmodf(position, 1.0f);
192 if (position < 0.0f) position += 1.0f;
194 else /* WrapModeFlip* */
196 position = fmodf(position, 2.0f);
197 if (position < 0.0f) position += 2.0f;
198 if (position > 1.0f) position = 2.0f - position;
201 if (brush->blendcount == 1)
202 blendfac = position;
203 else
205 int i=1;
206 REAL left_blendpos, left_blendfac, right_blendpos, right_blendfac;
207 REAL range;
209 /* locate the blend positions surrounding this position */
210 while (position > brush->blendpos[i])
211 i++;
213 /* interpolate between the blend positions */
214 left_blendpos = brush->blendpos[i-1];
215 left_blendfac = brush->blendfac[i-1];
216 right_blendpos = brush->blendpos[i];
217 right_blendfac = brush->blendfac[i];
218 range = right_blendpos - left_blendpos;
219 blendfac = (left_blendfac * (right_blendpos - position) +
220 right_blendfac * (position - left_blendpos)) / range;
222 return blend_colors(brush->startcolor, brush->endcolor, blendfac);
225 static void brush_fill_path(GpGraphics *graphics, GpBrush* brush)
227 switch (brush->bt)
229 case BrushTypeLinearGradient:
231 GpLineGradient *line = (GpLineGradient*)brush;
232 RECT rc;
234 SelectClipPath(graphics->hdc, RGN_AND);
235 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
237 GpPointF endpointsf[2];
238 POINT endpointsi[2];
239 POINT poly[4];
241 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
243 endpointsf[0] = line->startpoint;
244 endpointsf[1] = line->endpoint;
245 transform_and_round_points(graphics, endpointsi, endpointsf, 2);
247 if (abs(endpointsi[0].x-endpointsi[1].x) > abs(endpointsi[0].y-endpointsi[1].y))
249 /* vertical-ish gradient */
250 int startx, endx; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
251 int startbottomx; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
252 int width;
253 COLORREF col;
254 HBRUSH hbrush, hprevbrush;
255 int leftx, rightx; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
256 int x;
257 int tilt; /* horizontal distance covered by a gradient line */
259 startx = roundr((rc.top - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X);
260 endx = roundr((rc.top - endpointsf[1].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[1].X);
261 width = endx - startx;
262 startbottomx = roundr((rc.bottom - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X);
263 tilt = startx - startbottomx;
265 if (startx >= startbottomx)
267 leftx = rc.left;
268 rightx = rc.right + tilt;
270 else
272 leftx = rc.left + tilt;
273 rightx = rc.right;
276 poly[0].y = rc.bottom;
277 poly[1].y = rc.top;
278 poly[2].y = rc.top;
279 poly[3].y = rc.bottom;
281 for (x=leftx; x<=rightx; x++)
283 ARGB argb = blend_line_gradient(line, (x-startx)/(REAL)width);
284 col = ARGB2COLORREF(argb);
285 hbrush = CreateSolidBrush(col);
286 hprevbrush = SelectObject(graphics->hdc, hbrush);
287 poly[0].x = x - tilt - 1;
288 poly[1].x = x - 1;
289 poly[2].x = x;
290 poly[3].x = x - tilt;
291 Polygon(graphics->hdc, poly, 4);
292 SelectObject(graphics->hdc, hprevbrush);
293 DeleteObject(hbrush);
296 else if (endpointsi[0].y != endpointsi[1].y)
298 /* horizontal-ish gradient */
299 int starty, endy; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
300 int startrighty; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
301 int height;
302 COLORREF col;
303 HBRUSH hbrush, hprevbrush;
304 int topy, bottomy; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
305 int y;
306 int tilt; /* vertical distance covered by a gradient line */
308 starty = roundr((rc.left - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y);
309 endy = roundr((rc.left - endpointsf[1].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[1].Y);
310 height = endy - starty;
311 startrighty = roundr((rc.right - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y);
312 tilt = starty - startrighty;
314 if (starty >= startrighty)
316 topy = rc.top;
317 bottomy = rc.bottom + tilt;
319 else
321 topy = rc.top + tilt;
322 bottomy = rc.bottom;
325 poly[0].x = rc.right;
326 poly[1].x = rc.left;
327 poly[2].x = rc.left;
328 poly[3].x = rc.right;
330 for (y=topy; y<=bottomy; y++)
332 ARGB argb = blend_line_gradient(line, (y-starty)/(REAL)height);
333 col = ARGB2COLORREF(argb);
334 hbrush = CreateSolidBrush(col);
335 hprevbrush = SelectObject(graphics->hdc, hbrush);
336 poly[0].y = y - tilt - 1;
337 poly[1].y = y - 1;
338 poly[2].y = y;
339 poly[3].y = y - tilt;
340 Polygon(graphics->hdc, poly, 4);
341 SelectObject(graphics->hdc, hprevbrush);
342 DeleteObject(hbrush);
345 /* else startpoint == endpoint */
347 break;
349 default:
350 SelectObject(graphics->hdc, brush->gdibrush);
351 FillPath(graphics->hdc);
352 break;
356 /* GdipDrawPie/GdipFillPie helper function */
357 static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width,
358 REAL height, REAL startAngle, REAL sweepAngle)
360 GpPointF ptf[4];
361 POINT pti[4];
363 ptf[0].X = x;
364 ptf[0].Y = y;
365 ptf[1].X = x + width;
366 ptf[1].Y = y + height;
368 deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y);
369 deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y);
371 transform_and_round_points(graphics, pti, ptf, 4);
373 Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x,
374 pti[2].y, pti[3].x, pti[3].y);
377 /* Draws the linecap the specified color and size on the hdc. The linecap is in
378 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
379 * should not be called on an hdc that has a path you care about. */
380 static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
381 const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
383 HGDIOBJ oldbrush = NULL, oldpen = NULL;
384 GpMatrix *matrix = NULL;
385 HBRUSH brush = NULL;
386 HPEN pen = NULL;
387 PointF ptf[4], *custptf = NULL;
388 POINT pt[4], *custpt = NULL;
389 BYTE *tp = NULL;
390 REAL theta, dsmall, dbig, dx, dy = 0.0;
391 INT i, count;
392 LOGBRUSH lb;
393 BOOL customstroke;
395 if((x1 == x2) && (y1 == y2))
396 return;
398 theta = gdiplus_atan2(y2 - y1, x2 - x1);
400 customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
401 if(!customstroke){
402 brush = CreateSolidBrush(color);
403 lb.lbStyle = BS_SOLID;
404 lb.lbColor = color;
405 lb.lbHatch = 0;
406 pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
407 PS_JOIN_MITER, 1, &lb, 0,
408 NULL);
409 oldbrush = SelectObject(graphics->hdc, brush);
410 oldpen = SelectObject(graphics->hdc, pen);
413 switch(cap){
414 case LineCapFlat:
415 break;
416 case LineCapSquare:
417 case LineCapSquareAnchor:
418 case LineCapDiamondAnchor:
419 size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0;
420 if(cap == LineCapDiamondAnchor){
421 dsmall = cos(theta + M_PI_2) * size;
422 dbig = sin(theta + M_PI_2) * size;
424 else{
425 dsmall = cos(theta + M_PI_4) * size;
426 dbig = sin(theta + M_PI_4) * size;
429 ptf[0].X = x2 - dsmall;
430 ptf[1].X = x2 + dbig;
432 ptf[0].Y = y2 - dbig;
433 ptf[3].Y = y2 + dsmall;
435 ptf[1].Y = y2 - dsmall;
436 ptf[2].Y = y2 + dbig;
438 ptf[3].X = x2 - dbig;
439 ptf[2].X = x2 + dsmall;
441 transform_and_round_points(graphics, pt, ptf, 4);
442 Polygon(graphics->hdc, pt, 4);
444 break;
445 case LineCapArrowAnchor:
446 size = size * 4.0 / sqrt(3.0);
448 dx = cos(M_PI / 6.0 + theta) * size;
449 dy = sin(M_PI / 6.0 + theta) * size;
451 ptf[0].X = x2 - dx;
452 ptf[0].Y = y2 - dy;
454 dx = cos(- M_PI / 6.0 + theta) * size;
455 dy = sin(- M_PI / 6.0 + theta) * size;
457 ptf[1].X = x2 - dx;
458 ptf[1].Y = y2 - dy;
460 ptf[2].X = x2;
461 ptf[2].Y = y2;
463 transform_and_round_points(graphics, pt, ptf, 3);
464 Polygon(graphics->hdc, pt, 3);
466 break;
467 case LineCapRoundAnchor:
468 dx = dy = ANCHOR_WIDTH * size / 2.0;
470 ptf[0].X = x2 - dx;
471 ptf[0].Y = y2 - dy;
472 ptf[1].X = x2 + dx;
473 ptf[1].Y = y2 + dy;
475 transform_and_round_points(graphics, pt, ptf, 2);
476 Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
478 break;
479 case LineCapTriangle:
480 size = size / 2.0;
481 dx = cos(M_PI_2 + theta) * size;
482 dy = sin(M_PI_2 + theta) * size;
484 ptf[0].X = x2 - dx;
485 ptf[0].Y = y2 - dy;
486 ptf[1].X = x2 + dx;
487 ptf[1].Y = y2 + dy;
489 dx = cos(theta) * size;
490 dy = sin(theta) * size;
492 ptf[2].X = x2 + dx;
493 ptf[2].Y = y2 + dy;
495 transform_and_round_points(graphics, pt, ptf, 3);
496 Polygon(graphics->hdc, pt, 3);
498 break;
499 case LineCapRound:
500 dx = dy = size / 2.0;
502 ptf[0].X = x2 - dx;
503 ptf[0].Y = y2 - dy;
504 ptf[1].X = x2 + dx;
505 ptf[1].Y = y2 + dy;
507 dx = -cos(M_PI_2 + theta) * size;
508 dy = -sin(M_PI_2 + theta) * size;
510 ptf[2].X = x2 - dx;
511 ptf[2].Y = y2 - dy;
512 ptf[3].X = x2 + dx;
513 ptf[3].Y = y2 + dy;
515 transform_and_round_points(graphics, pt, ptf, 4);
516 Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x,
517 pt[2].y, pt[3].x, pt[3].y);
519 break;
520 case LineCapCustom:
521 if(!custom)
522 break;
524 count = custom->pathdata.Count;
525 custptf = GdipAlloc(count * sizeof(PointF));
526 custpt = GdipAlloc(count * sizeof(POINT));
527 tp = GdipAlloc(count);
529 if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok))
530 goto custend;
532 memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF));
534 GdipScaleMatrix(matrix, size, size, MatrixOrderAppend);
535 GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2),
536 MatrixOrderAppend);
537 GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend);
538 GdipTransformMatrixPoints(matrix, custptf, count);
540 transform_and_round_points(graphics, custpt, custptf, count);
542 for(i = 0; i < count; i++)
543 tp[i] = convert_path_point_type(custom->pathdata.Types[i]);
545 if(custom->fill){
546 BeginPath(graphics->hdc);
547 PolyDraw(graphics->hdc, custpt, tp, count);
548 EndPath(graphics->hdc);
549 StrokeAndFillPath(graphics->hdc);
551 else
552 PolyDraw(graphics->hdc, custpt, tp, count);
554 custend:
555 GdipFree(custptf);
556 GdipFree(custpt);
557 GdipFree(tp);
558 GdipDeleteMatrix(matrix);
559 break;
560 default:
561 break;
564 if(!customstroke){
565 SelectObject(graphics->hdc, oldbrush);
566 SelectObject(graphics->hdc, oldpen);
567 DeleteObject(brush);
568 DeleteObject(pen);
572 /* Shortens the line by the given percent by changing x2, y2.
573 * If percent is > 1.0 then the line will change direction.
574 * If percent is negative it can lengthen the line. */
575 static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL percent)
577 REAL dist, theta, dx, dy;
579 if((y1 == *y2) && (x1 == *x2))
580 return;
582 dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent;
583 theta = gdiplus_atan2((*y2 - y1), (*x2 - x1));
584 dx = cos(theta) * dist;
585 dy = sin(theta) * dist;
587 *x2 = *x2 + dx;
588 *y2 = *y2 + dy;
591 /* Shortens the line by the given amount by changing x2, y2.
592 * If the amount is greater than the distance, the line will become length 0.
593 * If the amount is negative, it can lengthen the line. */
594 static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt)
596 REAL dx, dy, percent;
598 dx = *x2 - x1;
599 dy = *y2 - y1;
600 if(dx == 0 && dy == 0)
601 return;
603 percent = amt / sqrt(dx * dx + dy * dy);
604 if(percent >= 1.0){
605 *x2 = x1;
606 *y2 = y1;
607 return;
610 shorten_line_percent(x1, y1, x2, y2, percent);
613 /* Draws lines between the given points, and if caps is true then draws an endcap
614 * at the end of the last line. */
615 static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen,
616 GDIPCONST GpPointF * pt, INT count, BOOL caps)
618 POINT *pti = NULL;
619 GpPointF *ptcopy = NULL;
620 GpStatus status = GenericError;
622 if(!count)
623 return Ok;
625 pti = GdipAlloc(count * sizeof(POINT));
626 ptcopy = GdipAlloc(count * sizeof(GpPointF));
628 if(!pti || !ptcopy){
629 status = OutOfMemory;
630 goto end;
633 memcpy(ptcopy, pt, count * sizeof(GpPointF));
635 if(caps){
636 if(pen->endcap == LineCapArrowAnchor)
637 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
638 &ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width);
639 else if((pen->endcap == LineCapCustom) && pen->customend)
640 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
641 &ptcopy[count-1].X, &ptcopy[count-1].Y,
642 pen->customend->inset * pen->width);
644 if(pen->startcap == LineCapArrowAnchor)
645 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
646 &ptcopy[0].X, &ptcopy[0].Y, pen->width);
647 else if((pen->startcap == LineCapCustom) && pen->customstart)
648 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
649 &ptcopy[0].X, &ptcopy[0].Y,
650 pen->customstart->inset * pen->width);
652 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
653 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
654 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
655 pt[1].X, pt[1].Y, pt[0].X, pt[0].Y);
658 transform_and_round_points(graphics, pti, ptcopy, count);
660 if(Polyline(graphics->hdc, pti, count))
661 status = Ok;
663 end:
664 GdipFree(pti);
665 GdipFree(ptcopy);
667 return status;
670 /* Conducts a linear search to find the bezier points that will back off
671 * the endpoint of the curve by a distance of amt. Linear search works
672 * better than binary in this case because there are multiple solutions,
673 * and binary searches often find a bad one. I don't think this is what
674 * Windows does but short of rendering the bezier without GDI's help it's
675 * the best we can do. If rev then work from the start of the passed points
676 * instead of the end. */
677 static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev)
679 GpPointF origpt[4];
680 REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0;
681 INT i, first = 0, second = 1, third = 2, fourth = 3;
683 if(rev){
684 first = 3;
685 second = 2;
686 third = 1;
687 fourth = 0;
690 origx = pt[fourth].X;
691 origy = pt[fourth].Y;
692 memcpy(origpt, pt, sizeof(GpPointF) * 4);
694 for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){
695 /* reset bezier points to original values */
696 memcpy(pt, origpt, sizeof(GpPointF) * 4);
697 /* Perform magic on bezier points. Order is important here.*/
698 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
699 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
700 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
701 shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent);
702 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
703 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
705 dx = pt[fourth].X - origx;
706 dy = pt[fourth].Y - origy;
708 diff = sqrt(dx * dx + dy * dy);
709 percent += 0.0005 * amt;
713 /* Draws bezier curves between given points, and if caps is true then draws an
714 * endcap at the end of the last line. */
715 static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
716 GDIPCONST GpPointF * pt, INT count, BOOL caps)
718 POINT *pti;
719 GpPointF *ptcopy;
720 GpStatus status = GenericError;
722 if(!count)
723 return Ok;
725 pti = GdipAlloc(count * sizeof(POINT));
726 ptcopy = GdipAlloc(count * sizeof(GpPointF));
728 if(!pti || !ptcopy){
729 status = OutOfMemory;
730 goto end;
733 memcpy(ptcopy, pt, count * sizeof(GpPointF));
735 if(caps){
736 if(pen->endcap == LineCapArrowAnchor)
737 shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
738 else if((pen->endcap == LineCapCustom) && pen->customend)
739 shorten_bezier_amt(&ptcopy[count-4], pen->width * pen->customend->inset,
740 FALSE);
742 if(pen->startcap == LineCapArrowAnchor)
743 shorten_bezier_amt(ptcopy, pen->width, TRUE);
744 else if((pen->startcap == LineCapCustom) && pen->customstart)
745 shorten_bezier_amt(ptcopy, pen->width * pen->customstart->inset, TRUE);
747 /* the direction of the line cap is parallel to the direction at the
748 * end of the bezier (which, if it has been shortened, is not the same
749 * as the direction from pt[count-2] to pt[count-1]) */
750 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
751 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
752 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
753 pt[count - 1].X, pt[count - 1].Y);
755 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
756 pt[0].X - (ptcopy[0].X - ptcopy[1].X),
757 pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
760 transform_and_round_points(graphics, pti, ptcopy, count);
762 PolyBezier(graphics->hdc, pti, count);
764 status = Ok;
766 end:
767 GdipFree(pti);
768 GdipFree(ptcopy);
770 return status;
773 /* Draws a combination of bezier curves and lines between points. */
774 static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
775 GDIPCONST BYTE * types, INT count, BOOL caps)
777 POINT *pti = GdipAlloc(count * sizeof(POINT));
778 BYTE *tp = GdipAlloc(count);
779 GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
780 INT i, j;
781 GpStatus status = GenericError;
783 if(!count){
784 status = Ok;
785 goto end;
787 if(!pti || !tp || !ptcopy){
788 status = OutOfMemory;
789 goto end;
792 for(i = 1; i < count; i++){
793 if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
794 if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
795 || !(types[i + 1] & PathPointTypeBezier)){
796 ERR("Bad bezier points\n");
797 goto end;
799 i += 2;
803 memcpy(ptcopy, pt, count * sizeof(GpPointF));
805 /* If we are drawing caps, go through the points and adjust them accordingly,
806 * and draw the caps. */
807 if(caps){
808 switch(types[count - 1] & PathPointTypePathTypeMask){
809 case PathPointTypeBezier:
810 if(pen->endcap == LineCapArrowAnchor)
811 shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
812 else if((pen->endcap == LineCapCustom) && pen->customend)
813 shorten_bezier_amt(&ptcopy[count - 4],
814 pen->width * pen->customend->inset, FALSE);
816 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
817 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
818 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
819 pt[count - 1].X, pt[count - 1].Y);
821 break;
822 case PathPointTypeLine:
823 if(pen->endcap == LineCapArrowAnchor)
824 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
825 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
826 pen->width);
827 else if((pen->endcap == LineCapCustom) && pen->customend)
828 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
829 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
830 pen->customend->inset * pen->width);
832 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
833 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
834 pt[count - 1].Y);
836 break;
837 default:
838 ERR("Bad path last point\n");
839 goto end;
842 /* Find start of points */
843 for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
844 == PathPointTypeStart); j++);
846 switch(types[j] & PathPointTypePathTypeMask){
847 case PathPointTypeBezier:
848 if(pen->startcap == LineCapArrowAnchor)
849 shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
850 else if((pen->startcap == LineCapCustom) && pen->customstart)
851 shorten_bezier_amt(&ptcopy[j - 1],
852 pen->width * pen->customstart->inset, TRUE);
854 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
855 pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
856 pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
857 pt[j - 1].X, pt[j - 1].Y);
859 break;
860 case PathPointTypeLine:
861 if(pen->startcap == LineCapArrowAnchor)
862 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
863 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
864 pen->width);
865 else if((pen->startcap == LineCapCustom) && pen->customstart)
866 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
867 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
868 pen->customstart->inset * pen->width);
870 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
871 pt[j].X, pt[j].Y, pt[j - 1].X,
872 pt[j - 1].Y);
874 break;
875 default:
876 ERR("Bad path points\n");
877 goto end;
881 transform_and_round_points(graphics, pti, ptcopy, count);
883 for(i = 0; i < count; i++){
884 tp[i] = convert_path_point_type(types[i]);
887 PolyDraw(graphics->hdc, pti, tp, count);
889 status = Ok;
891 end:
892 GdipFree(pti);
893 GdipFree(ptcopy);
894 GdipFree(tp);
896 return status;
899 GpStatus trace_path(GpGraphics *graphics, GpPath *path)
901 GpStatus result;
903 BeginPath(graphics->hdc);
904 result = draw_poly(graphics, NULL, path->pathdata.Points,
905 path->pathdata.Types, path->pathdata.Count, FALSE);
906 EndPath(graphics->hdc);
907 return result;
910 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
912 TRACE("(%p, %p)\n", hdc, graphics);
914 return GdipCreateFromHDC2(hdc, NULL, graphics);
917 GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **graphics)
919 GpStatus retval;
921 TRACE("(%p, %p, %p)\n", hdc, hDevice, graphics);
923 if(hDevice != NULL) {
924 FIXME("Don't know how to hadle parameter hDevice\n");
925 return NotImplemented;
928 if(hdc == NULL)
929 return OutOfMemory;
931 if(graphics == NULL)
932 return InvalidParameter;
934 *graphics = GdipAlloc(sizeof(GpGraphics));
935 if(!*graphics) return OutOfMemory;
937 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
938 GdipFree(*graphics);
939 return retval;
942 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
943 GdipFree((*graphics)->worldtrans);
944 GdipFree(*graphics);
945 return retval;
948 (*graphics)->hdc = hdc;
949 (*graphics)->hwnd = WindowFromDC(hdc);
950 (*graphics)->owndc = FALSE;
951 (*graphics)->smoothing = SmoothingModeDefault;
952 (*graphics)->compqual = CompositingQualityDefault;
953 (*graphics)->interpolation = InterpolationModeDefault;
954 (*graphics)->pixeloffset = PixelOffsetModeDefault;
955 (*graphics)->compmode = CompositingModeSourceOver;
956 (*graphics)->unit = UnitDisplay;
957 (*graphics)->scale = 1.0;
958 (*graphics)->busy = FALSE;
959 (*graphics)->textcontrast = 4;
961 return Ok;
964 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
966 GpStatus ret;
967 HDC hdc;
969 TRACE("(%p, %p)\n", hwnd, graphics);
971 hdc = GetDC(hwnd);
973 if((ret = GdipCreateFromHDC(hdc, graphics)) != Ok)
975 ReleaseDC(hwnd, hdc);
976 return ret;
979 (*graphics)->hwnd = hwnd;
980 (*graphics)->owndc = TRUE;
982 return Ok;
985 /* FIXME: no icm handling */
986 GpStatus WINGDIPAPI GdipCreateFromHWNDICM(HWND hwnd, GpGraphics **graphics)
988 TRACE("(%p, %p)\n", hwnd, graphics);
990 return GdipCreateFromHWND(hwnd, graphics);
993 GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
994 GpMetafile **metafile)
996 static int calls;
998 if(!hemf || !metafile)
999 return InvalidParameter;
1001 if(!(calls++))
1002 FIXME("not implemented\n");
1004 return NotImplemented;
1007 GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
1008 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
1010 IStream *stream = NULL;
1011 UINT read;
1012 BYTE* copy;
1013 HENHMETAFILE hemf;
1014 GpStatus retval = GenericError;
1016 TRACE("(%p, %d, %p, %p)\n", hwmf, delete, placeable, metafile);
1018 if(!hwmf || !metafile || !placeable)
1019 return InvalidParameter;
1021 *metafile = NULL;
1022 read = GetMetaFileBitsEx(hwmf, 0, NULL);
1023 if(!read)
1024 return GenericError;
1025 copy = GdipAlloc(read);
1026 GetMetaFileBitsEx(hwmf, read, copy);
1028 hemf = SetWinMetaFileBits(read, copy, NULL, NULL);
1029 GdipFree(copy);
1031 read = GetEnhMetaFileBits(hemf, 0, NULL);
1032 copy = GdipAlloc(read);
1033 GetEnhMetaFileBits(hemf, read, copy);
1034 DeleteEnhMetaFile(hemf);
1036 if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
1037 ERR("could not make stream\n");
1038 GdipFree(copy);
1039 goto err;
1042 *metafile = GdipAlloc(sizeof(GpMetafile));
1043 if(!*metafile){
1044 retval = OutOfMemory;
1045 goto err;
1048 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1049 (LPVOID*) &((*metafile)->image.picture)) != S_OK)
1050 goto err;
1053 (*metafile)->image.type = ImageTypeMetafile;
1054 (*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch);
1055 (*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Right) / ((REAL) placeable->Inch);
1056 (*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right
1057 - placeable->BoundingBox.Left)) / ((REAL) placeable->Inch);
1058 (*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom
1059 - placeable->BoundingBox.Top)) / ((REAL) placeable->Inch);
1060 (*metafile)->unit = UnitInch;
1062 if(delete)
1063 DeleteMetaFile(hwmf);
1065 return Ok;
1067 err:
1068 GdipFree(*metafile);
1069 IStream_Release(stream);
1070 return retval;
1073 GpStatus WINGDIPAPI GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR *file,
1074 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
1076 HMETAFILE hmf = GetMetaFileW(file);
1078 TRACE("(%s, %p, %p)\n", debugstr_w(file), placeable, metafile);
1080 if(!hmf) return InvalidParameter;
1082 return GdipCreateMetafileFromWmf(hmf, TRUE, placeable, metafile);
1085 GpStatus WINGDIPAPI GdipCreateStreamOnFile(GDIPCONST WCHAR * filename,
1086 UINT access, IStream **stream)
1088 DWORD dwMode;
1089 HRESULT ret;
1091 TRACE("(%s, %u, %p)\n", debugstr_w(filename), access, stream);
1093 if(!stream || !filename)
1094 return InvalidParameter;
1096 if(access & GENERIC_WRITE)
1097 dwMode = STGM_SHARE_DENY_WRITE | STGM_WRITE | STGM_CREATE;
1098 else if(access & GENERIC_READ)
1099 dwMode = STGM_SHARE_DENY_WRITE | STGM_READ | STGM_FAILIFTHERE;
1100 else
1101 return InvalidParameter;
1103 ret = SHCreateStreamOnFileW(filename, dwMode, stream);
1105 return hresult_to_status(ret);
1108 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
1110 TRACE("(%p)\n", graphics);
1112 if(!graphics) return InvalidParameter;
1113 if(graphics->busy) return ObjectBusy;
1115 if(graphics->owndc)
1116 ReleaseDC(graphics->hwnd, graphics->hdc);
1118 GdipDeleteRegion(graphics->clip);
1119 GdipDeleteMatrix(graphics->worldtrans);
1120 GdipFree(graphics);
1122 return Ok;
1125 GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
1126 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1128 INT save_state, num_pts;
1129 GpPointF points[MAX_ARC_PTS];
1130 GpStatus retval;
1132 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
1133 width, height, startAngle, sweepAngle);
1135 if(!graphics || !pen || width <= 0 || height <= 0)
1136 return InvalidParameter;
1138 if(graphics->busy)
1139 return ObjectBusy;
1141 num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
1143 save_state = prepare_dc(graphics, pen);
1145 retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
1147 restore_dc(graphics, save_state);
1149 return retval;
1152 GpStatus WINGDIPAPI GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x,
1153 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
1155 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
1156 width, height, startAngle, sweepAngle);
1158 return GdipDrawArc(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
1161 GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
1162 REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
1164 INT save_state;
1165 GpPointF pt[4];
1166 GpStatus retval;
1168 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1,
1169 x2, y2, x3, y3, x4, y4);
1171 if(!graphics || !pen)
1172 return InvalidParameter;
1174 if(graphics->busy)
1175 return ObjectBusy;
1177 pt[0].X = x1;
1178 pt[0].Y = y1;
1179 pt[1].X = x2;
1180 pt[1].Y = y2;
1181 pt[2].X = x3;
1182 pt[2].Y = y3;
1183 pt[3].X = x4;
1184 pt[3].Y = y4;
1186 save_state = prepare_dc(graphics, pen);
1188 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
1190 restore_dc(graphics, save_state);
1192 return retval;
1195 GpStatus WINGDIPAPI GdipDrawBezierI(GpGraphics *graphics, GpPen *pen, INT x1,
1196 INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4)
1198 INT save_state;
1199 GpPointF pt[4];
1200 GpStatus retval;
1202 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics, pen, x1, y1,
1203 x2, y2, x3, y3, x4, y4);
1205 if(!graphics || !pen)
1206 return InvalidParameter;
1208 if(graphics->busy)
1209 return ObjectBusy;
1211 pt[0].X = x1;
1212 pt[0].Y = y1;
1213 pt[1].X = x2;
1214 pt[1].Y = y2;
1215 pt[2].X = x3;
1216 pt[2].Y = y3;
1217 pt[3].X = x4;
1218 pt[3].Y = y4;
1220 save_state = prepare_dc(graphics, pen);
1222 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
1224 restore_dc(graphics, save_state);
1226 return retval;
1229 GpStatus WINGDIPAPI GdipDrawBeziers(GpGraphics *graphics, GpPen *pen,
1230 GDIPCONST GpPointF *points, INT count)
1232 INT i;
1233 GpStatus ret;
1235 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1237 if(!graphics || !pen || !points || (count <= 0))
1238 return InvalidParameter;
1240 if(graphics->busy)
1241 return ObjectBusy;
1243 for(i = 0; i < floor(count / 4); i++){
1244 ret = GdipDrawBezier(graphics, pen,
1245 points[4*i].X, points[4*i].Y,
1246 points[4*i + 1].X, points[4*i + 1].Y,
1247 points[4*i + 2].X, points[4*i + 2].Y,
1248 points[4*i + 3].X, points[4*i + 3].Y);
1249 if(ret != Ok)
1250 return ret;
1253 return Ok;
1256 GpStatus WINGDIPAPI GdipDrawBeziersI(GpGraphics *graphics, GpPen *pen,
1257 GDIPCONST GpPoint *points, INT count)
1259 GpPointF *pts;
1260 GpStatus ret;
1261 INT i;
1263 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1265 if(!graphics || !pen || !points || (count <= 0))
1266 return InvalidParameter;
1268 if(graphics->busy)
1269 return ObjectBusy;
1271 pts = GdipAlloc(sizeof(GpPointF) * count);
1272 if(!pts)
1273 return OutOfMemory;
1275 for(i = 0; i < count; i++){
1276 pts[i].X = (REAL)points[i].X;
1277 pts[i].Y = (REAL)points[i].Y;
1280 ret = GdipDrawBeziers(graphics,pen,pts,count);
1282 GdipFree(pts);
1284 return ret;
1287 GpStatus WINGDIPAPI GdipDrawClosedCurve(GpGraphics *graphics, GpPen *pen,
1288 GDIPCONST GpPointF *points, INT count)
1290 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1292 return GdipDrawClosedCurve2(graphics, pen, points, count, 1.0);
1295 GpStatus WINGDIPAPI GdipDrawClosedCurveI(GpGraphics *graphics, GpPen *pen,
1296 GDIPCONST GpPoint *points, INT count)
1298 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1300 return GdipDrawClosedCurve2I(graphics, pen, points, count, 1.0);
1303 GpStatus WINGDIPAPI GdipDrawClosedCurve2(GpGraphics *graphics, GpPen *pen,
1304 GDIPCONST GpPointF *points, INT count, REAL tension)
1306 GpPath *path;
1307 GpStatus stat;
1309 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1311 if(!graphics || !pen || !points || count <= 0)
1312 return InvalidParameter;
1314 if(graphics->busy)
1315 return ObjectBusy;
1317 if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok)
1318 return stat;
1320 stat = GdipAddPathClosedCurve2(path, points, count, tension);
1321 if(stat != Ok){
1322 GdipDeletePath(path);
1323 return stat;
1326 stat = GdipDrawPath(graphics, pen, path);
1328 GdipDeletePath(path);
1330 return stat;
1333 GpStatus WINGDIPAPI GdipDrawClosedCurve2I(GpGraphics *graphics, GpPen *pen,
1334 GDIPCONST GpPoint *points, INT count, REAL tension)
1336 GpPointF *ptf;
1337 GpStatus stat;
1338 INT i;
1340 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1342 if(!points || count <= 0)
1343 return InvalidParameter;
1345 ptf = GdipAlloc(sizeof(GpPointF)*count);
1346 if(!ptf)
1347 return OutOfMemory;
1349 for(i = 0; i < count; i++){
1350 ptf[i].X = (REAL)points[i].X;
1351 ptf[i].Y = (REAL)points[i].Y;
1354 stat = GdipDrawClosedCurve2(graphics, pen, ptf, count, tension);
1356 GdipFree(ptf);
1358 return stat;
1361 GpStatus WINGDIPAPI GdipDrawCurve(GpGraphics *graphics, GpPen *pen,
1362 GDIPCONST GpPointF *points, INT count)
1364 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1366 return GdipDrawCurve2(graphics,pen,points,count,1.0);
1369 GpStatus WINGDIPAPI GdipDrawCurveI(GpGraphics *graphics, GpPen *pen,
1370 GDIPCONST GpPoint *points, INT count)
1372 GpPointF *pointsF;
1373 GpStatus ret;
1374 INT i;
1376 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1378 if(!points || count <= 0)
1379 return InvalidParameter;
1381 pointsF = GdipAlloc(sizeof(GpPointF)*count);
1382 if(!pointsF)
1383 return OutOfMemory;
1385 for(i = 0; i < count; i++){
1386 pointsF[i].X = (REAL)points[i].X;
1387 pointsF[i].Y = (REAL)points[i].Y;
1390 ret = GdipDrawCurve(graphics,pen,pointsF,count);
1391 GdipFree(pointsF);
1393 return ret;
1396 /* Approximates cardinal spline with Bezier curves. */
1397 GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
1398 GDIPCONST GpPointF *points, INT count, REAL tension)
1400 /* PolyBezier expects count*3-2 points. */
1401 INT i, len_pt = count*3-2, save_state;
1402 GpPointF *pt;
1403 REAL x1, x2, y1, y2;
1404 GpStatus retval;
1406 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1408 if(!graphics || !pen)
1409 return InvalidParameter;
1411 if(graphics->busy)
1412 return ObjectBusy;
1414 pt = GdipAlloc(len_pt * sizeof(GpPointF));
1415 tension = tension * TENSION_CONST;
1417 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
1418 tension, &x1, &y1);
1420 pt[0].X = points[0].X;
1421 pt[0].Y = points[0].Y;
1422 pt[1].X = x1;
1423 pt[1].Y = y1;
1425 for(i = 0; i < count-2; i++){
1426 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
1428 pt[3*i+2].X = x1;
1429 pt[3*i+2].Y = y1;
1430 pt[3*i+3].X = points[i+1].X;
1431 pt[3*i+3].Y = points[i+1].Y;
1432 pt[3*i+4].X = x2;
1433 pt[3*i+4].Y = y2;
1436 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
1437 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
1439 pt[len_pt-2].X = x1;
1440 pt[len_pt-2].Y = y1;
1441 pt[len_pt-1].X = points[count-1].X;
1442 pt[len_pt-1].Y = points[count-1].Y;
1444 save_state = prepare_dc(graphics, pen);
1446 retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
1448 GdipFree(pt);
1449 restore_dc(graphics, save_state);
1451 return retval;
1454 GpStatus WINGDIPAPI GdipDrawCurve2I(GpGraphics *graphics, GpPen *pen,
1455 GDIPCONST GpPoint *points, INT count, REAL tension)
1457 GpPointF *pointsF;
1458 GpStatus ret;
1459 INT i;
1461 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1463 if(!points || count <= 0)
1464 return InvalidParameter;
1466 pointsF = GdipAlloc(sizeof(GpPointF)*count);
1467 if(!pointsF)
1468 return OutOfMemory;
1470 for(i = 0; i < count; i++){
1471 pointsF[i].X = (REAL)points[i].X;
1472 pointsF[i].Y = (REAL)points[i].Y;
1475 ret = GdipDrawCurve2(graphics,pen,pointsF,count,tension);
1476 GdipFree(pointsF);
1478 return ret;
1481 GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics *graphics, GpPen *pen, REAL x,
1482 REAL y, REAL width, REAL height)
1484 INT save_state;
1485 GpPointF ptf[2];
1486 POINT pti[2];
1488 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
1490 if(!graphics || !pen)
1491 return InvalidParameter;
1493 if(graphics->busy)
1494 return ObjectBusy;
1496 ptf[0].X = x;
1497 ptf[0].Y = y;
1498 ptf[1].X = x + width;
1499 ptf[1].Y = y + height;
1501 save_state = prepare_dc(graphics, pen);
1502 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1504 transform_and_round_points(graphics, pti, ptf, 2);
1506 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
1508 restore_dc(graphics, save_state);
1510 return Ok;
1513 GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics *graphics, GpPen *pen, INT x,
1514 INT y, INT width, INT height)
1516 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
1518 return GdipDrawEllipse(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1522 GpStatus WINGDIPAPI GdipDrawImage(GpGraphics *graphics, GpImage *image, REAL x, REAL y)
1524 TRACE("(%p, %p, %.2f, %.2f)\n", graphics, image, x, y);
1526 /* IPicture::Render uses LONG coords */
1527 return GdipDrawImageI(graphics,image,roundr(x),roundr(y));
1530 GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x,
1531 INT y)
1533 UINT width, height, srcw, srch;
1535 TRACE("(%p, %p, %d, %d)\n", graphics, image, x, y);
1537 if(!graphics || !image)
1538 return InvalidParameter;
1540 GdipGetImageWidth(image, &width);
1541 GdipGetImageHeight(image, &height);
1543 srcw = width * (((REAL) INCH_HIMETRIC) /
1544 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX)));
1545 srch = height * (((REAL) INCH_HIMETRIC) /
1546 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY)));
1548 if(image->type != ImageTypeMetafile){
1549 y += height;
1550 height *= -1;
1553 IPicture_Render(image->picture, graphics->hdc, x, y, width, height,
1554 0, 0, srcw, srch, NULL);
1556 return Ok;
1559 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1560 GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
1561 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
1562 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
1563 DrawImageAbort callback, VOID * callbackData)
1565 GpPointF ptf[3];
1566 POINT pti[3];
1567 REAL dx, dy;
1569 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics, image, points,
1570 count, srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
1571 callbackData);
1573 if(!graphics || !image || !points || count != 3)
1574 return InvalidParameter;
1576 if(srcUnit == UnitInch)
1577 dx = dy = (REAL) INCH_HIMETRIC;
1578 else if(srcUnit == UnitPixel){
1579 dx = ((REAL) INCH_HIMETRIC) /
1580 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
1581 dy = ((REAL) INCH_HIMETRIC) /
1582 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
1584 else
1585 return NotImplemented;
1587 memcpy(ptf, points, 3 * sizeof(GpPointF));
1588 transform_and_round_points(graphics, pti, ptf, 3);
1590 /* IPicture renders bitmaps with the y-axis reversed
1591 * FIXME: flipping for unknown image type might not be correct. */
1592 if(image->type != ImageTypeMetafile){
1593 INT temp;
1594 temp = pti[0].y;
1595 pti[0].y = pti[2].y;
1596 pti[2].y = temp;
1599 if(IPicture_Render(image->picture, graphics->hdc,
1600 pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
1601 srcx * dx, srcy * dy,
1602 srcwidth * dx, srcheight * dy,
1603 NULL) != S_OK){
1604 if(callback)
1605 callback(callbackData);
1606 return GenericError;
1609 return Ok;
1612 GpStatus WINGDIPAPI GdipDrawImagePointsRectI(GpGraphics *graphics, GpImage *image,
1613 GDIPCONST GpPoint *points, INT count, INT srcx, INT srcy, INT srcwidth,
1614 INT srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
1615 DrawImageAbort callback, VOID * callbackData)
1617 GpPointF pointsF[3];
1618 INT i;
1620 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics, image, points, count,
1621 srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
1622 callbackData);
1624 if(!points || count!=3)
1625 return InvalidParameter;
1627 for(i = 0; i < count; i++){
1628 pointsF[i].X = (REAL)points[i].X;
1629 pointsF[i].Y = (REAL)points[i].Y;
1632 return GdipDrawImagePointsRect(graphics, image, pointsF, count, (REAL)srcx, (REAL)srcy,
1633 (REAL)srcwidth, (REAL)srcheight, srcUnit, imageAttributes,
1634 callback, callbackData);
1637 GpStatus WINGDIPAPI GdipDrawImageRectRect(GpGraphics *graphics, GpImage *image,
1638 REAL dstx, REAL dsty, REAL dstwidth, REAL dstheight, REAL srcx, REAL srcy,
1639 REAL srcwidth, REAL srcheight, GpUnit srcUnit,
1640 GDIPCONST GpImageAttributes* imageattr, DrawImageAbort callback,
1641 VOID * callbackData)
1643 GpPointF points[3];
1645 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
1646 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
1647 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
1649 points[0].X = dstx;
1650 points[0].Y = dsty;
1651 points[1].X = dstx + dstwidth;
1652 points[1].Y = dsty;
1653 points[2].X = dstx;
1654 points[2].Y = dsty + dstheight;
1656 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
1657 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
1660 GpStatus WINGDIPAPI GdipDrawImageRectRectI(GpGraphics *graphics, GpImage *image,
1661 INT dstx, INT dsty, INT dstwidth, INT dstheight, INT srcx, INT srcy,
1662 INT srcwidth, INT srcheight, GpUnit srcUnit,
1663 GDIPCONST GpImageAttributes* imageAttributes, DrawImageAbort callback,
1664 VOID * callbackData)
1666 GpPointF points[3];
1668 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
1669 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
1670 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
1672 points[0].X = dstx;
1673 points[0].Y = dsty;
1674 points[1].X = dstx + dstwidth;
1675 points[1].Y = dsty;
1676 points[2].X = dstx;
1677 points[2].Y = dsty + dstheight;
1679 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
1680 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
1683 GpStatus WINGDIPAPI GdipDrawImageRect(GpGraphics *graphics, GpImage *image,
1684 REAL x, REAL y, REAL width, REAL height)
1686 RectF bounds;
1687 GpUnit unit;
1688 GpStatus ret;
1690 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, image, x, y, width, height);
1692 if(!graphics || !image)
1693 return InvalidParameter;
1695 ret = GdipGetImageBounds(image, &bounds, &unit);
1696 if(ret != Ok)
1697 return ret;
1699 return GdipDrawImageRectRect(graphics, image, x, y, width, height,
1700 bounds.X, bounds.Y, bounds.Width, bounds.Height,
1701 unit, NULL, NULL, NULL);
1704 GpStatus WINGDIPAPI GdipDrawImageRectI(GpGraphics *graphics, GpImage *image,
1705 INT x, INT y, INT width, INT height)
1707 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, image, x, y, width, height);
1709 return GdipDrawImageRect(graphics, image, (REAL)x, (REAL)y, (REAL)width, (REAL)height);
1712 GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1,
1713 REAL y1, REAL x2, REAL y2)
1715 INT save_state;
1716 GpPointF pt[2];
1717 GpStatus retval;
1719 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1, x2, y2);
1721 if(!pen || !graphics)
1722 return InvalidParameter;
1724 if(graphics->busy)
1725 return ObjectBusy;
1727 pt[0].X = x1;
1728 pt[0].Y = y1;
1729 pt[1].X = x2;
1730 pt[1].Y = y2;
1732 save_state = prepare_dc(graphics, pen);
1734 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
1736 restore_dc(graphics, save_state);
1738 return retval;
1741 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
1742 INT y1, INT x2, INT y2)
1744 INT save_state;
1745 GpPointF pt[2];
1746 GpStatus retval;
1748 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x1, y1, x2, y2);
1750 if(!pen || !graphics)
1751 return InvalidParameter;
1753 if(graphics->busy)
1754 return ObjectBusy;
1756 pt[0].X = (REAL)x1;
1757 pt[0].Y = (REAL)y1;
1758 pt[1].X = (REAL)x2;
1759 pt[1].Y = (REAL)y2;
1761 save_state = prepare_dc(graphics, pen);
1763 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
1765 restore_dc(graphics, save_state);
1767 return retval;
1770 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
1771 GpPointF *points, INT count)
1773 INT save_state;
1774 GpStatus retval;
1776 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1778 if(!pen || !graphics || (count < 2))
1779 return InvalidParameter;
1781 if(graphics->busy)
1782 return ObjectBusy;
1784 save_state = prepare_dc(graphics, pen);
1786 retval = draw_polyline(graphics, pen, points, count, TRUE);
1788 restore_dc(graphics, save_state);
1790 return retval;
1793 GpStatus WINGDIPAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, GDIPCONST
1794 GpPoint *points, INT count)
1796 INT save_state;
1797 GpStatus retval;
1798 GpPointF *ptf = NULL;
1799 int i;
1801 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1803 if(!pen || !graphics || (count < 2))
1804 return InvalidParameter;
1806 if(graphics->busy)
1807 return ObjectBusy;
1809 ptf = GdipAlloc(count * sizeof(GpPointF));
1810 if(!ptf) return OutOfMemory;
1812 for(i = 0; i < count; i ++){
1813 ptf[i].X = (REAL) points[i].X;
1814 ptf[i].Y = (REAL) points[i].Y;
1817 save_state = prepare_dc(graphics, pen);
1819 retval = draw_polyline(graphics, pen, ptf, count, TRUE);
1821 restore_dc(graphics, save_state);
1823 GdipFree(ptf);
1824 return retval;
1827 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
1829 INT save_state;
1830 GpStatus retval;
1832 TRACE("(%p, %p, %p)\n", graphics, pen, path);
1834 if(!pen || !graphics)
1835 return InvalidParameter;
1837 if(graphics->busy)
1838 return ObjectBusy;
1840 save_state = prepare_dc(graphics, pen);
1842 retval = draw_poly(graphics, pen, path->pathdata.Points,
1843 path->pathdata.Types, path->pathdata.Count, TRUE);
1845 restore_dc(graphics, save_state);
1847 return retval;
1850 GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
1851 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1853 INT save_state;
1855 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
1856 width, height, startAngle, sweepAngle);
1858 if(!graphics || !pen)
1859 return InvalidParameter;
1861 if(graphics->busy)
1862 return ObjectBusy;
1864 save_state = prepare_dc(graphics, pen);
1865 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1867 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
1869 restore_dc(graphics, save_state);
1871 return Ok;
1874 GpStatus WINGDIPAPI GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x,
1875 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
1877 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
1878 width, height, startAngle, sweepAngle);
1880 return GdipDrawPie(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
1883 GpStatus WINGDIPAPI GdipDrawRectangle(GpGraphics *graphics, GpPen *pen, REAL x,
1884 REAL y, REAL width, REAL height)
1886 INT save_state;
1887 GpPointF ptf[4];
1888 POINT pti[4];
1890 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
1892 if(!pen || !graphics)
1893 return InvalidParameter;
1895 if(graphics->busy)
1896 return ObjectBusy;
1898 ptf[0].X = x;
1899 ptf[0].Y = y;
1900 ptf[1].X = x + width;
1901 ptf[1].Y = y;
1902 ptf[2].X = x + width;
1903 ptf[2].Y = y + height;
1904 ptf[3].X = x;
1905 ptf[3].Y = y + height;
1907 save_state = prepare_dc(graphics, pen);
1908 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1910 transform_and_round_points(graphics, pti, ptf, 4);
1911 Polygon(graphics->hdc, pti, 4);
1913 restore_dc(graphics, save_state);
1915 return Ok;
1918 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
1919 INT y, INT width, INT height)
1921 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
1923 return GdipDrawRectangle(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1926 GpStatus WINGDIPAPI GdipDrawRectangles(GpGraphics *graphics, GpPen *pen,
1927 GDIPCONST GpRectF* rects, INT count)
1929 GpPointF *ptf;
1930 POINT *pti;
1931 INT save_state, i;
1933 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
1935 if(!graphics || !pen || !rects || count < 1)
1936 return InvalidParameter;
1938 if(graphics->busy)
1939 return ObjectBusy;
1941 ptf = GdipAlloc(4 * count * sizeof(GpPointF));
1942 pti = GdipAlloc(4 * count * sizeof(POINT));
1944 if(!ptf || !pti){
1945 GdipFree(ptf);
1946 GdipFree(pti);
1947 return OutOfMemory;
1950 for(i = 0; i < count; i++){
1951 ptf[4 * i + 3].X = ptf[4 * i].X = rects[i].X;
1952 ptf[4 * i + 1].Y = ptf[4 * i].Y = rects[i].Y;
1953 ptf[4 * i + 2].X = ptf[4 * i + 1].X = rects[i].X + rects[i].Width;
1954 ptf[4 * i + 3].Y = ptf[4 * i + 2].Y = rects[i].Y + rects[i].Height;
1957 save_state = prepare_dc(graphics, pen);
1958 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1960 transform_and_round_points(graphics, pti, ptf, 4 * count);
1962 for(i = 0; i < count; i++)
1963 Polygon(graphics->hdc, &pti[4 * i], 4);
1965 restore_dc(graphics, save_state);
1967 GdipFree(ptf);
1968 GdipFree(pti);
1970 return Ok;
1973 GpStatus WINGDIPAPI GdipDrawRectanglesI(GpGraphics *graphics, GpPen *pen,
1974 GDIPCONST GpRect* rects, INT count)
1976 GpRectF *rectsF;
1977 GpStatus ret;
1978 INT i;
1980 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
1982 if(!rects || count<=0)
1983 return InvalidParameter;
1985 rectsF = GdipAlloc(sizeof(GpRectF) * count);
1986 if(!rectsF)
1987 return OutOfMemory;
1989 for(i = 0;i < count;i++){
1990 rectsF[i].X = (REAL)rects[i].X;
1991 rectsF[i].Y = (REAL)rects[i].Y;
1992 rectsF[i].Width = (REAL)rects[i].Width;
1993 rectsF[i].Height = (REAL)rects[i].Height;
1996 ret = GdipDrawRectangles(graphics, pen, rectsF, count);
1997 GdipFree(rectsF);
1999 return ret;
2002 GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string,
2003 INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect,
2004 GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush)
2006 HRGN rgn = NULL;
2007 HFONT gdifont;
2008 LOGFONTW lfw;
2009 TEXTMETRICW textmet;
2010 GpPointF pt[2], rectcpy[4];
2011 POINT corners[4];
2012 WCHAR* stringdup;
2013 REAL angle, ang_cos, ang_sin, rel_width, rel_height;
2014 INT sum = 0, height = 0, fit, fitcpy, save_state, i, j, lret, nwidth,
2015 nheight;
2016 SIZE size;
2017 RECT drawcoord;
2019 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length),
2020 length, font, debugstr_rectf(rect), format, brush);
2022 if(!graphics || !string || !font || !brush || !rect)
2023 return InvalidParameter;
2025 if((brush->bt != BrushTypeSolidColor)){
2026 FIXME("not implemented for given parameters\n");
2027 return NotImplemented;
2030 if(format)
2031 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
2033 if(length == -1) length = lstrlenW(string);
2035 stringdup = GdipAlloc(length * sizeof(WCHAR));
2036 if(!stringdup) return OutOfMemory;
2038 save_state = SaveDC(graphics->hdc);
2039 SetBkMode(graphics->hdc, TRANSPARENT);
2040 SetTextColor(graphics->hdc, brush->lb.lbColor);
2042 rectcpy[3].X = rectcpy[0].X = rect->X;
2043 rectcpy[1].Y = rectcpy[0].Y = rect->Y;
2044 rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width;
2045 rectcpy[3].Y = rectcpy[2].Y = rect->Y + rect->Height;
2046 transform_and_round_points(graphics, corners, rectcpy, 4);
2048 if (roundr(rect->Width) == 0)
2050 rel_width = 1.0;
2051 nwidth = INT_MAX;
2053 else
2055 rel_width = sqrt((corners[1].x - corners[0].x) * (corners[1].x - corners[0].x) +
2056 (corners[1].y - corners[0].y) * (corners[1].y - corners[0].y))
2057 / rect->Width;
2058 nwidth = roundr(rel_width * rect->Width);
2061 if (roundr(rect->Height) == 0)
2063 rel_height = 1.0;
2064 nheight = INT_MAX;
2066 else
2068 rel_height = sqrt((corners[2].x - corners[1].x) * (corners[2].x - corners[1].x) +
2069 (corners[2].y - corners[1].y) * (corners[2].y - corners[1].y))
2070 / rect->Height;
2071 nheight = roundr(rel_height * rect->Height);
2074 if (roundr(rect->Width) != 0 && roundr(rect->Height) != 0)
2076 /* FIXME: If only the width or only the height is 0, we should probably still clip */
2077 rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
2078 SelectClipRgn(graphics->hdc, rgn);
2081 /* Use gdi to find the font, then perform transformations on it (height,
2082 * width, angle). */
2083 SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
2084 GetTextMetricsW(graphics->hdc, &textmet);
2085 lfw = font->lfw;
2087 lfw.lfHeight = roundr(((REAL)lfw.lfHeight) * rel_height);
2088 lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width);
2090 pt[0].X = 0.0;
2091 pt[0].Y = 0.0;
2092 pt[1].X = 1.0;
2093 pt[1].Y = 0.0;
2094 GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
2095 angle = gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X));
2096 ang_cos = cos(angle);
2097 ang_sin = sin(angle);
2098 lfw.lfEscapement = lfw.lfOrientation = -roundr((angle / M_PI) * 1800.0);
2100 gdifont = CreateFontIndirectW(&lfw);
2101 DeleteObject(SelectObject(graphics->hdc, CreateFontIndirectW(&lfw)));
2103 for(i = 0, j = 0; i < length; i++){
2104 if(!isprintW(string[i]) && (string[i] != '\n'))
2105 continue;
2107 stringdup[j] = string[i];
2108 j++;
2111 length = j;
2113 while(sum < length){
2114 drawcoord.left = corners[0].x + roundr(ang_sin * (REAL) height);
2115 drawcoord.top = corners[0].y + roundr(ang_cos * (REAL) height);
2117 GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum,
2118 nwidth, &fit, NULL, &size);
2119 fitcpy = fit;
2121 if(fit == 0){
2122 DrawTextW(graphics->hdc, stringdup + sum, 1, &drawcoord, DT_NOCLIP |
2123 DT_EXPANDTABS);
2124 break;
2127 for(lret = 0; lret < fit; lret++)
2128 if(*(stringdup + sum + lret) == '\n')
2129 break;
2131 /* Line break code (may look strange, but it imitates windows). */
2132 if(lret < fit)
2133 fit = lret; /* this is not an off-by-one error */
2134 else if(fit < (length - sum)){
2135 if(*(stringdup + sum + fit) == ' ')
2136 while(*(stringdup + sum + fit) == ' ')
2137 fit++;
2138 else
2139 while(*(stringdup + sum + fit - 1) != ' '){
2140 fit--;
2142 if(*(stringdup + sum + fit) == '\t')
2143 break;
2145 if(fit == 0){
2146 fit = fitcpy;
2147 break;
2151 DrawTextW(graphics->hdc, stringdup + sum, min(length - sum, fit),
2152 &drawcoord, DT_NOCLIP | DT_EXPANDTABS);
2154 sum += fit + (lret < fitcpy ? 1 : 0);
2155 height += size.cy;
2157 if(height > nheight)
2158 break;
2160 /* Stop if this was a linewrap (but not if it was a linebreak). */
2161 if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
2162 break;
2165 GdipFree(stringdup);
2166 DeleteObject(rgn);
2167 DeleteObject(gdifont);
2169 RestoreDC(graphics->hdc, save_state);
2171 return Ok;
2174 GpStatus WINGDIPAPI GdipFillClosedCurve2(GpGraphics *graphics, GpBrush *brush,
2175 GDIPCONST GpPointF *points, INT count, REAL tension, GpFillMode fill)
2177 GpPath *path;
2178 GpStatus stat;
2180 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2181 count, tension, fill);
2183 if(!graphics || !brush || !points)
2184 return InvalidParameter;
2186 if(graphics->busy)
2187 return ObjectBusy;
2189 stat = GdipCreatePath(fill, &path);
2190 if(stat != Ok)
2191 return stat;
2193 stat = GdipAddPathClosedCurve2(path, points, count, tension);
2194 if(stat != Ok){
2195 GdipDeletePath(path);
2196 return stat;
2199 stat = GdipFillPath(graphics, brush, path);
2200 if(stat != Ok){
2201 GdipDeletePath(path);
2202 return stat;
2205 GdipDeletePath(path);
2207 return Ok;
2210 GpStatus WINGDIPAPI GdipFillClosedCurve2I(GpGraphics *graphics, GpBrush *brush,
2211 GDIPCONST GpPoint *points, INT count, REAL tension, GpFillMode fill)
2213 GpPointF *ptf;
2214 GpStatus stat;
2215 INT i;
2217 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2218 count, tension, fill);
2220 if(!points || count <= 0)
2221 return InvalidParameter;
2223 ptf = GdipAlloc(sizeof(GpPointF)*count);
2224 if(!ptf)
2225 return OutOfMemory;
2227 for(i = 0;i < count;i++){
2228 ptf[i].X = (REAL)points[i].X;
2229 ptf[i].Y = (REAL)points[i].Y;
2232 stat = GdipFillClosedCurve2(graphics, brush, ptf, count, tension, fill);
2234 GdipFree(ptf);
2236 return stat;
2239 GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x,
2240 REAL y, REAL width, REAL height)
2242 INT save_state;
2243 GpPointF ptf[2];
2244 POINT pti[2];
2246 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
2248 if(!graphics || !brush)
2249 return InvalidParameter;
2251 if(graphics->busy)
2252 return ObjectBusy;
2254 ptf[0].X = x;
2255 ptf[0].Y = y;
2256 ptf[1].X = x + width;
2257 ptf[1].Y = y + height;
2259 save_state = SaveDC(graphics->hdc);
2260 EndPath(graphics->hdc);
2261 SelectObject(graphics->hdc, brush->gdibrush);
2262 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
2264 transform_and_round_points(graphics, pti, ptf, 2);
2266 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
2268 RestoreDC(graphics->hdc, save_state);
2270 return Ok;
2273 GpStatus WINGDIPAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x,
2274 INT y, INT width, INT height)
2276 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
2278 return GdipFillEllipse(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2281 GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
2283 INT save_state;
2284 GpStatus retval;
2286 TRACE("(%p, %p, %p)\n", graphics, brush, path);
2288 if(!brush || !graphics || !path)
2289 return InvalidParameter;
2291 if(graphics->busy)
2292 return ObjectBusy;
2294 save_state = SaveDC(graphics->hdc);
2295 EndPath(graphics->hdc);
2296 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
2297 : WINDING));
2299 BeginPath(graphics->hdc);
2300 retval = draw_poly(graphics, NULL, path->pathdata.Points,
2301 path->pathdata.Types, path->pathdata.Count, FALSE);
2303 if(retval != Ok)
2304 goto end;
2306 EndPath(graphics->hdc);
2307 brush_fill_path(graphics, brush);
2309 retval = Ok;
2311 end:
2312 RestoreDC(graphics->hdc, save_state);
2314 return retval;
2317 GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
2318 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2320 INT save_state;
2322 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2323 graphics, brush, x, y, width, height, startAngle, sweepAngle);
2325 if(!graphics || !brush)
2326 return InvalidParameter;
2328 if(graphics->busy)
2329 return ObjectBusy;
2331 save_state = SaveDC(graphics->hdc);
2332 EndPath(graphics->hdc);
2333 SelectObject(graphics->hdc, brush->gdibrush);
2334 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
2336 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
2338 RestoreDC(graphics->hdc, save_state);
2340 return Ok;
2343 GpStatus WINGDIPAPI GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x,
2344 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2346 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2347 graphics, brush, x, y, width, height, startAngle, sweepAngle);
2349 return GdipFillPie(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2352 GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush,
2353 GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)
2355 INT save_state;
2356 GpPointF *ptf = NULL;
2357 POINT *pti = NULL;
2358 GpStatus retval = Ok;
2360 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
2362 if(!graphics || !brush || !points || !count)
2363 return InvalidParameter;
2365 if(graphics->busy)
2366 return ObjectBusy;
2368 ptf = GdipAlloc(count * sizeof(GpPointF));
2369 pti = GdipAlloc(count * sizeof(POINT));
2370 if(!ptf || !pti){
2371 retval = OutOfMemory;
2372 goto end;
2375 memcpy(ptf, points, count * sizeof(GpPointF));
2377 save_state = SaveDC(graphics->hdc);
2378 EndPath(graphics->hdc);
2379 SelectObject(graphics->hdc, brush->gdibrush);
2380 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
2381 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
2382 : WINDING));
2384 transform_and_round_points(graphics, pti, ptf, count);
2385 Polygon(graphics->hdc, pti, count);
2387 RestoreDC(graphics->hdc, save_state);
2389 end:
2390 GdipFree(ptf);
2391 GdipFree(pti);
2393 return retval;
2396 GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
2397 GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
2399 INT save_state, i;
2400 GpPointF *ptf = NULL;
2401 POINT *pti = NULL;
2402 GpStatus retval = Ok;
2404 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
2406 if(!graphics || !brush || !points || !count)
2407 return InvalidParameter;
2409 if(graphics->busy)
2410 return ObjectBusy;
2412 ptf = GdipAlloc(count * sizeof(GpPointF));
2413 pti = GdipAlloc(count * sizeof(POINT));
2414 if(!ptf || !pti){
2415 retval = OutOfMemory;
2416 goto end;
2419 for(i = 0; i < count; i ++){
2420 ptf[i].X = (REAL) points[i].X;
2421 ptf[i].Y = (REAL) points[i].Y;
2424 save_state = SaveDC(graphics->hdc);
2425 EndPath(graphics->hdc);
2426 SelectObject(graphics->hdc, brush->gdibrush);
2427 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
2428 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
2429 : WINDING));
2431 transform_and_round_points(graphics, pti, ptf, count);
2432 Polygon(graphics->hdc, pti, count);
2434 RestoreDC(graphics->hdc, save_state);
2436 end:
2437 GdipFree(ptf);
2438 GdipFree(pti);
2440 return retval;
2443 GpStatus WINGDIPAPI GdipFillPolygon2(GpGraphics *graphics, GpBrush *brush,
2444 GDIPCONST GpPointF *points, INT count)
2446 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
2448 return GdipFillPolygon(graphics, brush, points, count, FillModeAlternate);
2451 GpStatus WINGDIPAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush,
2452 GDIPCONST GpPoint *points, INT count)
2454 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
2456 return GdipFillPolygonI(graphics, brush, points, count, FillModeAlternate);
2459 GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics *graphics, GpBrush *brush,
2460 REAL x, REAL y, REAL width, REAL height)
2462 INT save_state;
2463 GpPointF ptf[4];
2464 POINT pti[4];
2466 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
2468 if(!graphics || !brush)
2469 return InvalidParameter;
2471 if(graphics->busy)
2472 return ObjectBusy;
2474 ptf[0].X = x;
2475 ptf[0].Y = y;
2476 ptf[1].X = x + width;
2477 ptf[1].Y = y;
2478 ptf[2].X = x + width;
2479 ptf[2].Y = y + height;
2480 ptf[3].X = x;
2481 ptf[3].Y = y + height;
2483 save_state = SaveDC(graphics->hdc);
2484 EndPath(graphics->hdc);
2486 transform_and_round_points(graphics, pti, ptf, 4);
2488 BeginPath(graphics->hdc);
2489 Polygon(graphics->hdc, pti, 4);
2490 EndPath(graphics->hdc);
2492 brush_fill_path(graphics, brush);
2494 RestoreDC(graphics->hdc, save_state);
2496 return Ok;
2499 GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush,
2500 INT x, INT y, INT width, INT height)
2502 INT save_state;
2503 GpPointF ptf[4];
2504 POINT pti[4];
2506 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
2508 if(!graphics || !brush)
2509 return InvalidParameter;
2511 if(graphics->busy)
2512 return ObjectBusy;
2514 ptf[0].X = x;
2515 ptf[0].Y = y;
2516 ptf[1].X = x + width;
2517 ptf[1].Y = y;
2518 ptf[2].X = x + width;
2519 ptf[2].Y = y + height;
2520 ptf[3].X = x;
2521 ptf[3].Y = y + height;
2523 save_state = SaveDC(graphics->hdc);
2524 EndPath(graphics->hdc);
2525 SelectObject(graphics->hdc, brush->gdibrush);
2526 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
2528 transform_and_round_points(graphics, pti, ptf, 4);
2530 Polygon(graphics->hdc, pti, 4);
2532 RestoreDC(graphics->hdc, save_state);
2534 return Ok;
2537 GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRectF *rects,
2538 INT count)
2540 GpStatus ret;
2541 INT i;
2543 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
2545 if(!rects)
2546 return InvalidParameter;
2548 for(i = 0; i < count; i++){
2549 ret = GdipFillRectangle(graphics, brush, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
2550 if(ret != Ok) return ret;
2553 return Ok;
2556 GpStatus WINGDIPAPI GdipFillRectanglesI(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRect *rects,
2557 INT count)
2559 GpRectF *rectsF;
2560 GpStatus ret;
2561 INT i;
2563 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
2565 if(!rects || count <= 0)
2566 return InvalidParameter;
2568 rectsF = GdipAlloc(sizeof(GpRectF)*count);
2569 if(!rectsF)
2570 return OutOfMemory;
2572 for(i = 0; i < count; i++){
2573 rectsF[i].X = (REAL)rects[i].X;
2574 rectsF[i].Y = (REAL)rects[i].Y;
2575 rectsF[i].X = (REAL)rects[i].Width;
2576 rectsF[i].Height = (REAL)rects[i].Height;
2579 ret = GdipFillRectangles(graphics,brush,rectsF,count);
2580 GdipFree(rectsF);
2582 return ret;
2585 /*****************************************************************************
2586 * GdipFillRegion [GDIPLUS.@]
2588 GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
2589 GpRegion* region)
2591 INT save_state;
2592 GpStatus status;
2593 HRGN hrgn;
2595 TRACE("(%p, %p, %p)\n", graphics, brush, region);
2597 if (!(graphics && brush && region))
2598 return InvalidParameter;
2600 if(graphics->busy)
2601 return ObjectBusy;
2603 status = GdipGetRegionHRgn(region, graphics, &hrgn);
2604 if(status != Ok)
2605 return status;
2607 save_state = SaveDC(graphics->hdc);
2608 EndPath(graphics->hdc);
2609 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
2611 FillRgn(graphics->hdc, hrgn, brush->gdibrush);
2613 RestoreDC(graphics->hdc, save_state);
2615 DeleteObject(hrgn);
2617 return Ok;
2620 GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention)
2622 static int calls;
2624 if(!graphics)
2625 return InvalidParameter;
2627 if(graphics->busy)
2628 return ObjectBusy;
2630 if(!(calls++))
2631 FIXME("not implemented\n");
2633 return NotImplemented;
2636 /*****************************************************************************
2637 * GdipGetClipBounds [GDIPLUS.@]
2639 GpStatus WINGDIPAPI GdipGetClipBounds(GpGraphics *graphics, GpRectF *rect)
2641 TRACE("(%p, %p)\n", graphics, rect);
2643 if(!graphics)
2644 return InvalidParameter;
2646 if(graphics->busy)
2647 return ObjectBusy;
2649 return GdipGetRegionBounds(graphics->clip, graphics, rect);
2652 /*****************************************************************************
2653 * GdipGetClipBoundsI [GDIPLUS.@]
2655 GpStatus WINGDIPAPI GdipGetClipBoundsI(GpGraphics *graphics, GpRect *rect)
2657 TRACE("(%p, %p)\n", graphics, rect);
2659 if(!graphics)
2660 return InvalidParameter;
2662 if(graphics->busy)
2663 return ObjectBusy;
2665 return GdipGetRegionBoundsI(graphics->clip, graphics, rect);
2668 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
2669 GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics,
2670 CompositingMode *mode)
2672 TRACE("(%p, %p)\n", graphics, mode);
2674 if(!graphics || !mode)
2675 return InvalidParameter;
2677 if(graphics->busy)
2678 return ObjectBusy;
2680 *mode = graphics->compmode;
2682 return Ok;
2685 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
2686 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
2687 CompositingQuality *quality)
2689 TRACE("(%p, %p)\n", graphics, quality);
2691 if(!graphics || !quality)
2692 return InvalidParameter;
2694 if(graphics->busy)
2695 return ObjectBusy;
2697 *quality = graphics->compqual;
2699 return Ok;
2702 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
2703 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
2704 InterpolationMode *mode)
2706 TRACE("(%p, %p)\n", graphics, mode);
2708 if(!graphics || !mode)
2709 return InvalidParameter;
2711 if(graphics->busy)
2712 return ObjectBusy;
2714 *mode = graphics->interpolation;
2716 return Ok;
2719 GpStatus WINGDIPAPI GdipGetNearestColor(GpGraphics *graphics, ARGB* argb)
2721 if(!graphics || !argb)
2722 return InvalidParameter;
2724 if(graphics->busy)
2725 return ObjectBusy;
2727 FIXME("(%p, %p): stub\n", graphics, argb);
2729 return NotImplemented;
2732 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
2734 TRACE("(%p, %p)\n", graphics, scale);
2736 if(!graphics || !scale)
2737 return InvalidParameter;
2739 if(graphics->busy)
2740 return ObjectBusy;
2742 *scale = graphics->scale;
2744 return Ok;
2747 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
2749 TRACE("(%p, %p)\n", graphics, unit);
2751 if(!graphics || !unit)
2752 return InvalidParameter;
2754 if(graphics->busy)
2755 return ObjectBusy;
2757 *unit = graphics->unit;
2759 return Ok;
2762 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
2763 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
2764 *mode)
2766 TRACE("(%p, %p)\n", graphics, mode);
2768 if(!graphics || !mode)
2769 return InvalidParameter;
2771 if(graphics->busy)
2772 return ObjectBusy;
2774 *mode = graphics->pixeloffset;
2776 return Ok;
2779 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
2780 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
2782 TRACE("(%p, %p)\n", graphics, mode);
2784 if(!graphics || !mode)
2785 return InvalidParameter;
2787 if(graphics->busy)
2788 return ObjectBusy;
2790 *mode = graphics->smoothing;
2792 return Ok;
2795 GpStatus WINGDIPAPI GdipGetTextContrast(GpGraphics *graphics, UINT *contrast)
2797 TRACE("(%p, %p)\n", graphics, contrast);
2799 if(!graphics || !contrast)
2800 return InvalidParameter;
2802 *contrast = graphics->textcontrast;
2804 return Ok;
2807 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
2808 GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics,
2809 TextRenderingHint *hint)
2811 TRACE("(%p, %p)\n", graphics, hint);
2813 if(!graphics || !hint)
2814 return InvalidParameter;
2816 if(graphics->busy)
2817 return ObjectBusy;
2819 *hint = graphics->texthint;
2821 return Ok;
2824 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
2826 TRACE("(%p, %p)\n", graphics, matrix);
2828 if(!graphics || !matrix)
2829 return InvalidParameter;
2831 if(graphics->busy)
2832 return ObjectBusy;
2834 *matrix = *graphics->worldtrans;
2835 return Ok;
2838 GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color)
2840 GpSolidFill *brush;
2841 GpStatus stat;
2842 RECT rect;
2844 TRACE("(%p, %x)\n", graphics, color);
2846 if(!graphics)
2847 return InvalidParameter;
2849 if(graphics->busy)
2850 return ObjectBusy;
2852 if((stat = GdipCreateSolidFill(color, &brush)) != Ok)
2853 return stat;
2855 if(graphics->hwnd){
2856 if(!GetWindowRect(graphics->hwnd, &rect)){
2857 GdipDeleteBrush((GpBrush*)brush);
2858 return GenericError;
2861 GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, (REAL)(rect.right - rect.left),
2862 (REAL)(rect.bottom - rect.top));
2864 else
2865 GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, (REAL)GetDeviceCaps(graphics->hdc, HORZRES),
2866 (REAL)GetDeviceCaps(graphics->hdc, VERTRES));
2868 GdipDeleteBrush((GpBrush*)brush);
2870 return Ok;
2873 GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics *graphics, BOOL *res)
2875 TRACE("(%p, %p)\n", graphics, res);
2877 if(!graphics || !res)
2878 return InvalidParameter;
2880 return GdipIsEmptyRegion(graphics->clip, graphics, res);
2883 GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics *graphics, REAL x, REAL y, BOOL *result)
2885 FIXME("(%p, %.2f, %.2f, %p) stub\n", graphics, x, y, result);
2887 if(!graphics || !result)
2888 return InvalidParameter;
2890 if(graphics->busy)
2891 return ObjectBusy;
2893 return NotImplemented;
2896 GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics *graphics, INT x, INT y, BOOL *result)
2898 FIXME("(%p, %d, %d, %p) stub\n", graphics, x, y, result);
2900 if(!graphics || !result)
2901 return InvalidParameter;
2903 if(graphics->busy)
2904 return ObjectBusy;
2906 return NotImplemented;
2909 GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,
2910 GDIPCONST WCHAR* string, INT length, GDIPCONST GpFont* font,
2911 GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat *stringFormat,
2912 INT regionCount, GpRegion** regions)
2914 if (!(graphics && string && font && layoutRect && stringFormat && regions))
2915 return InvalidParameter;
2917 FIXME("stub: %p %s %d %p %p %p %d %p\n", graphics, debugstr_w(string),
2918 length, font, layoutRect, stringFormat, regionCount, regions);
2920 return NotImplemented;
2923 /* Find the smallest rectangle that bounds the text when it is printed in rect
2924 * according to the format options listed in format. If rect has 0 width and
2925 * height, then just find the smallest rectangle that bounds the text when it's
2926 * printed at location (rect->X, rect-Y). */
2927 GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
2928 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
2929 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
2930 INT *codepointsfitted, INT *linesfilled)
2932 HFONT oldfont;
2933 WCHAR* stringdup;
2934 INT sum = 0, height = 0, fit, fitcpy, max_width = 0, i, j, lret, nwidth,
2935 nheight;
2936 SIZE size;
2938 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics,
2939 debugstr_wn(string, length), length, font, debugstr_rectf(rect), format,
2940 bounds, codepointsfitted, linesfilled);
2942 if(!graphics || !string || !font || !rect)
2943 return InvalidParameter;
2945 if(linesfilled) *linesfilled = 0;
2946 if(codepointsfitted) *codepointsfitted = 0;
2948 if(format)
2949 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
2951 if(length == -1) length = lstrlenW(string);
2953 stringdup = GdipAlloc((length + 1) * sizeof(WCHAR));
2954 if(!stringdup) return OutOfMemory;
2956 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
2957 nwidth = roundr(rect->Width);
2958 nheight = roundr(rect->Height);
2960 if((nwidth == 0) && (nheight == 0))
2961 nwidth = nheight = INT_MAX;
2963 for(i = 0, j = 0; i < length; i++){
2964 if(!isprintW(string[i]) && (string[i] != '\n'))
2965 continue;
2967 stringdup[j] = string[i];
2968 j++;
2971 stringdup[j] = 0;
2972 length = j;
2974 while(sum < length){
2975 GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum,
2976 nwidth, &fit, NULL, &size);
2977 fitcpy = fit;
2979 if(fit == 0)
2980 break;
2982 for(lret = 0; lret < fit; lret++)
2983 if(*(stringdup + sum + lret) == '\n')
2984 break;
2986 /* Line break code (may look strange, but it imitates windows). */
2987 if(lret < fit)
2988 fit = lret; /* this is not an off-by-one error */
2989 else if(fit < (length - sum)){
2990 if(*(stringdup + sum + fit) == ' ')
2991 while(*(stringdup + sum + fit) == ' ')
2992 fit++;
2993 else
2994 while(*(stringdup + sum + fit - 1) != ' '){
2995 fit--;
2997 if(*(stringdup + sum + fit) == '\t')
2998 break;
3000 if(fit == 0){
3001 fit = fitcpy;
3002 break;
3007 GetTextExtentExPointW(graphics->hdc, stringdup + sum, fit,
3008 nwidth, &j, NULL, &size);
3010 sum += fit + (lret < fitcpy ? 1 : 0);
3011 if(codepointsfitted) *codepointsfitted = sum;
3013 height += size.cy;
3014 if(linesfilled) *linesfilled += size.cy;
3015 max_width = max(max_width, size.cx);
3017 if(height > nheight)
3018 break;
3020 /* Stop if this was a linewrap (but not if it was a linebreak). */
3021 if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
3022 break;
3025 bounds->X = rect->X;
3026 bounds->Y = rect->Y;
3027 bounds->Width = (REAL)max_width;
3028 bounds->Height = (REAL) min(height, nheight);
3030 GdipFree(stringdup);
3031 DeleteObject(SelectObject(graphics->hdc, oldfont));
3033 return Ok;
3036 GpStatus WINGDIPAPI GdipResetClip(GpGraphics *graphics)
3038 TRACE("(%p)\n", graphics);
3040 if(!graphics)
3041 return InvalidParameter;
3043 if(graphics->busy)
3044 return ObjectBusy;
3046 return GdipSetInfinite(graphics->clip);
3049 GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics)
3051 TRACE("(%p)\n", graphics);
3053 if(!graphics)
3054 return InvalidParameter;
3056 if(graphics->busy)
3057 return ObjectBusy;
3059 graphics->worldtrans->matrix[0] = 1.0;
3060 graphics->worldtrans->matrix[1] = 0.0;
3061 graphics->worldtrans->matrix[2] = 0.0;
3062 graphics->worldtrans->matrix[3] = 1.0;
3063 graphics->worldtrans->matrix[4] = 0.0;
3064 graphics->worldtrans->matrix[5] = 0.0;
3066 return Ok;
3069 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
3071 static int calls;
3073 if(!graphics)
3074 return InvalidParameter;
3076 if(!(calls++))
3077 FIXME("graphics state not implemented\n");
3079 return Ok;
3082 GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
3083 GpMatrixOrder order)
3085 TRACE("(%p, %.2f, %d)\n", graphics, angle, order);
3087 if(!graphics)
3088 return InvalidParameter;
3090 if(graphics->busy)
3091 return ObjectBusy;
3093 return GdipRotateMatrix(graphics->worldtrans, angle, order);
3096 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
3098 static int calls;
3100 if(!graphics || !state)
3101 return InvalidParameter;
3103 if(!(calls++))
3104 FIXME("graphics state not implemented\n");
3106 *state = 0xdeadbeef;
3107 return Ok;
3110 GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics *graphics, GraphicsContainer *state)
3112 FIXME("(%p, %p)\n", graphics, state);
3114 if(!graphics || !state)
3115 return InvalidParameter;
3117 *state = 0xdeadbeef;
3118 return Ok;
3121 GpStatus WINGDIPAPI GdipEndContainer(GpGraphics *graphics, GraphicsState state)
3123 FIXME("(%p, 0x%x)\n", graphics, state);
3125 if(!graphics || !state)
3126 return InvalidParameter;
3128 return Ok;
3131 GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
3132 REAL sy, GpMatrixOrder order)
3134 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, sx, sy, order);
3136 if(!graphics)
3137 return InvalidParameter;
3139 if(graphics->busy)
3140 return ObjectBusy;
3142 return GdipScaleMatrix(graphics->worldtrans, sx, sy, order);
3145 GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics *graphics, GpGraphics *srcgraphics,
3146 CombineMode mode)
3148 TRACE("(%p, %p, %d)\n", graphics, srcgraphics, mode);
3150 if(!graphics || !srcgraphics)
3151 return InvalidParameter;
3153 return GdipCombineRegionRegion(graphics->clip, srcgraphics->clip, mode);
3156 GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
3157 CompositingMode mode)
3159 TRACE("(%p, %d)\n", graphics, mode);
3161 if(!graphics)
3162 return InvalidParameter;
3164 if(graphics->busy)
3165 return ObjectBusy;
3167 graphics->compmode = mode;
3169 return Ok;
3172 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
3173 CompositingQuality quality)
3175 TRACE("(%p, %d)\n", graphics, quality);
3177 if(!graphics)
3178 return InvalidParameter;
3180 if(graphics->busy)
3181 return ObjectBusy;
3183 graphics->compqual = quality;
3185 return Ok;
3188 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
3189 InterpolationMode mode)
3191 TRACE("(%p, %d)\n", graphics, mode);
3193 if(!graphics)
3194 return InvalidParameter;
3196 if(graphics->busy)
3197 return ObjectBusy;
3199 graphics->interpolation = mode;
3201 return Ok;
3204 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
3206 TRACE("(%p, %.2f)\n", graphics, scale);
3208 if(!graphics || (scale <= 0.0))
3209 return InvalidParameter;
3211 if(graphics->busy)
3212 return ObjectBusy;
3214 graphics->scale = scale;
3216 return Ok;
3219 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
3221 TRACE("(%p, %d)\n", graphics, unit);
3223 if(!graphics)
3224 return InvalidParameter;
3226 if(graphics->busy)
3227 return ObjectBusy;
3229 if(unit == UnitWorld)
3230 return InvalidParameter;
3232 graphics->unit = unit;
3234 return Ok;
3237 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
3238 mode)
3240 TRACE("(%p, %d)\n", graphics, mode);
3242 if(!graphics)
3243 return InvalidParameter;
3245 if(graphics->busy)
3246 return ObjectBusy;
3248 graphics->pixeloffset = mode;
3250 return Ok;
3253 GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics *graphics, INT x, INT y)
3255 static int calls;
3257 TRACE("(%p,%i,%i)\n", graphics, x, y);
3259 if (!(calls++))
3260 FIXME("not implemented\n");
3262 return NotImplemented;
3265 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
3267 TRACE("(%p, %d)\n", graphics, mode);
3269 if(!graphics)
3270 return InvalidParameter;
3272 if(graphics->busy)
3273 return ObjectBusy;
3275 graphics->smoothing = mode;
3277 return Ok;
3280 GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics *graphics, UINT contrast)
3282 TRACE("(%p, %d)\n", graphics, contrast);
3284 if(!graphics)
3285 return InvalidParameter;
3287 graphics->textcontrast = contrast;
3289 return Ok;
3292 GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
3293 TextRenderingHint hint)
3295 TRACE("(%p, %d)\n", graphics, hint);
3297 if(!graphics)
3298 return InvalidParameter;
3300 if(graphics->busy)
3301 return ObjectBusy;
3303 graphics->texthint = hint;
3305 return Ok;
3308 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
3310 TRACE("(%p, %p)\n", graphics, matrix);
3312 if(!graphics || !matrix)
3313 return InvalidParameter;
3315 if(graphics->busy)
3316 return ObjectBusy;
3318 GdipDeleteMatrix(graphics->worldtrans);
3319 return GdipCloneMatrix(matrix, &graphics->worldtrans);
3322 GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
3323 REAL dy, GpMatrixOrder order)
3325 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, dx, dy, order);
3327 if(!graphics)
3328 return InvalidParameter;
3330 if(graphics->busy)
3331 return ObjectBusy;
3333 return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order);
3336 /*****************************************************************************
3337 * GdipSetClipHrgn [GDIPLUS.@]
3339 GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics *graphics, HRGN hrgn, CombineMode mode)
3341 GpRegion *region;
3342 GpStatus status;
3344 TRACE("(%p, %p, %d)\n", graphics, hrgn, mode);
3346 if(!graphics)
3347 return InvalidParameter;
3349 status = GdipCreateRegionHrgn(hrgn, &region);
3350 if(status != Ok)
3351 return status;
3353 status = GdipSetClipRegion(graphics, region, mode);
3355 GdipDeleteRegion(region);
3356 return status;
3359 GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics *graphics, GpPath *path, CombineMode mode)
3361 TRACE("(%p, %p, %d)\n", graphics, path, mode);
3363 if(!graphics)
3364 return InvalidParameter;
3366 if(graphics->busy)
3367 return ObjectBusy;
3369 return GdipCombineRegionPath(graphics->clip, path, mode);
3372 GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y,
3373 REAL width, REAL height,
3374 CombineMode mode)
3376 GpRectF rect;
3378 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics, x, y, width, height, mode);
3380 if(!graphics)
3381 return InvalidParameter;
3383 if(graphics->busy)
3384 return ObjectBusy;
3386 rect.X = x;
3387 rect.Y = y;
3388 rect.Width = width;
3389 rect.Height = height;
3391 return GdipCombineRegionRect(graphics->clip, &rect, mode);
3394 GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y,
3395 INT width, INT height,
3396 CombineMode mode)
3398 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics, x, y, width, height, mode);
3400 if(!graphics)
3401 return InvalidParameter;
3403 if(graphics->busy)
3404 return ObjectBusy;
3406 return GdipSetClipRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, mode);
3409 GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
3410 CombineMode mode)
3412 TRACE("(%p, %p, %d)\n", graphics, region, mode);
3414 if(!graphics || !region)
3415 return InvalidParameter;
3417 if(graphics->busy)
3418 return ObjectBusy;
3420 return GdipCombineRegionRegion(graphics->clip, region, mode);
3423 GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile *metafile,
3424 UINT limitDpi)
3426 static int calls;
3428 if(!(calls++))
3429 FIXME("not implemented\n");
3431 return NotImplemented;
3434 GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points,
3435 INT count)
3437 INT save_state;
3438 POINT *pti;
3440 TRACE("(%p, %p, %d)\n", graphics, points, count);
3442 if(!graphics || !pen || count<=0)
3443 return InvalidParameter;
3445 if(graphics->busy)
3446 return ObjectBusy;
3448 pti = GdipAlloc(sizeof(POINT) * count);
3450 save_state = prepare_dc(graphics, pen);
3451 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
3453 transform_and_round_points(graphics, pti, (GpPointF*)points, count);
3454 Polygon(graphics->hdc, pti, count);
3456 restore_dc(graphics, save_state);
3457 GdipFree(pti);
3459 return Ok;
3462 GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points,
3463 INT count)
3465 GpStatus ret;
3466 GpPointF *ptf;
3467 INT i;
3469 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
3471 if(count<=0) return InvalidParameter;
3472 ptf = GdipAlloc(sizeof(GpPointF) * count);
3474 for(i = 0;i < count; i++){
3475 ptf[i].X = (REAL)points[i].X;
3476 ptf[i].Y = (REAL)points[i].Y;
3479 ret = GdipDrawPolygon(graphics,pen,ptf,count);
3480 GdipFree(ptf);
3482 return ret;
3485 GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
3487 TRACE("(%p, %p)\n", graphics, dpi);
3489 if(!graphics || !dpi)
3490 return InvalidParameter;
3492 if(graphics->busy)
3493 return ObjectBusy;
3495 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
3497 return Ok;
3500 GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
3502 TRACE("(%p, %p)\n", graphics, dpi);
3504 if(!graphics || !dpi)
3505 return InvalidParameter;
3507 if(graphics->busy)
3508 return ObjectBusy;
3510 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
3512 return Ok;
3515 GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix,
3516 GpMatrixOrder order)
3518 GpMatrix m;
3519 GpStatus ret;
3521 TRACE("(%p, %p, %d)\n", graphics, matrix, order);
3523 if(!graphics || !matrix)
3524 return InvalidParameter;
3526 if(graphics->busy)
3527 return ObjectBusy;
3529 m = *(graphics->worldtrans);
3531 ret = GdipMultiplyMatrix(&m, matrix, order);
3532 if(ret == Ok)
3533 *(graphics->worldtrans) = m;
3535 return ret;
3538 GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
3540 TRACE("(%p, %p)\n", graphics, hdc);
3542 if(!graphics || !hdc)
3543 return InvalidParameter;
3545 if(graphics->busy)
3546 return ObjectBusy;
3548 *hdc = graphics->hdc;
3549 graphics->busy = TRUE;
3551 return Ok;
3554 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
3556 TRACE("(%p, %p)\n", graphics, hdc);
3558 if(!graphics)
3559 return InvalidParameter;
3561 if(graphics->hdc != hdc || !(graphics->busy))
3562 return InvalidParameter;
3564 graphics->busy = FALSE;
3566 return Ok;
3569 GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
3571 GpRegion *clip;
3572 GpStatus status;
3574 TRACE("(%p, %p)\n", graphics, region);
3576 if(!graphics || !region)
3577 return InvalidParameter;
3579 if(graphics->busy)
3580 return ObjectBusy;
3582 if((status = GdipCloneRegion(graphics->clip, &clip)) != Ok)
3583 return status;
3585 /* free everything except root node and header */
3586 delete_element(&region->node);
3587 memcpy(region, clip, sizeof(GpRegion));
3589 return Ok;
3592 GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space,
3593 GpCoordinateSpace src_space, GpPointF *points, INT count)
3595 if(!graphics || !points || count <= 0)
3596 return InvalidParameter;
3598 if(graphics->busy)
3599 return ObjectBusy;
3601 FIXME("(%p, %d, %d, %p, %d): stub\n", graphics, dst_space, src_space, points, count);
3603 return NotImplemented;
3606 GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space,
3607 GpCoordinateSpace src_space, GpPoint *points, INT count)
3609 FIXME("(%p, %d, %d, %p, %d): stub\n", graphics, dst_space, src_space, points, count);
3611 return NotImplemented;
3614 HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void)
3616 FIXME("\n");
3618 return NULL;
3621 /*****************************************************************************
3622 * GdipTranslateClip [GDIPLUS.@]
3624 GpStatus WINGDIPAPI GdipTranslateClip(GpGraphics *graphics, REAL dx, REAL dy)
3626 TRACE("(%p, %.2f, %.2f)\n", graphics, dx, dy);
3628 if(!graphics)
3629 return InvalidParameter;
3631 if(graphics->busy)
3632 return ObjectBusy;
3634 return GdipTranslateRegion(graphics->clip, dx, dy);
3637 /*****************************************************************************
3638 * GdipTranslateClipI [GDIPLUS.@]
3640 GpStatus WINGDIPAPI GdipTranslateClipI(GpGraphics *graphics, INT dx, INT dy)
3642 TRACE("(%p, %d, %d)\n", graphics, dx, dy);
3644 if(!graphics)
3645 return InvalidParameter;
3647 if(graphics->busy)
3648 return ObjectBusy;
3650 return GdipTranslateRegion(graphics->clip, (REAL)dx, (REAL)dy);