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;
850 HBITMAP bmp = ARGB2BMP(fill->color);
855 /* partially transparent fill */
857 SelectClipPath(graphics->hdc, RGN_AND);
858 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
860 HDC hdc = CreateCompatibleDC(NULL);
865 SelectObject(hdc, bmp);
867 bf.BlendOp = AC_SRC_OVER;
869 bf.SourceConstantAlpha = 255;
870 bf.AlphaFormat = AC_SRC_ALPHA;
872 GdiAlphaBlend(graphics->hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdc, 0, 0, 1, 1, bf);
880 /* else fall through */
884 HBRUSH gdibrush, old_brush;
886 gdibrush = create_gdi_brush(brush);
887 if (!gdibrush) return;
889 old_brush = SelectObject(graphics->hdc, gdibrush);
890 FillPath(graphics->hdc);
891 SelectObject(graphics->hdc, old_brush);
892 DeleteObject(gdibrush);
898 static INT brush_can_fill_pixels(GpBrush *brush)
902 case BrushTypeSolidColor:
903 case BrushTypeHatchFill:
904 case BrushTypeLinearGradient:
905 case BrushTypeTextureFill:
912 static GpStatus brush_fill_pixels(GpGraphics *graphics, GpBrush *brush,
913 DWORD *argb_pixels, GpRect *fill_area, UINT cdwStride)
917 case BrushTypeSolidColor:
920 GpSolidFill *fill = (GpSolidFill*)brush;
921 for (x=0; x<fill_area->Width; x++)
922 for (y=0; y<fill_area->Height; y++)
923 argb_pixels[x + y*cdwStride] = fill->color;
926 case BrushTypeHatchFill:
929 GpHatch *fill = (GpHatch*)brush;
930 const char *hatch_data;
932 if (get_hatch_data(fill->hatchstyle, &hatch_data) != Ok)
933 return NotImplemented;
935 for (x=0; x<fill_area->Width; x++)
936 for (y=0; y<fill_area->Height; y++)
940 /* FIXME: Account for the rendering origin */
941 hx = (x + fill_area->X) % 8;
942 hy = (y + fill_area->Y) % 8;
944 if ((hatch_data[7-hy] & (0x80 >> hx)) != 0)
945 argb_pixels[x + y*cdwStride] = fill->forecol;
947 argb_pixels[x + y*cdwStride] = fill->backcol;
952 case BrushTypeLinearGradient:
954 GpLineGradient *fill = (GpLineGradient*)brush;
955 GpPointF draw_points[3], line_points[3];
957 static const GpRectF box_1 = { 0.0, 0.0, 1.0, 1.0 };
958 GpMatrix *world_to_gradient; /* FIXME: Store this in the brush? */
961 draw_points[0].X = fill_area->X;
962 draw_points[0].Y = fill_area->Y;
963 draw_points[1].X = fill_area->X+1;
964 draw_points[1].Y = fill_area->Y;
965 draw_points[2].X = fill_area->X;
966 draw_points[2].Y = fill_area->Y+1;
968 /* Transform the points to a co-ordinate space where X is the point's
969 * position in the gradient, 0.0 being the start point and 1.0 the
971 stat = GdipTransformPoints(graphics, CoordinateSpaceWorld,
972 CoordinateSpaceDevice, draw_points, 3);
976 line_points[0] = fill->startpoint;
977 line_points[1] = fill->endpoint;
978 line_points[2].X = fill->startpoint.X + (fill->startpoint.Y - fill->endpoint.Y);
979 line_points[2].Y = fill->startpoint.Y + (fill->endpoint.X - fill->startpoint.X);
981 stat = GdipCreateMatrix3(&box_1, line_points, &world_to_gradient);
986 stat = GdipInvertMatrix(world_to_gradient);
989 stat = GdipTransformMatrixPoints(world_to_gradient, draw_points, 3);
991 GdipDeleteMatrix(world_to_gradient);
996 REAL x_delta = draw_points[1].X - draw_points[0].X;
997 REAL y_delta = draw_points[2].X - draw_points[0].X;
999 for (y=0; y<fill_area->Height; y++)
1001 for (x=0; x<fill_area->Width; x++)
1003 REAL pos = draw_points[0].X + x * x_delta + y * y_delta;
1005 argb_pixels[x + y*cdwStride] = blend_line_gradient(fill, pos);
1012 case BrushTypeTextureFill:
1014 GpTexture *fill = (GpTexture*)brush;
1015 GpPointF draw_points[3];
1017 GpMatrix *world_to_texture;
1023 if (fill->image->type != ImageTypeBitmap)
1025 FIXME("metafile texture brushes not implemented\n");
1026 return NotImplemented;
1029 bitmap = (GpBitmap*)fill->image;
1030 src_stride = sizeof(ARGB) * bitmap->width;
1032 src_area.X = src_area.Y = 0;
1033 src_area.Width = bitmap->width;
1034 src_area.Height = bitmap->height;
1036 draw_points[0].X = fill_area->X;
1037 draw_points[0].Y = fill_area->Y;
1038 draw_points[1].X = fill_area->X+1;
1039 draw_points[1].Y = fill_area->Y;
1040 draw_points[2].X = fill_area->X;
1041 draw_points[2].Y = fill_area->Y+1;
1043 /* Transform the points to the co-ordinate space of the bitmap. */
1044 stat = GdipTransformPoints(graphics, CoordinateSpaceWorld,
1045 CoordinateSpaceDevice, draw_points, 3);
1049 stat = GdipCloneMatrix(fill->transform, &world_to_texture);
1054 stat = GdipInvertMatrix(world_to_texture);
1057 stat = GdipTransformMatrixPoints(world_to_texture, draw_points, 3);
1059 GdipDeleteMatrix(world_to_texture);
1062 if (stat == Ok && !fill->bitmap_bits)
1064 BitmapData lockeddata;
1066 fill->bitmap_bits = GdipAlloc(sizeof(ARGB) * bitmap->width * bitmap->height);
1067 if (!fill->bitmap_bits)
1072 lockeddata.Width = bitmap->width;
1073 lockeddata.Height = bitmap->height;
1074 lockeddata.Stride = src_stride;
1075 lockeddata.PixelFormat = PixelFormat32bppARGB;
1076 lockeddata.Scan0 = fill->bitmap_bits;
1078 stat = GdipBitmapLockBits(bitmap, &src_area, ImageLockModeRead|ImageLockModeUserInputBuf,
1079 PixelFormat32bppARGB, &lockeddata);
1083 stat = GdipBitmapUnlockBits(bitmap, &lockeddata);
1086 apply_image_attributes(fill->imageattributes, fill->bitmap_bits,
1087 bitmap->width, bitmap->height,
1088 src_stride, ColorAdjustTypeBitmap);
1092 GdipFree(fill->bitmap_bits);
1093 fill->bitmap_bits = NULL;
1099 REAL x_dx = draw_points[1].X - draw_points[0].X;
1100 REAL x_dy = draw_points[1].Y - draw_points[0].Y;
1101 REAL y_dx = draw_points[2].X - draw_points[0].X;
1102 REAL y_dy = draw_points[2].Y - draw_points[0].Y;
1104 for (y=0; y<fill_area->Height; y++)
1106 for (x=0; x<fill_area->Width; x++)
1109 point.X = draw_points[0].X + x * x_dx + y * y_dx;
1110 point.Y = draw_points[0].Y + y * x_dy + y * y_dy;
1112 argb_pixels[x + y*cdwStride] = resample_bitmap_pixel(
1113 &src_area, fill->bitmap_bits, bitmap->width, bitmap->height,
1114 &point, fill->imageattributes, graphics->interpolation);
1122 return NotImplemented;
1126 /* GdipDrawPie/GdipFillPie helper function */
1127 static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width,
1128 REAL height, REAL startAngle, REAL sweepAngle)
1135 ptf[1].X = x + width;
1136 ptf[1].Y = y + height;
1138 deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y);
1139 deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y);
1141 transform_and_round_points(graphics, pti, ptf, 4);
1143 Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x,
1144 pti[2].y, pti[3].x, pti[3].y);
1147 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1148 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1149 * should not be called on an hdc that has a path you care about. */
1150 static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
1151 const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
1153 HGDIOBJ oldbrush = NULL, oldpen = NULL;
1154 GpMatrix *matrix = NULL;
1155 HBRUSH brush = NULL;
1157 PointF ptf[4], *custptf = NULL;
1158 POINT pt[4], *custpt = NULL;
1160 REAL theta, dsmall, dbig, dx, dy = 0.0;
1165 if((x1 == x2) && (y1 == y2))
1168 theta = gdiplus_atan2(y2 - y1, x2 - x1);
1170 customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
1172 brush = CreateSolidBrush(color);
1173 lb.lbStyle = BS_SOLID;
1176 pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
1177 PS_JOIN_MITER, 1, &lb, 0,
1179 oldbrush = SelectObject(graphics->hdc, brush);
1180 oldpen = SelectObject(graphics->hdc, pen);
1187 case LineCapSquareAnchor:
1188 case LineCapDiamondAnchor:
1189 size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0;
1190 if(cap == LineCapDiamondAnchor){
1191 dsmall = cos(theta + M_PI_2) * size;
1192 dbig = sin(theta + M_PI_2) * size;
1195 dsmall = cos(theta + M_PI_4) * size;
1196 dbig = sin(theta + M_PI_4) * size;
1199 ptf[0].X = x2 - dsmall;
1200 ptf[1].X = x2 + dbig;
1202 ptf[0].Y = y2 - dbig;
1203 ptf[3].Y = y2 + dsmall;
1205 ptf[1].Y = y2 - dsmall;
1206 ptf[2].Y = y2 + dbig;
1208 ptf[3].X = x2 - dbig;
1209 ptf[2].X = x2 + dsmall;
1211 transform_and_round_points(graphics, pt, ptf, 4);
1212 Polygon(graphics->hdc, pt, 4);
1215 case LineCapArrowAnchor:
1216 size = size * 4.0 / sqrt(3.0);
1218 dx = cos(M_PI / 6.0 + theta) * size;
1219 dy = sin(M_PI / 6.0 + theta) * size;
1224 dx = cos(- M_PI / 6.0 + theta) * size;
1225 dy = sin(- M_PI / 6.0 + theta) * size;
1233 transform_and_round_points(graphics, pt, ptf, 3);
1234 Polygon(graphics->hdc, pt, 3);
1237 case LineCapRoundAnchor:
1238 dx = dy = ANCHOR_WIDTH * size / 2.0;
1245 transform_and_round_points(graphics, pt, ptf, 2);
1246 Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
1249 case LineCapTriangle:
1251 dx = cos(M_PI_2 + theta) * size;
1252 dy = sin(M_PI_2 + theta) * size;
1259 dx = cos(theta) * size;
1260 dy = sin(theta) * size;
1265 transform_and_round_points(graphics, pt, ptf, 3);
1266 Polygon(graphics->hdc, pt, 3);
1270 dx = dy = size / 2.0;
1277 dx = -cos(M_PI_2 + theta) * size;
1278 dy = -sin(M_PI_2 + theta) * size;
1285 transform_and_round_points(graphics, pt, ptf, 4);
1286 Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x,
1287 pt[2].y, pt[3].x, pt[3].y);
1294 count = custom->pathdata.Count;
1295 custptf = GdipAlloc(count * sizeof(PointF));
1296 custpt = GdipAlloc(count * sizeof(POINT));
1297 tp = GdipAlloc(count);
1299 if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok))
1302 memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF));
1304 GdipScaleMatrix(matrix, size, size, MatrixOrderAppend);
1305 GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2),
1307 GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend);
1308 GdipTransformMatrixPoints(matrix, custptf, count);
1310 transform_and_round_points(graphics, custpt, custptf, count);
1312 for(i = 0; i < count; i++)
1313 tp[i] = convert_path_point_type(custom->pathdata.Types[i]);
1316 BeginPath(graphics->hdc);
1317 PolyDraw(graphics->hdc, custpt, tp, count);
1318 EndPath(graphics->hdc);
1319 StrokeAndFillPath(graphics->hdc);
1322 PolyDraw(graphics->hdc, custpt, tp, count);
1328 GdipDeleteMatrix(matrix);
1335 SelectObject(graphics->hdc, oldbrush);
1336 SelectObject(graphics->hdc, oldpen);
1337 DeleteObject(brush);
1342 /* Shortens the line by the given percent by changing x2, y2.
1343 * If percent is > 1.0 then the line will change direction.
1344 * If percent is negative it can lengthen the line. */
1345 static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL percent)
1347 REAL dist, theta, dx, dy;
1349 if((y1 == *y2) && (x1 == *x2))
1352 dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent;
1353 theta = gdiplus_atan2((*y2 - y1), (*x2 - x1));
1354 dx = cos(theta) * dist;
1355 dy = sin(theta) * dist;
1361 /* Shortens the line by the given amount by changing x2, y2.
1362 * If the amount is greater than the distance, the line will become length 0.
1363 * If the amount is negative, it can lengthen the line. */
1364 static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt)
1366 REAL dx, dy, percent;
1370 if(dx == 0 && dy == 0)
1373 percent = amt / sqrt(dx * dx + dy * dy);
1380 shorten_line_percent(x1, y1, x2, y2, percent);
1383 /* Draws lines between the given points, and if caps is true then draws an endcap
1384 * at the end of the last line. */
1385 static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen,
1386 GDIPCONST GpPointF * pt, INT count, BOOL caps)
1389 GpPointF *ptcopy = NULL;
1390 GpStatus status = GenericError;
1395 pti = GdipAlloc(count * sizeof(POINT));
1396 ptcopy = GdipAlloc(count * sizeof(GpPointF));
1398 if(!pti || !ptcopy){
1399 status = OutOfMemory;
1403 memcpy(ptcopy, pt, count * sizeof(GpPointF));
1406 if(pen->endcap == LineCapArrowAnchor)
1407 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
1408 &ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width);
1409 else if((pen->endcap == LineCapCustom) && pen->customend)
1410 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
1411 &ptcopy[count-1].X, &ptcopy[count-1].Y,
1412 pen->customend->inset * pen->width);
1414 if(pen->startcap == LineCapArrowAnchor)
1415 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
1416 &ptcopy[0].X, &ptcopy[0].Y, pen->width);
1417 else if((pen->startcap == LineCapCustom) && pen->customstart)
1418 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
1419 &ptcopy[0].X, &ptcopy[0].Y,
1420 pen->customstart->inset * pen->width);
1422 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->endcap, pen->width, pen->customend,
1423 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
1424 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->startcap, pen->width, pen->customstart,
1425 pt[1].X, pt[1].Y, pt[0].X, pt[0].Y);
1428 transform_and_round_points(graphics, pti, ptcopy, count);
1430 if(Polyline(graphics->hdc, pti, count))
1440 /* Conducts a linear search to find the bezier points that will back off
1441 * the endpoint of the curve by a distance of amt. Linear search works
1442 * better than binary in this case because there are multiple solutions,
1443 * and binary searches often find a bad one. I don't think this is what
1444 * Windows does but short of rendering the bezier without GDI's help it's
1445 * the best we can do. If rev then work from the start of the passed points
1446 * instead of the end. */
1447 static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev)
1450 REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0;
1451 INT i, first = 0, second = 1, third = 2, fourth = 3;
1460 origx = pt[fourth].X;
1461 origy = pt[fourth].Y;
1462 memcpy(origpt, pt, sizeof(GpPointF) * 4);
1464 for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){
1465 /* reset bezier points to original values */
1466 memcpy(pt, origpt, sizeof(GpPointF) * 4);
1467 /* Perform magic on bezier points. Order is important here.*/
1468 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
1469 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
1470 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
1471 shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent);
1472 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
1473 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
1475 dx = pt[fourth].X - origx;
1476 dy = pt[fourth].Y - origy;
1478 diff = sqrt(dx * dx + dy * dy);
1479 percent += 0.0005 * amt;
1483 /* Draws bezier curves between given points, and if caps is true then draws an
1484 * endcap at the end of the last line. */
1485 static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
1486 GDIPCONST GpPointF * pt, INT count, BOOL caps)
1490 GpStatus status = GenericError;
1495 pti = GdipAlloc(count * sizeof(POINT));
1496 ptcopy = GdipAlloc(count * sizeof(GpPointF));
1498 if(!pti || !ptcopy){
1499 status = OutOfMemory;
1503 memcpy(ptcopy, pt, count * sizeof(GpPointF));
1506 if(pen->endcap == LineCapArrowAnchor)
1507 shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
1508 else if((pen->endcap == LineCapCustom) && pen->customend)
1509 shorten_bezier_amt(&ptcopy[count-4], pen->width * pen->customend->inset,
1512 if(pen->startcap == LineCapArrowAnchor)
1513 shorten_bezier_amt(ptcopy, pen->width, TRUE);
1514 else if((pen->startcap == LineCapCustom) && pen->customstart)
1515 shorten_bezier_amt(ptcopy, pen->width * pen->customstart->inset, TRUE);
1517 /* the direction of the line cap is parallel to the direction at the
1518 * end of the bezier (which, if it has been shortened, is not the same
1519 * as the direction from pt[count-2] to pt[count-1]) */
1520 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->endcap, pen->width, pen->customend,
1521 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
1522 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
1523 pt[count - 1].X, pt[count - 1].Y);
1525 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->startcap, pen->width, pen->customstart,
1526 pt[0].X - (ptcopy[0].X - ptcopy[1].X),
1527 pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
1530 transform_and_round_points(graphics, pti, ptcopy, count);
1532 PolyBezier(graphics->hdc, pti, count);
1543 /* Draws a combination of bezier curves and lines between points. */
1544 static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
1545 GDIPCONST BYTE * types, INT count, BOOL caps)
1547 POINT *pti = GdipAlloc(count * sizeof(POINT));
1548 BYTE *tp = GdipAlloc(count);
1549 GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
1551 GpStatus status = GenericError;
1557 if(!pti || !tp || !ptcopy){
1558 status = OutOfMemory;
1562 for(i = 1; i < count; i++){
1563 if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
1564 if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
1565 || !(types[i + 1] & PathPointTypeBezier)){
1566 ERR("Bad bezier points\n");
1573 memcpy(ptcopy, pt, count * sizeof(GpPointF));
1575 /* If we are drawing caps, go through the points and adjust them accordingly,
1576 * and draw the caps. */
1578 switch(types[count - 1] & PathPointTypePathTypeMask){
1579 case PathPointTypeBezier:
1580 if(pen->endcap == LineCapArrowAnchor)
1581 shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
1582 else if((pen->endcap == LineCapCustom) && pen->customend)
1583 shorten_bezier_amt(&ptcopy[count - 4],
1584 pen->width * pen->customend->inset, FALSE);
1586 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->endcap, pen->width, pen->customend,
1587 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
1588 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
1589 pt[count - 1].X, pt[count - 1].Y);
1592 case PathPointTypeLine:
1593 if(pen->endcap == LineCapArrowAnchor)
1594 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
1595 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
1597 else if((pen->endcap == LineCapCustom) && pen->customend)
1598 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
1599 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
1600 pen->customend->inset * pen->width);
1602 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->endcap, pen->width, pen->customend,
1603 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
1608 ERR("Bad path last point\n");
1612 /* Find start of points */
1613 for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
1614 == PathPointTypeStart); j++);
1616 switch(types[j] & PathPointTypePathTypeMask){
1617 case PathPointTypeBezier:
1618 if(pen->startcap == LineCapArrowAnchor)
1619 shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
1620 else if((pen->startcap == LineCapCustom) && pen->customstart)
1621 shorten_bezier_amt(&ptcopy[j - 1],
1622 pen->width * pen->customstart->inset, TRUE);
1624 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->startcap, pen->width, pen->customstart,
1625 pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
1626 pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
1627 pt[j - 1].X, pt[j - 1].Y);
1630 case PathPointTypeLine:
1631 if(pen->startcap == LineCapArrowAnchor)
1632 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
1633 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
1635 else if((pen->startcap == LineCapCustom) && pen->customstart)
1636 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
1637 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
1638 pen->customstart->inset * pen->width);
1640 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->startcap, pen->width, pen->customstart,
1641 pt[j].X, pt[j].Y, pt[j - 1].X,
1646 ERR("Bad path points\n");
1651 transform_and_round_points(graphics, pti, ptcopy, count);
1653 for(i = 0; i < count; i++){
1654 tp[i] = convert_path_point_type(types[i]);
1657 PolyDraw(graphics->hdc, pti, tp, count);
1669 GpStatus trace_path(GpGraphics *graphics, GpPath *path)
1673 BeginPath(graphics->hdc);
1674 result = draw_poly(graphics, NULL, path->pathdata.Points,
1675 path->pathdata.Types, path->pathdata.Count, FALSE);
1676 EndPath(graphics->hdc);
1680 typedef struct _GraphicsContainerItem {
1682 GraphicsContainer contid;
1684 SmoothingMode smoothing;
1685 CompositingQuality compqual;
1686 InterpolationMode interpolation;
1687 CompositingMode compmode;
1688 TextRenderingHint texthint;
1691 PixelOffsetMode pixeloffset;
1693 GpMatrix* worldtrans;
1695 } GraphicsContainerItem;
1697 static GpStatus init_container(GraphicsContainerItem** container,
1698 GDIPCONST GpGraphics* graphics){
1701 *container = GdipAlloc(sizeof(GraphicsContainerItem));
1705 (*container)->contid = graphics->contid + 1;
1707 (*container)->smoothing = graphics->smoothing;
1708 (*container)->compqual = graphics->compqual;
1709 (*container)->interpolation = graphics->interpolation;
1710 (*container)->compmode = graphics->compmode;
1711 (*container)->texthint = graphics->texthint;
1712 (*container)->scale = graphics->scale;
1713 (*container)->unit = graphics->unit;
1714 (*container)->textcontrast = graphics->textcontrast;
1715 (*container)->pixeloffset = graphics->pixeloffset;
1717 sts = GdipCloneMatrix(graphics->worldtrans, &(*container)->worldtrans);
1719 GdipFree(*container);
1724 sts = GdipCloneRegion(graphics->clip, &(*container)->clip);
1726 GdipDeleteMatrix((*container)->worldtrans);
1727 GdipFree(*container);
1735 static void delete_container(GraphicsContainerItem* container){
1736 GdipDeleteMatrix(container->worldtrans);
1737 GdipDeleteRegion(container->clip);
1738 GdipFree(container);
1741 static GpStatus restore_container(GpGraphics* graphics,
1742 GDIPCONST GraphicsContainerItem* container){
1747 sts = GdipCloneMatrix(container->worldtrans, &newTrans);
1751 sts = GdipCloneRegion(container->clip, &newClip);
1753 GdipDeleteMatrix(newTrans);
1757 GdipDeleteMatrix(graphics->worldtrans);
1758 graphics->worldtrans = newTrans;
1760 GdipDeleteRegion(graphics->clip);
1761 graphics->clip = newClip;
1763 graphics->contid = container->contid - 1;
1765 graphics->smoothing = container->smoothing;
1766 graphics->compqual = container->compqual;
1767 graphics->interpolation = container->interpolation;
1768 graphics->compmode = container->compmode;
1769 graphics->texthint = container->texthint;
1770 graphics->scale = container->scale;
1771 graphics->unit = container->unit;
1772 graphics->textcontrast = container->textcontrast;
1773 graphics->pixeloffset = container->pixeloffset;
1778 static GpStatus get_graphics_bounds(GpGraphics* graphics, GpRectF* rect)
1784 if(graphics->hwnd) {
1785 if(!GetClientRect(graphics->hwnd, &wnd_rect))
1786 return GenericError;
1788 rect->X = wnd_rect.left;
1789 rect->Y = wnd_rect.top;
1790 rect->Width = wnd_rect.right - wnd_rect.left;
1791 rect->Height = wnd_rect.bottom - wnd_rect.top;
1792 }else if (graphics->image){
1793 stat = GdipGetImageBounds(graphics->image, rect, &unit);
1794 if (stat == Ok && unit != UnitPixel)
1795 FIXME("need to convert from unit %i\n", unit);
1799 rect->Width = GetDeviceCaps(graphics->hdc, HORZRES);
1800 rect->Height = GetDeviceCaps(graphics->hdc, VERTRES);
1806 /* on success, rgn will contain the region of the graphics object which
1807 * is visible after clipping has been applied */
1808 static GpStatus get_visible_clip_region(GpGraphics *graphics, GpRegion *rgn)
1814 if((stat = get_graphics_bounds(graphics, &rectf)) != Ok)
1817 if((stat = GdipCreateRegion(&tmp)) != Ok)
1820 if((stat = GdipCombineRegionRect(tmp, &rectf, CombineModeReplace)) != Ok)
1823 if((stat = GdipCombineRegionRegion(tmp, graphics->clip, CombineModeIntersect)) != Ok)
1826 stat = GdipCombineRegionRegion(rgn, tmp, CombineModeReplace);
1829 GdipDeleteRegion(tmp);
1833 void get_font_hfont(GpGraphics *graphics, GDIPCONST GpFont *font, HFONT *hfont)
1835 HDC hdc = CreateCompatibleDC(0);
1837 REAL angle, rel_width, rel_height;
1839 HFONT unscaled_font;
1840 TEXTMETRICW textmet;
1849 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
1850 angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X));
1851 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
1852 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
1853 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
1854 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
1857 lfw.lfHeight = roundr(-font->pixel_size * rel_height);
1858 unscaled_font = CreateFontIndirectW(&lfw);
1860 SelectObject(hdc, unscaled_font);
1861 GetTextMetricsW(hdc, &textmet);
1864 lfw.lfHeight = roundr(-font->pixel_size * rel_height);
1865 lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width / rel_height);
1866 lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0);
1868 *hfont = CreateFontIndirectW(&lfw);
1871 DeleteObject(unscaled_font);
1874 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
1876 TRACE("(%p, %p)\n", hdc, graphics);
1878 return GdipCreateFromHDC2(hdc, NULL, graphics);
1881 GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **graphics)
1885 TRACE("(%p, %p, %p)\n", hdc, hDevice, graphics);
1887 if(hDevice != NULL) {
1888 FIXME("Don't know how to handle parameter hDevice\n");
1889 return NotImplemented;
1895 if(graphics == NULL)
1896 return InvalidParameter;
1898 *graphics = GdipAlloc(sizeof(GpGraphics));
1899 if(!*graphics) return OutOfMemory;
1901 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
1902 GdipFree(*graphics);
1906 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
1907 GdipFree((*graphics)->worldtrans);
1908 GdipFree(*graphics);
1912 (*graphics)->hdc = hdc;
1913 (*graphics)->hwnd = WindowFromDC(hdc);
1914 (*graphics)->owndc = FALSE;
1915 (*graphics)->smoothing = SmoothingModeDefault;
1916 (*graphics)->compqual = CompositingQualityDefault;
1917 (*graphics)->interpolation = InterpolationModeBilinear;
1918 (*graphics)->pixeloffset = PixelOffsetModeDefault;
1919 (*graphics)->compmode = CompositingModeSourceOver;
1920 (*graphics)->unit = UnitDisplay;
1921 (*graphics)->scale = 1.0;
1922 (*graphics)->busy = FALSE;
1923 (*graphics)->textcontrast = 4;
1924 list_init(&(*graphics)->containers);
1925 (*graphics)->contid = 0;
1927 TRACE("<-- %p\n", *graphics);
1932 GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics)
1936 *graphics = GdipAlloc(sizeof(GpGraphics));
1937 if(!*graphics) return OutOfMemory;
1939 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
1940 GdipFree(*graphics);
1944 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
1945 GdipFree((*graphics)->worldtrans);
1946 GdipFree(*graphics);
1950 (*graphics)->hdc = NULL;
1951 (*graphics)->hwnd = NULL;
1952 (*graphics)->owndc = FALSE;
1953 (*graphics)->image = image;
1954 (*graphics)->smoothing = SmoothingModeDefault;
1955 (*graphics)->compqual = CompositingQualityDefault;
1956 (*graphics)->interpolation = InterpolationModeBilinear;
1957 (*graphics)->pixeloffset = PixelOffsetModeDefault;
1958 (*graphics)->compmode = CompositingModeSourceOver;
1959 (*graphics)->unit = UnitDisplay;
1960 (*graphics)->scale = 1.0;
1961 (*graphics)->busy = FALSE;
1962 (*graphics)->textcontrast = 4;
1963 list_init(&(*graphics)->containers);
1964 (*graphics)->contid = 0;
1966 TRACE("<-- %p\n", *graphics);
1971 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
1976 TRACE("(%p, %p)\n", hwnd, graphics);
1980 if((ret = GdipCreateFromHDC(hdc, graphics)) != Ok)
1982 ReleaseDC(hwnd, hdc);
1986 (*graphics)->hwnd = hwnd;
1987 (*graphics)->owndc = TRUE;
1992 /* FIXME: no icm handling */
1993 GpStatus WINGDIPAPI GdipCreateFromHWNDICM(HWND hwnd, GpGraphics **graphics)
1995 TRACE("(%p, %p)\n", hwnd, graphics);
1997 return GdipCreateFromHWND(hwnd, graphics);
2000 GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
2001 GpMetafile **metafile)
2005 TRACE("(%p,%i,%p)\n", hemf, delete, metafile);
2007 if(!hemf || !metafile)
2008 return InvalidParameter;
2011 FIXME("not implemented\n");
2013 return NotImplemented;
2016 GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
2017 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
2019 IStream *stream = NULL;
2023 GpStatus retval = Ok;
2025 TRACE("(%p, %d, %p, %p)\n", hwmf, delete, placeable, metafile);
2027 if(!hwmf || !metafile || !placeable)
2028 return InvalidParameter;
2031 read = GetMetaFileBitsEx(hwmf, 0, NULL);
2033 return GenericError;
2034 copy = GdipAlloc(read);
2035 GetMetaFileBitsEx(hwmf, read, copy);
2037 hemf = SetWinMetaFileBits(read, copy, NULL, NULL);
2040 read = GetEnhMetaFileBits(hemf, 0, NULL);
2041 copy = GdipAlloc(read);
2042 GetEnhMetaFileBits(hemf, read, copy);
2043 DeleteEnhMetaFile(hemf);
2045 if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
2046 ERR("could not make stream\n");
2048 retval = GenericError;
2052 *metafile = GdipAlloc(sizeof(GpMetafile));
2054 retval = OutOfMemory;
2058 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
2059 (LPVOID*) &((*metafile)->image.picture)) != S_OK)
2061 retval = GenericError;
2066 (*metafile)->image.type = ImageTypeMetafile;
2067 memcpy(&(*metafile)->image.format, &ImageFormatWMF, sizeof(GUID));
2068 (*metafile)->image.palette_flags = 0;
2069 (*metafile)->image.palette_count = 0;
2070 (*metafile)->image.palette_size = 0;
2071 (*metafile)->image.palette_entries = NULL;
2072 (*metafile)->image.xres = (REAL)placeable->Inch;
2073 (*metafile)->image.yres = (REAL)placeable->Inch;
2074 (*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch);
2075 (*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Top) / ((REAL) placeable->Inch);
2076 (*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right
2077 - placeable->BoundingBox.Left));
2078 (*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom
2079 - placeable->BoundingBox.Top));
2080 (*metafile)->unit = UnitPixel;
2083 DeleteMetaFile(hwmf);
2085 TRACE("<-- %p\n", *metafile);
2089 GdipFree(*metafile);
2090 IStream_Release(stream);
2094 GpStatus WINGDIPAPI GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR *file,
2095 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
2097 HMETAFILE hmf = GetMetaFileW(file);
2099 TRACE("(%s, %p, %p)\n", debugstr_w(file), placeable, metafile);
2101 if(!hmf) return InvalidParameter;
2103 return GdipCreateMetafileFromWmf(hmf, TRUE, placeable, metafile);
2106 GpStatus WINGDIPAPI GdipCreateMetafileFromFile(GDIPCONST WCHAR *file,
2107 GpMetafile **metafile)
2109 FIXME("(%p, %p): stub\n", file, metafile);
2110 return NotImplemented;
2113 GpStatus WINGDIPAPI GdipCreateMetafileFromStream(IStream *stream,
2114 GpMetafile **metafile)
2116 FIXME("(%p, %p): stub\n", stream, metafile);
2117 return NotImplemented;
2120 GpStatus WINGDIPAPI GdipCreateStreamOnFile(GDIPCONST WCHAR * filename,
2121 UINT access, IStream **stream)
2126 TRACE("(%s, %u, %p)\n", debugstr_w(filename), access, stream);
2128 if(!stream || !filename)
2129 return InvalidParameter;
2131 if(access & GENERIC_WRITE)
2132 dwMode = STGM_SHARE_DENY_WRITE | STGM_WRITE | STGM_CREATE;
2133 else if(access & GENERIC_READ)
2134 dwMode = STGM_SHARE_DENY_WRITE | STGM_READ | STGM_FAILIFTHERE;
2136 return InvalidParameter;
2138 ret = SHCreateStreamOnFileW(filename, dwMode, stream);
2140 return hresult_to_status(ret);
2143 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
2145 GraphicsContainerItem *cont, *next;
2147 TRACE("(%p)\n", graphics);
2149 if(!graphics) return InvalidParameter;
2150 if(graphics->busy) return ObjectBusy;
2152 if (graphics->image && graphics->image->type == ImageTypeMetafile)
2154 stat = METAFILE_GraphicsDeleted((GpMetafile*)graphics->image);
2160 ReleaseDC(graphics->hwnd, graphics->hdc);
2162 LIST_FOR_EACH_ENTRY_SAFE(cont, next, &graphics->containers, GraphicsContainerItem, entry){
2163 list_remove(&cont->entry);
2164 delete_container(cont);
2167 GdipDeleteRegion(graphics->clip);
2168 GdipDeleteMatrix(graphics->worldtrans);
2174 GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
2175 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2177 INT save_state, num_pts;
2178 GpPointF points[MAX_ARC_PTS];
2181 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
2182 width, height, startAngle, sweepAngle);
2184 if(!graphics || !pen || width <= 0 || height <= 0)
2185 return InvalidParameter;
2192 FIXME("graphics object has no HDC\n");
2196 num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
2198 save_state = prepare_dc(graphics, pen);
2200 retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
2202 restore_dc(graphics, save_state);
2207 GpStatus WINGDIPAPI GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x,
2208 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2210 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
2211 width, height, startAngle, sweepAngle);
2213 return GdipDrawArc(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2216 GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
2217 REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
2223 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1,
2224 x2, y2, x3, y3, x4, y4);
2226 if(!graphics || !pen)
2227 return InvalidParameter;
2234 FIXME("graphics object has no HDC\n");
2247 save_state = prepare_dc(graphics, pen);
2249 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
2251 restore_dc(graphics, save_state);
2256 GpStatus WINGDIPAPI GdipDrawBezierI(GpGraphics *graphics, GpPen *pen, INT x1,
2257 INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4)
2263 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics, pen, x1, y1,
2264 x2, y2, x3, y3, x4, y4);
2266 if(!graphics || !pen)
2267 return InvalidParameter;
2274 FIXME("graphics object has no HDC\n");
2287 save_state = prepare_dc(graphics, pen);
2289 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
2291 restore_dc(graphics, save_state);
2296 GpStatus WINGDIPAPI GdipDrawBeziers(GpGraphics *graphics, GpPen *pen,
2297 GDIPCONST GpPointF *points, INT count)
2302 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2304 if(!graphics || !pen || !points || (count <= 0))
2305 return InvalidParameter;
2310 for(i = 0; i < floor(count / 4); i++){
2311 ret = GdipDrawBezier(graphics, pen,
2312 points[4*i].X, points[4*i].Y,
2313 points[4*i + 1].X, points[4*i + 1].Y,
2314 points[4*i + 2].X, points[4*i + 2].Y,
2315 points[4*i + 3].X, points[4*i + 3].Y);
2323 GpStatus WINGDIPAPI GdipDrawBeziersI(GpGraphics *graphics, GpPen *pen,
2324 GDIPCONST GpPoint *points, INT count)
2330 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2332 if(!graphics || !pen || !points || (count <= 0))
2333 return InvalidParameter;
2338 pts = GdipAlloc(sizeof(GpPointF) * count);
2342 for(i = 0; i < count; i++){
2343 pts[i].X = (REAL)points[i].X;
2344 pts[i].Y = (REAL)points[i].Y;
2347 ret = GdipDrawBeziers(graphics,pen,pts,count);
2354 GpStatus WINGDIPAPI GdipDrawClosedCurve(GpGraphics *graphics, GpPen *pen,
2355 GDIPCONST GpPointF *points, INT count)
2357 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2359 return GdipDrawClosedCurve2(graphics, pen, points, count, 1.0);
2362 GpStatus WINGDIPAPI GdipDrawClosedCurveI(GpGraphics *graphics, GpPen *pen,
2363 GDIPCONST GpPoint *points, INT count)
2365 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2367 return GdipDrawClosedCurve2I(graphics, pen, points, count, 1.0);
2370 GpStatus WINGDIPAPI GdipDrawClosedCurve2(GpGraphics *graphics, GpPen *pen,
2371 GDIPCONST GpPointF *points, INT count, REAL tension)
2376 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
2378 if(!graphics || !pen || !points || count <= 0)
2379 return InvalidParameter;
2384 if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok)
2387 stat = GdipAddPathClosedCurve2(path, points, count, tension);
2389 GdipDeletePath(path);
2393 stat = GdipDrawPath(graphics, pen, path);
2395 GdipDeletePath(path);
2400 GpStatus WINGDIPAPI GdipDrawClosedCurve2I(GpGraphics *graphics, GpPen *pen,
2401 GDIPCONST GpPoint *points, INT count, REAL tension)
2407 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
2409 if(!points || count <= 0)
2410 return InvalidParameter;
2412 ptf = GdipAlloc(sizeof(GpPointF)*count);
2416 for(i = 0; i < count; i++){
2417 ptf[i].X = (REAL)points[i].X;
2418 ptf[i].Y = (REAL)points[i].Y;
2421 stat = GdipDrawClosedCurve2(graphics, pen, ptf, count, tension);
2428 GpStatus WINGDIPAPI GdipDrawCurve(GpGraphics *graphics, GpPen *pen,
2429 GDIPCONST GpPointF *points, INT count)
2431 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2433 return GdipDrawCurve2(graphics,pen,points,count,1.0);
2436 GpStatus WINGDIPAPI GdipDrawCurveI(GpGraphics *graphics, GpPen *pen,
2437 GDIPCONST GpPoint *points, INT count)
2443 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2446 return InvalidParameter;
2448 pointsF = GdipAlloc(sizeof(GpPointF)*count);
2452 for(i = 0; i < count; i++){
2453 pointsF[i].X = (REAL)points[i].X;
2454 pointsF[i].Y = (REAL)points[i].Y;
2457 ret = GdipDrawCurve(graphics,pen,pointsF,count);
2463 /* Approximates cardinal spline with Bezier curves. */
2464 GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
2465 GDIPCONST GpPointF *points, INT count, REAL tension)
2467 /* PolyBezier expects count*3-2 points. */
2468 INT i, len_pt = count*3-2, save_state;
2470 REAL x1, x2, y1, y2;
2473 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
2475 if(!graphics || !pen)
2476 return InvalidParameter;
2482 return InvalidParameter;
2486 FIXME("graphics object has no HDC\n");
2490 pt = GdipAlloc(len_pt * sizeof(GpPointF));
2494 tension = tension * TENSION_CONST;
2496 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
2499 pt[0].X = points[0].X;
2500 pt[0].Y = points[0].Y;
2504 for(i = 0; i < count-2; i++){
2505 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
2509 pt[3*i+3].X = points[i+1].X;
2510 pt[3*i+3].Y = points[i+1].Y;
2515 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
2516 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
2518 pt[len_pt-2].X = x1;
2519 pt[len_pt-2].Y = y1;
2520 pt[len_pt-1].X = points[count-1].X;
2521 pt[len_pt-1].Y = points[count-1].Y;
2523 save_state = prepare_dc(graphics, pen);
2525 retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
2528 restore_dc(graphics, save_state);
2533 GpStatus WINGDIPAPI GdipDrawCurve2I(GpGraphics *graphics, GpPen *pen,
2534 GDIPCONST GpPoint *points, INT count, REAL tension)
2540 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
2543 return InvalidParameter;
2545 pointsF = GdipAlloc(sizeof(GpPointF)*count);
2549 for(i = 0; i < count; i++){
2550 pointsF[i].X = (REAL)points[i].X;
2551 pointsF[i].Y = (REAL)points[i].Y;
2554 ret = GdipDrawCurve2(graphics,pen,pointsF,count,tension);
2560 GpStatus WINGDIPAPI GdipDrawCurve3(GpGraphics *graphics, GpPen *pen,
2561 GDIPCONST GpPointF *points, INT count, INT offset, INT numberOfSegments,
2564 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
2566 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
2567 return InvalidParameter;
2570 return GdipDrawCurve2(graphics, pen, points + offset, numberOfSegments + 1, tension);
2573 GpStatus WINGDIPAPI GdipDrawCurve3I(GpGraphics *graphics, GpPen *pen,
2574 GDIPCONST GpPoint *points, INT count, INT offset, INT numberOfSegments,
2577 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
2583 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
2584 return InvalidParameter;
2587 return GdipDrawCurve2I(graphics, pen, points + offset, numberOfSegments + 1, tension);
2590 GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics *graphics, GpPen *pen, REAL x,
2591 REAL y, REAL width, REAL height)
2597 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
2599 if(!graphics || !pen)
2600 return InvalidParameter;
2607 FIXME("graphics object has no HDC\n");
2613 ptf[1].X = x + width;
2614 ptf[1].Y = y + height;
2616 save_state = prepare_dc(graphics, pen);
2617 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2619 transform_and_round_points(graphics, pti, ptf, 2);
2621 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
2623 restore_dc(graphics, save_state);
2628 GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics *graphics, GpPen *pen, INT x,
2629 INT y, INT width, INT height)
2631 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
2633 return GdipDrawEllipse(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2637 GpStatus WINGDIPAPI GdipDrawImage(GpGraphics *graphics, GpImage *image, REAL x, REAL y)
2642 TRACE("(%p, %p, %.2f, %.2f)\n", graphics, image, x, y);
2644 if(!graphics || !image)
2645 return InvalidParameter;
2647 GdipGetImageWidth(image, &width);
2648 GdipGetImageHeight(image, &height);
2650 /* FIXME: we should use the graphics and image dpi, somehow */
2652 points[0].X = points[2].X = x;
2653 points[0].Y = points[1].Y = y;
2654 points[1].X = x + width;
2655 points[2].Y = y + height;
2657 return GdipDrawImagePointsRect(graphics, image, points, 3, 0, 0, width, height,
2658 UnitPixel, NULL, NULL, NULL);
2661 GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x,
2664 TRACE("(%p, %p, %d, %d)\n", graphics, image, x, y);
2666 return GdipDrawImage(graphics, image, (REAL)x, (REAL)y);
2669 GpStatus WINGDIPAPI GdipDrawImagePointRect(GpGraphics *graphics, GpImage *image,
2670 REAL x, REAL y, REAL srcx, REAL srcy, REAL srcwidth, REAL srcheight,
2674 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
2676 points[0].X = points[2].X = x;
2677 points[0].Y = points[1].Y = y;
2679 /* FIXME: convert image coordinates to Graphics coordinates? */
2680 points[1].X = x + srcwidth;
2681 points[2].Y = y + srcheight;
2683 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2684 srcwidth, srcheight, srcUnit, NULL, NULL, NULL);
2687 GpStatus WINGDIPAPI GdipDrawImagePointRectI(GpGraphics *graphics, GpImage *image,
2688 INT x, INT y, INT srcx, INT srcy, INT srcwidth, INT srcheight,
2691 return GdipDrawImagePointRect(graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
2694 GpStatus WINGDIPAPI GdipDrawImagePoints(GpGraphics *graphics, GpImage *image,
2695 GDIPCONST GpPointF *dstpoints, INT count)
2699 TRACE("(%p, %p, %p, %d)\n", graphics, image, dstpoints, count);
2702 return InvalidParameter;
2704 GdipGetImageWidth(image, &width);
2705 GdipGetImageHeight(image, &height);
2707 return GdipDrawImagePointsRect(graphics, image, dstpoints, count, 0, 0,
2708 width, height, UnitPixel, NULL, NULL, NULL);
2711 GpStatus WINGDIPAPI GdipDrawImagePointsI(GpGraphics *graphics, GpImage *image,
2712 GDIPCONST GpPoint *dstpoints, INT count)
2716 TRACE("(%p, %p, %p, %d)\n", graphics, image, dstpoints, count);
2718 if (count != 3 || !dstpoints)
2719 return InvalidParameter;
2721 ptf[0].X = (REAL)dstpoints[0].X;
2722 ptf[0].Y = (REAL)dstpoints[0].Y;
2723 ptf[1].X = (REAL)dstpoints[1].X;
2724 ptf[1].Y = (REAL)dstpoints[1].Y;
2725 ptf[2].X = (REAL)dstpoints[2].X;
2726 ptf[2].Y = (REAL)dstpoints[2].Y;
2728 return GdipDrawImagePoints(graphics, image, ptf, count);
2731 GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
2732 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
2733 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
2734 DrawImageAbort callback, VOID * callbackData)
2741 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics, image, points,
2742 count, srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
2746 return NotImplemented;
2748 if(!graphics || !image || !points || count != 3)
2749 return InvalidParameter;
2751 TRACE("%s %s %s\n", debugstr_pointf(&points[0]), debugstr_pointf(&points[1]),
2752 debugstr_pointf(&points[2]));
2754 memcpy(ptf, points, 3 * sizeof(GpPointF));
2755 ptf[3].X = ptf[2].X + ptf[1].X - ptf[0].X;
2756 ptf[3].Y = ptf[2].Y + ptf[1].Y - ptf[0].Y;
2757 if (!srcwidth || !srcheight || ptf[3].X == ptf[0].X || ptf[3].Y == ptf[0].Y)
2759 transform_and_round_points(graphics, pti, ptf, 4);
2765 FIXME("graphics object has no HDC\n");
2768 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2769 if(srcUnit == UnitInch)
2770 dx = dy = (REAL) INCH_HIMETRIC;
2771 else if(srcUnit == UnitPixel){
2772 dx = ((REAL) INCH_HIMETRIC) /
2773 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
2774 dy = ((REAL) INCH_HIMETRIC) /
2775 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
2778 return NotImplemented;
2780 if(IPicture_Render(image->picture, graphics->hdc,
2781 pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
2782 srcx * dx, srcy * dy,
2783 srcwidth * dx, srcheight * dy,
2786 callback(callbackData);
2787 return GenericError;
2790 else if (image->type == ImageTypeBitmap)
2792 GpBitmap* bitmap = (GpBitmap*)image;
2795 if (srcUnit == UnitInch)
2796 dx = dy = 96.0; /* FIXME: use the image resolution */
2797 else if (srcUnit == UnitPixel)
2800 return NotImplemented;
2804 srcwidth = srcwidth * dx;
2805 srcheight = srcheight * dy;
2807 if (imageAttributes ||
2808 (graphics->image && graphics->image->type == ImageTypeBitmap) ||
2809 !((GpBitmap*)image)->hbitmap ||
2810 ptf[1].Y != ptf[0].Y || ptf[2].X != ptf[0].X ||
2811 ptf[1].X - ptf[0].X != srcwidth || ptf[2].Y - ptf[0].Y != srcheight ||
2812 srcx < 0 || srcy < 0 ||
2813 srcx + srcwidth > bitmap->width || srcy + srcheight > bitmap->height)
2820 int i, x, y, src_stride, dst_stride;
2821 GpMatrix *dst_to_src;
2822 REAL m11, m12, m21, m22, mdx, mdy;
2823 LPBYTE src_data, dst_data;
2824 BitmapData lockeddata;
2825 InterpolationMode interpolation = graphics->interpolation;
2826 GpPointF dst_to_src_points[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
2827 REAL x_dx, x_dy, y_dx, y_dy;
2828 static const GpImageAttributes defaultImageAttributes = {WrapModeClamp, 0, FALSE};
2830 if (!imageAttributes)
2831 imageAttributes = &defaultImageAttributes;
2833 dst_area.left = dst_area.right = pti[0].x;
2834 dst_area.top = dst_area.bottom = pti[0].y;
2837 if (dst_area.left > pti[i].x) dst_area.left = pti[i].x;
2838 if (dst_area.right < pti[i].x) dst_area.right = pti[i].x;
2839 if (dst_area.top > pti[i].y) dst_area.top = pti[i].y;
2840 if (dst_area.bottom < pti[i].y) dst_area.bottom = pti[i].y;
2843 m11 = (ptf[1].X - ptf[0].X) / srcwidth;
2844 m21 = (ptf[2].X - ptf[0].X) / srcheight;
2845 mdx = ptf[0].X - m11 * srcx - m21 * srcy;
2846 m12 = (ptf[1].Y - ptf[0].Y) / srcwidth;
2847 m22 = (ptf[2].Y - ptf[0].Y) / srcheight;
2848 mdy = ptf[0].Y - m12 * srcx - m22 * srcy;
2850 stat = GdipCreateMatrix2(m11, m12, m21, m22, mdx, mdy, &dst_to_src);
2851 if (stat != Ok) return stat;
2853 stat = GdipInvertMatrix(dst_to_src);
2856 GdipDeleteMatrix(dst_to_src);
2860 dst_data = GdipAlloc(sizeof(ARGB) * (dst_area.right - dst_area.left) * (dst_area.bottom - dst_area.top));
2863 GdipDeleteMatrix(dst_to_src);
2867 dst_stride = sizeof(ARGB) * (dst_area.right - dst_area.left);
2869 get_bitmap_sample_size(interpolation, imageAttributes->wrap,
2870 bitmap, srcx, srcy, srcwidth, srcheight, &src_area);
2872 src_data = GdipAlloc(sizeof(ARGB) * src_area.Width * src_area.Height);
2876 GdipDeleteMatrix(dst_to_src);
2879 src_stride = sizeof(ARGB) * src_area.Width;
2881 /* Read the bits we need from the source bitmap into an ARGB buffer. */
2882 lockeddata.Width = src_area.Width;
2883 lockeddata.Height = src_area.Height;
2884 lockeddata.Stride = src_stride;
2885 lockeddata.PixelFormat = PixelFormat32bppARGB;
2886 lockeddata.Scan0 = src_data;
2888 stat = GdipBitmapLockBits(bitmap, &src_area, ImageLockModeRead|ImageLockModeUserInputBuf,
2889 PixelFormat32bppARGB, &lockeddata);
2892 stat = GdipBitmapUnlockBits(bitmap, &lockeddata);
2896 if (src_data != dst_data)
2899 GdipDeleteMatrix(dst_to_src);
2903 apply_image_attributes(imageAttributes, src_data,
2904 src_area.Width, src_area.Height,
2905 src_stride, ColorAdjustTypeBitmap);
2907 /* Transform the bits as needed to the destination. */
2908 GdipTransformMatrixPoints(dst_to_src, dst_to_src_points, 3);
2910 x_dx = dst_to_src_points[1].X - dst_to_src_points[0].X;
2911 x_dy = dst_to_src_points[1].Y - dst_to_src_points[0].Y;
2912 y_dx = dst_to_src_points[2].X - dst_to_src_points[0].X;
2913 y_dy = dst_to_src_points[2].Y - dst_to_src_points[0].Y;
2915 for (x=dst_area.left; x<dst_area.right; x++)
2917 for (y=dst_area.top; y<dst_area.bottom; y++)
2919 GpPointF src_pointf;
2922 src_pointf.X = dst_to_src_points[0].X + x * x_dx + y * y_dx;
2923 src_pointf.Y = dst_to_src_points[0].Y + x * x_dy + y * y_dy;
2925 dst_color = (ARGB*)(dst_data + dst_stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2927 if (src_pointf.X >= srcx && src_pointf.X < srcx + srcwidth && src_pointf.Y >= srcy && src_pointf.Y < srcy+srcheight)
2928 *dst_color = resample_bitmap_pixel(&src_area, src_data, bitmap->width, bitmap->height, &src_pointf, imageAttributes, interpolation);
2934 GdipDeleteMatrix(dst_to_src);
2938 stat = alpha_blend_pixels(graphics, dst_area.left, dst_area.top,
2939 dst_data, dst_area.right - dst_area.left, dst_area.bottom - dst_area.top, dst_stride);
2948 int temp_hdc=0, temp_bitmap=0;
2949 HBITMAP hbitmap, old_hbm=NULL;
2951 if (!(bitmap->format == PixelFormat16bppRGB555 ||
2952 bitmap->format == PixelFormat24bppRGB ||
2953 bitmap->format == PixelFormat32bppRGB ||
2954 bitmap->format == PixelFormat32bppPARGB))
2956 BITMAPINFOHEADER bih;
2958 PixelFormat dst_format;
2960 /* we can't draw a bitmap of this format directly */
2961 hdc = CreateCompatibleDC(0);
2965 bih.biSize = sizeof(BITMAPINFOHEADER);
2966 bih.biWidth = bitmap->width;
2967 bih.biHeight = -bitmap->height;
2969 bih.biBitCount = 32;
2970 bih.biCompression = BI_RGB;
2971 bih.biSizeImage = 0;
2972 bih.biXPelsPerMeter = 0;
2973 bih.biYPelsPerMeter = 0;
2975 bih.biClrImportant = 0;
2977 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
2978 (void**)&temp_bits, NULL, 0);
2980 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
2981 dst_format = PixelFormat32bppPARGB;
2983 dst_format = PixelFormat32bppRGB;
2985 convert_pixels(bitmap->width, bitmap->height,
2986 bitmap->width*4, temp_bits, dst_format,
2987 bitmap->stride, bitmap->bits, bitmap->format, bitmap->image.palette_entries);
2991 hbitmap = bitmap->hbitmap;
2993 temp_hdc = (hdc == 0);
2998 if (!hdc) hdc = CreateCompatibleDC(0);
2999 old_hbm = SelectObject(hdc, hbitmap);
3002 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
3006 bf.BlendOp = AC_SRC_OVER;
3008 bf.SourceConstantAlpha = 255;
3009 bf.AlphaFormat = AC_SRC_ALPHA;
3011 GdiAlphaBlend(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
3012 hdc, srcx, srcy, srcwidth, srcheight, bf);
3016 StretchBlt(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
3017 hdc, srcx, srcy, srcwidth, srcheight, SRCCOPY);
3022 SelectObject(hdc, old_hbm);
3027 DeleteObject(hbitmap);
3032 ERR("GpImage with no IPicture or HBITMAP?!\n");
3033 return NotImplemented;
3039 GpStatus WINGDIPAPI GdipDrawImagePointsRectI(GpGraphics *graphics, GpImage *image,
3040 GDIPCONST GpPoint *points, INT count, INT srcx, INT srcy, INT srcwidth,
3041 INT srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
3042 DrawImageAbort callback, VOID * callbackData)
3044 GpPointF pointsF[3];
3047 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics, image, points, count,
3048 srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
3051 if(!points || count!=3)
3052 return InvalidParameter;
3054 for(i = 0; i < count; i++){
3055 pointsF[i].X = (REAL)points[i].X;
3056 pointsF[i].Y = (REAL)points[i].Y;
3059 return GdipDrawImagePointsRect(graphics, image, pointsF, count, (REAL)srcx, (REAL)srcy,
3060 (REAL)srcwidth, (REAL)srcheight, srcUnit, imageAttributes,
3061 callback, callbackData);
3064 GpStatus WINGDIPAPI GdipDrawImageRectRect(GpGraphics *graphics, GpImage *image,
3065 REAL dstx, REAL dsty, REAL dstwidth, REAL dstheight, REAL srcx, REAL srcy,
3066 REAL srcwidth, REAL srcheight, GpUnit srcUnit,
3067 GDIPCONST GpImageAttributes* imageattr, DrawImageAbort callback,
3068 VOID * callbackData)
3072 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3073 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
3074 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
3078 points[1].X = dstx + dstwidth;
3081 points[2].Y = dsty + dstheight;
3083 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
3084 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
3087 GpStatus WINGDIPAPI GdipDrawImageRectRectI(GpGraphics *graphics, GpImage *image,
3088 INT dstx, INT dsty, INT dstwidth, INT dstheight, INT srcx, INT srcy,
3089 INT srcwidth, INT srcheight, GpUnit srcUnit,
3090 GDIPCONST GpImageAttributes* imageAttributes, DrawImageAbort callback,
3091 VOID * callbackData)
3095 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3096 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
3097 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
3101 points[1].X = dstx + dstwidth;
3104 points[2].Y = dsty + dstheight;
3106 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
3107 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
3110 GpStatus WINGDIPAPI GdipDrawImageRect(GpGraphics *graphics, GpImage *image,
3111 REAL x, REAL y, REAL width, REAL height)
3117 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, image, x, y, width, height);
3119 if(!graphics || !image)
3120 return InvalidParameter;
3122 ret = GdipGetImageBounds(image, &bounds, &unit);
3126 return GdipDrawImageRectRect(graphics, image, x, y, width, height,
3127 bounds.X, bounds.Y, bounds.Width, bounds.Height,
3128 unit, NULL, NULL, NULL);
3131 GpStatus WINGDIPAPI GdipDrawImageRectI(GpGraphics *graphics, GpImage *image,
3132 INT x, INT y, INT width, INT height)
3134 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, image, x, y, width, height);
3136 return GdipDrawImageRect(graphics, image, (REAL)x, (REAL)y, (REAL)width, (REAL)height);
3139 GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1,
3140 REAL y1, REAL x2, REAL y2)
3146 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1, x2, y2);
3148 if(!pen || !graphics)
3149 return InvalidParameter;
3156 FIXME("graphics object has no HDC\n");
3165 save_state = prepare_dc(graphics, pen);
3167 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
3169 restore_dc(graphics, save_state);
3174 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
3175 INT y1, INT x2, INT y2)
3181 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x1, y1, x2, y2);
3183 if(!pen || !graphics)
3184 return InvalidParameter;
3191 FIXME("graphics object has no HDC\n");
3200 save_state = prepare_dc(graphics, pen);
3202 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
3204 restore_dc(graphics, save_state);
3209 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
3210 GpPointF *points, INT count)
3215 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
3217 if(!pen || !graphics || (count < 2))
3218 return InvalidParameter;
3225 FIXME("graphics object has no HDC\n");
3229 save_state = prepare_dc(graphics, pen);
3231 retval = draw_polyline(graphics, pen, points, count, TRUE);
3233 restore_dc(graphics, save_state);
3238 GpStatus WINGDIPAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, GDIPCONST
3239 GpPoint *points, INT count)
3243 GpPointF *ptf = NULL;
3246 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
3248 if(!pen || !graphics || (count < 2))
3249 return InvalidParameter;
3256 FIXME("graphics object has no HDC\n");
3260 ptf = GdipAlloc(count * sizeof(GpPointF));
3261 if(!ptf) return OutOfMemory;
3263 for(i = 0; i < count; i ++){
3264 ptf[i].X = (REAL) points[i].X;
3265 ptf[i].Y = (REAL) points[i].Y;
3268 save_state = prepare_dc(graphics, pen);
3270 retval = draw_polyline(graphics, pen, ptf, count, TRUE);
3272 restore_dc(graphics, save_state);
3278 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
3283 TRACE("(%p, %p, %p)\n", graphics, pen, path);
3285 if(!pen || !graphics)
3286 return InvalidParameter;
3293 FIXME("graphics object has no HDC\n");
3297 save_state = prepare_dc(graphics, pen);
3299 retval = draw_poly(graphics, pen, path->pathdata.Points,
3300 path->pathdata.Types, path->pathdata.Count, TRUE);
3302 restore_dc(graphics, save_state);
3307 GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
3308 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
3312 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
3313 width, height, startAngle, sweepAngle);
3315 if(!graphics || !pen)
3316 return InvalidParameter;
3323 FIXME("graphics object has no HDC\n");
3327 save_state = prepare_dc(graphics, pen);
3328 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
3330 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
3332 restore_dc(graphics, save_state);
3337 GpStatus WINGDIPAPI GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x,
3338 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
3340 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
3341 width, height, startAngle, sweepAngle);
3343 return GdipDrawPie(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
3346 GpStatus WINGDIPAPI GdipDrawRectangle(GpGraphics *graphics, GpPen *pen, REAL x,
3347 REAL y, REAL width, REAL height)
3353 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
3355 if(!pen || !graphics)
3356 return InvalidParameter;
3363 FIXME("graphics object has no HDC\n");
3369 ptf[1].X = x + width;
3371 ptf[2].X = x + width;
3372 ptf[2].Y = y + height;
3374 ptf[3].Y = y + height;
3376 save_state = prepare_dc(graphics, pen);
3377 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
3379 transform_and_round_points(graphics, pti, ptf, 4);
3380 Polygon(graphics->hdc, pti, 4);
3382 restore_dc(graphics, save_state);
3387 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
3388 INT y, INT width, INT height)
3390 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
3392 return GdipDrawRectangle(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
3395 GpStatus WINGDIPAPI GdipDrawRectangles(GpGraphics *graphics, GpPen *pen,
3396 GDIPCONST GpRectF* rects, INT count)
3402 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
3404 if(!graphics || !pen || !rects || count < 1)
3405 return InvalidParameter;
3412 FIXME("graphics object has no HDC\n");
3416 ptf = GdipAlloc(4 * count * sizeof(GpPointF));
3417 pti = GdipAlloc(4 * count * sizeof(POINT));
3425 for(i = 0; i < count; i++){
3426 ptf[4 * i + 3].X = ptf[4 * i].X = rects[i].X;
3427 ptf[4 * i + 1].Y = ptf[4 * i].Y = rects[i].Y;
3428 ptf[4 * i + 2].X = ptf[4 * i + 1].X = rects[i].X + rects[i].Width;
3429 ptf[4 * i + 3].Y = ptf[4 * i + 2].Y = rects[i].Y + rects[i].Height;
3432 save_state = prepare_dc(graphics, pen);
3433 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
3435 transform_and_round_points(graphics, pti, ptf, 4 * count);
3437 for(i = 0; i < count; i++)
3438 Polygon(graphics->hdc, &pti[4 * i], 4);
3440 restore_dc(graphics, save_state);
3448 GpStatus WINGDIPAPI GdipDrawRectanglesI(GpGraphics *graphics, GpPen *pen,
3449 GDIPCONST GpRect* rects, INT count)
3455 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
3457 if(!rects || count<=0)
3458 return InvalidParameter;
3460 rectsF = GdipAlloc(sizeof(GpRectF) * count);
3464 for(i = 0;i < count;i++){
3465 rectsF[i].X = (REAL)rects[i].X;
3466 rectsF[i].Y = (REAL)rects[i].Y;
3467 rectsF[i].Width = (REAL)rects[i].Width;
3468 rectsF[i].Height = (REAL)rects[i].Height;
3471 ret = GdipDrawRectangles(graphics, pen, rectsF, count);
3477 GpStatus WINGDIPAPI GdipFillClosedCurve2(GpGraphics *graphics, GpBrush *brush,
3478 GDIPCONST GpPointF *points, INT count, REAL tension, GpFillMode fill)
3483 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
3484 count, tension, fill);
3486 if(!graphics || !brush || !points)
3487 return InvalidParameter;
3492 if(count == 1) /* Do nothing */
3495 stat = GdipCreatePath(fill, &path);
3499 stat = GdipAddPathClosedCurve2(path, points, count, tension);
3501 GdipDeletePath(path);
3505 stat = GdipFillPath(graphics, brush, path);
3507 GdipDeletePath(path);
3511 GdipDeletePath(path);
3516 GpStatus WINGDIPAPI GdipFillClosedCurve2I(GpGraphics *graphics, GpBrush *brush,
3517 GDIPCONST GpPoint *points, INT count, REAL tension, GpFillMode fill)
3523 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
3524 count, tension, fill);
3526 if(!points || count == 0)
3527 return InvalidParameter;
3529 if(count == 1) /* Do nothing */
3532 ptf = GdipAlloc(sizeof(GpPointF)*count);
3536 for(i = 0;i < count;i++){
3537 ptf[i].X = (REAL)points[i].X;
3538 ptf[i].Y = (REAL)points[i].Y;
3541 stat = GdipFillClosedCurve2(graphics, brush, ptf, count, tension, fill);
3548 GpStatus WINGDIPAPI GdipFillClosedCurve(GpGraphics *graphics, GpBrush *brush,
3549 GDIPCONST GpPointF *points, INT count)
3551 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3552 return GdipFillClosedCurve2(graphics, brush, points, count,
3553 0.5f, FillModeAlternate);
3556 GpStatus WINGDIPAPI GdipFillClosedCurveI(GpGraphics *graphics, GpBrush *brush,
3557 GDIPCONST GpPoint *points, INT count)
3559 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3560 return GdipFillClosedCurve2I(graphics, brush, points, count,
3561 0.5f, FillModeAlternate);
3564 GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x,
3565 REAL y, REAL width, REAL height)
3570 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
3572 if(!graphics || !brush)
3573 return InvalidParameter;
3578 stat = GdipCreatePath(FillModeAlternate, &path);
3582 stat = GdipAddPathEllipse(path, x, y, width, height);
3585 stat = GdipFillPath(graphics, brush, path);
3587 GdipDeletePath(path);
3593 GpStatus WINGDIPAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x,
3594 INT y, INT width, INT height)
3596 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
3598 return GdipFillEllipse(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
3601 static GpStatus GDI32_GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
3606 if(!graphics->hdc || !brush_can_fill_path(brush))
3607 return NotImplemented;
3609 save_state = SaveDC(graphics->hdc);
3610 EndPath(graphics->hdc);
3611 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
3614 BeginPath(graphics->hdc);
3615 retval = draw_poly(graphics, NULL, path->pathdata.Points,
3616 path->pathdata.Types, path->pathdata.Count, FALSE);
3621 EndPath(graphics->hdc);
3622 brush_fill_path(graphics, brush);
3627 RestoreDC(graphics->hdc, save_state);
3632 static GpStatus SOFTWARE_GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
3637 if (!brush_can_fill_pixels(brush))
3638 return NotImplemented;
3640 /* FIXME: This could probably be done more efficiently without regions. */
3642 stat = GdipCreateRegionPath(path, &rgn);
3646 stat = GdipFillRegion(graphics, brush, rgn);
3648 GdipDeleteRegion(rgn);
3654 GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
3656 GpStatus stat = NotImplemented;
3658 TRACE("(%p, %p, %p)\n", graphics, brush, path);
3660 if(!brush || !graphics || !path)
3661 return InvalidParameter;
3666 if (!graphics->image)
3667 stat = GDI32_GdipFillPath(graphics, brush, path);
3669 if (stat == NotImplemented)
3670 stat = SOFTWARE_GdipFillPath(graphics, brush, path);
3672 if (stat == NotImplemented)
3674 FIXME("Not implemented for brushtype %i\n", brush->bt);
3681 GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
3682 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
3687 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3688 graphics, brush, x, y, width, height, startAngle, sweepAngle);
3690 if(!graphics || !brush)
3691 return InvalidParameter;
3696 stat = GdipCreatePath(FillModeAlternate, &path);
3700 stat = GdipAddPathPie(path, x, y, width, height, startAngle, sweepAngle);
3703 stat = GdipFillPath(graphics, brush, path);
3705 GdipDeletePath(path);
3711 GpStatus WINGDIPAPI GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x,
3712 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
3714 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3715 graphics, brush, x, y, width, height, startAngle, sweepAngle);
3717 return GdipFillPie(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
3720 GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush,
3721 GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)
3726 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
3728 if(!graphics || !brush || !points || !count)
3729 return InvalidParameter;
3734 stat = GdipCreatePath(fillMode, &path);
3738 stat = GdipAddPathPolygon(path, points, count);
3741 stat = GdipFillPath(graphics, brush, path);
3743 GdipDeletePath(path);
3749 GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
3750 GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
3755 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
3757 if(!graphics || !brush || !points || !count)
3758 return InvalidParameter;
3763 stat = GdipCreatePath(fillMode, &path);
3767 stat = GdipAddPathPolygonI(path, points, count);
3770 stat = GdipFillPath(graphics, brush, path);
3772 GdipDeletePath(path);
3778 GpStatus WINGDIPAPI GdipFillPolygon2(GpGraphics *graphics, GpBrush *brush,
3779 GDIPCONST GpPointF *points, INT count)
3781 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3783 return GdipFillPolygon(graphics, brush, points, count, FillModeAlternate);
3786 GpStatus WINGDIPAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush,
3787 GDIPCONST GpPoint *points, INT count)
3789 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3791 return GdipFillPolygonI(graphics, brush, points, count, FillModeAlternate);
3794 GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics *graphics, GpBrush *brush,
3795 REAL x, REAL y, REAL width, REAL height)
3800 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
3802 if(!graphics || !brush)
3803 return InvalidParameter;
3808 stat = GdipCreatePath(FillModeAlternate, &path);
3812 stat = GdipAddPathRectangle(path, x, y, width, height);
3815 stat = GdipFillPath(graphics, brush, path);
3817 GdipDeletePath(path);
3823 GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush,
3824 INT x, INT y, INT width, INT height)
3826 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
3828 return GdipFillRectangle(graphics, brush, x, y, width, height);
3831 GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRectF *rects,
3837 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3840 return InvalidParameter;
3842 for(i = 0; i < count; i++){
3843 ret = GdipFillRectangle(graphics, brush, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
3844 if(ret != Ok) return ret;
3850 GpStatus WINGDIPAPI GdipFillRectanglesI(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRect *rects,
3857 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3859 if(!rects || count <= 0)
3860 return InvalidParameter;
3862 rectsF = GdipAlloc(sizeof(GpRectF)*count);
3866 for(i = 0; i < count; i++){
3867 rectsF[i].X = (REAL)rects[i].X;
3868 rectsF[i].Y = (REAL)rects[i].Y;
3869 rectsF[i].X = (REAL)rects[i].Width;
3870 rectsF[i].Height = (REAL)rects[i].Height;
3873 ret = GdipFillRectangles(graphics,brush,rectsF,count);
3879 static GpStatus GDI32_GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
3887 if(!graphics->hdc || !brush_can_fill_path(brush))
3888 return NotImplemented;
3890 status = GdipGetRegionHRgn(region, graphics, &hrgn);
3894 save_state = SaveDC(graphics->hdc);
3895 EndPath(graphics->hdc);
3897 ExtSelectClipRgn(graphics->hdc, hrgn, RGN_AND);
3899 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
3901 BeginPath(graphics->hdc);
3902 Rectangle(graphics->hdc, rc.left, rc.top, rc.right, rc.bottom);
3903 EndPath(graphics->hdc);
3905 brush_fill_path(graphics, brush);
3908 RestoreDC(graphics->hdc, save_state);
3915 static GpStatus SOFTWARE_GdipFillRegion(GpGraphics *graphics, GpBrush *brush,
3919 GpRegion *temp_region;
3920 GpMatrix *world_to_device, *identity;
3921 GpRectF graphics_bounds;
3922 UINT scans_count, i;
3924 GpRect *scans = NULL;
3927 if (!brush_can_fill_pixels(brush))
3928 return NotImplemented;
3930 stat = get_graphics_bounds(graphics, &graphics_bounds);
3933 stat = GdipCloneRegion(region, &temp_region);
3937 stat = get_graphics_transform(graphics, CoordinateSpaceDevice,
3938 CoordinateSpaceWorld, &world_to_device);
3942 stat = GdipTransformRegion(temp_region, world_to_device);
3944 GdipDeleteMatrix(world_to_device);
3948 stat = GdipCombineRegionRect(temp_region, &graphics_bounds, CombineModeIntersect);
3951 stat = GdipCreateMatrix(&identity);
3955 stat = GdipGetRegionScansCount(temp_region, &scans_count, identity);
3957 if (stat == Ok && scans_count != 0)
3959 scans = GdipAlloc(sizeof(*scans) * scans_count);
3965 stat = GdipGetRegionScansI(temp_region, scans, &dummy, identity);
3972 GdipDeleteMatrix(identity);
3975 GdipDeleteRegion(temp_region);
3978 if (stat == Ok && scans_count == 0)
3983 if (!graphics->image)
3985 /* If we have to go through gdi32, use as few alpha blends as possible. */
3986 INT min_x, min_y, max_x, max_y;
3987 UINT data_width, data_height;
3991 max_x = scans[0].X+scans[0].Width;
3992 max_y = scans[0].Y+scans[0].Height;
3994 for (i=1; i<scans_count; i++)
3996 min_x = min(min_x, scans[i].X);
3997 min_y = min(min_y, scans[i].Y);
3998 max_x = max(max_x, scans[i].X+scans[i].Width);
3999 max_y = max(max_y, scans[i].Y+scans[i].Height);
4002 data_width = max_x - min_x;
4003 data_height = max_y - min_y;
4005 pixel_data = GdipAlloc(sizeof(*pixel_data) * data_width * data_height);
4011 for (i=0; i<scans_count; i++)
4013 stat = brush_fill_pixels(graphics, brush,
4014 pixel_data + (scans[i].X - min_x) + (scans[i].Y - min_y) * data_width,
4015 &scans[i], data_width);
4023 stat = alpha_blend_pixels(graphics, min_x, min_y,
4024 (BYTE*)pixel_data, data_width, data_height,
4028 GdipFree(pixel_data);
4035 for (i=0; i<scans_count; i++)
4037 UINT size = scans[i].Width * scans[i].Height;
4039 if (size > max_size)
4043 pixel_data = GdipAlloc(sizeof(*pixel_data) * max_size);
4049 for (i=0; i<scans_count; i++)
4051 stat = brush_fill_pixels(graphics, brush, pixel_data, &scans[i],
4056 stat = alpha_blend_pixels(graphics, scans[i].X, scans[i].Y,
4057 (BYTE*)pixel_data, scans[i].Width, scans[i].Height,
4058 scans[i].Width * 4);
4065 GdipFree(pixel_data);
4075 /*****************************************************************************
4076 * GdipFillRegion [GDIPLUS.@]
4078 GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
4081 GpStatus stat = NotImplemented;
4083 TRACE("(%p, %p, %p)\n", graphics, brush, region);
4085 if (!(graphics && brush && region))
4086 return InvalidParameter;
4091 if (!graphics->image)
4092 stat = GDI32_GdipFillRegion(graphics, brush, region);
4094 if (stat == NotImplemented)
4095 stat = SOFTWARE_GdipFillRegion(graphics, brush, region);
4097 if (stat == NotImplemented)
4099 FIXME("not implemented for brushtype %i\n", brush->bt);
4106 GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention)
4108 TRACE("(%p,%u)\n", graphics, intention);
4111 return InvalidParameter;
4116 /* We have no internal operation queue, so there's no need to clear it. */
4124 /*****************************************************************************
4125 * GdipGetClipBounds [GDIPLUS.@]
4127 GpStatus WINGDIPAPI GdipGetClipBounds(GpGraphics *graphics, GpRectF *rect)
4129 TRACE("(%p, %p)\n", graphics, rect);
4132 return InvalidParameter;
4137 return GdipGetRegionBounds(graphics->clip, graphics, rect);
4140 /*****************************************************************************
4141 * GdipGetClipBoundsI [GDIPLUS.@]
4143 GpStatus WINGDIPAPI GdipGetClipBoundsI(GpGraphics *graphics, GpRect *rect)
4145 TRACE("(%p, %p)\n", graphics, rect);
4148 return InvalidParameter;
4153 return GdipGetRegionBoundsI(graphics->clip, graphics, rect);
4156 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4157 GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics,
4158 CompositingMode *mode)
4160 TRACE("(%p, %p)\n", graphics, mode);
4162 if(!graphics || !mode)
4163 return InvalidParameter;
4168 *mode = graphics->compmode;
4173 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4174 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
4175 CompositingQuality *quality)
4177 TRACE("(%p, %p)\n", graphics, quality);
4179 if(!graphics || !quality)
4180 return InvalidParameter;
4185 *quality = graphics->compqual;
4190 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4191 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
4192 InterpolationMode *mode)
4194 TRACE("(%p, %p)\n", graphics, mode);
4196 if(!graphics || !mode)
4197 return InvalidParameter;
4202 *mode = graphics->interpolation;
4207 /* FIXME: Need to handle color depths less than 24bpp */
4208 GpStatus WINGDIPAPI GdipGetNearestColor(GpGraphics *graphics, ARGB* argb)
4210 FIXME("(%p, %p): Passing color unmodified\n", graphics, argb);
4212 if(!graphics || !argb)
4213 return InvalidParameter;
4221 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
4223 TRACE("(%p, %p)\n", graphics, scale);
4225 if(!graphics || !scale)
4226 return InvalidParameter;
4231 *scale = graphics->scale;
4236 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
4238 TRACE("(%p, %p)\n", graphics, unit);
4240 if(!graphics || !unit)
4241 return InvalidParameter;
4246 *unit = graphics->unit;
4251 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4252 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
4255 TRACE("(%p, %p)\n", graphics, mode);
4257 if(!graphics || !mode)
4258 return InvalidParameter;
4263 *mode = graphics->pixeloffset;
4268 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4269 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
4271 TRACE("(%p, %p)\n", graphics, mode);
4273 if(!graphics || !mode)
4274 return InvalidParameter;
4279 *mode = graphics->smoothing;
4284 GpStatus WINGDIPAPI GdipGetTextContrast(GpGraphics *graphics, UINT *contrast)
4286 TRACE("(%p, %p)\n", graphics, contrast);
4288 if(!graphics || !contrast)
4289 return InvalidParameter;
4291 *contrast = graphics->textcontrast;
4296 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4297 GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics,
4298 TextRenderingHint *hint)
4300 TRACE("(%p, %p)\n", graphics, hint);
4302 if(!graphics || !hint)
4303 return InvalidParameter;
4308 *hint = graphics->texthint;
4313 GpStatus WINGDIPAPI GdipGetVisibleClipBounds(GpGraphics *graphics, GpRectF *rect)
4318 TRACE("(%p, %p)\n", graphics, rect);
4320 if(!graphics || !rect)
4321 return InvalidParameter;
4326 /* intersect window and graphics clipping regions */
4327 if((stat = GdipCreateRegion(&clip_rgn)) != Ok)
4330 if((stat = get_visible_clip_region(graphics, clip_rgn)) != Ok)
4333 /* get bounds of the region */
4334 stat = GdipGetRegionBounds(clip_rgn, graphics, rect);
4337 GdipDeleteRegion(clip_rgn);
4342 GpStatus WINGDIPAPI GdipGetVisibleClipBoundsI(GpGraphics *graphics, GpRect *rect)
4347 TRACE("(%p, %p)\n", graphics, rect);
4349 if(!graphics || !rect)
4350 return InvalidParameter;
4352 if((stat = GdipGetVisibleClipBounds(graphics, &rectf)) == Ok)
4354 rect->X = roundr(rectf.X);
4355 rect->Y = roundr(rectf.Y);
4356 rect->Width = roundr(rectf.Width);
4357 rect->Height = roundr(rectf.Height);
4363 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
4365 TRACE("(%p, %p)\n", graphics, matrix);
4367 if(!graphics || !matrix)
4368 return InvalidParameter;
4373 *matrix = *graphics->worldtrans;
4377 GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color)
4383 TRACE("(%p, %x)\n", graphics, color);
4386 return InvalidParameter;
4391 if((stat = GdipCreateSolidFill(color, &brush)) != Ok)
4394 if((stat = get_graphics_bounds(graphics, &wnd_rect)) != Ok){
4395 GdipDeleteBrush((GpBrush*)brush);
4399 GdipFillRectangle(graphics, (GpBrush*)brush, wnd_rect.X, wnd_rect.Y,
4400 wnd_rect.Width, wnd_rect.Height);
4402 GdipDeleteBrush((GpBrush*)brush);
4407 GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics *graphics, BOOL *res)
4409 TRACE("(%p, %p)\n", graphics, res);
4411 if(!graphics || !res)
4412 return InvalidParameter;
4414 return GdipIsEmptyRegion(graphics->clip, graphics, res);
4417 GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics *graphics, REAL x, REAL y, BOOL *result)
4423 TRACE("(%p, %.2f, %.2f, %p)\n", graphics, x, y, result);
4425 if(!graphics || !result)
4426 return InvalidParameter;
4433 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
4434 CoordinateSpaceWorld, &pt, 1)) != Ok)
4437 if((stat = GdipCreateRegion(&rgn)) != Ok)
4440 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
4443 stat = GdipIsVisibleRegionPoint(rgn, pt.X, pt.Y, graphics, result);
4446 GdipDeleteRegion(rgn);
4450 GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics *graphics, INT x, INT y, BOOL *result)
4452 return GdipIsVisiblePoint(graphics, (REAL)x, (REAL)y, result);
4455 GpStatus WINGDIPAPI GdipIsVisibleRect(GpGraphics *graphics, REAL x, REAL y, REAL width, REAL height, BOOL *result)
4461 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics, x, y, width, height, result);
4463 if(!graphics || !result)
4464 return InvalidParameter;
4471 pts[1].X = x + width;
4472 pts[1].Y = y + height;
4474 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
4475 CoordinateSpaceWorld, pts, 2)) != Ok)
4478 pts[1].X -= pts[0].X;
4479 pts[1].Y -= pts[0].Y;
4481 if((stat = GdipCreateRegion(&rgn)) != Ok)
4484 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
4487 stat = GdipIsVisibleRegionRect(rgn, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y, graphics, result);
4490 GdipDeleteRegion(rgn);
4494 GpStatus WINGDIPAPI GdipIsVisibleRectI(GpGraphics *graphics, INT x, INT y, INT width, INT height, BOOL *result)
4496 return GdipIsVisibleRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, result);
4499 GpStatus gdip_format_string(HDC hdc,
4500 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
4501 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4502 gdip_format_string_callback callback, void *user_data)
4505 int sum = 0, height = 0, fit, fitcpy, i, j, lret, nwidth,
4506 nheight, lineend, lineno = 0;
4508 StringAlignment halign;
4512 if(length == -1) length = lstrlenW(string);
4514 stringdup = GdipAlloc((length + 1) * sizeof(WCHAR));
4515 if(!stringdup) return OutOfMemory;
4517 nwidth = roundr(rect->Width);
4518 nheight = roundr(rect->Height);
4520 if (rect->Width >= INT_MAX || rect->Width < 0.5) nwidth = INT_MAX;
4521 if (rect->Height >= INT_MAX || rect->Height < 0.5) nheight = INT_MAX;
4523 for(i = 0, j = 0; i < length; i++){
4524 /* FIXME: This makes the indexes passed to callback inaccurate. */
4525 if(!isprintW(string[i]) && (string[i] != '\n'))
4528 stringdup[j] = string[i];
4534 if (format) halign = format->align;
4535 else halign = StringAlignmentNear;
4537 while(sum < length){
4538 GetTextExtentExPointW(hdc, stringdup + sum, length - sum,
4539 nwidth, &fit, NULL, &size);
4545 for(lret = 0; lret < fit; lret++)
4546 if(*(stringdup + sum + lret) == '\n')
4549 /* Line break code (may look strange, but it imitates windows). */
4551 lineend = fit = lret; /* this is not an off-by-one error */
4552 else if(fit < (length - sum)){
4553 if(*(stringdup + sum + fit) == ' ')
4554 while(*(stringdup + sum + fit) == ' ')
4557 while(*(stringdup + sum + fit - 1) != ' '){
4560 if(*(stringdup + sum + fit) == '\t')
4569 while(*(stringdup + sum + lineend - 1) == ' ' ||
4570 *(stringdup + sum + lineend - 1) == '\t')
4576 GetTextExtentExPointW(hdc, stringdup + sum, lineend,
4577 nwidth, &j, NULL, &size);
4579 bounds.Width = size.cx;
4581 if(height + size.cy > nheight)
4582 bounds.Height = nheight - (height + size.cy);
4584 bounds.Height = size.cy;
4586 bounds.Y = rect->Y + height;
4590 case StringAlignmentNear:
4594 case StringAlignmentCenter:
4595 bounds.X = rect->X + (rect->Width/2) - (bounds.Width/2);
4597 case StringAlignmentFar:
4598 bounds.X = rect->X + rect->Width - bounds.Width;
4602 stat = callback(hdc, stringdup, sum, lineend,
4603 font, rect, format, lineno, &bounds, user_data);
4608 sum += fit + (lret < fitcpy ? 1 : 0);
4612 if(height > nheight)
4615 /* Stop if this was a linewrap (but not if it was a linebreak). */
4616 if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
4620 GdipFree(stringdup);
4625 struct measure_ranges_args {
4629 static GpStatus measure_ranges_callback(HDC hdc,
4630 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4631 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4632 INT lineno, const RectF *bounds, void *user_data)
4636 struct measure_ranges_args *args = user_data;
4638 for (i=0; i<format->range_count; i++)
4640 INT range_start = max(index, format->character_ranges[i].First);
4641 INT range_end = min(index+length, format->character_ranges[i].First+format->character_ranges[i].Length);
4642 if (range_start < range_end)
4647 range_rect.Y = bounds->Y;
4648 range_rect.Height = bounds->Height;
4650 GetTextExtentExPointW(hdc, string + index, range_start - index,
4651 INT_MAX, NULL, NULL, &range_size);
4652 range_rect.X = bounds->X + range_size.cx;
4654 GetTextExtentExPointW(hdc, string + index, range_end - index,
4655 INT_MAX, NULL, NULL, &range_size);
4656 range_rect.Width = (bounds->X + range_size.cx) - range_rect.X;
4658 stat = GdipCombineRegionRect(args->regions[i], &range_rect, CombineModeUnion);
4667 GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,
4668 GDIPCONST WCHAR* string, INT length, GDIPCONST GpFont* font,
4669 GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat *stringFormat,
4670 INT regionCount, GpRegion** regions)
4675 struct measure_ranges_args args;
4676 HDC hdc, temp_hdc=NULL;
4678 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics, debugstr_w(string),
4679 length, font, debugstr_rectf(layoutRect), stringFormat, regionCount, regions);
4681 if (!(graphics && string && font && layoutRect && stringFormat && regions))
4682 return InvalidParameter;
4684 if (regionCount < stringFormat->range_count)
4685 return InvalidParameter;
4689 hdc = temp_hdc = CreateCompatibleDC(0);
4690 if (!temp_hdc) return OutOfMemory;
4693 hdc = graphics->hdc;
4695 if (stringFormat->attr)
4696 TRACE("may be ignoring some format flags: attr %x\n", stringFormat->attr);
4698 oldfont = SelectObject(hdc, CreateFontIndirectW(&font->lfw));
4700 for (i=0; i<stringFormat->range_count; i++)
4702 stat = GdipSetEmpty(regions[i]);
4707 args.regions = regions;
4709 stat = gdip_format_string(hdc, string, length, font, layoutRect, stringFormat,
4710 measure_ranges_callback, &args);
4712 DeleteObject(SelectObject(hdc, oldfont));
4720 struct measure_string_args {
4722 INT *codepointsfitted;
4726 static GpStatus measure_string_callback(HDC hdc,
4727 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4728 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4729 INT lineno, const RectF *bounds, void *user_data)
4731 struct measure_string_args *args = user_data;
4733 if (bounds->Width > args->bounds->Width)
4734 args->bounds->Width = bounds->Width;
4736 if (bounds->Height + bounds->Y > args->bounds->Height + args->bounds->Y)
4737 args->bounds->Height = bounds->Height + bounds->Y - args->bounds->Y;
4739 if (args->codepointsfitted)
4740 *args->codepointsfitted = index + length;
4742 if (args->linesfilled)
4743 (*args->linesfilled)++;
4748 /* Find the smallest rectangle that bounds the text when it is printed in rect
4749 * according to the format options listed in format. If rect has 0 width and
4750 * height, then just find the smallest rectangle that bounds the text when it's
4751 * printed at location (rect->X, rect-Y). */
4752 GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
4753 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
4754 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
4755 INT *codepointsfitted, INT *linesfilled)
4758 struct measure_string_args args;
4759 HDC temp_hdc=NULL, hdc;
4761 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics,
4762 debugstr_wn(string, length), length, font, debugstr_rectf(rect), format,
4763 bounds, codepointsfitted, linesfilled);
4765 if(!graphics || !string || !font || !rect || !bounds)
4766 return InvalidParameter;
4770 hdc = temp_hdc = CreateCompatibleDC(0);
4771 if (!temp_hdc) return OutOfMemory;
4774 hdc = graphics->hdc;
4776 if(linesfilled) *linesfilled = 0;
4777 if(codepointsfitted) *codepointsfitted = 0;
4780 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4782 oldfont = SelectObject(hdc, CreateFontIndirectW(&font->lfw));
4784 bounds->X = rect->X;
4785 bounds->Y = rect->Y;
4786 bounds->Width = 0.0;
4787 bounds->Height = 0.0;
4789 args.bounds = bounds;
4790 args.codepointsfitted = codepointsfitted;
4791 args.linesfilled = linesfilled;
4793 gdip_format_string(hdc, string, length, font, rect, format,
4794 measure_string_callback, &args);
4796 DeleteObject(SelectObject(hdc, oldfont));
4804 struct draw_string_args {
4805 GpGraphics *graphics;
4806 GDIPCONST GpBrush *brush;
4807 REAL x, y, rel_width, rel_height, ascent;
4810 static GpStatus draw_string_callback(HDC hdc,
4811 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4812 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4813 INT lineno, const RectF *bounds, void *user_data)
4815 struct draw_string_args *args = user_data;
4818 position.X = args->x + bounds->X / args->rel_width;
4819 position.Y = args->y + bounds->Y / args->rel_height + args->ascent;
4821 return GdipDrawDriverString(args->graphics, &string[index], length, font,
4822 args->brush, &position,
4823 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance, NULL);
4826 GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string,
4827 INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect,
4828 GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush)
4832 GpPointF pt[3], rectcpy[4];
4834 REAL rel_width, rel_height;
4837 struct draw_string_args args;
4839 HDC hdc, temp_hdc=NULL;
4840 TEXTMETRICW textmetric;
4842 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length),
4843 length, font, debugstr_rectf(rect), format, brush);
4845 if(!graphics || !string || !font || !brush || !rect)
4846 return InvalidParameter;
4850 hdc = graphics->hdc;
4854 hdc = temp_hdc = CreateCompatibleDC(0);
4858 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4860 /* Should be no need to explicitly test for StringAlignmentNear as
4861 * that is default behavior if no alignment is passed. */
4862 if(format->vertalign != StringAlignmentNear){
4864 GdipMeasureString(graphics, string, length, font, rect, format, &bounds, 0, 0);
4866 if(format->vertalign == StringAlignmentCenter)
4867 offsety = (rect->Height - bounds.Height) / 2;
4868 else if(format->vertalign == StringAlignmentFar)
4869 offsety = (rect->Height - bounds.Height);
4873 save_state = SaveDC(hdc);
4881 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
4882 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
4883 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
4884 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
4885 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
4887 rectcpy[3].X = rectcpy[0].X = rect->X;
4888 rectcpy[1].Y = rectcpy[0].Y = rect->Y + offsety;
4889 rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width;
4890 rectcpy[3].Y = rectcpy[2].Y = rect->Y + offsety + rect->Height;
4891 transform_and_round_points(graphics, corners, rectcpy, 4);
4893 scaled_rect.X = 0.0;
4894 scaled_rect.Y = 0.0;
4895 scaled_rect.Width = rel_width * rect->Width;
4896 scaled_rect.Height = rel_height * rect->Height;
4898 if (roundr(scaled_rect.Width) != 0 && roundr(scaled_rect.Height) != 0)
4900 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4901 rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
4902 SelectClipRgn(hdc, rgn);
4905 get_font_hfont(graphics, font, &gdifont);
4906 SelectObject(hdc, gdifont);
4908 args.graphics = graphics;
4912 args.y = rect->Y + offsety;
4914 args.rel_width = rel_width;
4915 args.rel_height = rel_height;
4917 GetTextMetricsW(hdc, &textmetric);
4918 args.ascent = textmetric.tmAscent / rel_height;
4920 gdip_format_string(hdc, string, length, font, &scaled_rect, format,
4921 draw_string_callback, &args);
4924 DeleteObject(gdifont);
4926 RestoreDC(hdc, save_state);
4933 GpStatus WINGDIPAPI GdipResetClip(GpGraphics *graphics)
4935 TRACE("(%p)\n", graphics);
4938 return InvalidParameter;
4943 return GdipSetInfinite(graphics->clip);
4946 GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics)
4948 TRACE("(%p)\n", graphics);
4951 return InvalidParameter;
4956 graphics->worldtrans->matrix[0] = 1.0;
4957 graphics->worldtrans->matrix[1] = 0.0;
4958 graphics->worldtrans->matrix[2] = 0.0;
4959 graphics->worldtrans->matrix[3] = 1.0;
4960 graphics->worldtrans->matrix[4] = 0.0;
4961 graphics->worldtrans->matrix[5] = 0.0;
4966 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
4968 return GdipEndContainer(graphics, state);
4971 GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
4972 GpMatrixOrder order)
4974 TRACE("(%p, %.2f, %d)\n", graphics, angle, order);
4977 return InvalidParameter;
4982 return GdipRotateMatrix(graphics->worldtrans, angle, order);
4985 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
4987 return GdipBeginContainer2(graphics, state);
4990 GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics *graphics,
4991 GraphicsContainer *state)
4993 GraphicsContainerItem *container;
4996 TRACE("(%p, %p)\n", graphics, state);
4998 if(!graphics || !state)
4999 return InvalidParameter;
5001 sts = init_container(&container, graphics);
5005 list_add_head(&graphics->containers, &container->entry);
5006 *state = graphics->contid = container->contid;
5011 GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics *graphics, GDIPCONST GpRectF *dstrect, GDIPCONST GpRectF *srcrect, GpUnit unit, GraphicsContainer *state)
5013 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
5014 return NotImplemented;
5017 GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics *graphics, GDIPCONST GpRect *dstrect, GDIPCONST GpRect *srcrect, GpUnit unit, GraphicsContainer *state)
5019 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
5020 return NotImplemented;
5023 GpStatus WINGDIPAPI GdipComment(GpGraphics *graphics, UINT sizeData, GDIPCONST BYTE *data)
5025 FIXME("(%p, %d, %p): stub\n", graphics, sizeData, data);
5026 return NotImplemented;
5029 GpStatus WINGDIPAPI GdipEndContainer(GpGraphics *graphics, GraphicsContainer state)
5032 GraphicsContainerItem *container, *container2;
5034 TRACE("(%p, %x)\n", graphics, state);
5037 return InvalidParameter;
5039 LIST_FOR_EACH_ENTRY(container, &graphics->containers, GraphicsContainerItem, entry){
5040 if(container->contid == state)
5044 /* did not find a matching container */
5045 if(&container->entry == &graphics->containers)
5048 sts = restore_container(graphics, container);
5052 /* remove all of the containers on top of the found container */
5053 LIST_FOR_EACH_ENTRY_SAFE(container, container2, &graphics->containers, GraphicsContainerItem, entry){
5054 if(container->contid == state)
5056 list_remove(&container->entry);
5057 delete_container(container);
5060 list_remove(&container->entry);
5061 delete_container(container);
5066 GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
5067 REAL sy, GpMatrixOrder order)
5069 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, sx, sy, order);
5072 return InvalidParameter;
5077 return GdipScaleMatrix(graphics->worldtrans, sx, sy, order);
5080 GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics *graphics, GpGraphics *srcgraphics,
5083 TRACE("(%p, %p, %d)\n", graphics, srcgraphics, mode);
5085 if(!graphics || !srcgraphics)
5086 return InvalidParameter;
5088 return GdipCombineRegionRegion(graphics->clip, srcgraphics->clip, mode);
5091 GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
5092 CompositingMode mode)
5094 TRACE("(%p, %d)\n", graphics, mode);
5097 return InvalidParameter;
5102 graphics->compmode = mode;
5107 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
5108 CompositingQuality quality)
5110 TRACE("(%p, %d)\n", graphics, quality);
5113 return InvalidParameter;
5118 graphics->compqual = quality;
5123 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
5124 InterpolationMode mode)
5126 TRACE("(%p, %d)\n", graphics, mode);
5128 if(!graphics || mode == InterpolationModeInvalid || mode > InterpolationModeHighQualityBicubic)
5129 return InvalidParameter;
5134 if (mode == InterpolationModeDefault || mode == InterpolationModeLowQuality)
5135 mode = InterpolationModeBilinear;
5137 if (mode == InterpolationModeHighQuality)
5138 mode = InterpolationModeHighQualityBicubic;
5140 graphics->interpolation = mode;
5145 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
5147 TRACE("(%p, %.2f)\n", graphics, scale);
5149 if(!graphics || (scale <= 0.0))
5150 return InvalidParameter;
5155 graphics->scale = scale;
5160 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
5162 TRACE("(%p, %d)\n", graphics, unit);
5165 return InvalidParameter;
5170 if(unit == UnitWorld)
5171 return InvalidParameter;
5173 graphics->unit = unit;
5178 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
5181 TRACE("(%p, %d)\n", graphics, mode);
5184 return InvalidParameter;
5189 graphics->pixeloffset = mode;
5194 GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics *graphics, INT x, INT y)
5198 TRACE("(%p,%i,%i)\n", graphics, x, y);
5201 FIXME("not implemented\n");
5203 return NotImplemented;
5206 GpStatus WINGDIPAPI GdipGetRenderingOrigin(GpGraphics *graphics, INT *x, INT *y)
5210 TRACE("(%p,%p,%p)\n", graphics, x, y);
5213 FIXME("not implemented\n");
5217 return NotImplemented;
5220 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
5222 TRACE("(%p, %d)\n", graphics, mode);
5225 return InvalidParameter;
5230 graphics->smoothing = mode;
5235 GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics *graphics, UINT contrast)
5237 TRACE("(%p, %d)\n", graphics, contrast);
5240 return InvalidParameter;
5242 graphics->textcontrast = contrast;
5247 GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
5248 TextRenderingHint hint)
5250 TRACE("(%p, %d)\n", graphics, hint);
5252 if(!graphics || hint > TextRenderingHintClearTypeGridFit)
5253 return InvalidParameter;
5258 graphics->texthint = hint;
5263 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
5265 TRACE("(%p, %p)\n", graphics, matrix);
5267 if(!graphics || !matrix)
5268 return InvalidParameter;
5273 GdipDeleteMatrix(graphics->worldtrans);
5274 return GdipCloneMatrix(matrix, &graphics->worldtrans);
5277 GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
5278 REAL dy, GpMatrixOrder order)
5280 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, dx, dy, order);
5283 return InvalidParameter;
5288 return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order);
5291 /*****************************************************************************
5292 * GdipSetClipHrgn [GDIPLUS.@]
5294 GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics *graphics, HRGN hrgn, CombineMode mode)
5299 TRACE("(%p, %p, %d)\n", graphics, hrgn, mode);
5302 return InvalidParameter;
5304 status = GdipCreateRegionHrgn(hrgn, ®ion);
5308 status = GdipSetClipRegion(graphics, region, mode);
5310 GdipDeleteRegion(region);
5314 GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics *graphics, GpPath *path, CombineMode mode)
5316 TRACE("(%p, %p, %d)\n", graphics, path, mode);
5319 return InvalidParameter;
5324 return GdipCombineRegionPath(graphics->clip, path, mode);
5327 GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y,
5328 REAL width, REAL height,
5333 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics, x, y, width, height, mode);
5336 return InvalidParameter;
5344 rect.Height = height;
5346 return GdipCombineRegionRect(graphics->clip, &rect, mode);
5349 GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y,
5350 INT width, INT height,
5353 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics, x, y, width, height, mode);
5356 return InvalidParameter;
5361 return GdipSetClipRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, mode);
5364 GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
5367 TRACE("(%p, %p, %d)\n", graphics, region, mode);
5369 if(!graphics || !region)
5370 return InvalidParameter;
5375 return GdipCombineRegionRegion(graphics->clip, region, mode);
5378 GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile *metafile,
5383 TRACE("(%p,%u)\n", metafile, limitDpi);
5386 FIXME("not implemented\n");
5388 return NotImplemented;
5391 GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points,
5397 TRACE("(%p, %p, %d)\n", graphics, points, count);
5399 if(!graphics || !pen || count<=0)
5400 return InvalidParameter;
5407 FIXME("graphics object has no HDC\n");
5411 pti = GdipAlloc(sizeof(POINT) * count);
5413 save_state = prepare_dc(graphics, pen);
5414 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
5416 transform_and_round_points(graphics, pti, (GpPointF*)points, count);
5417 Polygon(graphics->hdc, pti, count);
5419 restore_dc(graphics, save_state);
5425 GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points,
5432 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
5434 if(count<=0) return InvalidParameter;
5435 ptf = GdipAlloc(sizeof(GpPointF) * count);
5437 for(i = 0;i < count; i++){
5438 ptf[i].X = (REAL)points[i].X;
5439 ptf[i].Y = (REAL)points[i].Y;
5442 ret = GdipDrawPolygon(graphics,pen,ptf,count);
5448 GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
5450 TRACE("(%p, %p)\n", graphics, dpi);
5452 if(!graphics || !dpi)
5453 return InvalidParameter;
5458 if (graphics->image)
5459 *dpi = graphics->image->xres;
5461 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
5466 GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
5468 TRACE("(%p, %p)\n", graphics, dpi);
5470 if(!graphics || !dpi)
5471 return InvalidParameter;
5476 if (graphics->image)
5477 *dpi = graphics->image->yres;
5479 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
5484 GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix,
5485 GpMatrixOrder order)
5490 TRACE("(%p, %p, %d)\n", graphics, matrix, order);
5492 if(!graphics || !matrix)
5493 return InvalidParameter;
5498 m = *(graphics->worldtrans);
5500 ret = GdipMultiplyMatrix(&m, matrix, order);
5502 *(graphics->worldtrans) = m;
5507 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5508 static const COLORREF DC_BACKGROUND_KEY = 0x0c0b0d;
5510 GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
5514 TRACE("(%p, %p)\n", graphics, hdc);
5516 if(!graphics || !hdc)
5517 return InvalidParameter;
5522 if (graphics->image && graphics->image->type == ImageTypeMetafile)
5524 stat = METAFILE_GetDC((GpMetafile*)graphics->image, hdc);
5526 else if (!graphics->hdc ||
5527 (graphics->image && graphics->image->type == ImageTypeBitmap && ((GpBitmap*)graphics->image)->format & PixelFormatAlpha))
5529 /* Create a fake HDC and fill it with a constant color. */
5533 BITMAPINFOHEADER bmih;
5536 stat = get_graphics_bounds(graphics, &bounds);
5540 graphics->temp_hbitmap_width = bounds.Width;
5541 graphics->temp_hbitmap_height = bounds.Height;
5543 bmih.biSize = sizeof(bmih);
5544 bmih.biWidth = graphics->temp_hbitmap_width;
5545 bmih.biHeight = -graphics->temp_hbitmap_height;
5547 bmih.biBitCount = 32;
5548 bmih.biCompression = BI_RGB;
5549 bmih.biSizeImage = 0;
5550 bmih.biXPelsPerMeter = 0;
5551 bmih.biYPelsPerMeter = 0;
5553 bmih.biClrImportant = 0;
5555 hbitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
5556 (void**)&graphics->temp_bits, NULL, 0);
5558 return GenericError;
5560 temp_hdc = CreateCompatibleDC(0);
5563 DeleteObject(hbitmap);
5564 return GenericError;
5567 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
5568 ((DWORD*)graphics->temp_bits)[i] = DC_BACKGROUND_KEY;
5570 SelectObject(temp_hdc, hbitmap);
5572 graphics->temp_hbitmap = hbitmap;
5573 *hdc = graphics->temp_hdc = temp_hdc;
5577 *hdc = graphics->hdc;
5581 graphics->busy = TRUE;
5586 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
5590 TRACE("(%p, %p)\n", graphics, hdc);
5592 if(!graphics || !hdc || !graphics->busy)
5593 return InvalidParameter;
5595 if (graphics->image && graphics->image->type == ImageTypeMetafile)
5597 stat = METAFILE_ReleaseDC((GpMetafile*)graphics->image, hdc);
5599 else if (graphics->temp_hdc == hdc)
5604 /* Find the pixels that have changed, and mark them as opaque. */
5605 pos = (DWORD*)graphics->temp_bits;
5606 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
5608 if (*pos != DC_BACKGROUND_KEY)
5615 /* Write the changed pixels to the real target. */
5616 alpha_blend_pixels(graphics, 0, 0, graphics->temp_bits,
5617 graphics->temp_hbitmap_width, graphics->temp_hbitmap_height,
5618 graphics->temp_hbitmap_width * 4);
5621 DeleteDC(graphics->temp_hdc);
5622 DeleteObject(graphics->temp_hbitmap);
5623 graphics->temp_hdc = NULL;
5624 graphics->temp_hbitmap = NULL;
5626 else if (hdc != graphics->hdc)
5628 stat = InvalidParameter;
5632 graphics->busy = FALSE;
5637 GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
5642 TRACE("(%p, %p)\n", graphics, region);
5644 if(!graphics || !region)
5645 return InvalidParameter;
5650 if((status = GdipCloneRegion(graphics->clip, &clip)) != Ok)
5653 /* free everything except root node and header */
5654 delete_element(®ion->node);
5655 memcpy(region, clip, sizeof(GpRegion));
5661 static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace dst_space,
5662 GpCoordinateSpace src_space, GpMatrix **matrix)
5664 GpStatus stat = GdipCreateMatrix(matrix);
5667 if (dst_space != src_space && stat == Ok)
5669 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
5671 if(graphics->unit != UnitDisplay)
5672 unitscale *= graphics->scale;
5674 /* transform from src_space to CoordinateSpacePage */
5677 case CoordinateSpaceWorld:
5678 GdipMultiplyMatrix(*matrix, graphics->worldtrans, MatrixOrderAppend);
5680 case CoordinateSpacePage:
5682 case CoordinateSpaceDevice:
5683 GdipScaleMatrix(*matrix, 1.0/unitscale, 1.0/unitscale, MatrixOrderAppend);
5687 /* transform from CoordinateSpacePage to dst_space */
5690 case CoordinateSpaceWorld:
5692 GpMatrix *inverted_transform;
5693 stat = GdipCloneMatrix(graphics->worldtrans, &inverted_transform);
5696 stat = GdipInvertMatrix(inverted_transform);
5698 GdipMultiplyMatrix(*matrix, inverted_transform, MatrixOrderAppend);
5699 GdipDeleteMatrix(inverted_transform);
5703 case CoordinateSpacePage:
5705 case CoordinateSpaceDevice:
5706 GdipScaleMatrix(*matrix, unitscale, unitscale, MatrixOrderAppend);
5713 GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space,
5714 GpCoordinateSpace src_space, GpPointF *points, INT count)
5719 if(!graphics || !points || count <= 0)
5720 return InvalidParameter;
5725 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
5727 if (src_space == dst_space) return Ok;
5729 stat = get_graphics_transform(graphics, dst_space, src_space, &matrix);
5733 stat = GdipTransformMatrixPoints(matrix, points, count);
5735 GdipDeleteMatrix(matrix);
5741 GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space,
5742 GpCoordinateSpace src_space, GpPoint *points, INT count)
5748 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
5751 return InvalidParameter;
5753 pointsF = GdipAlloc(sizeof(GpPointF) * count);
5757 for(i = 0; i < count; i++){
5758 pointsF[i].X = (REAL)points[i].X;
5759 pointsF[i].Y = (REAL)points[i].Y;
5762 ret = GdipTransformPoints(graphics, dst_space, src_space, pointsF, count);
5765 for(i = 0; i < count; i++){
5766 points[i].X = roundr(pointsF[i].X);
5767 points[i].Y = roundr(pointsF[i].Y);
5774 HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void)
5786 /*****************************************************************************
5787 * GdipTranslateClip [GDIPLUS.@]
5789 GpStatus WINGDIPAPI GdipTranslateClip(GpGraphics *graphics, REAL dx, REAL dy)
5791 TRACE("(%p, %.2f, %.2f)\n", graphics, dx, dy);
5794 return InvalidParameter;
5799 return GdipTranslateRegion(graphics->clip, dx, dy);
5802 /*****************************************************************************
5803 * GdipTranslateClipI [GDIPLUS.@]
5805 GpStatus WINGDIPAPI GdipTranslateClipI(GpGraphics *graphics, INT dx, INT dy)
5807 TRACE("(%p, %d, %d)\n", graphics, dx, dy);
5810 return InvalidParameter;
5815 return GdipTranslateRegion(graphics->clip, (REAL)dx, (REAL)dy);
5819 /*****************************************************************************
5820 * GdipMeasureDriverString [GDIPLUS.@]
5822 GpStatus WINGDIPAPI GdipMeasureDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5823 GDIPCONST GpFont *font, GDIPCONST PointF *positions,
5824 INT flags, GDIPCONST GpMatrix *matrix, RectF *boundingBox)
5826 static const INT unsupported_flags = ~(DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance);
5829 REAL min_x, min_y, max_x, max_y, x, y;
5831 TEXTMETRICW textmetric;
5832 const WORD *glyph_indices;
5833 WORD *dynamic_glyph_indices=NULL;
5834 REAL rel_width, rel_height, ascent, descent;
5837 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics, text, length, font, positions, flags, matrix, boundingBox);
5839 if (!graphics || !text || !font || !positions || !boundingBox)
5840 return InvalidParameter;
5843 length = strlenW(text);
5847 boundingBox->X = 0.0;
5848 boundingBox->Y = 0.0;
5849 boundingBox->Width = 0.0;
5850 boundingBox->Height = 0.0;
5853 if (flags & unsupported_flags)
5854 FIXME("Ignoring flags %x\n", flags & unsupported_flags);
5857 FIXME("Ignoring matrix\n");
5859 get_font_hfont(graphics, font, &hfont);
5861 hdc = CreateCompatibleDC(0);
5862 SelectObject(hdc, hfont);
5864 GetTextMetricsW(hdc, &textmetric);
5872 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
5873 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
5874 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
5875 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
5876 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
5878 if (flags & DriverStringOptionsCmapLookup)
5880 glyph_indices = dynamic_glyph_indices = GdipAlloc(sizeof(WORD) * length);
5884 DeleteObject(hfont);
5888 GetGlyphIndicesW(hdc, text, length, dynamic_glyph_indices, 0);
5891 glyph_indices = text;
5893 min_x = max_x = x = positions[0].X;
5894 min_y = max_y = y = positions[0].Y;
5896 ascent = textmetric.tmAscent / rel_height;
5897 descent = textmetric.tmDescent / rel_height;
5899 for (i=0; i<length; i++)
5904 if (!(flags & DriverStringOptionsRealizedAdvance))
5910 GetCharABCWidthsW(hdc, glyph_indices[i], glyph_indices[i], &abc);
5911 char_width = abc.abcA + abc.abcB + abc.abcB;
5913 if (min_y > y - ascent) min_y = y - ascent;
5914 if (max_y < y + descent) max_y = y + descent;
5915 if (min_x > x) min_x = x;
5917 x += char_width / rel_width;
5919 if (max_x < x) max_x = x;
5922 GdipFree(dynamic_glyph_indices);
5924 DeleteObject(hfont);
5926 boundingBox->X = min_x;
5927 boundingBox->Y = min_y;
5928 boundingBox->Width = max_x - min_x;
5929 boundingBox->Height = max_y - min_y;
5934 static GpStatus GDI32_GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5935 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
5936 GDIPCONST PointF *positions, INT flags,
5937 GDIPCONST GpMatrix *matrix )
5939 static const INT unsupported_flags = ~(DriverStringOptionsRealizedAdvance|DriverStringOptionsCmapLookup);
5945 if (flags & unsupported_flags)
5946 FIXME("Ignoring flags %x\n", flags & unsupported_flags);
5949 FIXME("Ignoring matrix\n");
5951 if (!(flags & DriverStringOptionsCmapLookup))
5952 eto_flags |= ETO_GLYPH_INDEX;
5954 save_state = SaveDC(graphics->hdc);
5955 SetBkMode(graphics->hdc, TRANSPARENT);
5956 SetTextColor(graphics->hdc, get_gdi_brush_color(brush));
5959 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, &pt, 1);
5961 get_font_hfont(graphics, font, &hfont);
5962 SelectObject(graphics->hdc, hfont);
5964 SetTextAlign(graphics->hdc, TA_BASELINE|TA_LEFT);
5966 ExtTextOutW(graphics->hdc, roundr(pt.X), roundr(pt.Y), eto_flags, NULL, text, length, NULL);
5968 RestoreDC(graphics->hdc, save_state);
5970 DeleteObject(hfont);
5975 static GpStatus SOFTWARE_GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
5976 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
5977 GDIPCONST PointF *positions, INT flags,
5978 GDIPCONST GpMatrix *matrix )
5980 static const INT unsupported_flags = ~(DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance);
5982 PointF *real_positions, real_position;
5986 int min_x=INT_MAX, min_y=INT_MAX, max_x=INT_MIN, max_y=INT_MIN, i, x, y;
5987 DWORD max_glyphsize=0;
5988 GLYPHMETRICS glyphmetrics;
5989 static const MAT2 identity = {{0,1}, {0,0}, {0,0}, {0,1}};
5992 int text_mask_stride;
5994 int pixel_data_stride;
5996 UINT ggo_flags = GGO_GRAY8_BITMAP;
6001 if (!(flags & DriverStringOptionsCmapLookup))
6002 ggo_flags |= GGO_GLYPH_INDEX;
6004 if (flags & unsupported_flags)
6005 FIXME("Ignoring flags %x\n", flags & unsupported_flags);
6008 FIXME("Ignoring matrix\n");
6010 pti = GdipAlloc(sizeof(POINT) * length);
6014 if (flags & DriverStringOptionsRealizedAdvance)
6016 real_position = positions[0];
6018 transform_and_round_points(graphics, pti, &real_position, 1);
6022 real_positions = GdipAlloc(sizeof(PointF) * length);
6023 if (!real_positions)
6029 memcpy(real_positions, positions, sizeof(PointF) * length);
6031 transform_and_round_points(graphics, pti, real_positions, length);
6033 GdipFree(real_positions);
6036 get_font_hfont(graphics, font, &hfont);
6038 hdc = CreateCompatibleDC(0);
6039 SelectObject(hdc, hfont);
6041 /* Get the boundaries of the text to be drawn */
6042 for (i=0; i<length; i++)
6045 int left, top, right, bottom;
6047 glyphsize = GetGlyphOutlineW(hdc, text[i], ggo_flags,
6048 &glyphmetrics, 0, NULL, &identity);
6050 if (glyphsize == GDI_ERROR)
6052 ERR("GetGlyphOutlineW failed\n");
6055 DeleteObject(hfont);
6056 return GenericError;
6059 if (glyphsize > max_glyphsize)
6060 max_glyphsize = glyphsize;
6062 left = pti[i].x + glyphmetrics.gmptGlyphOrigin.x;
6063 top = pti[i].y - glyphmetrics.gmptGlyphOrigin.y;
6064 right = pti[i].x + glyphmetrics.gmptGlyphOrigin.x + glyphmetrics.gmBlackBoxX;
6065 bottom = pti[i].y - glyphmetrics.gmptGlyphOrigin.y + glyphmetrics.gmBlackBoxY;
6067 if (left < min_x) min_x = left;
6068 if (top < min_y) min_y = top;
6069 if (right > max_x) max_x = right;
6070 if (bottom > max_y) max_y = bottom;
6072 if (i+1 < length && (flags & DriverStringOptionsRealizedAdvance) == DriverStringOptionsRealizedAdvance)
6074 pti[i+1].x = pti[i].x + glyphmetrics.gmCellIncX;
6075 pti[i+1].y = pti[i].y + glyphmetrics.gmCellIncY;
6079 glyph_mask = GdipAlloc(max_glyphsize);
6080 text_mask = GdipAlloc((max_x - min_x) * (max_y - min_y));
6081 text_mask_stride = max_x - min_x;
6083 if (!(glyph_mask && text_mask))
6085 GdipFree(glyph_mask);
6086 GdipFree(text_mask);
6089 DeleteObject(hfont);
6093 /* Generate a mask for the text */
6094 for (i=0; i<length; i++)
6096 int left, top, stride;
6098 GetGlyphOutlineW(hdc, text[i], ggo_flags,
6099 &glyphmetrics, max_glyphsize, glyph_mask, &identity);
6101 left = pti[i].x + glyphmetrics.gmptGlyphOrigin.x;
6102 top = pti[i].y - glyphmetrics.gmptGlyphOrigin.y;
6103 stride = (glyphmetrics.gmBlackBoxX + 3) & (~3);
6105 for (y=0; y<glyphmetrics.gmBlackBoxY; y++)
6107 BYTE *glyph_val = glyph_mask + y * stride;
6108 BYTE *text_val = text_mask + (left - min_x) + (top - min_y + y) * text_mask_stride;
6109 for (x=0; x<glyphmetrics.gmBlackBoxX; x++)
6111 *text_val = min(64, *text_val + *glyph_val);
6120 DeleteObject(hfont);
6121 GdipFree(glyph_mask);
6123 /* get the brush data */
6124 pixel_data = GdipAlloc(4 * (max_x - min_x) * (max_y - min_y));
6127 GdipFree(text_mask);
6131 pixel_area.X = min_x;
6132 pixel_area.Y = min_y;
6133 pixel_area.Width = max_x - min_x;
6134 pixel_area.Height = max_y - min_y;
6135 pixel_data_stride = pixel_area.Width * 4;
6137 stat = brush_fill_pixels(graphics, (GpBrush*)brush, (DWORD*)pixel_data, &pixel_area, pixel_area.Width);
6140 GdipFree(text_mask);
6141 GdipFree(pixel_data);
6145 /* multiply the brush data by the mask */
6146 for (y=0; y<pixel_area.Height; y++)
6148 BYTE *text_val = text_mask + text_mask_stride * y;
6149 BYTE *pixel_val = pixel_data + pixel_data_stride * y + 3;
6150 for (x=0; x<pixel_area.Width; x++)
6152 *pixel_val = (*pixel_val) * (*text_val) / 64;
6158 GdipFree(text_mask);
6160 /* draw the result */
6161 stat = alpha_blend_pixels(graphics, min_x, min_y, pixel_data, pixel_area.Width,
6162 pixel_area.Height, pixel_data_stride);
6164 GdipFree(pixel_data);
6169 /*****************************************************************************
6170 * GdipDrawDriverString [GDIPLUS.@]
6172 GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
6173 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
6174 GDIPCONST PointF *positions, INT flags,
6175 GDIPCONST GpMatrix *matrix )
6177 GpStatus stat=NotImplemented;
6179 TRACE("(%p %s %p %p %p %d %p)\n", graphics, debugstr_wn(text, length), font, brush, positions, flags, matrix);
6181 if (!graphics || !text || !font || !brush || !positions)
6182 return InvalidParameter;
6185 length = strlenW(text);
6187 if (graphics->hdc &&
6188 ((flags & DriverStringOptionsRealizedAdvance) || length <= 1) &&
6189 brush->bt == BrushTypeSolidColor &&
6190 (((GpSolidFill*)brush)->color & 0xff000000) == 0xff000000)
6191 stat = GDI32_GdipDrawDriverString(graphics, text, length, font, brush,
6192 positions, flags, matrix);
6194 if (stat == NotImplemented)
6195 stat = SOFTWARE_GdipDrawDriverString(graphics, text, length, font, brush,
6196 positions, flags, matrix);
6201 GpStatus WINGDIPAPI GdipRecordMetafileStream(IStream *stream, HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
6202 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
6204 FIXME("(%p %p %d %p %d %p %p): stub\n", stream, hdc, type, frameRect, frameUnit, desc, metafile);
6205 return NotImplemented;
6208 /*****************************************************************************
6209 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6211 GpStatus WINGDIPAPI GdipIsVisibleClipEmpty(GpGraphics *graphics, BOOL *res)
6216 TRACE("(%p, %p)\n", graphics, res);
6218 if((stat = GdipCreateRegion(&rgn)) != Ok)
6221 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
6224 stat = GdipIsEmptyRegion(rgn, graphics, res);
6227 GdipDeleteRegion(rgn);