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
27 #include "wine/unicode.h"
39 #include "gdiplus_private.h"
40 #include "wine/debug.h"
41 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
45 /* looks-right constants */
46 #define ANCHOR_WIDTH (2.0)
47 #define MAX_ITERS (50)
49 /* Converts angle (in degrees) to x/y coordinates */
50 static void deg2xy(REAL angle, REAL x_0, REAL y_0, REAL *x, REAL *y)
52 REAL radAngle, hypotenuse;
54 radAngle = deg2rad(angle);
55 hypotenuse = 50.0; /* arbitrary */
57 *x = x_0 + cos(radAngle) * hypotenuse;
58 *y = y_0 + sin(radAngle) * hypotenuse;
61 /* Converts from gdiplus path point type to gdi path point type. */
62 static BYTE convert_path_point_type(BYTE type)
66 switch(type & PathPointTypePathTypeMask){
67 case PathPointTypeBezier:
70 case PathPointTypeLine:
73 case PathPointTypeStart:
77 ERR("Bad point type\n");
81 if(type & PathPointTypeCloseSubpath)
82 ret |= PT_CLOSEFIGURE;
87 static REAL graphics_res(GpGraphics *graphics)
89 if (graphics->image) return graphics->image->xres;
90 else return (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
93 static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
97 INT save_state, i, numdashes;
99 DWORD dash_array[MAX_DASHLEN];
103 FIXME("graphics object has no HDC\n");
106 save_state = SaveDC(graphics->hdc);
108 EndPath(graphics->hdc);
110 if(pen->unit == UnitPixel){
114 /* Get an estimate for the amount the pen width is affected by the world
115 * transform. (This is similar to what some of the wine drivers do.) */
120 GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
121 width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
122 (pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
124 width *= pen->width * convert_unit(graphics_res(graphics),
125 pen->unit == UnitWorld ? graphics->unit : pen->unit);
128 if(pen->dash == DashStyleCustom){
129 numdashes = min(pen->numdashes, MAX_DASHLEN);
131 TRACE("dashes are: ");
132 for(i = 0; i < numdashes; i++){
133 dash_array[i] = roundr(width * pen->dashes[i]);
134 TRACE("%d, ", dash_array[i]);
136 TRACE("\n and the pen style is %x\n", pen->style);
138 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb,
139 numdashes, dash_array);
142 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, 0, NULL);
144 SelectObject(graphics->hdc, gdipen);
149 static void restore_dc(GpGraphics *graphics, INT state)
151 DeleteObject(SelectObject(graphics->hdc, GetStockObject(NULL_PEN)));
152 RestoreDC(graphics->hdc, state);
155 /* This helper applies all the changes that the points listed in ptf need in
156 * order to be drawn on the device context. In the end, this should include at
158 * -scaling by page unit
159 * -applying world transformation
160 * -converting from float to int
161 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
162 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
163 * gdi to draw, and these functions would irreparably mess with line widths.
165 static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
166 GpPointF *ptf, INT count)
172 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
174 /* apply page scale */
175 if(graphics->unit != UnitDisplay)
176 unitscale *= graphics->scale;
178 GdipCloneMatrix(graphics->worldtrans, &matrix);
179 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
180 GdipTransformMatrixPoints(matrix, ptf, count);
181 GdipDeleteMatrix(matrix);
183 for(i = 0; i < count; i++){
184 pti[i].x = roundr(ptf[i].X);
185 pti[i].y = roundr(ptf[i].Y);
189 /* Draw non-premultiplied ARGB data to the given graphics object */
190 static GpStatus alpha_blend_pixels(GpGraphics *graphics, INT dst_x, INT dst_y,
191 const BYTE *src, INT src_width, INT src_height, INT src_stride)
193 if (graphics->image && graphics->image->type == ImageTypeBitmap)
195 GpBitmap *dst_bitmap = (GpBitmap*)graphics->image;
198 for (x=0; x<src_width; x++)
200 for (y=0; y<src_height; y++)
202 ARGB dst_color, src_color;
203 GdipBitmapGetPixel(dst_bitmap, x+dst_x, y+dst_y, &dst_color);
204 src_color = ((ARGB*)(src + src_stride * y))[x];
205 GdipBitmapSetPixel(dst_bitmap, x+dst_x, y+dst_y, color_over(dst_color, src_color));
214 HBITMAP hbitmap, old_hbm=NULL;
215 BITMAPINFOHEADER bih;
219 hdc = CreateCompatibleDC(0);
221 bih.biSize = sizeof(BITMAPINFOHEADER);
222 bih.biWidth = src_width;
223 bih.biHeight = -src_height;
226 bih.biCompression = BI_RGB;
228 bih.biXPelsPerMeter = 0;
229 bih.biYPelsPerMeter = 0;
231 bih.biClrImportant = 0;
233 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
234 (void**)&temp_bits, NULL, 0);
236 convert_32bppARGB_to_32bppPARGB(src_width, src_height, temp_bits,
237 4 * src_width, src, src_stride);
239 old_hbm = SelectObject(hdc, hbitmap);
241 bf.BlendOp = AC_SRC_OVER;
243 bf.SourceConstantAlpha = 255;
244 bf.AlphaFormat = AC_SRC_ALPHA;
246 GdiAlphaBlend(graphics->hdc, dst_x, dst_y, src_width, src_height,
247 hdc, 0, 0, src_width, src_height, bf);
249 SelectObject(hdc, old_hbm);
251 DeleteObject(hbitmap);
257 static ARGB blend_colors(ARGB start, ARGB end, REAL position)
261 for (i=0xff; i<=0xff0000; i = i << 8)
262 result |= (int)((start&i)*(1.0f - position)+(end&i)*(position))&i;
266 static ARGB blend_line_gradient(GpLineGradient* brush, REAL position)
270 /* clamp to between 0.0 and 1.0, using the wrap mode */
271 if (brush->wrap == WrapModeTile)
273 position = fmodf(position, 1.0f);
274 if (position < 0.0f) position += 1.0f;
276 else /* WrapModeFlip* */
278 position = fmodf(position, 2.0f);
279 if (position < 0.0f) position += 2.0f;
280 if (position > 1.0f) position = 2.0f - position;
283 if (brush->blendcount == 1)
288 REAL left_blendpos, left_blendfac, right_blendpos, right_blendfac;
291 /* locate the blend positions surrounding this position */
292 while (position > brush->blendpos[i])
295 /* interpolate between the blend positions */
296 left_blendpos = brush->blendpos[i-1];
297 left_blendfac = brush->blendfac[i-1];
298 right_blendpos = brush->blendpos[i];
299 right_blendfac = brush->blendfac[i];
300 range = right_blendpos - left_blendpos;
301 blendfac = (left_blendfac * (right_blendpos - position) +
302 right_blendfac * (position - left_blendpos)) / range;
305 if (brush->pblendcount == 0)
306 return blend_colors(brush->startcolor, brush->endcolor, blendfac);
310 ARGB left_blendcolor, right_blendcolor;
311 REAL left_blendpos, right_blendpos;
313 /* locate the blend colors surrounding this position */
314 while (blendfac > brush->pblendpos[i])
317 /* interpolate between the blend colors */
318 left_blendpos = brush->pblendpos[i-1];
319 left_blendcolor = brush->pblendcolor[i-1];
320 right_blendpos = brush->pblendpos[i];
321 right_blendcolor = brush->pblendcolor[i];
322 blendfac = (blendfac - left_blendpos) / (right_blendpos - left_blendpos);
323 return blend_colors(left_blendcolor, right_blendcolor, blendfac);
327 static void brush_fill_path(GpGraphics *graphics, GpBrush* brush)
331 case BrushTypeLinearGradient:
333 GpLineGradient *line = (GpLineGradient*)brush;
336 SelectClipPath(graphics->hdc, RGN_AND);
337 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
339 GpPointF endpointsf[2];
343 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
345 endpointsf[0] = line->startpoint;
346 endpointsf[1] = line->endpoint;
347 transform_and_round_points(graphics, endpointsi, endpointsf, 2);
349 if (abs(endpointsi[0].x-endpointsi[1].x) > abs(endpointsi[0].y-endpointsi[1].y))
351 /* vertical-ish gradient */
352 int startx, endx; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
353 int startbottomx; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
356 HBRUSH hbrush, hprevbrush;
357 int leftx, rightx; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
359 int tilt; /* horizontal distance covered by a gradient line */
361 startx = roundr((rc.top - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X);
362 endx = roundr((rc.top - endpointsf[1].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[1].X);
363 width = endx - startx;
364 startbottomx = roundr((rc.bottom - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X);
365 tilt = startx - startbottomx;
367 if (startx >= startbottomx)
370 rightx = rc.right + tilt;
374 leftx = rc.left + tilt;
378 poly[0].y = rc.bottom;
381 poly[3].y = rc.bottom;
383 for (x=leftx; x<=rightx; x++)
385 ARGB argb = blend_line_gradient(line, (x-startx)/(REAL)width);
386 col = ARGB2COLORREF(argb);
387 hbrush = CreateSolidBrush(col);
388 hprevbrush = SelectObject(graphics->hdc, hbrush);
389 poly[0].x = x - tilt - 1;
392 poly[3].x = x - tilt;
393 Polygon(graphics->hdc, poly, 4);
394 SelectObject(graphics->hdc, hprevbrush);
395 DeleteObject(hbrush);
398 else if (endpointsi[0].y != endpointsi[1].y)
400 /* horizontal-ish gradient */
401 int starty, endy; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
402 int startrighty; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
405 HBRUSH hbrush, hprevbrush;
406 int topy, bottomy; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
408 int tilt; /* vertical distance covered by a gradient line */
410 starty = roundr((rc.left - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y);
411 endy = roundr((rc.left - endpointsf[1].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[1].Y);
412 height = endy - starty;
413 startrighty = roundr((rc.right - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y);
414 tilt = starty - startrighty;
416 if (starty >= startrighty)
419 bottomy = rc.bottom + tilt;
423 topy = rc.top + tilt;
427 poly[0].x = rc.right;
430 poly[3].x = rc.right;
432 for (y=topy; y<=bottomy; y++)
434 ARGB argb = blend_line_gradient(line, (y-starty)/(REAL)height);
435 col = ARGB2COLORREF(argb);
436 hbrush = CreateSolidBrush(col);
437 hprevbrush = SelectObject(graphics->hdc, hbrush);
438 poly[0].y = y - tilt - 1;
441 poly[3].y = y - tilt;
442 Polygon(graphics->hdc, poly, 4);
443 SelectObject(graphics->hdc, hprevbrush);
444 DeleteObject(hbrush);
447 /* else startpoint == endpoint */
451 case BrushTypeSolidColor:
453 GpSolidFill *fill = (GpSolidFill*)brush;
457 /* partially transparent fill */
459 SelectClipPath(graphics->hdc, RGN_AND);
460 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
462 HDC hdc = CreateCompatibleDC(NULL);
468 oldbmp = SelectObject(hdc, fill->bmp);
470 bf.BlendOp = AC_SRC_OVER;
472 bf.SourceConstantAlpha = 255;
473 bf.AlphaFormat = AC_SRC_ALPHA;
475 GdiAlphaBlend(graphics->hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdc, 0, 0, 1, 1, bf);
477 SelectObject(hdc, oldbmp);
483 /* else fall through */
486 SelectObject(graphics->hdc, brush->gdibrush);
487 FillPath(graphics->hdc);
492 /* GdipDrawPie/GdipFillPie helper function */
493 static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width,
494 REAL height, REAL startAngle, REAL sweepAngle)
501 ptf[1].X = x + width;
502 ptf[1].Y = y + height;
504 deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y);
505 deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y);
507 transform_and_round_points(graphics, pti, ptf, 4);
509 Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x,
510 pti[2].y, pti[3].x, pti[3].y);
513 /* Draws the linecap the specified color and size on the hdc. The linecap is in
514 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
515 * should not be called on an hdc that has a path you care about. */
516 static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
517 const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
519 HGDIOBJ oldbrush = NULL, oldpen = NULL;
520 GpMatrix *matrix = NULL;
523 PointF ptf[4], *custptf = NULL;
524 POINT pt[4], *custpt = NULL;
526 REAL theta, dsmall, dbig, dx, dy = 0.0;
531 if((x1 == x2) && (y1 == y2))
534 theta = gdiplus_atan2(y2 - y1, x2 - x1);
536 customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
538 brush = CreateSolidBrush(color);
539 lb.lbStyle = BS_SOLID;
542 pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
543 PS_JOIN_MITER, 1, &lb, 0,
545 oldbrush = SelectObject(graphics->hdc, brush);
546 oldpen = SelectObject(graphics->hdc, pen);
553 case LineCapSquareAnchor:
554 case LineCapDiamondAnchor:
555 size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0;
556 if(cap == LineCapDiamondAnchor){
557 dsmall = cos(theta + M_PI_2) * size;
558 dbig = sin(theta + M_PI_2) * size;
561 dsmall = cos(theta + M_PI_4) * size;
562 dbig = sin(theta + M_PI_4) * size;
565 ptf[0].X = x2 - dsmall;
566 ptf[1].X = x2 + dbig;
568 ptf[0].Y = y2 - dbig;
569 ptf[3].Y = y2 + dsmall;
571 ptf[1].Y = y2 - dsmall;
572 ptf[2].Y = y2 + dbig;
574 ptf[3].X = x2 - dbig;
575 ptf[2].X = x2 + dsmall;
577 transform_and_round_points(graphics, pt, ptf, 4);
578 Polygon(graphics->hdc, pt, 4);
581 case LineCapArrowAnchor:
582 size = size * 4.0 / sqrt(3.0);
584 dx = cos(M_PI / 6.0 + theta) * size;
585 dy = sin(M_PI / 6.0 + theta) * size;
590 dx = cos(- M_PI / 6.0 + theta) * size;
591 dy = sin(- M_PI / 6.0 + theta) * size;
599 transform_and_round_points(graphics, pt, ptf, 3);
600 Polygon(graphics->hdc, pt, 3);
603 case LineCapRoundAnchor:
604 dx = dy = ANCHOR_WIDTH * size / 2.0;
611 transform_and_round_points(graphics, pt, ptf, 2);
612 Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
615 case LineCapTriangle:
617 dx = cos(M_PI_2 + theta) * size;
618 dy = sin(M_PI_2 + theta) * size;
625 dx = cos(theta) * size;
626 dy = sin(theta) * size;
631 transform_and_round_points(graphics, pt, ptf, 3);
632 Polygon(graphics->hdc, pt, 3);
636 dx = dy = size / 2.0;
643 dx = -cos(M_PI_2 + theta) * size;
644 dy = -sin(M_PI_2 + theta) * size;
651 transform_and_round_points(graphics, pt, ptf, 4);
652 Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x,
653 pt[2].y, pt[3].x, pt[3].y);
660 count = custom->pathdata.Count;
661 custptf = GdipAlloc(count * sizeof(PointF));
662 custpt = GdipAlloc(count * sizeof(POINT));
663 tp = GdipAlloc(count);
665 if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok))
668 memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF));
670 GdipScaleMatrix(matrix, size, size, MatrixOrderAppend);
671 GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2),
673 GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend);
674 GdipTransformMatrixPoints(matrix, custptf, count);
676 transform_and_round_points(graphics, custpt, custptf, count);
678 for(i = 0; i < count; i++)
679 tp[i] = convert_path_point_type(custom->pathdata.Types[i]);
682 BeginPath(graphics->hdc);
683 PolyDraw(graphics->hdc, custpt, tp, count);
684 EndPath(graphics->hdc);
685 StrokeAndFillPath(graphics->hdc);
688 PolyDraw(graphics->hdc, custpt, tp, count);
694 GdipDeleteMatrix(matrix);
701 SelectObject(graphics->hdc, oldbrush);
702 SelectObject(graphics->hdc, oldpen);
708 /* Shortens the line by the given percent by changing x2, y2.
709 * If percent is > 1.0 then the line will change direction.
710 * If percent is negative it can lengthen the line. */
711 static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL percent)
713 REAL dist, theta, dx, dy;
715 if((y1 == *y2) && (x1 == *x2))
718 dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent;
719 theta = gdiplus_atan2((*y2 - y1), (*x2 - x1));
720 dx = cos(theta) * dist;
721 dy = sin(theta) * dist;
727 /* Shortens the line by the given amount by changing x2, y2.
728 * If the amount is greater than the distance, the line will become length 0.
729 * If the amount is negative, it can lengthen the line. */
730 static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt)
732 REAL dx, dy, percent;
736 if(dx == 0 && dy == 0)
739 percent = amt / sqrt(dx * dx + dy * dy);
746 shorten_line_percent(x1, y1, x2, y2, percent);
749 /* Draws lines between the given points, and if caps is true then draws an endcap
750 * at the end of the last line. */
751 static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen,
752 GDIPCONST GpPointF * pt, INT count, BOOL caps)
755 GpPointF *ptcopy = NULL;
756 GpStatus status = GenericError;
761 pti = GdipAlloc(count * sizeof(POINT));
762 ptcopy = GdipAlloc(count * sizeof(GpPointF));
765 status = OutOfMemory;
769 memcpy(ptcopy, pt, count * sizeof(GpPointF));
772 if(pen->endcap == LineCapArrowAnchor)
773 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
774 &ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width);
775 else if((pen->endcap == LineCapCustom) && pen->customend)
776 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
777 &ptcopy[count-1].X, &ptcopy[count-1].Y,
778 pen->customend->inset * pen->width);
780 if(pen->startcap == LineCapArrowAnchor)
781 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
782 &ptcopy[0].X, &ptcopy[0].Y, pen->width);
783 else if((pen->startcap == LineCapCustom) && pen->customstart)
784 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
785 &ptcopy[0].X, &ptcopy[0].Y,
786 pen->customstart->inset * pen->width);
788 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
789 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
790 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
791 pt[1].X, pt[1].Y, pt[0].X, pt[0].Y);
794 transform_and_round_points(graphics, pti, ptcopy, count);
796 if(Polyline(graphics->hdc, pti, count))
806 /* Conducts a linear search to find the bezier points that will back off
807 * the endpoint of the curve by a distance of amt. Linear search works
808 * better than binary in this case because there are multiple solutions,
809 * and binary searches often find a bad one. I don't think this is what
810 * Windows does but short of rendering the bezier without GDI's help it's
811 * the best we can do. If rev then work from the start of the passed points
812 * instead of the end. */
813 static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev)
816 REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0;
817 INT i, first = 0, second = 1, third = 2, fourth = 3;
826 origx = pt[fourth].X;
827 origy = pt[fourth].Y;
828 memcpy(origpt, pt, sizeof(GpPointF) * 4);
830 for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){
831 /* reset bezier points to original values */
832 memcpy(pt, origpt, sizeof(GpPointF) * 4);
833 /* Perform magic on bezier points. Order is important here.*/
834 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
835 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
836 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
837 shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent);
838 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
839 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
841 dx = pt[fourth].X - origx;
842 dy = pt[fourth].Y - origy;
844 diff = sqrt(dx * dx + dy * dy);
845 percent += 0.0005 * amt;
849 /* Draws bezier curves between given points, and if caps is true then draws an
850 * endcap at the end of the last line. */
851 static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
852 GDIPCONST GpPointF * pt, INT count, BOOL caps)
856 GpStatus status = GenericError;
861 pti = GdipAlloc(count * sizeof(POINT));
862 ptcopy = GdipAlloc(count * sizeof(GpPointF));
865 status = OutOfMemory;
869 memcpy(ptcopy, pt, count * sizeof(GpPointF));
872 if(pen->endcap == LineCapArrowAnchor)
873 shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
874 else if((pen->endcap == LineCapCustom) && pen->customend)
875 shorten_bezier_amt(&ptcopy[count-4], pen->width * pen->customend->inset,
878 if(pen->startcap == LineCapArrowAnchor)
879 shorten_bezier_amt(ptcopy, pen->width, TRUE);
880 else if((pen->startcap == LineCapCustom) && pen->customstart)
881 shorten_bezier_amt(ptcopy, pen->width * pen->customstart->inset, TRUE);
883 /* the direction of the line cap is parallel to the direction at the
884 * end of the bezier (which, if it has been shortened, is not the same
885 * as the direction from pt[count-2] to pt[count-1]) */
886 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
887 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
888 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
889 pt[count - 1].X, pt[count - 1].Y);
891 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
892 pt[0].X - (ptcopy[0].X - ptcopy[1].X),
893 pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
896 transform_and_round_points(graphics, pti, ptcopy, count);
898 PolyBezier(graphics->hdc, pti, count);
909 /* Draws a combination of bezier curves and lines between points. */
910 static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
911 GDIPCONST BYTE * types, INT count, BOOL caps)
913 POINT *pti = GdipAlloc(count * sizeof(POINT));
914 BYTE *tp = GdipAlloc(count);
915 GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
917 GpStatus status = GenericError;
923 if(!pti || !tp || !ptcopy){
924 status = OutOfMemory;
928 for(i = 1; i < count; i++){
929 if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
930 if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
931 || !(types[i + 1] & PathPointTypeBezier)){
932 ERR("Bad bezier points\n");
939 memcpy(ptcopy, pt, count * sizeof(GpPointF));
941 /* If we are drawing caps, go through the points and adjust them accordingly,
942 * and draw the caps. */
944 switch(types[count - 1] & PathPointTypePathTypeMask){
945 case PathPointTypeBezier:
946 if(pen->endcap == LineCapArrowAnchor)
947 shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
948 else if((pen->endcap == LineCapCustom) && pen->customend)
949 shorten_bezier_amt(&ptcopy[count - 4],
950 pen->width * pen->customend->inset, FALSE);
952 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
953 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
954 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
955 pt[count - 1].X, pt[count - 1].Y);
958 case PathPointTypeLine:
959 if(pen->endcap == LineCapArrowAnchor)
960 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
961 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
963 else if((pen->endcap == LineCapCustom) && pen->customend)
964 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
965 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
966 pen->customend->inset * pen->width);
968 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
969 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
974 ERR("Bad path last point\n");
978 /* Find start of points */
979 for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
980 == PathPointTypeStart); j++);
982 switch(types[j] & PathPointTypePathTypeMask){
983 case PathPointTypeBezier:
984 if(pen->startcap == LineCapArrowAnchor)
985 shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
986 else if((pen->startcap == LineCapCustom) && pen->customstart)
987 shorten_bezier_amt(&ptcopy[j - 1],
988 pen->width * pen->customstart->inset, TRUE);
990 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
991 pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
992 pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
993 pt[j - 1].X, pt[j - 1].Y);
996 case PathPointTypeLine:
997 if(pen->startcap == LineCapArrowAnchor)
998 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
999 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
1001 else if((pen->startcap == LineCapCustom) && pen->customstart)
1002 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
1003 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
1004 pen->customstart->inset * pen->width);
1006 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
1007 pt[j].X, pt[j].Y, pt[j - 1].X,
1012 ERR("Bad path points\n");
1017 transform_and_round_points(graphics, pti, ptcopy, count);
1019 for(i = 0; i < count; i++){
1020 tp[i] = convert_path_point_type(types[i]);
1023 PolyDraw(graphics->hdc, pti, tp, count);
1035 GpStatus trace_path(GpGraphics *graphics, GpPath *path)
1039 BeginPath(graphics->hdc);
1040 result = draw_poly(graphics, NULL, path->pathdata.Points,
1041 path->pathdata.Types, path->pathdata.Count, FALSE);
1042 EndPath(graphics->hdc);
1046 typedef struct _GraphicsContainerItem {
1048 GraphicsContainer contid;
1050 SmoothingMode smoothing;
1051 CompositingQuality compqual;
1052 InterpolationMode interpolation;
1053 CompositingMode compmode;
1054 TextRenderingHint texthint;
1057 PixelOffsetMode pixeloffset;
1059 GpMatrix* worldtrans;
1061 } GraphicsContainerItem;
1063 static GpStatus init_container(GraphicsContainerItem** container,
1064 GDIPCONST GpGraphics* graphics){
1067 *container = GdipAlloc(sizeof(GraphicsContainerItem));
1071 (*container)->contid = graphics->contid + 1;
1073 (*container)->smoothing = graphics->smoothing;
1074 (*container)->compqual = graphics->compqual;
1075 (*container)->interpolation = graphics->interpolation;
1076 (*container)->compmode = graphics->compmode;
1077 (*container)->texthint = graphics->texthint;
1078 (*container)->scale = graphics->scale;
1079 (*container)->unit = graphics->unit;
1080 (*container)->textcontrast = graphics->textcontrast;
1081 (*container)->pixeloffset = graphics->pixeloffset;
1083 sts = GdipCloneMatrix(graphics->worldtrans, &(*container)->worldtrans);
1085 GdipFree(*container);
1090 sts = GdipCloneRegion(graphics->clip, &(*container)->clip);
1092 GdipDeleteMatrix((*container)->worldtrans);
1093 GdipFree(*container);
1101 static void delete_container(GraphicsContainerItem* container){
1102 GdipDeleteMatrix(container->worldtrans);
1103 GdipDeleteRegion(container->clip);
1104 GdipFree(container);
1107 static GpStatus restore_container(GpGraphics* graphics,
1108 GDIPCONST GraphicsContainerItem* container){
1113 sts = GdipCloneMatrix(container->worldtrans, &newTrans);
1117 sts = GdipCloneRegion(container->clip, &newClip);
1119 GdipDeleteMatrix(newTrans);
1123 GdipDeleteMatrix(graphics->worldtrans);
1124 graphics->worldtrans = newTrans;
1126 GdipDeleteRegion(graphics->clip);
1127 graphics->clip = newClip;
1129 graphics->contid = container->contid - 1;
1131 graphics->smoothing = container->smoothing;
1132 graphics->compqual = container->compqual;
1133 graphics->interpolation = container->interpolation;
1134 graphics->compmode = container->compmode;
1135 graphics->texthint = container->texthint;
1136 graphics->scale = container->scale;
1137 graphics->unit = container->unit;
1138 graphics->textcontrast = container->textcontrast;
1139 graphics->pixeloffset = container->pixeloffset;
1144 static GpStatus get_graphics_bounds(GpGraphics* graphics, GpRectF* rect)
1150 if(graphics->hwnd) {
1151 if(!GetClientRect(graphics->hwnd, &wnd_rect))
1152 return GenericError;
1154 rect->X = wnd_rect.left;
1155 rect->Y = wnd_rect.top;
1156 rect->Width = wnd_rect.right - wnd_rect.left;
1157 rect->Height = wnd_rect.bottom - wnd_rect.top;
1158 }else if (graphics->image){
1159 stat = GdipGetImageBounds(graphics->image, rect, &unit);
1160 if (stat == Ok && unit != UnitPixel)
1161 FIXME("need to convert from unit %i\n", unit);
1165 rect->Width = GetDeviceCaps(graphics->hdc, HORZRES);
1166 rect->Height = GetDeviceCaps(graphics->hdc, VERTRES);
1172 /* on success, rgn will contain the region of the graphics object which
1173 * is visible after clipping has been applied */
1174 static GpStatus get_visible_clip_region(GpGraphics *graphics, GpRegion *rgn)
1180 if((stat = get_graphics_bounds(graphics, &rectf)) != Ok)
1183 if((stat = GdipCreateRegion(&tmp)) != Ok)
1186 if((stat = GdipCombineRegionRect(tmp, &rectf, CombineModeReplace)) != Ok)
1189 if((stat = GdipCombineRegionRegion(tmp, graphics->clip, CombineModeIntersect)) != Ok)
1192 stat = GdipCombineRegionRegion(rgn, tmp, CombineModeReplace);
1195 GdipDeleteRegion(tmp);
1199 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
1201 TRACE("(%p, %p)\n", hdc, graphics);
1203 return GdipCreateFromHDC2(hdc, NULL, graphics);
1206 GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **graphics)
1210 TRACE("(%p, %p, %p)\n", hdc, hDevice, graphics);
1212 if(hDevice != NULL) {
1213 FIXME("Don't know how to handle parameter hDevice\n");
1214 return NotImplemented;
1220 if(graphics == NULL)
1221 return InvalidParameter;
1223 *graphics = GdipAlloc(sizeof(GpGraphics));
1224 if(!*graphics) return OutOfMemory;
1226 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
1227 GdipFree(*graphics);
1231 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
1232 GdipFree((*graphics)->worldtrans);
1233 GdipFree(*graphics);
1237 (*graphics)->hdc = hdc;
1238 (*graphics)->hwnd = WindowFromDC(hdc);
1239 (*graphics)->owndc = FALSE;
1240 (*graphics)->smoothing = SmoothingModeDefault;
1241 (*graphics)->compqual = CompositingQualityDefault;
1242 (*graphics)->interpolation = InterpolationModeDefault;
1243 (*graphics)->pixeloffset = PixelOffsetModeDefault;
1244 (*graphics)->compmode = CompositingModeSourceOver;
1245 (*graphics)->unit = UnitDisplay;
1246 (*graphics)->scale = 1.0;
1247 (*graphics)->busy = FALSE;
1248 (*graphics)->textcontrast = 4;
1249 list_init(&(*graphics)->containers);
1250 (*graphics)->contid = 0;
1252 TRACE("<-- %p\n", *graphics);
1257 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
1262 TRACE("(%p, %p)\n", hwnd, graphics);
1266 if((ret = GdipCreateFromHDC(hdc, graphics)) != Ok)
1268 ReleaseDC(hwnd, hdc);
1272 (*graphics)->hwnd = hwnd;
1273 (*graphics)->owndc = TRUE;
1278 /* FIXME: no icm handling */
1279 GpStatus WINGDIPAPI GdipCreateFromHWNDICM(HWND hwnd, GpGraphics **graphics)
1281 TRACE("(%p, %p)\n", hwnd, graphics);
1283 return GdipCreateFromHWND(hwnd, graphics);
1286 GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
1287 GpMetafile **metafile)
1291 TRACE("(%p,%i,%p)\n", hemf, delete, metafile);
1293 if(!hemf || !metafile)
1294 return InvalidParameter;
1297 FIXME("not implemented\n");
1299 return NotImplemented;
1302 GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
1303 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
1305 IStream *stream = NULL;
1309 GpStatus retval = Ok;
1311 TRACE("(%p, %d, %p, %p)\n", hwmf, delete, placeable, metafile);
1313 if(!hwmf || !metafile || !placeable)
1314 return InvalidParameter;
1317 read = GetMetaFileBitsEx(hwmf, 0, NULL);
1319 return GenericError;
1320 copy = GdipAlloc(read);
1321 GetMetaFileBitsEx(hwmf, read, copy);
1323 hemf = SetWinMetaFileBits(read, copy, NULL, NULL);
1326 read = GetEnhMetaFileBits(hemf, 0, NULL);
1327 copy = GdipAlloc(read);
1328 GetEnhMetaFileBits(hemf, read, copy);
1329 DeleteEnhMetaFile(hemf);
1331 if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
1332 ERR("could not make stream\n");
1334 retval = GenericError;
1338 *metafile = GdipAlloc(sizeof(GpMetafile));
1340 retval = OutOfMemory;
1344 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1345 (LPVOID*) &((*metafile)->image.picture)) != S_OK)
1347 retval = GenericError;
1352 (*metafile)->image.type = ImageTypeMetafile;
1353 memcpy(&(*metafile)->image.format, &ImageFormatWMF, sizeof(GUID));
1354 (*metafile)->image.palette_flags = 0;
1355 (*metafile)->image.palette_count = 0;
1356 (*metafile)->image.palette_size = 0;
1357 (*metafile)->image.palette_entries = NULL;
1358 (*metafile)->image.xres = (REAL)placeable->Inch;
1359 (*metafile)->image.yres = (REAL)placeable->Inch;
1360 (*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch);
1361 (*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Top) / ((REAL) placeable->Inch);
1362 (*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right
1363 - placeable->BoundingBox.Left));
1364 (*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom
1365 - placeable->BoundingBox.Top));
1366 (*metafile)->unit = UnitPixel;
1369 DeleteMetaFile(hwmf);
1371 TRACE("<-- %p\n", *metafile);
1375 GdipFree(*metafile);
1376 IStream_Release(stream);
1380 GpStatus WINGDIPAPI GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR *file,
1381 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
1383 HMETAFILE hmf = GetMetaFileW(file);
1385 TRACE("(%s, %p, %p)\n", debugstr_w(file), placeable, metafile);
1387 if(!hmf) return InvalidParameter;
1389 return GdipCreateMetafileFromWmf(hmf, TRUE, placeable, metafile);
1392 GpStatus WINGDIPAPI GdipCreateMetafileFromFile(GDIPCONST WCHAR *file,
1393 GpMetafile **metafile)
1395 FIXME("(%p, %p): stub\n", file, metafile);
1396 return NotImplemented;
1399 GpStatus WINGDIPAPI GdipCreateMetafileFromStream(IStream *stream,
1400 GpMetafile **metafile)
1402 FIXME("(%p, %p): stub\n", stream, metafile);
1403 return NotImplemented;
1406 GpStatus WINGDIPAPI GdipCreateStreamOnFile(GDIPCONST WCHAR * filename,
1407 UINT access, IStream **stream)
1412 TRACE("(%s, %u, %p)\n", debugstr_w(filename), access, stream);
1414 if(!stream || !filename)
1415 return InvalidParameter;
1417 if(access & GENERIC_WRITE)
1418 dwMode = STGM_SHARE_DENY_WRITE | STGM_WRITE | STGM_CREATE;
1419 else if(access & GENERIC_READ)
1420 dwMode = STGM_SHARE_DENY_WRITE | STGM_READ | STGM_FAILIFTHERE;
1422 return InvalidParameter;
1424 ret = SHCreateStreamOnFileW(filename, dwMode, stream);
1426 return hresult_to_status(ret);
1429 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
1431 GraphicsContainerItem *cont, *next;
1432 TRACE("(%p)\n", graphics);
1434 if(!graphics) return InvalidParameter;
1435 if(graphics->busy) return ObjectBusy;
1438 ReleaseDC(graphics->hwnd, graphics->hdc);
1440 LIST_FOR_EACH_ENTRY_SAFE(cont, next, &graphics->containers, GraphicsContainerItem, entry){
1441 list_remove(&cont->entry);
1442 delete_container(cont);
1445 GdipDeleteRegion(graphics->clip);
1446 GdipDeleteMatrix(graphics->worldtrans);
1452 GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
1453 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1455 INT save_state, num_pts;
1456 GpPointF points[MAX_ARC_PTS];
1459 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
1460 width, height, startAngle, sweepAngle);
1462 if(!graphics || !pen || width <= 0 || height <= 0)
1463 return InvalidParameter;
1468 num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
1470 save_state = prepare_dc(graphics, pen);
1472 retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
1474 restore_dc(graphics, save_state);
1479 GpStatus WINGDIPAPI GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x,
1480 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
1482 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
1483 width, height, startAngle, sweepAngle);
1485 return GdipDrawArc(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
1488 GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
1489 REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
1495 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1,
1496 x2, y2, x3, y3, x4, y4);
1498 if(!graphics || !pen)
1499 return InvalidParameter;
1513 save_state = prepare_dc(graphics, pen);
1515 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
1517 restore_dc(graphics, save_state);
1522 GpStatus WINGDIPAPI GdipDrawBezierI(GpGraphics *graphics, GpPen *pen, INT x1,
1523 INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4)
1529 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics, pen, x1, y1,
1530 x2, y2, x3, y3, x4, y4);
1532 if(!graphics || !pen)
1533 return InvalidParameter;
1547 save_state = prepare_dc(graphics, pen);
1549 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
1551 restore_dc(graphics, save_state);
1556 GpStatus WINGDIPAPI GdipDrawBeziers(GpGraphics *graphics, GpPen *pen,
1557 GDIPCONST GpPointF *points, INT count)
1562 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1564 if(!graphics || !pen || !points || (count <= 0))
1565 return InvalidParameter;
1570 for(i = 0; i < floor(count / 4); i++){
1571 ret = GdipDrawBezier(graphics, pen,
1572 points[4*i].X, points[4*i].Y,
1573 points[4*i + 1].X, points[4*i + 1].Y,
1574 points[4*i + 2].X, points[4*i + 2].Y,
1575 points[4*i + 3].X, points[4*i + 3].Y);
1583 GpStatus WINGDIPAPI GdipDrawBeziersI(GpGraphics *graphics, GpPen *pen,
1584 GDIPCONST GpPoint *points, INT count)
1590 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1592 if(!graphics || !pen || !points || (count <= 0))
1593 return InvalidParameter;
1598 pts = GdipAlloc(sizeof(GpPointF) * count);
1602 for(i = 0; i < count; i++){
1603 pts[i].X = (REAL)points[i].X;
1604 pts[i].Y = (REAL)points[i].Y;
1607 ret = GdipDrawBeziers(graphics,pen,pts,count);
1614 GpStatus WINGDIPAPI GdipDrawClosedCurve(GpGraphics *graphics, GpPen *pen,
1615 GDIPCONST GpPointF *points, INT count)
1617 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1619 return GdipDrawClosedCurve2(graphics, pen, points, count, 1.0);
1622 GpStatus WINGDIPAPI GdipDrawClosedCurveI(GpGraphics *graphics, GpPen *pen,
1623 GDIPCONST GpPoint *points, INT count)
1625 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1627 return GdipDrawClosedCurve2I(graphics, pen, points, count, 1.0);
1630 GpStatus WINGDIPAPI GdipDrawClosedCurve2(GpGraphics *graphics, GpPen *pen,
1631 GDIPCONST GpPointF *points, INT count, REAL tension)
1636 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1638 if(!graphics || !pen || !points || count <= 0)
1639 return InvalidParameter;
1644 if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok)
1647 stat = GdipAddPathClosedCurve2(path, points, count, tension);
1649 GdipDeletePath(path);
1653 stat = GdipDrawPath(graphics, pen, path);
1655 GdipDeletePath(path);
1660 GpStatus WINGDIPAPI GdipDrawClosedCurve2I(GpGraphics *graphics, GpPen *pen,
1661 GDIPCONST GpPoint *points, INT count, REAL tension)
1667 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1669 if(!points || count <= 0)
1670 return InvalidParameter;
1672 ptf = GdipAlloc(sizeof(GpPointF)*count);
1676 for(i = 0; i < count; i++){
1677 ptf[i].X = (REAL)points[i].X;
1678 ptf[i].Y = (REAL)points[i].Y;
1681 stat = GdipDrawClosedCurve2(graphics, pen, ptf, count, tension);
1688 GpStatus WINGDIPAPI GdipDrawCurve(GpGraphics *graphics, GpPen *pen,
1689 GDIPCONST GpPointF *points, INT count)
1691 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1693 return GdipDrawCurve2(graphics,pen,points,count,1.0);
1696 GpStatus WINGDIPAPI GdipDrawCurveI(GpGraphics *graphics, GpPen *pen,
1697 GDIPCONST GpPoint *points, INT count)
1703 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1706 return InvalidParameter;
1708 pointsF = GdipAlloc(sizeof(GpPointF)*count);
1712 for(i = 0; i < count; i++){
1713 pointsF[i].X = (REAL)points[i].X;
1714 pointsF[i].Y = (REAL)points[i].Y;
1717 ret = GdipDrawCurve(graphics,pen,pointsF,count);
1723 /* Approximates cardinal spline with Bezier curves. */
1724 GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
1725 GDIPCONST GpPointF *points, INT count, REAL tension)
1727 /* PolyBezier expects count*3-2 points. */
1728 INT i, len_pt = count*3-2, save_state;
1730 REAL x1, x2, y1, y2;
1733 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1735 if(!graphics || !pen)
1736 return InvalidParameter;
1742 return InvalidParameter;
1744 pt = GdipAlloc(len_pt * sizeof(GpPointF));
1748 tension = tension * TENSION_CONST;
1750 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
1753 pt[0].X = points[0].X;
1754 pt[0].Y = points[0].Y;
1758 for(i = 0; i < count-2; i++){
1759 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
1763 pt[3*i+3].X = points[i+1].X;
1764 pt[3*i+3].Y = points[i+1].Y;
1769 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
1770 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
1772 pt[len_pt-2].X = x1;
1773 pt[len_pt-2].Y = y1;
1774 pt[len_pt-1].X = points[count-1].X;
1775 pt[len_pt-1].Y = points[count-1].Y;
1777 save_state = prepare_dc(graphics, pen);
1779 retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
1782 restore_dc(graphics, save_state);
1787 GpStatus WINGDIPAPI GdipDrawCurve2I(GpGraphics *graphics, GpPen *pen,
1788 GDIPCONST GpPoint *points, INT count, REAL tension)
1794 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1797 return InvalidParameter;
1799 pointsF = GdipAlloc(sizeof(GpPointF)*count);
1803 for(i = 0; i < count; i++){
1804 pointsF[i].X = (REAL)points[i].X;
1805 pointsF[i].Y = (REAL)points[i].Y;
1808 ret = GdipDrawCurve2(graphics,pen,pointsF,count,tension);
1814 GpStatus WINGDIPAPI GdipDrawCurve3(GpGraphics *graphics, GpPen *pen,
1815 GDIPCONST GpPointF *points, INT count, INT offset, INT numberOfSegments,
1818 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
1820 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
1821 return InvalidParameter;
1824 return GdipDrawCurve2(graphics, pen, points + offset, numberOfSegments + 1, tension);
1827 GpStatus WINGDIPAPI GdipDrawCurve3I(GpGraphics *graphics, GpPen *pen,
1828 GDIPCONST GpPoint *points, INT count, INT offset, INT numberOfSegments,
1831 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
1837 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
1838 return InvalidParameter;
1841 return GdipDrawCurve2I(graphics, pen, points + offset, numberOfSegments + 1, tension);
1844 GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics *graphics, GpPen *pen, REAL x,
1845 REAL y, REAL width, REAL height)
1851 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
1853 if(!graphics || !pen)
1854 return InvalidParameter;
1861 ptf[1].X = x + width;
1862 ptf[1].Y = y + height;
1864 save_state = prepare_dc(graphics, pen);
1865 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1867 transform_and_round_points(graphics, pti, ptf, 2);
1869 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
1871 restore_dc(graphics, save_state);
1876 GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics *graphics, GpPen *pen, INT x,
1877 INT y, INT width, INT height)
1879 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
1881 return GdipDrawEllipse(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1885 GpStatus WINGDIPAPI GdipDrawImage(GpGraphics *graphics, GpImage *image, REAL x, REAL y)
1890 TRACE("(%p, %p, %.2f, %.2f)\n", graphics, image, x, y);
1892 if(!graphics || !image)
1893 return InvalidParameter;
1895 GdipGetImageWidth(image, &width);
1896 GdipGetImageHeight(image, &height);
1898 /* FIXME: we should use the graphics and image dpi, somehow */
1900 points[0].X = points[2].X = x;
1901 points[0].Y = points[1].Y = y;
1902 points[1].X = x + width;
1903 points[2].Y = y + height;
1905 return GdipDrawImagePointsRect(graphics, image, points, 3, 0, 0, width, height,
1906 UnitPixel, NULL, NULL, NULL);
1909 GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x,
1912 TRACE("(%p, %p, %d, %d)\n", graphics, image, x, y);
1914 return GdipDrawImage(graphics, image, (REAL)x, (REAL)y);
1917 GpStatus WINGDIPAPI GdipDrawImagePointRect(GpGraphics *graphics, GpImage *image,
1918 REAL x, REAL y, REAL srcx, REAL srcy, REAL srcwidth, REAL srcheight,
1922 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
1924 points[0].X = points[2].X = x;
1925 points[0].Y = points[1].Y = y;
1927 /* FIXME: convert image coordinates to Graphics coordinates? */
1928 points[1].X = x + srcwidth;
1929 points[2].Y = y + srcheight;
1931 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
1932 srcwidth, srcheight, srcUnit, NULL, NULL, NULL);
1935 GpStatus WINGDIPAPI GdipDrawImagePointRectI(GpGraphics *graphics, GpImage *image,
1936 INT x, INT y, INT srcx, INT srcy, INT srcwidth, INT srcheight,
1939 return GdipDrawImagePointRect(graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
1942 GpStatus WINGDIPAPI GdipDrawImagePoints(GpGraphics *graphics, GpImage *image,
1943 GDIPCONST GpPointF *dstpoints, INT count)
1945 FIXME("(%p, %p, %p, %d): stub\n", graphics, image, dstpoints, count);
1946 return NotImplemented;
1949 GpStatus WINGDIPAPI GdipDrawImagePointsI(GpGraphics *graphics, GpImage *image,
1950 GDIPCONST GpPoint *dstpoints, INT count)
1952 FIXME("(%p, %p, %p, %d): stub\n", graphics, image, dstpoints, count);
1953 return NotImplemented;
1956 GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
1957 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
1958 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
1959 DrawImageAbort callback, VOID * callbackData)
1966 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics, image, points,
1967 count, srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
1970 if(!graphics || !image || !points || count != 3)
1971 return InvalidParameter;
1973 TRACE("%s %s %s\n", debugstr_pointf(&points[0]), debugstr_pointf(&points[1]),
1974 debugstr_pointf(&points[2]));
1976 memcpy(ptf, points, 3 * sizeof(GpPointF));
1977 ptf[3].X = ptf[2].X + ptf[1].X - ptf[0].X;
1978 ptf[3].Y = ptf[2].Y + ptf[1].Y - ptf[0].Y;
1979 transform_and_round_points(graphics, pti, ptf, 4);
1985 FIXME("graphics object has no HDC\n");
1988 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1989 if(srcUnit == UnitInch)
1990 dx = dy = (REAL) INCH_HIMETRIC;
1991 else if(srcUnit == UnitPixel){
1992 dx = ((REAL) INCH_HIMETRIC) /
1993 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
1994 dy = ((REAL) INCH_HIMETRIC) /
1995 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
1998 return NotImplemented;
2000 if(IPicture_Render(image->picture, graphics->hdc,
2001 pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
2002 srcx * dx, srcy * dy,
2003 srcwidth * dx, srcheight * dy,
2006 callback(callbackData);
2007 return GenericError;
2010 else if (image->type == ImageTypeBitmap && ((GpBitmap*)image)->hbitmap)
2012 GpBitmap* bitmap = (GpBitmap*)image;
2015 if (srcUnit == UnitInch)
2016 dx = dy = 96.0; /* FIXME: use the image resolution */
2017 else if (srcUnit == UnitPixel)
2020 return NotImplemented;
2022 if (imageAttributes ||
2023 (graphics->image && graphics->image->type == ImageTypeBitmap) ||
2024 ptf[1].Y != ptf[0].Y || ptf[2].X != ptf[0].X)
2029 RECT src_area, dst_area;
2030 int i, x, y, stride;
2031 GpMatrix *dst_to_src;
2032 REAL m11, m12, m21, m22, mdx, mdy;
2035 src_area.left = srcx*dx;
2036 src_area.top = srcy*dy;
2037 src_area.right = (srcx+srcwidth)*dx;
2038 src_area.bottom = (srcy+srcheight)*dy;
2040 dst_area.left = dst_area.right = pti[0].x;
2041 dst_area.top = dst_area.bottom = pti[0].y;
2044 if (dst_area.left > pti[i].x) dst_area.left = pti[i].x;
2045 if (dst_area.right < pti[i].x) dst_area.right = pti[i].x;
2046 if (dst_area.top > pti[i].y) dst_area.top = pti[i].y;
2047 if (dst_area.bottom < pti[i].y) dst_area.bottom = pti[i].y;
2050 m11 = (ptf[1].X - ptf[0].X) / srcwidth;
2051 m21 = (ptf[2].X - ptf[0].X) / srcheight;
2052 mdx = ptf[0].X - m11 * srcx - m21 * srcy;
2053 m12 = (ptf[1].Y - ptf[0].Y) / srcwidth;
2054 m22 = (ptf[2].Y - ptf[0].Y) / srcheight;
2055 mdy = ptf[0].Y - m12 * srcx - m22 * srcy;
2057 stat = GdipCreateMatrix2(m11, m12, m21, m22, mdx, mdy, &dst_to_src);
2058 if (stat != Ok) return stat;
2060 stat = GdipInvertMatrix(dst_to_src);
2063 GdipDeleteMatrix(dst_to_src);
2067 data = GdipAlloc(sizeof(ARGB) * (dst_area.right - dst_area.left) * (dst_area.bottom - dst_area.top));
2070 GdipDeleteMatrix(dst_to_src);
2074 stride = sizeof(ARGB) * (dst_area.right - dst_area.left);
2076 if (imageAttributes &&
2077 (imageAttributes->wrap != WrapModeClamp ||
2078 imageAttributes->outside_color != 0x00000000 ||
2079 imageAttributes->clamp))
2083 FIXME("Image wrap mode not implemented\n");
2086 for (x=dst_area.left; x<dst_area.right; x++)
2088 for (y=dst_area.top; y<dst_area.bottom; y++)
2090 GpPointF src_pointf;
2097 GdipTransformMatrixPoints(dst_to_src, &src_pointf, 1);
2099 src_x = roundr(src_pointf.X);
2100 src_y = roundr(src_pointf.Y);
2102 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2104 if (src_x < src_area.left || src_x >= src_area.right ||
2105 src_y < src_area.top || src_y >= src_area.bottom)
2108 GdipBitmapGetPixel(bitmap, src_x, src_y, src_color);
2112 GdipDeleteMatrix(dst_to_src);
2114 if (imageAttributes)
2116 if (imageAttributes->colorkeys[ColorAdjustTypeBitmap].enabled ||
2117 imageAttributes->colorkeys[ColorAdjustTypeDefault].enabled)
2119 const struct color_key *key;
2120 BYTE min_blue, min_green, min_red;
2121 BYTE max_blue, max_green, max_red;
2123 if (imageAttributes->colorkeys[ColorAdjustTypeBitmap].enabled)
2124 key = &imageAttributes->colorkeys[ColorAdjustTypeBitmap];
2126 key = &imageAttributes->colorkeys[ColorAdjustTypeDefault];
2128 min_blue = key->low&0xff;
2129 min_green = (key->low>>8)&0xff;
2130 min_red = (key->low>>16)&0xff;
2132 max_blue = key->high&0xff;
2133 max_green = (key->high>>8)&0xff;
2134 max_red = (key->high>>16)&0xff;
2136 for (x=dst_area.left; x<dst_area.right; x++)
2137 for (y=dst_area.top; y<dst_area.bottom; y++)
2140 BYTE blue, green, red;
2141 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2142 blue = *src_color&0xff;
2143 green = (*src_color>>8)&0xff;
2144 red = (*src_color>>16)&0xff;
2145 if (blue >= min_blue && green >= min_green && red >= min_red &&
2146 blue <= max_blue && green <= max_green && red <= max_red)
2147 *src_color = 0x00000000;
2151 if (imageAttributes->colorremaptables[ColorAdjustTypeBitmap].enabled ||
2152 imageAttributes->colorremaptables[ColorAdjustTypeDefault].enabled)
2154 const struct color_remap_table *table;
2156 if (imageAttributes->colorremaptables[ColorAdjustTypeBitmap].enabled)
2157 table = &imageAttributes->colorremaptables[ColorAdjustTypeBitmap];
2159 table = &imageAttributes->colorremaptables[ColorAdjustTypeDefault];
2161 for (x=dst_area.left; x<dst_area.right; x++)
2162 for (y=dst_area.top; y<dst_area.bottom; y++)
2165 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2166 for (i=0; i<table->mapsize; i++)
2168 if (*src_color == table->colormap[i].oldColor.Argb)
2170 *src_color = table->colormap[i].newColor.Argb;
2177 if (imageAttributes->colormatrices[ColorAdjustTypeBitmap].enabled ||
2178 imageAttributes->colormatrices[ColorAdjustTypeDefault].enabled)
2182 FIXME("Color transforms not implemented\n");
2185 if (imageAttributes->gamma_enabled[ColorAdjustTypeBitmap] ||
2186 imageAttributes->gamma_enabled[ColorAdjustTypeDefault])
2190 FIXME("Gamma adjustment not implemented\n");
2194 stat = alpha_blend_pixels(graphics, dst_area.left, dst_area.top,
2195 data, dst_area.right - dst_area.left, dst_area.bottom - dst_area.top, stride);
2204 int temp_hdc=0, temp_bitmap=0;
2205 HBITMAP hbitmap, old_hbm=NULL;
2207 if (!(bitmap->format == PixelFormat16bppRGB555 ||
2208 bitmap->format == PixelFormat24bppRGB ||
2209 bitmap->format == PixelFormat32bppRGB ||
2210 bitmap->format == PixelFormat32bppPARGB))
2212 BITMAPINFOHEADER bih;
2214 PixelFormat dst_format;
2216 /* we can't draw a bitmap of this format directly */
2217 hdc = CreateCompatibleDC(0);
2221 bih.biSize = sizeof(BITMAPINFOHEADER);
2222 bih.biWidth = bitmap->width;
2223 bih.biHeight = -bitmap->height;
2225 bih.biBitCount = 32;
2226 bih.biCompression = BI_RGB;
2227 bih.biSizeImage = 0;
2228 bih.biXPelsPerMeter = 0;
2229 bih.biYPelsPerMeter = 0;
2231 bih.biClrImportant = 0;
2233 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
2234 (void**)&temp_bits, NULL, 0);
2236 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
2237 dst_format = PixelFormat32bppPARGB;
2239 dst_format = PixelFormat32bppRGB;
2241 convert_pixels(bitmap->width, bitmap->height,
2242 bitmap->width*4, temp_bits, dst_format,
2243 bitmap->stride, bitmap->bits, bitmap->format, bitmap->image.palette_entries);
2247 hbitmap = bitmap->hbitmap;
2249 temp_hdc = (hdc == 0);
2254 if (!hdc) hdc = CreateCompatibleDC(0);
2255 old_hbm = SelectObject(hdc, hbitmap);
2258 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
2262 bf.BlendOp = AC_SRC_OVER;
2264 bf.SourceConstantAlpha = 255;
2265 bf.AlphaFormat = AC_SRC_ALPHA;
2267 GdiAlphaBlend(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
2268 hdc, srcx*dx, srcy*dy, srcwidth*dx, srcheight*dy, bf);
2272 StretchBlt(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
2273 hdc, srcx*dx, srcy*dy, srcwidth*dx, srcheight*dy, SRCCOPY);
2278 SelectObject(hdc, old_hbm);
2283 DeleteObject(hbitmap);
2288 ERR("GpImage with no IPicture or HBITMAP?!\n");
2289 return NotImplemented;
2295 GpStatus WINGDIPAPI GdipDrawImagePointsRectI(GpGraphics *graphics, GpImage *image,
2296 GDIPCONST GpPoint *points, INT count, INT srcx, INT srcy, INT srcwidth,
2297 INT srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
2298 DrawImageAbort callback, VOID * callbackData)
2300 GpPointF pointsF[3];
2303 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics, image, points, count,
2304 srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
2307 if(!points || count!=3)
2308 return InvalidParameter;
2310 for(i = 0; i < count; i++){
2311 pointsF[i].X = (REAL)points[i].X;
2312 pointsF[i].Y = (REAL)points[i].Y;
2315 return GdipDrawImagePointsRect(graphics, image, pointsF, count, (REAL)srcx, (REAL)srcy,
2316 (REAL)srcwidth, (REAL)srcheight, srcUnit, imageAttributes,
2317 callback, callbackData);
2320 GpStatus WINGDIPAPI GdipDrawImageRectRect(GpGraphics *graphics, GpImage *image,
2321 REAL dstx, REAL dsty, REAL dstwidth, REAL dstheight, REAL srcx, REAL srcy,
2322 REAL srcwidth, REAL srcheight, GpUnit srcUnit,
2323 GDIPCONST GpImageAttributes* imageattr, DrawImageAbort callback,
2324 VOID * callbackData)
2328 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
2329 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
2330 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
2334 points[1].X = dstx + dstwidth;
2337 points[2].Y = dsty + dstheight;
2339 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2340 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
2343 GpStatus WINGDIPAPI GdipDrawImageRectRectI(GpGraphics *graphics, GpImage *image,
2344 INT dstx, INT dsty, INT dstwidth, INT dstheight, INT srcx, INT srcy,
2345 INT srcwidth, INT srcheight, GpUnit srcUnit,
2346 GDIPCONST GpImageAttributes* imageAttributes, DrawImageAbort callback,
2347 VOID * callbackData)
2351 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
2352 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
2353 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
2357 points[1].X = dstx + dstwidth;
2360 points[2].Y = dsty + dstheight;
2362 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2363 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
2366 GpStatus WINGDIPAPI GdipDrawImageRect(GpGraphics *graphics, GpImage *image,
2367 REAL x, REAL y, REAL width, REAL height)
2373 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, image, x, y, width, height);
2375 if(!graphics || !image)
2376 return InvalidParameter;
2378 ret = GdipGetImageBounds(image, &bounds, &unit);
2382 return GdipDrawImageRectRect(graphics, image, x, y, width, height,
2383 bounds.X, bounds.Y, bounds.Width, bounds.Height,
2384 unit, NULL, NULL, NULL);
2387 GpStatus WINGDIPAPI GdipDrawImageRectI(GpGraphics *graphics, GpImage *image,
2388 INT x, INT y, INT width, INT height)
2390 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, image, x, y, width, height);
2392 return GdipDrawImageRect(graphics, image, (REAL)x, (REAL)y, (REAL)width, (REAL)height);
2395 GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1,
2396 REAL y1, REAL x2, REAL y2)
2402 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1, x2, y2);
2404 if(!pen || !graphics)
2405 return InvalidParameter;
2415 save_state = prepare_dc(graphics, pen);
2417 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
2419 restore_dc(graphics, save_state);
2424 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
2425 INT y1, INT x2, INT y2)
2431 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x1, y1, x2, y2);
2433 if(!pen || !graphics)
2434 return InvalidParameter;
2444 save_state = prepare_dc(graphics, pen);
2446 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
2448 restore_dc(graphics, save_state);
2453 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
2454 GpPointF *points, INT count)
2459 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2461 if(!pen || !graphics || (count < 2))
2462 return InvalidParameter;
2467 save_state = prepare_dc(graphics, pen);
2469 retval = draw_polyline(graphics, pen, points, count, TRUE);
2471 restore_dc(graphics, save_state);
2476 GpStatus WINGDIPAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, GDIPCONST
2477 GpPoint *points, INT count)
2481 GpPointF *ptf = NULL;
2484 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2486 if(!pen || !graphics || (count < 2))
2487 return InvalidParameter;
2492 ptf = GdipAlloc(count * sizeof(GpPointF));
2493 if(!ptf) return OutOfMemory;
2495 for(i = 0; i < count; i ++){
2496 ptf[i].X = (REAL) points[i].X;
2497 ptf[i].Y = (REAL) points[i].Y;
2500 save_state = prepare_dc(graphics, pen);
2502 retval = draw_polyline(graphics, pen, ptf, count, TRUE);
2504 restore_dc(graphics, save_state);
2510 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
2515 TRACE("(%p, %p, %p)\n", graphics, pen, path);
2517 if(!pen || !graphics)
2518 return InvalidParameter;
2523 save_state = prepare_dc(graphics, pen);
2525 retval = draw_poly(graphics, pen, path->pathdata.Points,
2526 path->pathdata.Types, path->pathdata.Count, TRUE);
2528 restore_dc(graphics, save_state);
2533 GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
2534 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2538 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
2539 width, height, startAngle, sweepAngle);
2541 if(!graphics || !pen)
2542 return InvalidParameter;
2547 save_state = prepare_dc(graphics, pen);
2548 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2550 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
2552 restore_dc(graphics, save_state);
2557 GpStatus WINGDIPAPI GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x,
2558 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2560 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
2561 width, height, startAngle, sweepAngle);
2563 return GdipDrawPie(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2566 GpStatus WINGDIPAPI GdipDrawRectangle(GpGraphics *graphics, GpPen *pen, REAL x,
2567 REAL y, REAL width, REAL height)
2573 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
2575 if(!pen || !graphics)
2576 return InvalidParameter;
2583 ptf[1].X = x + width;
2585 ptf[2].X = x + width;
2586 ptf[2].Y = y + height;
2588 ptf[3].Y = y + height;
2590 save_state = prepare_dc(graphics, pen);
2591 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2593 transform_and_round_points(graphics, pti, ptf, 4);
2594 Polygon(graphics->hdc, pti, 4);
2596 restore_dc(graphics, save_state);
2601 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
2602 INT y, INT width, INT height)
2604 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
2606 return GdipDrawRectangle(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2609 GpStatus WINGDIPAPI GdipDrawRectangles(GpGraphics *graphics, GpPen *pen,
2610 GDIPCONST GpRectF* rects, INT count)
2616 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
2618 if(!graphics || !pen || !rects || count < 1)
2619 return InvalidParameter;
2624 ptf = GdipAlloc(4 * count * sizeof(GpPointF));
2625 pti = GdipAlloc(4 * count * sizeof(POINT));
2633 for(i = 0; i < count; i++){
2634 ptf[4 * i + 3].X = ptf[4 * i].X = rects[i].X;
2635 ptf[4 * i + 1].Y = ptf[4 * i].Y = rects[i].Y;
2636 ptf[4 * i + 2].X = ptf[4 * i + 1].X = rects[i].X + rects[i].Width;
2637 ptf[4 * i + 3].Y = ptf[4 * i + 2].Y = rects[i].Y + rects[i].Height;
2640 save_state = prepare_dc(graphics, pen);
2641 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2643 transform_and_round_points(graphics, pti, ptf, 4 * count);
2645 for(i = 0; i < count; i++)
2646 Polygon(graphics->hdc, &pti[4 * i], 4);
2648 restore_dc(graphics, save_state);
2656 GpStatus WINGDIPAPI GdipDrawRectanglesI(GpGraphics *graphics, GpPen *pen,
2657 GDIPCONST GpRect* rects, INT count)
2663 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
2665 if(!rects || count<=0)
2666 return InvalidParameter;
2668 rectsF = GdipAlloc(sizeof(GpRectF) * count);
2672 for(i = 0;i < count;i++){
2673 rectsF[i].X = (REAL)rects[i].X;
2674 rectsF[i].Y = (REAL)rects[i].Y;
2675 rectsF[i].Width = (REAL)rects[i].Width;
2676 rectsF[i].Height = (REAL)rects[i].Height;
2679 ret = GdipDrawRectangles(graphics, pen, rectsF, count);
2685 GpStatus WINGDIPAPI GdipFillClosedCurve2(GpGraphics *graphics, GpBrush *brush,
2686 GDIPCONST GpPointF *points, INT count, REAL tension, GpFillMode fill)
2691 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2692 count, tension, fill);
2694 if(!graphics || !brush || !points)
2695 return InvalidParameter;
2700 if(count == 1) /* Do nothing */
2703 stat = GdipCreatePath(fill, &path);
2707 stat = GdipAddPathClosedCurve2(path, points, count, tension);
2709 GdipDeletePath(path);
2713 stat = GdipFillPath(graphics, brush, path);
2715 GdipDeletePath(path);
2719 GdipDeletePath(path);
2724 GpStatus WINGDIPAPI GdipFillClosedCurve2I(GpGraphics *graphics, GpBrush *brush,
2725 GDIPCONST GpPoint *points, INT count, REAL tension, GpFillMode fill)
2731 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2732 count, tension, fill);
2734 if(!points || count == 0)
2735 return InvalidParameter;
2737 if(count == 1) /* Do nothing */
2740 ptf = GdipAlloc(sizeof(GpPointF)*count);
2744 for(i = 0;i < count;i++){
2745 ptf[i].X = (REAL)points[i].X;
2746 ptf[i].Y = (REAL)points[i].Y;
2749 stat = GdipFillClosedCurve2(graphics, brush, ptf, count, tension, fill);
2756 GpStatus WINGDIPAPI GdipFillClosedCurve(GpGraphics *graphics, GpBrush *brush,
2757 GDIPCONST GpPointF *points, INT count)
2759 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
2760 return GdipFillClosedCurve2(graphics, brush, points, count,
2761 0.5f, FillModeAlternate);
2764 GpStatus WINGDIPAPI GdipFillClosedCurveI(GpGraphics *graphics, GpBrush *brush,
2765 GDIPCONST GpPoint *points, INT count)
2767 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
2768 return GdipFillClosedCurve2I(graphics, brush, points, count,
2769 0.5f, FillModeAlternate);
2772 GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x,
2773 REAL y, REAL width, REAL height)
2779 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
2781 if(!graphics || !brush)
2782 return InvalidParameter;
2789 FIXME("graphics object has no HDC\n");
2795 ptf[1].X = x + width;
2796 ptf[1].Y = y + height;
2798 save_state = SaveDC(graphics->hdc);
2799 EndPath(graphics->hdc);
2801 transform_and_round_points(graphics, pti, ptf, 2);
2803 BeginPath(graphics->hdc);
2804 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
2805 EndPath(graphics->hdc);
2807 brush_fill_path(graphics, brush);
2809 RestoreDC(graphics->hdc, save_state);
2814 GpStatus WINGDIPAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x,
2815 INT y, INT width, INT height)
2817 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
2819 return GdipFillEllipse(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2822 GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
2827 TRACE("(%p, %p, %p)\n", graphics, brush, path);
2829 if(!brush || !graphics || !path)
2830 return InvalidParameter;
2837 FIXME("graphics object has no HDC\n");
2841 save_state = SaveDC(graphics->hdc);
2842 EndPath(graphics->hdc);
2843 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
2846 BeginPath(graphics->hdc);
2847 retval = draw_poly(graphics, NULL, path->pathdata.Points,
2848 path->pathdata.Types, path->pathdata.Count, FALSE);
2853 EndPath(graphics->hdc);
2854 brush_fill_path(graphics, brush);
2859 RestoreDC(graphics->hdc, save_state);
2864 GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
2865 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2869 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2870 graphics, brush, x, y, width, height, startAngle, sweepAngle);
2872 if(!graphics || !brush)
2873 return InvalidParameter;
2880 FIXME("graphics object has no HDC\n");
2884 save_state = SaveDC(graphics->hdc);
2885 EndPath(graphics->hdc);
2887 BeginPath(graphics->hdc);
2888 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
2889 EndPath(graphics->hdc);
2891 brush_fill_path(graphics, brush);
2893 RestoreDC(graphics->hdc, save_state);
2898 GpStatus WINGDIPAPI GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x,
2899 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2901 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2902 graphics, brush, x, y, width, height, startAngle, sweepAngle);
2904 return GdipFillPie(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2907 GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush,
2908 GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)
2911 GpPointF *ptf = NULL;
2913 GpStatus retval = Ok;
2915 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
2917 if(!graphics || !brush || !points || !count)
2918 return InvalidParameter;
2925 FIXME("graphics object has no HDC\n");
2929 ptf = GdipAlloc(count * sizeof(GpPointF));
2930 pti = GdipAlloc(count * sizeof(POINT));
2932 retval = OutOfMemory;
2936 memcpy(ptf, points, count * sizeof(GpPointF));
2938 save_state = SaveDC(graphics->hdc);
2939 EndPath(graphics->hdc);
2940 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
2943 transform_and_round_points(graphics, pti, ptf, count);
2945 BeginPath(graphics->hdc);
2946 Polygon(graphics->hdc, pti, count);
2947 EndPath(graphics->hdc);
2949 brush_fill_path(graphics, brush);
2951 RestoreDC(graphics->hdc, save_state);
2960 GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
2961 GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
2964 GpPointF *ptf = NULL;
2966 GpStatus retval = Ok;
2968 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
2970 if(!graphics || !brush || !points || !count)
2971 return InvalidParameter;
2978 FIXME("graphics object has no HDC\n");
2982 ptf = GdipAlloc(count * sizeof(GpPointF));
2983 pti = GdipAlloc(count * sizeof(POINT));
2985 retval = OutOfMemory;
2989 for(i = 0; i < count; i ++){
2990 ptf[i].X = (REAL) points[i].X;
2991 ptf[i].Y = (REAL) points[i].Y;
2994 save_state = SaveDC(graphics->hdc);
2995 EndPath(graphics->hdc);
2996 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
2999 transform_and_round_points(graphics, pti, ptf, count);
3001 BeginPath(graphics->hdc);
3002 Polygon(graphics->hdc, pti, count);
3003 EndPath(graphics->hdc);
3005 brush_fill_path(graphics, brush);
3007 RestoreDC(graphics->hdc, save_state);
3016 GpStatus WINGDIPAPI GdipFillPolygon2(GpGraphics *graphics, GpBrush *brush,
3017 GDIPCONST GpPointF *points, INT count)
3019 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3021 return GdipFillPolygon(graphics, brush, points, count, FillModeAlternate);
3024 GpStatus WINGDIPAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush,
3025 GDIPCONST GpPoint *points, INT count)
3027 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3029 return GdipFillPolygonI(graphics, brush, points, count, FillModeAlternate);
3032 GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics *graphics, GpBrush *brush,
3033 REAL x, REAL y, REAL width, REAL height)
3039 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
3041 if(!graphics || !brush)
3042 return InvalidParameter;
3049 FIXME("graphics object has no HDC\n");
3055 ptf[1].X = x + width;
3057 ptf[2].X = x + width;
3058 ptf[2].Y = y + height;
3060 ptf[3].Y = y + height;
3062 save_state = SaveDC(graphics->hdc);
3063 EndPath(graphics->hdc);
3065 transform_and_round_points(graphics, pti, ptf, 4);
3067 BeginPath(graphics->hdc);
3068 Polygon(graphics->hdc, pti, 4);
3069 EndPath(graphics->hdc);
3071 brush_fill_path(graphics, brush);
3073 RestoreDC(graphics->hdc, save_state);
3078 GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush,
3079 INT x, INT y, INT width, INT height)
3085 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
3087 if(!graphics || !brush)
3088 return InvalidParameter;
3095 FIXME("graphics object has no HDC\n");
3101 ptf[1].X = x + width;
3103 ptf[2].X = x + width;
3104 ptf[2].Y = y + height;
3106 ptf[3].Y = y + height;
3108 save_state = SaveDC(graphics->hdc);
3109 EndPath(graphics->hdc);
3111 transform_and_round_points(graphics, pti, ptf, 4);
3113 BeginPath(graphics->hdc);
3114 Polygon(graphics->hdc, pti, 4);
3115 EndPath(graphics->hdc);
3117 brush_fill_path(graphics, brush);
3119 RestoreDC(graphics->hdc, save_state);
3124 GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRectF *rects,
3130 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3133 return InvalidParameter;
3135 for(i = 0; i < count; i++){
3136 ret = GdipFillRectangle(graphics, brush, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
3137 if(ret != Ok) return ret;
3143 GpStatus WINGDIPAPI GdipFillRectanglesI(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRect *rects,
3150 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3152 if(!rects || count <= 0)
3153 return InvalidParameter;
3155 rectsF = GdipAlloc(sizeof(GpRectF)*count);
3159 for(i = 0; i < count; i++){
3160 rectsF[i].X = (REAL)rects[i].X;
3161 rectsF[i].Y = (REAL)rects[i].Y;
3162 rectsF[i].X = (REAL)rects[i].Width;
3163 rectsF[i].Height = (REAL)rects[i].Height;
3166 ret = GdipFillRectangles(graphics,brush,rectsF,count);
3172 /*****************************************************************************
3173 * GdipFillRegion [GDIPLUS.@]
3175 GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
3183 TRACE("(%p, %p, %p)\n", graphics, brush, region);
3185 if (!(graphics && brush && region))
3186 return InvalidParameter;
3193 FIXME("graphics object has no HDC\n");
3197 status = GdipGetRegionHRgn(region, graphics, &hrgn);
3201 save_state = SaveDC(graphics->hdc);
3202 EndPath(graphics->hdc);
3204 ExtSelectClipRgn(graphics->hdc, hrgn, RGN_AND);
3206 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
3208 BeginPath(graphics->hdc);
3209 Rectangle(graphics->hdc, rc.left, rc.top, rc.right, rc.bottom);
3210 EndPath(graphics->hdc);
3212 brush_fill_path(graphics, brush);
3215 RestoreDC(graphics->hdc, save_state);
3222 GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention)
3224 TRACE("(%p,%u)\n", graphics, intention);
3227 return InvalidParameter;
3232 /* We have no internal operation queue, so there's no need to clear it. */
3240 /*****************************************************************************
3241 * GdipGetClipBounds [GDIPLUS.@]
3243 GpStatus WINGDIPAPI GdipGetClipBounds(GpGraphics *graphics, GpRectF *rect)
3245 TRACE("(%p, %p)\n", graphics, rect);
3248 return InvalidParameter;
3253 return GdipGetRegionBounds(graphics->clip, graphics, rect);
3256 /*****************************************************************************
3257 * GdipGetClipBoundsI [GDIPLUS.@]
3259 GpStatus WINGDIPAPI GdipGetClipBoundsI(GpGraphics *graphics, GpRect *rect)
3261 TRACE("(%p, %p)\n", graphics, rect);
3264 return InvalidParameter;
3269 return GdipGetRegionBoundsI(graphics->clip, graphics, rect);
3272 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3273 GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics,
3274 CompositingMode *mode)
3276 TRACE("(%p, %p)\n", graphics, mode);
3278 if(!graphics || !mode)
3279 return InvalidParameter;
3284 *mode = graphics->compmode;
3289 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3290 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
3291 CompositingQuality *quality)
3293 TRACE("(%p, %p)\n", graphics, quality);
3295 if(!graphics || !quality)
3296 return InvalidParameter;
3301 *quality = graphics->compqual;
3306 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3307 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
3308 InterpolationMode *mode)
3310 TRACE("(%p, %p)\n", graphics, mode);
3312 if(!graphics || !mode)
3313 return InvalidParameter;
3318 *mode = graphics->interpolation;
3323 /* FIXME: Need to handle color depths less than 24bpp */
3324 GpStatus WINGDIPAPI GdipGetNearestColor(GpGraphics *graphics, ARGB* argb)
3326 FIXME("(%p, %p): Passing color unmodified\n", graphics, argb);
3328 if(!graphics || !argb)
3329 return InvalidParameter;
3337 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
3339 TRACE("(%p, %p)\n", graphics, scale);
3341 if(!graphics || !scale)
3342 return InvalidParameter;
3347 *scale = graphics->scale;
3352 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
3354 TRACE("(%p, %p)\n", graphics, unit);
3356 if(!graphics || !unit)
3357 return InvalidParameter;
3362 *unit = graphics->unit;
3367 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3368 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
3371 TRACE("(%p, %p)\n", graphics, mode);
3373 if(!graphics || !mode)
3374 return InvalidParameter;
3379 *mode = graphics->pixeloffset;
3384 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3385 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
3387 TRACE("(%p, %p)\n", graphics, mode);
3389 if(!graphics || !mode)
3390 return InvalidParameter;
3395 *mode = graphics->smoothing;
3400 GpStatus WINGDIPAPI GdipGetTextContrast(GpGraphics *graphics, UINT *contrast)
3402 TRACE("(%p, %p)\n", graphics, contrast);
3404 if(!graphics || !contrast)
3405 return InvalidParameter;
3407 *contrast = graphics->textcontrast;
3412 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3413 GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics,
3414 TextRenderingHint *hint)
3416 TRACE("(%p, %p)\n", graphics, hint);
3418 if(!graphics || !hint)
3419 return InvalidParameter;
3424 *hint = graphics->texthint;
3429 GpStatus WINGDIPAPI GdipGetVisibleClipBounds(GpGraphics *graphics, GpRectF *rect)
3434 TRACE("(%p, %p)\n", graphics, rect);
3436 if(!graphics || !rect)
3437 return InvalidParameter;
3442 /* intersect window and graphics clipping regions */
3443 if((stat = GdipCreateRegion(&clip_rgn)) != Ok)
3446 if((stat = get_visible_clip_region(graphics, clip_rgn)) != Ok)
3449 /* get bounds of the region */
3450 stat = GdipGetRegionBounds(clip_rgn, graphics, rect);
3453 GdipDeleteRegion(clip_rgn);
3458 GpStatus WINGDIPAPI GdipGetVisibleClipBoundsI(GpGraphics *graphics, GpRect *rect)
3463 TRACE("(%p, %p)\n", graphics, rect);
3465 if(!graphics || !rect)
3466 return InvalidParameter;
3468 if((stat = GdipGetVisibleClipBounds(graphics, &rectf)) == Ok)
3470 rect->X = roundr(rectf.X);
3471 rect->Y = roundr(rectf.Y);
3472 rect->Width = roundr(rectf.Width);
3473 rect->Height = roundr(rectf.Height);
3479 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
3481 TRACE("(%p, %p)\n", graphics, matrix);
3483 if(!graphics || !matrix)
3484 return InvalidParameter;
3489 *matrix = *graphics->worldtrans;
3493 GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color)
3499 TRACE("(%p, %x)\n", graphics, color);
3502 return InvalidParameter;
3507 if((stat = GdipCreateSolidFill(color, &brush)) != Ok)
3510 if((stat = get_graphics_bounds(graphics, &wnd_rect)) != Ok){
3511 GdipDeleteBrush((GpBrush*)brush);
3515 GdipFillRectangle(graphics, (GpBrush*)brush, wnd_rect.X, wnd_rect.Y,
3516 wnd_rect.Width, wnd_rect.Height);
3518 GdipDeleteBrush((GpBrush*)brush);
3523 GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics *graphics, BOOL *res)
3525 TRACE("(%p, %p)\n", graphics, res);
3527 if(!graphics || !res)
3528 return InvalidParameter;
3530 return GdipIsEmptyRegion(graphics->clip, graphics, res);
3533 GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics *graphics, REAL x, REAL y, BOOL *result)
3539 TRACE("(%p, %.2f, %.2f, %p)\n", graphics, x, y, result);
3541 if(!graphics || !result)
3542 return InvalidParameter;
3549 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3550 CoordinateSpaceWorld, &pt, 1)) != Ok)
3553 if((stat = GdipCreateRegion(&rgn)) != Ok)
3556 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3559 stat = GdipIsVisibleRegionPoint(rgn, pt.X, pt.Y, graphics, result);
3562 GdipDeleteRegion(rgn);
3566 GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics *graphics, INT x, INT y, BOOL *result)
3568 return GdipIsVisiblePoint(graphics, (REAL)x, (REAL)y, result);
3571 GpStatus WINGDIPAPI GdipIsVisibleRect(GpGraphics *graphics, REAL x, REAL y, REAL width, REAL height, BOOL *result)
3577 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics, x, y, width, height, result);
3579 if(!graphics || !result)
3580 return InvalidParameter;
3587 pts[1].X = x + width;
3588 pts[1].Y = y + height;
3590 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3591 CoordinateSpaceWorld, pts, 2)) != Ok)
3594 pts[1].X -= pts[0].X;
3595 pts[1].Y -= pts[0].Y;
3597 if((stat = GdipCreateRegion(&rgn)) != Ok)
3600 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3603 stat = GdipIsVisibleRegionRect(rgn, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y, graphics, result);
3606 GdipDeleteRegion(rgn);
3610 GpStatus WINGDIPAPI GdipIsVisibleRectI(GpGraphics *graphics, INT x, INT y, INT width, INT height, BOOL *result)
3612 return GdipIsVisibleRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, result);
3615 typedef GpStatus (*gdip_format_string_callback)(GpGraphics *graphics,
3616 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3617 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3618 INT lineno, const RectF *bounds, void *user_data);
3620 static GpStatus gdip_format_string(GpGraphics *graphics,
3621 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
3622 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3623 gdip_format_string_callback callback, void *user_data)
3626 int sum = 0, height = 0, fit, fitcpy, i, j, lret, nwidth,
3627 nheight, lineend, lineno = 0;
3629 StringAlignment halign;
3633 if(length == -1) length = lstrlenW(string);
3635 stringdup = GdipAlloc((length + 1) * sizeof(WCHAR));
3636 if(!stringdup) return OutOfMemory;
3638 nwidth = roundr(rect->Width);
3639 nheight = roundr(rect->Height);
3641 if (rect->Width >= INT_MAX || rect->Width < 0.5) nwidth = INT_MAX;
3642 if (rect->Height >= INT_MAX || rect->Width < 0.5) nheight = INT_MAX;
3644 for(i = 0, j = 0; i < length; i++){
3645 /* FIXME: This makes the indexes passed to callback inaccurate. */
3646 if(!isprintW(string[i]) && (string[i] != '\n'))
3649 stringdup[j] = string[i];
3655 if (format) halign = format->align;
3656 else halign = StringAlignmentNear;
3658 while(sum < length){
3659 GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum,
3660 nwidth, &fit, NULL, &size);
3666 for(lret = 0; lret < fit; lret++)
3667 if(*(stringdup + sum + lret) == '\n')
3670 /* Line break code (may look strange, but it imitates windows). */
3672 lineend = fit = lret; /* this is not an off-by-one error */
3673 else if(fit < (length - sum)){
3674 if(*(stringdup + sum + fit) == ' ')
3675 while(*(stringdup + sum + fit) == ' ')
3678 while(*(stringdup + sum + fit - 1) != ' '){
3681 if(*(stringdup + sum + fit) == '\t')
3690 while(*(stringdup + sum + lineend - 1) == ' ' ||
3691 *(stringdup + sum + lineend - 1) == '\t')
3697 GetTextExtentExPointW(graphics->hdc, stringdup + sum, lineend,
3698 nwidth, &j, NULL, &size);
3700 bounds.Width = size.cx;
3702 if(height + size.cy > nheight)
3703 bounds.Height = nheight - (height + size.cy);
3705 bounds.Height = size.cy;
3707 bounds.Y = rect->Y + height;
3711 case StringAlignmentNear:
3715 case StringAlignmentCenter:
3716 bounds.X = rect->X + (rect->Width/2) - (bounds.Width/2);
3718 case StringAlignmentFar:
3719 bounds.X = rect->X + rect->Width - bounds.Width;
3723 stat = callback(graphics, stringdup, sum, lineend,
3724 font, rect, format, lineno, &bounds, user_data);
3729 sum += fit + (lret < fitcpy ? 1 : 0);
3733 if(height > nheight)
3736 /* Stop if this was a linewrap (but not if it was a linebreak). */
3737 if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
3741 GdipFree(stringdup);
3746 struct measure_ranges_args {
3750 static GpStatus measure_ranges_callback(GpGraphics *graphics,
3751 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3752 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3753 INT lineno, const RectF *bounds, void *user_data)
3757 struct measure_ranges_args *args = user_data;
3759 for (i=0; i<format->range_count; i++)
3761 INT range_start = max(index, format->character_ranges[i].First);
3762 INT range_end = min(index+length, format->character_ranges[i].First+format->character_ranges[i].Length);
3763 if (range_start < range_end)
3768 range_rect.Y = bounds->Y;
3769 range_rect.Height = bounds->Height;
3771 GetTextExtentExPointW(graphics->hdc, string + index, range_start - index,
3772 INT_MAX, NULL, NULL, &range_size);
3773 range_rect.X = bounds->X + range_size.cx;
3775 GetTextExtentExPointW(graphics->hdc, string + index, range_end - index,
3776 INT_MAX, NULL, NULL, &range_size);
3777 range_rect.Width = (bounds->X + range_size.cx) - range_rect.X;
3779 stat = GdipCombineRegionRect(args->regions[i], &range_rect, CombineModeUnion);
3788 GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,
3789 GDIPCONST WCHAR* string, INT length, GDIPCONST GpFont* font,
3790 GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat *stringFormat,
3791 INT regionCount, GpRegion** regions)
3796 struct measure_ranges_args args;
3798 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics, debugstr_w(string),
3799 length, font, debugstr_rectf(layoutRect), stringFormat, regionCount, regions);
3801 if (!(graphics && string && font && layoutRect && stringFormat && regions))
3802 return InvalidParameter;
3804 if (regionCount < stringFormat->range_count)
3805 return InvalidParameter;
3809 FIXME("graphics object has no HDC\n");
3810 return NotImplemented;
3813 if (stringFormat->attr)
3814 TRACE("may be ignoring some format flags: attr %x\n", stringFormat->attr);
3816 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
3818 for (i=0; i<stringFormat->range_count; i++)
3820 stat = GdipSetEmpty(regions[i]);
3825 args.regions = regions;
3827 stat = gdip_format_string(graphics, string, length, font, layoutRect, stringFormat,
3828 measure_ranges_callback, &args);
3830 DeleteObject(SelectObject(graphics->hdc, oldfont));
3835 struct measure_string_args {
3837 INT *codepointsfitted;
3841 static GpStatus measure_string_callback(GpGraphics *graphics,
3842 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3843 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3844 INT lineno, const RectF *bounds, void *user_data)
3846 struct measure_string_args *args = user_data;
3848 if (bounds->Width > args->bounds->Width)
3849 args->bounds->Width = bounds->Width;
3851 if (bounds->Height + bounds->Y > args->bounds->Height + args->bounds->Y)
3852 args->bounds->Height = bounds->Height + bounds->Y - args->bounds->Y;
3854 if (args->codepointsfitted)
3855 *args->codepointsfitted = index + length;
3857 if (args->linesfilled)
3858 (*args->linesfilled)++;
3863 /* Find the smallest rectangle that bounds the text when it is printed in rect
3864 * according to the format options listed in format. If rect has 0 width and
3865 * height, then just find the smallest rectangle that bounds the text when it's
3866 * printed at location (rect->X, rect-Y). */
3867 GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
3868 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
3869 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
3870 INT *codepointsfitted, INT *linesfilled)
3873 struct measure_string_args args;
3875 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics,
3876 debugstr_wn(string, length), length, font, debugstr_rectf(rect), format,
3877 bounds, codepointsfitted, linesfilled);
3879 if(!graphics || !string || !font || !rect || !bounds)
3880 return InvalidParameter;
3884 FIXME("graphics object has no HDC\n");
3885 return NotImplemented;
3888 if(linesfilled) *linesfilled = 0;
3889 if(codepointsfitted) *codepointsfitted = 0;
3892 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
3894 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
3896 bounds->X = rect->X;
3897 bounds->Y = rect->Y;
3898 bounds->Width = 0.0;
3899 bounds->Height = 0.0;
3901 args.bounds = bounds;
3902 args.codepointsfitted = codepointsfitted;
3903 args.linesfilled = linesfilled;
3905 gdip_format_string(graphics, string, length, font, rect, format,
3906 measure_string_callback, &args);
3908 DeleteObject(SelectObject(graphics->hdc, oldfont));
3913 struct draw_string_args {
3916 REAL ang_cos, ang_sin;
3919 static GpStatus draw_string_callback(GpGraphics *graphics,
3920 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3921 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3922 INT lineno, const RectF *bounds, void *user_data)
3924 struct draw_string_args *args = user_data;
3927 drawcoord.left = drawcoord.right = args->drawbase.x + roundr(args->ang_sin * bounds->Y);
3928 drawcoord.top = drawcoord.bottom = args->drawbase.y + roundr(args->ang_cos * bounds->Y);
3930 DrawTextW(graphics->hdc, string + index, length, &drawcoord, args->drawflags);
3935 GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string,
3936 INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect,
3937 GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush)
3942 TEXTMETRICW textmet;
3943 GpPointF pt[3], rectcpy[4];
3945 REAL angle, rel_width, rel_height;
3946 INT offsety = 0, save_state;
3947 struct draw_string_args args;
3950 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length),
3951 length, font, debugstr_rectf(rect), format, brush);
3953 if(!graphics || !string || !font || !brush || !rect)
3954 return InvalidParameter;
3956 if((brush->bt != BrushTypeSolidColor)){
3957 FIXME("not implemented for given parameters\n");
3958 return NotImplemented;
3963 FIXME("graphics object has no HDC\n");
3964 return NotImplemented;
3968 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
3970 /* Should be no need to explicitly test for StringAlignmentNear as
3971 * that is default behavior if no alignment is passed. */
3972 if(format->vertalign != StringAlignmentNear){
3974 GdipMeasureString(graphics, string, length, font, rect, format, &bounds, 0, 0);
3976 if(format->vertalign == StringAlignmentCenter)
3977 offsety = (rect->Height - bounds.Height) / 2;
3978 else if(format->vertalign == StringAlignmentFar)
3979 offsety = (rect->Height - bounds.Height);
3983 save_state = SaveDC(graphics->hdc);
3984 SetBkMode(graphics->hdc, TRANSPARENT);
3985 SetTextColor(graphics->hdc, brush->lb.lbColor);
3993 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
3994 angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X));
3995 args.ang_cos = cos(angle);
3996 args.ang_sin = sin(angle);
3997 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
3998 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
3999 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
4000 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
4002 rectcpy[3].X = rectcpy[0].X = rect->X;
4003 rectcpy[1].Y = rectcpy[0].Y = rect->Y + offsety;
4004 rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width;
4005 rectcpy[3].Y = rectcpy[2].Y = rect->Y + offsety + rect->Height;
4006 transform_and_round_points(graphics, corners, rectcpy, 4);
4008 scaled_rect.X = 0.0;
4009 scaled_rect.Y = 0.0;
4010 scaled_rect.Width = rel_width * rect->Width;
4011 scaled_rect.Height = rel_height * rect->Height;
4013 if (roundr(scaled_rect.Width) != 0 && roundr(scaled_rect.Height) != 0)
4015 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4016 rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
4017 SelectClipRgn(graphics->hdc, rgn);
4020 /* Use gdi to find the font, then perform transformations on it (height,
4022 SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
4023 GetTextMetricsW(graphics->hdc, &textmet);
4026 lfw.lfHeight = roundr(((REAL)lfw.lfHeight) * rel_height);
4027 lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width);
4029 lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0);
4031 gdifont = CreateFontIndirectW(&lfw);
4032 DeleteObject(SelectObject(graphics->hdc, CreateFontIndirectW(&lfw)));
4034 if (!format || format->align == StringAlignmentNear)
4036 args.drawbase.x = corners[0].x;
4037 args.drawbase.y = corners[0].y;
4038 args.drawflags = DT_NOCLIP | DT_EXPANDTABS;
4040 else if (format->align == StringAlignmentCenter)
4042 args.drawbase.x = (corners[0].x + corners[1].x)/2;
4043 args.drawbase.y = (corners[0].y + corners[1].y)/2;
4044 args.drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_CENTER;
4046 else /* (format->align == StringAlignmentFar) */
4048 args.drawbase.x = corners[1].x;
4049 args.drawbase.y = corners[1].y;
4050 args.drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_RIGHT;
4053 gdip_format_string(graphics, string, length, font, &scaled_rect, format,
4054 draw_string_callback, &args);
4057 DeleteObject(gdifont);
4059 RestoreDC(graphics->hdc, save_state);
4064 GpStatus WINGDIPAPI GdipResetClip(GpGraphics *graphics)
4066 TRACE("(%p)\n", graphics);
4069 return InvalidParameter;
4074 return GdipSetInfinite(graphics->clip);
4077 GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics)
4079 TRACE("(%p)\n", graphics);
4082 return InvalidParameter;
4087 graphics->worldtrans->matrix[0] = 1.0;
4088 graphics->worldtrans->matrix[1] = 0.0;
4089 graphics->worldtrans->matrix[2] = 0.0;
4090 graphics->worldtrans->matrix[3] = 1.0;
4091 graphics->worldtrans->matrix[4] = 0.0;
4092 graphics->worldtrans->matrix[5] = 0.0;
4097 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
4099 return GdipEndContainer(graphics, state);
4102 GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
4103 GpMatrixOrder order)
4105 TRACE("(%p, %.2f, %d)\n", graphics, angle, order);
4108 return InvalidParameter;
4113 return GdipRotateMatrix(graphics->worldtrans, angle, order);
4116 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
4118 return GdipBeginContainer2(graphics, state);
4121 GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics *graphics,
4122 GraphicsContainer *state)
4124 GraphicsContainerItem *container;
4127 TRACE("(%p, %p)\n", graphics, state);
4129 if(!graphics || !state)
4130 return InvalidParameter;
4132 sts = init_container(&container, graphics);
4136 list_add_head(&graphics->containers, &container->entry);
4137 *state = graphics->contid = container->contid;
4142 GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics *graphics, GDIPCONST GpRectF *dstrect, GDIPCONST GpRectF *srcrect, GpUnit unit, GraphicsContainer *state)
4144 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
4145 return NotImplemented;
4148 GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics *graphics, GDIPCONST GpRect *dstrect, GDIPCONST GpRect *srcrect, GpUnit unit, GraphicsContainer *state)
4150 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
4151 return NotImplemented;
4154 GpStatus WINGDIPAPI GdipComment(GpGraphics *graphics, UINT sizeData, GDIPCONST BYTE *data)
4156 FIXME("(%p, %d, %p): stub\n", graphics, sizeData, data);
4157 return NotImplemented;
4160 GpStatus WINGDIPAPI GdipEndContainer(GpGraphics *graphics, GraphicsContainer state)
4163 GraphicsContainerItem *container, *container2;
4165 TRACE("(%p, %x)\n", graphics, state);
4168 return InvalidParameter;
4170 LIST_FOR_EACH_ENTRY(container, &graphics->containers, GraphicsContainerItem, entry){
4171 if(container->contid == state)
4175 /* did not find a matching container */
4176 if(&container->entry == &graphics->containers)
4179 sts = restore_container(graphics, container);
4183 /* remove all of the containers on top of the found container */
4184 LIST_FOR_EACH_ENTRY_SAFE(container, container2, &graphics->containers, GraphicsContainerItem, entry){
4185 if(container->contid == state)
4187 list_remove(&container->entry);
4188 delete_container(container);
4191 list_remove(&container->entry);
4192 delete_container(container);
4197 GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
4198 REAL sy, GpMatrixOrder order)
4200 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, sx, sy, order);
4203 return InvalidParameter;
4208 return GdipScaleMatrix(graphics->worldtrans, sx, sy, order);
4211 GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics *graphics, GpGraphics *srcgraphics,
4214 TRACE("(%p, %p, %d)\n", graphics, srcgraphics, mode);
4216 if(!graphics || !srcgraphics)
4217 return InvalidParameter;
4219 return GdipCombineRegionRegion(graphics->clip, srcgraphics->clip, mode);
4222 GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
4223 CompositingMode mode)
4225 TRACE("(%p, %d)\n", graphics, mode);
4228 return InvalidParameter;
4233 graphics->compmode = mode;
4238 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
4239 CompositingQuality quality)
4241 TRACE("(%p, %d)\n", graphics, quality);
4244 return InvalidParameter;
4249 graphics->compqual = quality;
4254 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
4255 InterpolationMode mode)
4257 TRACE("(%p, %d)\n", graphics, mode);
4260 return InvalidParameter;
4265 graphics->interpolation = mode;
4270 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
4272 TRACE("(%p, %.2f)\n", graphics, scale);
4274 if(!graphics || (scale <= 0.0))
4275 return InvalidParameter;
4280 graphics->scale = scale;
4285 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
4287 TRACE("(%p, %d)\n", graphics, unit);
4290 return InvalidParameter;
4295 if(unit == UnitWorld)
4296 return InvalidParameter;
4298 graphics->unit = unit;
4303 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
4306 TRACE("(%p, %d)\n", graphics, mode);
4309 return InvalidParameter;
4314 graphics->pixeloffset = mode;
4319 GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics *graphics, INT x, INT y)
4323 TRACE("(%p,%i,%i)\n", graphics, x, y);
4326 FIXME("not implemented\n");
4328 return NotImplemented;
4331 GpStatus WINGDIPAPI GdipGetRenderingOrigin(GpGraphics *graphics, INT *x, INT *y)
4335 TRACE("(%p,%p,%p)\n", graphics, x, y);
4338 FIXME("not implemented\n");
4342 return NotImplemented;
4345 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
4347 TRACE("(%p, %d)\n", graphics, mode);
4350 return InvalidParameter;
4355 graphics->smoothing = mode;
4360 GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics *graphics, UINT contrast)
4362 TRACE("(%p, %d)\n", graphics, contrast);
4365 return InvalidParameter;
4367 graphics->textcontrast = contrast;
4372 GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
4373 TextRenderingHint hint)
4375 TRACE("(%p, %d)\n", graphics, hint);
4378 return InvalidParameter;
4383 graphics->texthint = hint;
4388 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
4390 TRACE("(%p, %p)\n", graphics, matrix);
4392 if(!graphics || !matrix)
4393 return InvalidParameter;
4398 GdipDeleteMatrix(graphics->worldtrans);
4399 return GdipCloneMatrix(matrix, &graphics->worldtrans);
4402 GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
4403 REAL dy, GpMatrixOrder order)
4405 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, dx, dy, order);
4408 return InvalidParameter;
4413 return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order);
4416 /*****************************************************************************
4417 * GdipSetClipHrgn [GDIPLUS.@]
4419 GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics *graphics, HRGN hrgn, CombineMode mode)
4424 TRACE("(%p, %p, %d)\n", graphics, hrgn, mode);
4427 return InvalidParameter;
4429 status = GdipCreateRegionHrgn(hrgn, ®ion);
4433 status = GdipSetClipRegion(graphics, region, mode);
4435 GdipDeleteRegion(region);
4439 GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics *graphics, GpPath *path, CombineMode mode)
4441 TRACE("(%p, %p, %d)\n", graphics, path, mode);
4444 return InvalidParameter;
4449 return GdipCombineRegionPath(graphics->clip, path, mode);
4452 GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y,
4453 REAL width, REAL height,
4458 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics, x, y, width, height, mode);
4461 return InvalidParameter;
4469 rect.Height = height;
4471 return GdipCombineRegionRect(graphics->clip, &rect, mode);
4474 GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y,
4475 INT width, INT height,
4478 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics, x, y, width, height, mode);
4481 return InvalidParameter;
4486 return GdipSetClipRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, mode);
4489 GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
4492 TRACE("(%p, %p, %d)\n", graphics, region, mode);
4494 if(!graphics || !region)
4495 return InvalidParameter;
4500 return GdipCombineRegionRegion(graphics->clip, region, mode);
4503 GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile *metafile,
4508 TRACE("(%p,%u)\n", metafile, limitDpi);
4511 FIXME("not implemented\n");
4513 return NotImplemented;
4516 GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points,
4522 TRACE("(%p, %p, %d)\n", graphics, points, count);
4524 if(!graphics || !pen || count<=0)
4525 return InvalidParameter;
4530 pti = GdipAlloc(sizeof(POINT) * count);
4532 save_state = prepare_dc(graphics, pen);
4533 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
4535 transform_and_round_points(graphics, pti, (GpPointF*)points, count);
4536 Polygon(graphics->hdc, pti, count);
4538 restore_dc(graphics, save_state);
4544 GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points,
4551 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
4553 if(count<=0) return InvalidParameter;
4554 ptf = GdipAlloc(sizeof(GpPointF) * count);
4556 for(i = 0;i < count; i++){
4557 ptf[i].X = (REAL)points[i].X;
4558 ptf[i].Y = (REAL)points[i].Y;
4561 ret = GdipDrawPolygon(graphics,pen,ptf,count);
4567 GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
4569 TRACE("(%p, %p)\n", graphics, dpi);
4571 if(!graphics || !dpi)
4572 return InvalidParameter;
4577 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
4582 GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
4584 TRACE("(%p, %p)\n", graphics, dpi);
4586 if(!graphics || !dpi)
4587 return InvalidParameter;
4592 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
4597 GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix,
4598 GpMatrixOrder order)
4603 TRACE("(%p, %p, %d)\n", graphics, matrix, order);
4605 if(!graphics || !matrix)
4606 return InvalidParameter;
4611 m = *(graphics->worldtrans);
4613 ret = GdipMultiplyMatrix(&m, matrix, order);
4615 *(graphics->worldtrans) = m;
4620 GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
4622 TRACE("(%p, %p)\n", graphics, hdc);
4624 if(!graphics || !hdc)
4625 return InvalidParameter;
4632 WARN("no HDC for this graphics\n");
4634 return GenericError;
4637 *hdc = graphics->hdc;
4638 graphics->busy = TRUE;
4643 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
4645 TRACE("(%p, %p)\n", graphics, hdc);
4648 return InvalidParameter;
4650 if(graphics->hdc != hdc || !(graphics->busy))
4651 return InvalidParameter;
4653 graphics->busy = FALSE;
4658 GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
4663 TRACE("(%p, %p)\n", graphics, region);
4665 if(!graphics || !region)
4666 return InvalidParameter;
4671 if((status = GdipCloneRegion(graphics->clip, &clip)) != Ok)
4674 /* free everything except root node and header */
4675 delete_element(®ion->node);
4676 memcpy(region, clip, sizeof(GpRegion));
4682 GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space,
4683 GpCoordinateSpace src_space, GpPointF *points, INT count)
4689 if(!graphics || !points || count <= 0)
4690 return InvalidParameter;
4695 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
4697 if (src_space == dst_space) return Ok;
4699 stat = GdipCreateMatrix(&matrix);
4702 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
4704 if(graphics->unit != UnitDisplay)
4705 unitscale *= graphics->scale;
4707 /* transform from src_space to CoordinateSpacePage */
4710 case CoordinateSpaceWorld:
4711 GdipMultiplyMatrix(matrix, graphics->worldtrans, MatrixOrderAppend);
4713 case CoordinateSpacePage:
4715 case CoordinateSpaceDevice:
4716 GdipScaleMatrix(matrix, 1.0/unitscale, 1.0/unitscale, MatrixOrderAppend);
4720 /* transform from CoordinateSpacePage to dst_space */
4723 case CoordinateSpaceWorld:
4725 GpMatrix *inverted_transform;
4726 stat = GdipCloneMatrix(graphics->worldtrans, &inverted_transform);
4729 stat = GdipInvertMatrix(inverted_transform);
4731 GdipMultiplyMatrix(matrix, inverted_transform, MatrixOrderAppend);
4732 GdipDeleteMatrix(inverted_transform);
4736 case CoordinateSpacePage:
4738 case CoordinateSpaceDevice:
4739 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
4744 stat = GdipTransformMatrixPoints(matrix, points, count);
4746 GdipDeleteMatrix(matrix);
4752 GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space,
4753 GpCoordinateSpace src_space, GpPoint *points, INT count)
4759 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
4762 return InvalidParameter;
4764 pointsF = GdipAlloc(sizeof(GpPointF) * count);
4768 for(i = 0; i < count; i++){
4769 pointsF[i].X = (REAL)points[i].X;
4770 pointsF[i].Y = (REAL)points[i].Y;
4773 ret = GdipTransformPoints(graphics, dst_space, src_space, pointsF, count);
4776 for(i = 0; i < count; i++){
4777 points[i].X = roundr(pointsF[i].X);
4778 points[i].Y = roundr(pointsF[i].Y);
4785 HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void)
4797 /*****************************************************************************
4798 * GdipTranslateClip [GDIPLUS.@]
4800 GpStatus WINGDIPAPI GdipTranslateClip(GpGraphics *graphics, REAL dx, REAL dy)
4802 TRACE("(%p, %.2f, %.2f)\n", graphics, dx, dy);
4805 return InvalidParameter;
4810 return GdipTranslateRegion(graphics->clip, dx, dy);
4813 /*****************************************************************************
4814 * GdipTranslateClipI [GDIPLUS.@]
4816 GpStatus WINGDIPAPI GdipTranslateClipI(GpGraphics *graphics, INT dx, INT dy)
4818 TRACE("(%p, %d, %d)\n", graphics, dx, dy);
4821 return InvalidParameter;
4826 return GdipTranslateRegion(graphics->clip, (REAL)dx, (REAL)dy);
4830 /*****************************************************************************
4831 * GdipMeasureDriverString [GDIPLUS.@]
4833 GpStatus WINGDIPAPI GdipMeasureDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
4834 GDIPCONST GpFont *font, GDIPCONST PointF *positions,
4835 INT flags, GDIPCONST GpMatrix *matrix, RectF *boundingBox)
4837 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics, text, length, font, positions, flags, matrix, boundingBox);
4838 return NotImplemented;
4841 /*****************************************************************************
4842 * GdipDrawDriverString [GDIPLUS.@]
4844 GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
4845 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
4846 GDIPCONST PointF *positions, INT flags,
4847 GDIPCONST GpMatrix *matrix )
4849 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics, text, length, font, brush, positions, flags, matrix);
4850 return NotImplemented;
4853 GpStatus WINGDIPAPI GdipRecordMetafile(HDC hdc, EmfType type, GDIPCONST GpRectF *frameRect,
4854 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
4856 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
4857 return NotImplemented;
4860 /*****************************************************************************
4861 * GdipRecordMetafileI [GDIPLUS.@]
4863 GpStatus WINGDIPAPI GdipRecordMetafileI(HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
4864 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
4866 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
4867 return NotImplemented;
4870 GpStatus WINGDIPAPI GdipRecordMetafileStream(IStream *stream, HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
4871 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
4873 FIXME("(%p %p %d %p %d %p %p): stub\n", stream, hdc, type, frameRect, frameUnit, desc, metafile);
4874 return NotImplemented;
4877 /*****************************************************************************
4878 * GdipIsVisibleClipEmpty [GDIPLUS.@]
4880 GpStatus WINGDIPAPI GdipIsVisibleClipEmpty(GpGraphics *graphics, BOOL *res)
4885 TRACE("(%p, %p)\n", graphics, res);
4887 if((stat = GdipCreateRegion(&rgn)) != Ok)
4890 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
4893 stat = GdipIsEmptyRegion(rgn, graphics, res);
4896 GdipDeleteRegion(rgn);