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];
101 save_state = SaveDC(graphics->hdc);
103 EndPath(graphics->hdc);
105 if(pen->unit == UnitPixel){
109 /* Get an estimate for the amount the pen width is affected by the world
110 * transform. (This is similar to what some of the wine drivers do.) */
115 GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
116 width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
117 (pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
119 width *= pen->width * convert_unit(graphics_res(graphics),
120 pen->unit == UnitWorld ? graphics->unit : pen->unit);
123 if(pen->dash == DashStyleCustom){
124 numdashes = min(pen->numdashes, MAX_DASHLEN);
126 TRACE("dashes are: ");
127 for(i = 0; i < numdashes; i++){
128 dash_array[i] = roundr(width * pen->dashes[i]);
129 TRACE("%d, ", dash_array[i]);
131 TRACE("\n and the pen style is %x\n", pen->style);
133 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb,
134 numdashes, dash_array);
137 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, 0, NULL);
139 SelectObject(graphics->hdc, gdipen);
144 static void restore_dc(GpGraphics *graphics, INT state)
146 DeleteObject(SelectObject(graphics->hdc, GetStockObject(NULL_PEN)));
147 RestoreDC(graphics->hdc, state);
150 static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace dst_space,
151 GpCoordinateSpace src_space, GpMatrix **matrix);
153 /* This helper applies all the changes that the points listed in ptf need in
154 * order to be drawn on the device context. In the end, this should include at
156 * -scaling by page unit
157 * -applying world transformation
158 * -converting from float to int
159 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
160 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
161 * gdi to draw, and these functions would irreparably mess with line widths.
163 static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
164 GpPointF *ptf, INT count)
170 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
172 /* apply page scale */
173 if(graphics->unit != UnitDisplay)
174 unitscale *= graphics->scale;
176 GdipCloneMatrix(graphics->worldtrans, &matrix);
177 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
178 GdipTransformMatrixPoints(matrix, ptf, count);
179 GdipDeleteMatrix(matrix);
181 for(i = 0; i < count; i++){
182 pti[i].x = roundr(ptf[i].X);
183 pti[i].y = roundr(ptf[i].Y);
187 /* Draw non-premultiplied ARGB data to the given graphics object */
188 static GpStatus alpha_blend_pixels(GpGraphics *graphics, INT dst_x, INT dst_y,
189 const BYTE *src, INT src_width, INT src_height, INT src_stride)
191 if (graphics->image && graphics->image->type == ImageTypeBitmap)
193 GpBitmap *dst_bitmap = (GpBitmap*)graphics->image;
196 for (x=0; x<src_width; x++)
198 for (y=0; y<src_height; y++)
200 ARGB dst_color, src_color;
201 GdipBitmapGetPixel(dst_bitmap, x+dst_x, y+dst_y, &dst_color);
202 src_color = ((ARGB*)(src + src_stride * y))[x];
203 GdipBitmapSetPixel(dst_bitmap, x+dst_x, y+dst_y, color_over(dst_color, src_color));
212 HBITMAP hbitmap, old_hbm=NULL;
213 BITMAPINFOHEADER bih;
217 hdc = CreateCompatibleDC(0);
219 bih.biSize = sizeof(BITMAPINFOHEADER);
220 bih.biWidth = src_width;
221 bih.biHeight = -src_height;
224 bih.biCompression = BI_RGB;
226 bih.biXPelsPerMeter = 0;
227 bih.biYPelsPerMeter = 0;
229 bih.biClrImportant = 0;
231 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
232 (void**)&temp_bits, NULL, 0);
234 convert_32bppARGB_to_32bppPARGB(src_width, src_height, temp_bits,
235 4 * src_width, src, src_stride);
237 old_hbm = SelectObject(hdc, hbitmap);
239 bf.BlendOp = AC_SRC_OVER;
241 bf.SourceConstantAlpha = 255;
242 bf.AlphaFormat = AC_SRC_ALPHA;
244 GdiAlphaBlend(graphics->hdc, dst_x, dst_y, src_width, src_height,
245 hdc, 0, 0, src_width, src_height, bf);
247 SelectObject(hdc, old_hbm);
249 DeleteObject(hbitmap);
255 static ARGB blend_colors(ARGB start, ARGB end, REAL position)
261 a1 = (start >> 24) & 0xff;
262 a2 = (end >> 24) & 0xff;
264 a3 = (int)(a1*(1.0f - position)+a2*(position));
268 for (i=0xff; i<=0xff0000; i = i << 8)
269 result |= (int)((start&i)*(1.0f - position)+(end&i)*(position))&i;
273 static ARGB blend_line_gradient(GpLineGradient* brush, REAL position)
277 /* clamp to between 0.0 and 1.0, using the wrap mode */
278 if (brush->wrap == WrapModeTile)
280 position = fmodf(position, 1.0f);
281 if (position < 0.0f) position += 1.0f;
283 else /* WrapModeFlip* */
285 position = fmodf(position, 2.0f);
286 if (position < 0.0f) position += 2.0f;
287 if (position > 1.0f) position = 2.0f - position;
290 if (brush->blendcount == 1)
295 REAL left_blendpos, left_blendfac, right_blendpos, right_blendfac;
298 /* locate the blend positions surrounding this position */
299 while (position > brush->blendpos[i])
302 /* interpolate between the blend positions */
303 left_blendpos = brush->blendpos[i-1];
304 left_blendfac = brush->blendfac[i-1];
305 right_blendpos = brush->blendpos[i];
306 right_blendfac = brush->blendfac[i];
307 range = right_blendpos - left_blendpos;
308 blendfac = (left_blendfac * (right_blendpos - position) +
309 right_blendfac * (position - left_blendpos)) / range;
312 if (brush->pblendcount == 0)
313 return blend_colors(brush->startcolor, brush->endcolor, blendfac);
317 ARGB left_blendcolor, right_blendcolor;
318 REAL left_blendpos, right_blendpos;
320 /* locate the blend colors surrounding this position */
321 while (blendfac > brush->pblendpos[i])
324 /* interpolate between the blend colors */
325 left_blendpos = brush->pblendpos[i-1];
326 left_blendcolor = brush->pblendcolor[i-1];
327 right_blendpos = brush->pblendpos[i];
328 right_blendcolor = brush->pblendcolor[i];
329 blendfac = (blendfac - left_blendpos) / (right_blendpos - left_blendpos);
330 return blend_colors(left_blendcolor, right_blendcolor, blendfac);
334 static void brush_fill_path(GpGraphics *graphics, GpBrush* brush)
338 case BrushTypeLinearGradient:
340 GpLineGradient *line = (GpLineGradient*)brush;
343 SelectClipPath(graphics->hdc, RGN_AND);
344 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
346 GpPointF endpointsf[2];
350 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
352 endpointsf[0] = line->startpoint;
353 endpointsf[1] = line->endpoint;
354 transform_and_round_points(graphics, endpointsi, endpointsf, 2);
356 if (abs(endpointsi[0].x-endpointsi[1].x) > abs(endpointsi[0].y-endpointsi[1].y))
358 /* vertical-ish gradient */
359 int startx, endx; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
360 int startbottomx; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
363 HBRUSH hbrush, hprevbrush;
364 int leftx, rightx; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
366 int tilt; /* horizontal distance covered by a gradient line */
368 startx = roundr((rc.top - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X);
369 endx = roundr((rc.top - endpointsf[1].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[1].X);
370 width = endx - startx;
371 startbottomx = roundr((rc.bottom - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X);
372 tilt = startx - startbottomx;
374 if (startx >= startbottomx)
377 rightx = rc.right + tilt;
381 leftx = rc.left + tilt;
385 poly[0].y = rc.bottom;
388 poly[3].y = rc.bottom;
390 for (x=leftx; x<=rightx; x++)
392 ARGB argb = blend_line_gradient(line, (x-startx)/(REAL)width);
393 col = ARGB2COLORREF(argb);
394 hbrush = CreateSolidBrush(col);
395 hprevbrush = SelectObject(graphics->hdc, hbrush);
396 poly[0].x = x - tilt - 1;
399 poly[3].x = x - tilt;
400 Polygon(graphics->hdc, poly, 4);
401 SelectObject(graphics->hdc, hprevbrush);
402 DeleteObject(hbrush);
405 else if (endpointsi[0].y != endpointsi[1].y)
407 /* horizontal-ish gradient */
408 int starty, endy; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
409 int startrighty; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
412 HBRUSH hbrush, hprevbrush;
413 int topy, bottomy; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
415 int tilt; /* vertical distance covered by a gradient line */
417 starty = roundr((rc.left - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y);
418 endy = roundr((rc.left - endpointsf[1].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[1].Y);
419 height = endy - starty;
420 startrighty = roundr((rc.right - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y);
421 tilt = starty - startrighty;
423 if (starty >= startrighty)
426 bottomy = rc.bottom + tilt;
430 topy = rc.top + tilt;
434 poly[0].x = rc.right;
437 poly[3].x = rc.right;
439 for (y=topy; y<=bottomy; y++)
441 ARGB argb = blend_line_gradient(line, (y-starty)/(REAL)height);
442 col = ARGB2COLORREF(argb);
443 hbrush = CreateSolidBrush(col);
444 hprevbrush = SelectObject(graphics->hdc, hbrush);
445 poly[0].y = y - tilt - 1;
448 poly[3].y = y - tilt;
449 Polygon(graphics->hdc, poly, 4);
450 SelectObject(graphics->hdc, hprevbrush);
451 DeleteObject(hbrush);
454 /* else startpoint == endpoint */
458 case BrushTypeSolidColor:
460 GpSolidFill *fill = (GpSolidFill*)brush;
464 /* partially transparent fill */
466 SelectClipPath(graphics->hdc, RGN_AND);
467 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
469 HDC hdc = CreateCompatibleDC(NULL);
475 oldbmp = SelectObject(hdc, fill->bmp);
477 bf.BlendOp = AC_SRC_OVER;
479 bf.SourceConstantAlpha = 255;
480 bf.AlphaFormat = AC_SRC_ALPHA;
482 GdiAlphaBlend(graphics->hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdc, 0, 0, 1, 1, bf);
484 SelectObject(hdc, oldbmp);
490 /* else fall through */
493 SelectObject(graphics->hdc, brush->gdibrush);
494 FillPath(graphics->hdc);
499 static INT brush_can_fill_pixels(GpBrush *brush)
503 case BrushTypeSolidColor:
504 case BrushTypeHatchFill:
505 case BrushTypeLinearGradient:
512 static GpStatus brush_fill_pixels(GpGraphics *graphics, GpBrush *brush,
513 DWORD *argb_pixels, GpRect *fill_area, UINT cdwStride)
517 case BrushTypeSolidColor:
520 GpSolidFill *fill = (GpSolidFill*)brush;
521 for (x=0; x<fill_area->Width; x++)
522 for (y=0; y<fill_area->Height; y++)
523 argb_pixels[x + y*cdwStride] = fill->color;
526 case BrushTypeHatchFill:
529 GpHatch *fill = (GpHatch*)brush;
530 const char *hatch_data;
532 if (get_hatch_data(fill->hatchstyle, &hatch_data) != Ok)
533 return NotImplemented;
535 for (x=0; x<fill_area->Width; x++)
536 for (y=0; y<fill_area->Height; y++)
540 /* FIXME: Account for the rendering origin */
541 hx = (x + fill_area->X) % 8;
542 hy = (y + fill_area->Y) % 8;
544 if ((hatch_data[7-hy] & (0x80 >> hx)) != 0)
545 argb_pixels[x + y*cdwStride] = fill->forecol;
547 argb_pixels[x + y*cdwStride] = fill->backcol;
552 case BrushTypeLinearGradient:
554 GpLineGradient *fill = (GpLineGradient*)brush;
555 GpPointF draw_points[3], line_points[3];
557 static const GpRectF box_1 = { 0.0, 0.0, 1.0, 1.0 };
558 GpMatrix *world_to_gradient; /* FIXME: Store this in the brush? */
561 draw_points[0].X = fill_area->X;
562 draw_points[0].Y = fill_area->Y;
563 draw_points[1].X = fill_area->X+1;
564 draw_points[1].Y = fill_area->Y;
565 draw_points[2].X = fill_area->X;
566 draw_points[2].Y = fill_area->Y+1;
568 /* Transform the points to a co-ordinate space where X is the point's
569 * position in the gradient, 0.0 being the start point and 1.0 the
571 stat = GdipTransformPoints(graphics, CoordinateSpaceWorld,
572 CoordinateSpaceDevice, draw_points, 3);
576 line_points[0] = fill->startpoint;
577 line_points[1] = fill->endpoint;
578 line_points[2].X = fill->startpoint.X + (fill->startpoint.Y - fill->endpoint.Y);
579 line_points[2].Y = fill->startpoint.Y + (fill->endpoint.X - fill->startpoint.X);
581 stat = GdipCreateMatrix3(&box_1, line_points, &world_to_gradient);
586 stat = GdipInvertMatrix(world_to_gradient);
589 stat = GdipTransformMatrixPoints(world_to_gradient, draw_points, 3);
591 GdipDeleteMatrix(world_to_gradient);
596 REAL x_delta = draw_points[1].X - draw_points[0].X;
597 REAL y_delta = draw_points[2].X - draw_points[0].X;
599 for (y=0; y<fill_area->Height; y++)
601 for (x=0; x<fill_area->Width; x++)
603 REAL pos = draw_points[0].X + x * x_delta + y * y_delta;
605 argb_pixels[x + y*cdwStride] = blend_line_gradient(fill, pos);
613 return NotImplemented;
617 /* GdipDrawPie/GdipFillPie helper function */
618 static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width,
619 REAL height, REAL startAngle, REAL sweepAngle)
626 ptf[1].X = x + width;
627 ptf[1].Y = y + height;
629 deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y);
630 deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y);
632 transform_and_round_points(graphics, pti, ptf, 4);
634 Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x,
635 pti[2].y, pti[3].x, pti[3].y);
638 /* Draws the linecap the specified color and size on the hdc. The linecap is in
639 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
640 * should not be called on an hdc that has a path you care about. */
641 static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
642 const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
644 HGDIOBJ oldbrush = NULL, oldpen = NULL;
645 GpMatrix *matrix = NULL;
648 PointF ptf[4], *custptf = NULL;
649 POINT pt[4], *custpt = NULL;
651 REAL theta, dsmall, dbig, dx, dy = 0.0;
656 if((x1 == x2) && (y1 == y2))
659 theta = gdiplus_atan2(y2 - y1, x2 - x1);
661 customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
663 brush = CreateSolidBrush(color);
664 lb.lbStyle = BS_SOLID;
667 pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
668 PS_JOIN_MITER, 1, &lb, 0,
670 oldbrush = SelectObject(graphics->hdc, brush);
671 oldpen = SelectObject(graphics->hdc, pen);
678 case LineCapSquareAnchor:
679 case LineCapDiamondAnchor:
680 size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0;
681 if(cap == LineCapDiamondAnchor){
682 dsmall = cos(theta + M_PI_2) * size;
683 dbig = sin(theta + M_PI_2) * size;
686 dsmall = cos(theta + M_PI_4) * size;
687 dbig = sin(theta + M_PI_4) * size;
690 ptf[0].X = x2 - dsmall;
691 ptf[1].X = x2 + dbig;
693 ptf[0].Y = y2 - dbig;
694 ptf[3].Y = y2 + dsmall;
696 ptf[1].Y = y2 - dsmall;
697 ptf[2].Y = y2 + dbig;
699 ptf[3].X = x2 - dbig;
700 ptf[2].X = x2 + dsmall;
702 transform_and_round_points(graphics, pt, ptf, 4);
703 Polygon(graphics->hdc, pt, 4);
706 case LineCapArrowAnchor:
707 size = size * 4.0 / sqrt(3.0);
709 dx = cos(M_PI / 6.0 + theta) * size;
710 dy = sin(M_PI / 6.0 + theta) * size;
715 dx = cos(- M_PI / 6.0 + theta) * size;
716 dy = sin(- M_PI / 6.0 + theta) * size;
724 transform_and_round_points(graphics, pt, ptf, 3);
725 Polygon(graphics->hdc, pt, 3);
728 case LineCapRoundAnchor:
729 dx = dy = ANCHOR_WIDTH * size / 2.0;
736 transform_and_round_points(graphics, pt, ptf, 2);
737 Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
740 case LineCapTriangle:
742 dx = cos(M_PI_2 + theta) * size;
743 dy = sin(M_PI_2 + theta) * size;
750 dx = cos(theta) * size;
751 dy = sin(theta) * size;
756 transform_and_round_points(graphics, pt, ptf, 3);
757 Polygon(graphics->hdc, pt, 3);
761 dx = dy = size / 2.0;
768 dx = -cos(M_PI_2 + theta) * size;
769 dy = -sin(M_PI_2 + theta) * size;
776 transform_and_round_points(graphics, pt, ptf, 4);
777 Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x,
778 pt[2].y, pt[3].x, pt[3].y);
785 count = custom->pathdata.Count;
786 custptf = GdipAlloc(count * sizeof(PointF));
787 custpt = GdipAlloc(count * sizeof(POINT));
788 tp = GdipAlloc(count);
790 if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok))
793 memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF));
795 GdipScaleMatrix(matrix, size, size, MatrixOrderAppend);
796 GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2),
798 GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend);
799 GdipTransformMatrixPoints(matrix, custptf, count);
801 transform_and_round_points(graphics, custpt, custptf, count);
803 for(i = 0; i < count; i++)
804 tp[i] = convert_path_point_type(custom->pathdata.Types[i]);
807 BeginPath(graphics->hdc);
808 PolyDraw(graphics->hdc, custpt, tp, count);
809 EndPath(graphics->hdc);
810 StrokeAndFillPath(graphics->hdc);
813 PolyDraw(graphics->hdc, custpt, tp, count);
819 GdipDeleteMatrix(matrix);
826 SelectObject(graphics->hdc, oldbrush);
827 SelectObject(graphics->hdc, oldpen);
833 /* Shortens the line by the given percent by changing x2, y2.
834 * If percent is > 1.0 then the line will change direction.
835 * If percent is negative it can lengthen the line. */
836 static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL percent)
838 REAL dist, theta, dx, dy;
840 if((y1 == *y2) && (x1 == *x2))
843 dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent;
844 theta = gdiplus_atan2((*y2 - y1), (*x2 - x1));
845 dx = cos(theta) * dist;
846 dy = sin(theta) * dist;
852 /* Shortens the line by the given amount by changing x2, y2.
853 * If the amount is greater than the distance, the line will become length 0.
854 * If the amount is negative, it can lengthen the line. */
855 static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt)
857 REAL dx, dy, percent;
861 if(dx == 0 && dy == 0)
864 percent = amt / sqrt(dx * dx + dy * dy);
871 shorten_line_percent(x1, y1, x2, y2, percent);
874 /* Draws lines between the given points, and if caps is true then draws an endcap
875 * at the end of the last line. */
876 static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen,
877 GDIPCONST GpPointF * pt, INT count, BOOL caps)
880 GpPointF *ptcopy = NULL;
881 GpStatus status = GenericError;
886 pti = GdipAlloc(count * sizeof(POINT));
887 ptcopy = GdipAlloc(count * sizeof(GpPointF));
890 status = OutOfMemory;
894 memcpy(ptcopy, pt, count * sizeof(GpPointF));
897 if(pen->endcap == LineCapArrowAnchor)
898 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
899 &ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width);
900 else if((pen->endcap == LineCapCustom) && pen->customend)
901 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
902 &ptcopy[count-1].X, &ptcopy[count-1].Y,
903 pen->customend->inset * pen->width);
905 if(pen->startcap == LineCapArrowAnchor)
906 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
907 &ptcopy[0].X, &ptcopy[0].Y, pen->width);
908 else if((pen->startcap == LineCapCustom) && pen->customstart)
909 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
910 &ptcopy[0].X, &ptcopy[0].Y,
911 pen->customstart->inset * pen->width);
913 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
914 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
915 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
916 pt[1].X, pt[1].Y, pt[0].X, pt[0].Y);
919 transform_and_round_points(graphics, pti, ptcopy, count);
921 if(Polyline(graphics->hdc, pti, count))
931 /* Conducts a linear search to find the bezier points that will back off
932 * the endpoint of the curve by a distance of amt. Linear search works
933 * better than binary in this case because there are multiple solutions,
934 * and binary searches often find a bad one. I don't think this is what
935 * Windows does but short of rendering the bezier without GDI's help it's
936 * the best we can do. If rev then work from the start of the passed points
937 * instead of the end. */
938 static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev)
941 REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0;
942 INT i, first = 0, second = 1, third = 2, fourth = 3;
951 origx = pt[fourth].X;
952 origy = pt[fourth].Y;
953 memcpy(origpt, pt, sizeof(GpPointF) * 4);
955 for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){
956 /* reset bezier points to original values */
957 memcpy(pt, origpt, sizeof(GpPointF) * 4);
958 /* Perform magic on bezier points. Order is important here.*/
959 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
960 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
961 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
962 shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent);
963 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
964 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
966 dx = pt[fourth].X - origx;
967 dy = pt[fourth].Y - origy;
969 diff = sqrt(dx * dx + dy * dy);
970 percent += 0.0005 * amt;
974 /* Draws bezier curves between given points, and if caps is true then draws an
975 * endcap at the end of the last line. */
976 static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
977 GDIPCONST GpPointF * pt, INT count, BOOL caps)
981 GpStatus status = GenericError;
986 pti = GdipAlloc(count * sizeof(POINT));
987 ptcopy = GdipAlloc(count * sizeof(GpPointF));
990 status = OutOfMemory;
994 memcpy(ptcopy, pt, count * sizeof(GpPointF));
997 if(pen->endcap == LineCapArrowAnchor)
998 shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
999 else if((pen->endcap == LineCapCustom) && pen->customend)
1000 shorten_bezier_amt(&ptcopy[count-4], pen->width * pen->customend->inset,
1003 if(pen->startcap == LineCapArrowAnchor)
1004 shorten_bezier_amt(ptcopy, pen->width, TRUE);
1005 else if((pen->startcap == LineCapCustom) && pen->customstart)
1006 shorten_bezier_amt(ptcopy, pen->width * pen->customstart->inset, TRUE);
1008 /* the direction of the line cap is parallel to the direction at the
1009 * end of the bezier (which, if it has been shortened, is not the same
1010 * as the direction from pt[count-2] to pt[count-1]) */
1011 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
1012 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
1013 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
1014 pt[count - 1].X, pt[count - 1].Y);
1016 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
1017 pt[0].X - (ptcopy[0].X - ptcopy[1].X),
1018 pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
1021 transform_and_round_points(graphics, pti, ptcopy, count);
1023 PolyBezier(graphics->hdc, pti, count);
1034 /* Draws a combination of bezier curves and lines between points. */
1035 static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
1036 GDIPCONST BYTE * types, INT count, BOOL caps)
1038 POINT *pti = GdipAlloc(count * sizeof(POINT));
1039 BYTE *tp = GdipAlloc(count);
1040 GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
1042 GpStatus status = GenericError;
1048 if(!pti || !tp || !ptcopy){
1049 status = OutOfMemory;
1053 for(i = 1; i < count; i++){
1054 if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
1055 if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
1056 || !(types[i + 1] & PathPointTypeBezier)){
1057 ERR("Bad bezier points\n");
1064 memcpy(ptcopy, pt, count * sizeof(GpPointF));
1066 /* If we are drawing caps, go through the points and adjust them accordingly,
1067 * and draw the caps. */
1069 switch(types[count - 1] & PathPointTypePathTypeMask){
1070 case PathPointTypeBezier:
1071 if(pen->endcap == LineCapArrowAnchor)
1072 shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
1073 else if((pen->endcap == LineCapCustom) && pen->customend)
1074 shorten_bezier_amt(&ptcopy[count - 4],
1075 pen->width * pen->customend->inset, FALSE);
1077 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
1078 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
1079 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
1080 pt[count - 1].X, pt[count - 1].Y);
1083 case PathPointTypeLine:
1084 if(pen->endcap == LineCapArrowAnchor)
1085 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
1086 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
1088 else if((pen->endcap == LineCapCustom) && pen->customend)
1089 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
1090 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
1091 pen->customend->inset * pen->width);
1093 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
1094 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
1099 ERR("Bad path last point\n");
1103 /* Find start of points */
1104 for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
1105 == PathPointTypeStart); j++);
1107 switch(types[j] & PathPointTypePathTypeMask){
1108 case PathPointTypeBezier:
1109 if(pen->startcap == LineCapArrowAnchor)
1110 shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
1111 else if((pen->startcap == LineCapCustom) && pen->customstart)
1112 shorten_bezier_amt(&ptcopy[j - 1],
1113 pen->width * pen->customstart->inset, TRUE);
1115 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
1116 pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
1117 pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
1118 pt[j - 1].X, pt[j - 1].Y);
1121 case PathPointTypeLine:
1122 if(pen->startcap == LineCapArrowAnchor)
1123 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
1124 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
1126 else if((pen->startcap == LineCapCustom) && pen->customstart)
1127 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
1128 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
1129 pen->customstart->inset * pen->width);
1131 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
1132 pt[j].X, pt[j].Y, pt[j - 1].X,
1137 ERR("Bad path points\n");
1142 transform_and_round_points(graphics, pti, ptcopy, count);
1144 for(i = 0; i < count; i++){
1145 tp[i] = convert_path_point_type(types[i]);
1148 PolyDraw(graphics->hdc, pti, tp, count);
1160 GpStatus trace_path(GpGraphics *graphics, GpPath *path)
1164 BeginPath(graphics->hdc);
1165 result = draw_poly(graphics, NULL, path->pathdata.Points,
1166 path->pathdata.Types, path->pathdata.Count, FALSE);
1167 EndPath(graphics->hdc);
1171 typedef struct _GraphicsContainerItem {
1173 GraphicsContainer contid;
1175 SmoothingMode smoothing;
1176 CompositingQuality compqual;
1177 InterpolationMode interpolation;
1178 CompositingMode compmode;
1179 TextRenderingHint texthint;
1182 PixelOffsetMode pixeloffset;
1184 GpMatrix* worldtrans;
1186 } GraphicsContainerItem;
1188 static GpStatus init_container(GraphicsContainerItem** container,
1189 GDIPCONST GpGraphics* graphics){
1192 *container = GdipAlloc(sizeof(GraphicsContainerItem));
1196 (*container)->contid = graphics->contid + 1;
1198 (*container)->smoothing = graphics->smoothing;
1199 (*container)->compqual = graphics->compqual;
1200 (*container)->interpolation = graphics->interpolation;
1201 (*container)->compmode = graphics->compmode;
1202 (*container)->texthint = graphics->texthint;
1203 (*container)->scale = graphics->scale;
1204 (*container)->unit = graphics->unit;
1205 (*container)->textcontrast = graphics->textcontrast;
1206 (*container)->pixeloffset = graphics->pixeloffset;
1208 sts = GdipCloneMatrix(graphics->worldtrans, &(*container)->worldtrans);
1210 GdipFree(*container);
1215 sts = GdipCloneRegion(graphics->clip, &(*container)->clip);
1217 GdipDeleteMatrix((*container)->worldtrans);
1218 GdipFree(*container);
1226 static void delete_container(GraphicsContainerItem* container){
1227 GdipDeleteMatrix(container->worldtrans);
1228 GdipDeleteRegion(container->clip);
1229 GdipFree(container);
1232 static GpStatus restore_container(GpGraphics* graphics,
1233 GDIPCONST GraphicsContainerItem* container){
1238 sts = GdipCloneMatrix(container->worldtrans, &newTrans);
1242 sts = GdipCloneRegion(container->clip, &newClip);
1244 GdipDeleteMatrix(newTrans);
1248 GdipDeleteMatrix(graphics->worldtrans);
1249 graphics->worldtrans = newTrans;
1251 GdipDeleteRegion(graphics->clip);
1252 graphics->clip = newClip;
1254 graphics->contid = container->contid - 1;
1256 graphics->smoothing = container->smoothing;
1257 graphics->compqual = container->compqual;
1258 graphics->interpolation = container->interpolation;
1259 graphics->compmode = container->compmode;
1260 graphics->texthint = container->texthint;
1261 graphics->scale = container->scale;
1262 graphics->unit = container->unit;
1263 graphics->textcontrast = container->textcontrast;
1264 graphics->pixeloffset = container->pixeloffset;
1269 static GpStatus get_graphics_bounds(GpGraphics* graphics, GpRectF* rect)
1275 if(graphics->hwnd) {
1276 if(!GetClientRect(graphics->hwnd, &wnd_rect))
1277 return GenericError;
1279 rect->X = wnd_rect.left;
1280 rect->Y = wnd_rect.top;
1281 rect->Width = wnd_rect.right - wnd_rect.left;
1282 rect->Height = wnd_rect.bottom - wnd_rect.top;
1283 }else if (graphics->image){
1284 stat = GdipGetImageBounds(graphics->image, rect, &unit);
1285 if (stat == Ok && unit != UnitPixel)
1286 FIXME("need to convert from unit %i\n", unit);
1290 rect->Width = GetDeviceCaps(graphics->hdc, HORZRES);
1291 rect->Height = GetDeviceCaps(graphics->hdc, VERTRES);
1297 /* on success, rgn will contain the region of the graphics object which
1298 * is visible after clipping has been applied */
1299 static GpStatus get_visible_clip_region(GpGraphics *graphics, GpRegion *rgn)
1305 if((stat = get_graphics_bounds(graphics, &rectf)) != Ok)
1308 if((stat = GdipCreateRegion(&tmp)) != Ok)
1311 if((stat = GdipCombineRegionRect(tmp, &rectf, CombineModeReplace)) != Ok)
1314 if((stat = GdipCombineRegionRegion(tmp, graphics->clip, CombineModeIntersect)) != Ok)
1317 stat = GdipCombineRegionRegion(rgn, tmp, CombineModeReplace);
1320 GdipDeleteRegion(tmp);
1324 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
1326 TRACE("(%p, %p)\n", hdc, graphics);
1328 return GdipCreateFromHDC2(hdc, NULL, graphics);
1331 GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **graphics)
1335 TRACE("(%p, %p, %p)\n", hdc, hDevice, graphics);
1337 if(hDevice != NULL) {
1338 FIXME("Don't know how to handle parameter hDevice\n");
1339 return NotImplemented;
1345 if(graphics == NULL)
1346 return InvalidParameter;
1348 *graphics = GdipAlloc(sizeof(GpGraphics));
1349 if(!*graphics) return OutOfMemory;
1351 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
1352 GdipFree(*graphics);
1356 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
1357 GdipFree((*graphics)->worldtrans);
1358 GdipFree(*graphics);
1362 (*graphics)->hdc = hdc;
1363 (*graphics)->hwnd = WindowFromDC(hdc);
1364 (*graphics)->owndc = FALSE;
1365 (*graphics)->smoothing = SmoothingModeDefault;
1366 (*graphics)->compqual = CompositingQualityDefault;
1367 (*graphics)->interpolation = InterpolationModeDefault;
1368 (*graphics)->pixeloffset = PixelOffsetModeDefault;
1369 (*graphics)->compmode = CompositingModeSourceOver;
1370 (*graphics)->unit = UnitDisplay;
1371 (*graphics)->scale = 1.0;
1372 (*graphics)->busy = FALSE;
1373 (*graphics)->textcontrast = 4;
1374 list_init(&(*graphics)->containers);
1375 (*graphics)->contid = 0;
1377 TRACE("<-- %p\n", *graphics);
1382 GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics)
1386 *graphics = GdipAlloc(sizeof(GpGraphics));
1387 if(!*graphics) return OutOfMemory;
1389 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
1390 GdipFree(*graphics);
1394 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
1395 GdipFree((*graphics)->worldtrans);
1396 GdipFree(*graphics);
1400 (*graphics)->hdc = NULL;
1401 (*graphics)->hwnd = NULL;
1402 (*graphics)->owndc = FALSE;
1403 (*graphics)->image = image;
1404 (*graphics)->smoothing = SmoothingModeDefault;
1405 (*graphics)->compqual = CompositingQualityDefault;
1406 (*graphics)->interpolation = InterpolationModeDefault;
1407 (*graphics)->pixeloffset = PixelOffsetModeDefault;
1408 (*graphics)->compmode = CompositingModeSourceOver;
1409 (*graphics)->unit = UnitDisplay;
1410 (*graphics)->scale = 1.0;
1411 (*graphics)->busy = FALSE;
1412 (*graphics)->textcontrast = 4;
1413 list_init(&(*graphics)->containers);
1414 (*graphics)->contid = 0;
1416 TRACE("<-- %p\n", *graphics);
1421 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
1426 TRACE("(%p, %p)\n", hwnd, graphics);
1430 if((ret = GdipCreateFromHDC(hdc, graphics)) != Ok)
1432 ReleaseDC(hwnd, hdc);
1436 (*graphics)->hwnd = hwnd;
1437 (*graphics)->owndc = TRUE;
1442 /* FIXME: no icm handling */
1443 GpStatus WINGDIPAPI GdipCreateFromHWNDICM(HWND hwnd, GpGraphics **graphics)
1445 TRACE("(%p, %p)\n", hwnd, graphics);
1447 return GdipCreateFromHWND(hwnd, graphics);
1450 GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
1451 GpMetafile **metafile)
1455 TRACE("(%p,%i,%p)\n", hemf, delete, metafile);
1457 if(!hemf || !metafile)
1458 return InvalidParameter;
1461 FIXME("not implemented\n");
1463 return NotImplemented;
1466 GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
1467 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
1469 IStream *stream = NULL;
1473 GpStatus retval = Ok;
1475 TRACE("(%p, %d, %p, %p)\n", hwmf, delete, placeable, metafile);
1477 if(!hwmf || !metafile || !placeable)
1478 return InvalidParameter;
1481 read = GetMetaFileBitsEx(hwmf, 0, NULL);
1483 return GenericError;
1484 copy = GdipAlloc(read);
1485 GetMetaFileBitsEx(hwmf, read, copy);
1487 hemf = SetWinMetaFileBits(read, copy, NULL, NULL);
1490 read = GetEnhMetaFileBits(hemf, 0, NULL);
1491 copy = GdipAlloc(read);
1492 GetEnhMetaFileBits(hemf, read, copy);
1493 DeleteEnhMetaFile(hemf);
1495 if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
1496 ERR("could not make stream\n");
1498 retval = GenericError;
1502 *metafile = GdipAlloc(sizeof(GpMetafile));
1504 retval = OutOfMemory;
1508 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
1509 (LPVOID*) &((*metafile)->image.picture)) != S_OK)
1511 retval = GenericError;
1516 (*metafile)->image.type = ImageTypeMetafile;
1517 memcpy(&(*metafile)->image.format, &ImageFormatWMF, sizeof(GUID));
1518 (*metafile)->image.palette_flags = 0;
1519 (*metafile)->image.palette_count = 0;
1520 (*metafile)->image.palette_size = 0;
1521 (*metafile)->image.palette_entries = NULL;
1522 (*metafile)->image.xres = (REAL)placeable->Inch;
1523 (*metafile)->image.yres = (REAL)placeable->Inch;
1524 (*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch);
1525 (*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Top) / ((REAL) placeable->Inch);
1526 (*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right
1527 - placeable->BoundingBox.Left));
1528 (*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom
1529 - placeable->BoundingBox.Top));
1530 (*metafile)->unit = UnitPixel;
1533 DeleteMetaFile(hwmf);
1535 TRACE("<-- %p\n", *metafile);
1539 GdipFree(*metafile);
1540 IStream_Release(stream);
1544 GpStatus WINGDIPAPI GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR *file,
1545 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
1547 HMETAFILE hmf = GetMetaFileW(file);
1549 TRACE("(%s, %p, %p)\n", debugstr_w(file), placeable, metafile);
1551 if(!hmf) return InvalidParameter;
1553 return GdipCreateMetafileFromWmf(hmf, TRUE, placeable, metafile);
1556 GpStatus WINGDIPAPI GdipCreateMetafileFromFile(GDIPCONST WCHAR *file,
1557 GpMetafile **metafile)
1559 FIXME("(%p, %p): stub\n", file, metafile);
1560 return NotImplemented;
1563 GpStatus WINGDIPAPI GdipCreateMetafileFromStream(IStream *stream,
1564 GpMetafile **metafile)
1566 FIXME("(%p, %p): stub\n", stream, metafile);
1567 return NotImplemented;
1570 GpStatus WINGDIPAPI GdipCreateStreamOnFile(GDIPCONST WCHAR * filename,
1571 UINT access, IStream **stream)
1576 TRACE("(%s, %u, %p)\n", debugstr_w(filename), access, stream);
1578 if(!stream || !filename)
1579 return InvalidParameter;
1581 if(access & GENERIC_WRITE)
1582 dwMode = STGM_SHARE_DENY_WRITE | STGM_WRITE | STGM_CREATE;
1583 else if(access & GENERIC_READ)
1584 dwMode = STGM_SHARE_DENY_WRITE | STGM_READ | STGM_FAILIFTHERE;
1586 return InvalidParameter;
1588 ret = SHCreateStreamOnFileW(filename, dwMode, stream);
1590 return hresult_to_status(ret);
1593 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
1595 GraphicsContainerItem *cont, *next;
1596 TRACE("(%p)\n", graphics);
1598 if(!graphics) return InvalidParameter;
1599 if(graphics->busy) return ObjectBusy;
1602 ReleaseDC(graphics->hwnd, graphics->hdc);
1604 LIST_FOR_EACH_ENTRY_SAFE(cont, next, &graphics->containers, GraphicsContainerItem, entry){
1605 list_remove(&cont->entry);
1606 delete_container(cont);
1609 GdipDeleteRegion(graphics->clip);
1610 GdipDeleteMatrix(graphics->worldtrans);
1616 GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
1617 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1619 INT save_state, num_pts;
1620 GpPointF points[MAX_ARC_PTS];
1623 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
1624 width, height, startAngle, sweepAngle);
1626 if(!graphics || !pen || width <= 0 || height <= 0)
1627 return InvalidParameter;
1634 FIXME("graphics object has no HDC\n");
1638 num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
1640 save_state = prepare_dc(graphics, pen);
1642 retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
1644 restore_dc(graphics, save_state);
1649 GpStatus WINGDIPAPI GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x,
1650 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
1652 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
1653 width, height, startAngle, sweepAngle);
1655 return GdipDrawArc(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
1658 GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
1659 REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
1665 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1,
1666 x2, y2, x3, y3, x4, y4);
1668 if(!graphics || !pen)
1669 return InvalidParameter;
1676 FIXME("graphics object has no HDC\n");
1689 save_state = prepare_dc(graphics, pen);
1691 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
1693 restore_dc(graphics, save_state);
1698 GpStatus WINGDIPAPI GdipDrawBezierI(GpGraphics *graphics, GpPen *pen, INT x1,
1699 INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4)
1705 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics, pen, x1, y1,
1706 x2, y2, x3, y3, x4, y4);
1708 if(!graphics || !pen)
1709 return InvalidParameter;
1716 FIXME("graphics object has no HDC\n");
1729 save_state = prepare_dc(graphics, pen);
1731 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
1733 restore_dc(graphics, save_state);
1738 GpStatus WINGDIPAPI GdipDrawBeziers(GpGraphics *graphics, GpPen *pen,
1739 GDIPCONST GpPointF *points, INT count)
1744 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1746 if(!graphics || !pen || !points || (count <= 0))
1747 return InvalidParameter;
1752 for(i = 0; i < floor(count / 4); i++){
1753 ret = GdipDrawBezier(graphics, pen,
1754 points[4*i].X, points[4*i].Y,
1755 points[4*i + 1].X, points[4*i + 1].Y,
1756 points[4*i + 2].X, points[4*i + 2].Y,
1757 points[4*i + 3].X, points[4*i + 3].Y);
1765 GpStatus WINGDIPAPI GdipDrawBeziersI(GpGraphics *graphics, GpPen *pen,
1766 GDIPCONST GpPoint *points, INT count)
1772 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1774 if(!graphics || !pen || !points || (count <= 0))
1775 return InvalidParameter;
1780 pts = GdipAlloc(sizeof(GpPointF) * count);
1784 for(i = 0; i < count; i++){
1785 pts[i].X = (REAL)points[i].X;
1786 pts[i].Y = (REAL)points[i].Y;
1789 ret = GdipDrawBeziers(graphics,pen,pts,count);
1796 GpStatus WINGDIPAPI GdipDrawClosedCurve(GpGraphics *graphics, GpPen *pen,
1797 GDIPCONST GpPointF *points, INT count)
1799 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1801 return GdipDrawClosedCurve2(graphics, pen, points, count, 1.0);
1804 GpStatus WINGDIPAPI GdipDrawClosedCurveI(GpGraphics *graphics, GpPen *pen,
1805 GDIPCONST GpPoint *points, INT count)
1807 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1809 return GdipDrawClosedCurve2I(graphics, pen, points, count, 1.0);
1812 GpStatus WINGDIPAPI GdipDrawClosedCurve2(GpGraphics *graphics, GpPen *pen,
1813 GDIPCONST GpPointF *points, INT count, REAL tension)
1818 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1820 if(!graphics || !pen || !points || count <= 0)
1821 return InvalidParameter;
1826 if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok)
1829 stat = GdipAddPathClosedCurve2(path, points, count, tension);
1831 GdipDeletePath(path);
1835 stat = GdipDrawPath(graphics, pen, path);
1837 GdipDeletePath(path);
1842 GpStatus WINGDIPAPI GdipDrawClosedCurve2I(GpGraphics *graphics, GpPen *pen,
1843 GDIPCONST GpPoint *points, INT count, REAL tension)
1849 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1851 if(!points || count <= 0)
1852 return InvalidParameter;
1854 ptf = GdipAlloc(sizeof(GpPointF)*count);
1858 for(i = 0; i < count; i++){
1859 ptf[i].X = (REAL)points[i].X;
1860 ptf[i].Y = (REAL)points[i].Y;
1863 stat = GdipDrawClosedCurve2(graphics, pen, ptf, count, tension);
1870 GpStatus WINGDIPAPI GdipDrawCurve(GpGraphics *graphics, GpPen *pen,
1871 GDIPCONST GpPointF *points, INT count)
1873 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1875 return GdipDrawCurve2(graphics,pen,points,count,1.0);
1878 GpStatus WINGDIPAPI GdipDrawCurveI(GpGraphics *graphics, GpPen *pen,
1879 GDIPCONST GpPoint *points, INT count)
1885 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1888 return InvalidParameter;
1890 pointsF = GdipAlloc(sizeof(GpPointF)*count);
1894 for(i = 0; i < count; i++){
1895 pointsF[i].X = (REAL)points[i].X;
1896 pointsF[i].Y = (REAL)points[i].Y;
1899 ret = GdipDrawCurve(graphics,pen,pointsF,count);
1905 /* Approximates cardinal spline with Bezier curves. */
1906 GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
1907 GDIPCONST GpPointF *points, INT count, REAL tension)
1909 /* PolyBezier expects count*3-2 points. */
1910 INT i, len_pt = count*3-2, save_state;
1912 REAL x1, x2, y1, y2;
1915 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1917 if(!graphics || !pen)
1918 return InvalidParameter;
1924 return InvalidParameter;
1928 FIXME("graphics object has no HDC\n");
1932 pt = GdipAlloc(len_pt * sizeof(GpPointF));
1936 tension = tension * TENSION_CONST;
1938 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
1941 pt[0].X = points[0].X;
1942 pt[0].Y = points[0].Y;
1946 for(i = 0; i < count-2; i++){
1947 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
1951 pt[3*i+3].X = points[i+1].X;
1952 pt[3*i+3].Y = points[i+1].Y;
1957 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
1958 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
1960 pt[len_pt-2].X = x1;
1961 pt[len_pt-2].Y = y1;
1962 pt[len_pt-1].X = points[count-1].X;
1963 pt[len_pt-1].Y = points[count-1].Y;
1965 save_state = prepare_dc(graphics, pen);
1967 retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
1970 restore_dc(graphics, save_state);
1975 GpStatus WINGDIPAPI GdipDrawCurve2I(GpGraphics *graphics, GpPen *pen,
1976 GDIPCONST GpPoint *points, INT count, REAL tension)
1982 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1985 return InvalidParameter;
1987 pointsF = GdipAlloc(sizeof(GpPointF)*count);
1991 for(i = 0; i < count; i++){
1992 pointsF[i].X = (REAL)points[i].X;
1993 pointsF[i].Y = (REAL)points[i].Y;
1996 ret = GdipDrawCurve2(graphics,pen,pointsF,count,tension);
2002 GpStatus WINGDIPAPI GdipDrawCurve3(GpGraphics *graphics, GpPen *pen,
2003 GDIPCONST GpPointF *points, INT count, INT offset, INT numberOfSegments,
2006 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
2008 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
2009 return InvalidParameter;
2012 return GdipDrawCurve2(graphics, pen, points + offset, numberOfSegments + 1, tension);
2015 GpStatus WINGDIPAPI GdipDrawCurve3I(GpGraphics *graphics, GpPen *pen,
2016 GDIPCONST GpPoint *points, INT count, INT offset, INT numberOfSegments,
2019 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
2025 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
2026 return InvalidParameter;
2029 return GdipDrawCurve2I(graphics, pen, points + offset, numberOfSegments + 1, tension);
2032 GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics *graphics, GpPen *pen, REAL x,
2033 REAL y, REAL width, REAL height)
2039 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
2041 if(!graphics || !pen)
2042 return InvalidParameter;
2049 FIXME("graphics object has no HDC\n");
2055 ptf[1].X = x + width;
2056 ptf[1].Y = y + height;
2058 save_state = prepare_dc(graphics, pen);
2059 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2061 transform_and_round_points(graphics, pti, ptf, 2);
2063 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
2065 restore_dc(graphics, save_state);
2070 GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics *graphics, GpPen *pen, INT x,
2071 INT y, INT width, INT height)
2073 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
2075 return GdipDrawEllipse(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2079 GpStatus WINGDIPAPI GdipDrawImage(GpGraphics *graphics, GpImage *image, REAL x, REAL y)
2084 TRACE("(%p, %p, %.2f, %.2f)\n", graphics, image, x, y);
2086 if(!graphics || !image)
2087 return InvalidParameter;
2089 GdipGetImageWidth(image, &width);
2090 GdipGetImageHeight(image, &height);
2092 /* FIXME: we should use the graphics and image dpi, somehow */
2094 points[0].X = points[2].X = x;
2095 points[0].Y = points[1].Y = y;
2096 points[1].X = x + width;
2097 points[2].Y = y + height;
2099 return GdipDrawImagePointsRect(graphics, image, points, 3, 0, 0, width, height,
2100 UnitPixel, NULL, NULL, NULL);
2103 GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x,
2106 TRACE("(%p, %p, %d, %d)\n", graphics, image, x, y);
2108 return GdipDrawImage(graphics, image, (REAL)x, (REAL)y);
2111 GpStatus WINGDIPAPI GdipDrawImagePointRect(GpGraphics *graphics, GpImage *image,
2112 REAL x, REAL y, REAL srcx, REAL srcy, REAL srcwidth, REAL srcheight,
2116 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
2118 points[0].X = points[2].X = x;
2119 points[0].Y = points[1].Y = y;
2121 /* FIXME: convert image coordinates to Graphics coordinates? */
2122 points[1].X = x + srcwidth;
2123 points[2].Y = y + srcheight;
2125 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2126 srcwidth, srcheight, srcUnit, NULL, NULL, NULL);
2129 GpStatus WINGDIPAPI GdipDrawImagePointRectI(GpGraphics *graphics, GpImage *image,
2130 INT x, INT y, INT srcx, INT srcy, INT srcwidth, INT srcheight,
2133 return GdipDrawImagePointRect(graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
2136 GpStatus WINGDIPAPI GdipDrawImagePoints(GpGraphics *graphics, GpImage *image,
2137 GDIPCONST GpPointF *dstpoints, INT count)
2139 FIXME("(%p, %p, %p, %d): stub\n", graphics, image, dstpoints, count);
2140 return NotImplemented;
2143 GpStatus WINGDIPAPI GdipDrawImagePointsI(GpGraphics *graphics, GpImage *image,
2144 GDIPCONST GpPoint *dstpoints, INT count)
2146 FIXME("(%p, %p, %p, %d): stub\n", graphics, image, dstpoints, count);
2147 return NotImplemented;
2150 GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
2151 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
2152 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
2153 DrawImageAbort callback, VOID * callbackData)
2160 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics, image, points,
2161 count, srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
2164 if(!graphics || !image || !points || count != 3)
2165 return InvalidParameter;
2167 TRACE("%s %s %s\n", debugstr_pointf(&points[0]), debugstr_pointf(&points[1]),
2168 debugstr_pointf(&points[2]));
2170 memcpy(ptf, points, 3 * sizeof(GpPointF));
2171 ptf[3].X = ptf[2].X + ptf[1].X - ptf[0].X;
2172 ptf[3].Y = ptf[2].Y + ptf[1].Y - ptf[0].Y;
2173 transform_and_round_points(graphics, pti, ptf, 4);
2179 FIXME("graphics object has no HDC\n");
2182 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2183 if(srcUnit == UnitInch)
2184 dx = dy = (REAL) INCH_HIMETRIC;
2185 else if(srcUnit == UnitPixel){
2186 dx = ((REAL) INCH_HIMETRIC) /
2187 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
2188 dy = ((REAL) INCH_HIMETRIC) /
2189 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
2192 return NotImplemented;
2194 if(IPicture_Render(image->picture, graphics->hdc,
2195 pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
2196 srcx * dx, srcy * dy,
2197 srcwidth * dx, srcheight * dy,
2200 callback(callbackData);
2201 return GenericError;
2204 else if (image->type == ImageTypeBitmap)
2206 GpBitmap* bitmap = (GpBitmap*)image;
2209 if (srcUnit == UnitInch)
2210 dx = dy = 96.0; /* FIXME: use the image resolution */
2211 else if (srcUnit == UnitPixel)
2214 return NotImplemented;
2216 if (imageAttributes ||
2217 (graphics->image && graphics->image->type == ImageTypeBitmap) ||
2218 !((GpBitmap*)image)->hbitmap ||
2219 ptf[1].Y != ptf[0].Y || ptf[2].X != ptf[0].X)
2224 RECT src_area, dst_area;
2225 int i, x, y, stride;
2226 GpMatrix *dst_to_src;
2227 REAL m11, m12, m21, m22, mdx, mdy;
2230 src_area.left = srcx*dx;
2231 src_area.top = srcy*dy;
2232 src_area.right = (srcx+srcwidth)*dx;
2233 src_area.bottom = (srcy+srcheight)*dy;
2235 dst_area.left = dst_area.right = pti[0].x;
2236 dst_area.top = dst_area.bottom = pti[0].y;
2239 if (dst_area.left > pti[i].x) dst_area.left = pti[i].x;
2240 if (dst_area.right < pti[i].x) dst_area.right = pti[i].x;
2241 if (dst_area.top > pti[i].y) dst_area.top = pti[i].y;
2242 if (dst_area.bottom < pti[i].y) dst_area.bottom = pti[i].y;
2245 m11 = (ptf[1].X - ptf[0].X) / srcwidth;
2246 m21 = (ptf[2].X - ptf[0].X) / srcheight;
2247 mdx = ptf[0].X - m11 * srcx - m21 * srcy;
2248 m12 = (ptf[1].Y - ptf[0].Y) / srcwidth;
2249 m22 = (ptf[2].Y - ptf[0].Y) / srcheight;
2250 mdy = ptf[0].Y - m12 * srcx - m22 * srcy;
2252 stat = GdipCreateMatrix2(m11, m12, m21, m22, mdx, mdy, &dst_to_src);
2253 if (stat != Ok) return stat;
2255 stat = GdipInvertMatrix(dst_to_src);
2258 GdipDeleteMatrix(dst_to_src);
2262 data = GdipAlloc(sizeof(ARGB) * (dst_area.right - dst_area.left) * (dst_area.bottom - dst_area.top));
2265 GdipDeleteMatrix(dst_to_src);
2269 stride = sizeof(ARGB) * (dst_area.right - dst_area.left);
2271 if (imageAttributes &&
2272 (imageAttributes->wrap != WrapModeClamp ||
2273 imageAttributes->outside_color != 0x00000000 ||
2274 imageAttributes->clamp))
2278 FIXME("Image wrap mode not implemented\n");
2281 for (x=dst_area.left; x<dst_area.right; x++)
2283 for (y=dst_area.top; y<dst_area.bottom; y++)
2285 GpPointF src_pointf;
2292 GdipTransformMatrixPoints(dst_to_src, &src_pointf, 1);
2294 src_x = roundr(src_pointf.X);
2295 src_y = roundr(src_pointf.Y);
2297 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2299 if (src_x < src_area.left || src_x >= src_area.right ||
2300 src_y < src_area.top || src_y >= src_area.bottom)
2303 GdipBitmapGetPixel(bitmap, src_x, src_y, src_color);
2307 GdipDeleteMatrix(dst_to_src);
2309 if (imageAttributes)
2311 if (imageAttributes->colorkeys[ColorAdjustTypeBitmap].enabled ||
2312 imageAttributes->colorkeys[ColorAdjustTypeDefault].enabled)
2314 const struct color_key *key;
2315 BYTE min_blue, min_green, min_red;
2316 BYTE max_blue, max_green, max_red;
2318 if (imageAttributes->colorkeys[ColorAdjustTypeBitmap].enabled)
2319 key = &imageAttributes->colorkeys[ColorAdjustTypeBitmap];
2321 key = &imageAttributes->colorkeys[ColorAdjustTypeDefault];
2323 min_blue = key->low&0xff;
2324 min_green = (key->low>>8)&0xff;
2325 min_red = (key->low>>16)&0xff;
2327 max_blue = key->high&0xff;
2328 max_green = (key->high>>8)&0xff;
2329 max_red = (key->high>>16)&0xff;
2331 for (x=dst_area.left; x<dst_area.right; x++)
2332 for (y=dst_area.top; y<dst_area.bottom; y++)
2335 BYTE blue, green, red;
2336 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2337 blue = *src_color&0xff;
2338 green = (*src_color>>8)&0xff;
2339 red = (*src_color>>16)&0xff;
2340 if (blue >= min_blue && green >= min_green && red >= min_red &&
2341 blue <= max_blue && green <= max_green && red <= max_red)
2342 *src_color = 0x00000000;
2346 if (imageAttributes->colorremaptables[ColorAdjustTypeBitmap].enabled ||
2347 imageAttributes->colorremaptables[ColorAdjustTypeDefault].enabled)
2349 const struct color_remap_table *table;
2351 if (imageAttributes->colorremaptables[ColorAdjustTypeBitmap].enabled)
2352 table = &imageAttributes->colorremaptables[ColorAdjustTypeBitmap];
2354 table = &imageAttributes->colorremaptables[ColorAdjustTypeDefault];
2356 for (x=dst_area.left; x<dst_area.right; x++)
2357 for (y=dst_area.top; y<dst_area.bottom; y++)
2360 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2361 for (i=0; i<table->mapsize; i++)
2363 if (*src_color == table->colormap[i].oldColor.Argb)
2365 *src_color = table->colormap[i].newColor.Argb;
2372 if (imageAttributes->colormatrices[ColorAdjustTypeBitmap].enabled ||
2373 imageAttributes->colormatrices[ColorAdjustTypeDefault].enabled)
2377 FIXME("Color transforms not implemented\n");
2380 if (imageAttributes->gamma_enabled[ColorAdjustTypeBitmap] ||
2381 imageAttributes->gamma_enabled[ColorAdjustTypeDefault])
2385 FIXME("Gamma adjustment not implemented\n");
2389 stat = alpha_blend_pixels(graphics, dst_area.left, dst_area.top,
2390 data, dst_area.right - dst_area.left, dst_area.bottom - dst_area.top, stride);
2399 int temp_hdc=0, temp_bitmap=0;
2400 HBITMAP hbitmap, old_hbm=NULL;
2402 if (!(bitmap->format == PixelFormat16bppRGB555 ||
2403 bitmap->format == PixelFormat24bppRGB ||
2404 bitmap->format == PixelFormat32bppRGB ||
2405 bitmap->format == PixelFormat32bppPARGB))
2407 BITMAPINFOHEADER bih;
2409 PixelFormat dst_format;
2411 /* we can't draw a bitmap of this format directly */
2412 hdc = CreateCompatibleDC(0);
2416 bih.biSize = sizeof(BITMAPINFOHEADER);
2417 bih.biWidth = bitmap->width;
2418 bih.biHeight = -bitmap->height;
2420 bih.biBitCount = 32;
2421 bih.biCompression = BI_RGB;
2422 bih.biSizeImage = 0;
2423 bih.biXPelsPerMeter = 0;
2424 bih.biYPelsPerMeter = 0;
2426 bih.biClrImportant = 0;
2428 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
2429 (void**)&temp_bits, NULL, 0);
2431 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
2432 dst_format = PixelFormat32bppPARGB;
2434 dst_format = PixelFormat32bppRGB;
2436 convert_pixels(bitmap->width, bitmap->height,
2437 bitmap->width*4, temp_bits, dst_format,
2438 bitmap->stride, bitmap->bits, bitmap->format, bitmap->image.palette_entries);
2442 hbitmap = bitmap->hbitmap;
2444 temp_hdc = (hdc == 0);
2449 if (!hdc) hdc = CreateCompatibleDC(0);
2450 old_hbm = SelectObject(hdc, hbitmap);
2453 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
2457 bf.BlendOp = AC_SRC_OVER;
2459 bf.SourceConstantAlpha = 255;
2460 bf.AlphaFormat = AC_SRC_ALPHA;
2462 GdiAlphaBlend(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
2463 hdc, srcx*dx, srcy*dy, srcwidth*dx, srcheight*dy, bf);
2467 StretchBlt(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
2468 hdc, srcx*dx, srcy*dy, srcwidth*dx, srcheight*dy, SRCCOPY);
2473 SelectObject(hdc, old_hbm);
2478 DeleteObject(hbitmap);
2483 ERR("GpImage with no IPicture or HBITMAP?!\n");
2484 return NotImplemented;
2490 GpStatus WINGDIPAPI GdipDrawImagePointsRectI(GpGraphics *graphics, GpImage *image,
2491 GDIPCONST GpPoint *points, INT count, INT srcx, INT srcy, INT srcwidth,
2492 INT srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
2493 DrawImageAbort callback, VOID * callbackData)
2495 GpPointF pointsF[3];
2498 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics, image, points, count,
2499 srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
2502 if(!points || count!=3)
2503 return InvalidParameter;
2505 for(i = 0; i < count; i++){
2506 pointsF[i].X = (REAL)points[i].X;
2507 pointsF[i].Y = (REAL)points[i].Y;
2510 return GdipDrawImagePointsRect(graphics, image, pointsF, count, (REAL)srcx, (REAL)srcy,
2511 (REAL)srcwidth, (REAL)srcheight, srcUnit, imageAttributes,
2512 callback, callbackData);
2515 GpStatus WINGDIPAPI GdipDrawImageRectRect(GpGraphics *graphics, GpImage *image,
2516 REAL dstx, REAL dsty, REAL dstwidth, REAL dstheight, REAL srcx, REAL srcy,
2517 REAL srcwidth, REAL srcheight, GpUnit srcUnit,
2518 GDIPCONST GpImageAttributes* imageattr, DrawImageAbort callback,
2519 VOID * callbackData)
2523 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
2524 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
2525 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
2529 points[1].X = dstx + dstwidth;
2532 points[2].Y = dsty + dstheight;
2534 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2535 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
2538 GpStatus WINGDIPAPI GdipDrawImageRectRectI(GpGraphics *graphics, GpImage *image,
2539 INT dstx, INT dsty, INT dstwidth, INT dstheight, INT srcx, INT srcy,
2540 INT srcwidth, INT srcheight, GpUnit srcUnit,
2541 GDIPCONST GpImageAttributes* imageAttributes, DrawImageAbort callback,
2542 VOID * callbackData)
2546 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
2547 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
2548 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
2552 points[1].X = dstx + dstwidth;
2555 points[2].Y = dsty + dstheight;
2557 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2558 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
2561 GpStatus WINGDIPAPI GdipDrawImageRect(GpGraphics *graphics, GpImage *image,
2562 REAL x, REAL y, REAL width, REAL height)
2568 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, image, x, y, width, height);
2570 if(!graphics || !image)
2571 return InvalidParameter;
2573 ret = GdipGetImageBounds(image, &bounds, &unit);
2577 return GdipDrawImageRectRect(graphics, image, x, y, width, height,
2578 bounds.X, bounds.Y, bounds.Width, bounds.Height,
2579 unit, NULL, NULL, NULL);
2582 GpStatus WINGDIPAPI GdipDrawImageRectI(GpGraphics *graphics, GpImage *image,
2583 INT x, INT y, INT width, INT height)
2585 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, image, x, y, width, height);
2587 return GdipDrawImageRect(graphics, image, (REAL)x, (REAL)y, (REAL)width, (REAL)height);
2590 GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1,
2591 REAL y1, REAL x2, REAL y2)
2597 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1, x2, y2);
2599 if(!pen || !graphics)
2600 return InvalidParameter;
2607 FIXME("graphics object has no HDC\n");
2616 save_state = prepare_dc(graphics, pen);
2618 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
2620 restore_dc(graphics, save_state);
2625 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
2626 INT y1, INT x2, INT y2)
2632 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x1, y1, x2, y2);
2634 if(!pen || !graphics)
2635 return InvalidParameter;
2642 FIXME("graphics object has no HDC\n");
2651 save_state = prepare_dc(graphics, pen);
2653 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
2655 restore_dc(graphics, save_state);
2660 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
2661 GpPointF *points, INT count)
2666 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2668 if(!pen || !graphics || (count < 2))
2669 return InvalidParameter;
2676 FIXME("graphics object has no HDC\n");
2680 save_state = prepare_dc(graphics, pen);
2682 retval = draw_polyline(graphics, pen, points, count, TRUE);
2684 restore_dc(graphics, save_state);
2689 GpStatus WINGDIPAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, GDIPCONST
2690 GpPoint *points, INT count)
2694 GpPointF *ptf = NULL;
2697 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2699 if(!pen || !graphics || (count < 2))
2700 return InvalidParameter;
2707 FIXME("graphics object has no HDC\n");
2711 ptf = GdipAlloc(count * sizeof(GpPointF));
2712 if(!ptf) return OutOfMemory;
2714 for(i = 0; i < count; i ++){
2715 ptf[i].X = (REAL) points[i].X;
2716 ptf[i].Y = (REAL) points[i].Y;
2719 save_state = prepare_dc(graphics, pen);
2721 retval = draw_polyline(graphics, pen, ptf, count, TRUE);
2723 restore_dc(graphics, save_state);
2729 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
2734 TRACE("(%p, %p, %p)\n", graphics, pen, path);
2736 if(!pen || !graphics)
2737 return InvalidParameter;
2744 FIXME("graphics object has no HDC\n");
2748 save_state = prepare_dc(graphics, pen);
2750 retval = draw_poly(graphics, pen, path->pathdata.Points,
2751 path->pathdata.Types, path->pathdata.Count, TRUE);
2753 restore_dc(graphics, save_state);
2758 GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
2759 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2763 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
2764 width, height, startAngle, sweepAngle);
2766 if(!graphics || !pen)
2767 return InvalidParameter;
2774 FIXME("graphics object has no HDC\n");
2778 save_state = prepare_dc(graphics, pen);
2779 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2781 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
2783 restore_dc(graphics, save_state);
2788 GpStatus WINGDIPAPI GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x,
2789 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2791 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
2792 width, height, startAngle, sweepAngle);
2794 return GdipDrawPie(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2797 GpStatus WINGDIPAPI GdipDrawRectangle(GpGraphics *graphics, GpPen *pen, REAL x,
2798 REAL y, REAL width, REAL height)
2804 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
2806 if(!pen || !graphics)
2807 return InvalidParameter;
2814 FIXME("graphics object has no HDC\n");
2820 ptf[1].X = x + width;
2822 ptf[2].X = x + width;
2823 ptf[2].Y = y + height;
2825 ptf[3].Y = y + height;
2827 save_state = prepare_dc(graphics, pen);
2828 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2830 transform_and_round_points(graphics, pti, ptf, 4);
2831 Polygon(graphics->hdc, pti, 4);
2833 restore_dc(graphics, save_state);
2838 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
2839 INT y, INT width, INT height)
2841 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
2843 return GdipDrawRectangle(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2846 GpStatus WINGDIPAPI GdipDrawRectangles(GpGraphics *graphics, GpPen *pen,
2847 GDIPCONST GpRectF* rects, INT count)
2853 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
2855 if(!graphics || !pen || !rects || count < 1)
2856 return InvalidParameter;
2863 FIXME("graphics object has no HDC\n");
2867 ptf = GdipAlloc(4 * count * sizeof(GpPointF));
2868 pti = GdipAlloc(4 * count * sizeof(POINT));
2876 for(i = 0; i < count; i++){
2877 ptf[4 * i + 3].X = ptf[4 * i].X = rects[i].X;
2878 ptf[4 * i + 1].Y = ptf[4 * i].Y = rects[i].Y;
2879 ptf[4 * i + 2].X = ptf[4 * i + 1].X = rects[i].X + rects[i].Width;
2880 ptf[4 * i + 3].Y = ptf[4 * i + 2].Y = rects[i].Y + rects[i].Height;
2883 save_state = prepare_dc(graphics, pen);
2884 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2886 transform_and_round_points(graphics, pti, ptf, 4 * count);
2888 for(i = 0; i < count; i++)
2889 Polygon(graphics->hdc, &pti[4 * i], 4);
2891 restore_dc(graphics, save_state);
2899 GpStatus WINGDIPAPI GdipDrawRectanglesI(GpGraphics *graphics, GpPen *pen,
2900 GDIPCONST GpRect* rects, INT count)
2906 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
2908 if(!rects || count<=0)
2909 return InvalidParameter;
2911 rectsF = GdipAlloc(sizeof(GpRectF) * count);
2915 for(i = 0;i < count;i++){
2916 rectsF[i].X = (REAL)rects[i].X;
2917 rectsF[i].Y = (REAL)rects[i].Y;
2918 rectsF[i].Width = (REAL)rects[i].Width;
2919 rectsF[i].Height = (REAL)rects[i].Height;
2922 ret = GdipDrawRectangles(graphics, pen, rectsF, count);
2928 GpStatus WINGDIPAPI GdipFillClosedCurve2(GpGraphics *graphics, GpBrush *brush,
2929 GDIPCONST GpPointF *points, INT count, REAL tension, GpFillMode fill)
2934 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2935 count, tension, fill);
2937 if(!graphics || !brush || !points)
2938 return InvalidParameter;
2943 if(count == 1) /* Do nothing */
2946 stat = GdipCreatePath(fill, &path);
2950 stat = GdipAddPathClosedCurve2(path, points, count, tension);
2952 GdipDeletePath(path);
2956 stat = GdipFillPath(graphics, brush, path);
2958 GdipDeletePath(path);
2962 GdipDeletePath(path);
2967 GpStatus WINGDIPAPI GdipFillClosedCurve2I(GpGraphics *graphics, GpBrush *brush,
2968 GDIPCONST GpPoint *points, INT count, REAL tension, GpFillMode fill)
2974 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2975 count, tension, fill);
2977 if(!points || count == 0)
2978 return InvalidParameter;
2980 if(count == 1) /* Do nothing */
2983 ptf = GdipAlloc(sizeof(GpPointF)*count);
2987 for(i = 0;i < count;i++){
2988 ptf[i].X = (REAL)points[i].X;
2989 ptf[i].Y = (REAL)points[i].Y;
2992 stat = GdipFillClosedCurve2(graphics, brush, ptf, count, tension, fill);
2999 GpStatus WINGDIPAPI GdipFillClosedCurve(GpGraphics *graphics, GpBrush *brush,
3000 GDIPCONST GpPointF *points, INT count)
3002 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3003 return GdipFillClosedCurve2(graphics, brush, points, count,
3004 0.5f, FillModeAlternate);
3007 GpStatus WINGDIPAPI GdipFillClosedCurveI(GpGraphics *graphics, GpBrush *brush,
3008 GDIPCONST GpPoint *points, INT count)
3010 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3011 return GdipFillClosedCurve2I(graphics, brush, points, count,
3012 0.5f, FillModeAlternate);
3015 GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x,
3016 REAL y, REAL width, REAL height)
3022 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
3024 if(!graphics || !brush)
3025 return InvalidParameter;
3032 FIXME("graphics object has no HDC\n");
3038 ptf[1].X = x + width;
3039 ptf[1].Y = y + height;
3041 save_state = SaveDC(graphics->hdc);
3042 EndPath(graphics->hdc);
3044 transform_and_round_points(graphics, pti, ptf, 2);
3046 BeginPath(graphics->hdc);
3047 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
3048 EndPath(graphics->hdc);
3050 brush_fill_path(graphics, brush);
3052 RestoreDC(graphics->hdc, save_state);
3057 GpStatus WINGDIPAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x,
3058 INT y, INT width, INT height)
3060 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
3062 return GdipFillEllipse(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
3065 GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
3070 TRACE("(%p, %p, %p)\n", graphics, brush, path);
3072 if(!brush || !graphics || !path)
3073 return InvalidParameter;
3080 FIXME("graphics object has no HDC\n");
3084 save_state = SaveDC(graphics->hdc);
3085 EndPath(graphics->hdc);
3086 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
3089 BeginPath(graphics->hdc);
3090 retval = draw_poly(graphics, NULL, path->pathdata.Points,
3091 path->pathdata.Types, path->pathdata.Count, FALSE);
3096 EndPath(graphics->hdc);
3097 brush_fill_path(graphics, brush);
3102 RestoreDC(graphics->hdc, save_state);
3107 GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
3108 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
3112 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3113 graphics, brush, x, y, width, height, startAngle, sweepAngle);
3115 if(!graphics || !brush)
3116 return InvalidParameter;
3123 FIXME("graphics object has no HDC\n");
3127 save_state = SaveDC(graphics->hdc);
3128 EndPath(graphics->hdc);
3130 BeginPath(graphics->hdc);
3131 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
3132 EndPath(graphics->hdc);
3134 brush_fill_path(graphics, brush);
3136 RestoreDC(graphics->hdc, save_state);
3141 GpStatus WINGDIPAPI GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x,
3142 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
3144 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3145 graphics, brush, x, y, width, height, startAngle, sweepAngle);
3147 return GdipFillPie(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
3150 GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush,
3151 GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)
3154 GpPointF *ptf = NULL;
3156 GpStatus retval = Ok;
3158 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
3160 if(!graphics || !brush || !points || !count)
3161 return InvalidParameter;
3168 FIXME("graphics object has no HDC\n");
3172 ptf = GdipAlloc(count * sizeof(GpPointF));
3173 pti = GdipAlloc(count * sizeof(POINT));
3175 retval = OutOfMemory;
3179 memcpy(ptf, points, count * sizeof(GpPointF));
3181 save_state = SaveDC(graphics->hdc);
3182 EndPath(graphics->hdc);
3183 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
3186 transform_and_round_points(graphics, pti, ptf, count);
3188 BeginPath(graphics->hdc);
3189 Polygon(graphics->hdc, pti, count);
3190 EndPath(graphics->hdc);
3192 brush_fill_path(graphics, brush);
3194 RestoreDC(graphics->hdc, save_state);
3203 GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
3204 GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
3207 GpPointF *ptf = NULL;
3209 GpStatus retval = Ok;
3211 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
3213 if(!graphics || !brush || !points || !count)
3214 return InvalidParameter;
3221 FIXME("graphics object has no HDC\n");
3225 ptf = GdipAlloc(count * sizeof(GpPointF));
3226 pti = GdipAlloc(count * sizeof(POINT));
3228 retval = OutOfMemory;
3232 for(i = 0; i < count; i ++){
3233 ptf[i].X = (REAL) points[i].X;
3234 ptf[i].Y = (REAL) points[i].Y;
3237 save_state = SaveDC(graphics->hdc);
3238 EndPath(graphics->hdc);
3239 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
3242 transform_and_round_points(graphics, pti, ptf, count);
3244 BeginPath(graphics->hdc);
3245 Polygon(graphics->hdc, pti, count);
3246 EndPath(graphics->hdc);
3248 brush_fill_path(graphics, brush);
3250 RestoreDC(graphics->hdc, save_state);
3259 GpStatus WINGDIPAPI GdipFillPolygon2(GpGraphics *graphics, GpBrush *brush,
3260 GDIPCONST GpPointF *points, INT count)
3262 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3264 return GdipFillPolygon(graphics, brush, points, count, FillModeAlternate);
3267 GpStatus WINGDIPAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush,
3268 GDIPCONST GpPoint *points, INT count)
3270 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3272 return GdipFillPolygonI(graphics, brush, points, count, FillModeAlternate);
3275 GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics *graphics, GpBrush *brush,
3276 REAL x, REAL y, REAL width, REAL height)
3282 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
3284 if(!graphics || !brush)
3285 return InvalidParameter;
3292 FIXME("graphics object has no HDC\n");
3298 ptf[1].X = x + width;
3300 ptf[2].X = x + width;
3301 ptf[2].Y = y + height;
3303 ptf[3].Y = y + height;
3305 save_state = SaveDC(graphics->hdc);
3306 EndPath(graphics->hdc);
3308 transform_and_round_points(graphics, pti, ptf, 4);
3310 BeginPath(graphics->hdc);
3311 Polygon(graphics->hdc, pti, 4);
3312 EndPath(graphics->hdc);
3314 brush_fill_path(graphics, brush);
3316 RestoreDC(graphics->hdc, save_state);
3321 GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush,
3322 INT x, INT y, INT width, INT height)
3328 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
3330 if(!graphics || !brush)
3331 return InvalidParameter;
3338 FIXME("graphics object has no HDC\n");
3344 ptf[1].X = x + width;
3346 ptf[2].X = x + width;
3347 ptf[2].Y = y + height;
3349 ptf[3].Y = y + height;
3351 save_state = SaveDC(graphics->hdc);
3352 EndPath(graphics->hdc);
3354 transform_and_round_points(graphics, pti, ptf, 4);
3356 BeginPath(graphics->hdc);
3357 Polygon(graphics->hdc, pti, 4);
3358 EndPath(graphics->hdc);
3360 brush_fill_path(graphics, brush);
3362 RestoreDC(graphics->hdc, save_state);
3367 GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRectF *rects,
3373 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3376 return InvalidParameter;
3378 for(i = 0; i < count; i++){
3379 ret = GdipFillRectangle(graphics, brush, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
3380 if(ret != Ok) return ret;
3386 GpStatus WINGDIPAPI GdipFillRectanglesI(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRect *rects,
3393 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3395 if(!rects || count <= 0)
3396 return InvalidParameter;
3398 rectsF = GdipAlloc(sizeof(GpRectF)*count);
3402 for(i = 0; i < count; i++){
3403 rectsF[i].X = (REAL)rects[i].X;
3404 rectsF[i].Y = (REAL)rects[i].Y;
3405 rectsF[i].X = (REAL)rects[i].Width;
3406 rectsF[i].Height = (REAL)rects[i].Height;
3409 ret = GdipFillRectangles(graphics,brush,rectsF,count);
3415 static GpStatus GDI32_GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
3424 return NotImplemented;
3426 status = GdipGetRegionHRgn(region, graphics, &hrgn);
3430 save_state = SaveDC(graphics->hdc);
3431 EndPath(graphics->hdc);
3433 ExtSelectClipRgn(graphics->hdc, hrgn, RGN_AND);
3435 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
3437 BeginPath(graphics->hdc);
3438 Rectangle(graphics->hdc, rc.left, rc.top, rc.right, rc.bottom);
3439 EndPath(graphics->hdc);
3441 brush_fill_path(graphics, brush);
3444 RestoreDC(graphics->hdc, save_state);
3451 static GpStatus SOFTWARE_GdipFillRegion(GpGraphics *graphics, GpBrush *brush,
3455 GpRegion *temp_region;
3456 GpMatrix *world_to_device, *identity;
3457 GpRectF graphics_bounds;
3458 UINT scans_count, i;
3463 if (!brush_can_fill_pixels(brush))
3464 return NotImplemented;
3466 stat = get_graphics_bounds(graphics, &graphics_bounds);
3469 stat = GdipCloneRegion(region, &temp_region);
3473 stat = get_graphics_transform(graphics, CoordinateSpaceDevice,
3474 CoordinateSpaceWorld, &world_to_device);
3478 stat = GdipTransformRegion(temp_region, world_to_device);
3480 GdipDeleteMatrix(world_to_device);
3484 stat = GdipCombineRegionRect(temp_region, &graphics_bounds, CombineModeIntersect);
3487 stat = GdipCreateMatrix(&identity);
3491 stat = GdipGetRegionScansCount(temp_region, &scans_count, identity);
3493 if (stat == Ok && scans_count != 0)
3495 scans = GdipAlloc(sizeof(*scans) * scans_count);
3501 stat = GdipGetRegionScansI(temp_region, scans, &dummy, identity);
3508 GdipDeleteMatrix(identity);
3511 GdipDeleteRegion(temp_region);
3514 if (stat == Ok && scans_count == 0)
3521 for (i=0; i<scans_count; i++)
3523 UINT size = scans[i].Width * scans[i].Height;
3525 if (size > max_size)
3529 pixel_data = GdipAlloc(sizeof(*pixel_data) * max_size);
3535 for (i=0; i<scans_count; i++)
3537 stat = brush_fill_pixels(graphics, brush, pixel_data, &scans[i],
3542 stat = alpha_blend_pixels(graphics, scans[i].X, scans[i].Y,
3543 (BYTE*)pixel_data, scans[i].Width, scans[i].Height,
3544 scans[i].Width * 4);
3551 GdipFree(pixel_data);
3560 /*****************************************************************************
3561 * GdipFillRegion [GDIPLUS.@]
3563 GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
3566 GpStatus stat = NotImplemented;
3568 TRACE("(%p, %p, %p)\n", graphics, brush, region);
3570 if (!(graphics && brush && region))
3571 return InvalidParameter;
3576 if (!graphics->image)
3577 stat = GDI32_GdipFillRegion(graphics, brush, region);
3579 if (stat == NotImplemented)
3580 stat = SOFTWARE_GdipFillRegion(graphics, brush, region);
3582 if (stat == NotImplemented && graphics->image)
3583 stat = GDI32_GdipFillRegion(graphics, brush, region);
3585 if (stat == NotImplemented)
3587 FIXME("not implemented for brushtype %i\n", brush->bt);
3594 GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention)
3596 TRACE("(%p,%u)\n", graphics, intention);
3599 return InvalidParameter;
3604 /* We have no internal operation queue, so there's no need to clear it. */
3612 /*****************************************************************************
3613 * GdipGetClipBounds [GDIPLUS.@]
3615 GpStatus WINGDIPAPI GdipGetClipBounds(GpGraphics *graphics, GpRectF *rect)
3617 TRACE("(%p, %p)\n", graphics, rect);
3620 return InvalidParameter;
3625 return GdipGetRegionBounds(graphics->clip, graphics, rect);
3628 /*****************************************************************************
3629 * GdipGetClipBoundsI [GDIPLUS.@]
3631 GpStatus WINGDIPAPI GdipGetClipBoundsI(GpGraphics *graphics, GpRect *rect)
3633 TRACE("(%p, %p)\n", graphics, rect);
3636 return InvalidParameter;
3641 return GdipGetRegionBoundsI(graphics->clip, graphics, rect);
3644 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3645 GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics,
3646 CompositingMode *mode)
3648 TRACE("(%p, %p)\n", graphics, mode);
3650 if(!graphics || !mode)
3651 return InvalidParameter;
3656 *mode = graphics->compmode;
3661 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3662 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
3663 CompositingQuality *quality)
3665 TRACE("(%p, %p)\n", graphics, quality);
3667 if(!graphics || !quality)
3668 return InvalidParameter;
3673 *quality = graphics->compqual;
3678 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3679 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
3680 InterpolationMode *mode)
3682 TRACE("(%p, %p)\n", graphics, mode);
3684 if(!graphics || !mode)
3685 return InvalidParameter;
3690 *mode = graphics->interpolation;
3695 /* FIXME: Need to handle color depths less than 24bpp */
3696 GpStatus WINGDIPAPI GdipGetNearestColor(GpGraphics *graphics, ARGB* argb)
3698 FIXME("(%p, %p): Passing color unmodified\n", graphics, argb);
3700 if(!graphics || !argb)
3701 return InvalidParameter;
3709 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
3711 TRACE("(%p, %p)\n", graphics, scale);
3713 if(!graphics || !scale)
3714 return InvalidParameter;
3719 *scale = graphics->scale;
3724 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
3726 TRACE("(%p, %p)\n", graphics, unit);
3728 if(!graphics || !unit)
3729 return InvalidParameter;
3734 *unit = graphics->unit;
3739 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3740 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
3743 TRACE("(%p, %p)\n", graphics, mode);
3745 if(!graphics || !mode)
3746 return InvalidParameter;
3751 *mode = graphics->pixeloffset;
3756 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3757 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
3759 TRACE("(%p, %p)\n", graphics, mode);
3761 if(!graphics || !mode)
3762 return InvalidParameter;
3767 *mode = graphics->smoothing;
3772 GpStatus WINGDIPAPI GdipGetTextContrast(GpGraphics *graphics, UINT *contrast)
3774 TRACE("(%p, %p)\n", graphics, contrast);
3776 if(!graphics || !contrast)
3777 return InvalidParameter;
3779 *contrast = graphics->textcontrast;
3784 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3785 GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics,
3786 TextRenderingHint *hint)
3788 TRACE("(%p, %p)\n", graphics, hint);
3790 if(!graphics || !hint)
3791 return InvalidParameter;
3796 *hint = graphics->texthint;
3801 GpStatus WINGDIPAPI GdipGetVisibleClipBounds(GpGraphics *graphics, GpRectF *rect)
3806 TRACE("(%p, %p)\n", graphics, rect);
3808 if(!graphics || !rect)
3809 return InvalidParameter;
3814 /* intersect window and graphics clipping regions */
3815 if((stat = GdipCreateRegion(&clip_rgn)) != Ok)
3818 if((stat = get_visible_clip_region(graphics, clip_rgn)) != Ok)
3821 /* get bounds of the region */
3822 stat = GdipGetRegionBounds(clip_rgn, graphics, rect);
3825 GdipDeleteRegion(clip_rgn);
3830 GpStatus WINGDIPAPI GdipGetVisibleClipBoundsI(GpGraphics *graphics, GpRect *rect)
3835 TRACE("(%p, %p)\n", graphics, rect);
3837 if(!graphics || !rect)
3838 return InvalidParameter;
3840 if((stat = GdipGetVisibleClipBounds(graphics, &rectf)) == Ok)
3842 rect->X = roundr(rectf.X);
3843 rect->Y = roundr(rectf.Y);
3844 rect->Width = roundr(rectf.Width);
3845 rect->Height = roundr(rectf.Height);
3851 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
3853 TRACE("(%p, %p)\n", graphics, matrix);
3855 if(!graphics || !matrix)
3856 return InvalidParameter;
3861 *matrix = *graphics->worldtrans;
3865 GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color)
3871 TRACE("(%p, %x)\n", graphics, color);
3874 return InvalidParameter;
3879 if((stat = GdipCreateSolidFill(color, &brush)) != Ok)
3882 if((stat = get_graphics_bounds(graphics, &wnd_rect)) != Ok){
3883 GdipDeleteBrush((GpBrush*)brush);
3887 GdipFillRectangle(graphics, (GpBrush*)brush, wnd_rect.X, wnd_rect.Y,
3888 wnd_rect.Width, wnd_rect.Height);
3890 GdipDeleteBrush((GpBrush*)brush);
3895 GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics *graphics, BOOL *res)
3897 TRACE("(%p, %p)\n", graphics, res);
3899 if(!graphics || !res)
3900 return InvalidParameter;
3902 return GdipIsEmptyRegion(graphics->clip, graphics, res);
3905 GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics *graphics, REAL x, REAL y, BOOL *result)
3911 TRACE("(%p, %.2f, %.2f, %p)\n", graphics, x, y, result);
3913 if(!graphics || !result)
3914 return InvalidParameter;
3921 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3922 CoordinateSpaceWorld, &pt, 1)) != Ok)
3925 if((stat = GdipCreateRegion(&rgn)) != Ok)
3928 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3931 stat = GdipIsVisibleRegionPoint(rgn, pt.X, pt.Y, graphics, result);
3934 GdipDeleteRegion(rgn);
3938 GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics *graphics, INT x, INT y, BOOL *result)
3940 return GdipIsVisiblePoint(graphics, (REAL)x, (REAL)y, result);
3943 GpStatus WINGDIPAPI GdipIsVisibleRect(GpGraphics *graphics, REAL x, REAL y, REAL width, REAL height, BOOL *result)
3949 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics, x, y, width, height, result);
3951 if(!graphics || !result)
3952 return InvalidParameter;
3959 pts[1].X = x + width;
3960 pts[1].Y = y + height;
3962 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3963 CoordinateSpaceWorld, pts, 2)) != Ok)
3966 pts[1].X -= pts[0].X;
3967 pts[1].Y -= pts[0].Y;
3969 if((stat = GdipCreateRegion(&rgn)) != Ok)
3972 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3975 stat = GdipIsVisibleRegionRect(rgn, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y, graphics, result);
3978 GdipDeleteRegion(rgn);
3982 GpStatus WINGDIPAPI GdipIsVisibleRectI(GpGraphics *graphics, INT x, INT y, INT width, INT height, BOOL *result)
3984 return GdipIsVisibleRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, result);
3987 typedef GpStatus (*gdip_format_string_callback)(GpGraphics *graphics,
3988 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3989 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3990 INT lineno, const RectF *bounds, void *user_data);
3992 static GpStatus gdip_format_string(GpGraphics *graphics,
3993 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
3994 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3995 gdip_format_string_callback callback, void *user_data)
3998 int sum = 0, height = 0, fit, fitcpy, i, j, lret, nwidth,
3999 nheight, lineend, lineno = 0;
4001 StringAlignment halign;
4005 if(length == -1) length = lstrlenW(string);
4007 stringdup = GdipAlloc((length + 1) * sizeof(WCHAR));
4008 if(!stringdup) return OutOfMemory;
4010 nwidth = roundr(rect->Width);
4011 nheight = roundr(rect->Height);
4013 if (rect->Width >= INT_MAX || rect->Width < 0.5) nwidth = INT_MAX;
4014 if (rect->Height >= INT_MAX || rect->Width < 0.5) nheight = INT_MAX;
4016 for(i = 0, j = 0; i < length; i++){
4017 /* FIXME: This makes the indexes passed to callback inaccurate. */
4018 if(!isprintW(string[i]) && (string[i] != '\n'))
4021 stringdup[j] = string[i];
4027 if (format) halign = format->align;
4028 else halign = StringAlignmentNear;
4030 while(sum < length){
4031 GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum,
4032 nwidth, &fit, NULL, &size);
4038 for(lret = 0; lret < fit; lret++)
4039 if(*(stringdup + sum + lret) == '\n')
4042 /* Line break code (may look strange, but it imitates windows). */
4044 lineend = fit = lret; /* this is not an off-by-one error */
4045 else if(fit < (length - sum)){
4046 if(*(stringdup + sum + fit) == ' ')
4047 while(*(stringdup + sum + fit) == ' ')
4050 while(*(stringdup + sum + fit - 1) != ' '){
4053 if(*(stringdup + sum + fit) == '\t')
4062 while(*(stringdup + sum + lineend - 1) == ' ' ||
4063 *(stringdup + sum + lineend - 1) == '\t')
4069 GetTextExtentExPointW(graphics->hdc, stringdup + sum, lineend,
4070 nwidth, &j, NULL, &size);
4072 bounds.Width = size.cx;
4074 if(height + size.cy > nheight)
4075 bounds.Height = nheight - (height + size.cy);
4077 bounds.Height = size.cy;
4079 bounds.Y = rect->Y + height;
4083 case StringAlignmentNear:
4087 case StringAlignmentCenter:
4088 bounds.X = rect->X + (rect->Width/2) - (bounds.Width/2);
4090 case StringAlignmentFar:
4091 bounds.X = rect->X + rect->Width - bounds.Width;
4095 stat = callback(graphics, stringdup, sum, lineend,
4096 font, rect, format, lineno, &bounds, user_data);
4101 sum += fit + (lret < fitcpy ? 1 : 0);
4105 if(height > nheight)
4108 /* Stop if this was a linewrap (but not if it was a linebreak). */
4109 if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
4113 GdipFree(stringdup);
4118 struct measure_ranges_args {
4122 static GpStatus measure_ranges_callback(GpGraphics *graphics,
4123 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4124 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4125 INT lineno, const RectF *bounds, void *user_data)
4129 struct measure_ranges_args *args = user_data;
4131 for (i=0; i<format->range_count; i++)
4133 INT range_start = max(index, format->character_ranges[i].First);
4134 INT range_end = min(index+length, format->character_ranges[i].First+format->character_ranges[i].Length);
4135 if (range_start < range_end)
4140 range_rect.Y = bounds->Y;
4141 range_rect.Height = bounds->Height;
4143 GetTextExtentExPointW(graphics->hdc, string + index, range_start - index,
4144 INT_MAX, NULL, NULL, &range_size);
4145 range_rect.X = bounds->X + range_size.cx;
4147 GetTextExtentExPointW(graphics->hdc, string + index, range_end - index,
4148 INT_MAX, NULL, NULL, &range_size);
4149 range_rect.Width = (bounds->X + range_size.cx) - range_rect.X;
4151 stat = GdipCombineRegionRect(args->regions[i], &range_rect, CombineModeUnion);
4160 GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,
4161 GDIPCONST WCHAR* string, INT length, GDIPCONST GpFont* font,
4162 GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat *stringFormat,
4163 INT regionCount, GpRegion** regions)
4168 struct measure_ranges_args args;
4171 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics, debugstr_w(string),
4172 length, font, debugstr_rectf(layoutRect), stringFormat, regionCount, regions);
4174 if (!(graphics && string && font && layoutRect && stringFormat && regions))
4175 return InvalidParameter;
4177 if (regionCount < stringFormat->range_count)
4178 return InvalidParameter;
4182 temp_hdc = graphics->hdc = CreateCompatibleDC(0);
4183 if (!temp_hdc) return OutOfMemory;
4186 if (stringFormat->attr)
4187 TRACE("may be ignoring some format flags: attr %x\n", stringFormat->attr);
4189 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
4191 for (i=0; i<stringFormat->range_count; i++)
4193 stat = GdipSetEmpty(regions[i]);
4198 args.regions = regions;
4200 stat = gdip_format_string(graphics, string, length, font, layoutRect, stringFormat,
4201 measure_ranges_callback, &args);
4203 DeleteObject(SelectObject(graphics->hdc, oldfont));
4207 graphics->hdc = NULL;
4214 struct measure_string_args {
4216 INT *codepointsfitted;
4220 static GpStatus measure_string_callback(GpGraphics *graphics,
4221 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4222 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4223 INT lineno, const RectF *bounds, void *user_data)
4225 struct measure_string_args *args = user_data;
4227 if (bounds->Width > args->bounds->Width)
4228 args->bounds->Width = bounds->Width;
4230 if (bounds->Height + bounds->Y > args->bounds->Height + args->bounds->Y)
4231 args->bounds->Height = bounds->Height + bounds->Y - args->bounds->Y;
4233 if (args->codepointsfitted)
4234 *args->codepointsfitted = index + length;
4236 if (args->linesfilled)
4237 (*args->linesfilled)++;
4242 /* Find the smallest rectangle that bounds the text when it is printed in rect
4243 * according to the format options listed in format. If rect has 0 width and
4244 * height, then just find the smallest rectangle that bounds the text when it's
4245 * printed at location (rect->X, rect-Y). */
4246 GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
4247 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
4248 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
4249 INT *codepointsfitted, INT *linesfilled)
4252 struct measure_string_args args;
4255 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics,
4256 debugstr_wn(string, length), length, font, debugstr_rectf(rect), format,
4257 bounds, codepointsfitted, linesfilled);
4259 if(!graphics || !string || !font || !rect || !bounds)
4260 return InvalidParameter;
4264 temp_hdc = graphics->hdc = CreateCompatibleDC(0);
4265 if (!temp_hdc) return OutOfMemory;
4268 if(linesfilled) *linesfilled = 0;
4269 if(codepointsfitted) *codepointsfitted = 0;
4272 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4274 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
4276 bounds->X = rect->X;
4277 bounds->Y = rect->Y;
4278 bounds->Width = 0.0;
4279 bounds->Height = 0.0;
4281 args.bounds = bounds;
4282 args.codepointsfitted = codepointsfitted;
4283 args.linesfilled = linesfilled;
4285 gdip_format_string(graphics, string, length, font, rect, format,
4286 measure_string_callback, &args);
4288 DeleteObject(SelectObject(graphics->hdc, oldfont));
4292 graphics->hdc = NULL;
4299 struct draw_string_args {
4302 REAL ang_cos, ang_sin;
4305 static GpStatus draw_string_callback(GpGraphics *graphics,
4306 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4307 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4308 INT lineno, const RectF *bounds, void *user_data)
4310 struct draw_string_args *args = user_data;
4313 drawcoord.left = drawcoord.right = args->drawbase.x + roundr(args->ang_sin * bounds->Y);
4314 drawcoord.top = drawcoord.bottom = args->drawbase.y + roundr(args->ang_cos * bounds->Y);
4316 DrawTextW(graphics->hdc, string + index, length, &drawcoord, args->drawflags);
4321 GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string,
4322 INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect,
4323 GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush)
4328 TEXTMETRICW textmet;
4329 GpPointF pt[3], rectcpy[4];
4331 REAL angle, rel_width, rel_height;
4332 INT offsety = 0, save_state;
4333 struct draw_string_args args;
4336 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length),
4337 length, font, debugstr_rectf(rect), format, brush);
4339 if(!graphics || !string || !font || !brush || !rect)
4340 return InvalidParameter;
4342 if((brush->bt != BrushTypeSolidColor)){
4343 FIXME("not implemented for given parameters\n");
4344 return NotImplemented;
4349 FIXME("graphics object has no HDC\n");
4354 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4356 /* Should be no need to explicitly test for StringAlignmentNear as
4357 * that is default behavior if no alignment is passed. */
4358 if(format->vertalign != StringAlignmentNear){
4360 GdipMeasureString(graphics, string, length, font, rect, format, &bounds, 0, 0);
4362 if(format->vertalign == StringAlignmentCenter)
4363 offsety = (rect->Height - bounds.Height) / 2;
4364 else if(format->vertalign == StringAlignmentFar)
4365 offsety = (rect->Height - bounds.Height);
4369 save_state = SaveDC(graphics->hdc);
4370 SetBkMode(graphics->hdc, TRANSPARENT);
4371 SetTextColor(graphics->hdc, brush->lb.lbColor);
4379 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
4380 angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X));
4381 args.ang_cos = cos(angle);
4382 args.ang_sin = sin(angle);
4383 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
4384 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
4385 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
4386 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
4388 rectcpy[3].X = rectcpy[0].X = rect->X;
4389 rectcpy[1].Y = rectcpy[0].Y = rect->Y + offsety;
4390 rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width;
4391 rectcpy[3].Y = rectcpy[2].Y = rect->Y + offsety + rect->Height;
4392 transform_and_round_points(graphics, corners, rectcpy, 4);
4394 scaled_rect.X = 0.0;
4395 scaled_rect.Y = 0.0;
4396 scaled_rect.Width = rel_width * rect->Width;
4397 scaled_rect.Height = rel_height * rect->Height;
4399 if (roundr(scaled_rect.Width) != 0 && roundr(scaled_rect.Height) != 0)
4401 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4402 rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
4403 SelectClipRgn(graphics->hdc, rgn);
4406 /* Use gdi to find the font, then perform transformations on it (height,
4408 SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
4409 GetTextMetricsW(graphics->hdc, &textmet);
4412 lfw.lfHeight = roundr(((REAL)lfw.lfHeight) * rel_height);
4413 lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width);
4415 lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0);
4417 gdifont = CreateFontIndirectW(&lfw);
4418 DeleteObject(SelectObject(graphics->hdc, CreateFontIndirectW(&lfw)));
4420 if (!format || format->align == StringAlignmentNear)
4422 args.drawbase.x = corners[0].x;
4423 args.drawbase.y = corners[0].y;
4424 args.drawflags = DT_NOCLIP | DT_EXPANDTABS;
4426 else if (format->align == StringAlignmentCenter)
4428 args.drawbase.x = (corners[0].x + corners[1].x)/2;
4429 args.drawbase.y = (corners[0].y + corners[1].y)/2;
4430 args.drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_CENTER;
4432 else /* (format->align == StringAlignmentFar) */
4434 args.drawbase.x = corners[1].x;
4435 args.drawbase.y = corners[1].y;
4436 args.drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_RIGHT;
4439 gdip_format_string(graphics, string, length, font, &scaled_rect, format,
4440 draw_string_callback, &args);
4443 DeleteObject(gdifont);
4445 RestoreDC(graphics->hdc, save_state);
4450 GpStatus WINGDIPAPI GdipResetClip(GpGraphics *graphics)
4452 TRACE("(%p)\n", graphics);
4455 return InvalidParameter;
4460 return GdipSetInfinite(graphics->clip);
4463 GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics)
4465 TRACE("(%p)\n", graphics);
4468 return InvalidParameter;
4473 graphics->worldtrans->matrix[0] = 1.0;
4474 graphics->worldtrans->matrix[1] = 0.0;
4475 graphics->worldtrans->matrix[2] = 0.0;
4476 graphics->worldtrans->matrix[3] = 1.0;
4477 graphics->worldtrans->matrix[4] = 0.0;
4478 graphics->worldtrans->matrix[5] = 0.0;
4483 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
4485 return GdipEndContainer(graphics, state);
4488 GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
4489 GpMatrixOrder order)
4491 TRACE("(%p, %.2f, %d)\n", graphics, angle, order);
4494 return InvalidParameter;
4499 return GdipRotateMatrix(graphics->worldtrans, angle, order);
4502 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
4504 return GdipBeginContainer2(graphics, state);
4507 GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics *graphics,
4508 GraphicsContainer *state)
4510 GraphicsContainerItem *container;
4513 TRACE("(%p, %p)\n", graphics, state);
4515 if(!graphics || !state)
4516 return InvalidParameter;
4518 sts = init_container(&container, graphics);
4522 list_add_head(&graphics->containers, &container->entry);
4523 *state = graphics->contid = container->contid;
4528 GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics *graphics, GDIPCONST GpRectF *dstrect, GDIPCONST GpRectF *srcrect, GpUnit unit, GraphicsContainer *state)
4530 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
4531 return NotImplemented;
4534 GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics *graphics, GDIPCONST GpRect *dstrect, GDIPCONST GpRect *srcrect, GpUnit unit, GraphicsContainer *state)
4536 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
4537 return NotImplemented;
4540 GpStatus WINGDIPAPI GdipComment(GpGraphics *graphics, UINT sizeData, GDIPCONST BYTE *data)
4542 FIXME("(%p, %d, %p): stub\n", graphics, sizeData, data);
4543 return NotImplemented;
4546 GpStatus WINGDIPAPI GdipEndContainer(GpGraphics *graphics, GraphicsContainer state)
4549 GraphicsContainerItem *container, *container2;
4551 TRACE("(%p, %x)\n", graphics, state);
4554 return InvalidParameter;
4556 LIST_FOR_EACH_ENTRY(container, &graphics->containers, GraphicsContainerItem, entry){
4557 if(container->contid == state)
4561 /* did not find a matching container */
4562 if(&container->entry == &graphics->containers)
4565 sts = restore_container(graphics, container);
4569 /* remove all of the containers on top of the found container */
4570 LIST_FOR_EACH_ENTRY_SAFE(container, container2, &graphics->containers, GraphicsContainerItem, entry){
4571 if(container->contid == state)
4573 list_remove(&container->entry);
4574 delete_container(container);
4577 list_remove(&container->entry);
4578 delete_container(container);
4583 GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
4584 REAL sy, GpMatrixOrder order)
4586 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, sx, sy, order);
4589 return InvalidParameter;
4594 return GdipScaleMatrix(graphics->worldtrans, sx, sy, order);
4597 GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics *graphics, GpGraphics *srcgraphics,
4600 TRACE("(%p, %p, %d)\n", graphics, srcgraphics, mode);
4602 if(!graphics || !srcgraphics)
4603 return InvalidParameter;
4605 return GdipCombineRegionRegion(graphics->clip, srcgraphics->clip, mode);
4608 GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
4609 CompositingMode mode)
4611 TRACE("(%p, %d)\n", graphics, mode);
4614 return InvalidParameter;
4619 graphics->compmode = mode;
4624 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
4625 CompositingQuality quality)
4627 TRACE("(%p, %d)\n", graphics, quality);
4630 return InvalidParameter;
4635 graphics->compqual = quality;
4640 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
4641 InterpolationMode mode)
4643 TRACE("(%p, %d)\n", graphics, mode);
4646 return InvalidParameter;
4651 graphics->interpolation = mode;
4656 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
4658 TRACE("(%p, %.2f)\n", graphics, scale);
4660 if(!graphics || (scale <= 0.0))
4661 return InvalidParameter;
4666 graphics->scale = scale;
4671 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
4673 TRACE("(%p, %d)\n", graphics, unit);
4676 return InvalidParameter;
4681 if(unit == UnitWorld)
4682 return InvalidParameter;
4684 graphics->unit = unit;
4689 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
4692 TRACE("(%p, %d)\n", graphics, mode);
4695 return InvalidParameter;
4700 graphics->pixeloffset = mode;
4705 GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics *graphics, INT x, INT y)
4709 TRACE("(%p,%i,%i)\n", graphics, x, y);
4712 FIXME("not implemented\n");
4714 return NotImplemented;
4717 GpStatus WINGDIPAPI GdipGetRenderingOrigin(GpGraphics *graphics, INT *x, INT *y)
4721 TRACE("(%p,%p,%p)\n", graphics, x, y);
4724 FIXME("not implemented\n");
4728 return NotImplemented;
4731 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
4733 TRACE("(%p, %d)\n", graphics, mode);
4736 return InvalidParameter;
4741 graphics->smoothing = mode;
4746 GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics *graphics, UINT contrast)
4748 TRACE("(%p, %d)\n", graphics, contrast);
4751 return InvalidParameter;
4753 graphics->textcontrast = contrast;
4758 GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
4759 TextRenderingHint hint)
4761 TRACE("(%p, %d)\n", graphics, hint);
4764 return InvalidParameter;
4769 graphics->texthint = hint;
4774 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
4776 TRACE("(%p, %p)\n", graphics, matrix);
4778 if(!graphics || !matrix)
4779 return InvalidParameter;
4784 GdipDeleteMatrix(graphics->worldtrans);
4785 return GdipCloneMatrix(matrix, &graphics->worldtrans);
4788 GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
4789 REAL dy, GpMatrixOrder order)
4791 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, dx, dy, order);
4794 return InvalidParameter;
4799 return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order);
4802 /*****************************************************************************
4803 * GdipSetClipHrgn [GDIPLUS.@]
4805 GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics *graphics, HRGN hrgn, CombineMode mode)
4810 TRACE("(%p, %p, %d)\n", graphics, hrgn, mode);
4813 return InvalidParameter;
4815 status = GdipCreateRegionHrgn(hrgn, ®ion);
4819 status = GdipSetClipRegion(graphics, region, mode);
4821 GdipDeleteRegion(region);
4825 GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics *graphics, GpPath *path, CombineMode mode)
4827 TRACE("(%p, %p, %d)\n", graphics, path, mode);
4830 return InvalidParameter;
4835 return GdipCombineRegionPath(graphics->clip, path, mode);
4838 GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y,
4839 REAL width, REAL height,
4844 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics, x, y, width, height, mode);
4847 return InvalidParameter;
4855 rect.Height = height;
4857 return GdipCombineRegionRect(graphics->clip, &rect, mode);
4860 GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y,
4861 INT width, INT height,
4864 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics, x, y, width, height, mode);
4867 return InvalidParameter;
4872 return GdipSetClipRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, mode);
4875 GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
4878 TRACE("(%p, %p, %d)\n", graphics, region, mode);
4880 if(!graphics || !region)
4881 return InvalidParameter;
4886 return GdipCombineRegionRegion(graphics->clip, region, mode);
4889 GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile *metafile,
4894 TRACE("(%p,%u)\n", metafile, limitDpi);
4897 FIXME("not implemented\n");
4899 return NotImplemented;
4902 GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points,
4908 TRACE("(%p, %p, %d)\n", graphics, points, count);
4910 if(!graphics || !pen || count<=0)
4911 return InvalidParameter;
4918 FIXME("graphics object has no HDC\n");
4922 pti = GdipAlloc(sizeof(POINT) * count);
4924 save_state = prepare_dc(graphics, pen);
4925 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
4927 transform_and_round_points(graphics, pti, (GpPointF*)points, count);
4928 Polygon(graphics->hdc, pti, count);
4930 restore_dc(graphics, save_state);
4936 GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points,
4943 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
4945 if(count<=0) return InvalidParameter;
4946 ptf = GdipAlloc(sizeof(GpPointF) * count);
4948 for(i = 0;i < count; i++){
4949 ptf[i].X = (REAL)points[i].X;
4950 ptf[i].Y = (REAL)points[i].Y;
4953 ret = GdipDrawPolygon(graphics,pen,ptf,count);
4959 GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
4961 TRACE("(%p, %p)\n", graphics, dpi);
4963 if(!graphics || !dpi)
4964 return InvalidParameter;
4969 if (graphics->image)
4970 *dpi = graphics->image->xres;
4972 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
4977 GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
4979 TRACE("(%p, %p)\n", graphics, dpi);
4981 if(!graphics || !dpi)
4982 return InvalidParameter;
4987 if (graphics->image)
4988 *dpi = graphics->image->yres;
4990 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
4995 GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix,
4996 GpMatrixOrder order)
5001 TRACE("(%p, %p, %d)\n", graphics, matrix, order);
5003 if(!graphics || !matrix)
5004 return InvalidParameter;
5009 m = *(graphics->worldtrans);
5011 ret = GdipMultiplyMatrix(&m, matrix, order);
5013 *(graphics->worldtrans) = m;
5018 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5019 static const COLORREF DC_BACKGROUND_KEY = 0x0c0b0d;
5021 GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
5023 TRACE("(%p, %p)\n", graphics, hdc);
5025 if(!graphics || !hdc)
5026 return InvalidParameter;
5031 if (!graphics->hdc ||
5032 (graphics->image && graphics->image->type == ImageTypeBitmap && ((GpBitmap*)graphics->image)->format & PixelFormatAlpha))
5034 /* Create a fake HDC and fill it with a constant color. */
5039 BITMAPINFOHEADER bmih;
5042 stat = get_graphics_bounds(graphics, &bounds);
5046 graphics->temp_hbitmap_width = bounds.Width;
5047 graphics->temp_hbitmap_height = bounds.Height;
5049 bmih.biSize = sizeof(bmih);
5050 bmih.biWidth = graphics->temp_hbitmap_width;
5051 bmih.biHeight = -graphics->temp_hbitmap_height;
5053 bmih.biBitCount = 32;
5054 bmih.biCompression = BI_RGB;
5055 bmih.biSizeImage = 0;
5056 bmih.biXPelsPerMeter = 0;
5057 bmih.biYPelsPerMeter = 0;
5059 bmih.biClrImportant = 0;
5061 hbitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
5062 (void**)&graphics->temp_bits, NULL, 0);
5064 return GenericError;
5066 temp_hdc = CreateCompatibleDC(0);
5069 DeleteObject(hbitmap);
5070 return GenericError;
5073 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
5074 ((DWORD*)graphics->temp_bits)[i] = DC_BACKGROUND_KEY;
5076 SelectObject(temp_hdc, hbitmap);
5078 graphics->temp_hbitmap = hbitmap;
5079 *hdc = graphics->temp_hdc = temp_hdc;
5083 *hdc = graphics->hdc;
5086 graphics->busy = TRUE;
5091 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
5093 TRACE("(%p, %p)\n", graphics, hdc);
5095 if(!graphics || !hdc)
5096 return InvalidParameter;
5098 if((graphics->hdc != hdc && graphics->temp_hdc != hdc) || !(graphics->busy))
5099 return InvalidParameter;
5101 if (graphics->temp_hdc == hdc)
5106 /* Find the pixels that have changed, and mark them as opaque. */
5107 pos = (DWORD*)graphics->temp_bits;
5108 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
5110 if (*pos != DC_BACKGROUND_KEY)
5117 /* Write the changed pixels to the real target. */
5118 alpha_blend_pixels(graphics, 0, 0, graphics->temp_bits,
5119 graphics->temp_hbitmap_width, graphics->temp_hbitmap_height,
5120 graphics->temp_hbitmap_width * 4);
5123 DeleteDC(graphics->temp_hdc);
5124 DeleteObject(graphics->temp_hbitmap);
5125 graphics->temp_hdc = NULL;
5126 graphics->temp_hbitmap = NULL;
5129 graphics->busy = FALSE;
5134 GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
5139 TRACE("(%p, %p)\n", graphics, region);
5141 if(!graphics || !region)
5142 return InvalidParameter;
5147 if((status = GdipCloneRegion(graphics->clip, &clip)) != Ok)
5150 /* free everything except root node and header */
5151 delete_element(®ion->node);
5152 memcpy(region, clip, sizeof(GpRegion));
5158 static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace dst_space,
5159 GpCoordinateSpace src_space, GpMatrix **matrix)
5161 GpStatus stat = GdipCreateMatrix(matrix);
5164 if (dst_space != src_space && stat == Ok)
5166 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
5168 if(graphics->unit != UnitDisplay)
5169 unitscale *= graphics->scale;
5171 /* transform from src_space to CoordinateSpacePage */
5174 case CoordinateSpaceWorld:
5175 GdipMultiplyMatrix(*matrix, graphics->worldtrans, MatrixOrderAppend);
5177 case CoordinateSpacePage:
5179 case CoordinateSpaceDevice:
5180 GdipScaleMatrix(*matrix, 1.0/unitscale, 1.0/unitscale, MatrixOrderAppend);
5184 /* transform from CoordinateSpacePage to dst_space */
5187 case CoordinateSpaceWorld:
5189 GpMatrix *inverted_transform;
5190 stat = GdipCloneMatrix(graphics->worldtrans, &inverted_transform);
5193 stat = GdipInvertMatrix(inverted_transform);
5195 GdipMultiplyMatrix(*matrix, inverted_transform, MatrixOrderAppend);
5196 GdipDeleteMatrix(inverted_transform);
5200 case CoordinateSpacePage:
5202 case CoordinateSpaceDevice:
5203 GdipScaleMatrix(*matrix, unitscale, unitscale, MatrixOrderAppend);
5210 GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space,
5211 GpCoordinateSpace src_space, GpPointF *points, INT count)
5216 if(!graphics || !points || count <= 0)
5217 return InvalidParameter;
5222 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
5224 if (src_space == dst_space) return Ok;
5226 stat = get_graphics_transform(graphics, dst_space, src_space, &matrix);
5230 stat = GdipTransformMatrixPoints(matrix, points, count);
5232 GdipDeleteMatrix(matrix);
5238 GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space,
5239 GpCoordinateSpace src_space, GpPoint *points, INT count)
5245 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
5248 return InvalidParameter;
5250 pointsF = GdipAlloc(sizeof(GpPointF) * count);
5254 for(i = 0; i < count; i++){
5255 pointsF[i].X = (REAL)points[i].X;
5256 pointsF[i].Y = (REAL)points[i].Y;
5259 ret = GdipTransformPoints(graphics, dst_space, src_space, pointsF, count);
5262 for(i = 0; i < count; i++){
5263 points[i].X = roundr(pointsF[i].X);
5264 points[i].Y = roundr(pointsF[i].Y);
5271 HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void)
5283 /*****************************************************************************
5284 * GdipTranslateClip [GDIPLUS.@]
5286 GpStatus WINGDIPAPI GdipTranslateClip(GpGraphics *graphics, REAL dx, REAL dy)
5288 TRACE("(%p, %.2f, %.2f)\n", graphics, dx, dy);
5291 return InvalidParameter;
5296 return GdipTranslateRegion(graphics->clip, dx, dy);
5299 /*****************************************************************************
5300 * GdipTranslateClipI [GDIPLUS.@]
5302 GpStatus WINGDIPAPI GdipTranslateClipI(GpGraphics *graphics, INT dx, INT dy)
5304 TRACE("(%p, %d, %d)\n", graphics, dx, dy);
5307 return InvalidParameter;
5312 return GdipTranslateRegion(graphics->clip, (REAL)dx, (REAL)dy);
5316 /*****************************************************************************
5317 * GdipMeasureDriverString [GDIPLUS.@]
5319 GpStatus WINGDIPAPI GdipMeasureDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5320 GDIPCONST GpFont *font, GDIPCONST PointF *positions,
5321 INT flags, GDIPCONST GpMatrix *matrix, RectF *boundingBox)
5323 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics, text, length, font, positions, flags, matrix, boundingBox);
5324 return NotImplemented;
5327 /*****************************************************************************
5328 * GdipDrawDriverString [GDIPLUS.@]
5330 GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5331 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
5332 GDIPCONST PointF *positions, INT flags,
5333 GDIPCONST GpMatrix *matrix )
5335 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics, text, length, font, brush, positions, flags, matrix);
5336 return NotImplemented;
5339 GpStatus WINGDIPAPI GdipRecordMetafile(HDC hdc, EmfType type, GDIPCONST GpRectF *frameRect,
5340 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
5342 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
5343 return NotImplemented;
5346 /*****************************************************************************
5347 * GdipRecordMetafileI [GDIPLUS.@]
5349 GpStatus WINGDIPAPI GdipRecordMetafileI(HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
5350 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
5352 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
5353 return NotImplemented;
5356 GpStatus WINGDIPAPI GdipRecordMetafileStream(IStream *stream, HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
5357 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
5359 FIXME("(%p %p %d %p %d %p %p): stub\n", stream, hdc, type, frameRect, frameUnit, desc, metafile);
5360 return NotImplemented;
5363 /*****************************************************************************
5364 * GdipIsVisibleClipEmpty [GDIPLUS.@]
5366 GpStatus WINGDIPAPI GdipIsVisibleClipEmpty(GpGraphics *graphics, BOOL *res)
5371 TRACE("(%p, %p)\n", graphics, res);
5373 if((stat = GdipCreateRegion(&rgn)) != Ok)
5376 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
5379 stat = GdipIsEmptyRegion(rgn, graphics, res);
5382 GdipDeleteRegion(rgn);
5386 GpStatus WINGDIPAPI GdipGetHemfFromMetafile(GpMetafile *metafile, HENHMETAFILE *hEmf)
5388 FIXME("(%p,%p): stub\n", metafile, hEmf);
5390 if (!metafile || !hEmf)
5391 return InvalidParameter;
5395 return NotImplemented;