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 COLORREF get_gdi_brush_color(const GpBrush *brush)
99 case BrushTypeSolidColor:
101 const GpSolidFill *sf = (const GpSolidFill *)brush;
105 case BrushTypeHatchFill:
107 const GpHatch *hatch = (const GpHatch *)brush;
108 argb = hatch->forecol;
111 case BrushTypeLinearGradient:
113 const GpLineGradient *line = (const GpLineGradient *)brush;
114 argb = line->startcolor;
117 case BrushTypePathGradient:
119 const GpPathGradient *grad = (const GpPathGradient *)brush;
120 argb = grad->centercolor;
124 FIXME("unhandled brush type %d\n", brush->bt);
128 return ARGB2COLORREF(argb);
131 static HBITMAP create_hatch_bitmap(const GpHatch *hatch)
135 BITMAPINFOHEADER bmih;
139 hdc = CreateCompatibleDC(0);
143 bmih.biSize = sizeof(bmih);
147 bmih.biBitCount = 32;
148 bmih.biCompression = BI_RGB;
149 bmih.biSizeImage = 0;
151 hbmp = CreateDIBSection(hdc, (BITMAPINFO *)&bmih, DIB_RGB_COLORS, (void **)&bits, NULL, 0);
154 const char *hatch_data;
156 if (get_hatch_data(hatch->hatchstyle, &hatch_data) == Ok)
158 for (y = 0; y < 8; y++)
160 for (x = 0; x < 8; x++)
162 if (hatch_data[y] & (0x80 >> x))
163 bits[y * 8 + x] = hatch->forecol;
165 bits[y * 8 + x] = hatch->backcol;
171 FIXME("Unimplemented hatch style %d\n", hatch->hatchstyle);
173 for (y = 0; y < 64; y++)
174 bits[y] = hatch->forecol;
182 static GpStatus create_gdi_logbrush(const GpBrush *brush, LOGBRUSH *lb)
186 case BrushTypeSolidColor:
188 const GpSolidFill *sf = (const GpSolidFill *)brush;
189 lb->lbStyle = BS_SOLID;
190 lb->lbColor = ARGB2COLORREF(sf->color);
195 case BrushTypeHatchFill:
197 const GpHatch *hatch = (const GpHatch *)brush;
200 hbmp = create_hatch_bitmap(hatch);
201 if (!hbmp) return OutOfMemory;
203 lb->lbStyle = BS_PATTERN;
205 lb->lbHatch = (ULONG_PTR)hbmp;
210 FIXME("unhandled brush type %d\n", brush->bt);
211 lb->lbStyle = BS_SOLID;
212 lb->lbColor = get_gdi_brush_color(brush);
218 static GpStatus free_gdi_logbrush(LOGBRUSH *lb)
223 DeleteObject((HGDIOBJ)(ULONG_PTR)lb->lbHatch);
229 static HBRUSH create_gdi_brush(const GpBrush *brush)
234 if (create_gdi_logbrush(brush, &lb) != Ok) return 0;
236 gdibrush = CreateBrushIndirect(&lb);
237 free_gdi_logbrush(&lb);
242 static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
247 INT save_state, i, numdashes;
249 DWORD dash_array[MAX_DASHLEN];
251 save_state = SaveDC(graphics->hdc);
253 EndPath(graphics->hdc);
255 if(pen->unit == UnitPixel){
259 /* Get an estimate for the amount the pen width is affected by the world
260 * transform. (This is similar to what some of the wine drivers do.) */
265 GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
266 width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
267 (pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
269 width *= pen->width * convert_unit(graphics_res(graphics),
270 pen->unit == UnitWorld ? graphics->unit : pen->unit);
273 if(pen->dash == DashStyleCustom){
274 numdashes = min(pen->numdashes, MAX_DASHLEN);
276 TRACE("dashes are: ");
277 for(i = 0; i < numdashes; i++){
278 dash_array[i] = roundr(width * pen->dashes[i]);
279 TRACE("%d, ", dash_array[i]);
281 TRACE("\n and the pen style is %x\n", pen->style);
283 create_gdi_logbrush(pen->brush, &lb);
284 gdipen = ExtCreatePen(pen->style, roundr(width), &lb,
285 numdashes, dash_array);
286 free_gdi_logbrush(&lb);
290 create_gdi_logbrush(pen->brush, &lb);
291 gdipen = ExtCreatePen(pen->style, roundr(width), &lb, 0, NULL);
292 free_gdi_logbrush(&lb);
295 SelectObject(graphics->hdc, gdipen);
300 static void restore_dc(GpGraphics *graphics, INT state)
302 DeleteObject(SelectObject(graphics->hdc, GetStockObject(NULL_PEN)));
303 RestoreDC(graphics->hdc, state);
306 static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace dst_space,
307 GpCoordinateSpace src_space, GpMatrix **matrix);
309 /* This helper applies all the changes that the points listed in ptf need in
310 * order to be drawn on the device context. In the end, this should include at
312 * -scaling by page unit
313 * -applying world transformation
314 * -converting from float to int
315 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
316 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
317 * gdi to draw, and these functions would irreparably mess with line widths.
319 static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
320 GpPointF *ptf, INT count)
326 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
328 /* apply page scale */
329 if(graphics->unit != UnitDisplay)
330 unitscale *= graphics->scale;
332 GdipCloneMatrix(graphics->worldtrans, &matrix);
333 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
334 GdipTransformMatrixPoints(matrix, ptf, count);
335 GdipDeleteMatrix(matrix);
337 for(i = 0; i < count; i++){
338 pti[i].x = roundr(ptf[i].X);
339 pti[i].y = roundr(ptf[i].Y);
343 /* Draw non-premultiplied ARGB data to the given graphics object */
344 static GpStatus alpha_blend_pixels(GpGraphics *graphics, INT dst_x, INT dst_y,
345 const BYTE *src, INT src_width, INT src_height, INT src_stride)
347 if (graphics->image && graphics->image->type == ImageTypeBitmap)
349 GpBitmap *dst_bitmap = (GpBitmap*)graphics->image;
352 for (x=0; x<src_width; x++)
354 for (y=0; y<src_height; y++)
356 ARGB dst_color, src_color;
357 GdipBitmapGetPixel(dst_bitmap, x+dst_x, y+dst_y, &dst_color);
358 src_color = ((ARGB*)(src + src_stride * y))[x];
359 GdipBitmapSetPixel(dst_bitmap, x+dst_x, y+dst_y, color_over(dst_color, src_color));
365 else if (graphics->image && graphics->image->type == ImageTypeMetafile)
367 ERR("This should not be used for metafiles; fix caller\n");
368 return NotImplemented;
373 HBITMAP hbitmap, old_hbm=NULL;
374 BITMAPINFOHEADER bih;
378 hdc = CreateCompatibleDC(0);
380 bih.biSize = sizeof(BITMAPINFOHEADER);
381 bih.biWidth = src_width;
382 bih.biHeight = -src_height;
385 bih.biCompression = BI_RGB;
387 bih.biXPelsPerMeter = 0;
388 bih.biYPelsPerMeter = 0;
390 bih.biClrImportant = 0;
392 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
393 (void**)&temp_bits, NULL, 0);
395 convert_32bppARGB_to_32bppPARGB(src_width, src_height, temp_bits,
396 4 * src_width, src, src_stride);
398 old_hbm = SelectObject(hdc, hbitmap);
400 bf.BlendOp = AC_SRC_OVER;
402 bf.SourceConstantAlpha = 255;
403 bf.AlphaFormat = AC_SRC_ALPHA;
405 GdiAlphaBlend(graphics->hdc, dst_x, dst_y, src_width, src_height,
406 hdc, 0, 0, src_width, src_height, bf);
408 SelectObject(hdc, old_hbm);
410 DeleteObject(hbitmap);
416 static ARGB blend_colors(ARGB start, ARGB end, REAL position)
422 a1 = (start >> 24) & 0xff;
423 a2 = (end >> 24) & 0xff;
425 a3 = (int)(a1*(1.0f - position)+a2*(position));
429 for (i=0xff; i<=0xff0000; i = i << 8)
430 result |= (int)((start&i)*(1.0f - position)+(end&i)*(position))&i;
434 static ARGB blend_line_gradient(GpLineGradient* brush, REAL position)
438 /* clamp to between 0.0 and 1.0, using the wrap mode */
439 if (brush->wrap == WrapModeTile)
441 position = fmodf(position, 1.0f);
442 if (position < 0.0f) position += 1.0f;
444 else /* WrapModeFlip* */
446 position = fmodf(position, 2.0f);
447 if (position < 0.0f) position += 2.0f;
448 if (position > 1.0f) position = 2.0f - position;
451 if (brush->blendcount == 1)
456 REAL left_blendpos, left_blendfac, right_blendpos, right_blendfac;
459 /* locate the blend positions surrounding this position */
460 while (position > brush->blendpos[i])
463 /* interpolate between the blend positions */
464 left_blendpos = brush->blendpos[i-1];
465 left_blendfac = brush->blendfac[i-1];
466 right_blendpos = brush->blendpos[i];
467 right_blendfac = brush->blendfac[i];
468 range = right_blendpos - left_blendpos;
469 blendfac = (left_blendfac * (right_blendpos - position) +
470 right_blendfac * (position - left_blendpos)) / range;
473 if (brush->pblendcount == 0)
474 return blend_colors(brush->startcolor, brush->endcolor, blendfac);
478 ARGB left_blendcolor, right_blendcolor;
479 REAL left_blendpos, right_blendpos;
481 /* locate the blend colors surrounding this position */
482 while (blendfac > brush->pblendpos[i])
485 /* interpolate between the blend colors */
486 left_blendpos = brush->pblendpos[i-1];
487 left_blendcolor = brush->pblendcolor[i-1];
488 right_blendpos = brush->pblendpos[i];
489 right_blendcolor = brush->pblendcolor[i];
490 blendfac = (blendfac - left_blendpos) / (right_blendpos - left_blendpos);
491 return blend_colors(left_blendcolor, right_blendcolor, blendfac);
495 static ARGB transform_color(ARGB color, const ColorMatrix *matrix)
499 unsigned char a, r, g, b;
501 val[0] = ((color >> 16) & 0xff) / 255.0; /* red */
502 val[1] = ((color >> 8) & 0xff) / 255.0; /* green */
503 val[2] = (color & 0xff) / 255.0; /* blue */
504 val[3] = ((color >> 24) & 0xff) / 255.0; /* alpha */
505 val[4] = 1.0; /* translation */
512 res[i] += matrix->m[j][i] * val[j];
515 a = min(max(floorf(res[3]*255.0), 0.0), 255.0);
516 r = min(max(floorf(res[0]*255.0), 0.0), 255.0);
517 g = min(max(floorf(res[1]*255.0), 0.0), 255.0);
518 b = min(max(floorf(res[2]*255.0), 0.0), 255.0);
520 return (a << 24) | (r << 16) | (g << 8) | b;
523 static int color_is_gray(ARGB color)
525 unsigned char r, g, b;
527 r = (color >> 16) & 0xff;
528 g = (color >> 8) & 0xff;
531 return (r == g) && (g == b);
534 static void apply_image_attributes(const GpImageAttributes *attributes, LPBYTE data,
535 UINT width, UINT height, INT stride, ColorAdjustType type)
539 if (attributes->colorkeys[type].enabled ||
540 attributes->colorkeys[ColorAdjustTypeDefault].enabled)
542 const struct color_key *key;
543 BYTE min_blue, min_green, min_red;
544 BYTE max_blue, max_green, max_red;
546 if (attributes->colorkeys[type].enabled)
547 key = &attributes->colorkeys[type];
549 key = &attributes->colorkeys[ColorAdjustTypeDefault];
551 min_blue = key->low&0xff;
552 min_green = (key->low>>8)&0xff;
553 min_red = (key->low>>16)&0xff;
555 max_blue = key->high&0xff;
556 max_green = (key->high>>8)&0xff;
557 max_red = (key->high>>16)&0xff;
559 for (x=0; x<width; x++)
560 for (y=0; y<height; y++)
563 BYTE blue, green, red;
564 src_color = (ARGB*)(data + stride * y + sizeof(ARGB) * x);
565 blue = *src_color&0xff;
566 green = (*src_color>>8)&0xff;
567 red = (*src_color>>16)&0xff;
568 if (blue >= min_blue && green >= min_green && red >= min_red &&
569 blue <= max_blue && green <= max_green && red <= max_red)
570 *src_color = 0x00000000;
574 if (attributes->colorremaptables[type].enabled ||
575 attributes->colorremaptables[ColorAdjustTypeDefault].enabled)
577 const struct color_remap_table *table;
579 if (attributes->colorremaptables[type].enabled)
580 table = &attributes->colorremaptables[type];
582 table = &attributes->colorremaptables[ColorAdjustTypeDefault];
584 for (x=0; x<width; x++)
585 for (y=0; y<height; y++)
588 src_color = (ARGB*)(data + stride * y + sizeof(ARGB) * x);
589 for (i=0; i<table->mapsize; i++)
591 if (*src_color == table->colormap[i].oldColor.Argb)
593 *src_color = table->colormap[i].newColor.Argb;
600 if (attributes->colormatrices[type].enabled ||
601 attributes->colormatrices[ColorAdjustTypeDefault].enabled)
603 const struct color_matrix *colormatrices;
605 if (attributes->colormatrices[type].enabled)
606 colormatrices = &attributes->colormatrices[type];
608 colormatrices = &attributes->colormatrices[ColorAdjustTypeDefault];
610 for (x=0; x<width; x++)
611 for (y=0; y<height; y++)
614 src_color = (ARGB*)(data + stride * y + sizeof(ARGB) * x);
616 if (colormatrices->flags == ColorMatrixFlagsDefault ||
617 !color_is_gray(*src_color))
619 *src_color = transform_color(*src_color, &colormatrices->colormatrix);
621 else if (colormatrices->flags == ColorMatrixFlagsAltGray)
623 *src_color = transform_color(*src_color, &colormatrices->graymatrix);
628 if (attributes->gamma_enabled[type] ||
629 attributes->gamma_enabled[ColorAdjustTypeDefault])
633 if (attributes->gamma_enabled[type])
634 gamma = attributes->gamma[type];
636 gamma = attributes->gamma[ColorAdjustTypeDefault];
638 for (x=0; x<width; x++)
639 for (y=0; y<height; y++)
642 BYTE blue, green, red;
643 src_color = (ARGB*)(data + stride * y + sizeof(ARGB) * x);
645 blue = *src_color&0xff;
646 green = (*src_color>>8)&0xff;
647 red = (*src_color>>16)&0xff;
649 /* FIXME: We should probably use a table for this. */
650 blue = floorf(powf(blue / 255.0, gamma) * 255.0);
651 green = floorf(powf(green / 255.0, gamma) * 255.0);
652 red = floorf(powf(red / 255.0, gamma) * 255.0);
654 *src_color = (*src_color & 0xff000000) | (red << 16) | (green << 8) | blue;
659 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
660 * bitmap that contains all the pixels we may need to draw it. */
661 static void get_bitmap_sample_size(InterpolationMode interpolation, WrapMode wrap,
662 GpBitmap* bitmap, REAL srcx, REAL srcy, REAL srcwidth, REAL srcheight,
665 INT left, top, right, bottom;
667 switch (interpolation)
669 case InterpolationModeHighQualityBilinear:
670 case InterpolationModeHighQualityBicubic:
671 /* FIXME: Include a greater range for the prefilter? */
672 case InterpolationModeBicubic:
673 case InterpolationModeBilinear:
674 left = (INT)(floorf(srcx));
675 top = (INT)(floorf(srcy));
676 right = (INT)(ceilf(srcx+srcwidth));
677 bottom = (INT)(ceilf(srcy+srcheight));
679 case InterpolationModeNearestNeighbor:
683 right = roundr(srcx+srcwidth);
684 bottom = roundr(srcy+srcheight);
688 if (wrap == WrapModeClamp)
694 if (right >= bitmap->width)
695 right = bitmap->width-1;
696 if (bottom >= bitmap->height)
697 bottom = bitmap->height-1;
701 /* In some cases we can make the rectangle smaller here, but the logic
702 * is hard to get right, and tiling suggests we're likely to use the
703 * entire source image. */
704 if (left < 0 || right >= bitmap->width)
707 right = bitmap->width-1;
710 if (top < 0 || bottom >= bitmap->height)
713 bottom = bitmap->height-1;
719 rect->Width = right - left + 1;
720 rect->Height = bottom - top + 1;
723 static ARGB sample_bitmap_pixel(GDIPCONST GpRect *src_rect, LPBYTE bits, UINT width,
724 UINT height, INT x, INT y, GDIPCONST GpImageAttributes *attributes)
726 if (attributes->wrap == WrapModeClamp)
728 if (x < 0 || y < 0 || x >= width || y >= height)
729 return attributes->outside_color;
733 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
735 x = width*2 + x % (width * 2);
737 y = height*2 + y % (height * 2);
739 if ((attributes->wrap & 1) == 1)
742 if ((x / width) % 2 == 0)
745 x = width - 1 - x % width;
750 if ((attributes->wrap & 2) == 2)
753 if ((y / height) % 2 == 0)
756 y = height - 1 - y % height;
762 if (x < src_rect->X || y < src_rect->Y || x >= src_rect->X + src_rect->Width || y >= src_rect->Y + src_rect->Height)
764 ERR("out of range pixel requested\n");
768 return ((DWORD*)(bits))[(x - src_rect->X) + (y - src_rect->Y) * src_rect->Width];
771 static ARGB resample_bitmap_pixel(GDIPCONST GpRect *src_rect, LPBYTE bits, UINT width,
772 UINT height, GpPointF *point, GDIPCONST GpImageAttributes *attributes,
773 InterpolationMode interpolation)
777 switch (interpolation)
781 FIXME("Unimplemented interpolation %i\n", interpolation);
783 case InterpolationModeBilinear:
786 INT leftx, rightx, topy, bottomy;
787 ARGB topleft, topright, bottomleft, bottomright;
791 leftxf = floorf(point->X);
793 rightx = (INT)ceilf(point->X);
794 topyf = floorf(point->Y);
796 bottomy = (INT)ceilf(point->Y);
798 if (leftx == rightx && topy == bottomy)
799 return sample_bitmap_pixel(src_rect, bits, width, height,
800 leftx, topy, attributes);
802 topleft = sample_bitmap_pixel(src_rect, bits, width, height,
803 leftx, topy, attributes);
804 topright = sample_bitmap_pixel(src_rect, bits, width, height,
805 rightx, topy, attributes);
806 bottomleft = sample_bitmap_pixel(src_rect, bits, width, height,
807 leftx, bottomy, attributes);
808 bottomright = sample_bitmap_pixel(src_rect, bits, width, height,
809 rightx, bottomy, attributes);
811 x_offset = point->X - leftxf;
812 top = blend_colors(topleft, topright, x_offset);
813 bottom = blend_colors(bottomleft, bottomright, x_offset);
815 return blend_colors(top, bottom, point->Y - topyf);
817 case InterpolationModeNearestNeighbor:
818 return sample_bitmap_pixel(src_rect, bits, width, height,
819 roundr(point->X), roundr(point->Y), attributes);
823 static INT brush_can_fill_path(GpBrush *brush)
827 case BrushTypeSolidColor:
829 case BrushTypeHatchFill:
831 GpHatch *hatch = (GpHatch*)brush;
832 return ((hatch->forecol & 0xff000000) == 0xff000000) &&
833 ((hatch->backcol & 0xff000000) == 0xff000000);
835 case BrushTypeLinearGradient:
836 case BrushTypeTextureFill:
837 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
843 static void brush_fill_path(GpGraphics *graphics, GpBrush* brush)
847 case BrushTypeSolidColor:
849 GpSolidFill *fill = (GpSolidFill*)brush;
853 /* partially transparent fill */
855 SelectClipPath(graphics->hdc, RGN_AND);
856 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
858 HDC hdc = CreateCompatibleDC(NULL);
864 oldbmp = SelectObject(hdc, fill->bmp);
866 bf.BlendOp = AC_SRC_OVER;
868 bf.SourceConstantAlpha = 255;
869 bf.AlphaFormat = AC_SRC_ALPHA;
871 GdiAlphaBlend(graphics->hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdc, 0, 0, 1, 1, bf);
873 SelectObject(hdc, oldbmp);
879 /* else fall through */
883 HBRUSH gdibrush, old_brush;
885 gdibrush = create_gdi_brush(brush);
886 if (!gdibrush) return;
888 old_brush = SelectObject(graphics->hdc, gdibrush);
889 FillPath(graphics->hdc);
890 SelectObject(graphics->hdc, old_brush);
891 DeleteObject(gdibrush);
897 static INT brush_can_fill_pixels(GpBrush *brush)
901 case BrushTypeSolidColor:
902 case BrushTypeHatchFill:
903 case BrushTypeLinearGradient:
904 case BrushTypeTextureFill:
911 static GpStatus brush_fill_pixels(GpGraphics *graphics, GpBrush *brush,
912 DWORD *argb_pixels, GpRect *fill_area, UINT cdwStride)
916 case BrushTypeSolidColor:
919 GpSolidFill *fill = (GpSolidFill*)brush;
920 for (x=0; x<fill_area->Width; x++)
921 for (y=0; y<fill_area->Height; y++)
922 argb_pixels[x + y*cdwStride] = fill->color;
925 case BrushTypeHatchFill:
928 GpHatch *fill = (GpHatch*)brush;
929 const char *hatch_data;
931 if (get_hatch_data(fill->hatchstyle, &hatch_data) != Ok)
932 return NotImplemented;
934 for (x=0; x<fill_area->Width; x++)
935 for (y=0; y<fill_area->Height; y++)
939 /* FIXME: Account for the rendering origin */
940 hx = (x + fill_area->X) % 8;
941 hy = (y + fill_area->Y) % 8;
943 if ((hatch_data[7-hy] & (0x80 >> hx)) != 0)
944 argb_pixels[x + y*cdwStride] = fill->forecol;
946 argb_pixels[x + y*cdwStride] = fill->backcol;
951 case BrushTypeLinearGradient:
953 GpLineGradient *fill = (GpLineGradient*)brush;
954 GpPointF draw_points[3], line_points[3];
956 static const GpRectF box_1 = { 0.0, 0.0, 1.0, 1.0 };
957 GpMatrix *world_to_gradient; /* FIXME: Store this in the brush? */
960 draw_points[0].X = fill_area->X;
961 draw_points[0].Y = fill_area->Y;
962 draw_points[1].X = fill_area->X+1;
963 draw_points[1].Y = fill_area->Y;
964 draw_points[2].X = fill_area->X;
965 draw_points[2].Y = fill_area->Y+1;
967 /* Transform the points to a co-ordinate space where X is the point's
968 * position in the gradient, 0.0 being the start point and 1.0 the
970 stat = GdipTransformPoints(graphics, CoordinateSpaceWorld,
971 CoordinateSpaceDevice, draw_points, 3);
975 line_points[0] = fill->startpoint;
976 line_points[1] = fill->endpoint;
977 line_points[2].X = fill->startpoint.X + (fill->startpoint.Y - fill->endpoint.Y);
978 line_points[2].Y = fill->startpoint.Y + (fill->endpoint.X - fill->startpoint.X);
980 stat = GdipCreateMatrix3(&box_1, line_points, &world_to_gradient);
985 stat = GdipInvertMatrix(world_to_gradient);
988 stat = GdipTransformMatrixPoints(world_to_gradient, draw_points, 3);
990 GdipDeleteMatrix(world_to_gradient);
995 REAL x_delta = draw_points[1].X - draw_points[0].X;
996 REAL y_delta = draw_points[2].X - draw_points[0].X;
998 for (y=0; y<fill_area->Height; y++)
1000 for (x=0; x<fill_area->Width; x++)
1002 REAL pos = draw_points[0].X + x * x_delta + y * y_delta;
1004 argb_pixels[x + y*cdwStride] = blend_line_gradient(fill, pos);
1011 case BrushTypeTextureFill:
1013 GpTexture *fill = (GpTexture*)brush;
1014 GpPointF draw_points[3];
1016 GpMatrix *world_to_texture;
1022 if (fill->image->type != ImageTypeBitmap)
1024 FIXME("metafile texture brushes not implemented\n");
1025 return NotImplemented;
1028 bitmap = (GpBitmap*)fill->image;
1029 src_stride = sizeof(ARGB) * bitmap->width;
1031 src_area.X = src_area.Y = 0;
1032 src_area.Width = bitmap->width;
1033 src_area.Height = bitmap->height;
1035 draw_points[0].X = fill_area->X;
1036 draw_points[0].Y = fill_area->Y;
1037 draw_points[1].X = fill_area->X+1;
1038 draw_points[1].Y = fill_area->Y;
1039 draw_points[2].X = fill_area->X;
1040 draw_points[2].Y = fill_area->Y+1;
1042 /* Transform the points to the co-ordinate space of the bitmap. */
1043 stat = GdipTransformPoints(graphics, CoordinateSpaceWorld,
1044 CoordinateSpaceDevice, draw_points, 3);
1048 stat = GdipCloneMatrix(fill->transform, &world_to_texture);
1053 stat = GdipInvertMatrix(world_to_texture);
1056 stat = GdipTransformMatrixPoints(world_to_texture, draw_points, 3);
1058 GdipDeleteMatrix(world_to_texture);
1061 if (stat == Ok && !fill->bitmap_bits)
1063 BitmapData lockeddata;
1065 fill->bitmap_bits = GdipAlloc(sizeof(ARGB) * bitmap->width * bitmap->height);
1066 if (!fill->bitmap_bits)
1071 lockeddata.Width = bitmap->width;
1072 lockeddata.Height = bitmap->height;
1073 lockeddata.Stride = src_stride;
1074 lockeddata.PixelFormat = PixelFormat32bppARGB;
1075 lockeddata.Scan0 = fill->bitmap_bits;
1077 stat = GdipBitmapLockBits(bitmap, &src_area, ImageLockModeRead|ImageLockModeUserInputBuf,
1078 PixelFormat32bppARGB, &lockeddata);
1082 stat = GdipBitmapUnlockBits(bitmap, &lockeddata);
1085 apply_image_attributes(fill->imageattributes, fill->bitmap_bits,
1086 bitmap->width, bitmap->height,
1087 src_stride, ColorAdjustTypeBitmap);
1091 GdipFree(fill->bitmap_bits);
1092 fill->bitmap_bits = NULL;
1098 REAL x_dx = draw_points[1].X - draw_points[0].X;
1099 REAL x_dy = draw_points[1].Y - draw_points[0].Y;
1100 REAL y_dx = draw_points[2].X - draw_points[0].X;
1101 REAL y_dy = draw_points[2].Y - draw_points[0].Y;
1103 for (y=0; y<fill_area->Height; y++)
1105 for (x=0; x<fill_area->Width; x++)
1108 point.X = draw_points[0].X + x * x_dx + y * y_dx;
1109 point.Y = draw_points[0].Y + y * x_dy + y * y_dy;
1111 argb_pixels[x + y*cdwStride] = resample_bitmap_pixel(
1112 &src_area, fill->bitmap_bits, bitmap->width, bitmap->height,
1113 &point, fill->imageattributes, graphics->interpolation);
1121 return NotImplemented;
1125 /* GdipDrawPie/GdipFillPie helper function */
1126 static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width,
1127 REAL height, REAL startAngle, REAL sweepAngle)
1134 ptf[1].X = x + width;
1135 ptf[1].Y = y + height;
1137 deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y);
1138 deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y);
1140 transform_and_round_points(graphics, pti, ptf, 4);
1142 Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x,
1143 pti[2].y, pti[3].x, pti[3].y);
1146 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1147 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1148 * should not be called on an hdc that has a path you care about. */
1149 static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
1150 const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
1152 HGDIOBJ oldbrush = NULL, oldpen = NULL;
1153 GpMatrix *matrix = NULL;
1154 HBRUSH brush = NULL;
1156 PointF ptf[4], *custptf = NULL;
1157 POINT pt[4], *custpt = NULL;
1159 REAL theta, dsmall, dbig, dx, dy = 0.0;
1164 if((x1 == x2) && (y1 == y2))
1167 theta = gdiplus_atan2(y2 - y1, x2 - x1);
1169 customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
1171 brush = CreateSolidBrush(color);
1172 lb.lbStyle = BS_SOLID;
1175 pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
1176 PS_JOIN_MITER, 1, &lb, 0,
1178 oldbrush = SelectObject(graphics->hdc, brush);
1179 oldpen = SelectObject(graphics->hdc, pen);
1186 case LineCapSquareAnchor:
1187 case LineCapDiamondAnchor:
1188 size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0;
1189 if(cap == LineCapDiamondAnchor){
1190 dsmall = cos(theta + M_PI_2) * size;
1191 dbig = sin(theta + M_PI_2) * size;
1194 dsmall = cos(theta + M_PI_4) * size;
1195 dbig = sin(theta + M_PI_4) * size;
1198 ptf[0].X = x2 - dsmall;
1199 ptf[1].X = x2 + dbig;
1201 ptf[0].Y = y2 - dbig;
1202 ptf[3].Y = y2 + dsmall;
1204 ptf[1].Y = y2 - dsmall;
1205 ptf[2].Y = y2 + dbig;
1207 ptf[3].X = x2 - dbig;
1208 ptf[2].X = x2 + dsmall;
1210 transform_and_round_points(graphics, pt, ptf, 4);
1211 Polygon(graphics->hdc, pt, 4);
1214 case LineCapArrowAnchor:
1215 size = size * 4.0 / sqrt(3.0);
1217 dx = cos(M_PI / 6.0 + theta) * size;
1218 dy = sin(M_PI / 6.0 + theta) * size;
1223 dx = cos(- M_PI / 6.0 + theta) * size;
1224 dy = sin(- M_PI / 6.0 + theta) * size;
1232 transform_and_round_points(graphics, pt, ptf, 3);
1233 Polygon(graphics->hdc, pt, 3);
1236 case LineCapRoundAnchor:
1237 dx = dy = ANCHOR_WIDTH * size / 2.0;
1244 transform_and_round_points(graphics, pt, ptf, 2);
1245 Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
1248 case LineCapTriangle:
1250 dx = cos(M_PI_2 + theta) * size;
1251 dy = sin(M_PI_2 + theta) * size;
1258 dx = cos(theta) * size;
1259 dy = sin(theta) * size;
1264 transform_and_round_points(graphics, pt, ptf, 3);
1265 Polygon(graphics->hdc, pt, 3);
1269 dx = dy = size / 2.0;
1276 dx = -cos(M_PI_2 + theta) * size;
1277 dy = -sin(M_PI_2 + theta) * size;
1284 transform_and_round_points(graphics, pt, ptf, 4);
1285 Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x,
1286 pt[2].y, pt[3].x, pt[3].y);
1293 count = custom->pathdata.Count;
1294 custptf = GdipAlloc(count * sizeof(PointF));
1295 custpt = GdipAlloc(count * sizeof(POINT));
1296 tp = GdipAlloc(count);
1298 if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok))
1301 memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF));
1303 GdipScaleMatrix(matrix, size, size, MatrixOrderAppend);
1304 GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2),
1306 GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend);
1307 GdipTransformMatrixPoints(matrix, custptf, count);
1309 transform_and_round_points(graphics, custpt, custptf, count);
1311 for(i = 0; i < count; i++)
1312 tp[i] = convert_path_point_type(custom->pathdata.Types[i]);
1315 BeginPath(graphics->hdc);
1316 PolyDraw(graphics->hdc, custpt, tp, count);
1317 EndPath(graphics->hdc);
1318 StrokeAndFillPath(graphics->hdc);
1321 PolyDraw(graphics->hdc, custpt, tp, count);
1327 GdipDeleteMatrix(matrix);
1334 SelectObject(graphics->hdc, oldbrush);
1335 SelectObject(graphics->hdc, oldpen);
1336 DeleteObject(brush);
1341 /* Shortens the line by the given percent by changing x2, y2.
1342 * If percent is > 1.0 then the line will change direction.
1343 * If percent is negative it can lengthen the line. */
1344 static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL percent)
1346 REAL dist, theta, dx, dy;
1348 if((y1 == *y2) && (x1 == *x2))
1351 dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent;
1352 theta = gdiplus_atan2((*y2 - y1), (*x2 - x1));
1353 dx = cos(theta) * dist;
1354 dy = sin(theta) * dist;
1360 /* Shortens the line by the given amount by changing x2, y2.
1361 * If the amount is greater than the distance, the line will become length 0.
1362 * If the amount is negative, it can lengthen the line. */
1363 static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt)
1365 REAL dx, dy, percent;
1369 if(dx == 0 && dy == 0)
1372 percent = amt / sqrt(dx * dx + dy * dy);
1379 shorten_line_percent(x1, y1, x2, y2, percent);
1382 /* Draws lines between the given points, and if caps is true then draws an endcap
1383 * at the end of the last line. */
1384 static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen,
1385 GDIPCONST GpPointF * pt, INT count, BOOL caps)
1388 GpPointF *ptcopy = NULL;
1389 GpStatus status = GenericError;
1394 pti = GdipAlloc(count * sizeof(POINT));
1395 ptcopy = GdipAlloc(count * sizeof(GpPointF));
1397 if(!pti || !ptcopy){
1398 status = OutOfMemory;
1402 memcpy(ptcopy, pt, count * sizeof(GpPointF));
1405 if(pen->endcap == LineCapArrowAnchor)
1406 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
1407 &ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width);
1408 else if((pen->endcap == LineCapCustom) && pen->customend)
1409 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
1410 &ptcopy[count-1].X, &ptcopy[count-1].Y,
1411 pen->customend->inset * pen->width);
1413 if(pen->startcap == LineCapArrowAnchor)
1414 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
1415 &ptcopy[0].X, &ptcopy[0].Y, pen->width);
1416 else if((pen->startcap == LineCapCustom) && pen->customstart)
1417 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
1418 &ptcopy[0].X, &ptcopy[0].Y,
1419 pen->customstart->inset * pen->width);
1421 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->endcap, pen->width, pen->customend,
1422 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
1423 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->startcap, pen->width, pen->customstart,
1424 pt[1].X, pt[1].Y, pt[0].X, pt[0].Y);
1427 transform_and_round_points(graphics, pti, ptcopy, count);
1429 if(Polyline(graphics->hdc, pti, count))
1439 /* Conducts a linear search to find the bezier points that will back off
1440 * the endpoint of the curve by a distance of amt. Linear search works
1441 * better than binary in this case because there are multiple solutions,
1442 * and binary searches often find a bad one. I don't think this is what
1443 * Windows does but short of rendering the bezier without GDI's help it's
1444 * the best we can do. If rev then work from the start of the passed points
1445 * instead of the end. */
1446 static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev)
1449 REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0;
1450 INT i, first = 0, second = 1, third = 2, fourth = 3;
1459 origx = pt[fourth].X;
1460 origy = pt[fourth].Y;
1461 memcpy(origpt, pt, sizeof(GpPointF) * 4);
1463 for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){
1464 /* reset bezier points to original values */
1465 memcpy(pt, origpt, sizeof(GpPointF) * 4);
1466 /* Perform magic on bezier points. Order is important here.*/
1467 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
1468 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
1469 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
1470 shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent);
1471 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
1472 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
1474 dx = pt[fourth].X - origx;
1475 dy = pt[fourth].Y - origy;
1477 diff = sqrt(dx * dx + dy * dy);
1478 percent += 0.0005 * amt;
1482 /* Draws bezier curves between given points, and if caps is true then draws an
1483 * endcap at the end of the last line. */
1484 static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
1485 GDIPCONST GpPointF * pt, INT count, BOOL caps)
1489 GpStatus status = GenericError;
1494 pti = GdipAlloc(count * sizeof(POINT));
1495 ptcopy = GdipAlloc(count * sizeof(GpPointF));
1497 if(!pti || !ptcopy){
1498 status = OutOfMemory;
1502 memcpy(ptcopy, pt, count * sizeof(GpPointF));
1505 if(pen->endcap == LineCapArrowAnchor)
1506 shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
1507 else if((pen->endcap == LineCapCustom) && pen->customend)
1508 shorten_bezier_amt(&ptcopy[count-4], pen->width * pen->customend->inset,
1511 if(pen->startcap == LineCapArrowAnchor)
1512 shorten_bezier_amt(ptcopy, pen->width, TRUE);
1513 else if((pen->startcap == LineCapCustom) && pen->customstart)
1514 shorten_bezier_amt(ptcopy, pen->width * pen->customstart->inset, TRUE);
1516 /* the direction of the line cap is parallel to the direction at the
1517 * end of the bezier (which, if it has been shortened, is not the same
1518 * as the direction from pt[count-2] to pt[count-1]) */
1519 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->endcap, pen->width, pen->customend,
1520 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
1521 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
1522 pt[count - 1].X, pt[count - 1].Y);
1524 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->startcap, pen->width, pen->customstart,
1525 pt[0].X - (ptcopy[0].X - ptcopy[1].X),
1526 pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
1529 transform_and_round_points(graphics, pti, ptcopy, count);
1531 PolyBezier(graphics->hdc, pti, count);
1542 /* Draws a combination of bezier curves and lines between points. */
1543 static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
1544 GDIPCONST BYTE * types, INT count, BOOL caps)
1546 POINT *pti = GdipAlloc(count * sizeof(POINT));
1547 BYTE *tp = GdipAlloc(count);
1548 GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
1550 GpStatus status = GenericError;
1556 if(!pti || !tp || !ptcopy){
1557 status = OutOfMemory;
1561 for(i = 1; i < count; i++){
1562 if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
1563 if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
1564 || !(types[i + 1] & PathPointTypeBezier)){
1565 ERR("Bad bezier points\n");
1572 memcpy(ptcopy, pt, count * sizeof(GpPointF));
1574 /* If we are drawing caps, go through the points and adjust them accordingly,
1575 * and draw the caps. */
1577 switch(types[count - 1] & PathPointTypePathTypeMask){
1578 case PathPointTypeBezier:
1579 if(pen->endcap == LineCapArrowAnchor)
1580 shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
1581 else if((pen->endcap == LineCapCustom) && pen->customend)
1582 shorten_bezier_amt(&ptcopy[count - 4],
1583 pen->width * pen->customend->inset, FALSE);
1585 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->endcap, pen->width, pen->customend,
1586 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
1587 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
1588 pt[count - 1].X, pt[count - 1].Y);
1591 case PathPointTypeLine:
1592 if(pen->endcap == LineCapArrowAnchor)
1593 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
1594 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
1596 else if((pen->endcap == LineCapCustom) && pen->customend)
1597 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
1598 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
1599 pen->customend->inset * pen->width);
1601 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->endcap, pen->width, pen->customend,
1602 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
1607 ERR("Bad path last point\n");
1611 /* Find start of points */
1612 for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
1613 == PathPointTypeStart); j++);
1615 switch(types[j] & PathPointTypePathTypeMask){
1616 case PathPointTypeBezier:
1617 if(pen->startcap == LineCapArrowAnchor)
1618 shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
1619 else if((pen->startcap == LineCapCustom) && pen->customstart)
1620 shorten_bezier_amt(&ptcopy[j - 1],
1621 pen->width * pen->customstart->inset, TRUE);
1623 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->startcap, pen->width, pen->customstart,
1624 pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
1625 pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
1626 pt[j - 1].X, pt[j - 1].Y);
1629 case PathPointTypeLine:
1630 if(pen->startcap == LineCapArrowAnchor)
1631 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
1632 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
1634 else if((pen->startcap == LineCapCustom) && pen->customstart)
1635 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
1636 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
1637 pen->customstart->inset * pen->width);
1639 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->startcap, pen->width, pen->customstart,
1640 pt[j].X, pt[j].Y, pt[j - 1].X,
1645 ERR("Bad path points\n");
1650 transform_and_round_points(graphics, pti, ptcopy, count);
1652 for(i = 0; i < count; i++){
1653 tp[i] = convert_path_point_type(types[i]);
1656 PolyDraw(graphics->hdc, pti, tp, count);
1668 GpStatus trace_path(GpGraphics *graphics, GpPath *path)
1672 BeginPath(graphics->hdc);
1673 result = draw_poly(graphics, NULL, path->pathdata.Points,
1674 path->pathdata.Types, path->pathdata.Count, FALSE);
1675 EndPath(graphics->hdc);
1679 typedef struct _GraphicsContainerItem {
1681 GraphicsContainer contid;
1683 SmoothingMode smoothing;
1684 CompositingQuality compqual;
1685 InterpolationMode interpolation;
1686 CompositingMode compmode;
1687 TextRenderingHint texthint;
1690 PixelOffsetMode pixeloffset;
1692 GpMatrix* worldtrans;
1694 } GraphicsContainerItem;
1696 static GpStatus init_container(GraphicsContainerItem** container,
1697 GDIPCONST GpGraphics* graphics){
1700 *container = GdipAlloc(sizeof(GraphicsContainerItem));
1704 (*container)->contid = graphics->contid + 1;
1706 (*container)->smoothing = graphics->smoothing;
1707 (*container)->compqual = graphics->compqual;
1708 (*container)->interpolation = graphics->interpolation;
1709 (*container)->compmode = graphics->compmode;
1710 (*container)->texthint = graphics->texthint;
1711 (*container)->scale = graphics->scale;
1712 (*container)->unit = graphics->unit;
1713 (*container)->textcontrast = graphics->textcontrast;
1714 (*container)->pixeloffset = graphics->pixeloffset;
1716 sts = GdipCloneMatrix(graphics->worldtrans, &(*container)->worldtrans);
1718 GdipFree(*container);
1723 sts = GdipCloneRegion(graphics->clip, &(*container)->clip);
1725 GdipDeleteMatrix((*container)->worldtrans);
1726 GdipFree(*container);
1734 static void delete_container(GraphicsContainerItem* container){
1735 GdipDeleteMatrix(container->worldtrans);
1736 GdipDeleteRegion(container->clip);
1737 GdipFree(container);
1740 static GpStatus restore_container(GpGraphics* graphics,
1741 GDIPCONST GraphicsContainerItem* container){
1746 sts = GdipCloneMatrix(container->worldtrans, &newTrans);
1750 sts = GdipCloneRegion(container->clip, &newClip);
1752 GdipDeleteMatrix(newTrans);
1756 GdipDeleteMatrix(graphics->worldtrans);
1757 graphics->worldtrans = newTrans;
1759 GdipDeleteRegion(graphics->clip);
1760 graphics->clip = newClip;
1762 graphics->contid = container->contid - 1;
1764 graphics->smoothing = container->smoothing;
1765 graphics->compqual = container->compqual;
1766 graphics->interpolation = container->interpolation;
1767 graphics->compmode = container->compmode;
1768 graphics->texthint = container->texthint;
1769 graphics->scale = container->scale;
1770 graphics->unit = container->unit;
1771 graphics->textcontrast = container->textcontrast;
1772 graphics->pixeloffset = container->pixeloffset;
1777 static GpStatus get_graphics_bounds(GpGraphics* graphics, GpRectF* rect)
1783 if(graphics->hwnd) {
1784 if(!GetClientRect(graphics->hwnd, &wnd_rect))
1785 return GenericError;
1787 rect->X = wnd_rect.left;
1788 rect->Y = wnd_rect.top;
1789 rect->Width = wnd_rect.right - wnd_rect.left;
1790 rect->Height = wnd_rect.bottom - wnd_rect.top;
1791 }else if (graphics->image){
1792 stat = GdipGetImageBounds(graphics->image, rect, &unit);
1793 if (stat == Ok && unit != UnitPixel)
1794 FIXME("need to convert from unit %i\n", unit);
1798 rect->Width = GetDeviceCaps(graphics->hdc, HORZRES);
1799 rect->Height = GetDeviceCaps(graphics->hdc, VERTRES);
1805 /* on success, rgn will contain the region of the graphics object which
1806 * is visible after clipping has been applied */
1807 static GpStatus get_visible_clip_region(GpGraphics *graphics, GpRegion *rgn)
1813 if((stat = get_graphics_bounds(graphics, &rectf)) != Ok)
1816 if((stat = GdipCreateRegion(&tmp)) != Ok)
1819 if((stat = GdipCombineRegionRect(tmp, &rectf, CombineModeReplace)) != Ok)
1822 if((stat = GdipCombineRegionRegion(tmp, graphics->clip, CombineModeIntersect)) != Ok)
1825 stat = GdipCombineRegionRegion(rgn, tmp, CombineModeReplace);
1828 GdipDeleteRegion(tmp);
1832 void get_font_hfont(GpGraphics *graphics, GDIPCONST GpFont *font, HFONT *hfont)
1834 HDC hdc = CreateCompatibleDC(0);
1836 REAL angle, rel_width, rel_height;
1838 HFONT unscaled_font;
1839 TEXTMETRICW textmet;
1848 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
1849 angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X));
1850 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
1851 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
1852 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
1853 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
1856 lfw.lfHeight = roundr(-font->pixel_size * rel_height);
1857 unscaled_font = CreateFontIndirectW(&lfw);
1859 SelectObject(hdc, unscaled_font);
1860 GetTextMetricsW(hdc, &textmet);
1863 lfw.lfHeight = roundr(-font->pixel_size * rel_height);
1864 lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width / rel_height);
1865 lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0);
1867 *hfont = CreateFontIndirectW(&lfw);
1870 DeleteObject(unscaled_font);
1873 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
1875 TRACE("(%p, %p)\n", hdc, graphics);
1877 return GdipCreateFromHDC2(hdc, NULL, graphics);
1880 GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **graphics)
1884 TRACE("(%p, %p, %p)\n", hdc, hDevice, graphics);
1886 if(hDevice != NULL) {
1887 FIXME("Don't know how to handle parameter hDevice\n");
1888 return NotImplemented;
1894 if(graphics == NULL)
1895 return InvalidParameter;
1897 *graphics = GdipAlloc(sizeof(GpGraphics));
1898 if(!*graphics) return OutOfMemory;
1900 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
1901 GdipFree(*graphics);
1905 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
1906 GdipFree((*graphics)->worldtrans);
1907 GdipFree(*graphics);
1911 (*graphics)->hdc = hdc;
1912 (*graphics)->hwnd = WindowFromDC(hdc);
1913 (*graphics)->owndc = FALSE;
1914 (*graphics)->smoothing = SmoothingModeDefault;
1915 (*graphics)->compqual = CompositingQualityDefault;
1916 (*graphics)->interpolation = InterpolationModeBilinear;
1917 (*graphics)->pixeloffset = PixelOffsetModeDefault;
1918 (*graphics)->compmode = CompositingModeSourceOver;
1919 (*graphics)->unit = UnitDisplay;
1920 (*graphics)->scale = 1.0;
1921 (*graphics)->busy = FALSE;
1922 (*graphics)->textcontrast = 4;
1923 list_init(&(*graphics)->containers);
1924 (*graphics)->contid = 0;
1926 TRACE("<-- %p\n", *graphics);
1931 GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics)
1935 *graphics = GdipAlloc(sizeof(GpGraphics));
1936 if(!*graphics) return OutOfMemory;
1938 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
1939 GdipFree(*graphics);
1943 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
1944 GdipFree((*graphics)->worldtrans);
1945 GdipFree(*graphics);
1949 (*graphics)->hdc = NULL;
1950 (*graphics)->hwnd = NULL;
1951 (*graphics)->owndc = FALSE;
1952 (*graphics)->image = image;
1953 (*graphics)->smoothing = SmoothingModeDefault;
1954 (*graphics)->compqual = CompositingQualityDefault;
1955 (*graphics)->interpolation = InterpolationModeBilinear;
1956 (*graphics)->pixeloffset = PixelOffsetModeDefault;
1957 (*graphics)->compmode = CompositingModeSourceOver;
1958 (*graphics)->unit = UnitDisplay;
1959 (*graphics)->scale = 1.0;
1960 (*graphics)->busy = FALSE;
1961 (*graphics)->textcontrast = 4;
1962 list_init(&(*graphics)->containers);
1963 (*graphics)->contid = 0;
1965 TRACE("<-- %p\n", *graphics);
1970 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
1975 TRACE("(%p, %p)\n", hwnd, graphics);
1979 if((ret = GdipCreateFromHDC(hdc, graphics)) != Ok)
1981 ReleaseDC(hwnd, hdc);
1985 (*graphics)->hwnd = hwnd;
1986 (*graphics)->owndc = TRUE;
1991 /* FIXME: no icm handling */
1992 GpStatus WINGDIPAPI GdipCreateFromHWNDICM(HWND hwnd, GpGraphics **graphics)
1994 TRACE("(%p, %p)\n", hwnd, graphics);
1996 return GdipCreateFromHWND(hwnd, graphics);
1999 GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
2000 GpMetafile **metafile)
2004 TRACE("(%p,%i,%p)\n", hemf, delete, metafile);
2006 if(!hemf || !metafile)
2007 return InvalidParameter;
2010 FIXME("not implemented\n");
2012 return NotImplemented;
2015 GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
2016 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
2018 IStream *stream = NULL;
2022 GpStatus retval = Ok;
2024 TRACE("(%p, %d, %p, %p)\n", hwmf, delete, placeable, metafile);
2026 if(!hwmf || !metafile || !placeable)
2027 return InvalidParameter;
2030 read = GetMetaFileBitsEx(hwmf, 0, NULL);
2032 return GenericError;
2033 copy = GdipAlloc(read);
2034 GetMetaFileBitsEx(hwmf, read, copy);
2036 hemf = SetWinMetaFileBits(read, copy, NULL, NULL);
2039 read = GetEnhMetaFileBits(hemf, 0, NULL);
2040 copy = GdipAlloc(read);
2041 GetEnhMetaFileBits(hemf, read, copy);
2042 DeleteEnhMetaFile(hemf);
2044 if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
2045 ERR("could not make stream\n");
2047 retval = GenericError;
2051 *metafile = GdipAlloc(sizeof(GpMetafile));
2053 retval = OutOfMemory;
2057 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
2058 (LPVOID*) &((*metafile)->image.picture)) != S_OK)
2060 retval = GenericError;
2065 (*metafile)->image.type = ImageTypeMetafile;
2066 memcpy(&(*metafile)->image.format, &ImageFormatWMF, sizeof(GUID));
2067 (*metafile)->image.palette_flags = 0;
2068 (*metafile)->image.palette_count = 0;
2069 (*metafile)->image.palette_size = 0;
2070 (*metafile)->image.palette_entries = NULL;
2071 (*metafile)->image.xres = (REAL)placeable->Inch;
2072 (*metafile)->image.yres = (REAL)placeable->Inch;
2073 (*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch);
2074 (*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Top) / ((REAL) placeable->Inch);
2075 (*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right
2076 - placeable->BoundingBox.Left));
2077 (*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom
2078 - placeable->BoundingBox.Top));
2079 (*metafile)->unit = UnitPixel;
2082 DeleteMetaFile(hwmf);
2084 TRACE("<-- %p\n", *metafile);
2088 GdipFree(*metafile);
2089 IStream_Release(stream);
2093 GpStatus WINGDIPAPI GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR *file,
2094 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
2096 HMETAFILE hmf = GetMetaFileW(file);
2098 TRACE("(%s, %p, %p)\n", debugstr_w(file), placeable, metafile);
2100 if(!hmf) return InvalidParameter;
2102 return GdipCreateMetafileFromWmf(hmf, TRUE, placeable, metafile);
2105 GpStatus WINGDIPAPI GdipCreateMetafileFromFile(GDIPCONST WCHAR *file,
2106 GpMetafile **metafile)
2108 FIXME("(%p, %p): stub\n", file, metafile);
2109 return NotImplemented;
2112 GpStatus WINGDIPAPI GdipCreateMetafileFromStream(IStream *stream,
2113 GpMetafile **metafile)
2115 FIXME("(%p, %p): stub\n", stream, metafile);
2116 return NotImplemented;
2119 GpStatus WINGDIPAPI GdipCreateStreamOnFile(GDIPCONST WCHAR * filename,
2120 UINT access, IStream **stream)
2125 TRACE("(%s, %u, %p)\n", debugstr_w(filename), access, stream);
2127 if(!stream || !filename)
2128 return InvalidParameter;
2130 if(access & GENERIC_WRITE)
2131 dwMode = STGM_SHARE_DENY_WRITE | STGM_WRITE | STGM_CREATE;
2132 else if(access & GENERIC_READ)
2133 dwMode = STGM_SHARE_DENY_WRITE | STGM_READ | STGM_FAILIFTHERE;
2135 return InvalidParameter;
2137 ret = SHCreateStreamOnFileW(filename, dwMode, stream);
2139 return hresult_to_status(ret);
2142 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
2144 GraphicsContainerItem *cont, *next;
2146 TRACE("(%p)\n", graphics);
2148 if(!graphics) return InvalidParameter;
2149 if(graphics->busy) return ObjectBusy;
2151 if (graphics->image && graphics->image->type == ImageTypeMetafile)
2153 stat = METAFILE_GraphicsDeleted((GpMetafile*)graphics->image);
2159 ReleaseDC(graphics->hwnd, graphics->hdc);
2161 LIST_FOR_EACH_ENTRY_SAFE(cont, next, &graphics->containers, GraphicsContainerItem, entry){
2162 list_remove(&cont->entry);
2163 delete_container(cont);
2166 GdipDeleteRegion(graphics->clip);
2167 GdipDeleteMatrix(graphics->worldtrans);
2173 GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
2174 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2176 INT save_state, num_pts;
2177 GpPointF points[MAX_ARC_PTS];
2180 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
2181 width, height, startAngle, sweepAngle);
2183 if(!graphics || !pen || width <= 0 || height <= 0)
2184 return InvalidParameter;
2191 FIXME("graphics object has no HDC\n");
2195 num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
2197 save_state = prepare_dc(graphics, pen);
2199 retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
2201 restore_dc(graphics, save_state);
2206 GpStatus WINGDIPAPI GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x,
2207 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2209 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
2210 width, height, startAngle, sweepAngle);
2212 return GdipDrawArc(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2215 GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
2216 REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
2222 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1,
2223 x2, y2, x3, y3, x4, y4);
2225 if(!graphics || !pen)
2226 return InvalidParameter;
2233 FIXME("graphics object has no HDC\n");
2246 save_state = prepare_dc(graphics, pen);
2248 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
2250 restore_dc(graphics, save_state);
2255 GpStatus WINGDIPAPI GdipDrawBezierI(GpGraphics *graphics, GpPen *pen, INT x1,
2256 INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4)
2262 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics, pen, x1, y1,
2263 x2, y2, x3, y3, x4, y4);
2265 if(!graphics || !pen)
2266 return InvalidParameter;
2273 FIXME("graphics object has no HDC\n");
2286 save_state = prepare_dc(graphics, pen);
2288 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
2290 restore_dc(graphics, save_state);
2295 GpStatus WINGDIPAPI GdipDrawBeziers(GpGraphics *graphics, GpPen *pen,
2296 GDIPCONST GpPointF *points, INT count)
2301 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2303 if(!graphics || !pen || !points || (count <= 0))
2304 return InvalidParameter;
2309 for(i = 0; i < floor(count / 4); i++){
2310 ret = GdipDrawBezier(graphics, pen,
2311 points[4*i].X, points[4*i].Y,
2312 points[4*i + 1].X, points[4*i + 1].Y,
2313 points[4*i + 2].X, points[4*i + 2].Y,
2314 points[4*i + 3].X, points[4*i + 3].Y);
2322 GpStatus WINGDIPAPI GdipDrawBeziersI(GpGraphics *graphics, GpPen *pen,
2323 GDIPCONST GpPoint *points, INT count)
2329 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2331 if(!graphics || !pen || !points || (count <= 0))
2332 return InvalidParameter;
2337 pts = GdipAlloc(sizeof(GpPointF) * count);
2341 for(i = 0; i < count; i++){
2342 pts[i].X = (REAL)points[i].X;
2343 pts[i].Y = (REAL)points[i].Y;
2346 ret = GdipDrawBeziers(graphics,pen,pts,count);
2353 GpStatus WINGDIPAPI GdipDrawClosedCurve(GpGraphics *graphics, GpPen *pen,
2354 GDIPCONST GpPointF *points, INT count)
2356 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2358 return GdipDrawClosedCurve2(graphics, pen, points, count, 1.0);
2361 GpStatus WINGDIPAPI GdipDrawClosedCurveI(GpGraphics *graphics, GpPen *pen,
2362 GDIPCONST GpPoint *points, INT count)
2364 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2366 return GdipDrawClosedCurve2I(graphics, pen, points, count, 1.0);
2369 GpStatus WINGDIPAPI GdipDrawClosedCurve2(GpGraphics *graphics, GpPen *pen,
2370 GDIPCONST GpPointF *points, INT count, REAL tension)
2375 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
2377 if(!graphics || !pen || !points || count <= 0)
2378 return InvalidParameter;
2383 if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok)
2386 stat = GdipAddPathClosedCurve2(path, points, count, tension);
2388 GdipDeletePath(path);
2392 stat = GdipDrawPath(graphics, pen, path);
2394 GdipDeletePath(path);
2399 GpStatus WINGDIPAPI GdipDrawClosedCurve2I(GpGraphics *graphics, GpPen *pen,
2400 GDIPCONST GpPoint *points, INT count, REAL tension)
2406 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
2408 if(!points || count <= 0)
2409 return InvalidParameter;
2411 ptf = GdipAlloc(sizeof(GpPointF)*count);
2415 for(i = 0; i < count; i++){
2416 ptf[i].X = (REAL)points[i].X;
2417 ptf[i].Y = (REAL)points[i].Y;
2420 stat = GdipDrawClosedCurve2(graphics, pen, ptf, count, tension);
2427 GpStatus WINGDIPAPI GdipDrawCurve(GpGraphics *graphics, GpPen *pen,
2428 GDIPCONST GpPointF *points, INT count)
2430 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2432 return GdipDrawCurve2(graphics,pen,points,count,1.0);
2435 GpStatus WINGDIPAPI GdipDrawCurveI(GpGraphics *graphics, GpPen *pen,
2436 GDIPCONST GpPoint *points, INT count)
2442 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2445 return InvalidParameter;
2447 pointsF = GdipAlloc(sizeof(GpPointF)*count);
2451 for(i = 0; i < count; i++){
2452 pointsF[i].X = (REAL)points[i].X;
2453 pointsF[i].Y = (REAL)points[i].Y;
2456 ret = GdipDrawCurve(graphics,pen,pointsF,count);
2462 /* Approximates cardinal spline with Bezier curves. */
2463 GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
2464 GDIPCONST GpPointF *points, INT count, REAL tension)
2466 /* PolyBezier expects count*3-2 points. */
2467 INT i, len_pt = count*3-2, save_state;
2469 REAL x1, x2, y1, y2;
2472 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
2474 if(!graphics || !pen)
2475 return InvalidParameter;
2481 return InvalidParameter;
2485 FIXME("graphics object has no HDC\n");
2489 pt = GdipAlloc(len_pt * sizeof(GpPointF));
2493 tension = tension * TENSION_CONST;
2495 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
2498 pt[0].X = points[0].X;
2499 pt[0].Y = points[0].Y;
2503 for(i = 0; i < count-2; i++){
2504 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
2508 pt[3*i+3].X = points[i+1].X;
2509 pt[3*i+3].Y = points[i+1].Y;
2514 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
2515 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
2517 pt[len_pt-2].X = x1;
2518 pt[len_pt-2].Y = y1;
2519 pt[len_pt-1].X = points[count-1].X;
2520 pt[len_pt-1].Y = points[count-1].Y;
2522 save_state = prepare_dc(graphics, pen);
2524 retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
2527 restore_dc(graphics, save_state);
2532 GpStatus WINGDIPAPI GdipDrawCurve2I(GpGraphics *graphics, GpPen *pen,
2533 GDIPCONST GpPoint *points, INT count, REAL tension)
2539 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
2542 return InvalidParameter;
2544 pointsF = GdipAlloc(sizeof(GpPointF)*count);
2548 for(i = 0; i < count; i++){
2549 pointsF[i].X = (REAL)points[i].X;
2550 pointsF[i].Y = (REAL)points[i].Y;
2553 ret = GdipDrawCurve2(graphics,pen,pointsF,count,tension);
2559 GpStatus WINGDIPAPI GdipDrawCurve3(GpGraphics *graphics, GpPen *pen,
2560 GDIPCONST GpPointF *points, INT count, INT offset, INT numberOfSegments,
2563 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
2565 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
2566 return InvalidParameter;
2569 return GdipDrawCurve2(graphics, pen, points + offset, numberOfSegments + 1, tension);
2572 GpStatus WINGDIPAPI GdipDrawCurve3I(GpGraphics *graphics, GpPen *pen,
2573 GDIPCONST GpPoint *points, INT count, INT offset, INT numberOfSegments,
2576 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
2582 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
2583 return InvalidParameter;
2586 return GdipDrawCurve2I(graphics, pen, points + offset, numberOfSegments + 1, tension);
2589 GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics *graphics, GpPen *pen, REAL x,
2590 REAL y, REAL width, REAL height)
2596 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
2598 if(!graphics || !pen)
2599 return InvalidParameter;
2606 FIXME("graphics object has no HDC\n");
2612 ptf[1].X = x + width;
2613 ptf[1].Y = y + height;
2615 save_state = prepare_dc(graphics, pen);
2616 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2618 transform_and_round_points(graphics, pti, ptf, 2);
2620 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
2622 restore_dc(graphics, save_state);
2627 GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics *graphics, GpPen *pen, INT x,
2628 INT y, INT width, INT height)
2630 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
2632 return GdipDrawEllipse(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2636 GpStatus WINGDIPAPI GdipDrawImage(GpGraphics *graphics, GpImage *image, REAL x, REAL y)
2641 TRACE("(%p, %p, %.2f, %.2f)\n", graphics, image, x, y);
2643 if(!graphics || !image)
2644 return InvalidParameter;
2646 GdipGetImageWidth(image, &width);
2647 GdipGetImageHeight(image, &height);
2649 /* FIXME: we should use the graphics and image dpi, somehow */
2651 points[0].X = points[2].X = x;
2652 points[0].Y = points[1].Y = y;
2653 points[1].X = x + width;
2654 points[2].Y = y + height;
2656 return GdipDrawImagePointsRect(graphics, image, points, 3, 0, 0, width, height,
2657 UnitPixel, NULL, NULL, NULL);
2660 GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x,
2663 TRACE("(%p, %p, %d, %d)\n", graphics, image, x, y);
2665 return GdipDrawImage(graphics, image, (REAL)x, (REAL)y);
2668 GpStatus WINGDIPAPI GdipDrawImagePointRect(GpGraphics *graphics, GpImage *image,
2669 REAL x, REAL y, REAL srcx, REAL srcy, REAL srcwidth, REAL srcheight,
2673 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
2675 points[0].X = points[2].X = x;
2676 points[0].Y = points[1].Y = y;
2678 /* FIXME: convert image coordinates to Graphics coordinates? */
2679 points[1].X = x + srcwidth;
2680 points[2].Y = y + srcheight;
2682 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2683 srcwidth, srcheight, srcUnit, NULL, NULL, NULL);
2686 GpStatus WINGDIPAPI GdipDrawImagePointRectI(GpGraphics *graphics, GpImage *image,
2687 INT x, INT y, INT srcx, INT srcy, INT srcwidth, INT srcheight,
2690 return GdipDrawImagePointRect(graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
2693 GpStatus WINGDIPAPI GdipDrawImagePoints(GpGraphics *graphics, GpImage *image,
2694 GDIPCONST GpPointF *dstpoints, INT count)
2698 TRACE("(%p, %p, %p, %d)\n", graphics, image, dstpoints, count);
2701 return InvalidParameter;
2703 GdipGetImageWidth(image, &width);
2704 GdipGetImageHeight(image, &height);
2706 return GdipDrawImagePointsRect(graphics, image, dstpoints, count, 0, 0,
2707 width, height, UnitPixel, NULL, NULL, NULL);
2710 GpStatus WINGDIPAPI GdipDrawImagePointsI(GpGraphics *graphics, GpImage *image,
2711 GDIPCONST GpPoint *dstpoints, INT count)
2715 TRACE("(%p, %p, %p, %d)\n", graphics, image, dstpoints, count);
2717 if (count != 3 || !dstpoints)
2718 return InvalidParameter;
2720 ptf[0].X = (REAL)dstpoints[0].X;
2721 ptf[0].Y = (REAL)dstpoints[0].Y;
2722 ptf[1].X = (REAL)dstpoints[1].X;
2723 ptf[1].Y = (REAL)dstpoints[1].Y;
2724 ptf[2].X = (REAL)dstpoints[2].X;
2725 ptf[2].Y = (REAL)dstpoints[2].Y;
2727 return GdipDrawImagePoints(graphics, image, ptf, count);
2730 GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
2731 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
2732 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
2733 DrawImageAbort callback, VOID * callbackData)
2740 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics, image, points,
2741 count, srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
2745 return NotImplemented;
2747 if(!graphics || !image || !points || count != 3)
2748 return InvalidParameter;
2750 TRACE("%s %s %s\n", debugstr_pointf(&points[0]), debugstr_pointf(&points[1]),
2751 debugstr_pointf(&points[2]));
2753 memcpy(ptf, points, 3 * sizeof(GpPointF));
2754 ptf[3].X = ptf[2].X + ptf[1].X - ptf[0].X;
2755 ptf[3].Y = ptf[2].Y + ptf[1].Y - ptf[0].Y;
2756 if (!srcwidth || !srcheight || ptf[3].X == ptf[0].X || ptf[3].Y == ptf[0].Y)
2758 transform_and_round_points(graphics, pti, ptf, 4);
2764 FIXME("graphics object has no HDC\n");
2767 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2768 if(srcUnit == UnitInch)
2769 dx = dy = (REAL) INCH_HIMETRIC;
2770 else if(srcUnit == UnitPixel){
2771 dx = ((REAL) INCH_HIMETRIC) /
2772 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
2773 dy = ((REAL) INCH_HIMETRIC) /
2774 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
2777 return NotImplemented;
2779 if(IPicture_Render(image->picture, graphics->hdc,
2780 pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
2781 srcx * dx, srcy * dy,
2782 srcwidth * dx, srcheight * dy,
2785 callback(callbackData);
2786 return GenericError;
2789 else if (image->type == ImageTypeBitmap)
2791 GpBitmap* bitmap = (GpBitmap*)image;
2794 if (srcUnit == UnitInch)
2795 dx = dy = 96.0; /* FIXME: use the image resolution */
2796 else if (srcUnit == UnitPixel)
2799 return NotImplemented;
2803 srcwidth = srcwidth * dx;
2804 srcheight = srcheight * dy;
2806 if (imageAttributes ||
2807 (graphics->image && graphics->image->type == ImageTypeBitmap) ||
2808 !((GpBitmap*)image)->hbitmap ||
2809 ptf[1].Y != ptf[0].Y || ptf[2].X != ptf[0].X ||
2810 ptf[1].X - ptf[0].X != srcwidth || ptf[2].Y - ptf[0].Y != srcheight ||
2811 srcx < 0 || srcy < 0 ||
2812 srcx + srcwidth > bitmap->width || srcy + srcheight > bitmap->height)
2819 int i, x, y, src_stride, dst_stride;
2820 GpMatrix *dst_to_src;
2821 REAL m11, m12, m21, m22, mdx, mdy;
2822 LPBYTE src_data, dst_data;
2823 BitmapData lockeddata;
2824 InterpolationMode interpolation = graphics->interpolation;
2825 GpPointF dst_to_src_points[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2826 REAL x_dx, x_dy, y_dx, y_dy;
2827 static const GpImageAttributes defaultImageAttributes = {WrapModeClamp, 0, FALSE};
2829 if (!imageAttributes)
2830 imageAttributes = &defaultImageAttributes;
2832 dst_area.left = dst_area.right = pti[0].x;
2833 dst_area.top = dst_area.bottom = pti[0].y;
2836 if (dst_area.left > pti[i].x) dst_area.left = pti[i].x;
2837 if (dst_area.right < pti[i].x) dst_area.right = pti[i].x;
2838 if (dst_area.top > pti[i].y) dst_area.top = pti[i].y;
2839 if (dst_area.bottom < pti[i].y) dst_area.bottom = pti[i].y;
2842 m11 = (ptf[1].X - ptf[0].X) / srcwidth;
2843 m21 = (ptf[2].X - ptf[0].X) / srcheight;
2844 mdx = ptf[0].X - m11 * srcx - m21 * srcy;
2845 m12 = (ptf[1].Y - ptf[0].Y) / srcwidth;
2846 m22 = (ptf[2].Y - ptf[0].Y) / srcheight;
2847 mdy = ptf[0].Y - m12 * srcx - m22 * srcy;
2849 stat = GdipCreateMatrix2(m11, m12, m21, m22, mdx, mdy, &dst_to_src);
2850 if (stat != Ok) return stat;
2852 stat = GdipInvertMatrix(dst_to_src);
2855 GdipDeleteMatrix(dst_to_src);
2859 dst_data = GdipAlloc(sizeof(ARGB) * (dst_area.right - dst_area.left) * (dst_area.bottom - dst_area.top));
2862 GdipDeleteMatrix(dst_to_src);
2866 dst_stride = sizeof(ARGB) * (dst_area.right - dst_area.left);
2868 get_bitmap_sample_size(interpolation, imageAttributes->wrap,
2869 bitmap, srcx, srcy, srcwidth, srcheight, &src_area);
2871 src_data = GdipAlloc(sizeof(ARGB) * src_area.Width * src_area.Height);
2875 GdipDeleteMatrix(dst_to_src);
2878 src_stride = sizeof(ARGB) * src_area.Width;
2880 /* Read the bits we need from the source bitmap into an ARGB buffer. */
2881 lockeddata.Width = src_area.Width;
2882 lockeddata.Height = src_area.Height;
2883 lockeddata.Stride = src_stride;
2884 lockeddata.PixelFormat = PixelFormat32bppARGB;
2885 lockeddata.Scan0 = src_data;
2887 stat = GdipBitmapLockBits(bitmap, &src_area, ImageLockModeRead|ImageLockModeUserInputBuf,
2888 PixelFormat32bppARGB, &lockeddata);
2891 stat = GdipBitmapUnlockBits(bitmap, &lockeddata);
2895 if (src_data != dst_data)
2898 GdipDeleteMatrix(dst_to_src);
2902 apply_image_attributes(imageAttributes, src_data,
2903 src_area.Width, src_area.Height,
2904 src_stride, ColorAdjustTypeBitmap);
2906 /* Transform the bits as needed to the destination. */
2907 GdipTransformMatrixPoints(dst_to_src, dst_to_src_points, 3);
2909 x_dx = dst_to_src_points[1].X - dst_to_src_points[0].X;
2910 x_dy = dst_to_src_points[1].Y - dst_to_src_points[0].Y;
2911 y_dx = dst_to_src_points[2].X - dst_to_src_points[0].X;
2912 y_dy = dst_to_src_points[2].Y - dst_to_src_points[0].Y;
2914 for (x=dst_area.left; x<dst_area.right; x++)
2916 for (y=dst_area.top; y<dst_area.bottom; y++)
2918 GpPointF src_pointf;
2921 src_pointf.X = dst_to_src_points[0].X + x * x_dx + y * y_dx;
2922 src_pointf.Y = dst_to_src_points[0].Y + x * x_dy + y * y_dy;
2924 dst_color = (ARGB*)(dst_data + dst_stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2926 if (src_pointf.X >= srcx && src_pointf.X < srcx + srcwidth && src_pointf.Y >= srcy && src_pointf.Y < srcy+srcheight)
2927 *dst_color = resample_bitmap_pixel(&src_area, src_data, bitmap->width, bitmap->height, &src_pointf, imageAttributes, interpolation);
2933 GdipDeleteMatrix(dst_to_src);
2937 stat = alpha_blend_pixels(graphics, dst_area.left, dst_area.top,
2938 dst_data, dst_area.right - dst_area.left, dst_area.bottom - dst_area.top, dst_stride);
2947 int temp_hdc=0, temp_bitmap=0;
2948 HBITMAP hbitmap, old_hbm=NULL;
2950 if (!(bitmap->format == PixelFormat16bppRGB555 ||
2951 bitmap->format == PixelFormat24bppRGB ||
2952 bitmap->format == PixelFormat32bppRGB ||
2953 bitmap->format == PixelFormat32bppPARGB))
2955 BITMAPINFOHEADER bih;
2957 PixelFormat dst_format;
2959 /* we can't draw a bitmap of this format directly */
2960 hdc = CreateCompatibleDC(0);
2964 bih.biSize = sizeof(BITMAPINFOHEADER);
2965 bih.biWidth = bitmap->width;
2966 bih.biHeight = -bitmap->height;
2968 bih.biBitCount = 32;
2969 bih.biCompression = BI_RGB;
2970 bih.biSizeImage = 0;
2971 bih.biXPelsPerMeter = 0;
2972 bih.biYPelsPerMeter = 0;
2974 bih.biClrImportant = 0;
2976 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
2977 (void**)&temp_bits, NULL, 0);
2979 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
2980 dst_format = PixelFormat32bppPARGB;
2982 dst_format = PixelFormat32bppRGB;
2984 convert_pixels(bitmap->width, bitmap->height,
2985 bitmap->width*4, temp_bits, dst_format,
2986 bitmap->stride, bitmap->bits, bitmap->format, bitmap->image.palette_entries);
2990 hbitmap = bitmap->hbitmap;
2992 temp_hdc = (hdc == 0);
2997 if (!hdc) hdc = CreateCompatibleDC(0);
2998 old_hbm = SelectObject(hdc, hbitmap);
3001 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
3005 bf.BlendOp = AC_SRC_OVER;
3007 bf.SourceConstantAlpha = 255;
3008 bf.AlphaFormat = AC_SRC_ALPHA;
3010 GdiAlphaBlend(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
3011 hdc, srcx, srcy, srcwidth, srcheight, bf);
3015 StretchBlt(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
3016 hdc, srcx, srcy, srcwidth, srcheight, SRCCOPY);
3021 SelectObject(hdc, old_hbm);
3026 DeleteObject(hbitmap);
3031 ERR("GpImage with no IPicture or HBITMAP?!\n");
3032 return NotImplemented;
3038 GpStatus WINGDIPAPI GdipDrawImagePointsRectI(GpGraphics *graphics, GpImage *image,
3039 GDIPCONST GpPoint *points, INT count, INT srcx, INT srcy, INT srcwidth,
3040 INT srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
3041 DrawImageAbort callback, VOID * callbackData)
3043 GpPointF pointsF[3];
3046 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics, image, points, count,
3047 srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
3050 if(!points || count!=3)
3051 return InvalidParameter;
3053 for(i = 0; i < count; i++){
3054 pointsF[i].X = (REAL)points[i].X;
3055 pointsF[i].Y = (REAL)points[i].Y;
3058 return GdipDrawImagePointsRect(graphics, image, pointsF, count, (REAL)srcx, (REAL)srcy,
3059 (REAL)srcwidth, (REAL)srcheight, srcUnit, imageAttributes,
3060 callback, callbackData);
3063 GpStatus WINGDIPAPI GdipDrawImageRectRect(GpGraphics *graphics, GpImage *image,
3064 REAL dstx, REAL dsty, REAL dstwidth, REAL dstheight, REAL srcx, REAL srcy,
3065 REAL srcwidth, REAL srcheight, GpUnit srcUnit,
3066 GDIPCONST GpImageAttributes* imageattr, DrawImageAbort callback,
3067 VOID * callbackData)
3071 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3072 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
3073 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
3077 points[1].X = dstx + dstwidth;
3080 points[2].Y = dsty + dstheight;
3082 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
3083 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
3086 GpStatus WINGDIPAPI GdipDrawImageRectRectI(GpGraphics *graphics, GpImage *image,
3087 INT dstx, INT dsty, INT dstwidth, INT dstheight, INT srcx, INT srcy,
3088 INT srcwidth, INT srcheight, GpUnit srcUnit,
3089 GDIPCONST GpImageAttributes* imageAttributes, DrawImageAbort callback,
3090 VOID * callbackData)
3094 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3095 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
3096 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
3100 points[1].X = dstx + dstwidth;
3103 points[2].Y = dsty + dstheight;
3105 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
3106 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
3109 GpStatus WINGDIPAPI GdipDrawImageRect(GpGraphics *graphics, GpImage *image,
3110 REAL x, REAL y, REAL width, REAL height)
3116 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, image, x, y, width, height);
3118 if(!graphics || !image)
3119 return InvalidParameter;
3121 ret = GdipGetImageBounds(image, &bounds, &unit);
3125 return GdipDrawImageRectRect(graphics, image, x, y, width, height,
3126 bounds.X, bounds.Y, bounds.Width, bounds.Height,
3127 unit, NULL, NULL, NULL);
3130 GpStatus WINGDIPAPI GdipDrawImageRectI(GpGraphics *graphics, GpImage *image,
3131 INT x, INT y, INT width, INT height)
3133 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, image, x, y, width, height);
3135 return GdipDrawImageRect(graphics, image, (REAL)x, (REAL)y, (REAL)width, (REAL)height);
3138 GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1,
3139 REAL y1, REAL x2, REAL y2)
3145 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1, x2, y2);
3147 if(!pen || !graphics)
3148 return InvalidParameter;
3155 FIXME("graphics object has no HDC\n");
3164 save_state = prepare_dc(graphics, pen);
3166 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
3168 restore_dc(graphics, save_state);
3173 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
3174 INT y1, INT x2, INT y2)
3180 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x1, y1, x2, y2);
3182 if(!pen || !graphics)
3183 return InvalidParameter;
3190 FIXME("graphics object has no HDC\n");
3199 save_state = prepare_dc(graphics, pen);
3201 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
3203 restore_dc(graphics, save_state);
3208 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
3209 GpPointF *points, INT count)
3214 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
3216 if(!pen || !graphics || (count < 2))
3217 return InvalidParameter;
3224 FIXME("graphics object has no HDC\n");
3228 save_state = prepare_dc(graphics, pen);
3230 retval = draw_polyline(graphics, pen, points, count, TRUE);
3232 restore_dc(graphics, save_state);
3237 GpStatus WINGDIPAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, GDIPCONST
3238 GpPoint *points, INT count)
3242 GpPointF *ptf = NULL;
3245 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
3247 if(!pen || !graphics || (count < 2))
3248 return InvalidParameter;
3255 FIXME("graphics object has no HDC\n");
3259 ptf = GdipAlloc(count * sizeof(GpPointF));
3260 if(!ptf) return OutOfMemory;
3262 for(i = 0; i < count; i ++){
3263 ptf[i].X = (REAL) points[i].X;
3264 ptf[i].Y = (REAL) points[i].Y;
3267 save_state = prepare_dc(graphics, pen);
3269 retval = draw_polyline(graphics, pen, ptf, count, TRUE);
3271 restore_dc(graphics, save_state);
3277 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
3282 TRACE("(%p, %p, %p)\n", graphics, pen, path);
3284 if(!pen || !graphics)
3285 return InvalidParameter;
3292 FIXME("graphics object has no HDC\n");
3296 save_state = prepare_dc(graphics, pen);
3298 retval = draw_poly(graphics, pen, path->pathdata.Points,
3299 path->pathdata.Types, path->pathdata.Count, TRUE);
3301 restore_dc(graphics, save_state);
3306 GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
3307 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
3311 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
3312 width, height, startAngle, sweepAngle);
3314 if(!graphics || !pen)
3315 return InvalidParameter;
3322 FIXME("graphics object has no HDC\n");
3326 save_state = prepare_dc(graphics, pen);
3327 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
3329 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
3331 restore_dc(graphics, save_state);
3336 GpStatus WINGDIPAPI GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x,
3337 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
3339 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
3340 width, height, startAngle, sweepAngle);
3342 return GdipDrawPie(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
3345 GpStatus WINGDIPAPI GdipDrawRectangle(GpGraphics *graphics, GpPen *pen, REAL x,
3346 REAL y, REAL width, REAL height)
3352 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
3354 if(!pen || !graphics)
3355 return InvalidParameter;
3362 FIXME("graphics object has no HDC\n");
3368 ptf[1].X = x + width;
3370 ptf[2].X = x + width;
3371 ptf[2].Y = y + height;
3373 ptf[3].Y = y + height;
3375 save_state = prepare_dc(graphics, pen);
3376 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
3378 transform_and_round_points(graphics, pti, ptf, 4);
3379 Polygon(graphics->hdc, pti, 4);
3381 restore_dc(graphics, save_state);
3386 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
3387 INT y, INT width, INT height)
3389 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
3391 return GdipDrawRectangle(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
3394 GpStatus WINGDIPAPI GdipDrawRectangles(GpGraphics *graphics, GpPen *pen,
3395 GDIPCONST GpRectF* rects, INT count)
3401 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
3403 if(!graphics || !pen || !rects || count < 1)
3404 return InvalidParameter;
3411 FIXME("graphics object has no HDC\n");
3415 ptf = GdipAlloc(4 * count * sizeof(GpPointF));
3416 pti = GdipAlloc(4 * count * sizeof(POINT));
3424 for(i = 0; i < count; i++){
3425 ptf[4 * i + 3].X = ptf[4 * i].X = rects[i].X;
3426 ptf[4 * i + 1].Y = ptf[4 * i].Y = rects[i].Y;
3427 ptf[4 * i + 2].X = ptf[4 * i + 1].X = rects[i].X + rects[i].Width;
3428 ptf[4 * i + 3].Y = ptf[4 * i + 2].Y = rects[i].Y + rects[i].Height;
3431 save_state = prepare_dc(graphics, pen);
3432 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
3434 transform_and_round_points(graphics, pti, ptf, 4 * count);
3436 for(i = 0; i < count; i++)
3437 Polygon(graphics->hdc, &pti[4 * i], 4);
3439 restore_dc(graphics, save_state);
3447 GpStatus WINGDIPAPI GdipDrawRectanglesI(GpGraphics *graphics, GpPen *pen,
3448 GDIPCONST GpRect* rects, INT count)
3454 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
3456 if(!rects || count<=0)
3457 return InvalidParameter;
3459 rectsF = GdipAlloc(sizeof(GpRectF) * count);
3463 for(i = 0;i < count;i++){
3464 rectsF[i].X = (REAL)rects[i].X;
3465 rectsF[i].Y = (REAL)rects[i].Y;
3466 rectsF[i].Width = (REAL)rects[i].Width;
3467 rectsF[i].Height = (REAL)rects[i].Height;
3470 ret = GdipDrawRectangles(graphics, pen, rectsF, count);
3476 GpStatus WINGDIPAPI GdipFillClosedCurve2(GpGraphics *graphics, GpBrush *brush,
3477 GDIPCONST GpPointF *points, INT count, REAL tension, GpFillMode fill)
3482 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
3483 count, tension, fill);
3485 if(!graphics || !brush || !points)
3486 return InvalidParameter;
3491 if(count == 1) /* Do nothing */
3494 stat = GdipCreatePath(fill, &path);
3498 stat = GdipAddPathClosedCurve2(path, points, count, tension);
3500 GdipDeletePath(path);
3504 stat = GdipFillPath(graphics, brush, path);
3506 GdipDeletePath(path);
3510 GdipDeletePath(path);
3515 GpStatus WINGDIPAPI GdipFillClosedCurve2I(GpGraphics *graphics, GpBrush *brush,
3516 GDIPCONST GpPoint *points, INT count, REAL tension, GpFillMode fill)
3522 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
3523 count, tension, fill);
3525 if(!points || count == 0)
3526 return InvalidParameter;
3528 if(count == 1) /* Do nothing */
3531 ptf = GdipAlloc(sizeof(GpPointF)*count);
3535 for(i = 0;i < count;i++){
3536 ptf[i].X = (REAL)points[i].X;
3537 ptf[i].Y = (REAL)points[i].Y;
3540 stat = GdipFillClosedCurve2(graphics, brush, ptf, count, tension, fill);
3547 GpStatus WINGDIPAPI GdipFillClosedCurve(GpGraphics *graphics, GpBrush *brush,
3548 GDIPCONST GpPointF *points, INT count)
3550 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3551 return GdipFillClosedCurve2(graphics, brush, points, count,
3552 0.5f, FillModeAlternate);
3555 GpStatus WINGDIPAPI GdipFillClosedCurveI(GpGraphics *graphics, GpBrush *brush,
3556 GDIPCONST GpPoint *points, INT count)
3558 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3559 return GdipFillClosedCurve2I(graphics, brush, points, count,
3560 0.5f, FillModeAlternate);
3563 GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x,
3564 REAL y, REAL width, REAL height)
3569 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
3571 if(!graphics || !brush)
3572 return InvalidParameter;
3577 stat = GdipCreatePath(FillModeAlternate, &path);
3581 stat = GdipAddPathEllipse(path, x, y, width, height);
3584 stat = GdipFillPath(graphics, brush, path);
3586 GdipDeletePath(path);
3592 GpStatus WINGDIPAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x,
3593 INT y, INT width, INT height)
3595 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
3597 return GdipFillEllipse(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
3600 static GpStatus GDI32_GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
3605 if(!graphics->hdc || !brush_can_fill_path(brush))
3606 return NotImplemented;
3608 save_state = SaveDC(graphics->hdc);
3609 EndPath(graphics->hdc);
3610 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
3613 BeginPath(graphics->hdc);
3614 retval = draw_poly(graphics, NULL, path->pathdata.Points,
3615 path->pathdata.Types, path->pathdata.Count, FALSE);
3620 EndPath(graphics->hdc);
3621 brush_fill_path(graphics, brush);
3626 RestoreDC(graphics->hdc, save_state);
3631 static GpStatus SOFTWARE_GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
3636 if (!brush_can_fill_pixels(brush))
3637 return NotImplemented;
3639 /* FIXME: This could probably be done more efficiently without regions. */
3641 stat = GdipCreateRegionPath(path, &rgn);
3645 stat = GdipFillRegion(graphics, brush, rgn);
3647 GdipDeleteRegion(rgn);
3653 GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
3655 GpStatus stat = NotImplemented;
3657 TRACE("(%p, %p, %p)\n", graphics, brush, path);
3659 if(!brush || !graphics || !path)
3660 return InvalidParameter;
3665 if (!graphics->image)
3666 stat = GDI32_GdipFillPath(graphics, brush, path);
3668 if (stat == NotImplemented)
3669 stat = SOFTWARE_GdipFillPath(graphics, brush, path);
3671 if (stat == NotImplemented)
3673 FIXME("Not implemented for brushtype %i\n", brush->bt);
3680 GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
3681 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
3686 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3687 graphics, brush, x, y, width, height, startAngle, sweepAngle);
3689 if(!graphics || !brush)
3690 return InvalidParameter;
3695 stat = GdipCreatePath(FillModeAlternate, &path);
3699 stat = GdipAddPathPie(path, x, y, width, height, startAngle, sweepAngle);
3702 stat = GdipFillPath(graphics, brush, path);
3704 GdipDeletePath(path);
3710 GpStatus WINGDIPAPI GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x,
3711 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
3713 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3714 graphics, brush, x, y, width, height, startAngle, sweepAngle);
3716 return GdipFillPie(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
3719 GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush,
3720 GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)
3725 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
3727 if(!graphics || !brush || !points || !count)
3728 return InvalidParameter;
3733 stat = GdipCreatePath(fillMode, &path);
3737 stat = GdipAddPathPolygon(path, points, count);
3740 stat = GdipFillPath(graphics, brush, path);
3742 GdipDeletePath(path);
3748 GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
3749 GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
3754 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
3756 if(!graphics || !brush || !points || !count)
3757 return InvalidParameter;
3762 stat = GdipCreatePath(fillMode, &path);
3766 stat = GdipAddPathPolygonI(path, points, count);
3769 stat = GdipFillPath(graphics, brush, path);
3771 GdipDeletePath(path);
3777 GpStatus WINGDIPAPI GdipFillPolygon2(GpGraphics *graphics, GpBrush *brush,
3778 GDIPCONST GpPointF *points, INT count)
3780 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3782 return GdipFillPolygon(graphics, brush, points, count, FillModeAlternate);
3785 GpStatus WINGDIPAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush,
3786 GDIPCONST GpPoint *points, INT count)
3788 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3790 return GdipFillPolygonI(graphics, brush, points, count, FillModeAlternate);
3793 GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics *graphics, GpBrush *brush,
3794 REAL x, REAL y, REAL width, REAL height)
3799 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
3801 if(!graphics || !brush)
3802 return InvalidParameter;
3807 stat = GdipCreatePath(FillModeAlternate, &path);
3811 stat = GdipAddPathRectangle(path, x, y, width, height);
3814 stat = GdipFillPath(graphics, brush, path);
3816 GdipDeletePath(path);
3822 GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush,
3823 INT x, INT y, INT width, INT height)
3825 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
3827 return GdipFillRectangle(graphics, brush, x, y, width, height);
3830 GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRectF *rects,
3836 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3839 return InvalidParameter;
3841 for(i = 0; i < count; i++){
3842 ret = GdipFillRectangle(graphics, brush, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
3843 if(ret != Ok) return ret;
3849 GpStatus WINGDIPAPI GdipFillRectanglesI(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRect *rects,
3856 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3858 if(!rects || count <= 0)
3859 return InvalidParameter;
3861 rectsF = GdipAlloc(sizeof(GpRectF)*count);
3865 for(i = 0; i < count; i++){
3866 rectsF[i].X = (REAL)rects[i].X;
3867 rectsF[i].Y = (REAL)rects[i].Y;
3868 rectsF[i].X = (REAL)rects[i].Width;
3869 rectsF[i].Height = (REAL)rects[i].Height;
3872 ret = GdipFillRectangles(graphics,brush,rectsF,count);
3878 static GpStatus GDI32_GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
3886 if(!graphics->hdc || !brush_can_fill_path(brush))
3887 return NotImplemented;
3889 status = GdipGetRegionHRgn(region, graphics, &hrgn);
3893 save_state = SaveDC(graphics->hdc);
3894 EndPath(graphics->hdc);
3896 ExtSelectClipRgn(graphics->hdc, hrgn, RGN_AND);
3898 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
3900 BeginPath(graphics->hdc);
3901 Rectangle(graphics->hdc, rc.left, rc.top, rc.right, rc.bottom);
3902 EndPath(graphics->hdc);
3904 brush_fill_path(graphics, brush);
3907 RestoreDC(graphics->hdc, save_state);
3914 static GpStatus SOFTWARE_GdipFillRegion(GpGraphics *graphics, GpBrush *brush,
3918 GpRegion *temp_region;
3919 GpMatrix *world_to_device, *identity;
3920 GpRectF graphics_bounds;
3921 UINT scans_count, i;
3923 GpRect *scans = NULL;
3926 if (!brush_can_fill_pixels(brush))
3927 return NotImplemented;
3929 stat = get_graphics_bounds(graphics, &graphics_bounds);
3932 stat = GdipCloneRegion(region, &temp_region);
3936 stat = get_graphics_transform(graphics, CoordinateSpaceDevice,
3937 CoordinateSpaceWorld, &world_to_device);
3941 stat = GdipTransformRegion(temp_region, world_to_device);
3943 GdipDeleteMatrix(world_to_device);
3947 stat = GdipCombineRegionRect(temp_region, &graphics_bounds, CombineModeIntersect);
3950 stat = GdipCreateMatrix(&identity);
3954 stat = GdipGetRegionScansCount(temp_region, &scans_count, identity);
3956 if (stat == Ok && scans_count != 0)
3958 scans = GdipAlloc(sizeof(*scans) * scans_count);
3964 stat = GdipGetRegionScansI(temp_region, scans, &dummy, identity);
3971 GdipDeleteMatrix(identity);
3974 GdipDeleteRegion(temp_region);
3977 if (stat == Ok && scans_count == 0)
3982 if (!graphics->image)
3984 /* If we have to go through gdi32, use as few alpha blends as possible. */
3985 INT min_x, min_y, max_x, max_y;
3986 UINT data_width, data_height;
3990 max_x = scans[0].X+scans[0].Width;
3991 max_y = scans[0].Y+scans[0].Height;
3993 for (i=1; i<scans_count; i++)
3995 min_x = min(min_x, scans[i].X);
3996 min_y = min(min_y, scans[i].Y);
3997 max_x = max(max_x, scans[i].X+scans[i].Width);
3998 max_y = max(max_y, scans[i].Y+scans[i].Height);
4001 data_width = max_x - min_x;
4002 data_height = max_y - min_y;
4004 pixel_data = GdipAlloc(sizeof(*pixel_data) * data_width * data_height);
4010 for (i=0; i<scans_count; i++)
4012 stat = brush_fill_pixels(graphics, brush,
4013 pixel_data + (scans[i].X - min_x) + (scans[i].Y - min_y) * data_width,
4014 &scans[i], data_width);
4022 stat = alpha_blend_pixels(graphics, min_x, min_y,
4023 (BYTE*)pixel_data, data_width, data_height,
4027 GdipFree(pixel_data);
4034 for (i=0; i<scans_count; i++)
4036 UINT size = scans[i].Width * scans[i].Height;
4038 if (size > max_size)
4042 pixel_data = GdipAlloc(sizeof(*pixel_data) * max_size);
4048 for (i=0; i<scans_count; i++)
4050 stat = brush_fill_pixels(graphics, brush, pixel_data, &scans[i],
4055 stat = alpha_blend_pixels(graphics, scans[i].X, scans[i].Y,
4056 (BYTE*)pixel_data, scans[i].Width, scans[i].Height,
4057 scans[i].Width * 4);
4064 GdipFree(pixel_data);
4074 /*****************************************************************************
4075 * GdipFillRegion [GDIPLUS.@]
4077 GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
4080 GpStatus stat = NotImplemented;
4082 TRACE("(%p, %p, %p)\n", graphics, brush, region);
4084 if (!(graphics && brush && region))
4085 return InvalidParameter;
4090 if (!graphics->image)
4091 stat = GDI32_GdipFillRegion(graphics, brush, region);
4093 if (stat == NotImplemented)
4094 stat = SOFTWARE_GdipFillRegion(graphics, brush, region);
4096 if (stat == NotImplemented)
4098 FIXME("not implemented for brushtype %i\n", brush->bt);
4105 GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention)
4107 TRACE("(%p,%u)\n", graphics, intention);
4110 return InvalidParameter;
4115 /* We have no internal operation queue, so there's no need to clear it. */
4123 /*****************************************************************************
4124 * GdipGetClipBounds [GDIPLUS.@]
4126 GpStatus WINGDIPAPI GdipGetClipBounds(GpGraphics *graphics, GpRectF *rect)
4128 TRACE("(%p, %p)\n", graphics, rect);
4131 return InvalidParameter;
4136 return GdipGetRegionBounds(graphics->clip, graphics, rect);
4139 /*****************************************************************************
4140 * GdipGetClipBoundsI [GDIPLUS.@]
4142 GpStatus WINGDIPAPI GdipGetClipBoundsI(GpGraphics *graphics, GpRect *rect)
4144 TRACE("(%p, %p)\n", graphics, rect);
4147 return InvalidParameter;
4152 return GdipGetRegionBoundsI(graphics->clip, graphics, rect);
4155 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4156 GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics,
4157 CompositingMode *mode)
4159 TRACE("(%p, %p)\n", graphics, mode);
4161 if(!graphics || !mode)
4162 return InvalidParameter;
4167 *mode = graphics->compmode;
4172 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4173 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
4174 CompositingQuality *quality)
4176 TRACE("(%p, %p)\n", graphics, quality);
4178 if(!graphics || !quality)
4179 return InvalidParameter;
4184 *quality = graphics->compqual;
4189 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4190 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
4191 InterpolationMode *mode)
4193 TRACE("(%p, %p)\n", graphics, mode);
4195 if(!graphics || !mode)
4196 return InvalidParameter;
4201 *mode = graphics->interpolation;
4206 /* FIXME: Need to handle color depths less than 24bpp */
4207 GpStatus WINGDIPAPI GdipGetNearestColor(GpGraphics *graphics, ARGB* argb)
4209 FIXME("(%p, %p): Passing color unmodified\n", graphics, argb);
4211 if(!graphics || !argb)
4212 return InvalidParameter;
4220 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
4222 TRACE("(%p, %p)\n", graphics, scale);
4224 if(!graphics || !scale)
4225 return InvalidParameter;
4230 *scale = graphics->scale;
4235 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
4237 TRACE("(%p, %p)\n", graphics, unit);
4239 if(!graphics || !unit)
4240 return InvalidParameter;
4245 *unit = graphics->unit;
4250 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4251 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
4254 TRACE("(%p, %p)\n", graphics, mode);
4256 if(!graphics || !mode)
4257 return InvalidParameter;
4262 *mode = graphics->pixeloffset;
4267 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4268 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
4270 TRACE("(%p, %p)\n", graphics, mode);
4272 if(!graphics || !mode)
4273 return InvalidParameter;
4278 *mode = graphics->smoothing;
4283 GpStatus WINGDIPAPI GdipGetTextContrast(GpGraphics *graphics, UINT *contrast)
4285 TRACE("(%p, %p)\n", graphics, contrast);
4287 if(!graphics || !contrast)
4288 return InvalidParameter;
4290 *contrast = graphics->textcontrast;
4295 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4296 GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics,
4297 TextRenderingHint *hint)
4299 TRACE("(%p, %p)\n", graphics, hint);
4301 if(!graphics || !hint)
4302 return InvalidParameter;
4307 *hint = graphics->texthint;
4312 GpStatus WINGDIPAPI GdipGetVisibleClipBounds(GpGraphics *graphics, GpRectF *rect)
4317 TRACE("(%p, %p)\n", graphics, rect);
4319 if(!graphics || !rect)
4320 return InvalidParameter;
4325 /* intersect window and graphics clipping regions */
4326 if((stat = GdipCreateRegion(&clip_rgn)) != Ok)
4329 if((stat = get_visible_clip_region(graphics, clip_rgn)) != Ok)
4332 /* get bounds of the region */
4333 stat = GdipGetRegionBounds(clip_rgn, graphics, rect);
4336 GdipDeleteRegion(clip_rgn);
4341 GpStatus WINGDIPAPI GdipGetVisibleClipBoundsI(GpGraphics *graphics, GpRect *rect)
4346 TRACE("(%p, %p)\n", graphics, rect);
4348 if(!graphics || !rect)
4349 return InvalidParameter;
4351 if((stat = GdipGetVisibleClipBounds(graphics, &rectf)) == Ok)
4353 rect->X = roundr(rectf.X);
4354 rect->Y = roundr(rectf.Y);
4355 rect->Width = roundr(rectf.Width);
4356 rect->Height = roundr(rectf.Height);
4362 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
4364 TRACE("(%p, %p)\n", graphics, matrix);
4366 if(!graphics || !matrix)
4367 return InvalidParameter;
4372 *matrix = *graphics->worldtrans;
4376 GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color)
4382 TRACE("(%p, %x)\n", graphics, color);
4385 return InvalidParameter;
4390 if((stat = GdipCreateSolidFill(color, &brush)) != Ok)
4393 if((stat = get_graphics_bounds(graphics, &wnd_rect)) != Ok){
4394 GdipDeleteBrush((GpBrush*)brush);
4398 GdipFillRectangle(graphics, (GpBrush*)brush, wnd_rect.X, wnd_rect.Y,
4399 wnd_rect.Width, wnd_rect.Height);
4401 GdipDeleteBrush((GpBrush*)brush);
4406 GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics *graphics, BOOL *res)
4408 TRACE("(%p, %p)\n", graphics, res);
4410 if(!graphics || !res)
4411 return InvalidParameter;
4413 return GdipIsEmptyRegion(graphics->clip, graphics, res);
4416 GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics *graphics, REAL x, REAL y, BOOL *result)
4422 TRACE("(%p, %.2f, %.2f, %p)\n", graphics, x, y, result);
4424 if(!graphics || !result)
4425 return InvalidParameter;
4432 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
4433 CoordinateSpaceWorld, &pt, 1)) != Ok)
4436 if((stat = GdipCreateRegion(&rgn)) != Ok)
4439 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
4442 stat = GdipIsVisibleRegionPoint(rgn, pt.X, pt.Y, graphics, result);
4445 GdipDeleteRegion(rgn);
4449 GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics *graphics, INT x, INT y, BOOL *result)
4451 return GdipIsVisiblePoint(graphics, (REAL)x, (REAL)y, result);
4454 GpStatus WINGDIPAPI GdipIsVisibleRect(GpGraphics *graphics, REAL x, REAL y, REAL width, REAL height, BOOL *result)
4460 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics, x, y, width, height, result);
4462 if(!graphics || !result)
4463 return InvalidParameter;
4470 pts[1].X = x + width;
4471 pts[1].Y = y + height;
4473 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
4474 CoordinateSpaceWorld, pts, 2)) != Ok)
4477 pts[1].X -= pts[0].X;
4478 pts[1].Y -= pts[0].Y;
4480 if((stat = GdipCreateRegion(&rgn)) != Ok)
4483 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
4486 stat = GdipIsVisibleRegionRect(rgn, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y, graphics, result);
4489 GdipDeleteRegion(rgn);
4493 GpStatus WINGDIPAPI GdipIsVisibleRectI(GpGraphics *graphics, INT x, INT y, INT width, INT height, BOOL *result)
4495 return GdipIsVisibleRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, result);
4498 GpStatus gdip_format_string(HDC hdc,
4499 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
4500 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4501 gdip_format_string_callback callback, void *user_data)
4504 int sum = 0, height = 0, fit, fitcpy, i, j, lret, nwidth,
4505 nheight, lineend, lineno = 0;
4507 StringAlignment halign;
4511 if(length == -1) length = lstrlenW(string);
4513 stringdup = GdipAlloc((length + 1) * sizeof(WCHAR));
4514 if(!stringdup) return OutOfMemory;
4516 nwidth = roundr(rect->Width);
4517 nheight = roundr(rect->Height);
4519 if (rect->Width >= INT_MAX || rect->Width < 0.5) nwidth = INT_MAX;
4520 if (rect->Height >= INT_MAX || rect->Height < 0.5) nheight = INT_MAX;
4522 for(i = 0, j = 0; i < length; i++){
4523 /* FIXME: This makes the indexes passed to callback inaccurate. */
4524 if(!isprintW(string[i]) && (string[i] != '\n'))
4527 stringdup[j] = string[i];
4533 if (format) halign = format->align;
4534 else halign = StringAlignmentNear;
4536 while(sum < length){
4537 GetTextExtentExPointW(hdc, stringdup + sum, length - sum,
4538 nwidth, &fit, NULL, &size);
4544 for(lret = 0; lret < fit; lret++)
4545 if(*(stringdup + sum + lret) == '\n')
4548 /* Line break code (may look strange, but it imitates windows). */
4550 lineend = fit = lret; /* this is not an off-by-one error */
4551 else if(fit < (length - sum)){
4552 if(*(stringdup + sum + fit) == ' ')
4553 while(*(stringdup + sum + fit) == ' ')
4556 while(*(stringdup + sum + fit - 1) != ' '){
4559 if(*(stringdup + sum + fit) == '\t')
4568 while(*(stringdup + sum + lineend - 1) == ' ' ||
4569 *(stringdup + sum + lineend - 1) == '\t')
4575 GetTextExtentExPointW(hdc, stringdup + sum, lineend,
4576 nwidth, &j, NULL, &size);
4578 bounds.Width = size.cx;
4580 if(height + size.cy > nheight)
4581 bounds.Height = nheight - (height + size.cy);
4583 bounds.Height = size.cy;
4585 bounds.Y = rect->Y + height;
4589 case StringAlignmentNear:
4593 case StringAlignmentCenter:
4594 bounds.X = rect->X + (rect->Width/2) - (bounds.Width/2);
4596 case StringAlignmentFar:
4597 bounds.X = rect->X + rect->Width - bounds.Width;
4601 stat = callback(hdc, stringdup, sum, lineend,
4602 font, rect, format, lineno, &bounds, user_data);
4607 sum += fit + (lret < fitcpy ? 1 : 0);
4611 if(height > nheight)
4614 /* Stop if this was a linewrap (but not if it was a linebreak). */
4615 if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
4619 GdipFree(stringdup);
4624 struct measure_ranges_args {
4628 static GpStatus measure_ranges_callback(HDC hdc,
4629 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4630 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4631 INT lineno, const RectF *bounds, void *user_data)
4635 struct measure_ranges_args *args = user_data;
4637 for (i=0; i<format->range_count; i++)
4639 INT range_start = max(index, format->character_ranges[i].First);
4640 INT range_end = min(index+length, format->character_ranges[i].First+format->character_ranges[i].Length);
4641 if (range_start < range_end)
4646 range_rect.Y = bounds->Y;
4647 range_rect.Height = bounds->Height;
4649 GetTextExtentExPointW(hdc, string + index, range_start - index,
4650 INT_MAX, NULL, NULL, &range_size);
4651 range_rect.X = bounds->X + range_size.cx;
4653 GetTextExtentExPointW(hdc, string + index, range_end - index,
4654 INT_MAX, NULL, NULL, &range_size);
4655 range_rect.Width = (bounds->X + range_size.cx) - range_rect.X;
4657 stat = GdipCombineRegionRect(args->regions[i], &range_rect, CombineModeUnion);
4666 GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,
4667 GDIPCONST WCHAR* string, INT length, GDIPCONST GpFont* font,
4668 GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat *stringFormat,
4669 INT regionCount, GpRegion** regions)
4674 struct measure_ranges_args args;
4675 HDC hdc, temp_hdc=NULL;
4677 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics, debugstr_w(string),
4678 length, font, debugstr_rectf(layoutRect), stringFormat, regionCount, regions);
4680 if (!(graphics && string && font && layoutRect && stringFormat && regions))
4681 return InvalidParameter;
4683 if (regionCount < stringFormat->range_count)
4684 return InvalidParameter;
4688 hdc = temp_hdc = CreateCompatibleDC(0);
4689 if (!temp_hdc) return OutOfMemory;
4692 hdc = graphics->hdc;
4694 if (stringFormat->attr)
4695 TRACE("may be ignoring some format flags: attr %x\n", stringFormat->attr);
4697 oldfont = SelectObject(hdc, CreateFontIndirectW(&font->lfw));
4699 for (i=0; i<stringFormat->range_count; i++)
4701 stat = GdipSetEmpty(regions[i]);
4706 args.regions = regions;
4708 stat = gdip_format_string(hdc, string, length, font, layoutRect, stringFormat,
4709 measure_ranges_callback, &args);
4711 DeleteObject(SelectObject(hdc, oldfont));
4719 struct measure_string_args {
4721 INT *codepointsfitted;
4725 static GpStatus measure_string_callback(HDC hdc,
4726 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4727 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4728 INT lineno, const RectF *bounds, void *user_data)
4730 struct measure_string_args *args = user_data;
4732 if (bounds->Width > args->bounds->Width)
4733 args->bounds->Width = bounds->Width;
4735 if (bounds->Height + bounds->Y > args->bounds->Height + args->bounds->Y)
4736 args->bounds->Height = bounds->Height + bounds->Y - args->bounds->Y;
4738 if (args->codepointsfitted)
4739 *args->codepointsfitted = index + length;
4741 if (args->linesfilled)
4742 (*args->linesfilled)++;
4747 /* Find the smallest rectangle that bounds the text when it is printed in rect
4748 * according to the format options listed in format. If rect has 0 width and
4749 * height, then just find the smallest rectangle that bounds the text when it's
4750 * printed at location (rect->X, rect-Y). */
4751 GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
4752 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
4753 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
4754 INT *codepointsfitted, INT *linesfilled)
4757 struct measure_string_args args;
4758 HDC temp_hdc=NULL, hdc;
4760 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics,
4761 debugstr_wn(string, length), length, font, debugstr_rectf(rect), format,
4762 bounds, codepointsfitted, linesfilled);
4764 if(!graphics || !string || !font || !rect || !bounds)
4765 return InvalidParameter;
4769 hdc = temp_hdc = CreateCompatibleDC(0);
4770 if (!temp_hdc) return OutOfMemory;
4773 hdc = graphics->hdc;
4775 if(linesfilled) *linesfilled = 0;
4776 if(codepointsfitted) *codepointsfitted = 0;
4779 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4781 oldfont = SelectObject(hdc, CreateFontIndirectW(&font->lfw));
4783 bounds->X = rect->X;
4784 bounds->Y = rect->Y;
4785 bounds->Width = 0.0;
4786 bounds->Height = 0.0;
4788 args.bounds = bounds;
4789 args.codepointsfitted = codepointsfitted;
4790 args.linesfilled = linesfilled;
4792 gdip_format_string(hdc, string, length, font, rect, format,
4793 measure_string_callback, &args);
4795 DeleteObject(SelectObject(hdc, oldfont));
4803 struct draw_string_args {
4804 GpGraphics *graphics;
4805 GDIPCONST GpBrush *brush;
4806 REAL x, y, rel_width, rel_height, ascent;
4809 static GpStatus draw_string_callback(HDC hdc,
4810 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4811 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4812 INT lineno, const RectF *bounds, void *user_data)
4814 struct draw_string_args *args = user_data;
4817 position.X = args->x + bounds->X / args->rel_width;
4818 position.Y = args->y + bounds->Y / args->rel_height + args->ascent;
4820 return GdipDrawDriverString(args->graphics, &string[index], length, font,
4821 args->brush, &position,
4822 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance, NULL);
4825 GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string,
4826 INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect,
4827 GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush)
4831 GpPointF pt[3], rectcpy[4];
4833 REAL rel_width, rel_height;
4836 struct draw_string_args args;
4838 HDC hdc, temp_hdc=NULL;
4839 TEXTMETRICW textmetric;
4841 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length),
4842 length, font, debugstr_rectf(rect), format, brush);
4844 if(!graphics || !string || !font || !brush || !rect)
4845 return InvalidParameter;
4849 hdc = graphics->hdc;
4853 hdc = temp_hdc = CreateCompatibleDC(0);
4857 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4859 /* Should be no need to explicitly test for StringAlignmentNear as
4860 * that is default behavior if no alignment is passed. */
4861 if(format->vertalign != StringAlignmentNear){
4863 GdipMeasureString(graphics, string, length, font, rect, format, &bounds, 0, 0);
4865 if(format->vertalign == StringAlignmentCenter)
4866 offsety = (rect->Height - bounds.Height) / 2;
4867 else if(format->vertalign == StringAlignmentFar)
4868 offsety = (rect->Height - bounds.Height);
4872 save_state = SaveDC(hdc);
4880 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
4881 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
4882 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
4883 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
4884 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
4886 rectcpy[3].X = rectcpy[0].X = rect->X;
4887 rectcpy[1].Y = rectcpy[0].Y = rect->Y + offsety;
4888 rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width;
4889 rectcpy[3].Y = rectcpy[2].Y = rect->Y + offsety + rect->Height;
4890 transform_and_round_points(graphics, corners, rectcpy, 4);
4892 scaled_rect.X = 0.0;
4893 scaled_rect.Y = 0.0;
4894 scaled_rect.Width = rel_width * rect->Width;
4895 scaled_rect.Height = rel_height * rect->Height;
4897 if (roundr(scaled_rect.Width) != 0 && roundr(scaled_rect.Height) != 0)
4899 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4900 rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
4901 SelectClipRgn(hdc, rgn);
4904 get_font_hfont(graphics, font, &gdifont);
4905 SelectObject(hdc, gdifont);
4907 args.graphics = graphics;
4911 args.y = rect->Y + offsety;
4913 args.rel_width = rel_width;
4914 args.rel_height = rel_height;
4916 GetTextMetricsW(hdc, &textmetric);
4917 args.ascent = textmetric.tmAscent / rel_height;
4919 gdip_format_string(hdc, string, length, font, &scaled_rect, format,
4920 draw_string_callback, &args);
4923 DeleteObject(gdifont);
4925 RestoreDC(hdc, save_state);
4932 GpStatus WINGDIPAPI GdipResetClip(GpGraphics *graphics)
4934 TRACE("(%p)\n", graphics);
4937 return InvalidParameter;
4942 return GdipSetInfinite(graphics->clip);
4945 GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics)
4947 TRACE("(%p)\n", graphics);
4950 return InvalidParameter;
4955 graphics->worldtrans->matrix[0] = 1.0;
4956 graphics->worldtrans->matrix[1] = 0.0;
4957 graphics->worldtrans->matrix[2] = 0.0;
4958 graphics->worldtrans->matrix[3] = 1.0;
4959 graphics->worldtrans->matrix[4] = 0.0;
4960 graphics->worldtrans->matrix[5] = 0.0;
4965 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
4967 return GdipEndContainer(graphics, state);
4970 GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
4971 GpMatrixOrder order)
4973 TRACE("(%p, %.2f, %d)\n", graphics, angle, order);
4976 return InvalidParameter;
4981 return GdipRotateMatrix(graphics->worldtrans, angle, order);
4984 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
4986 return GdipBeginContainer2(graphics, state);
4989 GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics *graphics,
4990 GraphicsContainer *state)
4992 GraphicsContainerItem *container;
4995 TRACE("(%p, %p)\n", graphics, state);
4997 if(!graphics || !state)
4998 return InvalidParameter;
5000 sts = init_container(&container, graphics);
5004 list_add_head(&graphics->containers, &container->entry);
5005 *state = graphics->contid = container->contid;
5010 GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics *graphics, GDIPCONST GpRectF *dstrect, GDIPCONST GpRectF *srcrect, GpUnit unit, GraphicsContainer *state)
5012 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
5013 return NotImplemented;
5016 GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics *graphics, GDIPCONST GpRect *dstrect, GDIPCONST GpRect *srcrect, GpUnit unit, GraphicsContainer *state)
5018 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
5019 return NotImplemented;
5022 GpStatus WINGDIPAPI GdipComment(GpGraphics *graphics, UINT sizeData, GDIPCONST BYTE *data)
5024 FIXME("(%p, %d, %p): stub\n", graphics, sizeData, data);
5025 return NotImplemented;
5028 GpStatus WINGDIPAPI GdipEndContainer(GpGraphics *graphics, GraphicsContainer state)
5031 GraphicsContainerItem *container, *container2;
5033 TRACE("(%p, %x)\n", graphics, state);
5036 return InvalidParameter;
5038 LIST_FOR_EACH_ENTRY(container, &graphics->containers, GraphicsContainerItem, entry){
5039 if(container->contid == state)
5043 /* did not find a matching container */
5044 if(&container->entry == &graphics->containers)
5047 sts = restore_container(graphics, container);
5051 /* remove all of the containers on top of the found container */
5052 LIST_FOR_EACH_ENTRY_SAFE(container, container2, &graphics->containers, GraphicsContainerItem, entry){
5053 if(container->contid == state)
5055 list_remove(&container->entry);
5056 delete_container(container);
5059 list_remove(&container->entry);
5060 delete_container(container);
5065 GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
5066 REAL sy, GpMatrixOrder order)
5068 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, sx, sy, order);
5071 return InvalidParameter;
5076 return GdipScaleMatrix(graphics->worldtrans, sx, sy, order);
5079 GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics *graphics, GpGraphics *srcgraphics,
5082 TRACE("(%p, %p, %d)\n", graphics, srcgraphics, mode);
5084 if(!graphics || !srcgraphics)
5085 return InvalidParameter;
5087 return GdipCombineRegionRegion(graphics->clip, srcgraphics->clip, mode);
5090 GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
5091 CompositingMode mode)
5093 TRACE("(%p, %d)\n", graphics, mode);
5096 return InvalidParameter;
5101 graphics->compmode = mode;
5106 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
5107 CompositingQuality quality)
5109 TRACE("(%p, %d)\n", graphics, quality);
5112 return InvalidParameter;
5117 graphics->compqual = quality;
5122 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
5123 InterpolationMode mode)
5125 TRACE("(%p, %d)\n", graphics, mode);
5127 if(!graphics || mode == InterpolationModeInvalid || mode > InterpolationModeHighQualityBicubic)
5128 return InvalidParameter;
5133 if (mode == InterpolationModeDefault || mode == InterpolationModeLowQuality)
5134 mode = InterpolationModeBilinear;
5136 if (mode == InterpolationModeHighQuality)
5137 mode = InterpolationModeHighQualityBicubic;
5139 graphics->interpolation = mode;
5144 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
5146 TRACE("(%p, %.2f)\n", graphics, scale);
5148 if(!graphics || (scale <= 0.0))
5149 return InvalidParameter;
5154 graphics->scale = scale;
5159 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
5161 TRACE("(%p, %d)\n", graphics, unit);
5164 return InvalidParameter;
5169 if(unit == UnitWorld)
5170 return InvalidParameter;
5172 graphics->unit = unit;
5177 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
5180 TRACE("(%p, %d)\n", graphics, mode);
5183 return InvalidParameter;
5188 graphics->pixeloffset = mode;
5193 GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics *graphics, INT x, INT y)
5197 TRACE("(%p,%i,%i)\n", graphics, x, y);
5200 FIXME("not implemented\n");
5202 return NotImplemented;
5205 GpStatus WINGDIPAPI GdipGetRenderingOrigin(GpGraphics *graphics, INT *x, INT *y)
5209 TRACE("(%p,%p,%p)\n", graphics, x, y);
5212 FIXME("not implemented\n");
5216 return NotImplemented;
5219 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
5221 TRACE("(%p, %d)\n", graphics, mode);
5224 return InvalidParameter;
5229 graphics->smoothing = mode;
5234 GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics *graphics, UINT contrast)
5236 TRACE("(%p, %d)\n", graphics, contrast);
5239 return InvalidParameter;
5241 graphics->textcontrast = contrast;
5246 GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
5247 TextRenderingHint hint)
5249 TRACE("(%p, %d)\n", graphics, hint);
5251 if(!graphics || hint > TextRenderingHintClearTypeGridFit)
5252 return InvalidParameter;
5257 graphics->texthint = hint;
5262 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
5264 TRACE("(%p, %p)\n", graphics, matrix);
5266 if(!graphics || !matrix)
5267 return InvalidParameter;
5272 GdipDeleteMatrix(graphics->worldtrans);
5273 return GdipCloneMatrix(matrix, &graphics->worldtrans);
5276 GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
5277 REAL dy, GpMatrixOrder order)
5279 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, dx, dy, order);
5282 return InvalidParameter;
5287 return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order);
5290 /*****************************************************************************
5291 * GdipSetClipHrgn [GDIPLUS.@]
5293 GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics *graphics, HRGN hrgn, CombineMode mode)
5298 TRACE("(%p, %p, %d)\n", graphics, hrgn, mode);
5301 return InvalidParameter;
5303 status = GdipCreateRegionHrgn(hrgn, ®ion);
5307 status = GdipSetClipRegion(graphics, region, mode);
5309 GdipDeleteRegion(region);
5313 GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics *graphics, GpPath *path, CombineMode mode)
5315 TRACE("(%p, %p, %d)\n", graphics, path, mode);
5318 return InvalidParameter;
5323 return GdipCombineRegionPath(graphics->clip, path, mode);
5326 GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y,
5327 REAL width, REAL height,
5332 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics, x, y, width, height, mode);
5335 return InvalidParameter;
5343 rect.Height = height;
5345 return GdipCombineRegionRect(graphics->clip, &rect, mode);
5348 GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y,
5349 INT width, INT height,
5352 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics, x, y, width, height, mode);
5355 return InvalidParameter;
5360 return GdipSetClipRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, mode);
5363 GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
5366 TRACE("(%p, %p, %d)\n", graphics, region, mode);
5368 if(!graphics || !region)
5369 return InvalidParameter;
5374 return GdipCombineRegionRegion(graphics->clip, region, mode);
5377 GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile *metafile,
5382 TRACE("(%p,%u)\n", metafile, limitDpi);
5385 FIXME("not implemented\n");
5387 return NotImplemented;
5390 GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points,
5396 TRACE("(%p, %p, %d)\n", graphics, points, count);
5398 if(!graphics || !pen || count<=0)
5399 return InvalidParameter;
5406 FIXME("graphics object has no HDC\n");
5410 pti = GdipAlloc(sizeof(POINT) * count);
5412 save_state = prepare_dc(graphics, pen);
5413 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
5415 transform_and_round_points(graphics, pti, (GpPointF*)points, count);
5416 Polygon(graphics->hdc, pti, count);
5418 restore_dc(graphics, save_state);
5424 GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points,
5431 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
5433 if(count<=0) return InvalidParameter;
5434 ptf = GdipAlloc(sizeof(GpPointF) * count);
5436 for(i = 0;i < count; i++){
5437 ptf[i].X = (REAL)points[i].X;
5438 ptf[i].Y = (REAL)points[i].Y;
5441 ret = GdipDrawPolygon(graphics,pen,ptf,count);
5447 GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
5449 TRACE("(%p, %p)\n", graphics, dpi);
5451 if(!graphics || !dpi)
5452 return InvalidParameter;
5457 if (graphics->image)
5458 *dpi = graphics->image->xres;
5460 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
5465 GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
5467 TRACE("(%p, %p)\n", graphics, dpi);
5469 if(!graphics || !dpi)
5470 return InvalidParameter;
5475 if (graphics->image)
5476 *dpi = graphics->image->yres;
5478 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
5483 GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix,
5484 GpMatrixOrder order)
5489 TRACE("(%p, %p, %d)\n", graphics, matrix, order);
5491 if(!graphics || !matrix)
5492 return InvalidParameter;
5497 m = *(graphics->worldtrans);
5499 ret = GdipMultiplyMatrix(&m, matrix, order);
5501 *(graphics->worldtrans) = m;
5506 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5507 static const COLORREF DC_BACKGROUND_KEY = 0x0c0b0d;
5509 GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
5513 TRACE("(%p, %p)\n", graphics, hdc);
5515 if(!graphics || !hdc)
5516 return InvalidParameter;
5521 if (graphics->image && graphics->image->type == ImageTypeMetafile)
5523 stat = METAFILE_GetDC((GpMetafile*)graphics->image, hdc);
5525 else if (!graphics->hdc ||
5526 (graphics->image && graphics->image->type == ImageTypeBitmap && ((GpBitmap*)graphics->image)->format & PixelFormatAlpha))
5528 /* Create a fake HDC and fill it with a constant color. */
5532 BITMAPINFOHEADER bmih;
5535 stat = get_graphics_bounds(graphics, &bounds);
5539 graphics->temp_hbitmap_width = bounds.Width;
5540 graphics->temp_hbitmap_height = bounds.Height;
5542 bmih.biSize = sizeof(bmih);
5543 bmih.biWidth = graphics->temp_hbitmap_width;
5544 bmih.biHeight = -graphics->temp_hbitmap_height;
5546 bmih.biBitCount = 32;
5547 bmih.biCompression = BI_RGB;
5548 bmih.biSizeImage = 0;
5549 bmih.biXPelsPerMeter = 0;
5550 bmih.biYPelsPerMeter = 0;
5552 bmih.biClrImportant = 0;
5554 hbitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
5555 (void**)&graphics->temp_bits, NULL, 0);
5557 return GenericError;
5559 temp_hdc = CreateCompatibleDC(0);
5562 DeleteObject(hbitmap);
5563 return GenericError;
5566 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
5567 ((DWORD*)graphics->temp_bits)[i] = DC_BACKGROUND_KEY;
5569 SelectObject(temp_hdc, hbitmap);
5571 graphics->temp_hbitmap = hbitmap;
5572 *hdc = graphics->temp_hdc = temp_hdc;
5576 *hdc = graphics->hdc;
5580 graphics->busy = TRUE;
5585 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
5589 TRACE("(%p, %p)\n", graphics, hdc);
5591 if(!graphics || !hdc || !graphics->busy)
5592 return InvalidParameter;
5594 if (graphics->image && graphics->image->type == ImageTypeMetafile)
5596 stat = METAFILE_ReleaseDC((GpMetafile*)graphics->image, hdc);
5598 else if (graphics->temp_hdc == hdc)
5603 /* Find the pixels that have changed, and mark them as opaque. */
5604 pos = (DWORD*)graphics->temp_bits;
5605 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
5607 if (*pos != DC_BACKGROUND_KEY)
5614 /* Write the changed pixels to the real target. */
5615 alpha_blend_pixels(graphics, 0, 0, graphics->temp_bits,
5616 graphics->temp_hbitmap_width, graphics->temp_hbitmap_height,
5617 graphics->temp_hbitmap_width * 4);
5620 DeleteDC(graphics->temp_hdc);
5621 DeleteObject(graphics->temp_hbitmap);
5622 graphics->temp_hdc = NULL;
5623 graphics->temp_hbitmap = NULL;
5625 else if (hdc != graphics->hdc)
5627 stat = InvalidParameter;
5631 graphics->busy = FALSE;
5636 GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
5641 TRACE("(%p, %p)\n", graphics, region);
5643 if(!graphics || !region)
5644 return InvalidParameter;
5649 if((status = GdipCloneRegion(graphics->clip, &clip)) != Ok)
5652 /* free everything except root node and header */
5653 delete_element(®ion->node);
5654 memcpy(region, clip, sizeof(GpRegion));
5660 static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace dst_space,
5661 GpCoordinateSpace src_space, GpMatrix **matrix)
5663 GpStatus stat = GdipCreateMatrix(matrix);
5666 if (dst_space != src_space && stat == Ok)
5668 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
5670 if(graphics->unit != UnitDisplay)
5671 unitscale *= graphics->scale;
5673 /* transform from src_space to CoordinateSpacePage */
5676 case CoordinateSpaceWorld:
5677 GdipMultiplyMatrix(*matrix, graphics->worldtrans, MatrixOrderAppend);
5679 case CoordinateSpacePage:
5681 case CoordinateSpaceDevice:
5682 GdipScaleMatrix(*matrix, 1.0/unitscale, 1.0/unitscale, MatrixOrderAppend);
5686 /* transform from CoordinateSpacePage to dst_space */
5689 case CoordinateSpaceWorld:
5691 GpMatrix *inverted_transform;
5692 stat = GdipCloneMatrix(graphics->worldtrans, &inverted_transform);
5695 stat = GdipInvertMatrix(inverted_transform);
5697 GdipMultiplyMatrix(*matrix, inverted_transform, MatrixOrderAppend);
5698 GdipDeleteMatrix(inverted_transform);
5702 case CoordinateSpacePage:
5704 case CoordinateSpaceDevice:
5705 GdipScaleMatrix(*matrix, unitscale, unitscale, MatrixOrderAppend);
5712 GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space,
5713 GpCoordinateSpace src_space, GpPointF *points, INT count)
5718 if(!graphics || !points || count <= 0)
5719 return InvalidParameter;
5724 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
5726 if (src_space == dst_space) return Ok;
5728 stat = get_graphics_transform(graphics, dst_space, src_space, &matrix);
5732 stat = GdipTransformMatrixPoints(matrix, points, count);
5734 GdipDeleteMatrix(matrix);
5740 GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space,
5741 GpCoordinateSpace src_space, GpPoint *points, INT count)
5747 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
5750 return InvalidParameter;
5752 pointsF = GdipAlloc(sizeof(GpPointF) * count);
5756 for(i = 0; i < count; i++){
5757 pointsF[i].X = (REAL)points[i].X;
5758 pointsF[i].Y = (REAL)points[i].Y;
5761 ret = GdipTransformPoints(graphics, dst_space, src_space, pointsF, count);
5764 for(i = 0; i < count; i++){
5765 points[i].X = roundr(pointsF[i].X);
5766 points[i].Y = roundr(pointsF[i].Y);
5773 HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void)
5785 /*****************************************************************************
5786 * GdipTranslateClip [GDIPLUS.@]
5788 GpStatus WINGDIPAPI GdipTranslateClip(GpGraphics *graphics, REAL dx, REAL dy)
5790 TRACE("(%p, %.2f, %.2f)\n", graphics, dx, dy);
5793 return InvalidParameter;
5798 return GdipTranslateRegion(graphics->clip, dx, dy);
5801 /*****************************************************************************
5802 * GdipTranslateClipI [GDIPLUS.@]
5804 GpStatus WINGDIPAPI GdipTranslateClipI(GpGraphics *graphics, INT dx, INT dy)
5806 TRACE("(%p, %d, %d)\n", graphics, dx, dy);
5809 return InvalidParameter;
5814 return GdipTranslateRegion(graphics->clip, (REAL)dx, (REAL)dy);
5818 /*****************************************************************************
5819 * GdipMeasureDriverString [GDIPLUS.@]
5821 GpStatus WINGDIPAPI GdipMeasureDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5822 GDIPCONST GpFont *font, GDIPCONST PointF *positions,
5823 INT flags, GDIPCONST GpMatrix *matrix, RectF *boundingBox)
5825 static const INT unsupported_flags = ~(DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance);
5828 REAL min_x, min_y, max_x, max_y, x, y;
5830 TEXTMETRICW textmetric;
5831 const WORD *glyph_indices;
5832 WORD *dynamic_glyph_indices=NULL;
5833 REAL rel_width, rel_height, ascent, descent;
5836 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics, text, length, font, positions, flags, matrix, boundingBox);
5838 if (!graphics || !text || !font || !positions || !boundingBox)
5839 return InvalidParameter;
5842 length = strlenW(text);
5846 boundingBox->X = 0.0;
5847 boundingBox->Y = 0.0;
5848 boundingBox->Width = 0.0;
5849 boundingBox->Height = 0.0;
5852 if (flags & unsupported_flags)
5853 FIXME("Ignoring flags %x\n", flags & unsupported_flags);
5856 FIXME("Ignoring matrix\n");
5858 get_font_hfont(graphics, font, &hfont);
5860 hdc = CreateCompatibleDC(0);
5861 SelectObject(hdc, hfont);
5863 GetTextMetricsW(hdc, &textmetric);
5871 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
5872 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
5873 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
5874 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
5875 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
5877 if (flags & DriverStringOptionsCmapLookup)
5879 glyph_indices = dynamic_glyph_indices = GdipAlloc(sizeof(WORD) * length);
5883 DeleteObject(hfont);
5887 GetGlyphIndicesW(hdc, text, length, dynamic_glyph_indices, 0);
5890 glyph_indices = text;
5892 min_x = max_x = x = positions[0].X;
5893 min_y = max_y = y = positions[0].Y;
5895 ascent = textmetric.tmAscent / rel_height;
5896 descent = textmetric.tmDescent / rel_height;
5898 for (i=0; i<length; i++)
5903 if (!(flags & DriverStringOptionsRealizedAdvance))
5909 GetCharABCWidthsW(hdc, glyph_indices[i], glyph_indices[i], &abc);
5910 char_width = abc.abcA + abc.abcB + abc.abcB;
5912 if (min_y > y - ascent) min_y = y - ascent;
5913 if (max_y < y + descent) max_y = y + descent;
5914 if (min_x > x) min_x = x;
5916 x += char_width / rel_width;
5918 if (max_x < x) max_x = x;
5921 GdipFree(dynamic_glyph_indices);
5923 DeleteObject(hfont);
5925 boundingBox->X = min_x;
5926 boundingBox->Y = min_y;
5927 boundingBox->Width = max_x - min_x;
5928 boundingBox->Height = max_y - min_y;
5933 static GpStatus GDI32_GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5934 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
5935 GDIPCONST PointF *positions, INT flags,
5936 GDIPCONST GpMatrix *matrix )
5938 static const INT unsupported_flags = ~(DriverStringOptionsRealizedAdvance|DriverStringOptionsCmapLookup);
5944 if (flags & unsupported_flags)
5945 FIXME("Ignoring flags %x\n", flags & unsupported_flags);
5948 FIXME("Ignoring matrix\n");
5950 if (!(flags & DriverStringOptionsCmapLookup))
5951 eto_flags |= ETO_GLYPH_INDEX;
5953 save_state = SaveDC(graphics->hdc);
5954 SetBkMode(graphics->hdc, TRANSPARENT);
5955 SetTextColor(graphics->hdc, get_gdi_brush_color(brush));
5958 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, &pt, 1);
5960 get_font_hfont(graphics, font, &hfont);
5961 SelectObject(graphics->hdc, hfont);
5963 SetTextAlign(graphics->hdc, TA_BASELINE|TA_LEFT);
5965 ExtTextOutW(graphics->hdc, roundr(pt.X), roundr(pt.Y), eto_flags, NULL, text, length, NULL);
5967 RestoreDC(graphics->hdc, save_state);
5969 DeleteObject(hfont);
5974 static GpStatus SOFTWARE_GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5975 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
5976 GDIPCONST PointF *positions, INT flags,
5977 GDIPCONST GpMatrix *matrix )
5979 static const INT unsupported_flags = ~(DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance);
5981 PointF *real_positions, real_position;
5985 int min_x=INT_MAX, min_y=INT_MAX, max_x=INT_MIN, max_y=INT_MIN, i, x, y;
5986 DWORD max_glyphsize=0;
5987 GLYPHMETRICS glyphmetrics;
5988 static const MAT2 identity = {{0,1}, {0,0}, {0,0}, {0,1}};
5991 int text_mask_stride;
5993 int pixel_data_stride;
5995 UINT ggo_flags = GGO_GRAY8_BITMAP;
6000 if (!(flags & DriverStringOptionsCmapLookup))
6001 ggo_flags |= GGO_GLYPH_INDEX;
6003 if (flags & unsupported_flags)
6004 FIXME("Ignoring flags %x\n", flags & unsupported_flags);
6007 FIXME("Ignoring matrix\n");
6009 pti = GdipAlloc(sizeof(POINT) * length);
6013 if (flags & DriverStringOptionsRealizedAdvance)
6015 real_position = positions[0];
6017 transform_and_round_points(graphics, pti, &real_position, 1);
6021 real_positions = GdipAlloc(sizeof(PointF) * length);
6022 if (!real_positions)
6028 memcpy(real_positions, positions, sizeof(PointF) * length);
6030 transform_and_round_points(graphics, pti, real_positions, length);
6032 GdipFree(real_positions);
6035 get_font_hfont(graphics, font, &hfont);
6037 hdc = CreateCompatibleDC(0);
6038 SelectObject(hdc, hfont);
6040 /* Get the boundaries of the text to be drawn */
6041 for (i=0; i<length; i++)
6044 int left, top, right, bottom;
6046 glyphsize = GetGlyphOutlineW(hdc, text[i], ggo_flags,
6047 &glyphmetrics, 0, NULL, &identity);
6049 if (glyphsize == GDI_ERROR)
6051 ERR("GetGlyphOutlineW failed\n");
6054 DeleteObject(hfont);
6055 return GenericError;
6058 if (glyphsize > max_glyphsize)
6059 max_glyphsize = glyphsize;
6061 left = pti[i].x + glyphmetrics.gmptGlyphOrigin.x;
6062 top = pti[i].y - glyphmetrics.gmptGlyphOrigin.y;
6063 right = pti[i].x + glyphmetrics.gmptGlyphOrigin.x + glyphmetrics.gmBlackBoxX;
6064 bottom = pti[i].y - glyphmetrics.gmptGlyphOrigin.y + glyphmetrics.gmBlackBoxY;
6066 if (left < min_x) min_x = left;
6067 if (top < min_y) min_y = top;
6068 if (right > max_x) max_x = right;
6069 if (bottom > max_y) max_y = bottom;
6071 if (i+1 < length && (flags & DriverStringOptionsRealizedAdvance) == DriverStringOptionsRealizedAdvance)
6073 pti[i+1].x = pti[i].x + glyphmetrics.gmCellIncX;
6074 pti[i+1].y = pti[i].y + glyphmetrics.gmCellIncY;
6078 glyph_mask = GdipAlloc(max_glyphsize);
6079 text_mask = GdipAlloc((max_x - min_x) * (max_y - min_y));
6080 text_mask_stride = max_x - min_x;
6082 if (!(glyph_mask && text_mask))
6084 GdipFree(glyph_mask);
6085 GdipFree(text_mask);
6088 DeleteObject(hfont);
6092 /* Generate a mask for the text */
6093 for (i=0; i<length; i++)
6095 int left, top, stride;
6097 GetGlyphOutlineW(hdc, text[i], ggo_flags,
6098 &glyphmetrics, max_glyphsize, glyph_mask, &identity);
6100 left = pti[i].x + glyphmetrics.gmptGlyphOrigin.x;
6101 top = pti[i].y - glyphmetrics.gmptGlyphOrigin.y;
6102 stride = (glyphmetrics.gmBlackBoxX + 3) & (~3);
6104 for (y=0; y<glyphmetrics.gmBlackBoxY; y++)
6106 BYTE *glyph_val = glyph_mask + y * stride;
6107 BYTE *text_val = text_mask + (left - min_x) + (top - min_y + y) * text_mask_stride;
6108 for (x=0; x<glyphmetrics.gmBlackBoxX; x++)
6110 *text_val = min(64, *text_val + *glyph_val);
6119 DeleteObject(hfont);
6120 GdipFree(glyph_mask);
6122 /* get the brush data */
6123 pixel_data = GdipAlloc(4 * (max_x - min_x) * (max_y - min_y));
6126 GdipFree(text_mask);
6130 pixel_area.X = min_x;
6131 pixel_area.Y = min_y;
6132 pixel_area.Width = max_x - min_x;
6133 pixel_area.Height = max_y - min_y;
6134 pixel_data_stride = pixel_area.Width * 4;
6136 stat = brush_fill_pixels(graphics, (GpBrush*)brush, (DWORD*)pixel_data, &pixel_area, pixel_area.Width);
6139 GdipFree(text_mask);
6140 GdipFree(pixel_data);
6144 /* multiply the brush data by the mask */
6145 for (y=0; y<pixel_area.Height; y++)
6147 BYTE *text_val = text_mask + text_mask_stride * y;
6148 BYTE *pixel_val = pixel_data + pixel_data_stride * y + 3;
6149 for (x=0; x<pixel_area.Width; x++)
6151 *pixel_val = (*pixel_val) * (*text_val) / 64;
6157 GdipFree(text_mask);
6159 /* draw the result */
6160 stat = alpha_blend_pixels(graphics, min_x, min_y, pixel_data, pixel_area.Width,
6161 pixel_area.Height, pixel_data_stride);
6163 GdipFree(pixel_data);
6168 /*****************************************************************************
6169 * GdipDrawDriverString [GDIPLUS.@]
6171 GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
6172 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
6173 GDIPCONST PointF *positions, INT flags,
6174 GDIPCONST GpMatrix *matrix )
6176 GpStatus stat=NotImplemented;
6178 TRACE("(%p %s %p %p %p %d %p)\n", graphics, debugstr_wn(text, length), font, brush, positions, flags, matrix);
6180 if (!graphics || !text || !font || !brush || !positions)
6181 return InvalidParameter;
6184 length = strlenW(text);
6186 if (graphics->hdc &&
6187 ((flags & DriverStringOptionsRealizedAdvance) || length <= 1) &&
6188 brush->bt == BrushTypeSolidColor &&
6189 (((GpSolidFill*)brush)->color & 0xff000000) == 0xff000000)
6190 stat = GDI32_GdipDrawDriverString(graphics, text, length, font, brush,
6191 positions, flags, matrix);
6193 if (stat == NotImplemented)
6194 stat = SOFTWARE_GdipDrawDriverString(graphics, text, length, font, brush,
6195 positions, flags, matrix);
6200 GpStatus WINGDIPAPI GdipRecordMetafileStream(IStream *stream, HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
6201 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
6203 FIXME("(%p %p %d %p %d %p %p): stub\n", stream, hdc, type, frameRect, frameUnit, desc, metafile);
6204 return NotImplemented;
6207 /*****************************************************************************
6208 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6210 GpStatus WINGDIPAPI GdipIsVisibleClipEmpty(GpGraphics *graphics, BOOL *res)
6215 TRACE("(%p, %p)\n", graphics, res);
6217 if((stat = GdipCreateRegion(&rgn)) != Ok)
6220 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
6223 stat = GdipIsEmptyRegion(rgn, graphics, res);
6226 GdipDeleteRegion(rgn);