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)
134 BITMAPINFOHEADER bmih;
138 bmih.biSize = sizeof(bmih);
142 bmih.biBitCount = 32;
143 bmih.biCompression = BI_RGB;
144 bmih.biSizeImage = 0;
146 hbmp = CreateDIBSection(0, (BITMAPINFO *)&bmih, DIB_RGB_COLORS, (void **)&bits, NULL, 0);
149 const char *hatch_data;
151 if (get_hatch_data(hatch->hatchstyle, &hatch_data) == Ok)
153 for (y = 0; y < 8; y++)
155 for (x = 0; x < 8; x++)
157 if (hatch_data[y] & (0x80 >> x))
158 bits[y * 8 + x] = hatch->forecol;
160 bits[y * 8 + x] = hatch->backcol;
166 FIXME("Unimplemented hatch style %d\n", hatch->hatchstyle);
168 for (y = 0; y < 64; y++)
169 bits[y] = hatch->forecol;
176 static GpStatus create_gdi_logbrush(const GpBrush *brush, LOGBRUSH *lb)
180 case BrushTypeSolidColor:
182 const GpSolidFill *sf = (const GpSolidFill *)brush;
183 lb->lbStyle = BS_SOLID;
184 lb->lbColor = ARGB2COLORREF(sf->color);
189 case BrushTypeHatchFill:
191 const GpHatch *hatch = (const GpHatch *)brush;
194 hbmp = create_hatch_bitmap(hatch);
195 if (!hbmp) return OutOfMemory;
197 lb->lbStyle = BS_PATTERN;
199 lb->lbHatch = (ULONG_PTR)hbmp;
204 FIXME("unhandled brush type %d\n", brush->bt);
205 lb->lbStyle = BS_SOLID;
206 lb->lbColor = get_gdi_brush_color(brush);
212 static GpStatus free_gdi_logbrush(LOGBRUSH *lb)
217 DeleteObject((HGDIOBJ)(ULONG_PTR)lb->lbHatch);
223 static HBRUSH create_gdi_brush(const GpBrush *brush)
228 if (create_gdi_logbrush(brush, &lb) != Ok) return 0;
230 gdibrush = CreateBrushIndirect(&lb);
231 free_gdi_logbrush(&lb);
236 static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
241 INT save_state, i, numdashes;
243 DWORD dash_array[MAX_DASHLEN];
245 save_state = SaveDC(graphics->hdc);
247 EndPath(graphics->hdc);
249 if(pen->unit == UnitPixel){
253 /* Get an estimate for the amount the pen width is affected by the world
254 * transform. (This is similar to what some of the wine drivers do.) */
259 GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
260 width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
261 (pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
263 width *= pen->width * convert_unit(graphics_res(graphics),
264 pen->unit == UnitWorld ? graphics->unit : pen->unit);
267 if(pen->dash == DashStyleCustom){
268 numdashes = min(pen->numdashes, MAX_DASHLEN);
270 TRACE("dashes are: ");
271 for(i = 0; i < numdashes; i++){
272 dash_array[i] = roundr(width * pen->dashes[i]);
273 TRACE("%d, ", dash_array[i]);
275 TRACE("\n and the pen style is %x\n", pen->style);
277 create_gdi_logbrush(pen->brush, &lb);
278 gdipen = ExtCreatePen(pen->style, roundr(width), &lb,
279 numdashes, dash_array);
280 free_gdi_logbrush(&lb);
284 create_gdi_logbrush(pen->brush, &lb);
285 gdipen = ExtCreatePen(pen->style, roundr(width), &lb, 0, NULL);
286 free_gdi_logbrush(&lb);
289 SelectObject(graphics->hdc, gdipen);
294 static void restore_dc(GpGraphics *graphics, INT state)
296 DeleteObject(SelectObject(graphics->hdc, GetStockObject(NULL_PEN)));
297 RestoreDC(graphics->hdc, state);
300 static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace dst_space,
301 GpCoordinateSpace src_space, GpMatrix **matrix);
303 /* This helper applies all the changes that the points listed in ptf need in
304 * order to be drawn on the device context. In the end, this should include at
306 * -scaling by page unit
307 * -applying world transformation
308 * -converting from float to int
309 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
310 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
311 * gdi to draw, and these functions would irreparably mess with line widths.
313 static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
314 GpPointF *ptf, INT count)
320 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
322 /* apply page scale */
323 if(graphics->unit != UnitDisplay)
324 unitscale *= graphics->scale;
326 GdipCloneMatrix(graphics->worldtrans, &matrix);
327 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
328 GdipTransformMatrixPoints(matrix, ptf, count);
329 GdipDeleteMatrix(matrix);
331 for(i = 0; i < count; i++){
332 pti[i].x = roundr(ptf[i].X);
333 pti[i].y = roundr(ptf[i].Y);
337 static void gdi_alpha_blend(GpGraphics *graphics, INT dst_x, INT dst_y, INT dst_width, INT dst_height,
338 HDC hdc, INT src_x, INT src_y, INT src_width, INT src_height)
340 if (GetDeviceCaps(graphics->hdc, SHADEBLENDCAPS) == SB_NONE)
342 TRACE("alpha blending not supported by device, fallback to StretchBlt\n");
344 StretchBlt(graphics->hdc, dst_x, dst_y, dst_width, dst_height,
345 hdc, src_x, src_y, src_width, src_height, SRCCOPY);
351 bf.BlendOp = AC_SRC_OVER;
353 bf.SourceConstantAlpha = 255;
354 bf.AlphaFormat = AC_SRC_ALPHA;
356 GdiAlphaBlend(graphics->hdc, dst_x, dst_y, dst_width, dst_height,
357 hdc, src_x, src_y, src_width, src_height, bf);
361 /* Draw non-premultiplied ARGB data to the given graphics object */
362 static GpStatus alpha_blend_pixels(GpGraphics *graphics, INT dst_x, INT dst_y,
363 const BYTE *src, INT src_width, INT src_height, INT src_stride)
365 if (graphics->image && graphics->image->type == ImageTypeBitmap)
367 GpBitmap *dst_bitmap = (GpBitmap*)graphics->image;
370 for (x=0; x<src_width; x++)
372 for (y=0; y<src_height; y++)
374 ARGB dst_color, src_color;
375 GdipBitmapGetPixel(dst_bitmap, x+dst_x, y+dst_y, &dst_color);
376 src_color = ((ARGB*)(src + src_stride * y))[x];
377 GdipBitmapSetPixel(dst_bitmap, x+dst_x, y+dst_y, color_over(dst_color, src_color));
383 else if (graphics->image && graphics->image->type == ImageTypeMetafile)
385 ERR("This should not be used for metafiles; fix caller\n");
386 return NotImplemented;
392 BITMAPINFOHEADER bih;
395 hdc = CreateCompatibleDC(0);
397 bih.biSize = sizeof(BITMAPINFOHEADER);
398 bih.biWidth = src_width;
399 bih.biHeight = -src_height;
402 bih.biCompression = BI_RGB;
404 bih.biXPelsPerMeter = 0;
405 bih.biYPelsPerMeter = 0;
407 bih.biClrImportant = 0;
409 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
410 (void**)&temp_bits, NULL, 0);
412 convert_32bppARGB_to_32bppPARGB(src_width, src_height, temp_bits,
413 4 * src_width, src, src_stride);
415 SelectObject(hdc, hbitmap);
416 gdi_alpha_blend(graphics, dst_x, dst_y, src_width, src_height,
417 hdc, 0, 0, src_width, src_height);
419 DeleteObject(hbitmap);
425 static GpStatus alpha_blend_pixels_hrgn(GpGraphics *graphics, INT dst_x, INT dst_y,
426 const BYTE *src, INT src_width, INT src_height, INT src_stride, HRGN hregion)
430 if (graphics->image && graphics->image->type == ImageTypeBitmap)
436 size = GetRegionData(hregion, 0, NULL);
438 rgndata = GdipAlloc(size);
442 GetRegionData(hregion, size, rgndata);
444 rects = (RECT*)&rgndata->Buffer;
446 for (i=0; stat == Ok && i<rgndata->rdh.nCount; i++)
448 stat = alpha_blend_pixels(graphics, rects[i].left, rects[i].top,
449 &src[(rects[i].left - dst_x) * 4 + (rects[i].top - dst_y) * src_stride],
450 rects[i].right - rects[i].left, rects[i].bottom - rects[i].top,
458 else if (graphics->image && graphics->image->type == ImageTypeMetafile)
460 ERR("This should not be used for metafiles; fix caller\n");
461 return NotImplemented;
467 save = SaveDC(graphics->hdc);
469 ExtSelectClipRgn(graphics->hdc, hregion, RGN_AND);
471 stat = alpha_blend_pixels(graphics, dst_x, dst_y, src, src_width,
472 src_height, src_stride);
474 RestoreDC(graphics->hdc, save);
480 static ARGB blend_colors(ARGB start, ARGB end, REAL position)
486 a1 = (start >> 24) & 0xff;
487 a2 = (end >> 24) & 0xff;
489 a3 = (int)(a1*(1.0f - position)+a2*(position));
493 for (i=0xff; i<=0xff0000; i = i << 8)
494 result |= (int)((start&i)*(1.0f - position)+(end&i)*(position))&i;
498 static ARGB blend_line_gradient(GpLineGradient* brush, REAL position)
502 /* clamp to between 0.0 and 1.0, using the wrap mode */
503 if (brush->wrap == WrapModeTile)
505 position = fmodf(position, 1.0f);
506 if (position < 0.0f) position += 1.0f;
508 else /* WrapModeFlip* */
510 position = fmodf(position, 2.0f);
511 if (position < 0.0f) position += 2.0f;
512 if (position > 1.0f) position = 2.0f - position;
515 if (brush->blendcount == 1)
520 REAL left_blendpos, left_blendfac, right_blendpos, right_blendfac;
523 /* locate the blend positions surrounding this position */
524 while (position > brush->blendpos[i])
527 /* interpolate between the blend positions */
528 left_blendpos = brush->blendpos[i-1];
529 left_blendfac = brush->blendfac[i-1];
530 right_blendpos = brush->blendpos[i];
531 right_blendfac = brush->blendfac[i];
532 range = right_blendpos - left_blendpos;
533 blendfac = (left_blendfac * (right_blendpos - position) +
534 right_blendfac * (position - left_blendpos)) / range;
537 if (brush->pblendcount == 0)
538 return blend_colors(brush->startcolor, brush->endcolor, blendfac);
542 ARGB left_blendcolor, right_blendcolor;
543 REAL left_blendpos, right_blendpos;
545 /* locate the blend colors surrounding this position */
546 while (blendfac > brush->pblendpos[i])
549 /* interpolate between the blend colors */
550 left_blendpos = brush->pblendpos[i-1];
551 left_blendcolor = brush->pblendcolor[i-1];
552 right_blendpos = brush->pblendpos[i];
553 right_blendcolor = brush->pblendcolor[i];
554 blendfac = (blendfac - left_blendpos) / (right_blendpos - left_blendpos);
555 return blend_colors(left_blendcolor, right_blendcolor, blendfac);
559 static ARGB transform_color(ARGB color, const ColorMatrix *matrix)
563 unsigned char a, r, g, b;
565 val[0] = ((color >> 16) & 0xff) / 255.0; /* red */
566 val[1] = ((color >> 8) & 0xff) / 255.0; /* green */
567 val[2] = (color & 0xff) / 255.0; /* blue */
568 val[3] = ((color >> 24) & 0xff) / 255.0; /* alpha */
569 val[4] = 1.0; /* translation */
576 res[i] += matrix->m[j][i] * val[j];
579 a = min(max(floorf(res[3]*255.0), 0.0), 255.0);
580 r = min(max(floorf(res[0]*255.0), 0.0), 255.0);
581 g = min(max(floorf(res[1]*255.0), 0.0), 255.0);
582 b = min(max(floorf(res[2]*255.0), 0.0), 255.0);
584 return (a << 24) | (r << 16) | (g << 8) | b;
587 static int color_is_gray(ARGB color)
589 unsigned char r, g, b;
591 r = (color >> 16) & 0xff;
592 g = (color >> 8) & 0xff;
595 return (r == g) && (g == b);
598 static void apply_image_attributes(const GpImageAttributes *attributes, LPBYTE data,
599 UINT width, UINT height, INT stride, ColorAdjustType type)
603 if (attributes->colorkeys[type].enabled ||
604 attributes->colorkeys[ColorAdjustTypeDefault].enabled)
606 const struct color_key *key;
607 BYTE min_blue, min_green, min_red;
608 BYTE max_blue, max_green, max_red;
610 if (attributes->colorkeys[type].enabled)
611 key = &attributes->colorkeys[type];
613 key = &attributes->colorkeys[ColorAdjustTypeDefault];
615 min_blue = key->low&0xff;
616 min_green = (key->low>>8)&0xff;
617 min_red = (key->low>>16)&0xff;
619 max_blue = key->high&0xff;
620 max_green = (key->high>>8)&0xff;
621 max_red = (key->high>>16)&0xff;
623 for (x=0; x<width; x++)
624 for (y=0; y<height; y++)
627 BYTE blue, green, red;
628 src_color = (ARGB*)(data + stride * y + sizeof(ARGB) * x);
629 blue = *src_color&0xff;
630 green = (*src_color>>8)&0xff;
631 red = (*src_color>>16)&0xff;
632 if (blue >= min_blue && green >= min_green && red >= min_red &&
633 blue <= max_blue && green <= max_green && red <= max_red)
634 *src_color = 0x00000000;
638 if (attributes->colorremaptables[type].enabled ||
639 attributes->colorremaptables[ColorAdjustTypeDefault].enabled)
641 const struct color_remap_table *table;
643 if (attributes->colorremaptables[type].enabled)
644 table = &attributes->colorremaptables[type];
646 table = &attributes->colorremaptables[ColorAdjustTypeDefault];
648 for (x=0; x<width; x++)
649 for (y=0; y<height; y++)
652 src_color = (ARGB*)(data + stride * y + sizeof(ARGB) * x);
653 for (i=0; i<table->mapsize; i++)
655 if (*src_color == table->colormap[i].oldColor.Argb)
657 *src_color = table->colormap[i].newColor.Argb;
664 if (attributes->colormatrices[type].enabled ||
665 attributes->colormatrices[ColorAdjustTypeDefault].enabled)
667 const struct color_matrix *colormatrices;
669 if (attributes->colormatrices[type].enabled)
670 colormatrices = &attributes->colormatrices[type];
672 colormatrices = &attributes->colormatrices[ColorAdjustTypeDefault];
674 for (x=0; x<width; x++)
675 for (y=0; y<height; y++)
678 src_color = (ARGB*)(data + stride * y + sizeof(ARGB) * x);
680 if (colormatrices->flags == ColorMatrixFlagsDefault ||
681 !color_is_gray(*src_color))
683 *src_color = transform_color(*src_color, &colormatrices->colormatrix);
685 else if (colormatrices->flags == ColorMatrixFlagsAltGray)
687 *src_color = transform_color(*src_color, &colormatrices->graymatrix);
692 if (attributes->gamma_enabled[type] ||
693 attributes->gamma_enabled[ColorAdjustTypeDefault])
697 if (attributes->gamma_enabled[type])
698 gamma = attributes->gamma[type];
700 gamma = attributes->gamma[ColorAdjustTypeDefault];
702 for (x=0; x<width; x++)
703 for (y=0; y<height; y++)
706 BYTE blue, green, red;
707 src_color = (ARGB*)(data + stride * y + sizeof(ARGB) * x);
709 blue = *src_color&0xff;
710 green = (*src_color>>8)&0xff;
711 red = (*src_color>>16)&0xff;
713 /* FIXME: We should probably use a table for this. */
714 blue = floorf(powf(blue / 255.0, gamma) * 255.0);
715 green = floorf(powf(green / 255.0, gamma) * 255.0);
716 red = floorf(powf(red / 255.0, gamma) * 255.0);
718 *src_color = (*src_color & 0xff000000) | (red << 16) | (green << 8) | blue;
723 /* Given a bitmap and its source rectangle, find the smallest rectangle in the
724 * bitmap that contains all the pixels we may need to draw it. */
725 static void get_bitmap_sample_size(InterpolationMode interpolation, WrapMode wrap,
726 GpBitmap* bitmap, REAL srcx, REAL srcy, REAL srcwidth, REAL srcheight,
729 INT left, top, right, bottom;
731 switch (interpolation)
733 case InterpolationModeHighQualityBilinear:
734 case InterpolationModeHighQualityBicubic:
735 /* FIXME: Include a greater range for the prefilter? */
736 case InterpolationModeBicubic:
737 case InterpolationModeBilinear:
738 left = (INT)(floorf(srcx));
739 top = (INT)(floorf(srcy));
740 right = (INT)(ceilf(srcx+srcwidth));
741 bottom = (INT)(ceilf(srcy+srcheight));
743 case InterpolationModeNearestNeighbor:
747 right = roundr(srcx+srcwidth);
748 bottom = roundr(srcy+srcheight);
752 if (wrap == WrapModeClamp)
758 if (right >= bitmap->width)
759 right = bitmap->width-1;
760 if (bottom >= bitmap->height)
761 bottom = bitmap->height-1;
765 /* In some cases we can make the rectangle smaller here, but the logic
766 * is hard to get right, and tiling suggests we're likely to use the
767 * entire source image. */
768 if (left < 0 || right >= bitmap->width)
771 right = bitmap->width-1;
774 if (top < 0 || bottom >= bitmap->height)
777 bottom = bitmap->height-1;
783 rect->Width = right - left + 1;
784 rect->Height = bottom - top + 1;
787 static ARGB sample_bitmap_pixel(GDIPCONST GpRect *src_rect, LPBYTE bits, UINT width,
788 UINT height, INT x, INT y, GDIPCONST GpImageAttributes *attributes)
790 if (attributes->wrap == WrapModeClamp)
792 if (x < 0 || y < 0 || x >= width || y >= height)
793 return attributes->outside_color;
797 /* Tiling. Make sure co-ordinates are positive as it simplifies the math. */
799 x = width*2 + x % (width * 2);
801 y = height*2 + y % (height * 2);
803 if ((attributes->wrap & 1) == 1)
806 if ((x / width) % 2 == 0)
809 x = width - 1 - x % width;
814 if ((attributes->wrap & 2) == 2)
817 if ((y / height) % 2 == 0)
820 y = height - 1 - y % height;
826 if (x < src_rect->X || y < src_rect->Y || x >= src_rect->X + src_rect->Width || y >= src_rect->Y + src_rect->Height)
828 ERR("out of range pixel requested\n");
832 return ((DWORD*)(bits))[(x - src_rect->X) + (y - src_rect->Y) * src_rect->Width];
835 static ARGB resample_bitmap_pixel(GDIPCONST GpRect *src_rect, LPBYTE bits, UINT width,
836 UINT height, GpPointF *point, GDIPCONST GpImageAttributes *attributes,
837 InterpolationMode interpolation)
841 switch (interpolation)
845 FIXME("Unimplemented interpolation %i\n", interpolation);
847 case InterpolationModeBilinear:
850 INT leftx, rightx, topy, bottomy;
851 ARGB topleft, topright, bottomleft, bottomright;
855 leftxf = floorf(point->X);
857 rightx = (INT)ceilf(point->X);
858 topyf = floorf(point->Y);
860 bottomy = (INT)ceilf(point->Y);
862 if (leftx == rightx && topy == bottomy)
863 return sample_bitmap_pixel(src_rect, bits, width, height,
864 leftx, topy, attributes);
866 topleft = sample_bitmap_pixel(src_rect, bits, width, height,
867 leftx, topy, attributes);
868 topright = sample_bitmap_pixel(src_rect, bits, width, height,
869 rightx, topy, attributes);
870 bottomleft = sample_bitmap_pixel(src_rect, bits, width, height,
871 leftx, bottomy, attributes);
872 bottomright = sample_bitmap_pixel(src_rect, bits, width, height,
873 rightx, bottomy, attributes);
875 x_offset = point->X - leftxf;
876 top = blend_colors(topleft, topright, x_offset);
877 bottom = blend_colors(bottomleft, bottomright, x_offset);
879 return blend_colors(top, bottom, point->Y - topyf);
881 case InterpolationModeNearestNeighbor:
882 return sample_bitmap_pixel(src_rect, bits, width, height,
883 roundr(point->X), roundr(point->Y), attributes);
887 static REAL intersect_line_scanline(const GpPointF *p1, const GpPointF *p2, REAL y)
889 return (p1->X - p2->X) * (p2->Y - y) / (p2->Y - p1->Y) + p2->X;
892 static INT brush_can_fill_path(GpBrush *brush)
896 case BrushTypeSolidColor:
898 case BrushTypeHatchFill:
900 GpHatch *hatch = (GpHatch*)brush;
901 return ((hatch->forecol & 0xff000000) == 0xff000000) &&
902 ((hatch->backcol & 0xff000000) == 0xff000000);
904 case BrushTypeLinearGradient:
905 case BrushTypeTextureFill:
906 /* Gdi32 isn't much help with these, so we should use brush_fill_pixels instead. */
912 static void brush_fill_path(GpGraphics *graphics, GpBrush* brush)
916 case BrushTypeSolidColor:
918 GpSolidFill *fill = (GpSolidFill*)brush;
919 HBITMAP bmp = ARGB2BMP(fill->color);
924 /* partially transparent fill */
926 SelectClipPath(graphics->hdc, RGN_AND);
927 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
929 HDC hdc = CreateCompatibleDC(NULL);
933 SelectObject(hdc, bmp);
934 gdi_alpha_blend(graphics, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
942 /* else fall through */
946 HBRUSH gdibrush, old_brush;
948 gdibrush = create_gdi_brush(brush);
949 if (!gdibrush) return;
951 old_brush = SelectObject(graphics->hdc, gdibrush);
952 FillPath(graphics->hdc);
953 SelectObject(graphics->hdc, old_brush);
954 DeleteObject(gdibrush);
960 static INT brush_can_fill_pixels(GpBrush *brush)
964 case BrushTypeSolidColor:
965 case BrushTypeHatchFill:
966 case BrushTypeLinearGradient:
967 case BrushTypeTextureFill:
968 case BrushTypePathGradient:
975 static GpStatus brush_fill_pixels(GpGraphics *graphics, GpBrush *brush,
976 DWORD *argb_pixels, GpRect *fill_area, UINT cdwStride)
980 case BrushTypeSolidColor:
983 GpSolidFill *fill = (GpSolidFill*)brush;
984 for (x=0; x<fill_area->Width; x++)
985 for (y=0; y<fill_area->Height; y++)
986 argb_pixels[x + y*cdwStride] = fill->color;
989 case BrushTypeHatchFill:
992 GpHatch *fill = (GpHatch*)brush;
993 const char *hatch_data;
995 if (get_hatch_data(fill->hatchstyle, &hatch_data) != Ok)
996 return NotImplemented;
998 for (x=0; x<fill_area->Width; x++)
999 for (y=0; y<fill_area->Height; y++)
1003 /* FIXME: Account for the rendering origin */
1004 hx = (x + fill_area->X) % 8;
1005 hy = (y + fill_area->Y) % 8;
1007 if ((hatch_data[7-hy] & (0x80 >> hx)) != 0)
1008 argb_pixels[x + y*cdwStride] = fill->forecol;
1010 argb_pixels[x + y*cdwStride] = fill->backcol;
1015 case BrushTypeLinearGradient:
1017 GpLineGradient *fill = (GpLineGradient*)brush;
1018 GpPointF draw_points[3], line_points[3];
1020 static const GpRectF box_1 = { 0.0, 0.0, 1.0, 1.0 };
1021 GpMatrix *world_to_gradient; /* FIXME: Store this in the brush? */
1024 draw_points[0].X = fill_area->X;
1025 draw_points[0].Y = fill_area->Y;
1026 draw_points[1].X = fill_area->X+1;
1027 draw_points[1].Y = fill_area->Y;
1028 draw_points[2].X = fill_area->X;
1029 draw_points[2].Y = fill_area->Y+1;
1031 /* Transform the points to a co-ordinate space where X is the point's
1032 * position in the gradient, 0.0 being the start point and 1.0 the
1034 stat = GdipTransformPoints(graphics, CoordinateSpaceWorld,
1035 CoordinateSpaceDevice, draw_points, 3);
1039 line_points[0] = fill->startpoint;
1040 line_points[1] = fill->endpoint;
1041 line_points[2].X = fill->startpoint.X + (fill->startpoint.Y - fill->endpoint.Y);
1042 line_points[2].Y = fill->startpoint.Y + (fill->endpoint.X - fill->startpoint.X);
1044 stat = GdipCreateMatrix3(&box_1, line_points, &world_to_gradient);
1049 stat = GdipInvertMatrix(world_to_gradient);
1052 stat = GdipTransformMatrixPoints(world_to_gradient, draw_points, 3);
1054 GdipDeleteMatrix(world_to_gradient);
1059 REAL x_delta = draw_points[1].X - draw_points[0].X;
1060 REAL y_delta = draw_points[2].X - draw_points[0].X;
1062 for (y=0; y<fill_area->Height; y++)
1064 for (x=0; x<fill_area->Width; x++)
1066 REAL pos = draw_points[0].X + x * x_delta + y * y_delta;
1068 argb_pixels[x + y*cdwStride] = blend_line_gradient(fill, pos);
1075 case BrushTypeTextureFill:
1077 GpTexture *fill = (GpTexture*)brush;
1078 GpPointF draw_points[3];
1080 GpMatrix *world_to_texture;
1086 if (fill->image->type != ImageTypeBitmap)
1088 FIXME("metafile texture brushes not implemented\n");
1089 return NotImplemented;
1092 bitmap = (GpBitmap*)fill->image;
1093 src_stride = sizeof(ARGB) * bitmap->width;
1095 src_area.X = src_area.Y = 0;
1096 src_area.Width = bitmap->width;
1097 src_area.Height = bitmap->height;
1099 draw_points[0].X = fill_area->X;
1100 draw_points[0].Y = fill_area->Y;
1101 draw_points[1].X = fill_area->X+1;
1102 draw_points[1].Y = fill_area->Y;
1103 draw_points[2].X = fill_area->X;
1104 draw_points[2].Y = fill_area->Y+1;
1106 /* Transform the points to the co-ordinate space of the bitmap. */
1107 stat = GdipTransformPoints(graphics, CoordinateSpaceWorld,
1108 CoordinateSpaceDevice, draw_points, 3);
1112 stat = GdipCloneMatrix(fill->transform, &world_to_texture);
1117 stat = GdipInvertMatrix(world_to_texture);
1120 stat = GdipTransformMatrixPoints(world_to_texture, draw_points, 3);
1122 GdipDeleteMatrix(world_to_texture);
1125 if (stat == Ok && !fill->bitmap_bits)
1127 BitmapData lockeddata;
1129 fill->bitmap_bits = GdipAlloc(sizeof(ARGB) * bitmap->width * bitmap->height);
1130 if (!fill->bitmap_bits)
1135 lockeddata.Width = bitmap->width;
1136 lockeddata.Height = bitmap->height;
1137 lockeddata.Stride = src_stride;
1138 lockeddata.PixelFormat = PixelFormat32bppARGB;
1139 lockeddata.Scan0 = fill->bitmap_bits;
1141 stat = GdipBitmapLockBits(bitmap, &src_area, ImageLockModeRead|ImageLockModeUserInputBuf,
1142 PixelFormat32bppARGB, &lockeddata);
1146 stat = GdipBitmapUnlockBits(bitmap, &lockeddata);
1149 apply_image_attributes(fill->imageattributes, fill->bitmap_bits,
1150 bitmap->width, bitmap->height,
1151 src_stride, ColorAdjustTypeBitmap);
1155 GdipFree(fill->bitmap_bits);
1156 fill->bitmap_bits = NULL;
1162 REAL x_dx = draw_points[1].X - draw_points[0].X;
1163 REAL x_dy = draw_points[1].Y - draw_points[0].Y;
1164 REAL y_dx = draw_points[2].X - draw_points[0].X;
1165 REAL y_dy = draw_points[2].Y - draw_points[0].Y;
1167 for (y=0; y<fill_area->Height; y++)
1169 for (x=0; x<fill_area->Width; x++)
1172 point.X = draw_points[0].X + x * x_dx + y * y_dx;
1173 point.Y = draw_points[0].Y + y * x_dy + y * y_dy;
1175 argb_pixels[x + y*cdwStride] = resample_bitmap_pixel(
1176 &src_area, fill->bitmap_bits, bitmap->width, bitmap->height,
1177 &point, fill->imageattributes, graphics->interpolation);
1184 case BrushTypePathGradient:
1186 GpPathGradient *fill = (GpPathGradient*)brush;
1188 GpMatrix *world_to_device;
1190 int i, figure_start=0;
1191 GpPointF start_point, end_point, center_point;
1193 REAL min_yf, max_yf, line1_xf, line2_xf;
1194 INT min_y, max_y, min_x, max_x;
1197 static int transform_fixme_once;
1199 if (fill->focus.X != 0.0 || fill->focus.Y != 0.0)
1203 FIXME("path gradient focus not implemented\n");
1210 FIXME("path gradient gamma correction not implemented\n");
1213 if (fill->blendcount)
1217 FIXME("path gradient blend not implemented\n");
1220 if (fill->pblendcount)
1224 FIXME("path gradient preset blend not implemented\n");
1227 if (!transform_fixme_once)
1229 BOOL is_identity=TRUE;
1230 GdipIsMatrixIdentity(fill->transform, &is_identity);
1233 FIXME("path gradient transform not implemented\n");
1234 transform_fixme_once = 1;
1238 stat = GdipClonePath(fill->path, &flat_path);
1243 stat = get_graphics_transform(graphics, CoordinateSpaceDevice,
1244 CoordinateSpaceWorld, &world_to_device);
1247 stat = GdipTransformPath(flat_path, world_to_device);
1251 center_point = fill->center;
1252 stat = GdipTransformMatrixPoints(world_to_device, ¢er_point, 1);
1256 stat = GdipFlattenPath(flat_path, NULL, 0.5);
1258 GdipDeleteMatrix(world_to_device);
1263 GdipDeletePath(flat_path);
1267 for (i=0; i<flat_path->pathdata.Count; i++)
1269 int start_center_line=0, end_center_line=0;
1270 int seen_start=0, seen_end=0, seen_center=0;
1271 REAL center_distance;
1272 ARGB start_color, end_color;
1275 type = flat_path->pathdata.Types[i];
1277 if ((type&PathPointTypePathTypeMask) == PathPointTypeStart)
1280 start_point = flat_path->pathdata.Points[i];
1282 start_color = fill->surroundcolors[min(i, fill->surroundcolorcount-1)];
1284 if ((type&PathPointTypeCloseSubpath) == PathPointTypeCloseSubpath || i+1 >= flat_path->pathdata.Count)
1286 end_point = flat_path->pathdata.Points[figure_start];
1287 end_color = fill->surroundcolors[min(figure_start, fill->surroundcolorcount-1)];
1289 else if ((flat_path->pathdata.Types[i+1] & PathPointTypePathTypeMask) == PathPointTypeLine)
1291 end_point = flat_path->pathdata.Points[i+1];
1292 end_color = fill->surroundcolors[min(i+1, fill->surroundcolorcount-1)];
1297 outer_color = start_color;
1299 min_yf = center_point.Y;
1300 if (min_yf > start_point.Y) min_yf = start_point.Y;
1301 if (min_yf > end_point.Y) min_yf = end_point.Y;
1303 if (min_yf < fill_area->Y)
1304 min_y = fill_area->Y;
1306 min_y = (INT)ceil(min_yf);
1308 max_yf = center_point.Y;
1309 if (max_yf < start_point.Y) max_yf = start_point.Y;
1310 if (max_yf < end_point.Y) max_yf = end_point.Y;
1312 if (max_yf > fill_area->Y + fill_area->Height)
1313 max_y = fill_area->Y + fill_area->Height;
1315 max_y = (INT)ceil(max_yf);
1317 dy = end_point.Y - start_point.Y;
1318 dx = end_point.X - start_point.X;
1320 /* This is proportional to the distance from start-end line to center point. */
1321 center_distance = dy * (start_point.X - center_point.X) +
1322 dx * (center_point.Y - start_point.Y);
1324 for (y=min_y; y<max_y; y++)
1328 if (!seen_start && yf >= start_point.Y)
1331 start_center_line ^= 1;
1333 if (!seen_end && yf >= end_point.Y)
1336 end_center_line ^= 1;
1338 if (!seen_center && yf >= center_point.Y)
1341 start_center_line ^= 1;
1342 end_center_line ^= 1;
1345 if (start_center_line)
1346 line1_xf = intersect_line_scanline(&start_point, ¢er_point, yf);
1348 line1_xf = intersect_line_scanline(&start_point, &end_point, yf);
1350 if (end_center_line)
1351 line2_xf = intersect_line_scanline(&end_point, ¢er_point, yf);
1353 line2_xf = intersect_line_scanline(&start_point, &end_point, yf);
1355 if (line1_xf < line2_xf)
1357 min_x = (INT)ceil(line1_xf);
1358 max_x = (INT)ceil(line2_xf);
1362 min_x = (INT)ceil(line2_xf);
1363 max_x = (INT)ceil(line1_xf);
1366 if (min_x < fill_area->X)
1367 min_x = fill_area->X;
1368 if (max_x > fill_area->X + fill_area->Width)
1369 max_x = fill_area->X + fill_area->Width;
1371 for (x=min_x; x<max_x; x++)
1376 if (start_color != end_color)
1378 REAL blend_amount, pdy, pdx;
1379 pdy = yf - center_point.Y;
1380 pdx = xf - center_point.X;
1381 blend_amount = ( (center_point.Y - start_point.Y) * pdx + (start_point.X - center_point.X) * pdy ) / ( dy * pdx - dx * pdy );
1382 outer_color = blend_colors(start_color, end_color, blend_amount);
1385 distance = (end_point.Y - start_point.Y) * (start_point.X - xf) +
1386 (end_point.X - start_point.X) * (yf - start_point.Y);
1388 distance = distance / center_distance;
1390 argb_pixels[(x-fill_area->X) + (y-fill_area->Y)*cdwStride] =
1391 blend_colors(outer_color, fill->centercolor, distance);
1396 GdipDeletePath(flat_path);
1400 return NotImplemented;
1404 /* GdipDrawPie/GdipFillPie helper function */
1405 static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width,
1406 REAL height, REAL startAngle, REAL sweepAngle)
1413 ptf[1].X = x + width;
1414 ptf[1].Y = y + height;
1416 deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y);
1417 deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y);
1419 transform_and_round_points(graphics, pti, ptf, 4);
1421 Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x,
1422 pti[2].y, pti[3].x, pti[3].y);
1425 /* Draws the linecap the specified color and size on the hdc. The linecap is in
1426 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
1427 * should not be called on an hdc that has a path you care about. */
1428 static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
1429 const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
1431 HGDIOBJ oldbrush = NULL, oldpen = NULL;
1432 GpMatrix *matrix = NULL;
1433 HBRUSH brush = NULL;
1435 PointF ptf[4], *custptf = NULL;
1436 POINT pt[4], *custpt = NULL;
1438 REAL theta, dsmall, dbig, dx, dy = 0.0;
1443 if((x1 == x2) && (y1 == y2))
1446 theta = gdiplus_atan2(y2 - y1, x2 - x1);
1448 customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
1450 brush = CreateSolidBrush(color);
1451 lb.lbStyle = BS_SOLID;
1454 pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
1455 PS_JOIN_MITER, 1, &lb, 0,
1457 oldbrush = SelectObject(graphics->hdc, brush);
1458 oldpen = SelectObject(graphics->hdc, pen);
1465 case LineCapSquareAnchor:
1466 case LineCapDiamondAnchor:
1467 size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0;
1468 if(cap == LineCapDiamondAnchor){
1469 dsmall = cos(theta + M_PI_2) * size;
1470 dbig = sin(theta + M_PI_2) * size;
1473 dsmall = cos(theta + M_PI_4) * size;
1474 dbig = sin(theta + M_PI_4) * size;
1477 ptf[0].X = x2 - dsmall;
1478 ptf[1].X = x2 + dbig;
1480 ptf[0].Y = y2 - dbig;
1481 ptf[3].Y = y2 + dsmall;
1483 ptf[1].Y = y2 - dsmall;
1484 ptf[2].Y = y2 + dbig;
1486 ptf[3].X = x2 - dbig;
1487 ptf[2].X = x2 + dsmall;
1489 transform_and_round_points(graphics, pt, ptf, 4);
1490 Polygon(graphics->hdc, pt, 4);
1493 case LineCapArrowAnchor:
1494 size = size * 4.0 / sqrt(3.0);
1496 dx = cos(M_PI / 6.0 + theta) * size;
1497 dy = sin(M_PI / 6.0 + theta) * size;
1502 dx = cos(- M_PI / 6.0 + theta) * size;
1503 dy = sin(- M_PI / 6.0 + theta) * size;
1511 transform_and_round_points(graphics, pt, ptf, 3);
1512 Polygon(graphics->hdc, pt, 3);
1515 case LineCapRoundAnchor:
1516 dx = dy = ANCHOR_WIDTH * size / 2.0;
1523 transform_and_round_points(graphics, pt, ptf, 2);
1524 Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
1527 case LineCapTriangle:
1529 dx = cos(M_PI_2 + theta) * size;
1530 dy = sin(M_PI_2 + theta) * size;
1537 dx = cos(theta) * size;
1538 dy = sin(theta) * size;
1543 transform_and_round_points(graphics, pt, ptf, 3);
1544 Polygon(graphics->hdc, pt, 3);
1548 dx = dy = size / 2.0;
1555 dx = -cos(M_PI_2 + theta) * size;
1556 dy = -sin(M_PI_2 + theta) * size;
1563 transform_and_round_points(graphics, pt, ptf, 4);
1564 Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x,
1565 pt[2].y, pt[3].x, pt[3].y);
1572 count = custom->pathdata.Count;
1573 custptf = GdipAlloc(count * sizeof(PointF));
1574 custpt = GdipAlloc(count * sizeof(POINT));
1575 tp = GdipAlloc(count);
1577 if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok))
1580 memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF));
1582 GdipScaleMatrix(matrix, size, size, MatrixOrderAppend);
1583 GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2),
1585 GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend);
1586 GdipTransformMatrixPoints(matrix, custptf, count);
1588 transform_and_round_points(graphics, custpt, custptf, count);
1590 for(i = 0; i < count; i++)
1591 tp[i] = convert_path_point_type(custom->pathdata.Types[i]);
1594 BeginPath(graphics->hdc);
1595 PolyDraw(graphics->hdc, custpt, tp, count);
1596 EndPath(graphics->hdc);
1597 StrokeAndFillPath(graphics->hdc);
1600 PolyDraw(graphics->hdc, custpt, tp, count);
1606 GdipDeleteMatrix(matrix);
1613 SelectObject(graphics->hdc, oldbrush);
1614 SelectObject(graphics->hdc, oldpen);
1615 DeleteObject(brush);
1620 /* Shortens the line by the given percent by changing x2, y2.
1621 * If percent is > 1.0 then the line will change direction.
1622 * If percent is negative it can lengthen the line. */
1623 static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL percent)
1625 REAL dist, theta, dx, dy;
1627 if((y1 == *y2) && (x1 == *x2))
1630 dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent;
1631 theta = gdiplus_atan2((*y2 - y1), (*x2 - x1));
1632 dx = cos(theta) * dist;
1633 dy = sin(theta) * dist;
1639 /* Shortens the line by the given amount by changing x2, y2.
1640 * If the amount is greater than the distance, the line will become length 0.
1641 * If the amount is negative, it can lengthen the line. */
1642 static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt)
1644 REAL dx, dy, percent;
1648 if(dx == 0 && dy == 0)
1651 percent = amt / sqrt(dx * dx + dy * dy);
1658 shorten_line_percent(x1, y1, x2, y2, percent);
1661 /* Draws lines between the given points, and if caps is true then draws an endcap
1662 * at the end of the last line. */
1663 static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen,
1664 GDIPCONST GpPointF * pt, INT count, BOOL caps)
1667 GpPointF *ptcopy = NULL;
1668 GpStatus status = GenericError;
1673 pti = GdipAlloc(count * sizeof(POINT));
1674 ptcopy = GdipAlloc(count * sizeof(GpPointF));
1676 if(!pti || !ptcopy){
1677 status = OutOfMemory;
1681 memcpy(ptcopy, pt, count * sizeof(GpPointF));
1684 if(pen->endcap == LineCapArrowAnchor)
1685 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
1686 &ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width);
1687 else if((pen->endcap == LineCapCustom) && pen->customend)
1688 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
1689 &ptcopy[count-1].X, &ptcopy[count-1].Y,
1690 pen->customend->inset * pen->width);
1692 if(pen->startcap == LineCapArrowAnchor)
1693 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
1694 &ptcopy[0].X, &ptcopy[0].Y, pen->width);
1695 else if((pen->startcap == LineCapCustom) && pen->customstart)
1696 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
1697 &ptcopy[0].X, &ptcopy[0].Y,
1698 pen->customstart->inset * pen->width);
1700 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->endcap, pen->width, pen->customend,
1701 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
1702 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->startcap, pen->width, pen->customstart,
1703 pt[1].X, pt[1].Y, pt[0].X, pt[0].Y);
1706 transform_and_round_points(graphics, pti, ptcopy, count);
1708 if(Polyline(graphics->hdc, pti, count))
1718 /* Conducts a linear search to find the bezier points that will back off
1719 * the endpoint of the curve by a distance of amt. Linear search works
1720 * better than binary in this case because there are multiple solutions,
1721 * and binary searches often find a bad one. I don't think this is what
1722 * Windows does but short of rendering the bezier without GDI's help it's
1723 * the best we can do. If rev then work from the start of the passed points
1724 * instead of the end. */
1725 static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev)
1728 REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0;
1729 INT i, first = 0, second = 1, third = 2, fourth = 3;
1738 origx = pt[fourth].X;
1739 origy = pt[fourth].Y;
1740 memcpy(origpt, pt, sizeof(GpPointF) * 4);
1742 for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){
1743 /* reset bezier points to original values */
1744 memcpy(pt, origpt, sizeof(GpPointF) * 4);
1745 /* Perform magic on bezier points. Order is important here.*/
1746 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
1747 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
1748 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
1749 shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent);
1750 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
1751 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
1753 dx = pt[fourth].X - origx;
1754 dy = pt[fourth].Y - origy;
1756 diff = sqrt(dx * dx + dy * dy);
1757 percent += 0.0005 * amt;
1761 /* Draws bezier curves between given points, and if caps is true then draws an
1762 * endcap at the end of the last line. */
1763 static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
1764 GDIPCONST GpPointF * pt, INT count, BOOL caps)
1768 GpStatus status = GenericError;
1773 pti = GdipAlloc(count * sizeof(POINT));
1774 ptcopy = GdipAlloc(count * sizeof(GpPointF));
1776 if(!pti || !ptcopy){
1777 status = OutOfMemory;
1781 memcpy(ptcopy, pt, count * sizeof(GpPointF));
1784 if(pen->endcap == LineCapArrowAnchor)
1785 shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
1786 else if((pen->endcap == LineCapCustom) && pen->customend)
1787 shorten_bezier_amt(&ptcopy[count-4], pen->width * pen->customend->inset,
1790 if(pen->startcap == LineCapArrowAnchor)
1791 shorten_bezier_amt(ptcopy, pen->width, TRUE);
1792 else if((pen->startcap == LineCapCustom) && pen->customstart)
1793 shorten_bezier_amt(ptcopy, pen->width * pen->customstart->inset, TRUE);
1795 /* the direction of the line cap is parallel to the direction at the
1796 * end of the bezier (which, if it has been shortened, is not the same
1797 * as the direction from pt[count-2] to pt[count-1]) */
1798 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->endcap, pen->width, pen->customend,
1799 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
1800 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
1801 pt[count - 1].X, pt[count - 1].Y);
1803 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->startcap, pen->width, pen->customstart,
1804 pt[0].X - (ptcopy[0].X - ptcopy[1].X),
1805 pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
1808 transform_and_round_points(graphics, pti, ptcopy, count);
1810 PolyBezier(graphics->hdc, pti, count);
1821 /* Draws a combination of bezier curves and lines between points. */
1822 static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
1823 GDIPCONST BYTE * types, INT count, BOOL caps)
1825 POINT *pti = GdipAlloc(count * sizeof(POINT));
1826 BYTE *tp = GdipAlloc(count);
1827 GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
1829 GpStatus status = GenericError;
1835 if(!pti || !tp || !ptcopy){
1836 status = OutOfMemory;
1840 for(i = 1; i < count; i++){
1841 if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
1842 if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
1843 || !(types[i + 1] & PathPointTypeBezier)){
1844 ERR("Bad bezier points\n");
1851 memcpy(ptcopy, pt, count * sizeof(GpPointF));
1853 /* If we are drawing caps, go through the points and adjust them accordingly,
1854 * and draw the caps. */
1856 switch(types[count - 1] & PathPointTypePathTypeMask){
1857 case PathPointTypeBezier:
1858 if(pen->endcap == LineCapArrowAnchor)
1859 shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
1860 else if((pen->endcap == LineCapCustom) && pen->customend)
1861 shorten_bezier_amt(&ptcopy[count - 4],
1862 pen->width * pen->customend->inset, FALSE);
1864 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->endcap, pen->width, pen->customend,
1865 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
1866 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
1867 pt[count - 1].X, pt[count - 1].Y);
1870 case PathPointTypeLine:
1871 if(pen->endcap == LineCapArrowAnchor)
1872 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
1873 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
1875 else if((pen->endcap == LineCapCustom) && pen->customend)
1876 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
1877 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
1878 pen->customend->inset * pen->width);
1880 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->endcap, pen->width, pen->customend,
1881 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
1886 ERR("Bad path last point\n");
1890 /* Find start of points */
1891 for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
1892 == PathPointTypeStart); j++);
1894 switch(types[j] & PathPointTypePathTypeMask){
1895 case PathPointTypeBezier:
1896 if(pen->startcap == LineCapArrowAnchor)
1897 shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
1898 else if((pen->startcap == LineCapCustom) && pen->customstart)
1899 shorten_bezier_amt(&ptcopy[j - 1],
1900 pen->width * pen->customstart->inset, TRUE);
1902 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->startcap, pen->width, pen->customstart,
1903 pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
1904 pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
1905 pt[j - 1].X, pt[j - 1].Y);
1908 case PathPointTypeLine:
1909 if(pen->startcap == LineCapArrowAnchor)
1910 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
1911 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
1913 else if((pen->startcap == LineCapCustom) && pen->customstart)
1914 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
1915 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
1916 pen->customstart->inset * pen->width);
1918 draw_cap(graphics, get_gdi_brush_color(pen->brush), pen->startcap, pen->width, pen->customstart,
1919 pt[j].X, pt[j].Y, pt[j - 1].X,
1924 ERR("Bad path points\n");
1929 transform_and_round_points(graphics, pti, ptcopy, count);
1931 for(i = 0; i < count; i++){
1932 tp[i] = convert_path_point_type(types[i]);
1935 PolyDraw(graphics->hdc, pti, tp, count);
1947 GpStatus trace_path(GpGraphics *graphics, GpPath *path)
1951 BeginPath(graphics->hdc);
1952 result = draw_poly(graphics, NULL, path->pathdata.Points,
1953 path->pathdata.Types, path->pathdata.Count, FALSE);
1954 EndPath(graphics->hdc);
1958 typedef struct _GraphicsContainerItem {
1960 GraphicsContainer contid;
1962 SmoothingMode smoothing;
1963 CompositingQuality compqual;
1964 InterpolationMode interpolation;
1965 CompositingMode compmode;
1966 TextRenderingHint texthint;
1969 PixelOffsetMode pixeloffset;
1971 GpMatrix* worldtrans;
1973 INT origin_x, origin_y;
1974 } GraphicsContainerItem;
1976 static GpStatus init_container(GraphicsContainerItem** container,
1977 GDIPCONST GpGraphics* graphics){
1980 *container = GdipAlloc(sizeof(GraphicsContainerItem));
1984 (*container)->contid = graphics->contid + 1;
1986 (*container)->smoothing = graphics->smoothing;
1987 (*container)->compqual = graphics->compqual;
1988 (*container)->interpolation = graphics->interpolation;
1989 (*container)->compmode = graphics->compmode;
1990 (*container)->texthint = graphics->texthint;
1991 (*container)->scale = graphics->scale;
1992 (*container)->unit = graphics->unit;
1993 (*container)->textcontrast = graphics->textcontrast;
1994 (*container)->pixeloffset = graphics->pixeloffset;
1995 (*container)->origin_x = graphics->origin_x;
1996 (*container)->origin_y = graphics->origin_y;
1998 sts = GdipCloneMatrix(graphics->worldtrans, &(*container)->worldtrans);
2000 GdipFree(*container);
2005 sts = GdipCloneRegion(graphics->clip, &(*container)->clip);
2007 GdipDeleteMatrix((*container)->worldtrans);
2008 GdipFree(*container);
2016 static void delete_container(GraphicsContainerItem* container){
2017 GdipDeleteMatrix(container->worldtrans);
2018 GdipDeleteRegion(container->clip);
2019 GdipFree(container);
2022 static GpStatus restore_container(GpGraphics* graphics,
2023 GDIPCONST GraphicsContainerItem* container){
2028 sts = GdipCloneMatrix(container->worldtrans, &newTrans);
2032 sts = GdipCloneRegion(container->clip, &newClip);
2034 GdipDeleteMatrix(newTrans);
2038 GdipDeleteMatrix(graphics->worldtrans);
2039 graphics->worldtrans = newTrans;
2041 GdipDeleteRegion(graphics->clip);
2042 graphics->clip = newClip;
2044 graphics->contid = container->contid - 1;
2046 graphics->smoothing = container->smoothing;
2047 graphics->compqual = container->compqual;
2048 graphics->interpolation = container->interpolation;
2049 graphics->compmode = container->compmode;
2050 graphics->texthint = container->texthint;
2051 graphics->scale = container->scale;
2052 graphics->unit = container->unit;
2053 graphics->textcontrast = container->textcontrast;
2054 graphics->pixeloffset = container->pixeloffset;
2055 graphics->origin_x = container->origin_x;
2056 graphics->origin_y = container->origin_y;
2061 static GpStatus get_graphics_bounds(GpGraphics* graphics, GpRectF* rect)
2067 if(graphics->hwnd) {
2068 if(!GetClientRect(graphics->hwnd, &wnd_rect))
2069 return GenericError;
2071 rect->X = wnd_rect.left;
2072 rect->Y = wnd_rect.top;
2073 rect->Width = wnd_rect.right - wnd_rect.left;
2074 rect->Height = wnd_rect.bottom - wnd_rect.top;
2075 }else if (graphics->image){
2076 stat = GdipGetImageBounds(graphics->image, rect, &unit);
2077 if (stat == Ok && unit != UnitPixel)
2078 FIXME("need to convert from unit %i\n", unit);
2082 rect->Width = GetDeviceCaps(graphics->hdc, HORZRES);
2083 rect->Height = GetDeviceCaps(graphics->hdc, VERTRES);
2089 /* on success, rgn will contain the region of the graphics object which
2090 * is visible after clipping has been applied */
2091 static GpStatus get_visible_clip_region(GpGraphics *graphics, GpRegion *rgn)
2097 if((stat = get_graphics_bounds(graphics, &rectf)) != Ok)
2100 if((stat = GdipCreateRegion(&tmp)) != Ok)
2103 if((stat = GdipCombineRegionRect(tmp, &rectf, CombineModeReplace)) != Ok)
2106 if((stat = GdipCombineRegionRegion(tmp, graphics->clip, CombineModeIntersect)) != Ok)
2109 stat = GdipCombineRegionRegion(rgn, tmp, CombineModeReplace);
2112 GdipDeleteRegion(tmp);
2116 static void get_font_hfont(GpGraphics *graphics, GDIPCONST GpFont *font, HFONT *hfont)
2118 HDC hdc = CreateCompatibleDC(0);
2120 REAL angle, rel_width, rel_height;
2122 HFONT unscaled_font;
2123 TEXTMETRICW textmet;
2132 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
2133 angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X));
2134 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
2135 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
2136 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
2137 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
2139 get_log_fontW(font, graphics, &lfw);
2140 lfw.lfHeight = roundr(lfw.lfHeight * rel_height);
2141 unscaled_font = CreateFontIndirectW(&lfw);
2143 SelectObject(hdc, unscaled_font);
2144 GetTextMetricsW(hdc, &textmet);
2146 lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width / rel_height);
2147 lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0);
2149 *hfont = CreateFontIndirectW(&lfw);
2152 DeleteObject(unscaled_font);
2155 GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
2157 TRACE("(%p, %p)\n", hdc, graphics);
2159 return GdipCreateFromHDC2(hdc, NULL, graphics);
2162 GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **graphics)
2166 TRACE("(%p, %p, %p)\n", hdc, hDevice, graphics);
2168 if(hDevice != NULL) {
2169 FIXME("Don't know how to handle parameter hDevice\n");
2170 return NotImplemented;
2176 if(graphics == NULL)
2177 return InvalidParameter;
2179 *graphics = GdipAlloc(sizeof(GpGraphics));
2180 if(!*graphics) return OutOfMemory;
2182 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
2183 GdipFree(*graphics);
2187 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
2188 GdipFree((*graphics)->worldtrans);
2189 GdipFree(*graphics);
2193 (*graphics)->hdc = hdc;
2194 (*graphics)->hwnd = WindowFromDC(hdc);
2195 (*graphics)->owndc = FALSE;
2196 (*graphics)->smoothing = SmoothingModeDefault;
2197 (*graphics)->compqual = CompositingQualityDefault;
2198 (*graphics)->interpolation = InterpolationModeBilinear;
2199 (*graphics)->pixeloffset = PixelOffsetModeDefault;
2200 (*graphics)->compmode = CompositingModeSourceOver;
2201 (*graphics)->unit = UnitDisplay;
2202 (*graphics)->scale = 1.0;
2203 (*graphics)->busy = FALSE;
2204 (*graphics)->textcontrast = 4;
2205 list_init(&(*graphics)->containers);
2206 (*graphics)->contid = 0;
2208 TRACE("<-- %p\n", *graphics);
2213 GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics)
2217 *graphics = GdipAlloc(sizeof(GpGraphics));
2218 if(!*graphics) return OutOfMemory;
2220 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
2221 GdipFree(*graphics);
2225 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
2226 GdipFree((*graphics)->worldtrans);
2227 GdipFree(*graphics);
2231 (*graphics)->hdc = NULL;
2232 (*graphics)->hwnd = NULL;
2233 (*graphics)->owndc = FALSE;
2234 (*graphics)->image = image;
2235 (*graphics)->smoothing = SmoothingModeDefault;
2236 (*graphics)->compqual = CompositingQualityDefault;
2237 (*graphics)->interpolation = InterpolationModeBilinear;
2238 (*graphics)->pixeloffset = PixelOffsetModeDefault;
2239 (*graphics)->compmode = CompositingModeSourceOver;
2240 (*graphics)->unit = UnitDisplay;
2241 (*graphics)->scale = 1.0;
2242 (*graphics)->busy = FALSE;
2243 (*graphics)->textcontrast = 4;
2244 list_init(&(*graphics)->containers);
2245 (*graphics)->contid = 0;
2247 TRACE("<-- %p\n", *graphics);
2252 GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
2257 TRACE("(%p, %p)\n", hwnd, graphics);
2261 if((ret = GdipCreateFromHDC(hdc, graphics)) != Ok)
2263 ReleaseDC(hwnd, hdc);
2267 (*graphics)->hwnd = hwnd;
2268 (*graphics)->owndc = TRUE;
2273 /* FIXME: no icm handling */
2274 GpStatus WINGDIPAPI GdipCreateFromHWNDICM(HWND hwnd, GpGraphics **graphics)
2276 TRACE("(%p, %p)\n", hwnd, graphics);
2278 return GdipCreateFromHWND(hwnd, graphics);
2281 GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
2282 GpMetafile **metafile)
2284 IStream *stream = NULL;
2286 ENHMETAHEADER *copy;
2287 GpStatus retval = Ok;
2289 TRACE("(%p,%i,%p)\n", hemf, delete, metafile);
2291 if(!hemf || !metafile)
2292 return InvalidParameter;
2294 read = GetEnhMetaFileBits(hemf, 0, NULL);
2295 copy = GdipAlloc(read);
2296 GetEnhMetaFileBits(hemf, read, (BYTE *)copy);
2298 if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
2299 ERR("could not make stream\n");
2301 retval = GenericError;
2305 *metafile = GdipAlloc(sizeof(GpMetafile));
2307 retval = OutOfMemory;
2311 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
2312 (LPVOID*) &((*metafile)->image.picture)) != S_OK)
2314 retval = GenericError;
2319 (*metafile)->image.type = ImageTypeMetafile;
2320 memcpy(&(*metafile)->image.format, &ImageFormatWMF, sizeof(GUID));
2321 (*metafile)->image.palette = NULL;
2322 (*metafile)->image.xres = (REAL)copy->szlDevice.cx;
2323 (*metafile)->image.yres = (REAL)copy->szlDevice.cy;
2324 (*metafile)->bounds.X = (REAL)copy->rclBounds.left;
2325 (*metafile)->bounds.Y = (REAL)copy->rclBounds.top;
2326 (*metafile)->bounds.Width = (REAL)(copy->rclBounds.right - copy->rclBounds.left);
2327 (*metafile)->bounds.Height = (REAL)(copy->rclBounds.bottom - copy->rclBounds.top);
2328 (*metafile)->unit = UnitPixel;
2331 DeleteEnhMetaFile(hemf);
2333 TRACE("<-- %p\n", *metafile);
2337 GdipFree(*metafile);
2338 IStream_Release(stream);
2342 GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
2343 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
2348 GpStatus retval = Ok;
2350 TRACE("(%p, %d, %p, %p)\n", hwmf, delete, placeable, metafile);
2352 if(!hwmf || !metafile || !placeable)
2353 return InvalidParameter;
2356 read = GetMetaFileBitsEx(hwmf, 0, NULL);
2358 return GenericError;
2359 copy = GdipAlloc(read);
2360 GetMetaFileBitsEx(hwmf, read, copy);
2362 hemf = SetWinMetaFileBits(read, copy, NULL, NULL);
2365 retval = GdipCreateMetafileFromEmf(hemf, FALSE, metafile);
2369 (*metafile)->image.xres = (REAL)placeable->Inch;
2370 (*metafile)->image.yres = (REAL)placeable->Inch;
2371 (*metafile)->bounds.X = ((REAL)placeable->BoundingBox.Left) / ((REAL)placeable->Inch);
2372 (*metafile)->bounds.Y = ((REAL)placeable->BoundingBox.Top) / ((REAL)placeable->Inch);
2373 (*metafile)->bounds.Width = (REAL)(placeable->BoundingBox.Right -
2374 placeable->BoundingBox.Left);
2375 (*metafile)->bounds.Height = (REAL)(placeable->BoundingBox.Bottom -
2376 placeable->BoundingBox.Top);
2378 if (delete) DeleteMetaFile(hwmf);
2383 GpStatus WINGDIPAPI GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR *file,
2384 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
2386 HMETAFILE hmf = GetMetaFileW(file);
2388 TRACE("(%s, %p, %p)\n", debugstr_w(file), placeable, metafile);
2390 if(!hmf) return InvalidParameter;
2392 return GdipCreateMetafileFromWmf(hmf, TRUE, placeable, metafile);
2395 GpStatus WINGDIPAPI GdipCreateMetafileFromFile(GDIPCONST WCHAR *file,
2396 GpMetafile **metafile)
2398 FIXME("(%p, %p): stub\n", file, metafile);
2399 return NotImplemented;
2402 GpStatus WINGDIPAPI GdipCreateMetafileFromStream(IStream *stream,
2403 GpMetafile **metafile)
2405 FIXME("(%p, %p): stub\n", stream, metafile);
2406 return NotImplemented;
2409 GpStatus WINGDIPAPI GdipCreateStreamOnFile(GDIPCONST WCHAR * filename,
2410 UINT access, IStream **stream)
2415 TRACE("(%s, %u, %p)\n", debugstr_w(filename), access, stream);
2417 if(!stream || !filename)
2418 return InvalidParameter;
2420 if(access & GENERIC_WRITE)
2421 dwMode = STGM_SHARE_DENY_WRITE | STGM_WRITE | STGM_CREATE;
2422 else if(access & GENERIC_READ)
2423 dwMode = STGM_SHARE_DENY_WRITE | STGM_READ | STGM_FAILIFTHERE;
2425 return InvalidParameter;
2427 ret = SHCreateStreamOnFileW(filename, dwMode, stream);
2429 return hresult_to_status(ret);
2432 GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
2434 GraphicsContainerItem *cont, *next;
2436 TRACE("(%p)\n", graphics);
2438 if(!graphics) return InvalidParameter;
2439 if(graphics->busy) return ObjectBusy;
2441 if (graphics->image && graphics->image->type == ImageTypeMetafile)
2443 stat = METAFILE_GraphicsDeleted((GpMetafile*)graphics->image);
2449 ReleaseDC(graphics->hwnd, graphics->hdc);
2451 LIST_FOR_EACH_ENTRY_SAFE(cont, next, &graphics->containers, GraphicsContainerItem, entry){
2452 list_remove(&cont->entry);
2453 delete_container(cont);
2456 GdipDeleteRegion(graphics->clip);
2457 GdipDeleteMatrix(graphics->worldtrans);
2463 GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
2464 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2466 INT save_state, num_pts;
2467 GpPointF points[MAX_ARC_PTS];
2470 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
2471 width, height, startAngle, sweepAngle);
2473 if(!graphics || !pen || width <= 0 || height <= 0)
2474 return InvalidParameter;
2481 FIXME("graphics object has no HDC\n");
2485 num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
2487 save_state = prepare_dc(graphics, pen);
2489 retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
2491 restore_dc(graphics, save_state);
2496 GpStatus WINGDIPAPI GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x,
2497 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2499 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
2500 width, height, startAngle, sweepAngle);
2502 return GdipDrawArc(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2505 GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
2506 REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
2512 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1,
2513 x2, y2, x3, y3, x4, y4);
2515 if(!graphics || !pen)
2516 return InvalidParameter;
2523 FIXME("graphics object has no HDC\n");
2536 save_state = prepare_dc(graphics, pen);
2538 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
2540 restore_dc(graphics, save_state);
2545 GpStatus WINGDIPAPI GdipDrawBezierI(GpGraphics *graphics, GpPen *pen, INT x1,
2546 INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4)
2552 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics, pen, x1, y1,
2553 x2, y2, x3, y3, x4, y4);
2555 if(!graphics || !pen)
2556 return InvalidParameter;
2563 FIXME("graphics object has no HDC\n");
2576 save_state = prepare_dc(graphics, pen);
2578 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
2580 restore_dc(graphics, save_state);
2585 GpStatus WINGDIPAPI GdipDrawBeziers(GpGraphics *graphics, GpPen *pen,
2586 GDIPCONST GpPointF *points, INT count)
2591 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2593 if(!graphics || !pen || !points || (count <= 0))
2594 return InvalidParameter;
2599 for(i = 0; i < floor(count / 4); i++){
2600 ret = GdipDrawBezier(graphics, pen,
2601 points[4*i].X, points[4*i].Y,
2602 points[4*i + 1].X, points[4*i + 1].Y,
2603 points[4*i + 2].X, points[4*i + 2].Y,
2604 points[4*i + 3].X, points[4*i + 3].Y);
2612 GpStatus WINGDIPAPI GdipDrawBeziersI(GpGraphics *graphics, GpPen *pen,
2613 GDIPCONST GpPoint *points, INT count)
2619 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2621 if(!graphics || !pen || !points || (count <= 0))
2622 return InvalidParameter;
2627 pts = GdipAlloc(sizeof(GpPointF) * count);
2631 for(i = 0; i < count; i++){
2632 pts[i].X = (REAL)points[i].X;
2633 pts[i].Y = (REAL)points[i].Y;
2636 ret = GdipDrawBeziers(graphics,pen,pts,count);
2643 GpStatus WINGDIPAPI GdipDrawClosedCurve(GpGraphics *graphics, GpPen *pen,
2644 GDIPCONST GpPointF *points, INT count)
2646 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2648 return GdipDrawClosedCurve2(graphics, pen, points, count, 1.0);
2651 GpStatus WINGDIPAPI GdipDrawClosedCurveI(GpGraphics *graphics, GpPen *pen,
2652 GDIPCONST GpPoint *points, INT count)
2654 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2656 return GdipDrawClosedCurve2I(graphics, pen, points, count, 1.0);
2659 GpStatus WINGDIPAPI GdipDrawClosedCurve2(GpGraphics *graphics, GpPen *pen,
2660 GDIPCONST GpPointF *points, INT count, REAL tension)
2665 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
2667 if(!graphics || !pen || !points || count <= 0)
2668 return InvalidParameter;
2673 if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok)
2676 stat = GdipAddPathClosedCurve2(path, points, count, tension);
2678 GdipDeletePath(path);
2682 stat = GdipDrawPath(graphics, pen, path);
2684 GdipDeletePath(path);
2689 GpStatus WINGDIPAPI GdipDrawClosedCurve2I(GpGraphics *graphics, GpPen *pen,
2690 GDIPCONST GpPoint *points, INT count, REAL tension)
2696 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
2698 if(!points || count <= 0)
2699 return InvalidParameter;
2701 ptf = GdipAlloc(sizeof(GpPointF)*count);
2705 for(i = 0; i < count; i++){
2706 ptf[i].X = (REAL)points[i].X;
2707 ptf[i].Y = (REAL)points[i].Y;
2710 stat = GdipDrawClosedCurve2(graphics, pen, ptf, count, tension);
2717 GpStatus WINGDIPAPI GdipDrawCurve(GpGraphics *graphics, GpPen *pen,
2718 GDIPCONST GpPointF *points, INT count)
2720 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2722 return GdipDrawCurve2(graphics,pen,points,count,1.0);
2725 GpStatus WINGDIPAPI GdipDrawCurveI(GpGraphics *graphics, GpPen *pen,
2726 GDIPCONST GpPoint *points, INT count)
2732 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2735 return InvalidParameter;
2737 pointsF = GdipAlloc(sizeof(GpPointF)*count);
2741 for(i = 0; i < count; i++){
2742 pointsF[i].X = (REAL)points[i].X;
2743 pointsF[i].Y = (REAL)points[i].Y;
2746 ret = GdipDrawCurve(graphics,pen,pointsF,count);
2752 /* Approximates cardinal spline with Bezier curves. */
2753 GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
2754 GDIPCONST GpPointF *points, INT count, REAL tension)
2756 /* PolyBezier expects count*3-2 points. */
2757 INT i, len_pt = count*3-2, save_state;
2759 REAL x1, x2, y1, y2;
2762 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
2764 if(!graphics || !pen)
2765 return InvalidParameter;
2771 return InvalidParameter;
2775 FIXME("graphics object has no HDC\n");
2779 pt = GdipAlloc(len_pt * sizeof(GpPointF));
2783 tension = tension * TENSION_CONST;
2785 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
2788 pt[0].X = points[0].X;
2789 pt[0].Y = points[0].Y;
2793 for(i = 0; i < count-2; i++){
2794 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
2798 pt[3*i+3].X = points[i+1].X;
2799 pt[3*i+3].Y = points[i+1].Y;
2804 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
2805 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
2807 pt[len_pt-2].X = x1;
2808 pt[len_pt-2].Y = y1;
2809 pt[len_pt-1].X = points[count-1].X;
2810 pt[len_pt-1].Y = points[count-1].Y;
2812 save_state = prepare_dc(graphics, pen);
2814 retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
2817 restore_dc(graphics, save_state);
2822 GpStatus WINGDIPAPI GdipDrawCurve2I(GpGraphics *graphics, GpPen *pen,
2823 GDIPCONST GpPoint *points, INT count, REAL tension)
2829 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
2832 return InvalidParameter;
2834 pointsF = GdipAlloc(sizeof(GpPointF)*count);
2838 for(i = 0; i < count; i++){
2839 pointsF[i].X = (REAL)points[i].X;
2840 pointsF[i].Y = (REAL)points[i].Y;
2843 ret = GdipDrawCurve2(graphics,pen,pointsF,count,tension);
2849 GpStatus WINGDIPAPI GdipDrawCurve3(GpGraphics *graphics, GpPen *pen,
2850 GDIPCONST GpPointF *points, INT count, INT offset, INT numberOfSegments,
2853 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
2855 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
2856 return InvalidParameter;
2859 return GdipDrawCurve2(graphics, pen, points + offset, numberOfSegments + 1, tension);
2862 GpStatus WINGDIPAPI GdipDrawCurve3I(GpGraphics *graphics, GpPen *pen,
2863 GDIPCONST GpPoint *points, INT count, INT offset, INT numberOfSegments,
2866 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
2872 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
2873 return InvalidParameter;
2876 return GdipDrawCurve2I(graphics, pen, points + offset, numberOfSegments + 1, tension);
2879 GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics *graphics, GpPen *pen, REAL x,
2880 REAL y, REAL width, REAL height)
2886 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
2888 if(!graphics || !pen)
2889 return InvalidParameter;
2896 FIXME("graphics object has no HDC\n");
2902 ptf[1].X = x + width;
2903 ptf[1].Y = y + height;
2905 save_state = prepare_dc(graphics, pen);
2906 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2908 transform_and_round_points(graphics, pti, ptf, 2);
2910 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
2912 restore_dc(graphics, save_state);
2917 GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics *graphics, GpPen *pen, INT x,
2918 INT y, INT width, INT height)
2920 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
2922 return GdipDrawEllipse(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2926 GpStatus WINGDIPAPI GdipDrawImage(GpGraphics *graphics, GpImage *image, REAL x, REAL y)
2931 TRACE("(%p, %p, %.2f, %.2f)\n", graphics, image, x, y);
2933 if(!graphics || !image)
2934 return InvalidParameter;
2936 GdipGetImageWidth(image, &width);
2937 GdipGetImageHeight(image, &height);
2939 /* FIXME: we should use the graphics and image dpi, somehow */
2941 points[0].X = points[2].X = x;
2942 points[0].Y = points[1].Y = y;
2943 points[1].X = x + width;
2944 points[2].Y = y + height;
2946 return GdipDrawImagePointsRect(graphics, image, points, 3, 0, 0, width, height,
2947 UnitPixel, NULL, NULL, NULL);
2950 GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x,
2953 TRACE("(%p, %p, %d, %d)\n", graphics, image, x, y);
2955 return GdipDrawImage(graphics, image, (REAL)x, (REAL)y);
2958 GpStatus WINGDIPAPI GdipDrawImagePointRect(GpGraphics *graphics, GpImage *image,
2959 REAL x, REAL y, REAL srcx, REAL srcy, REAL srcwidth, REAL srcheight,
2963 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
2965 points[0].X = points[2].X = x;
2966 points[0].Y = points[1].Y = y;
2968 /* FIXME: convert image coordinates to Graphics coordinates? */
2969 points[1].X = x + srcwidth;
2970 points[2].Y = y + srcheight;
2972 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2973 srcwidth, srcheight, srcUnit, NULL, NULL, NULL);
2976 GpStatus WINGDIPAPI GdipDrawImagePointRectI(GpGraphics *graphics, GpImage *image,
2977 INT x, INT y, INT srcx, INT srcy, INT srcwidth, INT srcheight,
2980 return GdipDrawImagePointRect(graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
2983 GpStatus WINGDIPAPI GdipDrawImagePoints(GpGraphics *graphics, GpImage *image,
2984 GDIPCONST GpPointF *dstpoints, INT count)
2988 TRACE("(%p, %p, %p, %d)\n", graphics, image, dstpoints, count);
2991 return InvalidParameter;
2993 GdipGetImageWidth(image, &width);
2994 GdipGetImageHeight(image, &height);
2996 return GdipDrawImagePointsRect(graphics, image, dstpoints, count, 0, 0,
2997 width, height, UnitPixel, NULL, NULL, NULL);
3000 GpStatus WINGDIPAPI GdipDrawImagePointsI(GpGraphics *graphics, GpImage *image,
3001 GDIPCONST GpPoint *dstpoints, INT count)
3005 TRACE("(%p, %p, %p, %d)\n", graphics, image, dstpoints, count);
3007 if (count != 3 || !dstpoints)
3008 return InvalidParameter;
3010 ptf[0].X = (REAL)dstpoints[0].X;
3011 ptf[0].Y = (REAL)dstpoints[0].Y;
3012 ptf[1].X = (REAL)dstpoints[1].X;
3013 ptf[1].Y = (REAL)dstpoints[1].Y;
3014 ptf[2].X = (REAL)dstpoints[2].X;
3015 ptf[2].Y = (REAL)dstpoints[2].Y;
3017 return GdipDrawImagePoints(graphics, image, ptf, count);
3020 GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
3021 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
3022 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
3023 DrawImageAbort callback, VOID * callbackData)
3030 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics, image, points,
3031 count, srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
3035 return NotImplemented;
3037 if(!graphics || !image || !points || count != 3)
3038 return InvalidParameter;
3040 TRACE("%s %s %s\n", debugstr_pointf(&points[0]), debugstr_pointf(&points[1]),
3041 debugstr_pointf(&points[2]));
3043 memcpy(ptf, points, 3 * sizeof(GpPointF));
3044 ptf[3].X = ptf[2].X + ptf[1].X - ptf[0].X;
3045 ptf[3].Y = ptf[2].Y + ptf[1].Y - ptf[0].Y;
3046 if (!srcwidth || !srcheight || ptf[3].X == ptf[0].X || ptf[3].Y == ptf[0].Y)
3048 transform_and_round_points(graphics, pti, ptf, 4);
3054 FIXME("graphics object has no HDC\n");
3057 /* FIXME: partially implemented (only works for rectangular parallelograms) */
3058 if(srcUnit == UnitInch)
3059 dx = dy = (REAL) INCH_HIMETRIC;
3060 else if(srcUnit == UnitPixel){
3061 dx = ((REAL) INCH_HIMETRIC) /
3062 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
3063 dy = ((REAL) INCH_HIMETRIC) /
3064 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
3067 return NotImplemented;
3069 if(IPicture_Render(image->picture, graphics->hdc,
3070 pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
3071 srcx * dx, srcy * dy,
3072 srcwidth * dx, srcheight * dy,
3075 callback(callbackData);
3076 return GenericError;
3079 else if (image->type == ImageTypeBitmap)
3081 GpBitmap* bitmap = (GpBitmap*)image;
3084 if (srcUnit == UnitInch)
3085 dx = dy = 96.0; /* FIXME: use the image resolution */
3086 else if (srcUnit == UnitPixel)
3089 return NotImplemented;
3093 srcwidth = srcwidth * dx;
3094 srcheight = srcheight * dy;
3096 if (imageAttributes ||
3097 (graphics->image && graphics->image->type == ImageTypeBitmap) ||
3098 !((GpBitmap*)image)->hbitmap ||
3099 ptf[1].Y != ptf[0].Y || ptf[2].X != ptf[0].X ||
3100 ptf[1].X - ptf[0].X != srcwidth || ptf[2].Y - ptf[0].Y != srcheight ||
3101 srcx < 0 || srcy < 0 ||
3102 srcx + srcwidth > bitmap->width || srcy + srcheight > bitmap->height)
3109 int i, x, y, src_stride, dst_stride;
3110 GpMatrix *dst_to_src;
3111 REAL m11, m12, m21, m22, mdx, mdy;
3112 LPBYTE src_data, dst_data;
3113 BitmapData lockeddata;
3114 InterpolationMode interpolation = graphics->interpolation;
3115 GpPointF dst_to_src_points[3] = {{0.0, 0.0}, {1.0, 0.0}, {0.0, 1.0}};
3116 REAL x_dx, x_dy, y_dx, y_dy;
3117 static const GpImageAttributes defaultImageAttributes = {WrapModeClamp, 0, FALSE};
3119 if (!imageAttributes)
3120 imageAttributes = &defaultImageAttributes;
3122 dst_area.left = dst_area.right = pti[0].x;
3123 dst_area.top = dst_area.bottom = pti[0].y;
3126 if (dst_area.left > pti[i].x) dst_area.left = pti[i].x;
3127 if (dst_area.right < pti[i].x) dst_area.right = pti[i].x;
3128 if (dst_area.top > pti[i].y) dst_area.top = pti[i].y;
3129 if (dst_area.bottom < pti[i].y) dst_area.bottom = pti[i].y;
3132 m11 = (ptf[1].X - ptf[0].X) / srcwidth;
3133 m21 = (ptf[2].X - ptf[0].X) / srcheight;
3134 mdx = ptf[0].X - m11 * srcx - m21 * srcy;
3135 m12 = (ptf[1].Y - ptf[0].Y) / srcwidth;
3136 m22 = (ptf[2].Y - ptf[0].Y) / srcheight;
3137 mdy = ptf[0].Y - m12 * srcx - m22 * srcy;
3139 stat = GdipCreateMatrix2(m11, m12, m21, m22, mdx, mdy, &dst_to_src);
3140 if (stat != Ok) return stat;
3142 stat = GdipInvertMatrix(dst_to_src);
3145 GdipDeleteMatrix(dst_to_src);
3149 dst_data = GdipAlloc(sizeof(ARGB) * (dst_area.right - dst_area.left) * (dst_area.bottom - dst_area.top));
3152 GdipDeleteMatrix(dst_to_src);
3156 dst_stride = sizeof(ARGB) * (dst_area.right - dst_area.left);
3158 get_bitmap_sample_size(interpolation, imageAttributes->wrap,
3159 bitmap, srcx, srcy, srcwidth, srcheight, &src_area);
3161 src_data = GdipAlloc(sizeof(ARGB) * src_area.Width * src_area.Height);
3165 GdipDeleteMatrix(dst_to_src);
3168 src_stride = sizeof(ARGB) * src_area.Width;
3170 /* Read the bits we need from the source bitmap into an ARGB buffer. */
3171 lockeddata.Width = src_area.Width;
3172 lockeddata.Height = src_area.Height;
3173 lockeddata.Stride = src_stride;
3174 lockeddata.PixelFormat = PixelFormat32bppARGB;
3175 lockeddata.Scan0 = src_data;
3177 stat = GdipBitmapLockBits(bitmap, &src_area, ImageLockModeRead|ImageLockModeUserInputBuf,
3178 PixelFormat32bppARGB, &lockeddata);
3181 stat = GdipBitmapUnlockBits(bitmap, &lockeddata);
3185 if (src_data != dst_data)
3188 GdipDeleteMatrix(dst_to_src);
3192 apply_image_attributes(imageAttributes, src_data,
3193 src_area.Width, src_area.Height,
3194 src_stride, ColorAdjustTypeBitmap);
3196 /* Transform the bits as needed to the destination. */
3197 GdipTransformMatrixPoints(dst_to_src, dst_to_src_points, 3);
3199 x_dx = dst_to_src_points[1].X - dst_to_src_points[0].X;
3200 x_dy = dst_to_src_points[1].Y - dst_to_src_points[0].Y;
3201 y_dx = dst_to_src_points[2].X - dst_to_src_points[0].X;
3202 y_dy = dst_to_src_points[2].Y - dst_to_src_points[0].Y;
3204 for (x=dst_area.left; x<dst_area.right; x++)
3206 for (y=dst_area.top; y<dst_area.bottom; y++)
3208 GpPointF src_pointf;
3211 src_pointf.X = dst_to_src_points[0].X + x * x_dx + y * y_dx;
3212 src_pointf.Y = dst_to_src_points[0].Y + x * x_dy + y * y_dy;
3214 dst_color = (ARGB*)(dst_data + dst_stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
3216 if (src_pointf.X >= srcx && src_pointf.X < srcx + srcwidth && src_pointf.Y >= srcy && src_pointf.Y < srcy+srcheight)
3217 *dst_color = resample_bitmap_pixel(&src_area, src_data, bitmap->width, bitmap->height, &src_pointf, imageAttributes, interpolation);
3223 GdipDeleteMatrix(dst_to_src);
3227 stat = alpha_blend_pixels(graphics, dst_area.left, dst_area.top,
3228 dst_data, dst_area.right - dst_area.left, dst_area.bottom - dst_area.top, dst_stride);
3237 int temp_hdc=0, temp_bitmap=0;
3238 HBITMAP hbitmap, old_hbm=NULL;
3240 if (!(bitmap->format == PixelFormat16bppRGB555 ||
3241 bitmap->format == PixelFormat24bppRGB ||
3242 bitmap->format == PixelFormat32bppRGB ||
3243 bitmap->format == PixelFormat32bppPARGB))
3245 BITMAPINFOHEADER bih;
3247 PixelFormat dst_format;
3249 /* we can't draw a bitmap of this format directly */
3250 hdc = CreateCompatibleDC(0);
3254 bih.biSize = sizeof(BITMAPINFOHEADER);
3255 bih.biWidth = bitmap->width;
3256 bih.biHeight = -bitmap->height;
3258 bih.biBitCount = 32;
3259 bih.biCompression = BI_RGB;
3260 bih.biSizeImage = 0;
3261 bih.biXPelsPerMeter = 0;
3262 bih.biYPelsPerMeter = 0;
3264 bih.biClrImportant = 0;
3266 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
3267 (void**)&temp_bits, NULL, 0);
3269 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
3270 dst_format = PixelFormat32bppPARGB;
3272 dst_format = PixelFormat32bppRGB;
3274 convert_pixels(bitmap->width, bitmap->height,
3275 bitmap->width*4, temp_bits, dst_format,
3276 bitmap->stride, bitmap->bits, bitmap->format,
3277 bitmap->image.palette);
3281 hbitmap = bitmap->hbitmap;
3283 temp_hdc = (hdc == 0);
3288 if (!hdc) hdc = CreateCompatibleDC(0);
3289 old_hbm = SelectObject(hdc, hbitmap);
3292 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
3294 gdi_alpha_blend(graphics, pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
3295 hdc, srcx, srcy, srcwidth, srcheight);
3299 StretchBlt(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
3300 hdc, srcx, srcy, srcwidth, srcheight, SRCCOPY);
3305 SelectObject(hdc, old_hbm);
3310 DeleteObject(hbitmap);
3315 ERR("GpImage with no IPicture or HBITMAP?!\n");
3316 return NotImplemented;
3322 GpStatus WINGDIPAPI GdipDrawImagePointsRectI(GpGraphics *graphics, GpImage *image,
3323 GDIPCONST GpPoint *points, INT count, INT srcx, INT srcy, INT srcwidth,
3324 INT srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
3325 DrawImageAbort callback, VOID * callbackData)
3327 GpPointF pointsF[3];
3330 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics, image, points, count,
3331 srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
3334 if(!points || count!=3)
3335 return InvalidParameter;
3337 for(i = 0; i < count; i++){
3338 pointsF[i].X = (REAL)points[i].X;
3339 pointsF[i].Y = (REAL)points[i].Y;
3342 return GdipDrawImagePointsRect(graphics, image, pointsF, count, (REAL)srcx, (REAL)srcy,
3343 (REAL)srcwidth, (REAL)srcheight, srcUnit, imageAttributes,
3344 callback, callbackData);
3347 GpStatus WINGDIPAPI GdipDrawImageRectRect(GpGraphics *graphics, GpImage *image,
3348 REAL dstx, REAL dsty, REAL dstwidth, REAL dstheight, REAL srcx, REAL srcy,
3349 REAL srcwidth, REAL srcheight, GpUnit srcUnit,
3350 GDIPCONST GpImageAttributes* imageattr, DrawImageAbort callback,
3351 VOID * callbackData)
3355 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
3356 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
3357 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
3361 points[1].X = dstx + dstwidth;
3364 points[2].Y = dsty + dstheight;
3366 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
3367 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
3370 GpStatus WINGDIPAPI GdipDrawImageRectRectI(GpGraphics *graphics, GpImage *image,
3371 INT dstx, INT dsty, INT dstwidth, INT dstheight, INT srcx, INT srcy,
3372 INT srcwidth, INT srcheight, GpUnit srcUnit,
3373 GDIPCONST GpImageAttributes* imageAttributes, DrawImageAbort callback,
3374 VOID * callbackData)
3378 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
3379 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
3380 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
3384 points[1].X = dstx + dstwidth;
3387 points[2].Y = dsty + dstheight;
3389 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
3390 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
3393 GpStatus WINGDIPAPI GdipDrawImageRect(GpGraphics *graphics, GpImage *image,
3394 REAL x, REAL y, REAL width, REAL height)
3400 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, image, x, y, width, height);
3402 if(!graphics || !image)
3403 return InvalidParameter;
3405 ret = GdipGetImageBounds(image, &bounds, &unit);
3409 return GdipDrawImageRectRect(graphics, image, x, y, width, height,
3410 bounds.X, bounds.Y, bounds.Width, bounds.Height,
3411 unit, NULL, NULL, NULL);
3414 GpStatus WINGDIPAPI GdipDrawImageRectI(GpGraphics *graphics, GpImage *image,
3415 INT x, INT y, INT width, INT height)
3417 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, image, x, y, width, height);
3419 return GdipDrawImageRect(graphics, image, (REAL)x, (REAL)y, (REAL)width, (REAL)height);
3422 GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1,
3423 REAL y1, REAL x2, REAL y2)
3429 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1, x2, y2);
3431 if(!pen || !graphics)
3432 return InvalidParameter;
3439 FIXME("graphics object has no HDC\n");
3448 save_state = prepare_dc(graphics, pen);
3450 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
3452 restore_dc(graphics, save_state);
3457 GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
3458 INT y1, INT x2, INT y2)
3464 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x1, y1, x2, y2);
3466 if(!pen || !graphics)
3467 return InvalidParameter;
3474 FIXME("graphics object has no HDC\n");
3483 save_state = prepare_dc(graphics, pen);
3485 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
3487 restore_dc(graphics, save_state);
3492 GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
3493 GpPointF *points, INT count)
3498 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
3500 if(!pen || !graphics || (count < 2))
3501 return InvalidParameter;
3508 FIXME("graphics object has no HDC\n");
3512 save_state = prepare_dc(graphics, pen);
3514 retval = draw_polyline(graphics, pen, points, count, TRUE);
3516 restore_dc(graphics, save_state);
3521 GpStatus WINGDIPAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, GDIPCONST
3522 GpPoint *points, INT count)
3526 GpPointF *ptf = NULL;
3529 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
3531 if(!pen || !graphics || (count < 2))
3532 return InvalidParameter;
3539 FIXME("graphics object has no HDC\n");
3543 ptf = GdipAlloc(count * sizeof(GpPointF));
3544 if(!ptf) return OutOfMemory;
3546 for(i = 0; i < count; i ++){
3547 ptf[i].X = (REAL) points[i].X;
3548 ptf[i].Y = (REAL) points[i].Y;
3551 save_state = prepare_dc(graphics, pen);
3553 retval = draw_polyline(graphics, pen, ptf, count, TRUE);
3555 restore_dc(graphics, save_state);
3561 GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
3566 TRACE("(%p, %p, %p)\n", graphics, pen, path);
3568 if(!pen || !graphics)
3569 return InvalidParameter;
3576 FIXME("graphics object has no HDC\n");
3580 save_state = prepare_dc(graphics, pen);
3582 retval = draw_poly(graphics, pen, path->pathdata.Points,
3583 path->pathdata.Types, path->pathdata.Count, TRUE);
3585 restore_dc(graphics, save_state);
3590 GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
3591 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
3595 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
3596 width, height, startAngle, sweepAngle);
3598 if(!graphics || !pen)
3599 return InvalidParameter;
3606 FIXME("graphics object has no HDC\n");
3610 save_state = prepare_dc(graphics, pen);
3611 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
3613 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
3615 restore_dc(graphics, save_state);
3620 GpStatus WINGDIPAPI GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x,
3621 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
3623 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
3624 width, height, startAngle, sweepAngle);
3626 return GdipDrawPie(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
3629 GpStatus WINGDIPAPI GdipDrawRectangle(GpGraphics *graphics, GpPen *pen, REAL x,
3630 REAL y, REAL width, REAL height)
3636 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
3638 if(!pen || !graphics)
3639 return InvalidParameter;
3646 FIXME("graphics object has no HDC\n");
3652 ptf[1].X = x + width;
3654 ptf[2].X = x + width;
3655 ptf[2].Y = y + height;
3657 ptf[3].Y = y + height;
3659 save_state = prepare_dc(graphics, pen);
3660 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
3662 transform_and_round_points(graphics, pti, ptf, 4);
3663 Polygon(graphics->hdc, pti, 4);
3665 restore_dc(graphics, save_state);
3670 GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
3671 INT y, INT width, INT height)
3673 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
3675 return GdipDrawRectangle(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
3678 GpStatus WINGDIPAPI GdipDrawRectangles(GpGraphics *graphics, GpPen *pen,
3679 GDIPCONST GpRectF* rects, INT count)
3685 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
3687 if(!graphics || !pen || !rects || count < 1)
3688 return InvalidParameter;
3695 FIXME("graphics object has no HDC\n");
3699 ptf = GdipAlloc(4 * count * sizeof(GpPointF));
3700 pti = GdipAlloc(4 * count * sizeof(POINT));
3708 for(i = 0; i < count; i++){
3709 ptf[4 * i + 3].X = ptf[4 * i].X = rects[i].X;
3710 ptf[4 * i + 1].Y = ptf[4 * i].Y = rects[i].Y;
3711 ptf[4 * i + 2].X = ptf[4 * i + 1].X = rects[i].X + rects[i].Width;
3712 ptf[4 * i + 3].Y = ptf[4 * i + 2].Y = rects[i].Y + rects[i].Height;
3715 save_state = prepare_dc(graphics, pen);
3716 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
3718 transform_and_round_points(graphics, pti, ptf, 4 * count);
3720 for(i = 0; i < count; i++)
3721 Polygon(graphics->hdc, &pti[4 * i], 4);
3723 restore_dc(graphics, save_state);
3731 GpStatus WINGDIPAPI GdipDrawRectanglesI(GpGraphics *graphics, GpPen *pen,
3732 GDIPCONST GpRect* rects, INT count)
3738 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
3740 if(!rects || count<=0)
3741 return InvalidParameter;
3743 rectsF = GdipAlloc(sizeof(GpRectF) * count);
3747 for(i = 0;i < count;i++){
3748 rectsF[i].X = (REAL)rects[i].X;
3749 rectsF[i].Y = (REAL)rects[i].Y;
3750 rectsF[i].Width = (REAL)rects[i].Width;
3751 rectsF[i].Height = (REAL)rects[i].Height;
3754 ret = GdipDrawRectangles(graphics, pen, rectsF, count);
3760 GpStatus WINGDIPAPI GdipFillClosedCurve2(GpGraphics *graphics, GpBrush *brush,
3761 GDIPCONST GpPointF *points, INT count, REAL tension, GpFillMode fill)
3766 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
3767 count, tension, fill);
3769 if(!graphics || !brush || !points)
3770 return InvalidParameter;
3775 if(count == 1) /* Do nothing */
3778 stat = GdipCreatePath(fill, &path);
3782 stat = GdipAddPathClosedCurve2(path, points, count, tension);
3784 GdipDeletePath(path);
3788 stat = GdipFillPath(graphics, brush, path);
3790 GdipDeletePath(path);
3794 GdipDeletePath(path);
3799 GpStatus WINGDIPAPI GdipFillClosedCurve2I(GpGraphics *graphics, GpBrush *brush,
3800 GDIPCONST GpPoint *points, INT count, REAL tension, GpFillMode fill)
3806 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
3807 count, tension, fill);
3809 if(!points || count == 0)
3810 return InvalidParameter;
3812 if(count == 1) /* Do nothing */
3815 ptf = GdipAlloc(sizeof(GpPointF)*count);
3819 for(i = 0;i < count;i++){
3820 ptf[i].X = (REAL)points[i].X;
3821 ptf[i].Y = (REAL)points[i].Y;
3824 stat = GdipFillClosedCurve2(graphics, brush, ptf, count, tension, fill);
3831 GpStatus WINGDIPAPI GdipFillClosedCurve(GpGraphics *graphics, GpBrush *brush,
3832 GDIPCONST GpPointF *points, INT count)
3834 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3835 return GdipFillClosedCurve2(graphics, brush, points, count,
3836 0.5f, FillModeAlternate);
3839 GpStatus WINGDIPAPI GdipFillClosedCurveI(GpGraphics *graphics, GpBrush *brush,
3840 GDIPCONST GpPoint *points, INT count)
3842 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3843 return GdipFillClosedCurve2I(graphics, brush, points, count,
3844 0.5f, FillModeAlternate);
3847 GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x,
3848 REAL y, REAL width, REAL height)
3853 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
3855 if(!graphics || !brush)
3856 return InvalidParameter;
3861 stat = GdipCreatePath(FillModeAlternate, &path);
3865 stat = GdipAddPathEllipse(path, x, y, width, height);
3868 stat = GdipFillPath(graphics, brush, path);
3870 GdipDeletePath(path);
3876 GpStatus WINGDIPAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x,
3877 INT y, INT width, INT height)
3879 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
3881 return GdipFillEllipse(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
3884 static GpStatus GDI32_GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
3889 if(!graphics->hdc || !brush_can_fill_path(brush))
3890 return NotImplemented;
3892 save_state = SaveDC(graphics->hdc);
3893 EndPath(graphics->hdc);
3894 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
3897 BeginPath(graphics->hdc);
3898 retval = draw_poly(graphics, NULL, path->pathdata.Points,
3899 path->pathdata.Types, path->pathdata.Count, FALSE);
3904 EndPath(graphics->hdc);
3905 brush_fill_path(graphics, brush);
3910 RestoreDC(graphics->hdc, save_state);
3915 static GpStatus SOFTWARE_GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
3920 if (!brush_can_fill_pixels(brush))
3921 return NotImplemented;
3923 /* FIXME: This could probably be done more efficiently without regions. */
3925 stat = GdipCreateRegionPath(path, &rgn);
3929 stat = GdipFillRegion(graphics, brush, rgn);
3931 GdipDeleteRegion(rgn);
3937 GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
3939 GpStatus stat = NotImplemented;
3941 TRACE("(%p, %p, %p)\n", graphics, brush, path);
3943 if(!brush || !graphics || !path)
3944 return InvalidParameter;
3949 if (!graphics->image)
3950 stat = GDI32_GdipFillPath(graphics, brush, path);
3952 if (stat == NotImplemented)
3953 stat = SOFTWARE_GdipFillPath(graphics, brush, path);
3955 if (stat == NotImplemented)
3957 FIXME("Not implemented for brushtype %i\n", brush->bt);
3964 GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
3965 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
3970 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
3971 graphics, brush, x, y, width, height, startAngle, sweepAngle);
3973 if(!graphics || !brush)
3974 return InvalidParameter;
3979 stat = GdipCreatePath(FillModeAlternate, &path);
3983 stat = GdipAddPathPie(path, x, y, width, height, startAngle, sweepAngle);
3986 stat = GdipFillPath(graphics, brush, path);
3988 GdipDeletePath(path);
3994 GpStatus WINGDIPAPI GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x,
3995 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
3997 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3998 graphics, brush, x, y, width, height, startAngle, sweepAngle);
4000 return GdipFillPie(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
4003 GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush,
4004 GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)
4009 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
4011 if(!graphics || !brush || !points || !count)
4012 return InvalidParameter;
4017 stat = GdipCreatePath(fillMode, &path);
4021 stat = GdipAddPathPolygon(path, points, count);
4024 stat = GdipFillPath(graphics, brush, path);
4026 GdipDeletePath(path);
4032 GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
4033 GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
4038 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
4040 if(!graphics || !brush || !points || !count)
4041 return InvalidParameter;
4046 stat = GdipCreatePath(fillMode, &path);
4050 stat = GdipAddPathPolygonI(path, points, count);
4053 stat = GdipFillPath(graphics, brush, path);
4055 GdipDeletePath(path);
4061 GpStatus WINGDIPAPI GdipFillPolygon2(GpGraphics *graphics, GpBrush *brush,
4062 GDIPCONST GpPointF *points, INT count)
4064 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
4066 return GdipFillPolygon(graphics, brush, points, count, FillModeAlternate);
4069 GpStatus WINGDIPAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush,
4070 GDIPCONST GpPoint *points, INT count)
4072 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
4074 return GdipFillPolygonI(graphics, brush, points, count, FillModeAlternate);
4077 GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics *graphics, GpBrush *brush,
4078 REAL x, REAL y, REAL width, REAL height)
4083 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
4085 if(!graphics || !brush)
4086 return InvalidParameter;
4091 stat = GdipCreatePath(FillModeAlternate, &path);
4095 stat = GdipAddPathRectangle(path, x, y, width, height);
4098 stat = GdipFillPath(graphics, brush, path);
4100 GdipDeletePath(path);
4106 GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush,
4107 INT x, INT y, INT width, INT height)
4109 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
4111 return GdipFillRectangle(graphics, brush, x, y, width, height);
4114 GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRectF *rects,
4120 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
4123 return InvalidParameter;
4125 for(i = 0; i < count; i++){
4126 ret = GdipFillRectangle(graphics, brush, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
4127 if(ret != Ok) return ret;
4133 GpStatus WINGDIPAPI GdipFillRectanglesI(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRect *rects,
4140 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
4142 if(!rects || count <= 0)
4143 return InvalidParameter;
4145 rectsF = GdipAlloc(sizeof(GpRectF)*count);
4149 for(i = 0; i < count; i++){
4150 rectsF[i].X = (REAL)rects[i].X;
4151 rectsF[i].Y = (REAL)rects[i].Y;
4152 rectsF[i].X = (REAL)rects[i].Width;
4153 rectsF[i].Height = (REAL)rects[i].Height;
4156 ret = GdipFillRectangles(graphics,brush,rectsF,count);
4162 static GpStatus GDI32_GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
4170 if(!graphics->hdc || !brush_can_fill_path(brush))
4171 return NotImplemented;
4173 status = GdipGetRegionHRgn(region, graphics, &hrgn);
4177 save_state = SaveDC(graphics->hdc);
4178 EndPath(graphics->hdc);
4180 ExtSelectClipRgn(graphics->hdc, hrgn, RGN_AND);
4182 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
4184 BeginPath(graphics->hdc);
4185 Rectangle(graphics->hdc, rc.left, rc.top, rc.right, rc.bottom);
4186 EndPath(graphics->hdc);
4188 brush_fill_path(graphics, brush);
4191 RestoreDC(graphics->hdc, save_state);
4198 static GpStatus SOFTWARE_GdipFillRegion(GpGraphics *graphics, GpBrush *brush,
4202 GpRegion *temp_region;
4203 GpMatrix *world_to_device;
4204 GpRectF graphics_bounds;
4208 GpRect gp_bound_rect;
4210 if (!brush_can_fill_pixels(brush))
4211 return NotImplemented;
4213 stat = get_graphics_bounds(graphics, &graphics_bounds);
4216 stat = GdipCloneRegion(region, &temp_region);
4220 stat = get_graphics_transform(graphics, CoordinateSpaceDevice,
4221 CoordinateSpaceWorld, &world_to_device);
4225 stat = GdipTransformRegion(temp_region, world_to_device);
4227 GdipDeleteMatrix(world_to_device);
4231 stat = GdipCombineRegionRect(temp_region, &graphics_bounds, CombineModeIntersect);
4234 stat = GdipGetRegionHRgn(temp_region, NULL, &hregion);
4236 GdipDeleteRegion(temp_region);
4239 if (stat == Ok && GetRgnBox(hregion, &bound_rect) == NULLREGION)
4241 DeleteObject(hregion);
4247 gp_bound_rect.X = bound_rect.left;
4248 gp_bound_rect.Y = bound_rect.top;
4249 gp_bound_rect.Width = bound_rect.right - bound_rect.left;
4250 gp_bound_rect.Height = bound_rect.bottom - bound_rect.top;
4252 pixel_data = GdipAlloc(sizeof(*pixel_data) * gp_bound_rect.Width * gp_bound_rect.Height);
4258 stat = brush_fill_pixels(graphics, brush, pixel_data,
4259 &gp_bound_rect, gp_bound_rect.Width);
4262 stat = alpha_blend_pixels_hrgn(graphics, gp_bound_rect.X,
4263 gp_bound_rect.Y, (BYTE*)pixel_data, gp_bound_rect.Width,
4264 gp_bound_rect.Height, gp_bound_rect.Width * 4, hregion);
4266 GdipFree(pixel_data);
4269 DeleteObject(hregion);
4275 /*****************************************************************************
4276 * GdipFillRegion [GDIPLUS.@]
4278 GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
4281 GpStatus stat = NotImplemented;
4283 TRACE("(%p, %p, %p)\n", graphics, brush, region);
4285 if (!(graphics && brush && region))
4286 return InvalidParameter;
4291 if (!graphics->image)
4292 stat = GDI32_GdipFillRegion(graphics, brush, region);
4294 if (stat == NotImplemented)
4295 stat = SOFTWARE_GdipFillRegion(graphics, brush, region);
4297 if (stat == NotImplemented)
4299 FIXME("not implemented for brushtype %i\n", brush->bt);
4306 GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention)
4308 TRACE("(%p,%u)\n", graphics, intention);
4311 return InvalidParameter;
4316 /* We have no internal operation queue, so there's no need to clear it. */
4324 /*****************************************************************************
4325 * GdipGetClipBounds [GDIPLUS.@]
4327 GpStatus WINGDIPAPI GdipGetClipBounds(GpGraphics *graphics, GpRectF *rect)
4329 TRACE("(%p, %p)\n", graphics, rect);
4332 return InvalidParameter;
4337 return GdipGetRegionBounds(graphics->clip, graphics, rect);
4340 /*****************************************************************************
4341 * GdipGetClipBoundsI [GDIPLUS.@]
4343 GpStatus WINGDIPAPI GdipGetClipBoundsI(GpGraphics *graphics, GpRect *rect)
4345 TRACE("(%p, %p)\n", graphics, rect);
4348 return InvalidParameter;
4353 return GdipGetRegionBoundsI(graphics->clip, graphics, rect);
4356 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
4357 GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics,
4358 CompositingMode *mode)
4360 TRACE("(%p, %p)\n", graphics, mode);
4362 if(!graphics || !mode)
4363 return InvalidParameter;
4368 *mode = graphics->compmode;
4373 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
4374 GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
4375 CompositingQuality *quality)
4377 TRACE("(%p, %p)\n", graphics, quality);
4379 if(!graphics || !quality)
4380 return InvalidParameter;
4385 *quality = graphics->compqual;
4390 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
4391 GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
4392 InterpolationMode *mode)
4394 TRACE("(%p, %p)\n", graphics, mode);
4396 if(!graphics || !mode)
4397 return InvalidParameter;
4402 *mode = graphics->interpolation;
4407 /* FIXME: Need to handle color depths less than 24bpp */
4408 GpStatus WINGDIPAPI GdipGetNearestColor(GpGraphics *graphics, ARGB* argb)
4410 FIXME("(%p, %p): Passing color unmodified\n", graphics, argb);
4412 if(!graphics || !argb)
4413 return InvalidParameter;
4421 GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
4423 TRACE("(%p, %p)\n", graphics, scale);
4425 if(!graphics || !scale)
4426 return InvalidParameter;
4431 *scale = graphics->scale;
4436 GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
4438 TRACE("(%p, %p)\n", graphics, unit);
4440 if(!graphics || !unit)
4441 return InvalidParameter;
4446 *unit = graphics->unit;
4451 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
4452 GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
4455 TRACE("(%p, %p)\n", graphics, mode);
4457 if(!graphics || !mode)
4458 return InvalidParameter;
4463 *mode = graphics->pixeloffset;
4468 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
4469 GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
4471 TRACE("(%p, %p)\n", graphics, mode);
4473 if(!graphics || !mode)
4474 return InvalidParameter;
4479 *mode = graphics->smoothing;
4484 GpStatus WINGDIPAPI GdipGetTextContrast(GpGraphics *graphics, UINT *contrast)
4486 TRACE("(%p, %p)\n", graphics, contrast);
4488 if(!graphics || !contrast)
4489 return InvalidParameter;
4491 *contrast = graphics->textcontrast;
4496 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
4497 GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics,
4498 TextRenderingHint *hint)
4500 TRACE("(%p, %p)\n", graphics, hint);
4502 if(!graphics || !hint)
4503 return InvalidParameter;
4508 *hint = graphics->texthint;
4513 GpStatus WINGDIPAPI GdipGetVisibleClipBounds(GpGraphics *graphics, GpRectF *rect)
4518 TRACE("(%p, %p)\n", graphics, rect);
4520 if(!graphics || !rect)
4521 return InvalidParameter;
4526 /* intersect window and graphics clipping regions */
4527 if((stat = GdipCreateRegion(&clip_rgn)) != Ok)
4530 if((stat = get_visible_clip_region(graphics, clip_rgn)) != Ok)
4533 /* get bounds of the region */
4534 stat = GdipGetRegionBounds(clip_rgn, graphics, rect);
4537 GdipDeleteRegion(clip_rgn);
4542 GpStatus WINGDIPAPI GdipGetVisibleClipBoundsI(GpGraphics *graphics, GpRect *rect)
4547 TRACE("(%p, %p)\n", graphics, rect);
4549 if(!graphics || !rect)
4550 return InvalidParameter;
4552 if((stat = GdipGetVisibleClipBounds(graphics, &rectf)) == Ok)
4554 rect->X = roundr(rectf.X);
4555 rect->Y = roundr(rectf.Y);
4556 rect->Width = roundr(rectf.Width);
4557 rect->Height = roundr(rectf.Height);
4563 GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
4565 TRACE("(%p, %p)\n", graphics, matrix);
4567 if(!graphics || !matrix)
4568 return InvalidParameter;
4573 *matrix = *graphics->worldtrans;
4577 GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color)
4583 TRACE("(%p, %x)\n", graphics, color);
4586 return InvalidParameter;
4591 if((stat = GdipCreateSolidFill(color, &brush)) != Ok)
4594 if((stat = get_graphics_bounds(graphics, &wnd_rect)) != Ok){
4595 GdipDeleteBrush((GpBrush*)brush);
4599 GdipFillRectangle(graphics, (GpBrush*)brush, wnd_rect.X, wnd_rect.Y,
4600 wnd_rect.Width, wnd_rect.Height);
4602 GdipDeleteBrush((GpBrush*)brush);
4607 GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics *graphics, BOOL *res)
4609 TRACE("(%p, %p)\n", graphics, res);
4611 if(!graphics || !res)
4612 return InvalidParameter;
4614 return GdipIsEmptyRegion(graphics->clip, graphics, res);
4617 GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics *graphics, REAL x, REAL y, BOOL *result)
4623 TRACE("(%p, %.2f, %.2f, %p)\n", graphics, x, y, result);
4625 if(!graphics || !result)
4626 return InvalidParameter;
4633 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
4634 CoordinateSpaceWorld, &pt, 1)) != Ok)
4637 if((stat = GdipCreateRegion(&rgn)) != Ok)
4640 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
4643 stat = GdipIsVisibleRegionPoint(rgn, pt.X, pt.Y, graphics, result);
4646 GdipDeleteRegion(rgn);
4650 GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics *graphics, INT x, INT y, BOOL *result)
4652 return GdipIsVisiblePoint(graphics, (REAL)x, (REAL)y, result);
4655 GpStatus WINGDIPAPI GdipIsVisibleRect(GpGraphics *graphics, REAL x, REAL y, REAL width, REAL height, BOOL *result)
4661 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics, x, y, width, height, result);
4663 if(!graphics || !result)
4664 return InvalidParameter;
4671 pts[1].X = x + width;
4672 pts[1].Y = y + height;
4674 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
4675 CoordinateSpaceWorld, pts, 2)) != Ok)
4678 pts[1].X -= pts[0].X;
4679 pts[1].Y -= pts[0].Y;
4681 if((stat = GdipCreateRegion(&rgn)) != Ok)
4684 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
4687 stat = GdipIsVisibleRegionRect(rgn, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y, graphics, result);
4690 GdipDeleteRegion(rgn);
4694 GpStatus WINGDIPAPI GdipIsVisibleRectI(GpGraphics *graphics, INT x, INT y, INT width, INT height, BOOL *result)
4696 return GdipIsVisibleRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, result);
4699 GpStatus gdip_format_string(HDC hdc,
4700 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
4701 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4702 gdip_format_string_callback callback, void *user_data)
4705 int sum = 0, height = 0, fit, fitcpy, i, j, lret, nwidth,
4706 nheight, lineend, lineno = 0;
4708 StringAlignment halign;
4711 HotkeyPrefix hkprefix;
4712 INT *hotkeyprefix_offsets=NULL;
4713 INT hotkeyprefix_count=0;
4714 INT hotkeyprefix_pos=0, hotkeyprefix_end_pos=0;
4717 if(length == -1) length = lstrlenW(string);
4719 stringdup = GdipAlloc((length + 1) * sizeof(WCHAR));
4720 if(!stringdup) return OutOfMemory;
4722 nwidth = roundr(rect->Width);
4723 nheight = roundr(rect->Height);
4725 if (rect->Width >= INT_MAX || rect->Width < 0.5) nwidth = INT_MAX;
4726 if (rect->Height >= INT_MAX || rect->Height < 0.5) nheight = INT_MAX;
4729 hkprefix = format->hkprefix;
4731 hkprefix = HotkeyPrefixNone;
4733 if (hkprefix == HotkeyPrefixShow)
4735 for (i=0; i<length; i++)
4737 if (string[i] == '&')
4738 hotkeyprefix_count++;
4742 if (hotkeyprefix_count)
4743 hotkeyprefix_offsets = GdipAlloc(sizeof(INT) * hotkeyprefix_count);
4745 hotkeyprefix_count = 0;
4747 for(i = 0, j = 0; i < length; i++){
4748 /* FIXME: This makes the indexes passed to callback inaccurate. */
4749 if(!isprintW(string[i]) && (string[i] != '\n'))
4752 if (seen_prefix && hkprefix == HotkeyPrefixShow && string[i] != '&')
4753 hotkeyprefix_offsets[hotkeyprefix_count++] = j;
4754 else if (!seen_prefix && hkprefix != HotkeyPrefixNone && string[i] == '&')
4762 stringdup[j] = string[i];
4768 if (format) halign = format->align;
4769 else halign = StringAlignmentNear;
4771 while(sum < length){
4772 GetTextExtentExPointW(hdc, stringdup + sum, length - sum,
4773 nwidth, &fit, NULL, &size);
4779 for(lret = 0; lret < fit; lret++)
4780 if(*(stringdup + sum + lret) == '\n')
4783 /* Line break code (may look strange, but it imitates windows). */
4785 lineend = fit = lret; /* this is not an off-by-one error */
4786 else if(fit < (length - sum)){
4787 if(*(stringdup + sum + fit) == ' ')
4788 while(*(stringdup + sum + fit) == ' ')
4791 while(*(stringdup + sum + fit - 1) != ' '){
4794 if(*(stringdup + sum + fit) == '\t')
4803 while(*(stringdup + sum + lineend - 1) == ' ' ||
4804 *(stringdup + sum + lineend - 1) == '\t')
4810 GetTextExtentExPointW(hdc, stringdup + sum, lineend,
4811 nwidth, &j, NULL, &size);
4813 bounds.Width = size.cx;
4815 if(height + size.cy > nheight)
4816 bounds.Height = nheight - (height + size.cy);
4818 bounds.Height = size.cy;
4820 bounds.Y = rect->Y + height;
4824 case StringAlignmentNear:
4828 case StringAlignmentCenter:
4829 bounds.X = rect->X + (rect->Width/2) - (bounds.Width/2);
4831 case StringAlignmentFar:
4832 bounds.X = rect->X + rect->Width - bounds.Width;
4836 for (hotkeyprefix_end_pos=hotkeyprefix_pos; hotkeyprefix_end_pos<hotkeyprefix_count; hotkeyprefix_end_pos++)
4837 if (hotkeyprefix_offsets[hotkeyprefix_end_pos] >= sum + lineend)
4840 stat = callback(hdc, stringdup, sum, lineend,
4841 font, rect, format, lineno, &bounds,
4842 &hotkeyprefix_offsets[hotkeyprefix_pos],
4843 hotkeyprefix_end_pos-hotkeyprefix_pos, user_data);
4848 sum += fit + (lret < fitcpy ? 1 : 0);
4852 hotkeyprefix_pos = hotkeyprefix_end_pos;
4854 if(height > nheight)
4857 /* Stop if this was a linewrap (but not if it was a linebreak). */
4858 if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
4862 GdipFree(stringdup);
4863 GdipFree(hotkeyprefix_offsets);
4868 struct measure_ranges_args {
4872 static GpStatus measure_ranges_callback(HDC hdc,
4873 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
4874 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
4875 INT lineno, const RectF *bounds, INT *underlined_indexes,
4876 INT underlined_index_count, void *user_data)
4880 struct measure_ranges_args *args = user_data;
4882 for (i=0; i<format->range_count; i++)
4884 INT range_start = max(index, format->character_ranges[i].First);
4885 INT range_end = min(index+length, format->character_ranges[i].First+format->character_ranges[i].Length);
4886 if (range_start < range_end)
4891 range_rect.Y = bounds->Y;
4892 range_rect.Height = bounds->Height;
4894 GetTextExtentExPointW(hdc, string + index, range_start - index,
4895 INT_MAX, NULL, NULL, &range_size);
4896 range_rect.X = bounds->X + range_size.cx;
4898 GetTextExtentExPointW(hdc, string + index, range_end - index,
4899 INT_MAX, NULL, NULL, &range_size);
4900 range_rect.Width = (bounds->X + range_size.cx) - range_rect.X;
4902 stat = GdipCombineRegionRect(args->regions[i], &range_rect, CombineModeUnion);
4911 static void rect_to_pixels(const RectF *in, const GpGraphics *graphics, RectF *out)
4915 GdipGetDpiX((GpGraphics *)graphics, &dpi);
4916 out->X = units_to_pixels(in->X, graphics->unit, dpi);
4917 out->Width = units_to_pixels(in->Width, graphics->unit, dpi);
4918 GdipGetDpiY((GpGraphics *)graphics, &dpi);
4919 out->Y = units_to_pixels(in->Y, graphics->unit, dpi);
4920 out->Height = units_to_pixels(in->Height, graphics->unit, dpi);
4923 static void rect_to_units(const RectF *in, const GpGraphics *graphics, RectF *out)
4927 GdipGetDpiX((GpGraphics *)graphics, &dpi);
4928 out->X = pixels_to_units(in->X, graphics->unit, dpi);
4929 out->Width = pixels_to_units(in->Width, graphics->unit, dpi);
4930 GdipGetDpiY((GpGraphics *)graphics, &dpi);
4931 out->Y = pixels_to_units(in->Y, graphics->unit, dpi);
4932 out->Height = pixels_to_units(in->Height, graphics->unit, dpi);
4935 GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,
4936 GDIPCONST WCHAR* string, INT length, GDIPCONST GpFont* font,
4937 GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat *stringFormat,
4938 INT regionCount, GpRegion** regions)
4944 struct measure_ranges_args args;
4945 HDC hdc, temp_hdc=NULL;
4947 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics, debugstr_w(string),
4948 length, font, debugstr_rectf(layoutRect), stringFormat, regionCount, regions);
4950 if (!(graphics && string && font && layoutRect && stringFormat && regions))
4951 return InvalidParameter;
4953 if (regionCount < stringFormat->range_count)
4954 return InvalidParameter;
4956 get_log_fontW(font, graphics, &lfw);
4960 hdc = temp_hdc = CreateCompatibleDC(0);
4961 if (!temp_hdc) return OutOfMemory;
4964 hdc = graphics->hdc;
4966 if (stringFormat->attr)
4967 TRACE("may be ignoring some format flags: attr %x\n", stringFormat->attr);
4969 oldfont = SelectObject(hdc, CreateFontIndirectW(&lfw));
4971 for (i=0; i<stringFormat->range_count; i++)
4973 stat = GdipSetEmpty(regions[i]);
4978 args.regions = regions;
4980 stat = gdip_format_string(hdc, string, length, font, layoutRect, stringFormat,
4981 measure_ranges_callback, &args);
4983 DeleteObject(SelectObject(hdc, oldfont));
4991 struct measure_string_args {
4993 INT *codepointsfitted;
4995 REAL rel_width, rel_height;
4998 static GpStatus measure_string_callback(HDC hdc,
4999 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
5000 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
5001 INT lineno, const RectF *bounds, INT *underlined_indexes,
5002 INT underlined_index_count, void *user_data)
5004 struct measure_string_args *args = user_data;
5005 REAL new_width, new_height;
5007 new_width = bounds->Width / args->rel_width;
5008 new_height = (bounds->Height + bounds->Y - args->bounds->Y) / args->rel_height;
5010 if (new_width > args->bounds->Width)
5011 args->bounds->Width = new_width;
5013 if (new_height > args->bounds->Height)
5014 args->bounds->Height = new_height;
5016 if (args->codepointsfitted)
5017 *args->codepointsfitted = index + length;
5019 if (args->linesfilled)
5020 (*args->linesfilled)++;
5025 /* Find the smallest rectangle that bounds the text when it is printed in rect
5026 * according to the format options listed in format. If rect has 0 width and
5027 * height, then just find the smallest rectangle that bounds the text when it's
5028 * printed at location (rect->X, rect-Y). */
5029 GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
5030 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
5031 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
5032 INT *codepointsfitted, INT *linesfilled)
5034 HFONT oldfont, gdifont;
5035 struct measure_string_args args;
5036 HDC temp_hdc=NULL, hdc;
5040 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics,
5041 debugstr_wn(string, length), length, font, debugstr_rectf(rect), format,
5042 bounds, codepointsfitted, linesfilled);
5044 if(!graphics || !string || !font || !rect || !bounds)
5045 return InvalidParameter;
5049 hdc = temp_hdc = CreateCompatibleDC(0);
5050 if (!temp_hdc) return OutOfMemory;
5053 hdc = graphics->hdc;
5055 if(linesfilled) *linesfilled = 0;
5056 if(codepointsfitted) *codepointsfitted = 0;
5059 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
5067 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
5068 args.rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
5069 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
5070 args.rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
5071 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
5073 get_font_hfont(graphics, font, &gdifont);
5074 oldfont = SelectObject(hdc, gdifont);
5076 rect_to_pixels(rect, graphics, &rect_pixels);
5078 bounds->X = rect_pixels.X;
5079 bounds->Y = rect_pixels.Y;
5080 bounds->Width = 0.0;
5081 bounds->Height = 0.0;
5083 args.bounds = bounds;
5084 args.codepointsfitted = codepointsfitted;
5085 args.linesfilled = linesfilled;
5087 gdip_format_string(hdc, string, length, font, &rect_pixels, format,
5088 measure_string_callback, &args);
5090 rect_to_units(bounds, graphics, bounds);
5092 SelectObject(hdc, oldfont);
5093 DeleteObject(gdifont);
5101 struct draw_string_args {
5102 GpGraphics *graphics;
5103 GDIPCONST GpBrush *brush;
5104 REAL x, y, rel_width, rel_height, ascent;
5107 static GpStatus draw_string_callback(HDC hdc,
5108 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
5109 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
5110 INT lineno, const RectF *bounds, INT *underlined_indexes,
5111 INT underlined_index_count, void *user_data)
5113 struct draw_string_args *args = user_data;
5117 position.X = args->x + bounds->X / args->rel_width;
5118 position.Y = args->y + bounds->Y / args->rel_height + args->ascent;
5120 stat = GdipDrawDriverString(args->graphics, &string[index], length, font,
5121 args->brush, &position,
5122 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance, NULL);
5124 if (stat == Ok && underlined_index_count)
5126 OUTLINETEXTMETRICW otm;
5127 REAL underline_y, underline_height;
5130 GetOutlineTextMetricsW(hdc, sizeof(otm), &otm);
5132 underline_height = otm.otmsUnderscoreSize / args->rel_height;
5133 underline_y = position.Y - otm.otmsUnderscorePosition / args->rel_height - underline_height / 2;
5135 for (i=0; i<underlined_index_count; i++)
5137 REAL start_x, end_x;
5139 INT ofs = underlined_indexes[i] - index;
5141 GetTextExtentExPointW(hdc, string + index, ofs, INT_MAX, NULL, NULL, &text_size);
5142 start_x = text_size.cx / args->rel_width;
5144 GetTextExtentExPointW(hdc, string + index, ofs+1, INT_MAX, NULL, NULL, &text_size);
5145 end_x = text_size.cx / args->rel_width;
5147 GdipFillRectangle(args->graphics, (GpBrush*)args->brush, position.X+start_x, underline_y, end_x-start_x, underline_height);
5154 GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string,
5155 INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect,
5156 GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush)
5160 GpPointF pt[3], rectcpy[4];
5162 REAL rel_width, rel_height;
5165 struct draw_string_args args;
5167 HDC hdc, temp_hdc=NULL;
5168 TEXTMETRICW textmetric;
5170 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length),
5171 length, font, debugstr_rectf(rect), format, brush);
5173 if(!graphics || !string || !font || !brush || !rect)
5174 return InvalidParameter;
5178 hdc = graphics->hdc;
5182 hdc = temp_hdc = CreateCompatibleDC(0);
5186 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
5188 /* Should be no need to explicitly test for StringAlignmentNear as
5189 * that is default behavior if no alignment is passed. */
5190 if(format->vertalign != StringAlignmentNear){
5191 RectF bounds, in_rect = *rect;
5192 in_rect.Height = 0.0; /* avoid height clipping */
5193 GdipMeasureString(graphics, string, length, font, &in_rect, format, &bounds, 0, 0);
5195 TRACE("bounds %s\n", debugstr_rectf(&bounds));
5197 if(format->vertalign == StringAlignmentCenter)
5198 offsety = (rect->Height - bounds.Height) / 2;
5199 else if(format->vertalign == StringAlignmentFar)
5200 offsety = (rect->Height - bounds.Height);
5202 TRACE("vertical align %d, offsety %f\n", format->vertalign, offsety);
5205 save_state = SaveDC(hdc);
5213 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
5214 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
5215 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
5216 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
5217 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
5219 rectcpy[3].X = rectcpy[0].X = rect->X;
5220 rectcpy[1].Y = rectcpy[0].Y = rect->Y;
5221 rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width;
5222 rectcpy[3].Y = rectcpy[2].Y = rect->Y + rect->Height;
5223 transform_and_round_points(graphics, corners, rectcpy, 4);
5225 scaled_rect.X = 0.0;
5226 scaled_rect.Y = 0.0;
5227 scaled_rect.Width = rel_width * rect->Width;
5228 scaled_rect.Height = rel_height * rect->Height;
5230 if (roundr(scaled_rect.Width) != 0 && roundr(scaled_rect.Height) != 0)
5232 /* FIXME: If only the width or only the height is 0, we should probably still clip */
5233 rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
5234 SelectClipRgn(hdc, rgn);
5237 get_font_hfont(graphics, font, &gdifont);
5238 SelectObject(hdc, gdifont);
5240 args.graphics = graphics;
5244 args.y = rect->Y + offsety;
5246 args.rel_width = rel_width;
5247 args.rel_height = rel_height;
5249 GetTextMetricsW(hdc, &textmetric);
5250 args.ascent = textmetric.tmAscent / rel_height;
5252 gdip_format_string(hdc, string, length, font, &scaled_rect, format,
5253 draw_string_callback, &args);
5256 DeleteObject(gdifont);
5258 RestoreDC(hdc, save_state);
5265 GpStatus WINGDIPAPI GdipResetClip(GpGraphics *graphics)
5267 TRACE("(%p)\n", graphics);
5270 return InvalidParameter;
5275 return GdipSetInfinite(graphics->clip);
5278 GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics)
5280 TRACE("(%p)\n", graphics);
5283 return InvalidParameter;
5288 graphics->worldtrans->matrix[0] = 1.0;
5289 graphics->worldtrans->matrix[1] = 0.0;
5290 graphics->worldtrans->matrix[2] = 0.0;
5291 graphics->worldtrans->matrix[3] = 1.0;
5292 graphics->worldtrans->matrix[4] = 0.0;
5293 graphics->worldtrans->matrix[5] = 0.0;
5298 GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
5300 return GdipEndContainer(graphics, state);
5303 GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
5304 GpMatrixOrder order)
5306 TRACE("(%p, %.2f, %d)\n", graphics, angle, order);
5309 return InvalidParameter;
5314 return GdipRotateMatrix(graphics->worldtrans, angle, order);
5317 GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
5319 return GdipBeginContainer2(graphics, state);
5322 GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics *graphics,
5323 GraphicsContainer *state)
5325 GraphicsContainerItem *container;
5328 TRACE("(%p, %p)\n", graphics, state);
5330 if(!graphics || !state)
5331 return InvalidParameter;
5333 sts = init_container(&container, graphics);
5337 list_add_head(&graphics->containers, &container->entry);
5338 *state = graphics->contid = container->contid;
5343 GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics *graphics, GDIPCONST GpRectF *dstrect, GDIPCONST GpRectF *srcrect, GpUnit unit, GraphicsContainer *state)
5345 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
5346 return NotImplemented;
5349 GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics *graphics, GDIPCONST GpRect *dstrect, GDIPCONST GpRect *srcrect, GpUnit unit, GraphicsContainer *state)
5351 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
5352 return NotImplemented;
5355 GpStatus WINGDIPAPI GdipComment(GpGraphics *graphics, UINT sizeData, GDIPCONST BYTE *data)
5357 FIXME("(%p, %d, %p): stub\n", graphics, sizeData, data);
5358 return NotImplemented;
5361 GpStatus WINGDIPAPI GdipEndContainer(GpGraphics *graphics, GraphicsContainer state)
5364 GraphicsContainerItem *container, *container2;
5366 TRACE("(%p, %x)\n", graphics, state);
5369 return InvalidParameter;
5371 LIST_FOR_EACH_ENTRY(container, &graphics->containers, GraphicsContainerItem, entry){
5372 if(container->contid == state)
5376 /* did not find a matching container */
5377 if(&container->entry == &graphics->containers)
5380 sts = restore_container(graphics, container);
5384 /* remove all of the containers on top of the found container */
5385 LIST_FOR_EACH_ENTRY_SAFE(container, container2, &graphics->containers, GraphicsContainerItem, entry){
5386 if(container->contid == state)
5388 list_remove(&container->entry);
5389 delete_container(container);
5392 list_remove(&container->entry);
5393 delete_container(container);
5398 GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
5399 REAL sy, GpMatrixOrder order)
5401 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, sx, sy, order);
5404 return InvalidParameter;
5409 return GdipScaleMatrix(graphics->worldtrans, sx, sy, order);
5412 GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics *graphics, GpGraphics *srcgraphics,
5415 TRACE("(%p, %p, %d)\n", graphics, srcgraphics, mode);
5417 if(!graphics || !srcgraphics)
5418 return InvalidParameter;
5420 return GdipCombineRegionRegion(graphics->clip, srcgraphics->clip, mode);
5423 GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
5424 CompositingMode mode)
5426 TRACE("(%p, %d)\n", graphics, mode);
5429 return InvalidParameter;
5434 graphics->compmode = mode;
5439 GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
5440 CompositingQuality quality)
5442 TRACE("(%p, %d)\n", graphics, quality);
5445 return InvalidParameter;
5450 graphics->compqual = quality;
5455 GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
5456 InterpolationMode mode)
5458 TRACE("(%p, %d)\n", graphics, mode);
5460 if(!graphics || mode == InterpolationModeInvalid || mode > InterpolationModeHighQualityBicubic)
5461 return InvalidParameter;
5466 if (mode == InterpolationModeDefault || mode == InterpolationModeLowQuality)
5467 mode = InterpolationModeBilinear;
5469 if (mode == InterpolationModeHighQuality)
5470 mode = InterpolationModeHighQualityBicubic;
5472 graphics->interpolation = mode;
5477 GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
5479 TRACE("(%p, %.2f)\n", graphics, scale);
5481 if(!graphics || (scale <= 0.0))
5482 return InvalidParameter;
5487 graphics->scale = scale;
5492 GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
5494 TRACE("(%p, %d)\n", graphics, unit);
5497 return InvalidParameter;
5502 if(unit == UnitWorld)
5503 return InvalidParameter;
5505 graphics->unit = unit;
5510 GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
5513 TRACE("(%p, %d)\n", graphics, mode);
5516 return InvalidParameter;
5521 graphics->pixeloffset = mode;
5526 GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics *graphics, INT x, INT y)
5530 TRACE("(%p,%i,%i)\n", graphics, x, y);
5533 FIXME("value is unused in rendering\n");
5536 return InvalidParameter;
5538 graphics->origin_x = x;
5539 graphics->origin_y = y;
5544 GpStatus WINGDIPAPI GdipGetRenderingOrigin(GpGraphics *graphics, INT *x, INT *y)
5546 TRACE("(%p,%p,%p)\n", graphics, x, y);
5548 if (!graphics || !x || !y)
5549 return InvalidParameter;
5551 *x = graphics->origin_x;
5552 *y = graphics->origin_y;
5557 GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
5559 TRACE("(%p, %d)\n", graphics, mode);
5562 return InvalidParameter;
5567 graphics->smoothing = mode;
5572 GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics *graphics, UINT contrast)
5574 TRACE("(%p, %d)\n", graphics, contrast);
5577 return InvalidParameter;
5579 graphics->textcontrast = contrast;
5584 GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
5585 TextRenderingHint hint)
5587 TRACE("(%p, %d)\n", graphics, hint);
5589 if(!graphics || hint > TextRenderingHintClearTypeGridFit)
5590 return InvalidParameter;
5595 graphics->texthint = hint;
5600 GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
5602 TRACE("(%p, %p)\n", graphics, matrix);
5604 if(!graphics || !matrix)
5605 return InvalidParameter;
5610 GdipDeleteMatrix(graphics->worldtrans);
5611 return GdipCloneMatrix(matrix, &graphics->worldtrans);
5614 GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
5615 REAL dy, GpMatrixOrder order)
5617 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, dx, dy, order);
5620 return InvalidParameter;
5625 return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order);
5628 /*****************************************************************************
5629 * GdipSetClipHrgn [GDIPLUS.@]
5631 GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics *graphics, HRGN hrgn, CombineMode mode)
5636 TRACE("(%p, %p, %d)\n", graphics, hrgn, mode);
5639 return InvalidParameter;
5641 status = GdipCreateRegionHrgn(hrgn, ®ion);
5645 status = GdipSetClipRegion(graphics, region, mode);
5647 GdipDeleteRegion(region);
5651 GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics *graphics, GpPath *path, CombineMode mode)
5653 TRACE("(%p, %p, %d)\n", graphics, path, mode);
5656 return InvalidParameter;
5661 return GdipCombineRegionPath(graphics->clip, path, mode);
5664 GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y,
5665 REAL width, REAL height,
5670 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics, x, y, width, height, mode);
5673 return InvalidParameter;
5681 rect.Height = height;
5683 return GdipCombineRegionRect(graphics->clip, &rect, mode);
5686 GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y,
5687 INT width, INT height,
5690 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics, x, y, width, height, mode);
5693 return InvalidParameter;
5698 return GdipSetClipRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, mode);
5701 GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
5704 TRACE("(%p, %p, %d)\n", graphics, region, mode);
5706 if(!graphics || !region)
5707 return InvalidParameter;
5712 return GdipCombineRegionRegion(graphics->clip, region, mode);
5715 GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile *metafile,
5720 TRACE("(%p,%u)\n", metafile, limitDpi);
5723 FIXME("not implemented\n");
5725 return NotImplemented;
5728 GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points,
5734 TRACE("(%p, %p, %d)\n", graphics, points, count);
5736 if(!graphics || !pen || count<=0)
5737 return InvalidParameter;
5744 FIXME("graphics object has no HDC\n");
5748 pti = GdipAlloc(sizeof(POINT) * count);
5750 save_state = prepare_dc(graphics, pen);
5751 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
5753 transform_and_round_points(graphics, pti, (GpPointF*)points, count);
5754 Polygon(graphics->hdc, pti, count);
5756 restore_dc(graphics, save_state);
5762 GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points,
5769 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
5771 if(count<=0) return InvalidParameter;
5772 ptf = GdipAlloc(sizeof(GpPointF) * count);
5774 for(i = 0;i < count; i++){
5775 ptf[i].X = (REAL)points[i].X;
5776 ptf[i].Y = (REAL)points[i].Y;
5779 ret = GdipDrawPolygon(graphics,pen,ptf,count);
5785 GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
5787 TRACE("(%p, %p)\n", graphics, dpi);
5789 if(!graphics || !dpi)
5790 return InvalidParameter;
5795 if (graphics->image)
5796 *dpi = graphics->image->xres;
5798 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
5803 GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
5805 TRACE("(%p, %p)\n", graphics, dpi);
5807 if(!graphics || !dpi)
5808 return InvalidParameter;
5813 if (graphics->image)
5814 *dpi = graphics->image->yres;
5816 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
5821 GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix,
5822 GpMatrixOrder order)
5827 TRACE("(%p, %p, %d)\n", graphics, matrix, order);
5829 if(!graphics || !matrix)
5830 return InvalidParameter;
5835 m = *(graphics->worldtrans);
5837 ret = GdipMultiplyMatrix(&m, matrix, order);
5839 *(graphics->worldtrans) = m;
5844 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
5845 static const COLORREF DC_BACKGROUND_KEY = 0x0c0b0d;
5847 GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
5851 TRACE("(%p, %p)\n", graphics, hdc);
5853 if(!graphics || !hdc)
5854 return InvalidParameter;
5859 if (graphics->image && graphics->image->type == ImageTypeMetafile)
5861 stat = METAFILE_GetDC((GpMetafile*)graphics->image, hdc);
5863 else if (!graphics->hdc ||
5864 (graphics->image && graphics->image->type == ImageTypeBitmap && ((GpBitmap*)graphics->image)->format & PixelFormatAlpha))
5866 /* Create a fake HDC and fill it with a constant color. */
5870 BITMAPINFOHEADER bmih;
5873 stat = get_graphics_bounds(graphics, &bounds);
5877 graphics->temp_hbitmap_width = bounds.Width;
5878 graphics->temp_hbitmap_height = bounds.Height;
5880 bmih.biSize = sizeof(bmih);
5881 bmih.biWidth = graphics->temp_hbitmap_width;
5882 bmih.biHeight = -graphics->temp_hbitmap_height;
5884 bmih.biBitCount = 32;
5885 bmih.biCompression = BI_RGB;
5886 bmih.biSizeImage = 0;
5887 bmih.biXPelsPerMeter = 0;
5888 bmih.biYPelsPerMeter = 0;
5890 bmih.biClrImportant = 0;
5892 hbitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
5893 (void**)&graphics->temp_bits, NULL, 0);
5895 return GenericError;
5897 temp_hdc = CreateCompatibleDC(0);
5900 DeleteObject(hbitmap);
5901 return GenericError;
5904 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
5905 ((DWORD*)graphics->temp_bits)[i] = DC_BACKGROUND_KEY;
5907 SelectObject(temp_hdc, hbitmap);
5909 graphics->temp_hbitmap = hbitmap;
5910 *hdc = graphics->temp_hdc = temp_hdc;
5914 *hdc = graphics->hdc;
5918 graphics->busy = TRUE;
5923 GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
5927 TRACE("(%p, %p)\n", graphics, hdc);
5929 if(!graphics || !hdc || !graphics->busy)
5930 return InvalidParameter;
5932 if (graphics->image && graphics->image->type == ImageTypeMetafile)
5934 stat = METAFILE_ReleaseDC((GpMetafile*)graphics->image, hdc);
5936 else if (graphics->temp_hdc == hdc)
5941 /* Find the pixels that have changed, and mark them as opaque. */
5942 pos = (DWORD*)graphics->temp_bits;
5943 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
5945 if (*pos != DC_BACKGROUND_KEY)
5952 /* Write the changed pixels to the real target. */
5953 alpha_blend_pixels(graphics, 0, 0, graphics->temp_bits,
5954 graphics->temp_hbitmap_width, graphics->temp_hbitmap_height,
5955 graphics->temp_hbitmap_width * 4);
5958 DeleteDC(graphics->temp_hdc);
5959 DeleteObject(graphics->temp_hbitmap);
5960 graphics->temp_hdc = NULL;
5961 graphics->temp_hbitmap = NULL;
5963 else if (hdc != graphics->hdc)
5965 stat = InvalidParameter;
5969 graphics->busy = FALSE;
5974 GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
5979 TRACE("(%p, %p)\n", graphics, region);
5981 if(!graphics || !region)
5982 return InvalidParameter;
5987 if((status = GdipCloneRegion(graphics->clip, &clip)) != Ok)
5990 /* free everything except root node and header */
5991 delete_element(®ion->node);
5992 memcpy(region, clip, sizeof(GpRegion));
5998 static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace dst_space,
5999 GpCoordinateSpace src_space, GpMatrix **matrix)
6001 GpStatus stat = GdipCreateMatrix(matrix);
6004 if (dst_space != src_space && stat == Ok)
6006 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
6008 if(graphics->unit != UnitDisplay)
6009 unitscale *= graphics->scale;
6011 /* transform from src_space to CoordinateSpacePage */
6014 case CoordinateSpaceWorld:
6015 GdipMultiplyMatrix(*matrix, graphics->worldtrans, MatrixOrderAppend);
6017 case CoordinateSpacePage:
6019 case CoordinateSpaceDevice:
6020 GdipScaleMatrix(*matrix, 1.0/unitscale, 1.0/unitscale, MatrixOrderAppend);
6024 /* transform from CoordinateSpacePage to dst_space */
6027 case CoordinateSpaceWorld:
6029 GpMatrix *inverted_transform;
6030 stat = GdipCloneMatrix(graphics->worldtrans, &inverted_transform);
6033 stat = GdipInvertMatrix(inverted_transform);
6035 GdipMultiplyMatrix(*matrix, inverted_transform, MatrixOrderAppend);
6036 GdipDeleteMatrix(inverted_transform);
6040 case CoordinateSpacePage:
6042 case CoordinateSpaceDevice:
6043 GdipScaleMatrix(*matrix, unitscale, unitscale, MatrixOrderAppend);
6050 GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space,
6051 GpCoordinateSpace src_space, GpPointF *points, INT count)
6056 if(!graphics || !points || count <= 0)
6057 return InvalidParameter;
6062 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
6064 if (src_space == dst_space) return Ok;
6066 stat = get_graphics_transform(graphics, dst_space, src_space, &matrix);
6070 stat = GdipTransformMatrixPoints(matrix, points, count);
6072 GdipDeleteMatrix(matrix);
6078 GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space,
6079 GpCoordinateSpace src_space, GpPoint *points, INT count)
6085 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
6088 return InvalidParameter;
6090 pointsF = GdipAlloc(sizeof(GpPointF) * count);
6094 for(i = 0; i < count; i++){
6095 pointsF[i].X = (REAL)points[i].X;
6096 pointsF[i].Y = (REAL)points[i].Y;
6099 ret = GdipTransformPoints(graphics, dst_space, src_space, pointsF, count);
6102 for(i = 0; i < count; i++){
6103 points[i].X = roundr(pointsF[i].X);
6104 points[i].Y = roundr(pointsF[i].Y);
6111 HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void)
6123 /*****************************************************************************
6124 * GdipTranslateClip [GDIPLUS.@]
6126 GpStatus WINGDIPAPI GdipTranslateClip(GpGraphics *graphics, REAL dx, REAL dy)
6128 TRACE("(%p, %.2f, %.2f)\n", graphics, dx, dy);
6131 return InvalidParameter;
6136 return GdipTranslateRegion(graphics->clip, dx, dy);
6139 /*****************************************************************************
6140 * GdipTranslateClipI [GDIPLUS.@]
6142 GpStatus WINGDIPAPI GdipTranslateClipI(GpGraphics *graphics, INT dx, INT dy)
6144 TRACE("(%p, %d, %d)\n", graphics, dx, dy);
6147 return InvalidParameter;
6152 return GdipTranslateRegion(graphics->clip, (REAL)dx, (REAL)dy);
6156 /*****************************************************************************
6157 * GdipMeasureDriverString [GDIPLUS.@]
6159 GpStatus WINGDIPAPI GdipMeasureDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
6160 GDIPCONST GpFont *font, GDIPCONST PointF *positions,
6161 INT flags, GDIPCONST GpMatrix *matrix, RectF *boundingBox)
6163 static const INT unsupported_flags = ~(DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance);
6166 REAL min_x, min_y, max_x, max_y, x, y;
6168 TEXTMETRICW textmetric;
6169 const WORD *glyph_indices;
6170 WORD *dynamic_glyph_indices=NULL;
6171 REAL rel_width, rel_height, ascent, descent;
6174 TRACE("(%p %p %d %p %p %d %p %p)\n", graphics, text, length, font, positions, flags, matrix, boundingBox);
6176 if (!graphics || !text || !font || !positions || !boundingBox)
6177 return InvalidParameter;
6180 length = strlenW(text);
6184 boundingBox->X = 0.0;
6185 boundingBox->Y = 0.0;
6186 boundingBox->Width = 0.0;
6187 boundingBox->Height = 0.0;
6190 if (flags & unsupported_flags)
6191 FIXME("Ignoring flags %x\n", flags & unsupported_flags);
6194 FIXME("Ignoring matrix\n");
6196 get_font_hfont(graphics, font, &hfont);
6198 hdc = CreateCompatibleDC(0);
6199 SelectObject(hdc, hfont);
6201 GetTextMetricsW(hdc, &textmetric);
6209 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
6210 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
6211 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
6212 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
6213 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
6215 if (flags & DriverStringOptionsCmapLookup)
6217 glyph_indices = dynamic_glyph_indices = GdipAlloc(sizeof(WORD) * length);
6221 DeleteObject(hfont);
6225 GetGlyphIndicesW(hdc, text, length, dynamic_glyph_indices, 0);
6228 glyph_indices = text;
6230 min_x = max_x = x = positions[0].X;
6231 min_y = max_y = y = positions[0].Y;
6233 ascent = textmetric.tmAscent / rel_height;
6234 descent = textmetric.tmDescent / rel_height;
6236 for (i=0; i<length; i++)
6241 if (!(flags & DriverStringOptionsRealizedAdvance))
6247 GetCharABCWidthsW(hdc, glyph_indices[i], glyph_indices[i], &abc);
6248 char_width = abc.abcA + abc.abcB + abc.abcB;
6250 if (min_y > y - ascent) min_y = y - ascent;
6251 if (max_y < y + descent) max_y = y + descent;
6252 if (min_x > x) min_x = x;
6254 x += char_width / rel_width;
6256 if (max_x < x) max_x = x;
6259 GdipFree(dynamic_glyph_indices);
6261 DeleteObject(hfont);
6263 boundingBox->X = min_x;
6264 boundingBox->Y = min_y;
6265 boundingBox->Width = max_x - min_x;
6266 boundingBox->Height = max_y - min_y;
6271 static GpStatus GDI32_GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
6272 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
6273 GDIPCONST PointF *positions, INT flags,
6274 GDIPCONST GpMatrix *matrix )
6276 static const INT unsupported_flags = ~(DriverStringOptionsRealizedAdvance|DriverStringOptionsCmapLookup);
6282 if (flags & unsupported_flags)
6283 FIXME("Ignoring flags %x\n", flags & unsupported_flags);
6286 FIXME("Ignoring matrix\n");
6288 if (!(flags & DriverStringOptionsCmapLookup))
6289 eto_flags |= ETO_GLYPH_INDEX;
6291 save_state = SaveDC(graphics->hdc);
6292 SetBkMode(graphics->hdc, TRANSPARENT);
6293 SetTextColor(graphics->hdc, get_gdi_brush_color(brush));
6296 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, &pt, 1);
6298 get_font_hfont(graphics, font, &hfont);
6299 SelectObject(graphics->hdc, hfont);
6301 SetTextAlign(graphics->hdc, TA_BASELINE|TA_LEFT);
6303 ExtTextOutW(graphics->hdc, roundr(pt.X), roundr(pt.Y), eto_flags, NULL, text, length, NULL);
6305 RestoreDC(graphics->hdc, save_state);
6307 DeleteObject(hfont);
6312 static GpStatus SOFTWARE_GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
6313 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
6314 GDIPCONST PointF *positions, INT flags,
6315 GDIPCONST GpMatrix *matrix )
6317 static const INT unsupported_flags = ~(DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance);
6319 PointF *real_positions, real_position;
6323 int min_x=INT_MAX, min_y=INT_MAX, max_x=INT_MIN, max_y=INT_MIN, i, x, y;
6324 DWORD max_glyphsize=0;
6325 GLYPHMETRICS glyphmetrics;
6326 static const MAT2 identity = {{0,1}, {0,0}, {0,0}, {0,1}};
6329 int text_mask_stride;
6331 int pixel_data_stride;
6333 UINT ggo_flags = GGO_GRAY8_BITMAP;
6338 if (!(flags & DriverStringOptionsCmapLookup))
6339 ggo_flags |= GGO_GLYPH_INDEX;
6341 if (flags & unsupported_flags)
6342 FIXME("Ignoring flags %x\n", flags & unsupported_flags);
6345 FIXME("Ignoring matrix\n");
6347 pti = GdipAlloc(sizeof(POINT) * length);
6351 if (flags & DriverStringOptionsRealizedAdvance)
6353 real_position = positions[0];
6355 transform_and_round_points(graphics, pti, &real_position, 1);
6359 real_positions = GdipAlloc(sizeof(PointF) * length);
6360 if (!real_positions)
6366 memcpy(real_positions, positions, sizeof(PointF) * length);
6368 transform_and_round_points(graphics, pti, real_positions, length);
6370 GdipFree(real_positions);
6373 get_font_hfont(graphics, font, &hfont);
6375 hdc = CreateCompatibleDC(0);
6376 SelectObject(hdc, hfont);
6378 /* Get the boundaries of the text to be drawn */
6379 for (i=0; i<length; i++)
6382 int left, top, right, bottom;
6384 glyphsize = GetGlyphOutlineW(hdc, text[i], ggo_flags,
6385 &glyphmetrics, 0, NULL, &identity);
6387 if (glyphsize == GDI_ERROR)
6389 ERR("GetGlyphOutlineW failed\n");
6392 DeleteObject(hfont);
6393 return GenericError;
6396 if (glyphsize > max_glyphsize)
6397 max_glyphsize = glyphsize;
6399 left = pti[i].x + glyphmetrics.gmptGlyphOrigin.x;
6400 top = pti[i].y - glyphmetrics.gmptGlyphOrigin.y;
6401 right = pti[i].x + glyphmetrics.gmptGlyphOrigin.x + glyphmetrics.gmBlackBoxX;
6402 bottom = pti[i].y - glyphmetrics.gmptGlyphOrigin.y + glyphmetrics.gmBlackBoxY;
6404 if (left < min_x) min_x = left;
6405 if (top < min_y) min_y = top;
6406 if (right > max_x) max_x = right;
6407 if (bottom > max_y) max_y = bottom;
6409 if (i+1 < length && (flags & DriverStringOptionsRealizedAdvance) == DriverStringOptionsRealizedAdvance)
6411 pti[i+1].x = pti[i].x + glyphmetrics.gmCellIncX;
6412 pti[i+1].y = pti[i].y + glyphmetrics.gmCellIncY;
6416 glyph_mask = GdipAlloc(max_glyphsize);
6417 text_mask = GdipAlloc((max_x - min_x) * (max_y - min_y));
6418 text_mask_stride = max_x - min_x;
6420 if (!(glyph_mask && text_mask))
6422 GdipFree(glyph_mask);
6423 GdipFree(text_mask);
6426 DeleteObject(hfont);
6430 /* Generate a mask for the text */
6431 for (i=0; i<length; i++)
6433 int left, top, stride;
6435 GetGlyphOutlineW(hdc, text[i], ggo_flags,
6436 &glyphmetrics, max_glyphsize, glyph_mask, &identity);
6438 left = pti[i].x + glyphmetrics.gmptGlyphOrigin.x;
6439 top = pti[i].y - glyphmetrics.gmptGlyphOrigin.y;
6440 stride = (glyphmetrics.gmBlackBoxX + 3) & (~3);
6442 for (y=0; y<glyphmetrics.gmBlackBoxY; y++)
6444 BYTE *glyph_val = glyph_mask + y * stride;
6445 BYTE *text_val = text_mask + (left - min_x) + (top - min_y + y) * text_mask_stride;
6446 for (x=0; x<glyphmetrics.gmBlackBoxX; x++)
6448 *text_val = min(64, *text_val + *glyph_val);
6457 DeleteObject(hfont);
6458 GdipFree(glyph_mask);
6460 /* get the brush data */
6461 pixel_data = GdipAlloc(4 * (max_x - min_x) * (max_y - min_y));
6464 GdipFree(text_mask);
6468 pixel_area.X = min_x;
6469 pixel_area.Y = min_y;
6470 pixel_area.Width = max_x - min_x;
6471 pixel_area.Height = max_y - min_y;
6472 pixel_data_stride = pixel_area.Width * 4;
6474 stat = brush_fill_pixels(graphics, (GpBrush*)brush, (DWORD*)pixel_data, &pixel_area, pixel_area.Width);
6477 GdipFree(text_mask);
6478 GdipFree(pixel_data);
6482 /* multiply the brush data by the mask */
6483 for (y=0; y<pixel_area.Height; y++)
6485 BYTE *text_val = text_mask + text_mask_stride * y;
6486 BYTE *pixel_val = pixel_data + pixel_data_stride * y + 3;
6487 for (x=0; x<pixel_area.Width; x++)
6489 *pixel_val = (*pixel_val) * (*text_val) / 64;
6495 GdipFree(text_mask);
6497 /* draw the result */
6498 stat = alpha_blend_pixels(graphics, min_x, min_y, pixel_data, pixel_area.Width,
6499 pixel_area.Height, pixel_data_stride);
6501 GdipFree(pixel_data);
6506 /*****************************************************************************
6507 * GdipDrawDriverString [GDIPLUS.@]
6509 GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
6510 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
6511 GDIPCONST PointF *positions, INT flags,
6512 GDIPCONST GpMatrix *matrix )
6514 GpStatus stat=NotImplemented;
6516 TRACE("(%p %s %p %p %p %d %p)\n", graphics, debugstr_wn(text, length), font, brush, positions, flags, matrix);
6518 if (!graphics || !text || !font || !brush || !positions)
6519 return InvalidParameter;
6522 length = strlenW(text);
6524 if (graphics->hdc &&
6525 ((flags & DriverStringOptionsRealizedAdvance) || length <= 1) &&
6526 brush->bt == BrushTypeSolidColor &&
6527 (((GpSolidFill*)brush)->color & 0xff000000) == 0xff000000)
6528 stat = GDI32_GdipDrawDriverString(graphics, text, length, font, brush,
6529 positions, flags, matrix);
6531 if (stat == NotImplemented)
6532 stat = SOFTWARE_GdipDrawDriverString(graphics, text, length, font, brush,
6533 positions, flags, matrix);
6538 GpStatus WINGDIPAPI GdipRecordMetafileStream(IStream *stream, HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
6539 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
6541 FIXME("(%p %p %d %p %d %p %p): stub\n", stream, hdc, type, frameRect, frameUnit, desc, metafile);
6542 return NotImplemented;
6545 /*****************************************************************************
6546 * GdipIsVisibleClipEmpty [GDIPLUS.@]
6548 GpStatus WINGDIPAPI GdipIsVisibleClipEmpty(GpGraphics *graphics, BOOL *res)
6553 TRACE("(%p, %p)\n", graphics, res);
6555 if((stat = GdipCreateRegion(&rgn)) != Ok)
6558 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
6561 stat = GdipIsEmptyRegion(rgn, graphics, res);
6564 GdipDeleteRegion(rgn);
6568 GpStatus WINGDIPAPI GdipResetPageTransform(GpGraphics *graphics)
6572 TRACE("(%p) stub\n", graphics);
6575 FIXME("not implemented\n");
6577 return NotImplemented;