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,
2165 return NotImplemented;
2167 if(!graphics || !image || !points || count != 3)
2168 return InvalidParameter;
2170 TRACE("%s %s %s\n", debugstr_pointf(&points[0]), debugstr_pointf(&points[1]),
2171 debugstr_pointf(&points[2]));
2173 memcpy(ptf, points, 3 * sizeof(GpPointF));
2174 ptf[3].X = ptf[2].X + ptf[1].X - ptf[0].X;
2175 ptf[3].Y = ptf[2].Y + ptf[1].Y - ptf[0].Y;
2176 if (!srcwidth || !srcheight || ptf[3].X == ptf[0].X || ptf[3].Y == ptf[0].Y)
2178 transform_and_round_points(graphics, pti, ptf, 4);
2184 FIXME("graphics object has no HDC\n");
2187 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2188 if(srcUnit == UnitInch)
2189 dx = dy = (REAL) INCH_HIMETRIC;
2190 else if(srcUnit == UnitPixel){
2191 dx = ((REAL) INCH_HIMETRIC) /
2192 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
2193 dy = ((REAL) INCH_HIMETRIC) /
2194 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
2197 return NotImplemented;
2199 if(IPicture_Render(image->picture, graphics->hdc,
2200 pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
2201 srcx * dx, srcy * dy,
2202 srcwidth * dx, srcheight * dy,
2205 callback(callbackData);
2206 return GenericError;
2209 else if (image->type == ImageTypeBitmap)
2211 GpBitmap* bitmap = (GpBitmap*)image;
2214 if (srcUnit == UnitInch)
2215 dx = dy = 96.0; /* FIXME: use the image resolution */
2216 else if (srcUnit == UnitPixel)
2219 return NotImplemented;
2221 if (imageAttributes ||
2222 (graphics->image && graphics->image->type == ImageTypeBitmap) ||
2223 !((GpBitmap*)image)->hbitmap ||
2224 ptf[1].Y != ptf[0].Y || ptf[2].X != ptf[0].X)
2229 RECT src_area, dst_area;
2230 int i, x, y, stride;
2231 GpMatrix *dst_to_src;
2232 REAL m11, m12, m21, m22, mdx, mdy;
2235 src_area.left = srcx*dx;
2236 src_area.top = srcy*dy;
2237 src_area.right = (srcx+srcwidth)*dx;
2238 src_area.bottom = (srcy+srcheight)*dy;
2240 dst_area.left = dst_area.right = pti[0].x;
2241 dst_area.top = dst_area.bottom = pti[0].y;
2244 if (dst_area.left > pti[i].x) dst_area.left = pti[i].x;
2245 if (dst_area.right < pti[i].x) dst_area.right = pti[i].x;
2246 if (dst_area.top > pti[i].y) dst_area.top = pti[i].y;
2247 if (dst_area.bottom < pti[i].y) dst_area.bottom = pti[i].y;
2250 m11 = (ptf[1].X - ptf[0].X) / srcwidth;
2251 m21 = (ptf[2].X - ptf[0].X) / srcheight;
2252 mdx = ptf[0].X - m11 * srcx - m21 * srcy;
2253 m12 = (ptf[1].Y - ptf[0].Y) / srcwidth;
2254 m22 = (ptf[2].Y - ptf[0].Y) / srcheight;
2255 mdy = ptf[0].Y - m12 * srcx - m22 * srcy;
2257 stat = GdipCreateMatrix2(m11, m12, m21, m22, mdx, mdy, &dst_to_src);
2258 if (stat != Ok) return stat;
2260 stat = GdipInvertMatrix(dst_to_src);
2263 GdipDeleteMatrix(dst_to_src);
2267 data = GdipAlloc(sizeof(ARGB) * (dst_area.right - dst_area.left) * (dst_area.bottom - dst_area.top));
2270 GdipDeleteMatrix(dst_to_src);
2274 stride = sizeof(ARGB) * (dst_area.right - dst_area.left);
2276 if (imageAttributes &&
2277 (imageAttributes->wrap != WrapModeClamp ||
2278 imageAttributes->outside_color != 0x00000000 ||
2279 imageAttributes->clamp))
2283 FIXME("Image wrap mode not implemented\n");
2286 for (x=dst_area.left; x<dst_area.right; x++)
2288 for (y=dst_area.top; y<dst_area.bottom; y++)
2290 GpPointF src_pointf;
2297 GdipTransformMatrixPoints(dst_to_src, &src_pointf, 1);
2299 src_x = roundr(src_pointf.X);
2300 src_y = roundr(src_pointf.Y);
2302 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2304 if (src_x < src_area.left || src_x >= src_area.right ||
2305 src_y < src_area.top || src_y >= src_area.bottom)
2308 GdipBitmapGetPixel(bitmap, src_x, src_y, src_color);
2312 GdipDeleteMatrix(dst_to_src);
2314 if (imageAttributes)
2316 if (imageAttributes->colorkeys[ColorAdjustTypeBitmap].enabled ||
2317 imageAttributes->colorkeys[ColorAdjustTypeDefault].enabled)
2319 const struct color_key *key;
2320 BYTE min_blue, min_green, min_red;
2321 BYTE max_blue, max_green, max_red;
2323 if (imageAttributes->colorkeys[ColorAdjustTypeBitmap].enabled)
2324 key = &imageAttributes->colorkeys[ColorAdjustTypeBitmap];
2326 key = &imageAttributes->colorkeys[ColorAdjustTypeDefault];
2328 min_blue = key->low&0xff;
2329 min_green = (key->low>>8)&0xff;
2330 min_red = (key->low>>16)&0xff;
2332 max_blue = key->high&0xff;
2333 max_green = (key->high>>8)&0xff;
2334 max_red = (key->high>>16)&0xff;
2336 for (x=dst_area.left; x<dst_area.right; x++)
2337 for (y=dst_area.top; y<dst_area.bottom; y++)
2340 BYTE blue, green, red;
2341 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2342 blue = *src_color&0xff;
2343 green = (*src_color>>8)&0xff;
2344 red = (*src_color>>16)&0xff;
2345 if (blue >= min_blue && green >= min_green && red >= min_red &&
2346 blue <= max_blue && green <= max_green && red <= max_red)
2347 *src_color = 0x00000000;
2351 if (imageAttributes->colorremaptables[ColorAdjustTypeBitmap].enabled ||
2352 imageAttributes->colorremaptables[ColorAdjustTypeDefault].enabled)
2354 const struct color_remap_table *table;
2356 if (imageAttributes->colorremaptables[ColorAdjustTypeBitmap].enabled)
2357 table = &imageAttributes->colorremaptables[ColorAdjustTypeBitmap];
2359 table = &imageAttributes->colorremaptables[ColorAdjustTypeDefault];
2361 for (x=dst_area.left; x<dst_area.right; x++)
2362 for (y=dst_area.top; y<dst_area.bottom; y++)
2365 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2366 for (i=0; i<table->mapsize; i++)
2368 if (*src_color == table->colormap[i].oldColor.Argb)
2370 *src_color = table->colormap[i].newColor.Argb;
2377 if (imageAttributes->colormatrices[ColorAdjustTypeBitmap].enabled ||
2378 imageAttributes->colormatrices[ColorAdjustTypeDefault].enabled)
2382 FIXME("Color transforms not implemented\n");
2385 if (imageAttributes->gamma_enabled[ColorAdjustTypeBitmap] ||
2386 imageAttributes->gamma_enabled[ColorAdjustTypeDefault])
2390 FIXME("Gamma adjustment not implemented\n");
2394 stat = alpha_blend_pixels(graphics, dst_area.left, dst_area.top,
2395 data, dst_area.right - dst_area.left, dst_area.bottom - dst_area.top, stride);
2404 int temp_hdc=0, temp_bitmap=0;
2405 HBITMAP hbitmap, old_hbm=NULL;
2407 if (!(bitmap->format == PixelFormat16bppRGB555 ||
2408 bitmap->format == PixelFormat24bppRGB ||
2409 bitmap->format == PixelFormat32bppRGB ||
2410 bitmap->format == PixelFormat32bppPARGB))
2412 BITMAPINFOHEADER bih;
2414 PixelFormat dst_format;
2416 /* we can't draw a bitmap of this format directly */
2417 hdc = CreateCompatibleDC(0);
2421 bih.biSize = sizeof(BITMAPINFOHEADER);
2422 bih.biWidth = bitmap->width;
2423 bih.biHeight = -bitmap->height;
2425 bih.biBitCount = 32;
2426 bih.biCompression = BI_RGB;
2427 bih.biSizeImage = 0;
2428 bih.biXPelsPerMeter = 0;
2429 bih.biYPelsPerMeter = 0;
2431 bih.biClrImportant = 0;
2433 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
2434 (void**)&temp_bits, NULL, 0);
2436 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
2437 dst_format = PixelFormat32bppPARGB;
2439 dst_format = PixelFormat32bppRGB;
2441 convert_pixels(bitmap->width, bitmap->height,
2442 bitmap->width*4, temp_bits, dst_format,
2443 bitmap->stride, bitmap->bits, bitmap->format, bitmap->image.palette_entries);
2447 hbitmap = bitmap->hbitmap;
2449 temp_hdc = (hdc == 0);
2454 if (!hdc) hdc = CreateCompatibleDC(0);
2455 old_hbm = SelectObject(hdc, hbitmap);
2458 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
2462 bf.BlendOp = AC_SRC_OVER;
2464 bf.SourceConstantAlpha = 255;
2465 bf.AlphaFormat = AC_SRC_ALPHA;
2467 GdiAlphaBlend(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, bf);
2472 StretchBlt(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
2473 hdc, srcx*dx, srcy*dy, srcwidth*dx, srcheight*dy, SRCCOPY);
2478 SelectObject(hdc, old_hbm);
2483 DeleteObject(hbitmap);
2488 ERR("GpImage with no IPicture or HBITMAP?!\n");
2489 return NotImplemented;
2495 GpStatus WINGDIPAPI GdipDrawImagePointsRectI(GpGraphics *graphics, GpImage *image,
2496 GDIPCONST GpPoint *points, INT count, INT srcx, INT srcy, INT srcwidth,
2497 INT srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
2498 DrawImageAbort callback, VOID * callbackData)
2500 GpPointF pointsF[3];
2503 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics, image, points, count,
2504 srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
2507 if(!points || count!=3)
2508 return InvalidParameter;
2510 for(i = 0; i < count; i++){
2511 pointsF[i].X = (REAL)points[i].X;
2512 pointsF[i].Y = (REAL)points[i].Y;
2515 return GdipDrawImagePointsRect(graphics, image, pointsF, count, (REAL)srcx, (REAL)srcy,
2516 (REAL)srcwidth, (REAL)srcheight, srcUnit, imageAttributes,
2517 callback, callbackData);
2520 GpStatus WINGDIPAPI GdipDrawImageRectRect(GpGraphics *graphics, GpImage *image,
2521 REAL dstx, REAL dsty, REAL dstwidth, REAL dstheight, REAL srcx, REAL srcy,
2522 REAL srcwidth, REAL srcheight, GpUnit srcUnit,
2523 GDIPCONST GpImageAttributes* imageattr, DrawImageAbort callback,
2524 VOID * callbackData)
2528 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
2529 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
2530 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
2534 points[1].X = dstx + dstwidth;
2537 points[2].Y = dsty + dstheight;
2539 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2540 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
2543 GpStatus WINGDIPAPI GdipDrawImageRectRectI(GpGraphics *graphics, GpImage *image,
2544 INT dstx, INT dsty, INT dstwidth, INT dstheight, INT srcx, INT srcy,
2545 INT srcwidth, INT srcheight, GpUnit srcUnit,
2546 GDIPCONST GpImageAttributes* imageAttributes, DrawImageAbort callback,
2547 VOID * callbackData)
2551 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
2552 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
2553 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
2557 points[1].X = dstx + dstwidth;
2560 points[2].Y = dsty + dstheight;
2562 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2563 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
2566 GpStatus WINGDIPAPI GdipDrawImageRect(GpGraphics *graphics, GpImage *image,
2567 REAL x, REAL y, REAL width, REAL height)
2573 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, image, x, y, width, height);
2575 if(!graphics || !image)
2576 return InvalidParameter;
2578 ret = GdipGetImageBounds(image, &bounds, &unit);
2582 return GdipDrawImageRectRect(graphics, image, x, y, width, height,
2583 bounds.X, bounds.Y, bounds.Width, bounds.Height,
2584 unit, NULL, NULL, NULL);
2587 GpStatus WINGDIPAPI GdipDrawImageRectI(GpGraphics *graphics, GpImage *image,
2588 INT x, INT y, INT width, INT height)
2590 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, image, x, y, width, height);
2592 return GdipDrawImageRect(graphics, image, (REAL)x, (REAL)y, (REAL)width, (REAL)height);
2595 GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1,
2596 REAL y1, REAL x2, REAL y2)
2602 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1, x2, y2);
2604 if(!pen || !graphics)
2605 return InvalidParameter;
2612 FIXME("graphics object has no HDC\n");
2621 save_state = prepare_dc(graphics, pen);
2623 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
2625 restore_dc(graphics, save_state);
2630 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
2631 INT y1, INT x2, INT y2)
2637 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x1, y1, x2, y2);
2639 if(!pen || !graphics)
2640 return InvalidParameter;
2647 FIXME("graphics object has no HDC\n");
2656 save_state = prepare_dc(graphics, pen);
2658 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
2660 restore_dc(graphics, save_state);
2665 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
2666 GpPointF *points, INT count)
2671 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2673 if(!pen || !graphics || (count < 2))
2674 return InvalidParameter;
2681 FIXME("graphics object has no HDC\n");
2685 save_state = prepare_dc(graphics, pen);
2687 retval = draw_polyline(graphics, pen, points, count, TRUE);
2689 restore_dc(graphics, save_state);
2694 GpStatus WINGDIPAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, GDIPCONST
2695 GpPoint *points, INT count)
2699 GpPointF *ptf = NULL;
2702 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2704 if(!pen || !graphics || (count < 2))
2705 return InvalidParameter;
2712 FIXME("graphics object has no HDC\n");
2716 ptf = GdipAlloc(count * sizeof(GpPointF));
2717 if(!ptf) return OutOfMemory;
2719 for(i = 0; i < count; i ++){
2720 ptf[i].X = (REAL) points[i].X;
2721 ptf[i].Y = (REAL) points[i].Y;
2724 save_state = prepare_dc(graphics, pen);
2726 retval = draw_polyline(graphics, pen, ptf, count, TRUE);
2728 restore_dc(graphics, save_state);
2734 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
2739 TRACE("(%p, %p, %p)\n", graphics, pen, path);
2741 if(!pen || !graphics)
2742 return InvalidParameter;
2749 FIXME("graphics object has no HDC\n");
2753 save_state = prepare_dc(graphics, pen);
2755 retval = draw_poly(graphics, pen, path->pathdata.Points,
2756 path->pathdata.Types, path->pathdata.Count, TRUE);
2758 restore_dc(graphics, save_state);
2763 GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
2764 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2768 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
2769 width, height, startAngle, sweepAngle);
2771 if(!graphics || !pen)
2772 return InvalidParameter;
2779 FIXME("graphics object has no HDC\n");
2783 save_state = prepare_dc(graphics, pen);
2784 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2786 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
2788 restore_dc(graphics, save_state);
2793 GpStatus WINGDIPAPI GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x,
2794 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2796 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
2797 width, height, startAngle, sweepAngle);
2799 return GdipDrawPie(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2802 GpStatus WINGDIPAPI GdipDrawRectangle(GpGraphics *graphics, GpPen *pen, REAL x,
2803 REAL y, REAL width, REAL height)
2809 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
2811 if(!pen || !graphics)
2812 return InvalidParameter;
2819 FIXME("graphics object has no HDC\n");
2825 ptf[1].X = x + width;
2827 ptf[2].X = x + width;
2828 ptf[2].Y = y + height;
2830 ptf[3].Y = y + height;
2832 save_state = prepare_dc(graphics, pen);
2833 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2835 transform_and_round_points(graphics, pti, ptf, 4);
2836 Polygon(graphics->hdc, pti, 4);
2838 restore_dc(graphics, save_state);
2843 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
2844 INT y, INT width, INT height)
2846 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
2848 return GdipDrawRectangle(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2851 GpStatus WINGDIPAPI GdipDrawRectangles(GpGraphics *graphics, GpPen *pen,
2852 GDIPCONST GpRectF* rects, INT count)
2858 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
2860 if(!graphics || !pen || !rects || count < 1)
2861 return InvalidParameter;
2868 FIXME("graphics object has no HDC\n");
2872 ptf = GdipAlloc(4 * count * sizeof(GpPointF));
2873 pti = GdipAlloc(4 * count * sizeof(POINT));
2881 for(i = 0; i < count; i++){
2882 ptf[4 * i + 3].X = ptf[4 * i].X = rects[i].X;
2883 ptf[4 * i + 1].Y = ptf[4 * i].Y = rects[i].Y;
2884 ptf[4 * i + 2].X = ptf[4 * i + 1].X = rects[i].X + rects[i].Width;
2885 ptf[4 * i + 3].Y = ptf[4 * i + 2].Y = rects[i].Y + rects[i].Height;
2888 save_state = prepare_dc(graphics, pen);
2889 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2891 transform_and_round_points(graphics, pti, ptf, 4 * count);
2893 for(i = 0; i < count; i++)
2894 Polygon(graphics->hdc, &pti[4 * i], 4);
2896 restore_dc(graphics, save_state);
2904 GpStatus WINGDIPAPI GdipDrawRectanglesI(GpGraphics *graphics, GpPen *pen,
2905 GDIPCONST GpRect* rects, INT count)
2911 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
2913 if(!rects || count<=0)
2914 return InvalidParameter;
2916 rectsF = GdipAlloc(sizeof(GpRectF) * count);
2920 for(i = 0;i < count;i++){
2921 rectsF[i].X = (REAL)rects[i].X;
2922 rectsF[i].Y = (REAL)rects[i].Y;
2923 rectsF[i].Width = (REAL)rects[i].Width;
2924 rectsF[i].Height = (REAL)rects[i].Height;
2927 ret = GdipDrawRectangles(graphics, pen, rectsF, count);
2933 GpStatus WINGDIPAPI GdipFillClosedCurve2(GpGraphics *graphics, GpBrush *brush,
2934 GDIPCONST GpPointF *points, INT count, REAL tension, GpFillMode fill)
2939 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2940 count, tension, fill);
2942 if(!graphics || !brush || !points)
2943 return InvalidParameter;
2948 if(count == 1) /* Do nothing */
2951 stat = GdipCreatePath(fill, &path);
2955 stat = GdipAddPathClosedCurve2(path, points, count, tension);
2957 GdipDeletePath(path);
2961 stat = GdipFillPath(graphics, brush, path);
2963 GdipDeletePath(path);
2967 GdipDeletePath(path);
2972 GpStatus WINGDIPAPI GdipFillClosedCurve2I(GpGraphics *graphics, GpBrush *brush,
2973 GDIPCONST GpPoint *points, INT count, REAL tension, GpFillMode fill)
2979 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2980 count, tension, fill);
2982 if(!points || count == 0)
2983 return InvalidParameter;
2985 if(count == 1) /* Do nothing */
2988 ptf = GdipAlloc(sizeof(GpPointF)*count);
2992 for(i = 0;i < count;i++){
2993 ptf[i].X = (REAL)points[i].X;
2994 ptf[i].Y = (REAL)points[i].Y;
2997 stat = GdipFillClosedCurve2(graphics, brush, ptf, count, tension, fill);
3004 GpStatus WINGDIPAPI GdipFillClosedCurve(GpGraphics *graphics, GpBrush *brush,
3005 GDIPCONST GpPointF *points, INT count)
3007 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3008 return GdipFillClosedCurve2(graphics, brush, points, count,
3009 0.5f, FillModeAlternate);
3012 GpStatus WINGDIPAPI GdipFillClosedCurveI(GpGraphics *graphics, GpBrush *brush,
3013 GDIPCONST GpPoint *points, INT count)
3015 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3016 return GdipFillClosedCurve2I(graphics, brush, points, count,
3017 0.5f, FillModeAlternate);
3020 GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x,
3021 REAL y, REAL width, REAL height)
3027 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
3029 if(!graphics || !brush)
3030 return InvalidParameter;
3037 FIXME("graphics object has no HDC\n");
3043 ptf[1].X = x + width;
3044 ptf[1].Y = y + height;
3046 save_state = SaveDC(graphics->hdc);
3047 EndPath(graphics->hdc);
3049 transform_and_round_points(graphics, pti, ptf, 2);
3051 BeginPath(graphics->hdc);
3052 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
3053 EndPath(graphics->hdc);
3055 brush_fill_path(graphics, brush);
3057 RestoreDC(graphics->hdc, save_state);
3062 GpStatus WINGDIPAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x,
3063 INT y, INT width, INT height)
3065 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
3067 return GdipFillEllipse(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
3070 GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
3075 TRACE("(%p, %p, %p)\n", graphics, brush, path);
3077 if(!brush || !graphics || !path)
3078 return InvalidParameter;
3085 FIXME("graphics object has no HDC\n");
3089 save_state = SaveDC(graphics->hdc);
3090 EndPath(graphics->hdc);
3091 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
3094 BeginPath(graphics->hdc);
3095 retval = draw_poly(graphics, NULL, path->pathdata.Points,
3096 path->pathdata.Types, path->pathdata.Count, FALSE);
3101 EndPath(graphics->hdc);
3102 brush_fill_path(graphics, brush);
3107 RestoreDC(graphics->hdc, save_state);
3112 GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
3113 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
3117 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3118 graphics, brush, x, y, width, height, startAngle, sweepAngle);
3120 if(!graphics || !brush)
3121 return InvalidParameter;
3128 FIXME("graphics object has no HDC\n");
3132 save_state = SaveDC(graphics->hdc);
3133 EndPath(graphics->hdc);
3135 BeginPath(graphics->hdc);
3136 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
3137 EndPath(graphics->hdc);
3139 brush_fill_path(graphics, brush);
3141 RestoreDC(graphics->hdc, save_state);
3146 GpStatus WINGDIPAPI GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x,
3147 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
3149 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3150 graphics, brush, x, y, width, height, startAngle, sweepAngle);
3152 return GdipFillPie(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
3155 GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush,
3156 GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)
3159 GpPointF *ptf = NULL;
3161 GpStatus retval = Ok;
3163 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
3165 if(!graphics || !brush || !points || !count)
3166 return InvalidParameter;
3173 FIXME("graphics object has no HDC\n");
3177 ptf = GdipAlloc(count * sizeof(GpPointF));
3178 pti = GdipAlloc(count * sizeof(POINT));
3180 retval = OutOfMemory;
3184 memcpy(ptf, points, count * sizeof(GpPointF));
3186 save_state = SaveDC(graphics->hdc);
3187 EndPath(graphics->hdc);
3188 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
3191 transform_and_round_points(graphics, pti, ptf, count);
3193 BeginPath(graphics->hdc);
3194 Polygon(graphics->hdc, pti, count);
3195 EndPath(graphics->hdc);
3197 brush_fill_path(graphics, brush);
3199 RestoreDC(graphics->hdc, save_state);
3208 GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
3209 GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
3212 GpPointF *ptf = NULL;
3214 GpStatus retval = Ok;
3216 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
3218 if(!graphics || !brush || !points || !count)
3219 return InvalidParameter;
3226 FIXME("graphics object has no HDC\n");
3230 ptf = GdipAlloc(count * sizeof(GpPointF));
3231 pti = GdipAlloc(count * sizeof(POINT));
3233 retval = OutOfMemory;
3237 for(i = 0; i < count; i ++){
3238 ptf[i].X = (REAL) points[i].X;
3239 ptf[i].Y = (REAL) points[i].Y;
3242 save_state = SaveDC(graphics->hdc);
3243 EndPath(graphics->hdc);
3244 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
3247 transform_and_round_points(graphics, pti, ptf, count);
3249 BeginPath(graphics->hdc);
3250 Polygon(graphics->hdc, pti, count);
3251 EndPath(graphics->hdc);
3253 brush_fill_path(graphics, brush);
3255 RestoreDC(graphics->hdc, save_state);
3264 GpStatus WINGDIPAPI GdipFillPolygon2(GpGraphics *graphics, GpBrush *brush,
3265 GDIPCONST GpPointF *points, INT count)
3267 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3269 return GdipFillPolygon(graphics, brush, points, count, FillModeAlternate);
3272 GpStatus WINGDIPAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush,
3273 GDIPCONST GpPoint *points, INT count)
3275 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3277 return GdipFillPolygonI(graphics, brush, points, count, FillModeAlternate);
3280 GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics *graphics, GpBrush *brush,
3281 REAL x, REAL y, REAL width, REAL height)
3287 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
3289 if(!graphics || !brush)
3290 return InvalidParameter;
3297 FIXME("graphics object has no HDC\n");
3303 ptf[1].X = x + width;
3305 ptf[2].X = x + width;
3306 ptf[2].Y = y + height;
3308 ptf[3].Y = y + height;
3310 save_state = SaveDC(graphics->hdc);
3311 EndPath(graphics->hdc);
3313 transform_and_round_points(graphics, pti, ptf, 4);
3315 BeginPath(graphics->hdc);
3316 Polygon(graphics->hdc, pti, 4);
3317 EndPath(graphics->hdc);
3319 brush_fill_path(graphics, brush);
3321 RestoreDC(graphics->hdc, save_state);
3326 GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush,
3327 INT x, INT y, INT width, INT height)
3333 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
3335 if(!graphics || !brush)
3336 return InvalidParameter;
3343 FIXME("graphics object has no HDC\n");
3349 ptf[1].X = x + width;
3351 ptf[2].X = x + width;
3352 ptf[2].Y = y + height;
3354 ptf[3].Y = y + height;
3356 save_state = SaveDC(graphics->hdc);
3357 EndPath(graphics->hdc);
3359 transform_and_round_points(graphics, pti, ptf, 4);
3361 BeginPath(graphics->hdc);
3362 Polygon(graphics->hdc, pti, 4);
3363 EndPath(graphics->hdc);
3365 brush_fill_path(graphics, brush);
3367 RestoreDC(graphics->hdc, save_state);
3372 GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRectF *rects,
3378 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3381 return InvalidParameter;
3383 for(i = 0; i < count; i++){
3384 ret = GdipFillRectangle(graphics, brush, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
3385 if(ret != Ok) return ret;
3391 GpStatus WINGDIPAPI GdipFillRectanglesI(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRect *rects,
3398 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3400 if(!rects || count <= 0)
3401 return InvalidParameter;
3403 rectsF = GdipAlloc(sizeof(GpRectF)*count);
3407 for(i = 0; i < count; i++){
3408 rectsF[i].X = (REAL)rects[i].X;
3409 rectsF[i].Y = (REAL)rects[i].Y;
3410 rectsF[i].X = (REAL)rects[i].Width;
3411 rectsF[i].Height = (REAL)rects[i].Height;
3414 ret = GdipFillRectangles(graphics,brush,rectsF,count);
3420 static GpStatus GDI32_GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
3429 return NotImplemented;
3431 status = GdipGetRegionHRgn(region, graphics, &hrgn);
3435 save_state = SaveDC(graphics->hdc);
3436 EndPath(graphics->hdc);
3438 ExtSelectClipRgn(graphics->hdc, hrgn, RGN_AND);
3440 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
3442 BeginPath(graphics->hdc);
3443 Rectangle(graphics->hdc, rc.left, rc.top, rc.right, rc.bottom);
3444 EndPath(graphics->hdc);
3446 brush_fill_path(graphics, brush);
3449 RestoreDC(graphics->hdc, save_state);
3456 static GpStatus SOFTWARE_GdipFillRegion(GpGraphics *graphics, GpBrush *brush,
3460 GpRegion *temp_region;
3461 GpMatrix *world_to_device, *identity;
3462 GpRectF graphics_bounds;
3463 UINT scans_count, i;
3468 if (!brush_can_fill_pixels(brush))
3469 return NotImplemented;
3471 stat = get_graphics_bounds(graphics, &graphics_bounds);
3474 stat = GdipCloneRegion(region, &temp_region);
3478 stat = get_graphics_transform(graphics, CoordinateSpaceDevice,
3479 CoordinateSpaceWorld, &world_to_device);
3483 stat = GdipTransformRegion(temp_region, world_to_device);
3485 GdipDeleteMatrix(world_to_device);
3489 stat = GdipCombineRegionRect(temp_region, &graphics_bounds, CombineModeIntersect);
3492 stat = GdipCreateMatrix(&identity);
3496 stat = GdipGetRegionScansCount(temp_region, &scans_count, identity);
3498 if (stat == Ok && scans_count != 0)
3500 scans = GdipAlloc(sizeof(*scans) * scans_count);
3506 stat = GdipGetRegionScansI(temp_region, scans, &dummy, identity);
3513 GdipDeleteMatrix(identity);
3516 GdipDeleteRegion(temp_region);
3519 if (stat == Ok && scans_count == 0)
3526 for (i=0; i<scans_count; i++)
3528 UINT size = scans[i].Width * scans[i].Height;
3530 if (size > max_size)
3534 pixel_data = GdipAlloc(sizeof(*pixel_data) * max_size);
3540 for (i=0; i<scans_count; i++)
3542 stat = brush_fill_pixels(graphics, brush, pixel_data, &scans[i],
3547 stat = alpha_blend_pixels(graphics, scans[i].X, scans[i].Y,
3548 (BYTE*)pixel_data, scans[i].Width, scans[i].Height,
3549 scans[i].Width * 4);
3556 GdipFree(pixel_data);
3565 /*****************************************************************************
3566 * GdipFillRegion [GDIPLUS.@]
3568 GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
3571 GpStatus stat = NotImplemented;
3573 TRACE("(%p, %p, %p)\n", graphics, brush, region);
3575 if (!(graphics && brush && region))
3576 return InvalidParameter;
3581 if (!graphics->image)
3582 stat = GDI32_GdipFillRegion(graphics, brush, region);
3584 if (stat == NotImplemented)
3585 stat = SOFTWARE_GdipFillRegion(graphics, brush, region);
3587 if (stat == NotImplemented && graphics->image)
3588 stat = GDI32_GdipFillRegion(graphics, brush, region);
3590 if (stat == NotImplemented)
3592 FIXME("not implemented for brushtype %i\n", brush->bt);
3599 GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention)
3601 TRACE("(%p,%u)\n", graphics, intention);
3604 return InvalidParameter;
3609 /* We have no internal operation queue, so there's no need to clear it. */
3617 /*****************************************************************************
3618 * GdipGetClipBounds [GDIPLUS.@]
3620 GpStatus WINGDIPAPI GdipGetClipBounds(GpGraphics *graphics, GpRectF *rect)
3622 TRACE("(%p, %p)\n", graphics, rect);
3625 return InvalidParameter;
3630 return GdipGetRegionBounds(graphics->clip, graphics, rect);
3633 /*****************************************************************************
3634 * GdipGetClipBoundsI [GDIPLUS.@]
3636 GpStatus WINGDIPAPI GdipGetClipBoundsI(GpGraphics *graphics, GpRect *rect)
3638 TRACE("(%p, %p)\n", graphics, rect);
3641 return InvalidParameter;
3646 return GdipGetRegionBoundsI(graphics->clip, graphics, rect);
3649 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3650 GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics,
3651 CompositingMode *mode)
3653 TRACE("(%p, %p)\n", graphics, mode);
3655 if(!graphics || !mode)
3656 return InvalidParameter;
3661 *mode = graphics->compmode;
3666 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3667 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
3668 CompositingQuality *quality)
3670 TRACE("(%p, %p)\n", graphics, quality);
3672 if(!graphics || !quality)
3673 return InvalidParameter;
3678 *quality = graphics->compqual;
3683 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3684 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
3685 InterpolationMode *mode)
3687 TRACE("(%p, %p)\n", graphics, mode);
3689 if(!graphics || !mode)
3690 return InvalidParameter;
3695 *mode = graphics->interpolation;
3700 /* FIXME: Need to handle color depths less than 24bpp */
3701 GpStatus WINGDIPAPI GdipGetNearestColor(GpGraphics *graphics, ARGB* argb)
3703 FIXME("(%p, %p): Passing color unmodified\n", graphics, argb);
3705 if(!graphics || !argb)
3706 return InvalidParameter;
3714 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
3716 TRACE("(%p, %p)\n", graphics, scale);
3718 if(!graphics || !scale)
3719 return InvalidParameter;
3724 *scale = graphics->scale;
3729 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
3731 TRACE("(%p, %p)\n", graphics, unit);
3733 if(!graphics || !unit)
3734 return InvalidParameter;
3739 *unit = graphics->unit;
3744 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3745 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
3748 TRACE("(%p, %p)\n", graphics, mode);
3750 if(!graphics || !mode)
3751 return InvalidParameter;
3756 *mode = graphics->pixeloffset;
3761 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3762 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
3764 TRACE("(%p, %p)\n", graphics, mode);
3766 if(!graphics || !mode)
3767 return InvalidParameter;
3772 *mode = graphics->smoothing;
3777 GpStatus WINGDIPAPI GdipGetTextContrast(GpGraphics *graphics, UINT *contrast)
3779 TRACE("(%p, %p)\n", graphics, contrast);
3781 if(!graphics || !contrast)
3782 return InvalidParameter;
3784 *contrast = graphics->textcontrast;
3789 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3790 GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics,
3791 TextRenderingHint *hint)
3793 TRACE("(%p, %p)\n", graphics, hint);
3795 if(!graphics || !hint)
3796 return InvalidParameter;
3801 *hint = graphics->texthint;
3806 GpStatus WINGDIPAPI GdipGetVisibleClipBounds(GpGraphics *graphics, GpRectF *rect)
3811 TRACE("(%p, %p)\n", graphics, rect);
3813 if(!graphics || !rect)
3814 return InvalidParameter;
3819 /* intersect window and graphics clipping regions */
3820 if((stat = GdipCreateRegion(&clip_rgn)) != Ok)
3823 if((stat = get_visible_clip_region(graphics, clip_rgn)) != Ok)
3826 /* get bounds of the region */
3827 stat = GdipGetRegionBounds(clip_rgn, graphics, rect);
3830 GdipDeleteRegion(clip_rgn);
3835 GpStatus WINGDIPAPI GdipGetVisibleClipBoundsI(GpGraphics *graphics, GpRect *rect)
3840 TRACE("(%p, %p)\n", graphics, rect);
3842 if(!graphics || !rect)
3843 return InvalidParameter;
3845 if((stat = GdipGetVisibleClipBounds(graphics, &rectf)) == Ok)
3847 rect->X = roundr(rectf.X);
3848 rect->Y = roundr(rectf.Y);
3849 rect->Width = roundr(rectf.Width);
3850 rect->Height = roundr(rectf.Height);
3856 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
3858 TRACE("(%p, %p)\n", graphics, matrix);
3860 if(!graphics || !matrix)
3861 return InvalidParameter;
3866 *matrix = *graphics->worldtrans;
3870 GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color)
3876 TRACE("(%p, %x)\n", graphics, color);
3879 return InvalidParameter;
3884 if((stat = GdipCreateSolidFill(color, &brush)) != Ok)
3887 if((stat = get_graphics_bounds(graphics, &wnd_rect)) != Ok){
3888 GdipDeleteBrush((GpBrush*)brush);
3892 GdipFillRectangle(graphics, (GpBrush*)brush, wnd_rect.X, wnd_rect.Y,
3893 wnd_rect.Width, wnd_rect.Height);
3895 GdipDeleteBrush((GpBrush*)brush);
3900 GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics *graphics, BOOL *res)
3902 TRACE("(%p, %p)\n", graphics, res);
3904 if(!graphics || !res)
3905 return InvalidParameter;
3907 return GdipIsEmptyRegion(graphics->clip, graphics, res);
3910 GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics *graphics, REAL x, REAL y, BOOL *result)
3916 TRACE("(%p, %.2f, %.2f, %p)\n", graphics, x, y, result);
3918 if(!graphics || !result)
3919 return InvalidParameter;
3926 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3927 CoordinateSpaceWorld, &pt, 1)) != Ok)
3930 if((stat = GdipCreateRegion(&rgn)) != Ok)
3933 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3936 stat = GdipIsVisibleRegionPoint(rgn, pt.X, pt.Y, graphics, result);
3939 GdipDeleteRegion(rgn);
3943 GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics *graphics, INT x, INT y, BOOL *result)
3945 return GdipIsVisiblePoint(graphics, (REAL)x, (REAL)y, result);
3948 GpStatus WINGDIPAPI GdipIsVisibleRect(GpGraphics *graphics, REAL x, REAL y, REAL width, REAL height, BOOL *result)
3954 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics, x, y, width, height, result);
3956 if(!graphics || !result)
3957 return InvalidParameter;
3964 pts[1].X = x + width;
3965 pts[1].Y = y + height;
3967 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3968 CoordinateSpaceWorld, pts, 2)) != Ok)
3971 pts[1].X -= pts[0].X;
3972 pts[1].Y -= pts[0].Y;
3974 if((stat = GdipCreateRegion(&rgn)) != Ok)
3977 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3980 stat = GdipIsVisibleRegionRect(rgn, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y, graphics, result);
3983 GdipDeleteRegion(rgn);
3987 GpStatus WINGDIPAPI GdipIsVisibleRectI(GpGraphics *graphics, INT x, INT y, INT width, INT height, BOOL *result)
3989 return GdipIsVisibleRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, result);
3992 GpStatus gdip_format_string(HDC hdc,
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(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(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(hdc, 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(HDC hdc,
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(hdc, string + index, range_start - index,
4144 INT_MAX, NULL, NULL, &range_size);
4145 range_rect.X = bounds->X + range_size.cx;
4147 GetTextExtentExPointW(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;
4169 HDC hdc, temp_hdc=NULL;
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 hdc = temp_hdc = CreateCompatibleDC(0);
4183 if (!temp_hdc) return OutOfMemory;
4186 hdc = graphics->hdc;
4188 if (stringFormat->attr)
4189 TRACE("may be ignoring some format flags: attr %x\n", stringFormat->attr);
4191 oldfont = SelectObject(hdc, CreateFontIndirectW(&font->lfw));
4193 for (i=0; i<stringFormat->range_count; i++)
4195 stat = GdipSetEmpty(regions[i]);
4200 args.regions = regions;
4202 stat = gdip_format_string(hdc, string, length, font, layoutRect, stringFormat,
4203 measure_ranges_callback, &args);
4205 DeleteObject(SelectObject(hdc, oldfont));
4213 struct measure_string_args {
4215 INT *codepointsfitted;
4219 static GpStatus measure_string_callback(HDC hdc,
4220 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4221 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4222 INT lineno, const RectF *bounds, void *user_data)
4224 struct measure_string_args *args = user_data;
4226 if (bounds->Width > args->bounds->Width)
4227 args->bounds->Width = bounds->Width;
4229 if (bounds->Height + bounds->Y > args->bounds->Height + args->bounds->Y)
4230 args->bounds->Height = bounds->Height + bounds->Y - args->bounds->Y;
4232 if (args->codepointsfitted)
4233 *args->codepointsfitted = index + length;
4235 if (args->linesfilled)
4236 (*args->linesfilled)++;
4241 /* Find the smallest rectangle that bounds the text when it is printed in rect
4242 * according to the format options listed in format. If rect has 0 width and
4243 * height, then just find the smallest rectangle that bounds the text when it's
4244 * printed at location (rect->X, rect-Y). */
4245 GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
4246 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
4247 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
4248 INT *codepointsfitted, INT *linesfilled)
4251 struct measure_string_args args;
4254 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics,
4255 debugstr_wn(string, length), length, font, debugstr_rectf(rect), format,
4256 bounds, codepointsfitted, linesfilled);
4258 if(!graphics || !string || !font || !rect || !bounds)
4259 return InvalidParameter;
4263 temp_hdc = CreateCompatibleDC(0);
4264 if (!temp_hdc) return OutOfMemory;
4267 if(linesfilled) *linesfilled = 0;
4268 if(codepointsfitted) *codepointsfitted = 0;
4271 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4273 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
4275 bounds->X = rect->X;
4276 bounds->Y = rect->Y;
4277 bounds->Width = 0.0;
4278 bounds->Height = 0.0;
4280 args.bounds = bounds;
4281 args.codepointsfitted = codepointsfitted;
4282 args.linesfilled = linesfilled;
4284 gdip_format_string(graphics->hdc ? graphics->hdc : temp_hdc, string, length, font, rect, format,
4285 measure_string_callback, &args);
4287 DeleteObject(SelectObject(graphics->hdc, oldfont));
4295 struct draw_string_args {
4298 REAL ang_cos, ang_sin;
4301 static GpStatus draw_string_callback(HDC hdc,
4302 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4303 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4304 INT lineno, const RectF *bounds, void *user_data)
4306 struct draw_string_args *args = user_data;
4309 drawcoord.left = drawcoord.right = args->drawbase.x + roundr(args->ang_sin * bounds->Y);
4310 drawcoord.top = drawcoord.bottom = args->drawbase.y + roundr(args->ang_cos * bounds->Y);
4312 DrawTextW(hdc, string + index, length, &drawcoord, args->drawflags);
4317 GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string,
4318 INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect,
4319 GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush)
4324 TEXTMETRICW textmet;
4325 GpPointF pt[3], rectcpy[4];
4327 REAL angle, rel_width, rel_height;
4328 INT offsety = 0, save_state;
4329 struct draw_string_args args;
4332 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length),
4333 length, font, debugstr_rectf(rect), format, brush);
4335 if(!graphics || !string || !font || !brush || !rect)
4336 return InvalidParameter;
4338 if((brush->bt != BrushTypeSolidColor)){
4339 FIXME("not implemented for given parameters\n");
4340 return NotImplemented;
4345 FIXME("graphics object has no HDC\n");
4350 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4352 /* Should be no need to explicitly test for StringAlignmentNear as
4353 * that is default behavior if no alignment is passed. */
4354 if(format->vertalign != StringAlignmentNear){
4356 GdipMeasureString(graphics, string, length, font, rect, format, &bounds, 0, 0);
4358 if(format->vertalign == StringAlignmentCenter)
4359 offsety = (rect->Height - bounds.Height) / 2;
4360 else if(format->vertalign == StringAlignmentFar)
4361 offsety = (rect->Height - bounds.Height);
4365 save_state = SaveDC(graphics->hdc);
4366 SetBkMode(graphics->hdc, TRANSPARENT);
4367 SetTextColor(graphics->hdc, brush->lb.lbColor);
4375 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
4376 angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X));
4377 args.ang_cos = cos(angle);
4378 args.ang_sin = sin(angle);
4379 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
4380 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
4381 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
4382 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
4384 rectcpy[3].X = rectcpy[0].X = rect->X;
4385 rectcpy[1].Y = rectcpy[0].Y = rect->Y + offsety;
4386 rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width;
4387 rectcpy[3].Y = rectcpy[2].Y = rect->Y + offsety + rect->Height;
4388 transform_and_round_points(graphics, corners, rectcpy, 4);
4390 scaled_rect.X = 0.0;
4391 scaled_rect.Y = 0.0;
4392 scaled_rect.Width = rel_width * rect->Width;
4393 scaled_rect.Height = rel_height * rect->Height;
4395 if (roundr(scaled_rect.Width) != 0 && roundr(scaled_rect.Height) != 0)
4397 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4398 rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
4399 SelectClipRgn(graphics->hdc, rgn);
4402 /* Use gdi to find the font, then perform transformations on it (height,
4404 SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
4405 GetTextMetricsW(graphics->hdc, &textmet);
4408 lfw.lfHeight = roundr(((REAL)lfw.lfHeight) * rel_height);
4409 lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width);
4411 lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0);
4413 gdifont = CreateFontIndirectW(&lfw);
4414 DeleteObject(SelectObject(graphics->hdc, CreateFontIndirectW(&lfw)));
4416 if (!format || format->align == StringAlignmentNear)
4418 args.drawbase.x = corners[0].x;
4419 args.drawbase.y = corners[0].y;
4420 args.drawflags = DT_NOCLIP | DT_EXPANDTABS;
4422 else if (format->align == StringAlignmentCenter)
4424 args.drawbase.x = (corners[0].x + corners[1].x)/2;
4425 args.drawbase.y = (corners[0].y + corners[1].y)/2;
4426 args.drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_CENTER;
4428 else /* (format->align == StringAlignmentFar) */
4430 args.drawbase.x = corners[1].x;
4431 args.drawbase.y = corners[1].y;
4432 args.drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_RIGHT;
4435 gdip_format_string(graphics->hdc, string, length, font, &scaled_rect, format,
4436 draw_string_callback, &args);
4439 DeleteObject(gdifont);
4441 RestoreDC(graphics->hdc, save_state);
4446 GpStatus WINGDIPAPI GdipResetClip(GpGraphics *graphics)
4448 TRACE("(%p)\n", graphics);
4451 return InvalidParameter;
4456 return GdipSetInfinite(graphics->clip);
4459 GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics)
4461 TRACE("(%p)\n", graphics);
4464 return InvalidParameter;
4469 graphics->worldtrans->matrix[0] = 1.0;
4470 graphics->worldtrans->matrix[1] = 0.0;
4471 graphics->worldtrans->matrix[2] = 0.0;
4472 graphics->worldtrans->matrix[3] = 1.0;
4473 graphics->worldtrans->matrix[4] = 0.0;
4474 graphics->worldtrans->matrix[5] = 0.0;
4479 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
4481 return GdipEndContainer(graphics, state);
4484 GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
4485 GpMatrixOrder order)
4487 TRACE("(%p, %.2f, %d)\n", graphics, angle, order);
4490 return InvalidParameter;
4495 return GdipRotateMatrix(graphics->worldtrans, angle, order);
4498 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
4500 return GdipBeginContainer2(graphics, state);
4503 GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics *graphics,
4504 GraphicsContainer *state)
4506 GraphicsContainerItem *container;
4509 TRACE("(%p, %p)\n", graphics, state);
4511 if(!graphics || !state)
4512 return InvalidParameter;
4514 sts = init_container(&container, graphics);
4518 list_add_head(&graphics->containers, &container->entry);
4519 *state = graphics->contid = container->contid;
4524 GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics *graphics, GDIPCONST GpRectF *dstrect, GDIPCONST GpRectF *srcrect, GpUnit unit, GraphicsContainer *state)
4526 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
4527 return NotImplemented;
4530 GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics *graphics, GDIPCONST GpRect *dstrect, GDIPCONST GpRect *srcrect, GpUnit unit, GraphicsContainer *state)
4532 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
4533 return NotImplemented;
4536 GpStatus WINGDIPAPI GdipComment(GpGraphics *graphics, UINT sizeData, GDIPCONST BYTE *data)
4538 FIXME("(%p, %d, %p): stub\n", graphics, sizeData, data);
4539 return NotImplemented;
4542 GpStatus WINGDIPAPI GdipEndContainer(GpGraphics *graphics, GraphicsContainer state)
4545 GraphicsContainerItem *container, *container2;
4547 TRACE("(%p, %x)\n", graphics, state);
4550 return InvalidParameter;
4552 LIST_FOR_EACH_ENTRY(container, &graphics->containers, GraphicsContainerItem, entry){
4553 if(container->contid == state)
4557 /* did not find a matching container */
4558 if(&container->entry == &graphics->containers)
4561 sts = restore_container(graphics, container);
4565 /* remove all of the containers on top of the found container */
4566 LIST_FOR_EACH_ENTRY_SAFE(container, container2, &graphics->containers, GraphicsContainerItem, entry){
4567 if(container->contid == state)
4569 list_remove(&container->entry);
4570 delete_container(container);
4573 list_remove(&container->entry);
4574 delete_container(container);
4579 GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
4580 REAL sy, GpMatrixOrder order)
4582 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, sx, sy, order);
4585 return InvalidParameter;
4590 return GdipScaleMatrix(graphics->worldtrans, sx, sy, order);
4593 GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics *graphics, GpGraphics *srcgraphics,
4596 TRACE("(%p, %p, %d)\n", graphics, srcgraphics, mode);
4598 if(!graphics || !srcgraphics)
4599 return InvalidParameter;
4601 return GdipCombineRegionRegion(graphics->clip, srcgraphics->clip, mode);
4604 GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
4605 CompositingMode mode)
4607 TRACE("(%p, %d)\n", graphics, mode);
4610 return InvalidParameter;
4615 graphics->compmode = mode;
4620 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
4621 CompositingQuality quality)
4623 TRACE("(%p, %d)\n", graphics, quality);
4626 return InvalidParameter;
4631 graphics->compqual = quality;
4636 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
4637 InterpolationMode mode)
4639 TRACE("(%p, %d)\n", graphics, mode);
4642 return InvalidParameter;
4647 graphics->interpolation = mode;
4652 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
4654 TRACE("(%p, %.2f)\n", graphics, scale);
4656 if(!graphics || (scale <= 0.0))
4657 return InvalidParameter;
4662 graphics->scale = scale;
4667 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
4669 TRACE("(%p, %d)\n", graphics, unit);
4672 return InvalidParameter;
4677 if(unit == UnitWorld)
4678 return InvalidParameter;
4680 graphics->unit = unit;
4685 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
4688 TRACE("(%p, %d)\n", graphics, mode);
4691 return InvalidParameter;
4696 graphics->pixeloffset = mode;
4701 GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics *graphics, INT x, INT y)
4705 TRACE("(%p,%i,%i)\n", graphics, x, y);
4708 FIXME("not implemented\n");
4710 return NotImplemented;
4713 GpStatus WINGDIPAPI GdipGetRenderingOrigin(GpGraphics *graphics, INT *x, INT *y)
4717 TRACE("(%p,%p,%p)\n", graphics, x, y);
4720 FIXME("not implemented\n");
4724 return NotImplemented;
4727 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
4729 TRACE("(%p, %d)\n", graphics, mode);
4732 return InvalidParameter;
4737 graphics->smoothing = mode;
4742 GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics *graphics, UINT contrast)
4744 TRACE("(%p, %d)\n", graphics, contrast);
4747 return InvalidParameter;
4749 graphics->textcontrast = contrast;
4754 GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
4755 TextRenderingHint hint)
4757 TRACE("(%p, %d)\n", graphics, hint);
4760 return InvalidParameter;
4765 graphics->texthint = hint;
4770 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
4772 TRACE("(%p, %p)\n", graphics, matrix);
4774 if(!graphics || !matrix)
4775 return InvalidParameter;
4780 GdipDeleteMatrix(graphics->worldtrans);
4781 return GdipCloneMatrix(matrix, &graphics->worldtrans);
4784 GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
4785 REAL dy, GpMatrixOrder order)
4787 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, dx, dy, order);
4790 return InvalidParameter;
4795 return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order);
4798 /*****************************************************************************
4799 * GdipSetClipHrgn [GDIPLUS.@]
4801 GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics *graphics, HRGN hrgn, CombineMode mode)
4806 TRACE("(%p, %p, %d)\n", graphics, hrgn, mode);
4809 return InvalidParameter;
4811 status = GdipCreateRegionHrgn(hrgn, ®ion);
4815 status = GdipSetClipRegion(graphics, region, mode);
4817 GdipDeleteRegion(region);
4821 GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics *graphics, GpPath *path, CombineMode mode)
4823 TRACE("(%p, %p, %d)\n", graphics, path, mode);
4826 return InvalidParameter;
4831 return GdipCombineRegionPath(graphics->clip, path, mode);
4834 GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y,
4835 REAL width, REAL height,
4840 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics, x, y, width, height, mode);
4843 return InvalidParameter;
4851 rect.Height = height;
4853 return GdipCombineRegionRect(graphics->clip, &rect, mode);
4856 GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y,
4857 INT width, INT height,
4860 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics, x, y, width, height, mode);
4863 return InvalidParameter;
4868 return GdipSetClipRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, mode);
4871 GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
4874 TRACE("(%p, %p, %d)\n", graphics, region, mode);
4876 if(!graphics || !region)
4877 return InvalidParameter;
4882 return GdipCombineRegionRegion(graphics->clip, region, mode);
4885 GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile *metafile,
4890 TRACE("(%p,%u)\n", metafile, limitDpi);
4893 FIXME("not implemented\n");
4895 return NotImplemented;
4898 GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points,
4904 TRACE("(%p, %p, %d)\n", graphics, points, count);
4906 if(!graphics || !pen || count<=0)
4907 return InvalidParameter;
4914 FIXME("graphics object has no HDC\n");
4918 pti = GdipAlloc(sizeof(POINT) * count);
4920 save_state = prepare_dc(graphics, pen);
4921 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
4923 transform_and_round_points(graphics, pti, (GpPointF*)points, count);
4924 Polygon(graphics->hdc, pti, count);
4926 restore_dc(graphics, save_state);
4932 GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points,
4939 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
4941 if(count<=0) return InvalidParameter;
4942 ptf = GdipAlloc(sizeof(GpPointF) * count);
4944 for(i = 0;i < count; i++){
4945 ptf[i].X = (REAL)points[i].X;
4946 ptf[i].Y = (REAL)points[i].Y;
4949 ret = GdipDrawPolygon(graphics,pen,ptf,count);
4955 GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
4957 TRACE("(%p, %p)\n", graphics, dpi);
4959 if(!graphics || !dpi)
4960 return InvalidParameter;
4965 if (graphics->image)
4966 *dpi = graphics->image->xres;
4968 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
4973 GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
4975 TRACE("(%p, %p)\n", graphics, dpi);
4977 if(!graphics || !dpi)
4978 return InvalidParameter;
4983 if (graphics->image)
4984 *dpi = graphics->image->yres;
4986 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
4991 GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix,
4992 GpMatrixOrder order)
4997 TRACE("(%p, %p, %d)\n", graphics, matrix, order);
4999 if(!graphics || !matrix)
5000 return InvalidParameter;
5005 m = *(graphics->worldtrans);
5007 ret = GdipMultiplyMatrix(&m, matrix, order);
5009 *(graphics->worldtrans) = m;
5014 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5015 static const COLORREF DC_BACKGROUND_KEY = 0x0c0b0d;
5017 GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
5019 TRACE("(%p, %p)\n", graphics, hdc);
5021 if(!graphics || !hdc)
5022 return InvalidParameter;
5027 if (!graphics->hdc ||
5028 (graphics->image && graphics->image->type == ImageTypeBitmap && ((GpBitmap*)graphics->image)->format & PixelFormatAlpha))
5030 /* Create a fake HDC and fill it with a constant color. */
5035 BITMAPINFOHEADER bmih;
5038 stat = get_graphics_bounds(graphics, &bounds);
5042 graphics->temp_hbitmap_width = bounds.Width;
5043 graphics->temp_hbitmap_height = bounds.Height;
5045 bmih.biSize = sizeof(bmih);
5046 bmih.biWidth = graphics->temp_hbitmap_width;
5047 bmih.biHeight = -graphics->temp_hbitmap_height;
5049 bmih.biBitCount = 32;
5050 bmih.biCompression = BI_RGB;
5051 bmih.biSizeImage = 0;
5052 bmih.biXPelsPerMeter = 0;
5053 bmih.biYPelsPerMeter = 0;
5055 bmih.biClrImportant = 0;
5057 hbitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
5058 (void**)&graphics->temp_bits, NULL, 0);
5060 return GenericError;
5062 temp_hdc = CreateCompatibleDC(0);
5065 DeleteObject(hbitmap);
5066 return GenericError;
5069 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
5070 ((DWORD*)graphics->temp_bits)[i] = DC_BACKGROUND_KEY;
5072 SelectObject(temp_hdc, hbitmap);
5074 graphics->temp_hbitmap = hbitmap;
5075 *hdc = graphics->temp_hdc = temp_hdc;
5079 *hdc = graphics->hdc;
5082 graphics->busy = TRUE;
5087 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
5089 TRACE("(%p, %p)\n", graphics, hdc);
5091 if(!graphics || !hdc)
5092 return InvalidParameter;
5094 if((graphics->hdc != hdc && graphics->temp_hdc != hdc) || !(graphics->busy))
5095 return InvalidParameter;
5097 if (graphics->temp_hdc == hdc)
5102 /* Find the pixels that have changed, and mark them as opaque. */
5103 pos = (DWORD*)graphics->temp_bits;
5104 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
5106 if (*pos != DC_BACKGROUND_KEY)
5113 /* Write the changed pixels to the real target. */
5114 alpha_blend_pixels(graphics, 0, 0, graphics->temp_bits,
5115 graphics->temp_hbitmap_width, graphics->temp_hbitmap_height,
5116 graphics->temp_hbitmap_width * 4);
5119 DeleteDC(graphics->temp_hdc);
5120 DeleteObject(graphics->temp_hbitmap);
5121 graphics->temp_hdc = NULL;
5122 graphics->temp_hbitmap = NULL;
5125 graphics->busy = FALSE;
5130 GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
5135 TRACE("(%p, %p)\n", graphics, region);
5137 if(!graphics || !region)
5138 return InvalidParameter;
5143 if((status = GdipCloneRegion(graphics->clip, &clip)) != Ok)
5146 /* free everything except root node and header */
5147 delete_element(®ion->node);
5148 memcpy(region, clip, sizeof(GpRegion));
5154 static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace dst_space,
5155 GpCoordinateSpace src_space, GpMatrix **matrix)
5157 GpStatus stat = GdipCreateMatrix(matrix);
5160 if (dst_space != src_space && stat == Ok)
5162 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
5164 if(graphics->unit != UnitDisplay)
5165 unitscale *= graphics->scale;
5167 /* transform from src_space to CoordinateSpacePage */
5170 case CoordinateSpaceWorld:
5171 GdipMultiplyMatrix(*matrix, graphics->worldtrans, MatrixOrderAppend);
5173 case CoordinateSpacePage:
5175 case CoordinateSpaceDevice:
5176 GdipScaleMatrix(*matrix, 1.0/unitscale, 1.0/unitscale, MatrixOrderAppend);
5180 /* transform from CoordinateSpacePage to dst_space */
5183 case CoordinateSpaceWorld:
5185 GpMatrix *inverted_transform;
5186 stat = GdipCloneMatrix(graphics->worldtrans, &inverted_transform);
5189 stat = GdipInvertMatrix(inverted_transform);
5191 GdipMultiplyMatrix(*matrix, inverted_transform, MatrixOrderAppend);
5192 GdipDeleteMatrix(inverted_transform);
5196 case CoordinateSpacePage:
5198 case CoordinateSpaceDevice:
5199 GdipScaleMatrix(*matrix, unitscale, unitscale, MatrixOrderAppend);
5206 GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space,
5207 GpCoordinateSpace src_space, GpPointF *points, INT count)
5212 if(!graphics || !points || count <= 0)
5213 return InvalidParameter;
5218 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
5220 if (src_space == dst_space) return Ok;
5222 stat = get_graphics_transform(graphics, dst_space, src_space, &matrix);
5226 stat = GdipTransformMatrixPoints(matrix, points, count);
5228 GdipDeleteMatrix(matrix);
5234 GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space,
5235 GpCoordinateSpace src_space, GpPoint *points, INT count)
5241 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
5244 return InvalidParameter;
5246 pointsF = GdipAlloc(sizeof(GpPointF) * count);
5250 for(i = 0; i < count; i++){
5251 pointsF[i].X = (REAL)points[i].X;
5252 pointsF[i].Y = (REAL)points[i].Y;
5255 ret = GdipTransformPoints(graphics, dst_space, src_space, pointsF, count);
5258 for(i = 0; i < count; i++){
5259 points[i].X = roundr(pointsF[i].X);
5260 points[i].Y = roundr(pointsF[i].Y);
5267 HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void)
5279 /*****************************************************************************
5280 * GdipTranslateClip [GDIPLUS.@]
5282 GpStatus WINGDIPAPI GdipTranslateClip(GpGraphics *graphics, REAL dx, REAL dy)
5284 TRACE("(%p, %.2f, %.2f)\n", graphics, dx, dy);
5287 return InvalidParameter;
5292 return GdipTranslateRegion(graphics->clip, dx, dy);
5295 /*****************************************************************************
5296 * GdipTranslateClipI [GDIPLUS.@]
5298 GpStatus WINGDIPAPI GdipTranslateClipI(GpGraphics *graphics, INT dx, INT dy)
5300 TRACE("(%p, %d, %d)\n", graphics, dx, dy);
5303 return InvalidParameter;
5308 return GdipTranslateRegion(graphics->clip, (REAL)dx, (REAL)dy);
5312 /*****************************************************************************
5313 * GdipMeasureDriverString [GDIPLUS.@]
5315 GpStatus WINGDIPAPI GdipMeasureDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5316 GDIPCONST GpFont *font, GDIPCONST PointF *positions,
5317 INT flags, GDIPCONST GpMatrix *matrix, RectF *boundingBox)
5319 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics, text, length, font, positions, flags, matrix, boundingBox);
5320 return NotImplemented;
5323 /*****************************************************************************
5324 * GdipDrawDriverString [GDIPLUS.@]
5326 GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5327 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
5328 GDIPCONST PointF *positions, INT flags,
5329 GDIPCONST GpMatrix *matrix )
5331 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics, text, length, font, brush, positions, flags, matrix);
5332 return NotImplemented;
5335 GpStatus WINGDIPAPI GdipRecordMetafile(HDC hdc, EmfType type, GDIPCONST GpRectF *frameRect,
5336 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
5338 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
5339 return NotImplemented;
5342 /*****************************************************************************
5343 * GdipRecordMetafileI [GDIPLUS.@]
5345 GpStatus WINGDIPAPI GdipRecordMetafileI(HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
5346 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
5348 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
5349 return NotImplemented;
5352 GpStatus WINGDIPAPI GdipRecordMetafileStream(IStream *stream, HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
5353 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
5355 FIXME("(%p %p %d %p %d %p %p): stub\n", stream, hdc, type, frameRect, frameUnit, desc, metafile);
5356 return NotImplemented;
5359 /*****************************************************************************
5360 * GdipIsVisibleClipEmpty [GDIPLUS.@]
5362 GpStatus WINGDIPAPI GdipIsVisibleClipEmpty(GpGraphics *graphics, BOOL *res)
5367 TRACE("(%p, %p)\n", graphics, res);
5369 if((stat = GdipCreateRegion(&rgn)) != Ok)
5372 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
5375 stat = GdipIsEmptyRegion(rgn, graphics, res);
5378 GdipDeleteRegion(rgn);
5382 GpStatus WINGDIPAPI GdipGetHemfFromMetafile(GpMetafile *metafile, HENHMETAFILE *hEmf)
5384 FIXME("(%p,%p): stub\n", metafile, hEmf);
5386 if (!metafile || !hEmf)
5387 return InvalidParameter;
5391 return NotImplemented;