blob: 8e203f35b7b1c9f14f6fa849094b010e04a6e709 [file] [log] [blame]
Evan Staded50be492007-06-11 11:54:03 -07001/*
2 * Copyright (C) 2007 Google (Evan Stade)
3 *
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.
8 *
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.
13 *
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
17 */
18
19#include <stdarg.h>
20#include <math.h>
Evan Stade44e98392007-08-15 16:22:09 -070021#include <limits.h>
Evan Staded50be492007-06-11 11:54:03 -070022
23#include "windef.h"
24#include "winbase.h"
25#include "winuser.h"
26#include "wingdi.h"
Evan Stadef7d27e02007-08-14 18:58:39 -070027#include "wine/unicode.h"
Evan Stade50799cf2007-07-30 19:10:03 -070028
29#define COBJMACROS
30#include "objbase.h"
31#include "ocidl.h"
32#include "olectl.h"
33#include "ole2.h"
34
Evan Stade3ea77f52007-08-07 18:42:00 -070035#include "winreg.h"
36#include "shlwapi.h"
37
Evan Staded50be492007-06-11 11:54:03 -070038#include "gdiplus.h"
39#include "gdiplus_private.h"
40#include "wine/debug.h"
Andrew Eikum632aef32009-07-05 17:04:20 -050041#include "wine/list.h"
Evan Staded50be492007-06-11 11:54:03 -070042
Evan Stade5128e5d2007-07-07 13:20:41 -070043WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
44
45/* looks-right constants */
Evan Stade5128e5d2007-07-07 13:20:41 -070046#define ANCHOR_WIDTH (2.0)
Evan Stade69a807c2007-07-06 16:13:49 -070047#define MAX_ITERS (50)
Evan Stade5c8b83c2007-06-19 19:31:28 -070048
Evan Stade72ab72c502007-06-18 16:55:51 -070049/* Converts angle (in degrees) to x/y coordinates */
50static void deg2xy(REAL angle, REAL x_0, REAL y_0, REAL *x, REAL *y)
51{
52 REAL radAngle, hypotenuse;
53
54 radAngle = deg2rad(angle);
55 hypotenuse = 50.0; /* arbitrary */
56
57 *x = x_0 + cos(radAngle) * hypotenuse;
58 *y = y_0 + sin(radAngle) * hypotenuse;
59}
60
Evan Stade85b5df42007-07-19 18:22:51 -070061/* Converts from gdiplus path point type to gdi path point type. */
62static BYTE convert_path_point_type(BYTE type)
63{
64 BYTE ret;
65
66 switch(type & PathPointTypePathTypeMask){
67 case PathPointTypeBezier:
68 ret = PT_BEZIERTO;
69 break;
70 case PathPointTypeLine:
71 ret = PT_LINETO;
72 break;
73 case PathPointTypeStart:
74 ret = PT_MOVETO;
75 break;
76 default:
77 ERR("Bad point type\n");
78 return 0;
79 }
80
81 if(type & PathPointTypeCloseSubpath)
82 ret |= PT_CLOSEFIGURE;
83
84 return ret;
85}
86
Vincent Povirk85a57102010-08-08 15:24:45 -050087static REAL graphics_res(GpGraphics *graphics)
88{
89 if (graphics->image) return graphics->image->xres;
90 else return (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
91}
92
Evan Stade4c424b32007-07-24 17:18:54 -070093static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
94{
95 HPEN gdipen;
96 REAL width;
Vincent Povirkc3ca6be2010-08-08 15:34:23 -050097 INT save_state, i, numdashes;
Evan Stadeb7053b72007-07-24 17:18:58 -070098 GpPointF pt[2];
Evan Stade1f61f482007-07-27 16:07:39 -070099 DWORD dash_array[MAX_DASHLEN];
Evan Stade4c424b32007-07-24 17:18:54 -0700100
Vincent Povirkc3ca6be2010-08-08 15:34:23 -0500101 if (!graphics->hdc)
102 {
103 FIXME("graphics object has no HDC\n");
104 }
105
106 save_state = SaveDC(graphics->hdc);
107
Evan Stade4c424b32007-07-24 17:18:54 -0700108 EndPath(graphics->hdc);
109
Evan Stadeafa4d322007-08-13 18:34:31 -0700110 if(pen->unit == UnitPixel){
111 width = pen->width;
112 }
113 else{
114 /* Get an estimate for the amount the pen width is affected by the world
115 * transform. (This is similar to what some of the wine drivers do.) */
116 pt[0].X = 0.0;
117 pt[0].Y = 0.0;
118 pt[1].X = 1.0;
119 pt[1].Y = 1.0;
120 GdipTransformMatrixPoints(graphics->worldtrans, pt, 2);
121 width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
122 (pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
Evan Stadeb7053b72007-07-24 17:18:58 -0700123
Vincent Povirk85a57102010-08-08 15:24:45 -0500124 width *= pen->width * convert_unit(graphics_res(graphics),
Evan Stadeafa4d322007-08-13 18:34:31 -0700125 pen->unit == UnitWorld ? graphics->unit : pen->unit);
126 }
Evan Stade4c424b32007-07-24 17:18:54 -0700127
Evan Stade1f61f482007-07-27 16:07:39 -0700128 if(pen->dash == DashStyleCustom){
129 numdashes = min(pen->numdashes, MAX_DASHLEN);
130
131 TRACE("dashes are: ");
132 for(i = 0; i < numdashes; i++){
133 dash_array[i] = roundr(width * pen->dashes[i]);
134 TRACE("%d, ", dash_array[i]);
135 }
136 TRACE("\n and the pen style is %x\n", pen->style);
137
138 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb,
139 numdashes, dash_array);
140 }
141 else
142 gdipen = ExtCreatePen(pen->style, roundr(width), &pen->brush->lb, 0, NULL);
143
Evan Stade4c424b32007-07-24 17:18:54 -0700144 SelectObject(graphics->hdc, gdipen);
145
146 return save_state;
147}
148
149static void restore_dc(GpGraphics *graphics, INT state)
150{
151 DeleteObject(SelectObject(graphics->hdc, GetStockObject(NULL_PEN)));
152 RestoreDC(graphics->hdc, state);
153}
154
Evan Staded01c6972007-07-23 20:24:53 -0700155/* This helper applies all the changes that the points listed in ptf need in
156 * order to be drawn on the device context. In the end, this should include at
157 * least:
158 * -scaling by page unit
159 * -applying world transformation
160 * -converting from float to int
161 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
162 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
163 * gdi to draw, and these functions would irreparably mess with line widths.
164 */
165static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
Evan Stadec3e8af42007-07-24 17:18:50 -0700166 GpPointF *ptf, INT count)
Evan Staded01c6972007-07-23 20:24:53 -0700167{
168 REAL unitscale;
Evan Stadec3e8af42007-07-24 17:18:50 -0700169 GpMatrix *matrix;
Evan Staded01c6972007-07-23 20:24:53 -0700170 int i;
171
Vincent Povirk85a57102010-08-08 15:24:45 -0500172 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
Evan Staded01c6972007-07-23 20:24:53 -0700173
Evan Stade81621392007-07-24 17:18:39 -0700174 /* apply page scale */
175 if(graphics->unit != UnitDisplay)
176 unitscale *= graphics->scale;
177
Evan Stadec3e8af42007-07-24 17:18:50 -0700178 GdipCloneMatrix(graphics->worldtrans, &matrix);
179 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
180 GdipTransformMatrixPoints(matrix, ptf, count);
Evan Stadef52adfd2007-07-25 19:15:20 -0700181 GdipDeleteMatrix(matrix);
Evan Stadec3e8af42007-07-24 17:18:50 -0700182
Evan Staded01c6972007-07-23 20:24:53 -0700183 for(i = 0; i < count; i++){
Evan Stadec3e8af42007-07-24 17:18:50 -0700184 pti[i].x = roundr(ptf[i].X);
185 pti[i].y = roundr(ptf[i].Y);
Evan Staded01c6972007-07-23 20:24:53 -0700186 }
187}
188
Vincent Povirk9c380b12010-04-15 14:11:07 -0500189/* Draw non-premultiplied ARGB data to the given graphics object */
190static GpStatus alpha_blend_pixels(GpGraphics *graphics, INT dst_x, INT dst_y,
191 const BYTE *src, INT src_width, INT src_height, INT src_stride)
192{
193 if (graphics->image && graphics->image->type == ImageTypeBitmap)
194 {
195 GpBitmap *dst_bitmap = (GpBitmap*)graphics->image;
196 INT x, y;
197
198 for (x=0; x<src_width; x++)
199 {
200 for (y=0; y<src_height; y++)
201 {
202 ARGB dst_color, src_color;
203 GdipBitmapGetPixel(dst_bitmap, x+dst_x, y+dst_y, &dst_color);
204 src_color = ((ARGB*)(src + src_stride * y))[x];
205 GdipBitmapSetPixel(dst_bitmap, x+dst_x, y+dst_y, color_over(dst_color, src_color));
206 }
207 }
208
209 return Ok;
210 }
211 else
212 {
Vincent Povirk7791f022010-04-15 14:48:47 -0500213 HDC hdc;
214 HBITMAP hbitmap, old_hbm=NULL;
215 BITMAPINFOHEADER bih;
216 BYTE *temp_bits;
217 BLENDFUNCTION bf;
218
219 hdc = CreateCompatibleDC(0);
220
221 bih.biSize = sizeof(BITMAPINFOHEADER);
222 bih.biWidth = src_width;
223 bih.biHeight = -src_height;
224 bih.biPlanes = 1;
225 bih.biBitCount = 32;
226 bih.biCompression = BI_RGB;
227 bih.biSizeImage = 0;
228 bih.biXPelsPerMeter = 0;
229 bih.biYPelsPerMeter = 0;
230 bih.biClrUsed = 0;
231 bih.biClrImportant = 0;
232
233 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
234 (void**)&temp_bits, NULL, 0);
235
236 convert_32bppARGB_to_32bppPARGB(src_width, src_height, temp_bits,
237 4 * src_width, src, src_stride);
238
239 old_hbm = SelectObject(hdc, hbitmap);
240
241 bf.BlendOp = AC_SRC_OVER;
242 bf.BlendFlags = 0;
243 bf.SourceConstantAlpha = 255;
244 bf.AlphaFormat = AC_SRC_ALPHA;
245
246 GdiAlphaBlend(graphics->hdc, dst_x, dst_y, src_width, src_height,
247 hdc, 0, 0, src_width, src_height, bf);
248
249 SelectObject(hdc, old_hbm);
250 DeleteDC(hdc);
251 DeleteObject(hbitmap);
252
253 return Ok;
Vincent Povirk9c380b12010-04-15 14:11:07 -0500254 }
255}
256
Vincent Povirka6161302009-05-01 14:26:50 -0500257static ARGB blend_colors(ARGB start, ARGB end, REAL position)
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500258{
259 ARGB result=0;
260 ARGB i;
261 for (i=0xff; i<=0xff0000; i = i << 8)
Vincent Povirka6161302009-05-01 14:26:50 -0500262 result |= (int)((start&i)*(1.0f - position)+(end&i)*(position))&i;
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500263 return result;
264}
265
Vincent Povirka6161302009-05-01 14:26:50 -0500266static ARGB blend_line_gradient(GpLineGradient* brush, REAL position)
267{
268 REAL blendfac;
269
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500270 /* clamp to between 0.0 and 1.0, using the wrap mode */
271 if (brush->wrap == WrapModeTile)
272 {
273 position = fmodf(position, 1.0f);
274 if (position < 0.0f) position += 1.0f;
275 }
276 else /* WrapModeFlip* */
277 {
278 position = fmodf(position, 2.0f);
279 if (position < 0.0f) position += 2.0f;
280 if (position > 1.0f) position = 2.0f - position;
281 }
282
Vincent Povirka6161302009-05-01 14:26:50 -0500283 if (brush->blendcount == 1)
284 blendfac = position;
285 else
286 {
287 int i=1;
288 REAL left_blendpos, left_blendfac, right_blendpos, right_blendfac;
289 REAL range;
290
291 /* locate the blend positions surrounding this position */
292 while (position > brush->blendpos[i])
293 i++;
294
295 /* interpolate between the blend positions */
296 left_blendpos = brush->blendpos[i-1];
297 left_blendfac = brush->blendfac[i-1];
298 right_blendpos = brush->blendpos[i];
299 right_blendfac = brush->blendfac[i];
300 range = right_blendpos - left_blendpos;
301 blendfac = (left_blendfac * (right_blendpos - position) +
302 right_blendfac * (position - left_blendpos)) / range;
303 }
Vincent Povirkd2e999d2009-09-14 16:48:03 -0500304
305 if (brush->pblendcount == 0)
306 return blend_colors(brush->startcolor, brush->endcolor, blendfac);
307 else
308 {
309 int i=1;
310 ARGB left_blendcolor, right_blendcolor;
311 REAL left_blendpos, right_blendpos;
312
313 /* locate the blend colors surrounding this position */
314 while (blendfac > brush->pblendpos[i])
315 i++;
316
317 /* interpolate between the blend colors */
318 left_blendpos = brush->pblendpos[i-1];
319 left_blendcolor = brush->pblendcolor[i-1];
320 right_blendpos = brush->pblendpos[i];
321 right_blendcolor = brush->pblendcolor[i];
322 blendfac = (blendfac - left_blendpos) / (right_blendpos - left_blendpos);
323 return blend_colors(left_blendcolor, right_blendcolor, blendfac);
324 }
Vincent Povirka6161302009-05-01 14:26:50 -0500325}
326
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500327static void brush_fill_path(GpGraphics *graphics, GpBrush* brush)
328{
329 switch (brush->bt)
330 {
331 case BrushTypeLinearGradient:
332 {
333 GpLineGradient *line = (GpLineGradient*)brush;
334 RECT rc;
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500335
336 SelectClipPath(graphics->hdc, RGN_AND);
337 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
338 {
339 GpPointF endpointsf[2];
340 POINT endpointsi[2];
341 POINT poly[4];
342
343 SelectObject(graphics->hdc, GetStockObject(NULL_PEN));
344
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500345 endpointsf[0] = line->startpoint;
346 endpointsf[1] = line->endpoint;
347 transform_and_round_points(graphics, endpointsi, endpointsf, 2);
348
349 if (abs(endpointsi[0].x-endpointsi[1].x) > abs(endpointsi[0].y-endpointsi[1].y))
350 {
351 /* vertical-ish gradient */
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500352 int startx, endx; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500353 int startbottomx; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500354 int width;
355 COLORREF col;
356 HBRUSH hbrush, hprevbrush;
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500357 int leftx, rightx; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
358 int x;
359 int tilt; /* horizontal distance covered by a gradient line */
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500360
361 startx = roundr((rc.top - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X);
362 endx = roundr((rc.top - endpointsf[1].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[1].X);
363 width = endx - startx;
364 startbottomx = roundr((rc.bottom - endpointsf[0].Y) * (endpointsf[1].Y - endpointsf[0].Y) / (endpointsf[0].X - endpointsf[1].X) + endpointsf[0].X);
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500365 tilt = startx - startbottomx;
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500366
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500367 if (startx >= startbottomx)
368 {
369 leftx = rc.left;
370 rightx = rc.right + tilt;
371 }
372 else
373 {
374 leftx = rc.left + tilt;
375 rightx = rc.right;
376 }
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500377
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500378 poly[0].y = rc.bottom;
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500379 poly[1].y = rc.top;
380 poly[2].y = rc.top;
381 poly[3].y = rc.bottom;
382
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500383 for (x=leftx; x<=rightx; x++)
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500384 {
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500385 ARGB argb = blend_line_gradient(line, (x-startx)/(REAL)width);
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500386 col = ARGB2COLORREF(argb);
387 hbrush = CreateSolidBrush(col);
388 hprevbrush = SelectObject(graphics->hdc, hbrush);
Vincent Povirkcb478a32009-05-01 15:37:35 -0500389 poly[0].x = x - tilt - 1;
390 poly[1].x = x - 1;
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500391 poly[2].x = x;
392 poly[3].x = x - tilt;
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500393 Polygon(graphics->hdc, poly, 4);
394 SelectObject(graphics->hdc, hprevbrush);
395 DeleteObject(hbrush);
396 }
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500397 }
398 else if (endpointsi[0].y != endpointsi[1].y)
399 {
400 /* horizontal-ish gradient */
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500401 int starty, endy; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500402 int startrighty; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500403 int height;
404 COLORREF col;
405 HBRUSH hbrush, hprevbrush;
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500406 int topy, bottomy; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
407 int y;
408 int tilt; /* vertical distance covered by a gradient line */
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500409
410 starty = roundr((rc.left - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y);
411 endy = roundr((rc.left - endpointsf[1].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[1].Y);
412 height = endy - starty;
413 startrighty = roundr((rc.right - endpointsf[0].X) * (endpointsf[0].X - endpointsf[1].X) / (endpointsf[1].Y - endpointsf[0].Y) + endpointsf[0].Y);
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500414 tilt = starty - startrighty;
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500415
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500416 if (starty >= startrighty)
417 {
418 topy = rc.top;
419 bottomy = rc.bottom + tilt;
420 }
421 else
422 {
423 topy = rc.top + tilt;
424 bottomy = rc.bottom;
425 }
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500426
427 poly[0].x = rc.right;
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500428 poly[1].x = rc.left;
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500429 poly[2].x = rc.left;
430 poly[3].x = rc.right;
431
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500432 for (y=topy; y<=bottomy; y++)
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500433 {
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500434 ARGB argb = blend_line_gradient(line, (y-starty)/(REAL)height);
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500435 col = ARGB2COLORREF(argb);
436 hbrush = CreateSolidBrush(col);
437 hprevbrush = SelectObject(graphics->hdc, hbrush);
Vincent Povirkcb478a32009-05-01 15:37:35 -0500438 poly[0].y = y - tilt - 1;
439 poly[1].y = y - 1;
Vincent Povirk966fd5e2009-05-01 15:23:02 -0500440 poly[2].y = y;
441 poly[3].y = y - tilt;
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500442 Polygon(graphics->hdc, poly, 4);
443 SelectObject(graphics->hdc, hprevbrush);
444 DeleteObject(hbrush);
445 }
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500446 }
447 /* else startpoint == endpoint */
448 }
449 break;
450 }
Vincent Povirk60167df2009-05-20 11:24:18 -0500451 case BrushTypeSolidColor:
452 {
453 GpSolidFill *fill = (GpSolidFill*)brush;
454 if (fill->bmp)
455 {
456 RECT rc;
457 /* partially transparent fill */
458
459 SelectClipPath(graphics->hdc, RGN_AND);
460 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
461 {
462 HDC hdc = CreateCompatibleDC(NULL);
463 HBITMAP oldbmp;
464 BLENDFUNCTION bf;
465
466 if (!hdc) break;
467
468 oldbmp = SelectObject(hdc, fill->bmp);
469
470 bf.BlendOp = AC_SRC_OVER;
471 bf.BlendFlags = 0;
472 bf.SourceConstantAlpha = 255;
473 bf.AlphaFormat = AC_SRC_ALPHA;
474
475 GdiAlphaBlend(graphics->hdc, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, hdc, 0, 0, 1, 1, bf);
476
477 SelectObject(hdc, oldbmp);
478 DeleteDC(hdc);
479 }
480
481 break;
482 }
483 /* else fall through */
484 }
Vincent Povirk68dba4e2009-03-16 12:51:04 -0500485 default:
486 SelectObject(graphics->hdc, brush->gdibrush);
487 FillPath(graphics->hdc);
488 break;
489 }
490}
491
Evan Stade72ab72c502007-06-18 16:55:51 -0700492/* GdipDrawPie/GdipFillPie helper function */
Evan Stade4c424b32007-07-24 17:18:54 -0700493static void draw_pie(GpGraphics *graphics, REAL x, REAL y, REAL width,
494 REAL height, REAL startAngle, REAL sweepAngle)
Evan Stade72ab72c502007-06-18 16:55:51 -0700495{
Evan Staded01c6972007-07-23 20:24:53 -0700496 GpPointF ptf[4];
497 POINT pti[4];
Evan Stade72ab72c502007-06-18 16:55:51 -0700498
Evan Staded01c6972007-07-23 20:24:53 -0700499 ptf[0].X = x;
500 ptf[0].Y = y;
501 ptf[1].X = x + width;
502 ptf[1].Y = y + height;
Evan Stade72ab72c502007-06-18 16:55:51 -0700503
Evan Staded01c6972007-07-23 20:24:53 -0700504 deg2xy(startAngle+sweepAngle, x + width / 2.0, y + width / 2.0, &ptf[2].X, &ptf[2].Y);
505 deg2xy(startAngle, x + width / 2.0, y + width / 2.0, &ptf[3].X, &ptf[3].Y);
Evan Stade72ab72c502007-06-18 16:55:51 -0700506
Evan Staded01c6972007-07-23 20:24:53 -0700507 transform_and_round_points(graphics, pti, ptf, 4);
508
509 Pie(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y, pti[2].x,
510 pti[2].y, pti[3].x, pti[3].y);
Evan Stade72ab72c502007-06-18 16:55:51 -0700511}
512
Evan Stade5128e5d2007-07-07 13:20:41 -0700513/* Draws the linecap the specified color and size on the hdc. The linecap is in
Evan Stade8c5bcef2007-07-20 17:50:02 -0700514 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
515 * should not be called on an hdc that has a path you care about. */
Evan Staded01c6972007-07-23 20:24:53 -0700516static void draw_cap(GpGraphics *graphics, COLORREF color, GpLineCap cap, REAL size,
Evan Stade85b5df42007-07-19 18:22:51 -0700517 const GpCustomLineCap *custom, REAL x1, REAL y1, REAL x2, REAL y2)
Evan Stade5128e5d2007-07-07 13:20:41 -0700518{
Evan Stadeb7053b72007-07-24 17:18:58 -0700519 HGDIOBJ oldbrush = NULL, oldpen = NULL;
Evan Stade85b5df42007-07-19 18:22:51 -0700520 GpMatrix *matrix = NULL;
Evan Stadeb7053b72007-07-24 17:18:58 -0700521 HBRUSH brush = NULL;
522 HPEN pen = NULL;
Evan Staded01c6972007-07-23 20:24:53 -0700523 PointF ptf[4], *custptf = NULL;
Evan Stade85b5df42007-07-19 18:22:51 -0700524 POINT pt[4], *custpt = NULL;
525 BYTE *tp = NULL;
Evan Staded01c6972007-07-23 20:24:53 -0700526 REAL theta, dsmall, dbig, dx, dy = 0.0;
Evan Stade85b5df42007-07-19 18:22:51 -0700527 INT i, count;
528 LOGBRUSH lb;
Evan Stadeb7053b72007-07-24 17:18:58 -0700529 BOOL customstroke;
Evan Stade5128e5d2007-07-07 13:20:41 -0700530
Evan Stade818051d2007-07-20 17:50:14 -0700531 if((x1 == x2) && (y1 == y2))
Evan Stade5128e5d2007-07-07 13:20:41 -0700532 return;
533
Evan Stade818051d2007-07-20 17:50:14 -0700534 theta = gdiplus_atan2(y2 - y1, x2 - x1);
535
Evan Stadeb7053b72007-07-24 17:18:58 -0700536 customstroke = (cap == LineCapCustom) && custom && (!custom->fill);
537 if(!customstroke){
538 brush = CreateSolidBrush(color);
539 lb.lbStyle = BS_SOLID;
540 lb.lbColor = color;
541 lb.lbHatch = 0;
542 pen = ExtCreatePen(PS_GEOMETRIC | PS_SOLID | PS_ENDCAP_FLAT |
543 PS_JOIN_MITER, 1, &lb, 0,
544 NULL);
545 oldbrush = SelectObject(graphics->hdc, brush);
546 oldpen = SelectObject(graphics->hdc, pen);
547 }
Evan Stade5128e5d2007-07-07 13:20:41 -0700548
549 switch(cap){
550 case LineCapFlat:
551 break;
552 case LineCapSquare:
553 case LineCapSquareAnchor:
554 case LineCapDiamondAnchor:
555 size = size * (cap & LineCapNoAnchor ? ANCHOR_WIDTH : 1.0) / 2.0;
556 if(cap == LineCapDiamondAnchor){
557 dsmall = cos(theta + M_PI_2) * size;
558 dbig = sin(theta + M_PI_2) * size;
559 }
560 else{
561 dsmall = cos(theta + M_PI_4) * size;
562 dbig = sin(theta + M_PI_4) * size;
563 }
564
Evan Staded01c6972007-07-23 20:24:53 -0700565 ptf[0].X = x2 - dsmall;
566 ptf[1].X = x2 + dbig;
Evan Stade5128e5d2007-07-07 13:20:41 -0700567
Evan Staded01c6972007-07-23 20:24:53 -0700568 ptf[0].Y = y2 - dbig;
569 ptf[3].Y = y2 + dsmall;
Evan Stade5128e5d2007-07-07 13:20:41 -0700570
Evan Staded01c6972007-07-23 20:24:53 -0700571 ptf[1].Y = y2 - dsmall;
572 ptf[2].Y = y2 + dbig;
Evan Stade5128e5d2007-07-07 13:20:41 -0700573
Evan Staded01c6972007-07-23 20:24:53 -0700574 ptf[3].X = x2 - dbig;
575 ptf[2].X = x2 + dsmall;
Evan Stade5128e5d2007-07-07 13:20:41 -0700576
Evan Staded01c6972007-07-23 20:24:53 -0700577 transform_and_round_points(graphics, pt, ptf, 4);
578 Polygon(graphics->hdc, pt, 4);
Evan Stade5128e5d2007-07-07 13:20:41 -0700579
580 break;
581 case LineCapArrowAnchor:
582 size = size * 4.0 / sqrt(3.0);
583
Evan Stadeea5898c2007-07-19 18:22:47 -0700584 dx = cos(M_PI / 6.0 + theta) * size;
585 dy = sin(M_PI / 6.0 + theta) * size;
Evan Stade5128e5d2007-07-07 13:20:41 -0700586
Evan Staded01c6972007-07-23 20:24:53 -0700587 ptf[0].X = x2 - dx;
588 ptf[0].Y = y2 - dy;
Evan Stade5128e5d2007-07-07 13:20:41 -0700589
Evan Stadeea5898c2007-07-19 18:22:47 -0700590 dx = cos(- M_PI / 6.0 + theta) * size;
591 dy = sin(- M_PI / 6.0 + theta) * size;
Evan Stade5128e5d2007-07-07 13:20:41 -0700592
Evan Staded01c6972007-07-23 20:24:53 -0700593 ptf[1].X = x2 - dx;
594 ptf[1].Y = y2 - dy;
Evan Stade5128e5d2007-07-07 13:20:41 -0700595
Evan Staded01c6972007-07-23 20:24:53 -0700596 ptf[2].X = x2;
597 ptf[2].Y = y2;
Evan Stade5128e5d2007-07-07 13:20:41 -0700598
Evan Staded01c6972007-07-23 20:24:53 -0700599 transform_and_round_points(graphics, pt, ptf, 3);
600 Polygon(graphics->hdc, pt, 3);
Evan Stade5128e5d2007-07-07 13:20:41 -0700601
602 break;
603 case LineCapRoundAnchor:
604 dx = dy = ANCHOR_WIDTH * size / 2.0;
605
Evan Staded01c6972007-07-23 20:24:53 -0700606 ptf[0].X = x2 - dx;
607 ptf[0].Y = y2 - dy;
608 ptf[1].X = x2 + dx;
609 ptf[1].Y = y2 + dy;
Evan Stade5128e5d2007-07-07 13:20:41 -0700610
Evan Staded01c6972007-07-23 20:24:53 -0700611 transform_and_round_points(graphics, pt, ptf, 2);
612 Ellipse(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y);
613
Evan Stade5128e5d2007-07-07 13:20:41 -0700614 break;
615 case LineCapTriangle:
616 size = size / 2.0;
617 dx = cos(M_PI_2 + theta) * size;
618 dy = sin(M_PI_2 + theta) * size;
619
Evan Staded01c6972007-07-23 20:24:53 -0700620 ptf[0].X = x2 - dx;
621 ptf[0].Y = y2 - dy;
622 ptf[1].X = x2 + dx;
623 ptf[1].Y = y2 + dy;
Evan Stade5128e5d2007-07-07 13:20:41 -0700624
Evan Stadeea5898c2007-07-19 18:22:47 -0700625 dx = cos(theta) * size;
626 dy = sin(theta) * size;
Evan Stade5128e5d2007-07-07 13:20:41 -0700627
Evan Staded01c6972007-07-23 20:24:53 -0700628 ptf[2].X = x2 + dx;
629 ptf[2].Y = y2 + dy;
Evan Stade5128e5d2007-07-07 13:20:41 -0700630
Evan Staded01c6972007-07-23 20:24:53 -0700631 transform_and_round_points(graphics, pt, ptf, 3);
632 Polygon(graphics->hdc, pt, 3);
Evan Stade5128e5d2007-07-07 13:20:41 -0700633
634 break;
635 case LineCapRound:
Evan Staded01c6972007-07-23 20:24:53 -0700636 dx = dy = size / 2.0;
637
638 ptf[0].X = x2 - dx;
639 ptf[0].Y = y2 - dy;
640 ptf[1].X = x2 + dx;
641 ptf[1].Y = y2 + dy;
642
Evan Stadeea5898c2007-07-19 18:22:47 -0700643 dx = -cos(M_PI_2 + theta) * size;
644 dy = -sin(M_PI_2 + theta) * size;
Evan Stade5128e5d2007-07-07 13:20:41 -0700645
Evan Staded01c6972007-07-23 20:24:53 -0700646 ptf[2].X = x2 - dx;
647 ptf[2].Y = y2 - dy;
648 ptf[3].X = x2 + dx;
649 ptf[3].Y = y2 + dy;
Evan Stade5128e5d2007-07-07 13:20:41 -0700650
Evan Staded01c6972007-07-23 20:24:53 -0700651 transform_and_round_points(graphics, pt, ptf, 4);
652 Pie(graphics->hdc, pt[0].x, pt[0].y, pt[1].x, pt[1].y, pt[2].x,
653 pt[2].y, pt[3].x, pt[3].y);
Evan Stade5128e5d2007-07-07 13:20:41 -0700654
Evan Stade5128e5d2007-07-07 13:20:41 -0700655 break;
656 case LineCapCustom:
Evan Stade85b5df42007-07-19 18:22:51 -0700657 if(!custom)
658 break;
659
Evan Stade85b5df42007-07-19 18:22:51 -0700660 count = custom->pathdata.Count;
661 custptf = GdipAlloc(count * sizeof(PointF));
662 custpt = GdipAlloc(count * sizeof(POINT));
663 tp = GdipAlloc(count);
664
665 if(!custptf || !custpt || !tp || (GdipCreateMatrix(&matrix) != Ok))
666 goto custend;
667
668 memcpy(custptf, custom->pathdata.Points, count * sizeof(PointF));
669
670 GdipScaleMatrix(matrix, size, size, MatrixOrderAppend);
671 GdipRotateMatrix(matrix, (180.0 / M_PI) * (theta - M_PI_2),
672 MatrixOrderAppend);
673 GdipTranslateMatrix(matrix, x2, y2, MatrixOrderAppend);
674 GdipTransformMatrixPoints(matrix, custptf, count);
675
Evan Staded01c6972007-07-23 20:24:53 -0700676 transform_and_round_points(graphics, custpt, custptf, count);
677
678 for(i = 0; i < count; i++)
Evan Stade85b5df42007-07-19 18:22:51 -0700679 tp[i] = convert_path_point_type(custom->pathdata.Types[i]);
Evan Stade85b5df42007-07-19 18:22:51 -0700680
Evan Stade8c5bcef2007-07-20 17:50:02 -0700681 if(custom->fill){
Evan Staded01c6972007-07-23 20:24:53 -0700682 BeginPath(graphics->hdc);
683 PolyDraw(graphics->hdc, custpt, tp, count);
684 EndPath(graphics->hdc);
685 StrokeAndFillPath(graphics->hdc);
Evan Stade8c5bcef2007-07-20 17:50:02 -0700686 }
687 else
Evan Staded01c6972007-07-23 20:24:53 -0700688 PolyDraw(graphics->hdc, custpt, tp, count);
Evan Stade85b5df42007-07-19 18:22:51 -0700689
690custend:
691 GdipFree(custptf);
692 GdipFree(custpt);
693 GdipFree(tp);
694 GdipDeleteMatrix(matrix);
695 break;
Evan Stade5128e5d2007-07-07 13:20:41 -0700696 default:
697 break;
698 }
699
Evan Stadeb7053b72007-07-24 17:18:58 -0700700 if(!customstroke){
701 SelectObject(graphics->hdc, oldbrush);
702 SelectObject(graphics->hdc, oldpen);
703 DeleteObject(brush);
704 DeleteObject(pen);
705 }
Evan Stade5128e5d2007-07-07 13:20:41 -0700706}
707
708/* Shortens the line by the given percent by changing x2, y2.
Evan Stadef56fa322007-07-20 17:50:07 -0700709 * If percent is > 1.0 then the line will change direction.
710 * If percent is negative it can lengthen the line. */
Evan Stade5128e5d2007-07-07 13:20:41 -0700711static void shorten_line_percent(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL percent)
712{
713 REAL dist, theta, dx, dy;
714
715 if((y1 == *y2) && (x1 == *x2))
716 return;
717
Evan Stadef56fa322007-07-20 17:50:07 -0700718 dist = sqrt((*x2 - x1) * (*x2 - x1) + (*y2 - y1) * (*y2 - y1)) * -percent;
Evan Stade818051d2007-07-20 17:50:14 -0700719 theta = gdiplus_atan2((*y2 - y1), (*x2 - x1));
Evan Stade5128e5d2007-07-07 13:20:41 -0700720 dx = cos(theta) * dist;
721 dy = sin(theta) * dist;
722
Evan Stadef56fa322007-07-20 17:50:07 -0700723 *x2 = *x2 + dx;
724 *y2 = *y2 + dy;
Evan Stade5128e5d2007-07-07 13:20:41 -0700725}
726
727/* Shortens the line by the given amount by changing x2, y2.
Evan Stadef56fa322007-07-20 17:50:07 -0700728 * If the amount is greater than the distance, the line will become length 0.
729 * If the amount is negative, it can lengthen the line. */
Evan Stade5128e5d2007-07-07 13:20:41 -0700730static void shorten_line_amt(REAL x1, REAL y1, REAL *x2, REAL *y2, REAL amt)
731{
732 REAL dx, dy, percent;
733
734 dx = *x2 - x1;
735 dy = *y2 - y1;
736 if(dx == 0 && dy == 0)
737 return;
738
739 percent = amt / sqrt(dx * dx + dy * dy);
740 if(percent >= 1.0){
741 *x2 = x1;
742 *y2 = y1;
743 return;
744 }
745
746 shorten_line_percent(x1, y1, x2, y2, percent);
747}
748
749/* Draws lines between the given points, and if caps is true then draws an endcap
Evan Stade88ab6d32007-08-02 17:53:13 -0700750 * at the end of the last line. */
Evan Staded01c6972007-07-23 20:24:53 -0700751static GpStatus draw_polyline(GpGraphics *graphics, GpPen *pen,
752 GDIPCONST GpPointF * pt, INT count, BOOL caps)
Evan Stade5128e5d2007-07-07 13:20:41 -0700753{
Evan Stadea84b5672007-07-20 17:50:11 -0700754 POINT *pti = NULL;
755 GpPointF *ptcopy = NULL;
Evan Stade6f4ab522007-07-11 18:07:44 -0700756 GpStatus status = GenericError;
757
758 if(!count)
759 return Ok;
760
761 pti = GdipAlloc(count * sizeof(POINT));
Evan Stadea84b5672007-07-20 17:50:11 -0700762 ptcopy = GdipAlloc(count * sizeof(GpPointF));
Evan Stade6f4ab522007-07-11 18:07:44 -0700763
Evan Stadea84b5672007-07-20 17:50:11 -0700764 if(!pti || !ptcopy){
Evan Stade6f4ab522007-07-11 18:07:44 -0700765 status = OutOfMemory;
766 goto end;
767 }
Evan Stade5128e5d2007-07-07 13:20:41 -0700768
Evan Stadec3e8af42007-07-24 17:18:50 -0700769 memcpy(ptcopy, pt, count * sizeof(GpPointF));
Evan Staded01c6972007-07-23 20:24:53 -0700770
Evan Stadec3e8af42007-07-24 17:18:50 -0700771 if(caps){
Evan Stade5128e5d2007-07-07 13:20:41 -0700772 if(pen->endcap == LineCapArrowAnchor)
Evan Stadea84b5672007-07-20 17:50:11 -0700773 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
774 &ptcopy[count-1].X, &ptcopy[count-1].Y, pen->width);
Evan Stadef56fa322007-07-20 17:50:07 -0700775 else if((pen->endcap == LineCapCustom) && pen->customend)
Evan Stadea84b5672007-07-20 17:50:11 -0700776 shorten_line_amt(ptcopy[count-2].X, ptcopy[count-2].Y,
777 &ptcopy[count-1].X, &ptcopy[count-1].Y,
778 pen->customend->inset * pen->width);
779
780 if(pen->startcap == LineCapArrowAnchor)
781 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
782 &ptcopy[0].X, &ptcopy[0].Y, pen->width);
783 else if((pen->startcap == LineCapCustom) && pen->customstart)
784 shorten_line_amt(ptcopy[1].X, ptcopy[1].Y,
785 &ptcopy[0].X, &ptcopy[0].Y,
Evan Stade02887b62007-08-07 18:42:44 -0700786 pen->customstart->inset * pen->width);
Evan Stade5128e5d2007-07-07 13:20:41 -0700787
Evan Staded01c6972007-07-23 20:24:53 -0700788 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
Evan Stadea84b5672007-07-20 17:50:11 -0700789 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X, pt[count - 1].Y);
Evan Staded01c6972007-07-23 20:24:53 -0700790 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
Michael Stefaniuc1f26b142007-12-31 17:29:57 +0100791 pt[1].X, pt[1].Y, pt[0].X, pt[0].Y);
Evan Stade5128e5d2007-07-07 13:20:41 -0700792 }
Evan Stadec3e8af42007-07-24 17:18:50 -0700793
794 transform_and_round_points(graphics, pti, ptcopy, count);
Evan Stade5128e5d2007-07-07 13:20:41 -0700795
Royal Chanc86f2c22008-02-10 12:40:52 -0800796 if(Polyline(graphics->hdc, pti, count))
797 status = Ok;
Evan Stade6f4ab522007-07-11 18:07:44 -0700798
799end:
Evan Stade5128e5d2007-07-07 13:20:41 -0700800 GdipFree(pti);
Evan Stadea84b5672007-07-20 17:50:11 -0700801 GdipFree(ptcopy);
Evan Stade6f4ab522007-07-11 18:07:44 -0700802
803 return status;
Evan Stade5128e5d2007-07-07 13:20:41 -0700804}
805
Evan Stade69a807c2007-07-06 16:13:49 -0700806/* Conducts a linear search to find the bezier points that will back off
807 * the endpoint of the curve by a distance of amt. Linear search works
808 * better than binary in this case because there are multiple solutions,
809 * and binary searches often find a bad one. I don't think this is what
810 * Windows does but short of rendering the bezier without GDI's help it's
Evan Stadea84b5672007-07-20 17:50:11 -0700811 * the best we can do. If rev then work from the start of the passed points
812 * instead of the end. */
813static void shorten_bezier_amt(GpPointF * pt, REAL amt, BOOL rev)
Evan Stade69a807c2007-07-06 16:13:49 -0700814{
815 GpPointF origpt[4];
Evan Stadea84b5672007-07-20 17:50:11 -0700816 REAL percent = 0.00, dx, dy, origx, origy, diff = -1.0;
817 INT i, first = 0, second = 1, third = 2, fourth = 3;
Evan Stade69a807c2007-07-06 16:13:49 -0700818
Evan Stadea84b5672007-07-20 17:50:11 -0700819 if(rev){
820 first = 3;
821 second = 2;
822 third = 1;
823 fourth = 0;
824 }
825
826 origx = pt[fourth].X;
827 origy = pt[fourth].Y;
Evan Stade69a807c2007-07-06 16:13:49 -0700828 memcpy(origpt, pt, sizeof(GpPointF) * 4);
829
830 for(i = 0; (i < MAX_ITERS) && (diff < amt); i++){
831 /* reset bezier points to original values */
832 memcpy(pt, origpt, sizeof(GpPointF) * 4);
833 /* Perform magic on bezier points. Order is important here.*/
Evan Stadea84b5672007-07-20 17:50:11 -0700834 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
835 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
836 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
837 shorten_line_percent(pt[first].X, pt[first].Y, &pt[second].X, &pt[second].Y, percent);
838 shorten_line_percent(pt[second].X, pt[second].Y, &pt[third].X, &pt[third].Y, percent);
839 shorten_line_percent(pt[third].X, pt[third].Y, &pt[fourth].X, &pt[fourth].Y, percent);
Evan Stade69a807c2007-07-06 16:13:49 -0700840
Evan Stadea84b5672007-07-20 17:50:11 -0700841 dx = pt[fourth].X - origx;
842 dy = pt[fourth].Y - origy;
Evan Stade69a807c2007-07-06 16:13:49 -0700843
844 diff = sqrt(dx * dx + dy * dy);
845 percent += 0.0005 * amt;
846 }
847}
848
849/* Draws bezier curves between given points, and if caps is true then draws an
Evan Stade88ab6d32007-08-02 17:53:13 -0700850 * endcap at the end of the last line. */
Evan Staded01c6972007-07-23 20:24:53 -0700851static GpStatus draw_polybezier(GpGraphics *graphics, GpPen *pen,
852 GDIPCONST GpPointF * pt, INT count, BOOL caps)
Evan Stade69a807c2007-07-06 16:13:49 -0700853{
Evan Stade7f0aa3a2007-08-02 17:53:08 -0700854 POINT *pti;
Evan Stadea84b5672007-07-20 17:50:11 -0700855 GpPointF *ptcopy;
Evan Stadefa312172007-07-11 18:07:39 -0700856 GpStatus status = GenericError;
857
858 if(!count)
859 return Ok;
860
861 pti = GdipAlloc(count * sizeof(POINT));
Evan Stadea84b5672007-07-20 17:50:11 -0700862 ptcopy = GdipAlloc(count * sizeof(GpPointF));
Evan Stadefa312172007-07-11 18:07:39 -0700863
Evan Stadea84b5672007-07-20 17:50:11 -0700864 if(!pti || !ptcopy){
Evan Stadefa312172007-07-11 18:07:39 -0700865 status = OutOfMemory;
866 goto end;
867 }
Evan Stade69a807c2007-07-06 16:13:49 -0700868
Evan Stadec3e8af42007-07-24 17:18:50 -0700869 memcpy(ptcopy, pt, count * sizeof(GpPointF));
Evan Staded01c6972007-07-23 20:24:53 -0700870
Evan Stadec3e8af42007-07-24 17:18:50 -0700871 if(caps){
Evan Stade69a807c2007-07-06 16:13:49 -0700872 if(pen->endcap == LineCapArrowAnchor)
Evan Stadea84b5672007-07-20 17:50:11 -0700873 shorten_bezier_amt(&ptcopy[count-4], pen->width, FALSE);
Evan Stade7f0aa3a2007-08-02 17:53:08 -0700874 else if((pen->endcap == LineCapCustom) && pen->customend)
875 shorten_bezier_amt(&ptcopy[count-4], pen->width * pen->customend->inset,
876 FALSE);
Evan Stade69a807c2007-07-06 16:13:49 -0700877
Evan Stadea84b5672007-07-20 17:50:11 -0700878 if(pen->startcap == LineCapArrowAnchor)
879 shorten_bezier_amt(ptcopy, pen->width, TRUE);
Evan Stade7f0aa3a2007-08-02 17:53:08 -0700880 else if((pen->startcap == LineCapCustom) && pen->customstart)
Evan Stade02887b62007-08-07 18:42:44 -0700881 shorten_bezier_amt(ptcopy, pen->width * pen->customstart->inset, TRUE);
Evan Stadea84b5672007-07-20 17:50:11 -0700882
Evan Stade55d70e82007-07-11 18:08:26 -0700883 /* the direction of the line cap is parallel to the direction at the
884 * end of the bezier (which, if it has been shortened, is not the same
885 * as the direction from pt[count-2] to pt[count-1]) */
Evan Staded01c6972007-07-23 20:24:53 -0700886 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
Evan Stadea84b5672007-07-20 17:50:11 -0700887 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
888 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
Evan Stade55d70e82007-07-11 18:08:26 -0700889 pt[count - 1].X, pt[count - 1].Y);
Evan Stadea84b5672007-07-20 17:50:11 -0700890
Evan Staded01c6972007-07-23 20:24:53 -0700891 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
Evan Stadea84b5672007-07-20 17:50:11 -0700892 pt[0].X - (ptcopy[0].X - ptcopy[1].X),
893 pt[0].Y - (ptcopy[0].Y - ptcopy[1].Y), pt[0].X, pt[0].Y);
Evan Stade69a807c2007-07-06 16:13:49 -0700894 }
Evan Stadec3e8af42007-07-24 17:18:50 -0700895
896 transform_and_round_points(graphics, pti, ptcopy, count);
Evan Stade69a807c2007-07-06 16:13:49 -0700897
Evan Staded01c6972007-07-23 20:24:53 -0700898 PolyBezier(graphics->hdc, pti, count);
Evan Stadefa312172007-07-11 18:07:39 -0700899
900 status = Ok;
901
902end:
Evan Stade69a807c2007-07-06 16:13:49 -0700903 GdipFree(pti);
Evan Stadea84b5672007-07-20 17:50:11 -0700904 GdipFree(ptcopy);
Evan Stadefa312172007-07-11 18:07:39 -0700905
906 return status;
Evan Stade69a807c2007-07-06 16:13:49 -0700907}
908
Evan Stade9d5f5682007-07-11 18:07:34 -0700909/* Draws a combination of bezier curves and lines between points. */
Evan Staded01c6972007-07-23 20:24:53 -0700910static GpStatus draw_poly(GpGraphics *graphics, GpPen *pen, GDIPCONST GpPointF * pt,
Evan Stade9d5f5682007-07-11 18:07:34 -0700911 GDIPCONST BYTE * types, INT count, BOOL caps)
912{
Evan Stade7f0aa3a2007-08-02 17:53:08 -0700913 POINT *pti = GdipAlloc(count * sizeof(POINT));
Evan Stade9d5f5682007-07-11 18:07:34 -0700914 BYTE *tp = GdipAlloc(count);
Evan Stadea84b5672007-07-20 17:50:11 -0700915 GpPointF *ptcopy = GdipAlloc(count * sizeof(GpPointF));
Evan Stadea84b5672007-07-20 17:50:11 -0700916 INT i, j;
Evan Stade9d5f5682007-07-11 18:07:34 -0700917 GpStatus status = GenericError;
918
919 if(!count){
920 status = Ok;
921 goto end;
922 }
Evan Stadea84b5672007-07-20 17:50:11 -0700923 if(!pti || !tp || !ptcopy){
Evan Stade9d5f5682007-07-11 18:07:34 -0700924 status = OutOfMemory;
925 goto end;
926 }
927
Evan Stadea84b5672007-07-20 17:50:11 -0700928 for(i = 1; i < count; i++){
Evan Stade9d5f5682007-07-11 18:07:34 -0700929 if((types[i] & PathPointTypePathTypeMask) == PathPointTypeBezier){
930 if((i + 2 >= count) || !(types[i + 1] & PathPointTypeBezier)
931 || !(types[i + 1] & PathPointTypeBezier)){
932 ERR("Bad bezier points\n");
933 goto end;
934 }
Evan Stade9d5f5682007-07-11 18:07:34 -0700935 i += 2;
936 }
937 }
938
Evan Stadec3e8af42007-07-24 17:18:50 -0700939 memcpy(ptcopy, pt, count * sizeof(GpPointF));
940
Evan Stade9e883472007-07-13 17:51:49 -0700941 /* If we are drawing caps, go through the points and adjust them accordingly,
942 * and draw the caps. */
943 if(caps){
944 switch(types[count - 1] & PathPointTypePathTypeMask){
945 case PathPointTypeBezier:
Evan Stade9e883472007-07-13 17:51:49 -0700946 if(pen->endcap == LineCapArrowAnchor)
Evan Stadea84b5672007-07-20 17:50:11 -0700947 shorten_bezier_amt(&ptcopy[count - 4], pen->width, FALSE);
Evan Stade7f0aa3a2007-08-02 17:53:08 -0700948 else if((pen->endcap == LineCapCustom) && pen->customend)
949 shorten_bezier_amt(&ptcopy[count - 4],
950 pen->width * pen->customend->inset, FALSE);
Evan Stade9e883472007-07-13 17:51:49 -0700951
Evan Staded01c6972007-07-23 20:24:53 -0700952 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
Evan Stadea84b5672007-07-20 17:50:11 -0700953 pt[count - 1].X - (ptcopy[count - 1].X - ptcopy[count - 2].X),
954 pt[count - 1].Y - (ptcopy[count - 1].Y - ptcopy[count - 2].Y),
Evan Stade9e883472007-07-13 17:51:49 -0700955 pt[count - 1].X, pt[count - 1].Y);
956
Evan Stade9e883472007-07-13 17:51:49 -0700957 break;
Evan Stade9e883472007-07-13 17:51:49 -0700958 case PathPointTypeLine:
959 if(pen->endcap == LineCapArrowAnchor)
Evan Stadea84b5672007-07-20 17:50:11 -0700960 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
961 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
Evan Stade9e883472007-07-13 17:51:49 -0700962 pen->width);
Evan Stadef56fa322007-07-20 17:50:07 -0700963 else if((pen->endcap == LineCapCustom) && pen->customend)
Evan Stadea84b5672007-07-20 17:50:11 -0700964 shorten_line_amt(ptcopy[count - 2].X, ptcopy[count - 2].Y,
965 &ptcopy[count - 1].X, &ptcopy[count - 1].Y,
Evan Stadef56fa322007-07-20 17:50:07 -0700966 pen->customend->inset * pen->width);
Evan Stade9e883472007-07-13 17:51:49 -0700967
Evan Staded01c6972007-07-23 20:24:53 -0700968 draw_cap(graphics, pen->brush->lb.lbColor, pen->endcap, pen->width, pen->customend,
Evan Stade85b5df42007-07-19 18:22:51 -0700969 pt[count - 2].X, pt[count - 2].Y, pt[count - 1].X,
970 pt[count - 1].Y);
Evan Stade9e883472007-07-13 17:51:49 -0700971
Evan Stade9e883472007-07-13 17:51:49 -0700972 break;
973 default:
974 ERR("Bad path last point\n");
975 goto end;
Evan Stade9d5f5682007-07-11 18:07:34 -0700976 }
Evan Stadea84b5672007-07-20 17:50:11 -0700977
978 /* Find start of points */
979 for(j = 1; j < count && ((types[j] & PathPointTypePathTypeMask)
980 == PathPointTypeStart); j++);
981
982 switch(types[j] & PathPointTypePathTypeMask){
983 case PathPointTypeBezier:
984 if(pen->startcap == LineCapArrowAnchor)
985 shorten_bezier_amt(&ptcopy[j - 1], pen->width, TRUE);
Evan Stade7f0aa3a2007-08-02 17:53:08 -0700986 else if((pen->startcap == LineCapCustom) && pen->customstart)
987 shorten_bezier_amt(&ptcopy[j - 1],
Evan Stade02887b62007-08-07 18:42:44 -0700988 pen->width * pen->customstart->inset, TRUE);
Evan Stadea84b5672007-07-20 17:50:11 -0700989
Evan Staded01c6972007-07-23 20:24:53 -0700990 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
Evan Stadea84b5672007-07-20 17:50:11 -0700991 pt[j - 1].X - (ptcopy[j - 1].X - ptcopy[j].X),
992 pt[j - 1].Y - (ptcopy[j - 1].Y - ptcopy[j].Y),
993 pt[j - 1].X, pt[j - 1].Y);
994
995 break;
996 case PathPointTypeLine:
997 if(pen->startcap == LineCapArrowAnchor)
998 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
999 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
1000 pen->width);
1001 else if((pen->startcap == LineCapCustom) && pen->customstart)
1002 shorten_line_amt(ptcopy[j].X, ptcopy[j].Y,
1003 &ptcopy[j - 1].X, &ptcopy[j - 1].Y,
1004 pen->customstart->inset * pen->width);
1005
Evan Stade629e0132007-07-27 16:07:50 -07001006 draw_cap(graphics, pen->brush->lb.lbColor, pen->startcap, pen->width, pen->customstart,
Evan Stadea84b5672007-07-20 17:50:11 -07001007 pt[j].X, pt[j].Y, pt[j - 1].X,
1008 pt[j - 1].Y);
1009
1010 break;
1011 default:
1012 ERR("Bad path points\n");
1013 goto end;
1014 }
Evan Stade9d5f5682007-07-11 18:07:34 -07001015 }
Evan Stadec3e8af42007-07-24 17:18:50 -07001016
1017 transform_and_round_points(graphics, pti, ptcopy, count);
Evan Stade9d5f5682007-07-11 18:07:34 -07001018
1019 for(i = 0; i < count; i++){
1020 tp[i] = convert_path_point_type(types[i]);
1021 }
1022
Evan Staded01c6972007-07-23 20:24:53 -07001023 PolyDraw(graphics->hdc, pti, tp, count);
Evan Stade9d5f5682007-07-11 18:07:34 -07001024
1025 status = Ok;
1026
1027end:
1028 GdipFree(pti);
Evan Stadea84b5672007-07-20 17:50:11 -07001029 GdipFree(ptcopy);
Evan Stade9d5f5682007-07-11 18:07:34 -07001030 GdipFree(tp);
1031
1032 return status;
1033}
1034
Vincent Povirk08aa0ca2008-11-24 15:01:47 -06001035GpStatus trace_path(GpGraphics *graphics, GpPath *path)
1036{
1037 GpStatus result;
1038
1039 BeginPath(graphics->hdc);
1040 result = draw_poly(graphics, NULL, path->pathdata.Points,
1041 path->pathdata.Types, path->pathdata.Count, FALSE);
1042 EndPath(graphics->hdc);
1043 return result;
1044}
1045
Andrew Eikum632aef32009-07-05 17:04:20 -05001046typedef struct _GraphicsContainerItem {
1047 struct list entry;
1048 GraphicsContainer contid;
1049
1050 SmoothingMode smoothing;
1051 CompositingQuality compqual;
1052 InterpolationMode interpolation;
1053 CompositingMode compmode;
1054 TextRenderingHint texthint;
1055 REAL scale;
1056 GpUnit unit;
1057 PixelOffsetMode pixeloffset;
1058 UINT textcontrast;
1059 GpMatrix* worldtrans;
1060 GpRegion* clip;
1061} GraphicsContainerItem;
1062
1063static GpStatus init_container(GraphicsContainerItem** container,
1064 GDIPCONST GpGraphics* graphics){
1065 GpStatus sts;
1066
1067 *container = GdipAlloc(sizeof(GraphicsContainerItem));
1068 if(!(*container))
1069 return OutOfMemory;
1070
1071 (*container)->contid = graphics->contid + 1;
1072
1073 (*container)->smoothing = graphics->smoothing;
1074 (*container)->compqual = graphics->compqual;
1075 (*container)->interpolation = graphics->interpolation;
1076 (*container)->compmode = graphics->compmode;
1077 (*container)->texthint = graphics->texthint;
1078 (*container)->scale = graphics->scale;
1079 (*container)->unit = graphics->unit;
1080 (*container)->textcontrast = graphics->textcontrast;
1081 (*container)->pixeloffset = graphics->pixeloffset;
1082
1083 sts = GdipCloneMatrix(graphics->worldtrans, &(*container)->worldtrans);
1084 if(sts != Ok){
1085 GdipFree(*container);
1086 *container = NULL;
1087 return sts;
1088 }
1089
1090 sts = GdipCloneRegion(graphics->clip, &(*container)->clip);
1091 if(sts != Ok){
1092 GdipDeleteMatrix((*container)->worldtrans);
1093 GdipFree(*container);
1094 *container = NULL;
1095 return sts;
1096 }
1097
1098 return Ok;
1099}
1100
1101static void delete_container(GraphicsContainerItem* container){
1102 GdipDeleteMatrix(container->worldtrans);
1103 GdipDeleteRegion(container->clip);
1104 GdipFree(container);
1105}
1106
1107static GpStatus restore_container(GpGraphics* graphics,
1108 GDIPCONST GraphicsContainerItem* container){
1109 GpStatus sts;
1110 GpMatrix *newTrans;
1111 GpRegion *newClip;
1112
1113 sts = GdipCloneMatrix(container->worldtrans, &newTrans);
1114 if(sts != Ok)
1115 return sts;
1116
1117 sts = GdipCloneRegion(container->clip, &newClip);
1118 if(sts != Ok){
1119 GdipDeleteMatrix(newTrans);
1120 return sts;
1121 }
1122
1123 GdipDeleteMatrix(graphics->worldtrans);
1124 graphics->worldtrans = newTrans;
1125
1126 GdipDeleteRegion(graphics->clip);
1127 graphics->clip = newClip;
1128
1129 graphics->contid = container->contid - 1;
1130
1131 graphics->smoothing = container->smoothing;
1132 graphics->compqual = container->compqual;
1133 graphics->interpolation = container->interpolation;
1134 graphics->compmode = container->compmode;
1135 graphics->texthint = container->texthint;
1136 graphics->scale = container->scale;
1137 graphics->unit = container->unit;
1138 graphics->textcontrast = container->textcontrast;
1139 graphics->pixeloffset = container->pixeloffset;
1140
1141 return Ok;
1142}
1143
Andrew Eikumfdf48f12009-08-12 15:36:54 -05001144static GpStatus get_graphics_bounds(GpGraphics* graphics, GpRectF* rect)
1145{
1146 RECT wnd_rect;
Vincent Povirk56018602010-08-08 15:31:03 -05001147 GpStatus stat=Ok;
1148 GpUnit unit;
Andrew Eikumfdf48f12009-08-12 15:36:54 -05001149
1150 if(graphics->hwnd) {
1151 if(!GetClientRect(graphics->hwnd, &wnd_rect))
1152 return GenericError;
1153
1154 rect->X = wnd_rect.left;
1155 rect->Y = wnd_rect.top;
1156 rect->Width = wnd_rect.right - wnd_rect.left;
1157 rect->Height = wnd_rect.bottom - wnd_rect.top;
Vincent Povirk56018602010-08-08 15:31:03 -05001158 }else if (graphics->image){
1159 stat = GdipGetImageBounds(graphics->image, rect, &unit);
1160 if (stat == Ok && unit != UnitPixel)
1161 FIXME("need to convert from unit %i\n", unit);
Andrew Eikumfdf48f12009-08-12 15:36:54 -05001162 }else{
1163 rect->X = 0;
1164 rect->Y = 0;
1165 rect->Width = GetDeviceCaps(graphics->hdc, HORZRES);
1166 rect->Height = GetDeviceCaps(graphics->hdc, VERTRES);
1167 }
1168
Vincent Povirk56018602010-08-08 15:31:03 -05001169 return stat;
Andrew Eikumfdf48f12009-08-12 15:36:54 -05001170}
1171
Andrew Eikum39f6f492009-08-26 18:03:08 -05001172/* on success, rgn will contain the region of the graphics object which
1173 * is visible after clipping has been applied */
1174static GpStatus get_visible_clip_region(GpGraphics *graphics, GpRegion *rgn)
1175{
1176 GpStatus stat;
1177 GpRectF rectf;
1178 GpRegion* tmp;
1179
1180 if((stat = get_graphics_bounds(graphics, &rectf)) != Ok)
1181 return stat;
1182
1183 if((stat = GdipCreateRegion(&tmp)) != Ok)
1184 return stat;
1185
1186 if((stat = GdipCombineRegionRect(tmp, &rectf, CombineModeReplace)) != Ok)
1187 goto end;
1188
1189 if((stat = GdipCombineRegionRegion(tmp, graphics->clip, CombineModeIntersect)) != Ok)
1190 goto end;
1191
1192 stat = GdipCombineRegionRegion(rgn, tmp, CombineModeReplace);
1193
1194end:
1195 GdipDeleteRegion(tmp);
1196 return stat;
1197}
1198
Evan Staded50be492007-06-11 11:54:03 -07001199GpStatus WINGDIPAPI GdipCreateFromHDC(HDC hdc, GpGraphics **graphics)
1200{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001201 TRACE("(%p, %p)\n", hdc, graphics);
1202
Stefan Leichterbfffb4f2007-12-23 10:56:32 +01001203 return GdipCreateFromHDC2(hdc, NULL, graphics);
1204}
1205
1206GpStatus WINGDIPAPI GdipCreateFromHDC2(HDC hdc, HANDLE hDevice, GpGraphics **graphics)
1207{
Evan Stadef30732f2007-07-24 17:18:47 -07001208 GpStatus retval;
1209
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001210 TRACE("(%p, %p, %p)\n", hdc, hDevice, graphics);
1211
Stefan Leichterbfffb4f2007-12-23 10:56:32 +01001212 if(hDevice != NULL) {
Ken Sharpe3f48592009-06-09 21:48:05 +01001213 FIXME("Don't know how to handle parameter hDevice\n");
Stefan Leichterbfffb4f2007-12-23 10:56:32 +01001214 return NotImplemented;
1215 }
1216
Evan Staded50be492007-06-11 11:54:03 -07001217 if(hdc == NULL)
1218 return OutOfMemory;
1219
1220 if(graphics == NULL)
1221 return InvalidParameter;
1222
Evan Stade6490dad2007-06-22 19:27:02 -07001223 *graphics = GdipAlloc(sizeof(GpGraphics));
1224 if(!*graphics) return OutOfMemory;
1225
Evan Stadef30732f2007-07-24 17:18:47 -07001226 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
1227 GdipFree(*graphics);
1228 return retval;
1229 }
1230
Nikolay Sivovef50aa32008-08-27 02:03:27 +04001231 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
1232 GdipFree((*graphics)->worldtrans);
1233 GdipFree(*graphics);
1234 return retval;
1235 }
1236
Evan Staded50be492007-06-11 11:54:03 -07001237 (*graphics)->hdc = hdc;
Nikolay Sivov7258dea2008-09-05 16:51:25 +04001238 (*graphics)->hwnd = WindowFromDC(hdc);
Vincent Povirk8a3d9ff2009-04-24 13:29:56 -05001239 (*graphics)->owndc = FALSE;
Evan Stade53e17d22007-07-13 17:51:13 -07001240 (*graphics)->smoothing = SmoothingModeDefault;
Evan Stade60cad232007-07-13 17:51:25 -07001241 (*graphics)->compqual = CompositingQualityDefault;
Evan Stadea87ce7a2007-07-13 17:51:29 -07001242 (*graphics)->interpolation = InterpolationModeDefault;
Evan Staded6bd866d2007-07-13 17:51:33 -07001243 (*graphics)->pixeloffset = PixelOffsetModeDefault;
Evan Stadee807eb92007-08-13 18:34:27 -07001244 (*graphics)->compmode = CompositingModeSourceOver;
Evan Stade10b575b2007-07-23 20:24:41 -07001245 (*graphics)->unit = UnitDisplay;
Evan Stade81621392007-07-24 17:18:39 -07001246 (*graphics)->scale = 1.0;
Nikolay Sivov366ae1e2008-08-24 14:45:18 +04001247 (*graphics)->busy = FALSE;
Nikolay Sivov56173d42008-11-09 14:32:26 +03001248 (*graphics)->textcontrast = 4;
Andrew Eikum632aef32009-07-05 17:04:20 -05001249 list_init(&(*graphics)->containers);
1250 (*graphics)->contid = 0;
Evan Staded50be492007-06-11 11:54:03 -07001251
Vincent Povirkf8ca3722009-12-18 15:09:45 -06001252 TRACE("<-- %p\n", *graphics);
1253
Evan Staded50be492007-06-11 11:54:03 -07001254 return Ok;
1255}
1256
Vincent Povirk9a6eabf2010-08-08 16:18:40 -05001257GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics)
1258{
1259 GpStatus retval;
1260
1261 *graphics = GdipAlloc(sizeof(GpGraphics));
1262 if(!*graphics) return OutOfMemory;
1263
1264 if((retval = GdipCreateMatrix(&(*graphics)->worldtrans)) != Ok){
1265 GdipFree(*graphics);
1266 return retval;
1267 }
1268
1269 if((retval = GdipCreateRegion(&(*graphics)->clip)) != Ok){
1270 GdipFree((*graphics)->worldtrans);
1271 GdipFree(*graphics);
1272 return retval;
1273 }
1274
1275 (*graphics)->hdc = NULL;
1276 (*graphics)->hwnd = NULL;
1277 (*graphics)->owndc = FALSE;
1278 (*graphics)->image = image;
1279 (*graphics)->smoothing = SmoothingModeDefault;
1280 (*graphics)->compqual = CompositingQualityDefault;
1281 (*graphics)->interpolation = InterpolationModeDefault;
1282 (*graphics)->pixeloffset = PixelOffsetModeDefault;
1283 (*graphics)->compmode = CompositingModeSourceOver;
1284 (*graphics)->unit = UnitDisplay;
1285 (*graphics)->scale = 1.0;
1286 (*graphics)->busy = FALSE;
1287 (*graphics)->textcontrast = 4;
1288 list_init(&(*graphics)->containers);
1289 (*graphics)->contid = 0;
1290
1291 TRACE("<-- %p\n", *graphics);
1292
1293 return Ok;
1294}
1295
Evan Staded50be492007-06-11 11:54:03 -07001296GpStatus WINGDIPAPI GdipCreateFromHWND(HWND hwnd, GpGraphics **graphics)
1297{
1298 GpStatus ret;
Vincent Povirkc3d23952009-04-24 13:34:55 -05001299 HDC hdc;
Evan Staded50be492007-06-11 11:54:03 -07001300
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001301 TRACE("(%p, %p)\n", hwnd, graphics);
1302
Vincent Povirkc3d23952009-04-24 13:34:55 -05001303 hdc = GetDC(hwnd);
1304
1305 if((ret = GdipCreateFromHDC(hdc, graphics)) != Ok)
1306 {
1307 ReleaseDC(hwnd, hdc);
Evan Staded50be492007-06-11 11:54:03 -07001308 return ret;
Vincent Povirkc3d23952009-04-24 13:34:55 -05001309 }
Evan Staded50be492007-06-11 11:54:03 -07001310
1311 (*graphics)->hwnd = hwnd;
Vincent Povirk8a3d9ff2009-04-24 13:29:56 -05001312 (*graphics)->owndc = TRUE;
Evan Staded50be492007-06-11 11:54:03 -07001313
1314 return Ok;
1315}
1316
Nikolay Sivoveb18ce92008-05-09 16:40:41 +04001317/* FIXME: no icm handling */
1318GpStatus WINGDIPAPI GdipCreateFromHWNDICM(HWND hwnd, GpGraphics **graphics)
1319{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001320 TRACE("(%p, %p)\n", hwnd, graphics);
1321
Nikolay Sivoveb18ce92008-05-09 16:40:41 +04001322 return GdipCreateFromHWND(hwnd, graphics);
1323}
1324
Evan Stade5cc8c102007-07-24 17:19:05 -07001325GpStatus WINGDIPAPI GdipCreateMetafileFromEmf(HENHMETAFILE hemf, BOOL delete,
1326 GpMetafile **metafile)
1327{
1328 static int calls;
1329
Vincent Povirk2005fe92009-12-18 16:04:20 -06001330 TRACE("(%p,%i,%p)\n", hemf, delete, metafile);
1331
Evan Stade5cc8c102007-07-24 17:19:05 -07001332 if(!hemf || !metafile)
1333 return InvalidParameter;
1334
1335 if(!(calls++))
1336 FIXME("not implemented\n");
1337
1338 return NotImplemented;
1339}
1340
Evan Stade021997f2007-07-24 17:19:15 -07001341GpStatus WINGDIPAPI GdipCreateMetafileFromWmf(HMETAFILE hwmf, BOOL delete,
1342 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
1343{
Evan Stadecfef9812007-07-31 19:15:12 -07001344 IStream *stream = NULL;
Evan Stade50799cf2007-07-30 19:10:03 -07001345 UINT read;
1346 BYTE* copy;
Evan Stade50799cf2007-07-30 19:10:03 -07001347 HENHMETAFILE hemf;
Vincent Povirk01b32952009-12-31 16:15:37 -06001348 GpStatus retval = Ok;
Evan Stade021997f2007-07-24 17:19:15 -07001349
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001350 TRACE("(%p, %d, %p, %p)\n", hwmf, delete, placeable, metafile);
1351
Evan Stade021997f2007-07-24 17:19:15 -07001352 if(!hwmf || !metafile || !placeable)
1353 return InvalidParameter;
Evan Stade7d03a412007-08-07 18:42:16 -07001354
1355 *metafile = NULL;
Evan Stade50799cf2007-07-30 19:10:03 -07001356 read = GetMetaFileBitsEx(hwmf, 0, NULL);
1357 if(!read)
1358 return GenericError;
1359 copy = GdipAlloc(read);
1360 GetMetaFileBitsEx(hwmf, read, copy);
1361
Evan Stade192e1112007-08-01 17:55:33 -07001362 hemf = SetWinMetaFileBits(read, copy, NULL, NULL);
Evan Stade50799cf2007-07-30 19:10:03 -07001363 GdipFree(copy);
1364
1365 read = GetEnhMetaFileBits(hemf, 0, NULL);
1366 copy = GdipAlloc(read);
1367 GetEnhMetaFileBits(hemf, read, copy);
1368 DeleteEnhMetaFile(hemf);
1369
1370 if(CreateStreamOnHGlobal(copy, TRUE, &stream) != S_OK){
1371 ERR("could not make stream\n");
Evan Stade7d03a412007-08-07 18:42:16 -07001372 GdipFree(copy);
Vincent Povirk01b32952009-12-31 16:15:37 -06001373 retval = GenericError;
Evan Stade7d03a412007-08-07 18:42:16 -07001374 goto err;
Evan Stade50799cf2007-07-30 19:10:03 -07001375 }
1376
1377 *metafile = GdipAlloc(sizeof(GpMetafile));
Evan Stadecfef9812007-07-31 19:15:12 -07001378 if(!*metafile){
1379 retval = OutOfMemory;
Evan Stade7d03a412007-08-07 18:42:16 -07001380 goto err;
Evan Stadecfef9812007-07-31 19:15:12 -07001381 }
Evan Stade50799cf2007-07-30 19:10:03 -07001382
1383 if(OleLoadPicture(stream, 0, FALSE, &IID_IPicture,
Evan Stade7d03a412007-08-07 18:42:16 -07001384 (LPVOID*) &((*metafile)->image.picture)) != S_OK)
Vincent Povirk01b32952009-12-31 16:15:37 -06001385 {
1386 retval = GenericError;
Evan Stade7d03a412007-08-07 18:42:16 -07001387 goto err;
Vincent Povirk01b32952009-12-31 16:15:37 -06001388 }
Evan Stade7d03a412007-08-07 18:42:16 -07001389
Evan Stade50799cf2007-07-30 19:10:03 -07001390
1391 (*metafile)->image.type = ImageTypeMetafile;
Vincent Povirk0595fc52009-09-14 11:23:45 -05001392 memcpy(&(*metafile)->image.format, &ImageFormatWMF, sizeof(GUID));
Vincent Povirk39dc81c2009-12-11 16:51:46 -06001393 (*metafile)->image.palette_flags = 0;
1394 (*metafile)->image.palette_count = 0;
1395 (*metafile)->image.palette_size = 0;
1396 (*metafile)->image.palette_entries = NULL;
Vincent Povirk1aea88c2009-12-26 20:46:55 -05001397 (*metafile)->image.xres = (REAL)placeable->Inch;
1398 (*metafile)->image.yres = (REAL)placeable->Inch;
Evan Stade586e63e2007-07-30 19:09:57 -07001399 (*metafile)->bounds.X = ((REAL) placeable->BoundingBox.Left) / ((REAL) placeable->Inch);
Vincent Povirkc38d3342009-12-26 20:07:37 -05001400 (*metafile)->bounds.Y = ((REAL) placeable->BoundingBox.Top) / ((REAL) placeable->Inch);
Evan Stade586e63e2007-07-30 19:09:57 -07001401 (*metafile)->bounds.Width = ((REAL) (placeable->BoundingBox.Right
Vincent Povirk2f9c6092010-04-15 13:32:44 -05001402 - placeable->BoundingBox.Left));
Evan Stade586e63e2007-07-30 19:09:57 -07001403 (*metafile)->bounds.Height = ((REAL) (placeable->BoundingBox.Bottom
Vincent Povirk2f9c6092010-04-15 13:32:44 -05001404 - placeable->BoundingBox.Top));
1405 (*metafile)->unit = UnitPixel;
Evan Stade586e63e2007-07-30 19:09:57 -07001406
Evan Stade50799cf2007-07-30 19:10:03 -07001407 if(delete)
1408 DeleteMetaFile(hwmf);
1409
Vincent Povirkf8ca3722009-12-18 15:09:45 -06001410 TRACE("<-- %p\n", *metafile);
1411
Evan Stade7d03a412007-08-07 18:42:16 -07001412err:
Vincent Povirk01b32952009-12-31 16:15:37 -06001413 if (retval != Ok)
1414 GdipFree(*metafile);
Evan Stadecfef9812007-07-31 19:15:12 -07001415 IStream_Release(stream);
Evan Stadecfef9812007-07-31 19:15:12 -07001416 return retval;
Evan Stade021997f2007-07-24 17:19:15 -07001417}
1418
Huw Davieseb9d7f52008-07-10 15:30:30 +01001419GpStatus WINGDIPAPI GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR *file,
1420 GDIPCONST WmfPlaceableFileHeader * placeable, GpMetafile **metafile)
1421{
1422 HMETAFILE hmf = GetMetaFileW(file);
1423
1424 TRACE("(%s, %p, %p)\n", debugstr_w(file), placeable, metafile);
1425
1426 if(!hmf) return InvalidParameter;
1427
1428 return GdipCreateMetafileFromWmf(hmf, TRUE, placeable, metafile);
1429}
1430
Andrew Eikumc02e75c2009-06-01 20:02:11 -05001431GpStatus WINGDIPAPI GdipCreateMetafileFromFile(GDIPCONST WCHAR *file,
1432 GpMetafile **metafile)
1433{
1434 FIXME("(%p, %p): stub\n", file, metafile);
1435 return NotImplemented;
1436}
1437
1438GpStatus WINGDIPAPI GdipCreateMetafileFromStream(IStream *stream,
1439 GpMetafile **metafile)
1440{
1441 FIXME("(%p, %p): stub\n", stream, metafile);
1442 return NotImplemented;
1443}
1444
Evan Stade3ea77f52007-08-07 18:42:00 -07001445GpStatus WINGDIPAPI GdipCreateStreamOnFile(GDIPCONST WCHAR * filename,
1446 UINT access, IStream **stream)
1447{
1448 DWORD dwMode;
1449 HRESULT ret;
1450
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001451 TRACE("(%s, %u, %p)\n", debugstr_w(filename), access, stream);
1452
Evan Stade3ea77f52007-08-07 18:42:00 -07001453 if(!stream || !filename)
1454 return InvalidParameter;
1455
1456 if(access & GENERIC_WRITE)
1457 dwMode = STGM_SHARE_DENY_WRITE | STGM_WRITE | STGM_CREATE;
1458 else if(access & GENERIC_READ)
1459 dwMode = STGM_SHARE_DENY_WRITE | STGM_READ | STGM_FAILIFTHERE;
1460 else
1461 return InvalidParameter;
1462
1463 ret = SHCreateStreamOnFileW(filename, dwMode, stream);
1464
1465 return hresult_to_status(ret);
1466}
1467
Evan Staded50be492007-06-11 11:54:03 -07001468GpStatus WINGDIPAPI GdipDeleteGraphics(GpGraphics *graphics)
1469{
Andrew Eikum632aef32009-07-05 17:04:20 -05001470 GraphicsContainerItem *cont, *next;
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001471 TRACE("(%p)\n", graphics);
1472
Evan Staded50be492007-06-11 11:54:03 -07001473 if(!graphics) return InvalidParameter;
Nikolay Sivov960de092008-08-26 01:58:33 +04001474 if(graphics->busy) return ObjectBusy;
1475
Vincent Povirk8a3d9ff2009-04-24 13:29:56 -05001476 if(graphics->owndc)
Evan Staded50be492007-06-11 11:54:03 -07001477 ReleaseDC(graphics->hwnd, graphics->hdc);
1478
Andrew Eikum632aef32009-07-05 17:04:20 -05001479 LIST_FOR_EACH_ENTRY_SAFE(cont, next, &graphics->containers, GraphicsContainerItem, entry){
1480 list_remove(&cont->entry);
1481 delete_container(cont);
1482 }
1483
Nikolay Sivovef50aa32008-08-27 02:03:27 +04001484 GdipDeleteRegion(graphics->clip);
Evan Stadef30732f2007-07-24 17:18:47 -07001485 GdipDeleteMatrix(graphics->worldtrans);
Nikolay Sivov6e37ec62008-08-24 14:45:05 +04001486 GdipFree(graphics);
Evan Staded50be492007-06-11 11:54:03 -07001487
1488 return Ok;
1489}
Evan Stade2689b182007-06-12 10:44:31 -07001490
Evan Stadec42f8792007-06-19 19:31:19 -07001491GpStatus WINGDIPAPI GdipDrawArc(GpGraphics *graphics, GpPen *pen, REAL x,
1492 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
1493{
Evan Stade40f22732007-07-11 18:07:09 -07001494 INT save_state, num_pts;
1495 GpPointF points[MAX_ARC_PTS];
Evan Stadefa312172007-07-11 18:07:39 -07001496 GpStatus retval;
Evan Stadec42f8792007-06-19 19:31:19 -07001497
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001498 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
1499 width, height, startAngle, sweepAngle);
1500
Royal Chanea928722008-02-25 21:06:27 -08001501 if(!graphics || !pen || width <= 0 || height <= 0)
Evan Stadec42f8792007-06-19 19:31:19 -07001502 return InvalidParameter;
1503
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04001504 if(graphics->busy)
1505 return ObjectBusy;
1506
Evan Stade40f22732007-07-11 18:07:09 -07001507 num_pts = arc2polybezier(points, x, y, width, height, startAngle, sweepAngle);
Evan Stadec42f8792007-06-19 19:31:19 -07001508
Evan Stade4c424b32007-07-24 17:18:54 -07001509 save_state = prepare_dc(graphics, pen);
Evan Stadec42f8792007-06-19 19:31:19 -07001510
Evan Staded01c6972007-07-23 20:24:53 -07001511 retval = draw_polybezier(graphics, pen, points, num_pts, TRUE);
Evan Stadec42f8792007-06-19 19:31:19 -07001512
Evan Stade4c424b32007-07-24 17:18:54 -07001513 restore_dc(graphics, save_state);
Evan Stadec42f8792007-06-19 19:31:19 -07001514
Evan Stadefa312172007-07-11 18:07:39 -07001515 return retval;
Evan Stadec42f8792007-06-19 19:31:19 -07001516}
1517
Royal Chanfc313032008-02-25 21:02:59 -08001518GpStatus WINGDIPAPI GdipDrawArcI(GpGraphics *graphics, GpPen *pen, INT x,
1519 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
1520{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001521 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
1522 width, height, startAngle, sweepAngle);
1523
Nikolay Sivova77dc342008-05-08 00:39:05 +04001524 return GdipDrawArc(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
Royal Chanfc313032008-02-25 21:02:59 -08001525}
1526
Evan Stade8b9f5342007-06-15 21:27:38 -07001527GpStatus WINGDIPAPI GdipDrawBezier(GpGraphics *graphics, GpPen *pen, REAL x1,
1528 REAL y1, REAL x2, REAL y2, REAL x3, REAL y3, REAL x4, REAL y4)
1529{
Evan Stade69a807c2007-07-06 16:13:49 -07001530 INT save_state;
1531 GpPointF pt[4];
Evan Stadefa312172007-07-11 18:07:39 -07001532 GpStatus retval;
Evan Stade8b9f5342007-06-15 21:27:38 -07001533
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001534 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1,
1535 x2, y2, x3, y3, x4, y4);
1536
Evan Stade8b9f5342007-06-15 21:27:38 -07001537 if(!graphics || !pen)
1538 return InvalidParameter;
1539
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04001540 if(graphics->busy)
1541 return ObjectBusy;
1542
Evan Stade69a807c2007-07-06 16:13:49 -07001543 pt[0].X = x1;
1544 pt[0].Y = y1;
1545 pt[1].X = x2;
1546 pt[1].Y = y2;
1547 pt[2].X = x3;
1548 pt[2].Y = y3;
1549 pt[3].X = x4;
1550 pt[3].Y = y4;
Evan Stade8b9f5342007-06-15 21:27:38 -07001551
Evan Stade4c424b32007-07-24 17:18:54 -07001552 save_state = prepare_dc(graphics, pen);
Evan Stade8b9f5342007-06-15 21:27:38 -07001553
Evan Staded01c6972007-07-23 20:24:53 -07001554 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
Evan Stade69a807c2007-07-06 16:13:49 -07001555
Evan Stade4c424b32007-07-24 17:18:54 -07001556 restore_dc(graphics, save_state);
Evan Stade8b9f5342007-06-15 21:27:38 -07001557
Evan Stadefa312172007-07-11 18:07:39 -07001558 return retval;
Evan Stade8b9f5342007-06-15 21:27:38 -07001559}
1560
Royal Chanda161a52008-02-25 21:00:43 -08001561GpStatus WINGDIPAPI GdipDrawBezierI(GpGraphics *graphics, GpPen *pen, INT x1,
1562 INT y1, INT x2, INT y2, INT x3, INT y3, INT x4, INT y4)
1563{
1564 INT save_state;
1565 GpPointF pt[4];
1566 GpStatus retval;
1567
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001568 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics, pen, x1, y1,
1569 x2, y2, x3, y3, x4, y4);
1570
Royal Chanda161a52008-02-25 21:00:43 -08001571 if(!graphics || !pen)
1572 return InvalidParameter;
1573
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04001574 if(graphics->busy)
1575 return ObjectBusy;
1576
Royal Chanda161a52008-02-25 21:00:43 -08001577 pt[0].X = x1;
1578 pt[0].Y = y1;
1579 pt[1].X = x2;
1580 pt[1].Y = y2;
1581 pt[2].X = x3;
1582 pt[2].Y = y3;
1583 pt[3].X = x4;
1584 pt[3].Y = y4;
1585
1586 save_state = prepare_dc(graphics, pen);
1587
1588 retval = draw_polybezier(graphics, pen, pt, 4, TRUE);
1589
1590 restore_dc(graphics, save_state);
1591
1592 return retval;
1593}
1594
Nikolay Sivovd0204742008-07-03 03:04:50 +04001595GpStatus WINGDIPAPI GdipDrawBeziers(GpGraphics *graphics, GpPen *pen,
1596 GDIPCONST GpPointF *points, INT count)
1597{
1598 INT i;
1599 GpStatus ret;
1600
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001601 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1602
Nikolay Sivovd0204742008-07-03 03:04:50 +04001603 if(!graphics || !pen || !points || (count <= 0))
1604 return InvalidParameter;
1605
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04001606 if(graphics->busy)
1607 return ObjectBusy;
1608
Nikolay Sivovd0204742008-07-03 03:04:50 +04001609 for(i = 0; i < floor(count / 4); i++){
1610 ret = GdipDrawBezier(graphics, pen,
1611 points[4*i].X, points[4*i].Y,
1612 points[4*i + 1].X, points[4*i + 1].Y,
1613 points[4*i + 2].X, points[4*i + 2].Y,
1614 points[4*i + 3].X, points[4*i + 3].Y);
1615 if(ret != Ok)
1616 return ret;
1617 }
1618
1619 return Ok;
1620}
1621
1622GpStatus WINGDIPAPI GdipDrawBeziersI(GpGraphics *graphics, GpPen *pen,
1623 GDIPCONST GpPoint *points, INT count)
1624{
1625 GpPointF *pts;
1626 GpStatus ret;
1627 INT i;
1628
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001629 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1630
Nikolay Sivovd0204742008-07-03 03:04:50 +04001631 if(!graphics || !pen || !points || (count <= 0))
1632 return InvalidParameter;
1633
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04001634 if(graphics->busy)
1635 return ObjectBusy;
1636
Nikolay Sivovd0204742008-07-03 03:04:50 +04001637 pts = GdipAlloc(sizeof(GpPointF) * count);
1638 if(!pts)
1639 return OutOfMemory;
1640
1641 for(i = 0; i < count; i++){
1642 pts[i].X = (REAL)points[i].X;
1643 pts[i].Y = (REAL)points[i].Y;
1644 }
1645
1646 ret = GdipDrawBeziers(graphics,pen,pts,count);
1647
1648 GdipFree(pts);
1649
1650 return ret;
1651}
1652
Nikolay Sivov55916bb2008-07-09 00:39:31 +04001653GpStatus WINGDIPAPI GdipDrawClosedCurve(GpGraphics *graphics, GpPen *pen,
1654 GDIPCONST GpPointF *points, INT count)
1655{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001656 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1657
Nikolay Sivov55916bb2008-07-09 00:39:31 +04001658 return GdipDrawClosedCurve2(graphics, pen, points, count, 1.0);
1659}
1660
1661GpStatus WINGDIPAPI GdipDrawClosedCurveI(GpGraphics *graphics, GpPen *pen,
1662 GDIPCONST GpPoint *points, INT count)
1663{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001664 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1665
Nikolay Sivov55916bb2008-07-09 00:39:31 +04001666 return GdipDrawClosedCurve2I(graphics, pen, points, count, 1.0);
1667}
1668
Nikolay Sivov8b8864b2008-07-09 00:39:19 +04001669GpStatus WINGDIPAPI GdipDrawClosedCurve2(GpGraphics *graphics, GpPen *pen,
1670 GDIPCONST GpPointF *points, INT count, REAL tension)
1671{
Nikolay Sivov9c60a572008-09-03 19:57:09 +04001672 GpPath *path;
Nikolay Sivov8b8864b2008-07-09 00:39:19 +04001673 GpStatus stat;
1674
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001675 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1676
Nikolay Sivov8b8864b2008-07-09 00:39:19 +04001677 if(!graphics || !pen || !points || count <= 0)
1678 return InvalidParameter;
1679
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04001680 if(graphics->busy)
1681 return ObjectBusy;
1682
Nikolay Sivov9c60a572008-09-03 19:57:09 +04001683 if((stat = GdipCreatePath(FillModeAlternate, &path)) != Ok)
1684 return stat;
Nikolay Sivov8b8864b2008-07-09 00:39:19 +04001685
Nikolay Sivov9c60a572008-09-03 19:57:09 +04001686 stat = GdipAddPathClosedCurve2(path, points, count, tension);
1687 if(stat != Ok){
1688 GdipDeletePath(path);
1689 return stat;
1690 }
Nikolay Sivov8b8864b2008-07-09 00:39:19 +04001691
Nikolay Sivov9c60a572008-09-03 19:57:09 +04001692 stat = GdipDrawPath(graphics, pen, path);
Nikolay Sivov8b8864b2008-07-09 00:39:19 +04001693
Nikolay Sivov9c60a572008-09-03 19:57:09 +04001694 GdipDeletePath(path);
Nikolay Sivov8b8864b2008-07-09 00:39:19 +04001695
1696 return stat;
1697}
1698
1699GpStatus WINGDIPAPI GdipDrawClosedCurve2I(GpGraphics *graphics, GpPen *pen,
1700 GDIPCONST GpPoint *points, INT count, REAL tension)
1701{
1702 GpPointF *ptf;
1703 GpStatus stat;
1704 INT i;
1705
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001706 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1707
Nikolay Sivov8b8864b2008-07-09 00:39:19 +04001708 if(!points || count <= 0)
1709 return InvalidParameter;
1710
1711 ptf = GdipAlloc(sizeof(GpPointF)*count);
1712 if(!ptf)
1713 return OutOfMemory;
1714
1715 for(i = 0; i < count; i++){
1716 ptf[i].X = (REAL)points[i].X;
1717 ptf[i].Y = (REAL)points[i].Y;
1718 }
1719
1720 stat = GdipDrawClosedCurve2(graphics, pen, ptf, count, tension);
1721
1722 GdipFree(ptf);
1723
1724 return stat;
1725}
1726
Nikolay Sivovfe1782e2008-04-29 00:09:55 +04001727GpStatus WINGDIPAPI GdipDrawCurve(GpGraphics *graphics, GpPen *pen,
1728 GDIPCONST GpPointF *points, INT count)
1729{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001730 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1731
Nikolay Sivovfe1782e2008-04-29 00:09:55 +04001732 return GdipDrawCurve2(graphics,pen,points,count,1.0);
1733}
1734
1735GpStatus WINGDIPAPI GdipDrawCurveI(GpGraphics *graphics, GpPen *pen,
1736 GDIPCONST GpPoint *points, INT count)
1737{
1738 GpPointF *pointsF;
1739 GpStatus ret;
1740 INT i;
1741
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001742 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
1743
Andrew Eikumfe55f0d2009-06-28 13:33:52 -05001744 if(!points)
Nikolay Sivovfe1782e2008-04-29 00:09:55 +04001745 return InvalidParameter;
1746
1747 pointsF = GdipAlloc(sizeof(GpPointF)*count);
1748 if(!pointsF)
1749 return OutOfMemory;
1750
1751 for(i = 0; i < count; i++){
1752 pointsF[i].X = (REAL)points[i].X;
1753 pointsF[i].Y = (REAL)points[i].Y;
1754 }
1755
1756 ret = GdipDrawCurve(graphics,pen,pointsF,count);
1757 GdipFree(pointsF);
1758
1759 return ret;
1760}
1761
Evan Stade5c8b83c2007-06-19 19:31:28 -07001762/* Approximates cardinal spline with Bezier curves. */
1763GpStatus WINGDIPAPI GdipDrawCurve2(GpGraphics *graphics, GpPen *pen,
1764 GDIPCONST GpPointF *points, INT count, REAL tension)
1765{
Evan Stade5c8b83c2007-06-19 19:31:28 -07001766 /* PolyBezier expects count*3-2 points. */
Evan Stadeb72dc0d2007-07-09 20:54:23 -07001767 INT i, len_pt = count*3-2, save_state;
1768 GpPointF *pt;
Evan Stade5c8b83c2007-06-19 19:31:28 -07001769 REAL x1, x2, y1, y2;
Evan Stadefa312172007-07-11 18:07:39 -07001770 GpStatus retval;
Evan Stade5c8b83c2007-06-19 19:31:28 -07001771
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001772 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1773
Evan Stade5c8b83c2007-06-19 19:31:28 -07001774 if(!graphics || !pen)
1775 return InvalidParameter;
1776
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04001777 if(graphics->busy)
1778 return ObjectBusy;
1779
Andrew Eikum119e9af2009-06-06 12:02:29 -05001780 if(count < 2)
1781 return InvalidParameter;
1782
Evan Stadeb72dc0d2007-07-09 20:54:23 -07001783 pt = GdipAlloc(len_pt * sizeof(GpPointF));
Andrew Eikum119e9af2009-06-06 12:02:29 -05001784 if(!pt)
1785 return OutOfMemory;
1786
Evan Stade5c8b83c2007-06-19 19:31:28 -07001787 tension = tension * TENSION_CONST;
1788
1789 calc_curve_bezier_endp(points[0].X, points[0].Y, points[1].X, points[1].Y,
1790 tension, &x1, &y1);
1791
Evan Stadeb72dc0d2007-07-09 20:54:23 -07001792 pt[0].X = points[0].X;
1793 pt[0].Y = points[0].Y;
1794 pt[1].X = x1;
1795 pt[1].Y = y1;
Evan Stade5c8b83c2007-06-19 19:31:28 -07001796
1797 for(i = 0; i < count-2; i++){
1798 calc_curve_bezier(&(points[i]), tension, &x1, &y1, &x2, &y2);
1799
Evan Stadeb72dc0d2007-07-09 20:54:23 -07001800 pt[3*i+2].X = x1;
1801 pt[3*i+2].Y = y1;
1802 pt[3*i+3].X = points[i+1].X;
1803 pt[3*i+3].Y = points[i+1].Y;
1804 pt[3*i+4].X = x2;
1805 pt[3*i+4].Y = y2;
Evan Stade5c8b83c2007-06-19 19:31:28 -07001806 }
1807
1808 calc_curve_bezier_endp(points[count-1].X, points[count-1].Y,
1809 points[count-2].X, points[count-2].Y, tension, &x1, &y1);
1810
Evan Stadeb72dc0d2007-07-09 20:54:23 -07001811 pt[len_pt-2].X = x1;
1812 pt[len_pt-2].Y = y1;
1813 pt[len_pt-1].X = points[count-1].X;
1814 pt[len_pt-1].Y = points[count-1].Y;
Evan Stade5c8b83c2007-06-19 19:31:28 -07001815
Evan Stade4c424b32007-07-24 17:18:54 -07001816 save_state = prepare_dc(graphics, pen);
Evan Stade5c8b83c2007-06-19 19:31:28 -07001817
Evan Staded01c6972007-07-23 20:24:53 -07001818 retval = draw_polybezier(graphics, pen, pt, len_pt, TRUE);
Evan Stade5c8b83c2007-06-19 19:31:28 -07001819
Evan Stadeb72dc0d2007-07-09 20:54:23 -07001820 GdipFree(pt);
Evan Stade4c424b32007-07-24 17:18:54 -07001821 restore_dc(graphics, save_state);
Evan Stade5c8b83c2007-06-19 19:31:28 -07001822
Evan Stadefa312172007-07-11 18:07:39 -07001823 return retval;
Evan Stade5c8b83c2007-06-19 19:31:28 -07001824}
1825
Nikolay Sivov00cfffb2008-04-29 00:09:44 +04001826GpStatus WINGDIPAPI GdipDrawCurve2I(GpGraphics *graphics, GpPen *pen,
1827 GDIPCONST GpPoint *points, INT count, REAL tension)
1828{
1829 GpPointF *pointsF;
1830 GpStatus ret;
1831 INT i;
1832
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001833 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics, pen, points, count, tension);
1834
Andrew Eikumc2aa66d2009-06-28 13:33:59 -05001835 if(!points)
Nikolay Sivov00cfffb2008-04-29 00:09:44 +04001836 return InvalidParameter;
1837
1838 pointsF = GdipAlloc(sizeof(GpPointF)*count);
1839 if(!pointsF)
1840 return OutOfMemory;
1841
1842 for(i = 0; i < count; i++){
1843 pointsF[i].X = (REAL)points[i].X;
1844 pointsF[i].Y = (REAL)points[i].Y;
1845 }
1846
1847 ret = GdipDrawCurve2(graphics,pen,pointsF,count,tension);
1848 GdipFree(pointsF);
1849
1850 return ret;
1851}
1852
Andrew Eikum4c0edba2009-06-29 22:12:40 -05001853GpStatus WINGDIPAPI GdipDrawCurve3(GpGraphics *graphics, GpPen *pen,
1854 GDIPCONST GpPointF *points, INT count, INT offset, INT numberOfSegments,
1855 REAL tension)
1856{
1857 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
1858
1859 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
1860 return InvalidParameter;
1861 }
1862
1863 return GdipDrawCurve2(graphics, pen, points + offset, numberOfSegments + 1, tension);
1864}
1865
1866GpStatus WINGDIPAPI GdipDrawCurve3I(GpGraphics *graphics, GpPen *pen,
1867 GDIPCONST GpPoint *points, INT count, INT offset, INT numberOfSegments,
1868 REAL tension)
1869{
1870 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics, pen, points, count, offset, numberOfSegments, tension);
1871
1872 if(count < 0){
1873 return OutOfMemory;
1874 }
1875
1876 if(offset >= count || numberOfSegments > count - offset - 1 || numberOfSegments <= 0){
1877 return InvalidParameter;
1878 }
1879
1880 return GdipDrawCurve2I(graphics, pen, points + offset, numberOfSegments + 1, tension);
1881}
1882
Przemysław Białek864384e2008-06-27 10:59:23 +02001883GpStatus WINGDIPAPI GdipDrawEllipse(GpGraphics *graphics, GpPen *pen, REAL x,
1884 REAL y, REAL width, REAL height)
1885{
1886 INT save_state;
1887 GpPointF ptf[2];
1888 POINT pti[2];
1889
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001890 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
1891
Przemysław Białek864384e2008-06-27 10:59:23 +02001892 if(!graphics || !pen)
1893 return InvalidParameter;
1894
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04001895 if(graphics->busy)
1896 return ObjectBusy;
1897
Przemysław Białek864384e2008-06-27 10:59:23 +02001898 ptf[0].X = x;
1899 ptf[0].Y = y;
1900 ptf[1].X = x + width;
1901 ptf[1].Y = y + height;
1902
1903 save_state = prepare_dc(graphics, pen);
1904 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
1905
1906 transform_and_round_points(graphics, pti, ptf, 2);
1907
1908 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
1909
1910 restore_dc(graphics, save_state);
1911
1912 return Ok;
1913}
1914
1915GpStatus WINGDIPAPI GdipDrawEllipseI(GpGraphics *graphics, GpPen *pen, INT x,
1916 INT y, INT width, INT height)
1917{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001918 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
1919
Przemysław Białek864384e2008-06-27 10:59:23 +02001920 return GdipDrawEllipse(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
1921}
1922
1923
Nikolay Sivov49247042008-04-29 00:10:01 +04001924GpStatus WINGDIPAPI GdipDrawImage(GpGraphics *graphics, GpImage *image, REAL x, REAL y)
1925{
Vincent Povirke72defc2009-08-20 16:16:05 -05001926 UINT width, height;
1927 GpPointF points[3];
1928
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04001929 TRACE("(%p, %p, %.2f, %.2f)\n", graphics, image, x, y);
1930
Evan Stadede351ab2007-08-07 18:42:12 -07001931 if(!graphics || !image)
1932 return InvalidParameter;
1933
1934 GdipGetImageWidth(image, &width);
1935 GdipGetImageHeight(image, &height);
1936
Vincent Povirke72defc2009-08-20 16:16:05 -05001937 /* FIXME: we should use the graphics and image dpi, somehow */
Evan Stadede351ab2007-08-07 18:42:12 -07001938
Vincent Povirke72defc2009-08-20 16:16:05 -05001939 points[0].X = points[2].X = x;
1940 points[0].Y = points[1].Y = y;
1941 points[1].X = x + width;
1942 points[2].Y = y + height;
Evan Stadede351ab2007-08-07 18:42:12 -07001943
Vincent Povirke72defc2009-08-20 16:16:05 -05001944 return GdipDrawImagePointsRect(graphics, image, points, 3, 0, 0, width, height,
1945 UnitPixel, NULL, NULL, NULL);
1946}
Evan Stadede351ab2007-08-07 18:42:12 -07001947
Vincent Povirke72defc2009-08-20 16:16:05 -05001948GpStatus WINGDIPAPI GdipDrawImageI(GpGraphics *graphics, GpImage *image, INT x,
1949 INT y)
1950{
1951 TRACE("(%p, %p, %d, %d)\n", graphics, image, x, y);
1952
1953 return GdipDrawImage(graphics, image, (REAL)x, (REAL)y);
Evan Stadede351ab2007-08-07 18:42:12 -07001954}
1955
Andrew Eikumeec8d512009-06-02 22:34:37 -05001956GpStatus WINGDIPAPI GdipDrawImagePointRect(GpGraphics *graphics, GpImage *image,
1957 REAL x, REAL y, REAL srcx, REAL srcy, REAL srcwidth, REAL srcheight,
1958 GpUnit srcUnit)
1959{
Vincent Povirk94ab2332009-09-04 12:51:48 -05001960 GpPointF points[3];
1961 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
1962
1963 points[0].X = points[2].X = x;
1964 points[0].Y = points[1].Y = y;
1965
1966 /* FIXME: convert image coordinates to Graphics coordinates? */
1967 points[1].X = x + srcwidth;
1968 points[2].Y = y + srcheight;
1969
1970 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
1971 srcwidth, srcheight, srcUnit, NULL, NULL, NULL);
Andrew Eikumeec8d512009-06-02 22:34:37 -05001972}
1973
1974GpStatus WINGDIPAPI GdipDrawImagePointRectI(GpGraphics *graphics, GpImage *image,
1975 INT x, INT y, INT srcx, INT srcy, INT srcwidth, INT srcheight,
1976 GpUnit srcUnit)
1977{
Vincent Povirk94ab2332009-09-04 12:51:48 -05001978 return GdipDrawImagePointRect(graphics, image, x, y, srcx, srcy, srcwidth, srcheight, srcUnit);
Andrew Eikumeec8d512009-06-02 22:34:37 -05001979}
1980
Andrew Eikum156eeb02009-06-03 23:31:21 -05001981GpStatus WINGDIPAPI GdipDrawImagePoints(GpGraphics *graphics, GpImage *image,
1982 GDIPCONST GpPointF *dstpoints, INT count)
1983{
1984 FIXME("(%p, %p, %p, %d): stub\n", graphics, image, dstpoints, count);
1985 return NotImplemented;
1986}
1987
1988GpStatus WINGDIPAPI GdipDrawImagePointsI(GpGraphics *graphics, GpImage *image,
1989 GDIPCONST GpPoint *dstpoints, INT count)
1990{
1991 FIXME("(%p, %p, %p, %d): stub\n", graphics, image, dstpoints, count);
1992 return NotImplemented;
1993}
1994
Evan Stade460f01b2007-07-30 19:09:45 -07001995GpStatus WINGDIPAPI GdipDrawImagePointsRect(GpGraphics *graphics, GpImage *image,
Evan Stadea9c4f302007-07-30 19:10:07 -07001996 GDIPCONST GpPointF *points, INT count, REAL srcx, REAL srcy, REAL srcwidth,
1997 REAL srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
1998 DrawImageAbort callback, VOID * callbackData)
Evan Stade460f01b2007-07-30 19:09:45 -07001999{
Vincent Povirk54339692010-03-28 22:25:20 -05002000 GpPointF ptf[4];
2001 POINT pti[4];
Evan Stade6e0c5742007-07-31 19:16:23 -07002002 REAL dx, dy;
Vincent Povirk54339692010-03-28 22:25:20 -05002003 GpStatus stat;
Evan Stade460f01b2007-07-30 19:09:45 -07002004
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002005 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics, image, points,
2006 count, srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
Evan Stadea9c4f302007-07-30 19:10:07 -07002007 callbackData);
Evan Stade460f01b2007-07-30 19:09:45 -07002008
Nikolay Sivov8cf56082008-04-25 01:58:36 +04002009 if(!graphics || !image || !points || count != 3)
Evan Stadea9c4f302007-07-30 19:10:07 -07002010 return InvalidParameter;
Evan Stade460f01b2007-07-30 19:09:45 -07002011
Vincent Povirk7ded3d82009-12-18 15:45:02 -06002012 TRACE("%s %s %s\n", debugstr_pointf(&points[0]), debugstr_pointf(&points[1]),
2013 debugstr_pointf(&points[2]));
2014
Evan Stadea9c4f302007-07-30 19:10:07 -07002015 memcpy(ptf, points, 3 * sizeof(GpPointF));
Vincent Povirk54339692010-03-28 22:25:20 -05002016 ptf[3].X = ptf[2].X + ptf[1].X - ptf[0].X;
2017 ptf[3].Y = ptf[2].Y + ptf[1].Y - ptf[0].Y;
2018 transform_and_round_points(graphics, pti, ptf, 4);
Evan Stadea9c4f302007-07-30 19:10:07 -07002019
Vincent Povirk436b3be2009-08-28 16:21:27 -05002020 if (image->picture)
2021 {
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05002022 if (!graphics->hdc)
2023 {
2024 FIXME("graphics object has no HDC\n");
2025 }
2026
Vincent Povirk7791f022010-04-15 14:48:47 -05002027 /* FIXME: partially implemented (only works for rectangular parallelograms) */
Vincent Povirk436b3be2009-08-28 16:21:27 -05002028 if(srcUnit == UnitInch)
2029 dx = dy = (REAL) INCH_HIMETRIC;
2030 else if(srcUnit == UnitPixel){
2031 dx = ((REAL) INCH_HIMETRIC) /
2032 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSX));
2033 dy = ((REAL) INCH_HIMETRIC) /
2034 ((REAL) GetDeviceCaps(graphics->hdc, LOGPIXELSY));
2035 }
2036 else
2037 return NotImplemented;
Evan Stade6e0c5742007-07-31 19:16:23 -07002038
Vincent Povirk436b3be2009-08-28 16:21:27 -05002039 if(IPicture_Render(image->picture, graphics->hdc,
2040 pti[0].x, pti[0].y, pti[1].x - pti[0].x, pti[2].y - pti[0].y,
2041 srcx * dx, srcy * dy,
2042 srcwidth * dx, srcheight * dy,
2043 NULL) != S_OK){
2044 if(callback)
2045 callback(callbackData);
2046 return GenericError;
2047 }
2048 }
Vincent Povirk2a345f32010-08-16 14:53:07 -05002049 else if (image->type == ImageTypeBitmap)
Vincent Povirk436b3be2009-08-28 16:21:27 -05002050 {
Vincent Povirk436b3be2009-08-28 16:21:27 -05002051 GpBitmap* bitmap = (GpBitmap*)image;
Vincent Povirk54339692010-03-28 22:25:20 -05002052 int use_software=0;
Vincent Povirk436b3be2009-08-28 16:21:27 -05002053
2054 if (srcUnit == UnitInch)
2055 dx = dy = 96.0; /* FIXME: use the image resolution */
2056 else if (srcUnit == UnitPixel)
2057 dx = dy = 1.0;
2058 else
2059 return NotImplemented;
2060
Vincent Povirk42472472010-04-15 15:24:25 -05002061 if (imageAttributes ||
Vincent Povirk8b2543b2010-04-15 15:26:15 -05002062 (graphics->image && graphics->image->type == ImageTypeBitmap) ||
Vincent Povirk2a345f32010-08-16 14:53:07 -05002063 !((GpBitmap*)image)->hbitmap ||
Vincent Povirk42472472010-04-15 15:24:25 -05002064 ptf[1].Y != ptf[0].Y || ptf[2].X != ptf[0].X)
Vincent Povirk7791f022010-04-15 14:48:47 -05002065 use_software = 1;
Vincent Povirk895c6d82009-08-28 17:21:10 -05002066
Vincent Povirk54339692010-03-28 22:25:20 -05002067 if (use_software)
2068 {
2069 RECT src_area, dst_area;
Vincent Povirk9c380b12010-04-15 14:11:07 -05002070 int i, x, y, stride;
Vincent Povirk54339692010-03-28 22:25:20 -05002071 GpMatrix *dst_to_src;
2072 REAL m11, m12, m21, m22, mdx, mdy;
Vincent Povirk9c380b12010-04-15 14:11:07 -05002073 LPBYTE data;
Vincent Povirk895c6d82009-08-28 17:21:10 -05002074
Vincent Povirk54339692010-03-28 22:25:20 -05002075 src_area.left = srcx*dx;
2076 src_area.top = srcy*dy;
2077 src_area.right = (srcx+srcwidth)*dx;
2078 src_area.bottom = (srcy+srcheight)*dy;
Vincent Povirk895c6d82009-08-28 17:21:10 -05002079
Vincent Povirk54339692010-03-28 22:25:20 -05002080 dst_area.left = dst_area.right = pti[0].x;
2081 dst_area.top = dst_area.bottom = pti[0].y;
2082 for (i=1; i<4; i++)
2083 {
2084 if (dst_area.left > pti[i].x) dst_area.left = pti[i].x;
2085 if (dst_area.right < pti[i].x) dst_area.right = pti[i].x;
2086 if (dst_area.top > pti[i].y) dst_area.top = pti[i].y;
2087 if (dst_area.bottom < pti[i].y) dst_area.bottom = pti[i].y;
2088 }
2089
2090 m11 = (ptf[1].X - ptf[0].X) / srcwidth;
Vincent Povirkbb9c1872010-04-15 15:13:34 -05002091 m21 = (ptf[2].X - ptf[0].X) / srcheight;
2092 mdx = ptf[0].X - m11 * srcx - m21 * srcy;
2093 m12 = (ptf[1].Y - ptf[0].Y) / srcwidth;
Vincent Povirk54339692010-03-28 22:25:20 -05002094 m22 = (ptf[2].Y - ptf[0].Y) / srcheight;
Vincent Povirkbb9c1872010-04-15 15:13:34 -05002095 mdy = ptf[0].Y - m12 * srcx - m22 * srcy;
Vincent Povirk54339692010-03-28 22:25:20 -05002096
2097 stat = GdipCreateMatrix2(m11, m12, m21, m22, mdx, mdy, &dst_to_src);
2098 if (stat != Ok) return stat;
2099
2100 stat = GdipInvertMatrix(dst_to_src);
2101 if (stat != Ok)
2102 {
2103 GdipDeleteMatrix(dst_to_src);
2104 return stat;
2105 }
2106
Vincent Povirk9c380b12010-04-15 14:11:07 -05002107 data = GdipAlloc(sizeof(ARGB) * (dst_area.right - dst_area.left) * (dst_area.bottom - dst_area.top));
2108 if (!data)
2109 {
2110 GdipDeleteMatrix(dst_to_src);
2111 return OutOfMemory;
2112 }
2113
2114 stride = sizeof(ARGB) * (dst_area.right - dst_area.left);
2115
Vincent Povirk0ae0c0c2010-05-08 12:53:07 -05002116 if (imageAttributes &&
2117 (imageAttributes->wrap != WrapModeClamp ||
2118 imageAttributes->outside_color != 0x00000000 ||
2119 imageAttributes->clamp))
2120 {
2121 static int fixme;
2122 if (!fixme++)
2123 FIXME("Image wrap mode not implemented\n");
2124 }
2125
Vincent Povirk54339692010-03-28 22:25:20 -05002126 for (x=dst_area.left; x<dst_area.right; x++)
2127 {
2128 for (y=dst_area.top; y<dst_area.bottom; y++)
2129 {
2130 GpPointF src_pointf;
2131 int src_x, src_y;
Vincent Povirk9c380b12010-04-15 14:11:07 -05002132 ARGB *src_color;
Vincent Povirk54339692010-03-28 22:25:20 -05002133
2134 src_pointf.X = x;
2135 src_pointf.Y = y;
2136
2137 GdipTransformMatrixPoints(dst_to_src, &src_pointf, 1);
2138
2139 src_x = roundr(src_pointf.X);
2140 src_y = roundr(src_pointf.Y);
2141
Vincent Povirk9c380b12010-04-15 14:11:07 -05002142 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2143
Vincent Povirk54339692010-03-28 22:25:20 -05002144 if (src_x < src_area.left || src_x >= src_area.right ||
2145 src_y < src_area.top || src_y >= src_area.bottom)
Vincent Povirk9c380b12010-04-15 14:11:07 -05002146 *src_color = 0;
2147 else
2148 GdipBitmapGetPixel(bitmap, src_x, src_y, src_color);
Vincent Povirk54339692010-03-28 22:25:20 -05002149 }
2150 }
2151
2152 GdipDeleteMatrix(dst_to_src);
Vincent Povirk9c380b12010-04-15 14:11:07 -05002153
Vincent Povirk42472472010-04-15 15:24:25 -05002154 if (imageAttributes)
2155 {
Vincent Povirkede103c2010-04-15 15:31:45 -05002156 if (imageAttributes->colorkeys[ColorAdjustTypeBitmap].enabled ||
2157 imageAttributes->colorkeys[ColorAdjustTypeDefault].enabled)
2158 {
Vincent Povirk15ebd842010-05-08 12:26:02 -05002159 const struct color_key *key;
2160 BYTE min_blue, min_green, min_red;
2161 BYTE max_blue, max_green, max_red;
2162
2163 if (imageAttributes->colorkeys[ColorAdjustTypeBitmap].enabled)
2164 key = &imageAttributes->colorkeys[ColorAdjustTypeBitmap];
2165 else
2166 key = &imageAttributes->colorkeys[ColorAdjustTypeDefault];
2167
2168 min_blue = key->low&0xff;
2169 min_green = (key->low>>8)&0xff;
2170 min_red = (key->low>>16)&0xff;
2171
2172 max_blue = key->high&0xff;
2173 max_green = (key->high>>8)&0xff;
2174 max_red = (key->high>>16)&0xff;
2175
2176 for (x=dst_area.left; x<dst_area.right; x++)
2177 for (y=dst_area.top; y<dst_area.bottom; y++)
2178 {
2179 ARGB *src_color;
2180 BYTE blue, green, red;
2181 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2182 blue = *src_color&0xff;
2183 green = (*src_color>>8)&0xff;
2184 red = (*src_color>>16)&0xff;
2185 if (blue >= min_blue && green >= min_green && red >= min_red &&
2186 blue <= max_blue && green <= max_green && red <= max_red)
2187 *src_color = 0x00000000;
2188 }
Vincent Povirkede103c2010-04-15 15:31:45 -05002189 }
2190
Vincent Povirk42472472010-04-15 15:24:25 -05002191 if (imageAttributes->colorremaptables[ColorAdjustTypeBitmap].enabled ||
2192 imageAttributes->colorremaptables[ColorAdjustTypeDefault].enabled)
2193 {
2194 const struct color_remap_table *table;
2195
2196 if (imageAttributes->colorremaptables[ColorAdjustTypeBitmap].enabled)
2197 table = &imageAttributes->colorremaptables[ColorAdjustTypeBitmap];
2198 else
2199 table = &imageAttributes->colorremaptables[ColorAdjustTypeDefault];
2200
2201 for (x=dst_area.left; x<dst_area.right; x++)
2202 for (y=dst_area.top; y<dst_area.bottom; y++)
2203 {
2204 ARGB *src_color;
2205 src_color = (ARGB*)(data + stride * (y - dst_area.top) + sizeof(ARGB) * (x - dst_area.left));
2206 for (i=0; i<table->mapsize; i++)
2207 {
2208 if (*src_color == table->colormap[i].oldColor.Argb)
2209 {
2210 *src_color = table->colormap[i].newColor.Argb;
2211 break;
2212 }
2213 }
2214 }
2215 }
Vincent Povirkede103c2010-04-15 15:31:45 -05002216
2217 if (imageAttributes->colormatrices[ColorAdjustTypeBitmap].enabled ||
2218 imageAttributes->colormatrices[ColorAdjustTypeDefault].enabled)
2219 {
2220 static int fixme;
2221 if (!fixme++)
2222 FIXME("Color transforms not implemented\n");
2223 }
2224
2225 if (imageAttributes->gamma_enabled[ColorAdjustTypeBitmap] ||
2226 imageAttributes->gamma_enabled[ColorAdjustTypeDefault])
2227 {
2228 static int fixme;
2229 if (!fixme++)
2230 FIXME("Gamma adjustment not implemented\n");
2231 }
Vincent Povirk42472472010-04-15 15:24:25 -05002232 }
2233
Vincent Povirk9c380b12010-04-15 14:11:07 -05002234 stat = alpha_blend_pixels(graphics, dst_area.left, dst_area.top,
2235 data, dst_area.right - dst_area.left, dst_area.bottom - dst_area.top, stride);
2236
2237 GdipFree(data);
2238
2239 return stat;
Vincent Povirk54339692010-03-28 22:25:20 -05002240 }
2241 else
2242 {
2243 HDC hdc;
2244 int temp_hdc=0, temp_bitmap=0;
2245 HBITMAP hbitmap, old_hbm=NULL;
2246
2247 if (!(bitmap->format == PixelFormat16bppRGB555 ||
2248 bitmap->format == PixelFormat24bppRGB ||
2249 bitmap->format == PixelFormat32bppRGB ||
2250 bitmap->format == PixelFormat32bppPARGB))
2251 {
2252 BITMAPINFOHEADER bih;
2253 BYTE *temp_bits;
2254 PixelFormat dst_format;
2255
2256 /* we can't draw a bitmap of this format directly */
2257 hdc = CreateCompatibleDC(0);
2258 temp_hdc = 1;
2259 temp_bitmap = 1;
2260
2261 bih.biSize = sizeof(BITMAPINFOHEADER);
2262 bih.biWidth = bitmap->width;
2263 bih.biHeight = -bitmap->height;
2264 bih.biPlanes = 1;
2265 bih.biBitCount = 32;
2266 bih.biCompression = BI_RGB;
2267 bih.biSizeImage = 0;
2268 bih.biXPelsPerMeter = 0;
2269 bih.biYPelsPerMeter = 0;
2270 bih.biClrUsed = 0;
2271 bih.biClrImportant = 0;
2272
2273 hbitmap = CreateDIBSection(hdc, (BITMAPINFO*)&bih, DIB_RGB_COLORS,
2274 (void**)&temp_bits, NULL, 0);
2275
2276 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
2277 dst_format = PixelFormat32bppPARGB;
2278 else
2279 dst_format = PixelFormat32bppRGB;
2280
2281 convert_pixels(bitmap->width, bitmap->height,
2282 bitmap->width*4, temp_bits, dst_format,
2283 bitmap->stride, bitmap->bits, bitmap->format, bitmap->image.palette_entries);
2284 }
2285 else
2286 {
2287 hbitmap = bitmap->hbitmap;
2288 hdc = bitmap->hdc;
2289 temp_hdc = (hdc == 0);
2290 }
2291
2292 if (temp_hdc)
2293 {
2294 if (!hdc) hdc = CreateCompatibleDC(0);
2295 old_hbm = SelectObject(hdc, hbitmap);
2296 }
Vincent Povirk895c6d82009-08-28 17:21:10 -05002297
Vincent Povirk00dec582010-02-05 13:48:36 -06002298 if (bitmap->format & (PixelFormatAlpha|PixelFormatPAlpha))
Vincent Povirk54339692010-03-28 22:25:20 -05002299 {
2300 BLENDFUNCTION bf;
2301
2302 bf.BlendOp = AC_SRC_OVER;
2303 bf.BlendFlags = 0;
2304 bf.SourceConstantAlpha = 255;
2305 bf.AlphaFormat = AC_SRC_ALPHA;
2306
2307 GdiAlphaBlend(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
2308 hdc, srcx*dx, srcy*dy, srcwidth*dx, srcheight*dy, bf);
2309 }
Vincent Povirk00dec582010-02-05 13:48:36 -06002310 else
Vincent Povirk54339692010-03-28 22:25:20 -05002311 {
2312 StretchBlt(graphics->hdc, pti[0].x, pti[0].y, pti[1].x-pti[0].x, pti[2].y-pti[0].y,
2313 hdc, srcx*dx, srcy*dy, srcwidth*dx, srcheight*dy, SRCCOPY);
2314 }
Vincent Povirk00dec582010-02-05 13:48:36 -06002315
Vincent Povirk54339692010-03-28 22:25:20 -05002316 if (temp_hdc)
2317 {
2318 SelectObject(hdc, old_hbm);
2319 DeleteDC(hdc);
2320 }
2321
2322 if (temp_bitmap)
2323 DeleteObject(hbitmap);
Vincent Povirk895c6d82009-08-28 17:21:10 -05002324 }
Vincent Povirk436b3be2009-08-28 16:21:27 -05002325 }
2326 else
2327 {
2328 ERR("GpImage with no IPicture or HBITMAP?!\n");
2329 return NotImplemented;
Evan Stadea9c4f302007-07-30 19:10:07 -07002330 }
2331
2332 return Ok;
Evan Stade460f01b2007-07-30 19:09:45 -07002333}
2334
Nikolay Sivov79b49a82008-04-29 00:10:05 +04002335GpStatus WINGDIPAPI GdipDrawImagePointsRectI(GpGraphics *graphics, GpImage *image,
2336 GDIPCONST GpPoint *points, INT count, INT srcx, INT srcy, INT srcwidth,
2337 INT srcheight, GpUnit srcUnit, GDIPCONST GpImageAttributes* imageAttributes,
2338 DrawImageAbort callback, VOID * callbackData)
2339{
2340 GpPointF pointsF[3];
2341 INT i;
2342
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002343 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics, image, points, count,
2344 srcx, srcy, srcwidth, srcheight, srcUnit, imageAttributes, callback,
2345 callbackData);
2346
Nikolay Sivov79b49a82008-04-29 00:10:05 +04002347 if(!points || count!=3)
2348 return InvalidParameter;
2349
2350 for(i = 0; i < count; i++){
2351 pointsF[i].X = (REAL)points[i].X;
2352 pointsF[i].Y = (REAL)points[i].Y;
2353 }
2354
2355 return GdipDrawImagePointsRect(graphics, image, pointsF, count, (REAL)srcx, (REAL)srcy,
2356 (REAL)srcwidth, (REAL)srcheight, srcUnit, imageAttributes,
2357 callback, callbackData);
2358}
2359
Evan Stade04d4c262007-08-09 18:25:09 -07002360GpStatus WINGDIPAPI GdipDrawImageRectRect(GpGraphics *graphics, GpImage *image,
2361 REAL dstx, REAL dsty, REAL dstwidth, REAL dstheight, REAL srcx, REAL srcy,
2362 REAL srcwidth, REAL srcheight, GpUnit srcUnit,
2363 GDIPCONST GpImageAttributes* imageattr, DrawImageAbort callback,
2364 VOID * callbackData)
2365{
2366 GpPointF points[3];
2367
Francois Gouget758c4532008-09-05 13:14:56 +02002368 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002369 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
2370 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
2371
Evan Stade04d4c262007-08-09 18:25:09 -07002372 points[0].X = dstx;
2373 points[0].Y = dsty;
2374 points[1].X = dstx + dstwidth;
2375 points[1].Y = dsty;
2376 points[2].X = dstx;
2377 points[2].Y = dsty + dstheight;
2378
2379 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2380 srcwidth, srcheight, srcUnit, imageattr, callback, callbackData);
2381}
2382
Jon Yang29bc9ba2008-02-28 21:54:47 -08002383GpStatus WINGDIPAPI GdipDrawImageRectRectI(GpGraphics *graphics, GpImage *image,
2384 INT dstx, INT dsty, INT dstwidth, INT dstheight, INT srcx, INT srcy,
2385 INT srcwidth, INT srcheight, GpUnit srcUnit,
2386 GDIPCONST GpImageAttributes* imageAttributes, DrawImageAbort callback,
2387 VOID * callbackData)
2388{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002389 GpPointF points[3];
2390
Francois Gouget758c4532008-09-05 13:14:56 +02002391 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002392 graphics, image, dstx, dsty, dstwidth, dstheight, srcx, srcy,
2393 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
Jon Yang29bc9ba2008-02-28 21:54:47 -08002394
2395 points[0].X = dstx;
2396 points[0].Y = dsty;
2397 points[1].X = dstx + dstwidth;
2398 points[1].Y = dsty;
2399 points[2].X = dstx;
2400 points[2].Y = dsty + dstheight;
2401
2402 return GdipDrawImagePointsRect(graphics, image, points, 3, srcx, srcy,
2403 srcwidth, srcheight, srcUnit, imageAttributes, callback, callbackData);
2404}
2405
Nikolay Sivov8cf56082008-04-25 01:58:36 +04002406GpStatus WINGDIPAPI GdipDrawImageRect(GpGraphics *graphics, GpImage *image,
2407 REAL x, REAL y, REAL width, REAL height)
2408{
2409 RectF bounds;
2410 GpUnit unit;
2411 GpStatus ret;
2412
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002413 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, image, x, y, width, height);
2414
Nikolay Sivov8cf56082008-04-25 01:58:36 +04002415 if(!graphics || !image)
2416 return InvalidParameter;
2417
2418 ret = GdipGetImageBounds(image, &bounds, &unit);
2419 if(ret != Ok)
2420 return ret;
2421
2422 return GdipDrawImageRectRect(graphics, image, x, y, width, height,
2423 bounds.X, bounds.Y, bounds.Width, bounds.Height,
2424 unit, NULL, NULL, NULL);
2425}
2426
2427GpStatus WINGDIPAPI GdipDrawImageRectI(GpGraphics *graphics, GpImage *image,
2428 INT x, INT y, INT width, INT height)
2429{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002430 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, image, x, y, width, height);
2431
Nikolay Sivov8cf56082008-04-25 01:58:36 +04002432 return GdipDrawImageRect(graphics, image, (REAL)x, (REAL)y, (REAL)width, (REAL)height);
2433}
2434
Evan Stade5e29e372007-08-01 17:55:58 -07002435GpStatus WINGDIPAPI GdipDrawLine(GpGraphics *graphics, GpPen *pen, REAL x1,
2436 REAL y1, REAL x2, REAL y2)
2437{
2438 INT save_state;
2439 GpPointF pt[2];
2440 GpStatus retval;
2441
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002442 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x1, y1, x2, y2);
2443
Evan Stade5e29e372007-08-01 17:55:58 -07002444 if(!pen || !graphics)
2445 return InvalidParameter;
2446
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002447 if(graphics->busy)
2448 return ObjectBusy;
2449
Evan Stade5e29e372007-08-01 17:55:58 -07002450 pt[0].X = x1;
2451 pt[0].Y = y1;
2452 pt[1].X = x2;
2453 pt[1].Y = y2;
2454
2455 save_state = prepare_dc(graphics, pen);
2456
2457 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
2458
2459 restore_dc(graphics, save_state);
2460
2461 return retval;
2462}
2463
Evan Stade2689b182007-06-12 10:44:31 -07002464GpStatus WINGDIPAPI GdipDrawLineI(GpGraphics *graphics, GpPen *pen, INT x1,
2465 INT y1, INT x2, INT y2)
2466{
Evan Staded9ef1722007-07-02 15:13:05 -07002467 INT save_state;
Evan Stade5128e5d2007-07-07 13:20:41 -07002468 GpPointF pt[2];
Evan Stade6f4ab522007-07-11 18:07:44 -07002469 GpStatus retval;
Evan Stade2689b182007-06-12 10:44:31 -07002470
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002471 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x1, y1, x2, y2);
2472
Evan Stade2689b182007-06-12 10:44:31 -07002473 if(!pen || !graphics)
2474 return InvalidParameter;
2475
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002476 if(graphics->busy)
2477 return ObjectBusy;
2478
Evan Stade5128e5d2007-07-07 13:20:41 -07002479 pt[0].X = (REAL)x1;
2480 pt[0].Y = (REAL)y1;
2481 pt[1].X = (REAL)x2;
2482 pt[1].Y = (REAL)y2;
2483
Evan Stade4c424b32007-07-24 17:18:54 -07002484 save_state = prepare_dc(graphics, pen);
Evan Staded9ef1722007-07-02 15:13:05 -07002485
Evan Staded01c6972007-07-23 20:24:53 -07002486 retval = draw_polyline(graphics, pen, pt, 2, TRUE);
Evan Staded9ef1722007-07-02 15:13:05 -07002487
Evan Stade4c424b32007-07-24 17:18:54 -07002488 restore_dc(graphics, save_state);
Evan Stade2689b182007-06-12 10:44:31 -07002489
Evan Stade6f4ab522007-07-11 18:07:44 -07002490 return retval;
Evan Stade2689b182007-06-12 10:44:31 -07002491}
Evan Stade4b9bfbe2007-06-12 10:51:20 -07002492
Evan Stadef6f04f62007-06-21 16:15:13 -07002493GpStatus WINGDIPAPI GdipDrawLines(GpGraphics *graphics, GpPen *pen, GDIPCONST
2494 GpPointF *points, INT count)
2495{
Evan Stade852aac82007-07-11 18:07:16 -07002496 INT save_state;
Evan Stade6f4ab522007-07-11 18:07:44 -07002497 GpStatus retval;
Evan Stadef6f04f62007-06-21 16:15:13 -07002498
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002499 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2500
Evan Stadef6f04f62007-06-21 16:15:13 -07002501 if(!pen || !graphics || (count < 2))
2502 return InvalidParameter;
2503
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002504 if(graphics->busy)
2505 return ObjectBusy;
2506
Evan Stade4c424b32007-07-24 17:18:54 -07002507 save_state = prepare_dc(graphics, pen);
Evan Stadef6f04f62007-06-21 16:15:13 -07002508
Evan Staded01c6972007-07-23 20:24:53 -07002509 retval = draw_polyline(graphics, pen, points, count, TRUE);
Evan Stadef6f04f62007-06-21 16:15:13 -07002510
Evan Stade4c424b32007-07-24 17:18:54 -07002511 restore_dc(graphics, save_state);
Evan Stadef6f04f62007-06-21 16:15:13 -07002512
Evan Stade6f4ab522007-07-11 18:07:44 -07002513 return retval;
Evan Stadef6f04f62007-06-21 16:15:13 -07002514}
2515
Royal Chan6e7b5342008-02-29 04:58:39 -08002516GpStatus WINGDIPAPI GdipDrawLinesI(GpGraphics *graphics, GpPen *pen, GDIPCONST
2517 GpPoint *points, INT count)
2518{
2519 INT save_state;
2520 GpStatus retval;
2521 GpPointF *ptf = NULL;
2522 int i;
2523
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002524 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
2525
Royal Chan6e7b5342008-02-29 04:58:39 -08002526 if(!pen || !graphics || (count < 2))
2527 return InvalidParameter;
2528
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002529 if(graphics->busy)
2530 return ObjectBusy;
2531
Royal Chan6e7b5342008-02-29 04:58:39 -08002532 ptf = GdipAlloc(count * sizeof(GpPointF));
2533 if(!ptf) return OutOfMemory;
2534
2535 for(i = 0; i < count; i ++){
2536 ptf[i].X = (REAL) points[i].X;
2537 ptf[i].Y = (REAL) points[i].Y;
2538 }
2539
2540 save_state = prepare_dc(graphics, pen);
2541
2542 retval = draw_polyline(graphics, pen, ptf, count, TRUE);
2543
2544 restore_dc(graphics, save_state);
2545
2546 GdipFree(ptf);
2547 return retval;
2548}
2549
Evan Stade9d5f5682007-07-11 18:07:34 -07002550GpStatus WINGDIPAPI GdipDrawPath(GpGraphics *graphics, GpPen *pen, GpPath *path)
2551{
Evan Stade9e883472007-07-13 17:51:49 -07002552 INT save_state;
Evan Stade9d5f5682007-07-11 18:07:34 -07002553 GpStatus retval;
2554
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002555 TRACE("(%p, %p, %p)\n", graphics, pen, path);
2556
Evan Stade9d5f5682007-07-11 18:07:34 -07002557 if(!pen || !graphics)
2558 return InvalidParameter;
2559
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002560 if(graphics->busy)
2561 return ObjectBusy;
2562
Evan Stade4c424b32007-07-24 17:18:54 -07002563 save_state = prepare_dc(graphics, pen);
Evan Stade9d5f5682007-07-11 18:07:34 -07002564
Evan Staded01c6972007-07-23 20:24:53 -07002565 retval = draw_poly(graphics, pen, path->pathdata.Points,
Evan Stade9e883472007-07-13 17:51:49 -07002566 path->pathdata.Types, path->pathdata.Count, TRUE);
Evan Stade9d5f5682007-07-11 18:07:34 -07002567
Evan Stade4c424b32007-07-24 17:18:54 -07002568 restore_dc(graphics, save_state);
Evan Stade9d5f5682007-07-11 18:07:34 -07002569
2570 return retval;
2571}
2572
Evan Stade72ab72c502007-06-18 16:55:51 -07002573GpStatus WINGDIPAPI GdipDrawPie(GpGraphics *graphics, GpPen *pen, REAL x,
2574 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2575{
Evan Stade4c424b32007-07-24 17:18:54 -07002576 INT save_state;
2577
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002578 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y,
2579 width, height, startAngle, sweepAngle);
2580
Evan Stade4c424b32007-07-24 17:18:54 -07002581 if(!graphics || !pen)
Evan Stade72ab72c502007-06-18 16:55:51 -07002582 return InvalidParameter;
2583
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002584 if(graphics->busy)
2585 return ObjectBusy;
2586
Evan Stade4c424b32007-07-24 17:18:54 -07002587 save_state = prepare_dc(graphics, pen);
2588 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2589
2590 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
2591
2592 restore_dc(graphics, save_state);
2593
2594 return Ok;
Evan Stade72ab72c502007-06-18 16:55:51 -07002595}
2596
Nikolay Sivov71931612008-04-24 20:48:00 +04002597GpStatus WINGDIPAPI GdipDrawPieI(GpGraphics *graphics, GpPen *pen, INT x,
2598 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2599{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002600 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics, pen, x, y,
2601 width, height, startAngle, sweepAngle);
2602
Nikolay Sivov71931612008-04-24 20:48:00 +04002603 return GdipDrawPie(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2604}
2605
Nikolay Sivov172389e2008-04-20 21:27:10 +04002606GpStatus WINGDIPAPI GdipDrawRectangle(GpGraphics *graphics, GpPen *pen, REAL x,
2607 REAL y, REAL width, REAL height)
Evan Stade4b9bfbe2007-06-12 10:51:20 -07002608{
Evan Stade14e0df12007-07-09 20:54:18 -07002609 INT save_state;
Evan Stadec84c2042007-08-07 18:43:08 -07002610 GpPointF ptf[4];
2611 POINT pti[4];
Evan Stade4b9bfbe2007-06-12 10:51:20 -07002612
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002613 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, pen, x, y, width, height);
2614
Evan Stade4b9bfbe2007-06-12 10:51:20 -07002615 if(!pen || !graphics)
2616 return InvalidParameter;
2617
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002618 if(graphics->busy)
2619 return ObjectBusy;
2620
Evan Stadec84c2042007-08-07 18:43:08 -07002621 ptf[0].X = x;
2622 ptf[0].Y = y;
2623 ptf[1].X = x + width;
2624 ptf[1].Y = y;
2625 ptf[2].X = x + width;
2626 ptf[2].Y = y + height;
2627 ptf[3].X = x;
2628 ptf[3].Y = y + height;
2629
Evan Stade4c424b32007-07-24 17:18:54 -07002630 save_state = prepare_dc(graphics, pen);
Evan Stade14e0df12007-07-09 20:54:18 -07002631 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
Evan Stade4b9bfbe2007-06-12 10:51:20 -07002632
Evan Stadec84c2042007-08-07 18:43:08 -07002633 transform_and_round_points(graphics, pti, ptf, 4);
2634 Polygon(graphics->hdc, pti, 4);
Evan Stade4b9bfbe2007-06-12 10:51:20 -07002635
Evan Stade4c424b32007-07-24 17:18:54 -07002636 restore_dc(graphics, save_state);
Evan Stade4b9bfbe2007-06-12 10:51:20 -07002637
2638 return Ok;
2639}
Evan Stade72ab72c502007-06-18 16:55:51 -07002640
Nikolay Sivov172389e2008-04-20 21:27:10 +04002641GpStatus WINGDIPAPI GdipDrawRectangleI(GpGraphics *graphics, GpPen *pen, INT x,
2642 INT y, INT width, INT height)
2643{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002644 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, pen, x, y, width, height);
2645
Nikolay Sivov172389e2008-04-20 21:27:10 +04002646 return GdipDrawRectangle(graphics,pen,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2647}
2648
Evan Stade9d6e0752007-08-13 18:34:46 -07002649GpStatus WINGDIPAPI GdipDrawRectangles(GpGraphics *graphics, GpPen *pen,
Francois Gougetb6b97b12007-08-29 21:42:01 +02002650 GDIPCONST GpRectF* rects, INT count)
Evan Stade9d6e0752007-08-13 18:34:46 -07002651{
2652 GpPointF *ptf;
2653 POINT *pti;
2654 INT save_state, i;
2655
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002656 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
2657
Evan Stade9d6e0752007-08-13 18:34:46 -07002658 if(!graphics || !pen || !rects || count < 1)
2659 return InvalidParameter;
2660
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002661 if(graphics->busy)
2662 return ObjectBusy;
2663
Evan Stade9d6e0752007-08-13 18:34:46 -07002664 ptf = GdipAlloc(4 * count * sizeof(GpPointF));
2665 pti = GdipAlloc(4 * count * sizeof(POINT));
2666
2667 if(!ptf || !pti){
2668 GdipFree(ptf);
2669 GdipFree(pti);
2670 return OutOfMemory;
2671 }
2672
2673 for(i = 0; i < count; i++){
2674 ptf[4 * i + 3].X = ptf[4 * i].X = rects[i].X;
2675 ptf[4 * i + 1].Y = ptf[4 * i].Y = rects[i].Y;
2676 ptf[4 * i + 2].X = ptf[4 * i + 1].X = rects[i].X + rects[i].Width;
2677 ptf[4 * i + 3].Y = ptf[4 * i + 2].Y = rects[i].Y + rects[i].Height;
2678 }
2679
2680 save_state = prepare_dc(graphics, pen);
2681 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
2682
2683 transform_and_round_points(graphics, pti, ptf, 4 * count);
2684
2685 for(i = 0; i < count; i++)
2686 Polygon(graphics->hdc, &pti[4 * i], 4);
2687
2688 restore_dc(graphics, save_state);
2689
2690 GdipFree(ptf);
2691 GdipFree(pti);
2692
2693 return Ok;
2694}
2695
Nikolay Sivov3903ac62008-04-24 20:48:08 +04002696GpStatus WINGDIPAPI GdipDrawRectanglesI(GpGraphics *graphics, GpPen *pen,
2697 GDIPCONST GpRect* rects, INT count)
2698{
2699 GpRectF *rectsF;
2700 GpStatus ret;
2701 INT i;
2702
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002703 TRACE("(%p, %p, %p, %d)\n", graphics, pen, rects, count);
2704
Nikolay Sivov3903ac62008-04-24 20:48:08 +04002705 if(!rects || count<=0)
2706 return InvalidParameter;
2707
2708 rectsF = GdipAlloc(sizeof(GpRectF) * count);
2709 if(!rectsF)
2710 return OutOfMemory;
2711
2712 for(i = 0;i < count;i++){
2713 rectsF[i].X = (REAL)rects[i].X;
2714 rectsF[i].Y = (REAL)rects[i].Y;
2715 rectsF[i].Width = (REAL)rects[i].Width;
2716 rectsF[i].Height = (REAL)rects[i].Height;
2717 }
2718
2719 ret = GdipDrawRectangles(graphics, pen, rectsF, count);
2720 GdipFree(rectsF);
2721
2722 return ret;
2723}
2724
Nikolay Sivov4a441002008-08-22 02:16:49 +04002725GpStatus WINGDIPAPI GdipFillClosedCurve2(GpGraphics *graphics, GpBrush *brush,
2726 GDIPCONST GpPointF *points, INT count, REAL tension, GpFillMode fill)
2727{
2728 GpPath *path;
2729 GpStatus stat;
2730
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002731 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2732 count, tension, fill);
2733
Nikolay Sivov4a441002008-08-22 02:16:49 +04002734 if(!graphics || !brush || !points)
2735 return InvalidParameter;
2736
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002737 if(graphics->busy)
2738 return ObjectBusy;
2739
Wade Gobelf4e2af62010-07-26 09:21:40 -05002740 if(count == 1) /* Do nothing */
2741 return Ok;
2742
Nikolay Sivov4a441002008-08-22 02:16:49 +04002743 stat = GdipCreatePath(fill, &path);
2744 if(stat != Ok)
2745 return stat;
2746
2747 stat = GdipAddPathClosedCurve2(path, points, count, tension);
2748 if(stat != Ok){
2749 GdipDeletePath(path);
2750 return stat;
2751 }
2752
2753 stat = GdipFillPath(graphics, brush, path);
2754 if(stat != Ok){
2755 GdipDeletePath(path);
2756 return stat;
2757 }
2758
2759 GdipDeletePath(path);
2760
2761 return Ok;
2762}
2763
2764GpStatus WINGDIPAPI GdipFillClosedCurve2I(GpGraphics *graphics, GpBrush *brush,
2765 GDIPCONST GpPoint *points, INT count, REAL tension, GpFillMode fill)
2766{
2767 GpPointF *ptf;
2768 GpStatus stat;
2769 INT i;
2770
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002771 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics, brush, points,
2772 count, tension, fill);
2773
Wade Gobelf4e2af62010-07-26 09:21:40 -05002774 if(!points || count == 0)
Nikolay Sivov4a441002008-08-22 02:16:49 +04002775 return InvalidParameter;
2776
Wade Gobelf4e2af62010-07-26 09:21:40 -05002777 if(count == 1) /* Do nothing */
2778 return Ok;
2779
Nikolay Sivov4a441002008-08-22 02:16:49 +04002780 ptf = GdipAlloc(sizeof(GpPointF)*count);
2781 if(!ptf)
2782 return OutOfMemory;
2783
2784 for(i = 0;i < count;i++){
2785 ptf[i].X = (REAL)points[i].X;
2786 ptf[i].Y = (REAL)points[i].Y;
2787 }
2788
2789 stat = GdipFillClosedCurve2(graphics, brush, ptf, count, tension, fill);
2790
2791 GdipFree(ptf);
2792
2793 return stat;
2794}
2795
Wade Gobelcceb3dc2010-07-26 09:21:50 -05002796GpStatus WINGDIPAPI GdipFillClosedCurve(GpGraphics *graphics, GpBrush *brush,
2797 GDIPCONST GpPointF *points, INT count)
2798{
2799 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
2800 return GdipFillClosedCurve2(graphics, brush, points, count,
2801 0.5f, FillModeAlternate);
2802}
2803
2804GpStatus WINGDIPAPI GdipFillClosedCurveI(GpGraphics *graphics, GpBrush *brush,
2805 GDIPCONST GpPoint *points, INT count)
2806{
2807 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
2808 return GdipFillClosedCurve2I(graphics, brush, points, count,
2809 0.5f, FillModeAlternate);
2810}
2811
Nikolay Sivovfc2dc8b2008-04-29 00:10:10 +04002812GpStatus WINGDIPAPI GdipFillEllipse(GpGraphics *graphics, GpBrush *brush, REAL x,
2813 REAL y, REAL width, REAL height)
2814{
2815 INT save_state;
2816 GpPointF ptf[2];
2817 POINT pti[2];
2818
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002819 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
2820
Nikolay Sivovfc2dc8b2008-04-29 00:10:10 +04002821 if(!graphics || !brush)
2822 return InvalidParameter;
2823
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002824 if(graphics->busy)
2825 return ObjectBusy;
2826
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05002827 if(!graphics->hdc)
2828 {
2829 FIXME("graphics object has no HDC\n");
2830 return Ok;
2831 }
2832
Nikolay Sivovfc2dc8b2008-04-29 00:10:10 +04002833 ptf[0].X = x;
2834 ptf[0].Y = y;
2835 ptf[1].X = x + width;
2836 ptf[1].Y = y + height;
2837
2838 save_state = SaveDC(graphics->hdc);
2839 EndPath(graphics->hdc);
Nikolay Sivovfc2dc8b2008-04-29 00:10:10 +04002840
2841 transform_and_round_points(graphics, pti, ptf, 2);
2842
Vincent Povirke3063162009-07-11 10:29:44 -05002843 BeginPath(graphics->hdc);
Nikolay Sivovfc2dc8b2008-04-29 00:10:10 +04002844 Ellipse(graphics->hdc, pti[0].x, pti[0].y, pti[1].x, pti[1].y);
Vincent Povirke3063162009-07-11 10:29:44 -05002845 EndPath(graphics->hdc);
2846
2847 brush_fill_path(graphics, brush);
Nikolay Sivovfc2dc8b2008-04-29 00:10:10 +04002848
2849 RestoreDC(graphics->hdc, save_state);
2850
2851 return Ok;
2852}
2853
2854GpStatus WINGDIPAPI GdipFillEllipseI(GpGraphics *graphics, GpBrush *brush, INT x,
2855 INT y, INT width, INT height)
2856{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002857 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
2858
Nikolay Sivovfc2dc8b2008-04-29 00:10:10 +04002859 return GdipFillEllipse(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height);
2860}
2861
Evan Staded362b582007-07-13 20:19:46 -07002862GpStatus WINGDIPAPI GdipFillPath(GpGraphics *graphics, GpBrush *brush, GpPath *path)
2863{
2864 INT save_state;
2865 GpStatus retval;
2866
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002867 TRACE("(%p, %p, %p)\n", graphics, brush, path);
2868
Evan Staded362b582007-07-13 20:19:46 -07002869 if(!brush || !graphics || !path)
2870 return InvalidParameter;
2871
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002872 if(graphics->busy)
2873 return ObjectBusy;
2874
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05002875 if(!graphics->hdc)
2876 {
2877 FIXME("graphics object has no HDC\n");
2878 return Ok;
2879 }
2880
Evan Staded362b582007-07-13 20:19:46 -07002881 save_state = SaveDC(graphics->hdc);
2882 EndPath(graphics->hdc);
Evan Staded362b582007-07-13 20:19:46 -07002883 SetPolyFillMode(graphics->hdc, (path->fill == FillModeAlternate ? ALTERNATE
2884 : WINDING));
2885
2886 BeginPath(graphics->hdc);
Evan Staded01c6972007-07-23 20:24:53 -07002887 retval = draw_poly(graphics, NULL, path->pathdata.Points,
Evan Staded362b582007-07-13 20:19:46 -07002888 path->pathdata.Types, path->pathdata.Count, FALSE);
2889
2890 if(retval != Ok)
2891 goto end;
2892
2893 EndPath(graphics->hdc);
Vincent Povirk68dba4e2009-03-16 12:51:04 -05002894 brush_fill_path(graphics, brush);
Evan Staded362b582007-07-13 20:19:46 -07002895
2896 retval = Ok;
2897
2898end:
2899 RestoreDC(graphics->hdc, save_state);
2900
2901 return retval;
2902}
2903
Evan Stade72ab72c502007-06-18 16:55:51 -07002904GpStatus WINGDIPAPI GdipFillPie(GpGraphics *graphics, GpBrush *brush, REAL x,
2905 REAL y, REAL width, REAL height, REAL startAngle, REAL sweepAngle)
2906{
Evan Stade4c424b32007-07-24 17:18:54 -07002907 INT save_state;
2908
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002909 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2910 graphics, brush, x, y, width, height, startAngle, sweepAngle);
2911
Evan Stade4c424b32007-07-24 17:18:54 -07002912 if(!graphics || !brush)
Evan Stade72ab72c502007-06-18 16:55:51 -07002913 return InvalidParameter;
2914
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002915 if(graphics->busy)
2916 return ObjectBusy;
2917
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05002918 if(!graphics->hdc)
2919 {
2920 FIXME("graphics object has no HDC\n");
2921 return Ok;
2922 }
2923
Evan Stade4c424b32007-07-24 17:18:54 -07002924 save_state = SaveDC(graphics->hdc);
2925 EndPath(graphics->hdc);
Evan Stade4c424b32007-07-24 17:18:54 -07002926
Vincent Povirkbedbd402009-07-11 10:32:34 -05002927 BeginPath(graphics->hdc);
Evan Stade4c424b32007-07-24 17:18:54 -07002928 draw_pie(graphics, x, y, width, height, startAngle, sweepAngle);
Vincent Povirkbedbd402009-07-11 10:32:34 -05002929 EndPath(graphics->hdc);
2930
2931 brush_fill_path(graphics, brush);
Evan Stade4c424b32007-07-24 17:18:54 -07002932
2933 RestoreDC(graphics->hdc, save_state);
2934
2935 return Ok;
Evan Stade72ab72c502007-06-18 16:55:51 -07002936}
Evan Stade53e17d22007-07-13 17:51:13 -07002937
Nikolay Sivov2c059d72008-04-24 20:48:23 +04002938GpStatus WINGDIPAPI GdipFillPieI(GpGraphics *graphics, GpBrush *brush, INT x,
2939 INT y, INT width, INT height, REAL startAngle, REAL sweepAngle)
2940{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002941 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2942 graphics, brush, x, y, width, height, startAngle, sweepAngle);
2943
Nikolay Sivov2c059d72008-04-24 20:48:23 +04002944 return GdipFillPie(graphics,brush,(REAL)x,(REAL)y,(REAL)width,(REAL)height,startAngle,sweepAngle);
2945}
2946
Evan Stade1ef77932007-08-01 17:55:50 -07002947GpStatus WINGDIPAPI GdipFillPolygon(GpGraphics *graphics, GpBrush *brush,
2948 GDIPCONST GpPointF *points, INT count, GpFillMode fillMode)
2949{
2950 INT save_state;
2951 GpPointF *ptf = NULL;
2952 POINT *pti = NULL;
2953 GpStatus retval = Ok;
2954
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04002955 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
2956
Evan Stade1ef77932007-08-01 17:55:50 -07002957 if(!graphics || !brush || !points || !count)
2958 return InvalidParameter;
2959
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04002960 if(graphics->busy)
2961 return ObjectBusy;
2962
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05002963 if(!graphics->hdc)
2964 {
2965 FIXME("graphics object has no HDC\n");
2966 return Ok;
2967 }
2968
Evan Stade1ef77932007-08-01 17:55:50 -07002969 ptf = GdipAlloc(count * sizeof(GpPointF));
2970 pti = GdipAlloc(count * sizeof(POINT));
2971 if(!ptf || !pti){
2972 retval = OutOfMemory;
2973 goto end;
2974 }
2975
2976 memcpy(ptf, points, count * sizeof(GpPointF));
2977
2978 save_state = SaveDC(graphics->hdc);
2979 EndPath(graphics->hdc);
Evan Stade1ef77932007-08-01 17:55:50 -07002980 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
2981 : WINDING));
2982
2983 transform_and_round_points(graphics, pti, ptf, count);
Vincent Povirk15fef072009-07-11 10:35:40 -05002984
2985 BeginPath(graphics->hdc);
Evan Stade1ef77932007-08-01 17:55:50 -07002986 Polygon(graphics->hdc, pti, count);
Vincent Povirk15fef072009-07-11 10:35:40 -05002987 EndPath(graphics->hdc);
2988
2989 brush_fill_path(graphics, brush);
Evan Stade1ef77932007-08-01 17:55:50 -07002990
2991 RestoreDC(graphics->hdc, save_state);
2992
2993end:
2994 GdipFree(ptf);
2995 GdipFree(pti);
2996
2997 return retval;
2998}
2999
Evan Stade64675262007-07-23 20:24:35 -07003000GpStatus WINGDIPAPI GdipFillPolygonI(GpGraphics *graphics, GpBrush *brush,
3001 GDIPCONST GpPoint *points, INT count, GpFillMode fillMode)
3002{
Evan Staded01c6972007-07-23 20:24:53 -07003003 INT save_state, i;
3004 GpPointF *ptf = NULL;
3005 POINT *pti = NULL;
3006 GpStatus retval = Ok;
Evan Stade64675262007-07-23 20:24:35 -07003007
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003008 TRACE("(%p, %p, %p, %d, %d)\n", graphics, brush, points, count, fillMode);
3009
Evan Stade64675262007-07-23 20:24:35 -07003010 if(!graphics || !brush || !points || !count)
3011 return InvalidParameter;
3012
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003013 if(graphics->busy)
3014 return ObjectBusy;
3015
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05003016 if(!graphics->hdc)
3017 {
3018 FIXME("graphics object has no HDC\n");
3019 return Ok;
3020 }
3021
Evan Staded01c6972007-07-23 20:24:53 -07003022 ptf = GdipAlloc(count * sizeof(GpPointF));
3023 pti = GdipAlloc(count * sizeof(POINT));
3024 if(!ptf || !pti){
3025 retval = OutOfMemory;
3026 goto end;
3027 }
3028
3029 for(i = 0; i < count; i ++){
3030 ptf[i].X = (REAL) points[i].X;
3031 ptf[i].Y = (REAL) points[i].Y;
3032 }
3033
Evan Stade64675262007-07-23 20:24:35 -07003034 save_state = SaveDC(graphics->hdc);
3035 EndPath(graphics->hdc);
Evan Stade64675262007-07-23 20:24:35 -07003036 SetPolyFillMode(graphics->hdc, (fillMode == FillModeAlternate ? ALTERNATE
3037 : WINDING));
Evan Staded01c6972007-07-23 20:24:53 -07003038
3039 transform_and_round_points(graphics, pti, ptf, count);
Vincent Povirk38fc8942009-07-11 10:37:22 -05003040
3041 BeginPath(graphics->hdc);
Evan Staded01c6972007-07-23 20:24:53 -07003042 Polygon(graphics->hdc, pti, count);
Vincent Povirk38fc8942009-07-11 10:37:22 -05003043 EndPath(graphics->hdc);
3044
3045 brush_fill_path(graphics, brush);
Evan Stade64675262007-07-23 20:24:35 -07003046
3047 RestoreDC(graphics->hdc, save_state);
Evan Staded01c6972007-07-23 20:24:53 -07003048
3049end:
3050 GdipFree(ptf);
3051 GdipFree(pti);
3052
3053 return retval;
Evan Stade64675262007-07-23 20:24:35 -07003054}
3055
Nikolay Sivove04a6622008-08-03 12:19:36 +04003056GpStatus WINGDIPAPI GdipFillPolygon2(GpGraphics *graphics, GpBrush *brush,
3057 GDIPCONST GpPointF *points, INT count)
3058{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003059 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3060
Nikolay Sivove04a6622008-08-03 12:19:36 +04003061 return GdipFillPolygon(graphics, brush, points, count, FillModeAlternate);
3062}
3063
3064GpStatus WINGDIPAPI GdipFillPolygon2I(GpGraphics *graphics, GpBrush *brush,
3065 GDIPCONST GpPoint *points, INT count)
3066{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003067 TRACE("(%p, %p, %p, %d)\n", graphics, brush, points, count);
3068
Nikolay Sivove04a6622008-08-03 12:19:36 +04003069 return GdipFillPolygonI(graphics, brush, points, count, FillModeAlternate);
3070}
3071
Evan Stadeb66c0a02007-08-08 19:42:10 -07003072GpStatus WINGDIPAPI GdipFillRectangle(GpGraphics *graphics, GpBrush *brush,
3073 REAL x, REAL y, REAL width, REAL height)
3074{
3075 INT save_state;
3076 GpPointF ptf[4];
3077 POINT pti[4];
3078
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003079 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics, brush, x, y, width, height);
3080
Evan Stadeb66c0a02007-08-08 19:42:10 -07003081 if(!graphics || !brush)
3082 return InvalidParameter;
3083
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003084 if(graphics->busy)
3085 return ObjectBusy;
3086
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05003087 if(!graphics->hdc)
3088 {
3089 FIXME("graphics object has no HDC\n");
3090 return Ok;
3091 }
3092
Evan Stadeb66c0a02007-08-08 19:42:10 -07003093 ptf[0].X = x;
3094 ptf[0].Y = y;
3095 ptf[1].X = x + width;
3096 ptf[1].Y = y;
3097 ptf[2].X = x + width;
3098 ptf[2].Y = y + height;
3099 ptf[3].X = x;
3100 ptf[3].Y = y + height;
3101
3102 save_state = SaveDC(graphics->hdc);
3103 EndPath(graphics->hdc);
Evan Stadeb66c0a02007-08-08 19:42:10 -07003104
3105 transform_and_round_points(graphics, pti, ptf, 4);
3106
Vincent Povirk323e7e682009-05-06 16:34:19 -05003107 BeginPath(graphics->hdc);
Evan Stadeb66c0a02007-08-08 19:42:10 -07003108 Polygon(graphics->hdc, pti, 4);
Vincent Povirk323e7e682009-05-06 16:34:19 -05003109 EndPath(graphics->hdc);
3110
3111 brush_fill_path(graphics, brush);
Evan Stadeb66c0a02007-08-08 19:42:10 -07003112
3113 RestoreDC(graphics->hdc, save_state);
3114
3115 return Ok;
3116}
3117
Evan Stadebb904a22007-08-07 18:43:04 -07003118GpStatus WINGDIPAPI GdipFillRectangleI(GpGraphics *graphics, GpBrush *brush,
3119 INT x, INT y, INT width, INT height)
3120{
3121 INT save_state;
3122 GpPointF ptf[4];
3123 POINT pti[4];
3124
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003125 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics, brush, x, y, width, height);
3126
Evan Stadebb904a22007-08-07 18:43:04 -07003127 if(!graphics || !brush)
3128 return InvalidParameter;
3129
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003130 if(graphics->busy)
3131 return ObjectBusy;
3132
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05003133 if(!graphics->hdc)
3134 {
3135 FIXME("graphics object has no HDC\n");
3136 return Ok;
3137 }
3138
Evan Stadebb904a22007-08-07 18:43:04 -07003139 ptf[0].X = x;
3140 ptf[0].Y = y;
3141 ptf[1].X = x + width;
3142 ptf[1].Y = y;
3143 ptf[2].X = x + width;
3144 ptf[2].Y = y + height;
3145 ptf[3].X = x;
3146 ptf[3].Y = y + height;
3147
3148 save_state = SaveDC(graphics->hdc);
3149 EndPath(graphics->hdc);
Evan Stadebb904a22007-08-07 18:43:04 -07003150
3151 transform_and_round_points(graphics, pti, ptf, 4);
3152
Vincent Povirk849af302009-07-11 10:38:47 -05003153 BeginPath(graphics->hdc);
Evan Stadebb904a22007-08-07 18:43:04 -07003154 Polygon(graphics->hdc, pti, 4);
Vincent Povirk849af302009-07-11 10:38:47 -05003155 EndPath(graphics->hdc);
3156
3157 brush_fill_path(graphics, brush);
Evan Stadebb904a22007-08-07 18:43:04 -07003158
3159 RestoreDC(graphics->hdc, save_state);
3160
3161 return Ok;
3162}
3163
Nikolay Sivov7ce48b02008-04-29 00:10:15 +04003164GpStatus WINGDIPAPI GdipFillRectangles(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRectF *rects,
3165 INT count)
3166{
3167 GpStatus ret;
3168 INT i;
3169
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003170 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3171
Nikolay Sivov7ce48b02008-04-29 00:10:15 +04003172 if(!rects)
3173 return InvalidParameter;
3174
3175 for(i = 0; i < count; i++){
3176 ret = GdipFillRectangle(graphics, brush, rects[i].X, rects[i].Y, rects[i].Width, rects[i].Height);
3177 if(ret != Ok) return ret;
3178 }
3179
3180 return Ok;
3181}
3182
3183GpStatus WINGDIPAPI GdipFillRectanglesI(GpGraphics *graphics, GpBrush *brush, GDIPCONST GpRect *rects,
3184 INT count)
3185{
3186 GpRectF *rectsF;
3187 GpStatus ret;
3188 INT i;
3189
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003190 TRACE("(%p, %p, %p, %d)\n", graphics, brush, rects, count);
3191
Nikolay Sivov7ce48b02008-04-29 00:10:15 +04003192 if(!rects || count <= 0)
3193 return InvalidParameter;
3194
3195 rectsF = GdipAlloc(sizeof(GpRectF)*count);
3196 if(!rectsF)
3197 return OutOfMemory;
3198
3199 for(i = 0; i < count; i++){
3200 rectsF[i].X = (REAL)rects[i].X;
3201 rectsF[i].Y = (REAL)rects[i].Y;
3202 rectsF[i].X = (REAL)rects[i].Width;
3203 rectsF[i].Height = (REAL)rects[i].Height;
3204 }
3205
3206 ret = GdipFillRectangles(graphics,brush,rectsF,count);
3207 GdipFree(rectsF);
3208
3209 return ret;
3210}
3211
Nikolay Sivov9f0edc52009-02-03 22:17:47 +03003212/*****************************************************************************
3213 * GdipFillRegion [GDIPLUS.@]
3214 */
Nikolay Sivov0e840f62008-07-10 23:15:59 +04003215GpStatus WINGDIPAPI GdipFillRegion(GpGraphics* graphics, GpBrush* brush,
3216 GpRegion* region)
3217{
Nikolay Sivov9f0edc52009-02-03 22:17:47 +03003218 INT save_state;
3219 GpStatus status;
3220 HRGN hrgn;
Vincent Povirk6a8a7702009-07-11 10:57:07 -05003221 RECT rc;
Nikolay Sivov9f0edc52009-02-03 22:17:47 +03003222
3223 TRACE("(%p, %p, %p)\n", graphics, brush, region);
3224
Nikolay Sivov0e840f62008-07-10 23:15:59 +04003225 if (!(graphics && brush && region))
3226 return InvalidParameter;
3227
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003228 if(graphics->busy)
3229 return ObjectBusy;
3230
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05003231 if(!graphics->hdc)
3232 {
3233 FIXME("graphics object has no HDC\n");
3234 return Ok;
3235 }
3236
Nikolay Sivov9f0edc52009-02-03 22:17:47 +03003237 status = GdipGetRegionHRgn(region, graphics, &hrgn);
3238 if(status != Ok)
3239 return status;
Nikolay Sivov0e840f62008-07-10 23:15:59 +04003240
Nikolay Sivov9f0edc52009-02-03 22:17:47 +03003241 save_state = SaveDC(graphics->hdc);
3242 EndPath(graphics->hdc);
Nikolay Sivov9f0edc52009-02-03 22:17:47 +03003243
Vincent Povirk6a8a7702009-07-11 10:57:07 -05003244 ExtSelectClipRgn(graphics->hdc, hrgn, RGN_AND);
3245
3246 if (GetClipBox(graphics->hdc, &rc) != NULLREGION)
3247 {
3248 BeginPath(graphics->hdc);
3249 Rectangle(graphics->hdc, rc.left, rc.top, rc.right, rc.bottom);
3250 EndPath(graphics->hdc);
3251
3252 brush_fill_path(graphics, brush);
3253 }
Nikolay Sivov9f0edc52009-02-03 22:17:47 +03003254
3255 RestoreDC(graphics->hdc, save_state);
3256
3257 DeleteObject(hrgn);
3258
3259 return Ok;
Nikolay Sivov0e840f62008-07-10 23:15:59 +04003260}
3261
Nikolay Sivovf620b662008-06-18 11:33:10 +04003262GpStatus WINGDIPAPI GdipFlush(GpGraphics *graphics, GpFlushIntention intention)
3263{
Vincent Povirk2005fe92009-12-18 16:04:20 -06003264 TRACE("(%p,%u)\n", graphics, intention);
3265
Nikolay Sivovf620b662008-06-18 11:33:10 +04003266 if(!graphics)
3267 return InvalidParameter;
3268
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003269 if(graphics->busy)
3270 return ObjectBusy;
3271
Vincent Povirkade25062010-04-02 09:19:13 -05003272 /* We have no internal operation queue, so there's no need to clear it. */
Nikolay Sivovf620b662008-06-18 11:33:10 +04003273
Vincent Povirkade25062010-04-02 09:19:13 -05003274 if (graphics->hdc)
3275 GdiFlush();
3276
3277 return Ok;
Nikolay Sivovf620b662008-06-18 11:33:10 +04003278}
3279
Nikolay Sivovbcfe4e72009-02-02 22:58:27 +03003280/*****************************************************************************
3281 * GdipGetClipBounds [GDIPLUS.@]
3282 */
3283GpStatus WINGDIPAPI GdipGetClipBounds(GpGraphics *graphics, GpRectF *rect)
3284{
3285 TRACE("(%p, %p)\n", graphics, rect);
3286
3287 if(!graphics)
3288 return InvalidParameter;
3289
Nikolay Sivov8c096162009-02-02 23:48:01 +03003290 if(graphics->busy)
3291 return ObjectBusy;
3292
Nikolay Sivovbcfe4e72009-02-02 22:58:27 +03003293 return GdipGetRegionBounds(graphics->clip, graphics, rect);
3294}
3295
3296/*****************************************************************************
3297 * GdipGetClipBoundsI [GDIPLUS.@]
3298 */
3299GpStatus WINGDIPAPI GdipGetClipBoundsI(GpGraphics *graphics, GpRect *rect)
3300{
3301 TRACE("(%p, %p)\n", graphics, rect);
3302
3303 if(!graphics)
3304 return InvalidParameter;
3305
Nikolay Sivov8c096162009-02-02 23:48:01 +03003306 if(graphics->busy)
3307 return ObjectBusy;
3308
Nikolay Sivovbcfe4e72009-02-02 22:58:27 +03003309 return GdipGetRegionBoundsI(graphics->clip, graphics, rect);
3310}
3311
Evan Stadee807eb92007-08-13 18:34:27 -07003312/* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3313GpStatus WINGDIPAPI GdipGetCompositingMode(GpGraphics *graphics,
3314 CompositingMode *mode)
3315{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003316 TRACE("(%p, %p)\n", graphics, mode);
3317
Evan Stadee807eb92007-08-13 18:34:27 -07003318 if(!graphics || !mode)
3319 return InvalidParameter;
3320
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003321 if(graphics->busy)
3322 return ObjectBusy;
3323
Evan Stadee807eb92007-08-13 18:34:27 -07003324 *mode = graphics->compmode;
3325
3326 return Ok;
3327}
3328
Evan Stade60cad232007-07-13 17:51:25 -07003329/* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3330GpStatus WINGDIPAPI GdipGetCompositingQuality(GpGraphics *graphics,
3331 CompositingQuality *quality)
3332{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003333 TRACE("(%p, %p)\n", graphics, quality);
3334
Evan Stade60cad232007-07-13 17:51:25 -07003335 if(!graphics || !quality)
3336 return InvalidParameter;
3337
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003338 if(graphics->busy)
3339 return ObjectBusy;
3340
Evan Stade60cad232007-07-13 17:51:25 -07003341 *quality = graphics->compqual;
3342
3343 return Ok;
3344}
3345
Evan Stadea87ce7a2007-07-13 17:51:29 -07003346/* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3347GpStatus WINGDIPAPI GdipGetInterpolationMode(GpGraphics *graphics,
3348 InterpolationMode *mode)
3349{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003350 TRACE("(%p, %p)\n", graphics, mode);
3351
Evan Stadea87ce7a2007-07-13 17:51:29 -07003352 if(!graphics || !mode)
3353 return InvalidParameter;
3354
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003355 if(graphics->busy)
3356 return ObjectBusy;
3357
Evan Stadea87ce7a2007-07-13 17:51:29 -07003358 *mode = graphics->interpolation;
3359
3360 return Ok;
3361}
3362
Justin Chevrierb4bfa6e2010-02-25 21:45:55 -05003363/* FIXME: Need to handle color depths less than 24bpp */
Nikolay Sivov63ae7142008-12-11 10:32:43 +03003364GpStatus WINGDIPAPI GdipGetNearestColor(GpGraphics *graphics, ARGB* argb)
3365{
Justin Chevrierb4bfa6e2010-02-25 21:45:55 -05003366 FIXME("(%p, %p): Passing color unmodified\n", graphics, argb);
Vincent Povirk2005fe92009-12-18 16:04:20 -06003367
Nikolay Sivov63ae7142008-12-11 10:32:43 +03003368 if(!graphics || !argb)
3369 return InvalidParameter;
3370
3371 if(graphics->busy)
3372 return ObjectBusy;
3373
Justin Chevrierb4bfa6e2010-02-25 21:45:55 -05003374 return Ok;
Nikolay Sivov63ae7142008-12-11 10:32:43 +03003375}
3376
Evan Stade81621392007-07-24 17:18:39 -07003377GpStatus WINGDIPAPI GdipGetPageScale(GpGraphics *graphics, REAL *scale)
3378{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003379 TRACE("(%p, %p)\n", graphics, scale);
3380
Evan Stade81621392007-07-24 17:18:39 -07003381 if(!graphics || !scale)
3382 return InvalidParameter;
3383
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003384 if(graphics->busy)
3385 return ObjectBusy;
3386
Evan Stade81621392007-07-24 17:18:39 -07003387 *scale = graphics->scale;
3388
3389 return Ok;
3390}
3391
Evan Stade10b575b2007-07-23 20:24:41 -07003392GpStatus WINGDIPAPI GdipGetPageUnit(GpGraphics *graphics, GpUnit *unit)
3393{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003394 TRACE("(%p, %p)\n", graphics, unit);
3395
Evan Stade10b575b2007-07-23 20:24:41 -07003396 if(!graphics || !unit)
3397 return InvalidParameter;
3398
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003399 if(graphics->busy)
3400 return ObjectBusy;
3401
Evan Stade10b575b2007-07-23 20:24:41 -07003402 *unit = graphics->unit;
3403
3404 return Ok;
3405}
3406
Evan Staded6bd866d2007-07-13 17:51:33 -07003407/* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3408GpStatus WINGDIPAPI GdipGetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
3409 *mode)
3410{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003411 TRACE("(%p, %p)\n", graphics, mode);
3412
Evan Staded6bd866d2007-07-13 17:51:33 -07003413 if(!graphics || !mode)
3414 return InvalidParameter;
3415
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003416 if(graphics->busy)
3417 return ObjectBusy;
3418
Evan Staded6bd866d2007-07-13 17:51:33 -07003419 *mode = graphics->pixeloffset;
3420
3421 return Ok;
3422}
3423
Evan Stade53e17d22007-07-13 17:51:13 -07003424/* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3425GpStatus WINGDIPAPI GdipGetSmoothingMode(GpGraphics *graphics, SmoothingMode *mode)
3426{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003427 TRACE("(%p, %p)\n", graphics, mode);
3428
Evan Stade53e17d22007-07-13 17:51:13 -07003429 if(!graphics || !mode)
3430 return InvalidParameter;
3431
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003432 if(graphics->busy)
3433 return ObjectBusy;
3434
Evan Stade53e17d22007-07-13 17:51:13 -07003435 *mode = graphics->smoothing;
3436
3437 return Ok;
3438}
3439
Nikolay Sivov56173d42008-11-09 14:32:26 +03003440GpStatus WINGDIPAPI GdipGetTextContrast(GpGraphics *graphics, UINT *contrast)
3441{
3442 TRACE("(%p, %p)\n", graphics, contrast);
3443
3444 if(!graphics || !contrast)
3445 return InvalidParameter;
3446
3447 *contrast = graphics->textcontrast;
3448
3449 return Ok;
3450}
3451
Evan Stade56628202007-08-14 19:00:09 -07003452/* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3453GpStatus WINGDIPAPI GdipGetTextRenderingHint(GpGraphics *graphics,
3454 TextRenderingHint *hint)
3455{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003456 TRACE("(%p, %p)\n", graphics, hint);
3457
Evan Stade56628202007-08-14 19:00:09 -07003458 if(!graphics || !hint)
3459 return InvalidParameter;
3460
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003461 if(graphics->busy)
3462 return ObjectBusy;
3463
Evan Stade56628202007-08-14 19:00:09 -07003464 *hint = graphics->texthint;
3465
3466 return Ok;
3467}
3468
Andrew Eikumef0ee6e2009-08-12 15:37:09 -05003469GpStatus WINGDIPAPI GdipGetVisibleClipBounds(GpGraphics *graphics, GpRectF *rect)
3470{
3471 GpRegion *clip_rgn;
3472 GpStatus stat;
Andrew Eikumef0ee6e2009-08-12 15:37:09 -05003473
3474 TRACE("(%p, %p)\n", graphics, rect);
3475
3476 if(!graphics || !rect)
3477 return InvalidParameter;
3478
3479 if(graphics->busy)
3480 return ObjectBusy;
3481
Andrew Eikumef0ee6e2009-08-12 15:37:09 -05003482 /* intersect window and graphics clipping regions */
3483 if((stat = GdipCreateRegion(&clip_rgn)) != Ok)
3484 return stat;
3485
Andrew Eikum39f6f492009-08-26 18:03:08 -05003486 if((stat = get_visible_clip_region(graphics, clip_rgn)) != Ok)
Andrew Eikumef0ee6e2009-08-12 15:37:09 -05003487 goto cleanup;
3488
3489 /* get bounds of the region */
3490 stat = GdipGetRegionBounds(clip_rgn, graphics, rect);
3491
3492cleanup:
3493 GdipDeleteRegion(clip_rgn);
3494
3495 return stat;
3496}
3497
3498GpStatus WINGDIPAPI GdipGetVisibleClipBoundsI(GpGraphics *graphics, GpRect *rect)
3499{
3500 GpRectF rectf;
3501 GpStatus stat;
3502
3503 TRACE("(%p, %p)\n", graphics, rect);
3504
3505 if(!graphics || !rect)
3506 return InvalidParameter;
3507
3508 if((stat = GdipGetVisibleClipBounds(graphics, &rectf)) == Ok)
3509 {
3510 rect->X = roundr(rectf.X);
3511 rect->Y = roundr(rectf.Y);
3512 rect->Width = roundr(rectf.Width);
3513 rect->Height = roundr(rectf.Height);
3514 }
3515
3516 return stat;
3517}
3518
Evan Stadef30732f2007-07-24 17:18:47 -07003519GpStatus WINGDIPAPI GdipGetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
3520{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003521 TRACE("(%p, %p)\n", graphics, matrix);
3522
Evan Stadef30732f2007-07-24 17:18:47 -07003523 if(!graphics || !matrix)
3524 return InvalidParameter;
3525
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04003526 if(graphics->busy)
3527 return ObjectBusy;
3528
Andrew Talbot5e8253a2008-02-29 22:06:47 +00003529 *matrix = *graphics->worldtrans;
Evan Stadef30732f2007-07-24 17:18:47 -07003530 return Ok;
3531}
3532
Nikolay Sivovbff16782008-09-05 13:56:10 +04003533GpStatus WINGDIPAPI GdipGraphicsClear(GpGraphics *graphics, ARGB color)
3534{
3535 GpSolidFill *brush;
3536 GpStatus stat;
Andrew Eikumfdf48f12009-08-12 15:36:54 -05003537 GpRectF wnd_rect;
Nikolay Sivovbff16782008-09-05 13:56:10 +04003538
3539 TRACE("(%p, %x)\n", graphics, color);
3540
3541 if(!graphics)
3542 return InvalidParameter;
3543
3544 if(graphics->busy)
3545 return ObjectBusy;
3546
3547 if((stat = GdipCreateSolidFill(color, &brush)) != Ok)
3548 return stat;
3549
Andrew Eikumfdf48f12009-08-12 15:36:54 -05003550 if((stat = get_graphics_bounds(graphics, &wnd_rect)) != Ok){
3551 GdipDeleteBrush((GpBrush*)brush);
3552 return stat;
Nikolay Sivovbff16782008-09-05 13:56:10 +04003553 }
Andrew Eikumfdf48f12009-08-12 15:36:54 -05003554
3555 GdipFillRectangle(graphics, (GpBrush*)brush, wnd_rect.X, wnd_rect.Y,
3556 wnd_rect.Width, wnd_rect.Height);
Nikolay Sivovbff16782008-09-05 13:56:10 +04003557
3558 GdipDeleteBrush((GpBrush*)brush);
3559
3560 return Ok;
3561}
3562
Nikolay Sivov813d6dc2008-08-28 17:49:41 +04003563GpStatus WINGDIPAPI GdipIsClipEmpty(GpGraphics *graphics, BOOL *res)
3564{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04003565 TRACE("(%p, %p)\n", graphics, res);
3566
Nikolay Sivov813d6dc2008-08-28 17:49:41 +04003567 if(!graphics || !res)
3568 return InvalidParameter;
3569
3570 return GdipIsEmptyRegion(graphics->clip, graphics, res);
3571}
3572
Nikolay Sivov3ecb8bd2008-09-26 22:34:39 +04003573GpStatus WINGDIPAPI GdipIsVisiblePoint(GpGraphics *graphics, REAL x, REAL y, BOOL *result)
3574{
Andrew Eikumd06dd2d2009-08-26 18:03:11 -05003575 GpStatus stat;
3576 GpRegion* rgn;
3577 GpPointF pt;
3578
3579 TRACE("(%p, %.2f, %.2f, %p)\n", graphics, x, y, result);
Nikolay Sivov3ecb8bd2008-09-26 22:34:39 +04003580
3581 if(!graphics || !result)
3582 return InvalidParameter;
3583
3584 if(graphics->busy)
3585 return ObjectBusy;
3586
Andrew Eikumd06dd2d2009-08-26 18:03:11 -05003587 pt.X = x;
3588 pt.Y = y;
3589 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3590 CoordinateSpaceWorld, &pt, 1)) != Ok)
3591 return stat;
3592
3593 if((stat = GdipCreateRegion(&rgn)) != Ok)
3594 return stat;
3595
3596 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3597 goto cleanup;
3598
3599 stat = GdipIsVisibleRegionPoint(rgn, pt.X, pt.Y, graphics, result);
3600
3601cleanup:
3602 GdipDeleteRegion(rgn);
3603 return stat;
Nikolay Sivov3ecb8bd2008-09-26 22:34:39 +04003604}
3605
3606GpStatus WINGDIPAPI GdipIsVisiblePointI(GpGraphics *graphics, INT x, INT y, BOOL *result)
3607{
Andrew Eikumd06dd2d2009-08-26 18:03:11 -05003608 return GdipIsVisiblePoint(graphics, (REAL)x, (REAL)y, result);
Nikolay Sivov3ecb8bd2008-09-26 22:34:39 +04003609}
3610
Andrew Eikumf5896a22009-08-26 18:03:13 -05003611GpStatus WINGDIPAPI GdipIsVisibleRect(GpGraphics *graphics, REAL x, REAL y, REAL width, REAL height, BOOL *result)
3612{
3613 GpStatus stat;
3614 GpRegion* rgn;
3615 GpPointF pts[2];
3616
3617 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics, x, y, width, height, result);
3618
3619 if(!graphics || !result)
3620 return InvalidParameter;
3621
3622 if(graphics->busy)
3623 return ObjectBusy;
3624
3625 pts[0].X = x;
3626 pts[0].Y = y;
3627 pts[1].X = x + width;
3628 pts[1].Y = y + height;
3629
3630 if((stat = GdipTransformPoints(graphics, CoordinateSpaceDevice,
3631 CoordinateSpaceWorld, pts, 2)) != Ok)
3632 return stat;
3633
3634 pts[1].X -= pts[0].X;
3635 pts[1].Y -= pts[0].Y;
3636
3637 if((stat = GdipCreateRegion(&rgn)) != Ok)
3638 return stat;
3639
3640 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
3641 goto cleanup;
3642
3643 stat = GdipIsVisibleRegionRect(rgn, pts[0].X, pts[0].Y, pts[1].X, pts[1].Y, graphics, result);
3644
3645cleanup:
3646 GdipDeleteRegion(rgn);
3647 return stat;
3648}
3649
3650GpStatus WINGDIPAPI GdipIsVisibleRectI(GpGraphics *graphics, INT x, INT y, INT width, INT height, BOOL *result)
3651{
3652 return GdipIsVisibleRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, result);
3653}
3654
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003655typedef GpStatus (*gdip_format_string_callback)(GpGraphics *graphics,
3656 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3657 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3658 INT lineno, const RectF *bounds, void *user_data);
Adam Petacciabe4a2262008-07-09 03:33:40 -04003659
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003660static GpStatus gdip_format_string(GpGraphics *graphics,
Evan Stadea51cf1d2007-08-15 16:21:52 -07003661 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003662 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3663 gdip_format_string_callback callback, void *user_data)
Evan Stadea51cf1d2007-08-15 16:21:52 -07003664{
Evan Stadea51cf1d2007-08-15 16:21:52 -07003665 WCHAR* stringdup;
Vincent Povirk68ce9e92010-04-17 12:04:03 -05003666 int sum = 0, height = 0, fit, fitcpy, i, j, lret, nwidth,
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003667 nheight, lineend, lineno = 0;
3668 RectF bounds;
3669 StringAlignment halign;
3670 GpStatus stat = Ok;
Evan Stadea51cf1d2007-08-15 16:21:52 -07003671 SIZE size;
3672
Evan Stadea51cf1d2007-08-15 16:21:52 -07003673 if(length == -1) length = lstrlenW(string);
3674
Alexandre Julliarda2d04672008-09-25 11:19:23 +02003675 stringdup = GdipAlloc((length + 1) * sizeof(WCHAR));
Evan Stadea51cf1d2007-08-15 16:21:52 -07003676 if(!stringdup) return OutOfMemory;
3677
Evan Stadea51cf1d2007-08-15 16:21:52 -07003678 nwidth = roundr(rect->Width);
Evan Stade44e98392007-08-15 16:22:09 -07003679 nheight = roundr(rect->Height);
3680
Vincent Povirk43576202010-05-08 16:32:18 -05003681 if (rect->Width >= INT_MAX || rect->Width < 0.5) nwidth = INT_MAX;
3682 if (rect->Height >= INT_MAX || rect->Width < 0.5) nheight = INT_MAX;
Evan Stadea51cf1d2007-08-15 16:21:52 -07003683
3684 for(i = 0, j = 0; i < length; i++){
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003685 /* FIXME: This makes the indexes passed to callback inaccurate. */
Evan Stadea51cf1d2007-08-15 16:21:52 -07003686 if(!isprintW(string[i]) && (string[i] != '\n'))
3687 continue;
3688
3689 stringdup[j] = string[i];
3690 j++;
3691 }
3692
Evan Stadea51cf1d2007-08-15 16:21:52 -07003693 length = j;
3694
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003695 if (format) halign = format->align;
3696 else halign = StringAlignmentNear;
3697
Evan Stadea51cf1d2007-08-15 16:21:52 -07003698 while(sum < length){
3699 GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum,
3700 nwidth, &fit, NULL, &size);
3701 fitcpy = fit;
3702
3703 if(fit == 0)
3704 break;
3705
3706 for(lret = 0; lret < fit; lret++)
3707 if(*(stringdup + sum + lret) == '\n')
3708 break;
3709
3710 /* Line break code (may look strange, but it imitates windows). */
3711 if(lret < fit)
Vincent Povirke0d9d172009-07-24 16:24:19 -05003712 lineend = fit = lret; /* this is not an off-by-one error */
Evan Stadea51cf1d2007-08-15 16:21:52 -07003713 else if(fit < (length - sum)){
3714 if(*(stringdup + sum + fit) == ' ')
3715 while(*(stringdup + sum + fit) == ' ')
3716 fit++;
3717 else
3718 while(*(stringdup + sum + fit - 1) != ' '){
3719 fit--;
3720
3721 if(*(stringdup + sum + fit) == '\t')
3722 break;
3723
3724 if(fit == 0){
3725 fit = fitcpy;
3726 break;
3727 }
3728 }
Vincent Povirke0d9d172009-07-24 16:24:19 -05003729 lineend = fit;
3730 while(*(stringdup + sum + lineend - 1) == ' ' ||
3731 *(stringdup + sum + lineend - 1) == '\t')
3732 lineend--;
Evan Stadea51cf1d2007-08-15 16:21:52 -07003733 }
Vincent Povirke0d9d172009-07-24 16:24:19 -05003734 else
3735 lineend = fit;
Evan Stadea51cf1d2007-08-15 16:21:52 -07003736
Vincent Povirke0d9d172009-07-24 16:24:19 -05003737 GetTextExtentExPointW(graphics->hdc, stringdup + sum, lineend,
Evan Stadea51cf1d2007-08-15 16:21:52 -07003738 nwidth, &j, NULL, &size);
3739
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003740 bounds.Width = size.cx;
Hans Leidekker1e170c92008-11-24 10:22:26 +01003741
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003742 if(height + size.cy > nheight)
3743 bounds.Height = nheight - (height + size.cy);
3744 else
3745 bounds.Height = size.cy;
3746
3747 bounds.Y = rect->Y + height;
3748
3749 switch (halign)
3750 {
3751 case StringAlignmentNear:
3752 default:
3753 bounds.X = rect->X;
3754 break;
3755 case StringAlignmentCenter:
3756 bounds.X = rect->X + (rect->Width/2) - (bounds.Width/2);
3757 break;
3758 case StringAlignmentFar:
3759 bounds.X = rect->X + rect->Width - bounds.Width;
3760 break;
3761 }
3762
3763 stat = callback(graphics, stringdup, sum, lineend,
3764 font, rect, format, lineno, &bounds, user_data);
3765
3766 if (stat != Ok)
3767 break;
3768
3769 sum += fit + (lret < fitcpy ? 1 : 0);
Evan Stadea51cf1d2007-08-15 16:21:52 -07003770 height += size.cy;
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003771 lineno++;
Evan Stadea51cf1d2007-08-15 16:21:52 -07003772
Evan Stade44e98392007-08-15 16:22:09 -07003773 if(height > nheight)
Evan Stadea51cf1d2007-08-15 16:21:52 -07003774 break;
Evan Staded4107db2007-08-15 16:22:04 -07003775
3776 /* Stop if this was a linewrap (but not if it was a linebreak). */
3777 if((lret == fitcpy) && format && (format->attr & StringFormatFlagsNoWrap))
3778 break;
Evan Stadea51cf1d2007-08-15 16:21:52 -07003779 }
3780
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003781 GdipFree(stringdup);
3782
3783 return stat;
3784}
3785
Vincent Povirkdeb64662010-03-30 15:51:44 -05003786struct measure_ranges_args {
3787 GpRegion **regions;
3788};
3789
Francois Gougeta56375f2010-06-24 10:12:48 +02003790static GpStatus measure_ranges_callback(GpGraphics *graphics,
Vincent Povirkdeb64662010-03-30 15:51:44 -05003791 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3792 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3793 INT lineno, const RectF *bounds, void *user_data)
3794{
3795 int i;
3796 GpStatus stat = Ok;
3797 struct measure_ranges_args *args = user_data;
3798
3799 for (i=0; i<format->range_count; i++)
3800 {
3801 INT range_start = max(index, format->character_ranges[i].First);
3802 INT range_end = min(index+length, format->character_ranges[i].First+format->character_ranges[i].Length);
3803 if (range_start < range_end)
3804 {
3805 GpRectF range_rect;
3806 SIZE range_size;
3807
3808 range_rect.Y = bounds->Y;
3809 range_rect.Height = bounds->Height;
3810
3811 GetTextExtentExPointW(graphics->hdc, string + index, range_start - index,
3812 INT_MAX, NULL, NULL, &range_size);
3813 range_rect.X = bounds->X + range_size.cx;
3814
3815 GetTextExtentExPointW(graphics->hdc, string + index, range_end - index,
3816 INT_MAX, NULL, NULL, &range_size);
3817 range_rect.Width = (bounds->X + range_size.cx) - range_rect.X;
3818
3819 stat = GdipCombineRegionRect(args->regions[i], &range_rect, CombineModeUnion);
3820 if (stat != Ok)
3821 break;
3822 }
3823 }
3824
3825 return stat;
3826}
3827
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003828GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,
3829 GDIPCONST WCHAR* string, INT length, GDIPCONST GpFont* font,
3830 GDIPCONST RectF* layoutRect, GDIPCONST GpStringFormat *stringFormat,
3831 INT regionCount, GpRegion** regions)
3832{
Vincent Povirkdeb64662010-03-30 15:51:44 -05003833 GpStatus stat;
3834 int i;
3835 HFONT oldfont;
3836 struct measure_ranges_args args;
3837
3838 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics, debugstr_w(string),
3839 length, font, debugstr_rectf(layoutRect), stringFormat, regionCount, regions);
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003840
3841 if (!(graphics && string && font && layoutRect && stringFormat && regions))
3842 return InvalidParameter;
3843
Vincent Povirkdeb64662010-03-30 15:51:44 -05003844 if (regionCount < stringFormat->range_count)
3845 return InvalidParameter;
3846
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05003847 if(!graphics->hdc)
3848 {
3849 FIXME("graphics object has no HDC\n");
3850 return NotImplemented;
3851 }
3852
Vincent Povirkdeb64662010-03-30 15:51:44 -05003853 if (stringFormat->attr)
3854 TRACE("may be ignoring some format flags: attr %x\n", stringFormat->attr);
3855
3856 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
3857
3858 for (i=0; i<stringFormat->range_count; i++)
3859 {
3860 stat = GdipSetEmpty(regions[i]);
3861 if (stat != Ok)
3862 return stat;
3863 }
3864
3865 args.regions = regions;
3866
3867 stat = gdip_format_string(graphics, string, length, font, layoutRect, stringFormat,
3868 measure_ranges_callback, &args);
3869
3870 DeleteObject(SelectObject(graphics->hdc, oldfont));
3871
3872 return stat;
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003873}
3874
3875struct measure_string_args {
3876 RectF *bounds;
3877 INT *codepointsfitted;
3878 INT *linesfilled;
3879};
3880
3881static GpStatus measure_string_callback(GpGraphics *graphics,
3882 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3883 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3884 INT lineno, const RectF *bounds, void *user_data)
3885{
3886 struct measure_string_args *args = user_data;
3887
3888 if (bounds->Width > args->bounds->Width)
3889 args->bounds->Width = bounds->Width;
3890
3891 if (bounds->Height + bounds->Y > args->bounds->Height + args->bounds->Y)
3892 args->bounds->Height = bounds->Height + bounds->Y - args->bounds->Y;
3893
3894 if (args->codepointsfitted)
3895 *args->codepointsfitted = index + length;
3896
3897 if (args->linesfilled)
Vincent Povirk21109a42010-03-30 14:22:06 -05003898 (*args->linesfilled)++;
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003899
3900 return Ok;
3901}
3902
3903/* Find the smallest rectangle that bounds the text when it is printed in rect
3904 * according to the format options listed in format. If rect has 0 width and
3905 * height, then just find the smallest rectangle that bounds the text when it's
3906 * printed at location (rect->X, rect-Y). */
3907GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
3908 GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
3909 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, RectF *bounds,
3910 INT *codepointsfitted, INT *linesfilled)
3911{
3912 HFONT oldfont;
3913 struct measure_string_args args;
3914
3915 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics,
3916 debugstr_wn(string, length), length, font, debugstr_rectf(rect), format,
3917 bounds, codepointsfitted, linesfilled);
3918
3919 if(!graphics || !string || !font || !rect || !bounds)
3920 return InvalidParameter;
3921
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05003922 if(!graphics->hdc)
3923 {
3924 FIXME("graphics object has no HDC\n");
3925 return NotImplemented;
3926 }
3927
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003928 if(linesfilled) *linesfilled = 0;
3929 if(codepointsfitted) *codepointsfitted = 0;
3930
3931 if(format)
3932 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
3933
3934 oldfont = SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
3935
Evan Stadea51cf1d2007-08-15 16:21:52 -07003936 bounds->X = rect->X;
3937 bounds->Y = rect->Y;
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003938 bounds->Width = 0.0;
3939 bounds->Height = 0.0;
Evan Stadea51cf1d2007-08-15 16:21:52 -07003940
Vincent Povirk3cee74c2010-03-30 13:41:04 -05003941 args.bounds = bounds;
3942 args.codepointsfitted = codepointsfitted;
3943 args.linesfilled = linesfilled;
3944
3945 gdip_format_string(graphics, string, length, font, rect, format,
3946 measure_string_callback, &args);
3947
Evan Stadea51cf1d2007-08-15 16:21:52 -07003948 DeleteObject(SelectObject(graphics->hdc, oldfont));
3949
3950 return Ok;
3951}
3952
Vincent Povirk2cde94a2010-03-30 14:15:48 -05003953struct draw_string_args {
3954 POINT drawbase;
3955 UINT drawflags;
3956 REAL ang_cos, ang_sin;
3957};
3958
3959static GpStatus draw_string_callback(GpGraphics *graphics,
3960 GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
3961 GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
3962 INT lineno, const RectF *bounds, void *user_data)
3963{
3964 struct draw_string_args *args = user_data;
3965 RECT drawcoord;
3966
3967 drawcoord.left = drawcoord.right = args->drawbase.x + roundr(args->ang_sin * bounds->Y);
3968 drawcoord.top = drawcoord.bottom = args->drawbase.y + roundr(args->ang_cos * bounds->Y);
3969
3970 DrawTextW(graphics->hdc, string + index, length, &drawcoord, args->drawflags);
3971
3972 return Ok;
3973}
3974
3975GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string,
3976 INT length, GDIPCONST GpFont *font, GDIPCONST RectF *rect,
3977 GDIPCONST GpStringFormat *format, GDIPCONST GpBrush *brush)
3978{
3979 HRGN rgn = NULL;
3980 HFONT gdifont;
3981 LOGFONTW lfw;
3982 TEXTMETRICW textmet;
3983 GpPointF pt[3], rectcpy[4];
3984 POINT corners[4];
3985 REAL angle, rel_width, rel_height;
3986 INT offsety = 0, save_state;
3987 struct draw_string_args args;
3988 RectF scaled_rect;
3989
3990 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics, debugstr_wn(string, length),
3991 length, font, debugstr_rectf(rect), format, brush);
3992
3993 if(!graphics || !string || !font || !brush || !rect)
3994 return InvalidParameter;
3995
3996 if((brush->bt != BrushTypeSolidColor)){
3997 FIXME("not implemented for given parameters\n");
3998 return NotImplemented;
3999 }
4000
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05004001 if(!graphics->hdc)
4002 {
4003 FIXME("graphics object has no HDC\n");
4004 return NotImplemented;
4005 }
4006
Vincent Povirk2cde94a2010-03-30 14:15:48 -05004007 if(format){
4008 TRACE("may be ignoring some format flags: attr %x\n", format->attr);
4009
4010 /* Should be no need to explicitly test for StringAlignmentNear as
4011 * that is default behavior if no alignment is passed. */
4012 if(format->vertalign != StringAlignmentNear){
4013 RectF bounds;
4014 GdipMeasureString(graphics, string, length, font, rect, format, &bounds, 0, 0);
4015
4016 if(format->vertalign == StringAlignmentCenter)
4017 offsety = (rect->Height - bounds.Height) / 2;
4018 else if(format->vertalign == StringAlignmentFar)
4019 offsety = (rect->Height - bounds.Height);
4020 }
4021 }
4022
4023 save_state = SaveDC(graphics->hdc);
4024 SetBkMode(graphics->hdc, TRANSPARENT);
4025 SetTextColor(graphics->hdc, brush->lb.lbColor);
4026
4027 pt[0].X = 0.0;
4028 pt[0].Y = 0.0;
4029 pt[1].X = 1.0;
4030 pt[1].Y = 0.0;
4031 pt[2].X = 0.0;
4032 pt[2].Y = 1.0;
4033 GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 3);
4034 angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X));
4035 args.ang_cos = cos(angle);
4036 args.ang_sin = sin(angle);
4037 rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+
4038 (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X));
4039 rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+
4040 (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X));
4041
4042 rectcpy[3].X = rectcpy[0].X = rect->X;
4043 rectcpy[1].Y = rectcpy[0].Y = rect->Y + offsety;
4044 rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width;
4045 rectcpy[3].Y = rectcpy[2].Y = rect->Y + offsety + rect->Height;
4046 transform_and_round_points(graphics, corners, rectcpy, 4);
4047
4048 scaled_rect.X = 0.0;
4049 scaled_rect.Y = 0.0;
4050 scaled_rect.Width = rel_width * rect->Width;
4051 scaled_rect.Height = rel_height * rect->Height;
4052
4053 if (roundr(scaled_rect.Width) != 0 && roundr(scaled_rect.Height) != 0)
4054 {
4055 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4056 rgn = CreatePolygonRgn(corners, 4, ALTERNATE);
4057 SelectClipRgn(graphics->hdc, rgn);
4058 }
4059
4060 /* Use gdi to find the font, then perform transformations on it (height,
4061 * width, angle). */
4062 SelectObject(graphics->hdc, CreateFontIndirectW(&font->lfw));
4063 GetTextMetricsW(graphics->hdc, &textmet);
4064 lfw = font->lfw;
4065
4066 lfw.lfHeight = roundr(((REAL)lfw.lfHeight) * rel_height);
4067 lfw.lfWidth = roundr(textmet.tmAveCharWidth * rel_width);
4068
4069 lfw.lfEscapement = lfw.lfOrientation = roundr((angle / M_PI) * 1800.0);
4070
4071 gdifont = CreateFontIndirectW(&lfw);
4072 DeleteObject(SelectObject(graphics->hdc, CreateFontIndirectW(&lfw)));
4073
4074 if (!format || format->align == StringAlignmentNear)
4075 {
4076 args.drawbase.x = corners[0].x;
4077 args.drawbase.y = corners[0].y;
4078 args.drawflags = DT_NOCLIP | DT_EXPANDTABS;
4079 }
4080 else if (format->align == StringAlignmentCenter)
4081 {
4082 args.drawbase.x = (corners[0].x + corners[1].x)/2;
4083 args.drawbase.y = (corners[0].y + corners[1].y)/2;
4084 args.drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_CENTER;
4085 }
4086 else /* (format->align == StringAlignmentFar) */
4087 {
4088 args.drawbase.x = corners[1].x;
4089 args.drawbase.y = corners[1].y;
4090 args.drawflags = DT_NOCLIP | DT_EXPANDTABS | DT_RIGHT;
4091 }
4092
4093 gdip_format_string(graphics, string, length, font, &scaled_rect, format,
4094 draw_string_callback, &args);
4095
4096 DeleteObject(rgn);
4097 DeleteObject(gdifont);
4098
4099 RestoreDC(graphics->hdc, save_state);
4100
4101 return Ok;
4102}
4103
Nikolay Sivovff88d4e2008-08-28 17:34:22 +04004104GpStatus WINGDIPAPI GdipResetClip(GpGraphics *graphics)
4105{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004106 TRACE("(%p)\n", graphics);
4107
Nikolay Sivovff88d4e2008-08-28 17:34:22 +04004108 if(!graphics)
4109 return InvalidParameter;
4110
4111 if(graphics->busy)
4112 return ObjectBusy;
4113
4114 return GdipSetInfinite(graphics->clip);
4115}
4116
Nikolay Sivov169e87d2008-08-06 18:36:16 +04004117GpStatus WINGDIPAPI GdipResetWorldTransform(GpGraphics *graphics)
4118{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004119 TRACE("(%p)\n", graphics);
4120
Nikolay Sivov169e87d2008-08-06 18:36:16 +04004121 if(!graphics)
4122 return InvalidParameter;
4123
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004124 if(graphics->busy)
4125 return ObjectBusy;
4126
Nikolay Sivov169e87d2008-08-06 18:36:16 +04004127 graphics->worldtrans->matrix[0] = 1.0;
4128 graphics->worldtrans->matrix[1] = 0.0;
4129 graphics->worldtrans->matrix[2] = 0.0;
4130 graphics->worldtrans->matrix[3] = 1.0;
4131 graphics->worldtrans->matrix[4] = 0.0;
4132 graphics->worldtrans->matrix[5] = 0.0;
4133
4134 return Ok;
4135}
4136
Evan Stadec7606682007-07-13 17:51:37 -07004137GpStatus WINGDIPAPI GdipRestoreGraphics(GpGraphics *graphics, GraphicsState state)
4138{
Andrew Eikum1ef13942009-07-07 22:30:49 -05004139 return GdipEndContainer(graphics, state);
Evan Stadec7606682007-07-13 17:51:37 -07004140}
4141
Evan Stade3126c772007-08-13 18:34:35 -07004142GpStatus WINGDIPAPI GdipRotateWorldTransform(GpGraphics *graphics, REAL angle,
4143 GpMatrixOrder order)
4144{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004145 TRACE("(%p, %.2f, %d)\n", graphics, angle, order);
4146
Evan Stade3126c772007-08-13 18:34:35 -07004147 if(!graphics)
4148 return InvalidParameter;
4149
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004150 if(graphics->busy)
4151 return ObjectBusy;
4152
Evan Stade3126c772007-08-13 18:34:35 -07004153 return GdipRotateMatrix(graphics->worldtrans, angle, order);
4154}
4155
Evan Stadec7606682007-07-13 17:51:37 -07004156GpStatus WINGDIPAPI GdipSaveGraphics(GpGraphics *graphics, GraphicsState *state)
4157{
Andrew Eikum1ef13942009-07-07 22:30:49 -05004158 return GdipBeginContainer2(graphics, state);
Evan Stadec7606682007-07-13 17:51:37 -07004159}
4160
Andrew Eikum632aef32009-07-05 17:04:20 -05004161GpStatus WINGDIPAPI GdipBeginContainer2(GpGraphics *graphics,
4162 GraphicsContainer *state)
Hans Leidekker5ce729a2008-11-24 10:22:51 +01004163{
Andrew Eikum632aef32009-07-05 17:04:20 -05004164 GraphicsContainerItem *container;
4165 GpStatus sts;
4166
4167 TRACE("(%p, %p)\n", graphics, state);
Hans Leidekker5ce729a2008-11-24 10:22:51 +01004168
4169 if(!graphics || !state)
4170 return InvalidParameter;
4171
Andrew Eikum632aef32009-07-05 17:04:20 -05004172 sts = init_container(&container, graphics);
4173 if(sts != Ok)
4174 return sts;
4175
4176 list_add_head(&graphics->containers, &container->entry);
4177 *state = graphics->contid = container->contid;
4178
Hans Leidekker5ce729a2008-11-24 10:22:51 +01004179 return Ok;
4180}
4181
Andrew Eikum30915062009-05-31 15:00:03 -05004182GpStatus WINGDIPAPI GdipBeginContainer(GpGraphics *graphics, GDIPCONST GpRectF *dstrect, GDIPCONST GpRectF *srcrect, GpUnit unit, GraphicsContainer *state)
4183{
4184 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
4185 return NotImplemented;
4186}
4187
4188GpStatus WINGDIPAPI GdipBeginContainerI(GpGraphics *graphics, GDIPCONST GpRect *dstrect, GDIPCONST GpRect *srcrect, GpUnit unit, GraphicsContainer *state)
4189{
4190 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics, dstrect, srcrect, unit, state);
4191 return NotImplemented;
4192}
4193
Andrew Eikumb8500082009-06-01 20:01:43 -05004194GpStatus WINGDIPAPI GdipComment(GpGraphics *graphics, UINT sizeData, GDIPCONST BYTE *data)
4195{
4196 FIXME("(%p, %d, %p): stub\n", graphics, sizeData, data);
4197 return NotImplemented;
4198}
4199
Andrew Eikuma06c2572009-07-07 22:30:29 -05004200GpStatus WINGDIPAPI GdipEndContainer(GpGraphics *graphics, GraphicsContainer state)
Hans Leidekker5ce729a2008-11-24 10:22:51 +01004201{
Andrew Eikum632aef32009-07-05 17:04:20 -05004202 GpStatus sts;
4203 GraphicsContainerItem *container, *container2;
Hans Leidekker5ce729a2008-11-24 10:22:51 +01004204
Andrew Eikum632aef32009-07-05 17:04:20 -05004205 TRACE("(%p, %x)\n", graphics, state);
4206
4207 if(!graphics)
Hans Leidekker5ce729a2008-11-24 10:22:51 +01004208 return InvalidParameter;
4209
Andrew Eikum632aef32009-07-05 17:04:20 -05004210 LIST_FOR_EACH_ENTRY(container, &graphics->containers, GraphicsContainerItem, entry){
4211 if(container->contid == state)
4212 break;
4213 }
4214
4215 /* did not find a matching container */
4216 if(&container->entry == &graphics->containers)
4217 return Ok;
4218
Andrew Eikuma06c2572009-07-07 22:30:29 -05004219 sts = restore_container(graphics, container);
4220 if(sts != Ok)
4221 return sts;
4222
Andrew Eikum632aef32009-07-05 17:04:20 -05004223 /* remove all of the containers on top of the found container */
4224 LIST_FOR_EACH_ENTRY_SAFE(container, container2, &graphics->containers, GraphicsContainerItem, entry){
4225 if(container->contid == state)
4226 break;
4227 list_remove(&container->entry);
4228 delete_container(container);
4229 }
4230
4231 list_remove(&container->entry);
Andrew Eikum632aef32009-07-05 17:04:20 -05004232 delete_container(container);
4233
Andrew Eikuma06c2572009-07-07 22:30:29 -05004234 return Ok;
Hans Leidekker5ce729a2008-11-24 10:22:51 +01004235}
4236
Evan Stade30fdcc72007-08-13 18:34:38 -07004237GpStatus WINGDIPAPI GdipScaleWorldTransform(GpGraphics *graphics, REAL sx,
4238 REAL sy, GpMatrixOrder order)
4239{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004240 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, sx, sy, order);
4241
Evan Stade30fdcc72007-08-13 18:34:38 -07004242 if(!graphics)
4243 return InvalidParameter;
4244
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004245 if(graphics->busy)
4246 return ObjectBusy;
4247
Evan Stade30fdcc72007-08-13 18:34:38 -07004248 return GdipScaleMatrix(graphics->worldtrans, sx, sy, order);
4249}
4250
Nikolay Sivovc543f3d2008-10-22 20:03:10 +04004251GpStatus WINGDIPAPI GdipSetClipGraphics(GpGraphics *graphics, GpGraphics *srcgraphics,
4252 CombineMode mode)
4253{
4254 TRACE("(%p, %p, %d)\n", graphics, srcgraphics, mode);
4255
4256 if(!graphics || !srcgraphics)
4257 return InvalidParameter;
4258
4259 return GdipCombineRegionRegion(graphics->clip, srcgraphics->clip, mode);
4260}
4261
Evan Stadee807eb92007-08-13 18:34:27 -07004262GpStatus WINGDIPAPI GdipSetCompositingMode(GpGraphics *graphics,
4263 CompositingMode mode)
4264{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004265 TRACE("(%p, %d)\n", graphics, mode);
4266
Evan Stadee807eb92007-08-13 18:34:27 -07004267 if(!graphics)
4268 return InvalidParameter;
4269
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004270 if(graphics->busy)
4271 return ObjectBusy;
4272
Evan Stadee807eb92007-08-13 18:34:27 -07004273 graphics->compmode = mode;
4274
4275 return Ok;
4276}
4277
Evan Stade60cad232007-07-13 17:51:25 -07004278GpStatus WINGDIPAPI GdipSetCompositingQuality(GpGraphics *graphics,
4279 CompositingQuality quality)
4280{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004281 TRACE("(%p, %d)\n", graphics, quality);
4282
Evan Stade60cad232007-07-13 17:51:25 -07004283 if(!graphics)
4284 return InvalidParameter;
4285
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004286 if(graphics->busy)
4287 return ObjectBusy;
4288
Evan Stade60cad232007-07-13 17:51:25 -07004289 graphics->compqual = quality;
4290
4291 return Ok;
4292}
4293
Evan Stadea87ce7a2007-07-13 17:51:29 -07004294GpStatus WINGDIPAPI GdipSetInterpolationMode(GpGraphics *graphics,
4295 InterpolationMode mode)
4296{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004297 TRACE("(%p, %d)\n", graphics, mode);
4298
Evan Stadea87ce7a2007-07-13 17:51:29 -07004299 if(!graphics)
4300 return InvalidParameter;
4301
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004302 if(graphics->busy)
4303 return ObjectBusy;
4304
Evan Stadea87ce7a2007-07-13 17:51:29 -07004305 graphics->interpolation = mode;
4306
4307 return Ok;
4308}
4309
Evan Stade81621392007-07-24 17:18:39 -07004310GpStatus WINGDIPAPI GdipSetPageScale(GpGraphics *graphics, REAL scale)
4311{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004312 TRACE("(%p, %.2f)\n", graphics, scale);
4313
Evan Stade81621392007-07-24 17:18:39 -07004314 if(!graphics || (scale <= 0.0))
4315 return InvalidParameter;
4316
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004317 if(graphics->busy)
4318 return ObjectBusy;
4319
Evan Stade81621392007-07-24 17:18:39 -07004320 graphics->scale = scale;
4321
4322 return Ok;
4323}
4324
Evan Stade10b575b2007-07-23 20:24:41 -07004325GpStatus WINGDIPAPI GdipSetPageUnit(GpGraphics *graphics, GpUnit unit)
4326{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004327 TRACE("(%p, %d)\n", graphics, unit);
4328
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004329 if(!graphics)
4330 return InvalidParameter;
4331
4332 if(graphics->busy)
4333 return ObjectBusy;
4334
4335 if(unit == UnitWorld)
Evan Stade10b575b2007-07-23 20:24:41 -07004336 return InvalidParameter;
4337
4338 graphics->unit = unit;
4339
4340 return Ok;
4341}
4342
Evan Staded6bd866d2007-07-13 17:51:33 -07004343GpStatus WINGDIPAPI GdipSetPixelOffsetMode(GpGraphics *graphics, PixelOffsetMode
4344 mode)
4345{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004346 TRACE("(%p, %d)\n", graphics, mode);
4347
Evan Staded6bd866d2007-07-13 17:51:33 -07004348 if(!graphics)
4349 return InvalidParameter;
4350
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004351 if(graphics->busy)
4352 return ObjectBusy;
4353
Evan Staded6bd866d2007-07-13 17:51:33 -07004354 graphics->pixeloffset = mode;
4355
4356 return Ok;
4357}
4358
Vincent Povirk27b47ea2009-05-06 16:03:27 -05004359GpStatus WINGDIPAPI GdipSetRenderingOrigin(GpGraphics *graphics, INT x, INT y)
4360{
4361 static int calls;
4362
4363 TRACE("(%p,%i,%i)\n", graphics, x, y);
4364
4365 if (!(calls++))
4366 FIXME("not implemented\n");
4367
4368 return NotImplemented;
4369}
4370
Vincent Povirk85c0e832010-06-24 12:09:26 -05004371GpStatus WINGDIPAPI GdipGetRenderingOrigin(GpGraphics *graphics, INT *x, INT *y)
4372{
4373 static int calls;
4374
4375 TRACE("(%p,%p,%p)\n", graphics, x, y);
4376
4377 if (!(calls++))
4378 FIXME("not implemented\n");
4379
4380 *x = *y = 0;
4381
4382 return NotImplemented;
4383}
4384
Evan Stade53e17d22007-07-13 17:51:13 -07004385GpStatus WINGDIPAPI GdipSetSmoothingMode(GpGraphics *graphics, SmoothingMode mode)
4386{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004387 TRACE("(%p, %d)\n", graphics, mode);
4388
Evan Stade53e17d22007-07-13 17:51:13 -07004389 if(!graphics)
4390 return InvalidParameter;
4391
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004392 if(graphics->busy)
4393 return ObjectBusy;
4394
Evan Stade53e17d22007-07-13 17:51:13 -07004395 graphics->smoothing = mode;
4396
4397 return Ok;
4398}
Evan Stadef30732f2007-07-24 17:18:47 -07004399
Nikolay Sivov71264732008-11-09 14:38:16 +03004400GpStatus WINGDIPAPI GdipSetTextContrast(GpGraphics *graphics, UINT contrast)
4401{
4402 TRACE("(%p, %d)\n", graphics, contrast);
4403
4404 if(!graphics)
4405 return InvalidParameter;
4406
4407 graphics->textcontrast = contrast;
4408
4409 return Ok;
4410}
4411
Evan Stade56628202007-08-14 19:00:09 -07004412GpStatus WINGDIPAPI GdipSetTextRenderingHint(GpGraphics *graphics,
4413 TextRenderingHint hint)
4414{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004415 TRACE("(%p, %d)\n", graphics, hint);
4416
Evan Stade56628202007-08-14 19:00:09 -07004417 if(!graphics)
4418 return InvalidParameter;
4419
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004420 if(graphics->busy)
4421 return ObjectBusy;
4422
Evan Stade56628202007-08-14 19:00:09 -07004423 graphics->texthint = hint;
4424
4425 return Ok;
4426}
4427
Evan Stadef30732f2007-07-24 17:18:47 -07004428GpStatus WINGDIPAPI GdipSetWorldTransform(GpGraphics *graphics, GpMatrix *matrix)
4429{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004430 TRACE("(%p, %p)\n", graphics, matrix);
4431
Evan Stadef30732f2007-07-24 17:18:47 -07004432 if(!graphics || !matrix)
4433 return InvalidParameter;
4434
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004435 if(graphics->busy)
4436 return ObjectBusy;
4437
Evan Stadef30732f2007-07-24 17:18:47 -07004438 GdipDeleteMatrix(graphics->worldtrans);
4439 return GdipCloneMatrix(matrix, &graphics->worldtrans);
4440}
Evan Stade795b6222007-08-09 18:25:31 -07004441
4442GpStatus WINGDIPAPI GdipTranslateWorldTransform(GpGraphics *graphics, REAL dx,
4443 REAL dy, GpMatrixOrder order)
4444{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004445 TRACE("(%p, %.2f, %.2f, %d)\n", graphics, dx, dy, order);
4446
Evan Stade795b6222007-08-09 18:25:31 -07004447 if(!graphics)
4448 return InvalidParameter;
4449
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004450 if(graphics->busy)
4451 return ObjectBusy;
4452
Evan Stade795b6222007-08-09 18:25:31 -07004453 return GdipTranslateMatrix(graphics->worldtrans, dx, dy, order);
4454}
Lei Zhangd9a42992008-04-08 14:44:41 -07004455
Nikolay Sivovf8edb062009-02-02 23:33:41 +03004456/*****************************************************************************
4457 * GdipSetClipHrgn [GDIPLUS.@]
4458 */
4459GpStatus WINGDIPAPI GdipSetClipHrgn(GpGraphics *graphics, HRGN hrgn, CombineMode mode)
4460{
4461 GpRegion *region;
4462 GpStatus status;
4463
4464 TRACE("(%p, %p, %d)\n", graphics, hrgn, mode);
4465
4466 if(!graphics)
4467 return InvalidParameter;
4468
4469 status = GdipCreateRegionHrgn(hrgn, &region);
4470 if(status != Ok)
4471 return status;
4472
4473 status = GdipSetClipRegion(graphics, region, mode);
4474
4475 GdipDeleteRegion(region);
4476 return status;
4477}
4478
Nikolay Sivove2817e52008-09-26 22:18:09 +04004479GpStatus WINGDIPAPI GdipSetClipPath(GpGraphics *graphics, GpPath *path, CombineMode mode)
4480{
4481 TRACE("(%p, %p, %d)\n", graphics, path, mode);
4482
4483 if(!graphics)
4484 return InvalidParameter;
4485
4486 if(graphics->busy)
4487 return ObjectBusy;
4488
4489 return GdipCombineRegionPath(graphics->clip, path, mode);
4490}
4491
Nikolay Sivov8d9c4862008-09-25 10:41:15 +04004492GpStatus WINGDIPAPI GdipSetClipRect(GpGraphics *graphics, REAL x, REAL y,
4493 REAL width, REAL height,
4494 CombineMode mode)
Lei Zhangd9a42992008-04-08 14:44:41 -07004495{
Nikolay Sivov8d9c4862008-09-25 10:41:15 +04004496 GpRectF rect;
4497
4498 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics, x, y, width, height, mode);
Lei Zhangd9a42992008-04-08 14:44:41 -07004499
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004500 if(!graphics)
4501 return InvalidParameter;
4502
4503 if(graphics->busy)
4504 return ObjectBusy;
4505
Nikolay Sivov8d9c4862008-09-25 10:41:15 +04004506 rect.X = x;
4507 rect.Y = y;
4508 rect.Width = width;
4509 rect.Height = height;
Lei Zhangd9a42992008-04-08 14:44:41 -07004510
Nikolay Sivov8d9c4862008-09-25 10:41:15 +04004511 return GdipCombineRegionRect(graphics->clip, &rect, mode);
4512}
4513
4514GpStatus WINGDIPAPI GdipSetClipRectI(GpGraphics *graphics, INT x, INT y,
4515 INT width, INT height,
4516 CombineMode mode)
4517{
4518 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics, x, y, width, height, mode);
4519
4520 if(!graphics)
4521 return InvalidParameter;
4522
4523 if(graphics->busy)
4524 return ObjectBusy;
4525
4526 return GdipSetClipRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, mode);
Lei Zhangd9a42992008-04-08 14:44:41 -07004527}
Lei Zhangcec6c2e2008-04-09 12:35:29 -07004528
4529GpStatus WINGDIPAPI GdipSetClipRegion(GpGraphics *graphics, GpRegion *region,
Nikolay Sivov0df5fb52008-08-27 23:30:59 +04004530 CombineMode mode)
Lei Zhangcec6c2e2008-04-09 12:35:29 -07004531{
Nikolay Sivov0df5fb52008-08-27 23:30:59 +04004532 TRACE("(%p, %p, %d)\n", graphics, region, mode);
Lei Zhangcec6c2e2008-04-09 12:35:29 -07004533
Nikolay Sivov0df5fb52008-08-27 23:30:59 +04004534 if(!graphics || !region)
4535 return InvalidParameter;
Lei Zhangcec6c2e2008-04-09 12:35:29 -07004536
Nikolay Sivov0df5fb52008-08-27 23:30:59 +04004537 if(graphics->busy)
4538 return ObjectBusy;
4539
4540 return GdipCombineRegionRegion(graphics->clip, region, mode);
Lei Zhangcec6c2e2008-04-09 12:35:29 -07004541}
Lei Zhang54a06642008-04-10 12:40:21 -07004542
Nikolay Sivov45705012008-08-24 14:45:14 +04004543GpStatus WINGDIPAPI GdipSetMetafileDownLevelRasterizationLimit(GpMetafile *metafile,
Lei Zhang54a06642008-04-10 12:40:21 -07004544 UINT limitDpi)
4545{
4546 static int calls;
4547
Vincent Povirk2005fe92009-12-18 16:04:20 -06004548 TRACE("(%p,%u)\n", metafile, limitDpi);
4549
Lei Zhang54a06642008-04-10 12:40:21 -07004550 if(!(calls++))
4551 FIXME("not implemented\n");
4552
4553 return NotImplemented;
4554}
Nikolay Sivov46975932008-04-24 20:48:17 +04004555
4556GpStatus WINGDIPAPI GdipDrawPolygon(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPointF *points,
4557 INT count)
4558{
4559 INT save_state;
4560 POINT *pti;
4561
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004562 TRACE("(%p, %p, %d)\n", graphics, points, count);
4563
Nikolay Sivov46975932008-04-24 20:48:17 +04004564 if(!graphics || !pen || count<=0)
4565 return InvalidParameter;
4566
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004567 if(graphics->busy)
4568 return ObjectBusy;
4569
Nikolay Sivov46975932008-04-24 20:48:17 +04004570 pti = GdipAlloc(sizeof(POINT) * count);
4571
4572 save_state = prepare_dc(graphics, pen);
4573 SelectObject(graphics->hdc, GetStockObject(NULL_BRUSH));
4574
4575 transform_and_round_points(graphics, pti, (GpPointF*)points, count);
4576 Polygon(graphics->hdc, pti, count);
4577
4578 restore_dc(graphics, save_state);
4579 GdipFree(pti);
4580
4581 return Ok;
4582}
4583
4584GpStatus WINGDIPAPI GdipDrawPolygonI(GpGraphics *graphics,GpPen *pen,GDIPCONST GpPoint *points,
4585 INT count)
4586{
4587 GpStatus ret;
4588 GpPointF *ptf;
4589 INT i;
4590
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004591 TRACE("(%p, %p, %p, %d)\n", graphics, pen, points, count);
4592
Nikolay Sivov46975932008-04-24 20:48:17 +04004593 if(count<=0) return InvalidParameter;
4594 ptf = GdipAlloc(sizeof(GpPointF) * count);
4595
4596 for(i = 0;i < count; i++){
4597 ptf[i].X = (REAL)points[i].X;
4598 ptf[i].Y = (REAL)points[i].Y;
4599 }
4600
4601 ret = GdipDrawPolygon(graphics,pen,ptf,count);
4602 GdipFree(ptf);
4603
4604 return ret;
4605}
Nikolay Sivovd5769952008-04-29 00:10:20 +04004606
4607GpStatus WINGDIPAPI GdipGetDpiX(GpGraphics *graphics, REAL* dpi)
4608{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004609 TRACE("(%p, %p)\n", graphics, dpi);
4610
Nikolay Sivovd5769952008-04-29 00:10:20 +04004611 if(!graphics || !dpi)
4612 return InvalidParameter;
4613
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004614 if(graphics->busy)
4615 return ObjectBusy;
4616
Vincent Povirk963c7092010-08-08 15:53:08 -05004617 if (graphics->image)
4618 *dpi = graphics->image->xres;
4619 else
4620 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
Nikolay Sivovd5769952008-04-29 00:10:20 +04004621
4622 return Ok;
4623}
4624
4625GpStatus WINGDIPAPI GdipGetDpiY(GpGraphics *graphics, REAL* dpi)
4626{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004627 TRACE("(%p, %p)\n", graphics, dpi);
4628
Nikolay Sivovd5769952008-04-29 00:10:20 +04004629 if(!graphics || !dpi)
4630 return InvalidParameter;
4631
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004632 if(graphics->busy)
4633 return ObjectBusy;
4634
Vincent Povirk963c7092010-08-08 15:53:08 -05004635 if (graphics->image)
4636 *dpi = graphics->image->yres;
4637 else
4638 *dpi = (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSY);
Nikolay Sivovd5769952008-04-29 00:10:20 +04004639
4640 return Ok;
4641}
Nikolay Sivov510c26a2008-04-30 01:28:40 +04004642
4643GpStatus WINGDIPAPI GdipMultiplyWorldTransform(GpGraphics *graphics, GDIPCONST GpMatrix *matrix,
4644 GpMatrixOrder order)
4645{
4646 GpMatrix m;
4647 GpStatus ret;
4648
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004649 TRACE("(%p, %p, %d)\n", graphics, matrix, order);
4650
Nikolay Sivov510c26a2008-04-30 01:28:40 +04004651 if(!graphics || !matrix)
4652 return InvalidParameter;
4653
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004654 if(graphics->busy)
4655 return ObjectBusy;
4656
Nikolay Sivov510c26a2008-04-30 01:28:40 +04004657 m = *(graphics->worldtrans);
4658
Michael Stefaniucb53877d2009-01-14 09:52:24 +01004659 ret = GdipMultiplyMatrix(&m, matrix, order);
Nikolay Sivov510c26a2008-04-30 01:28:40 +04004660 if(ret == Ok)
4661 *(graphics->worldtrans) = m;
4662
4663 return ret;
4664}
Huw Davies6cfb4692008-05-12 16:51:32 +01004665
Vincent Povirk9d0cd092010-08-16 16:31:18 -05004666/* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
4667static const COLORREF DC_BACKGROUND_KEY = 0x0c0b0d;
4668
Huw Davies6cfb4692008-05-12 16:51:32 +01004669GpStatus WINGDIPAPI GdipGetDC(GpGraphics *graphics, HDC *hdc)
4670{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004671 TRACE("(%p, %p)\n", graphics, hdc);
4672
Nikolay Sivov45705012008-08-24 14:45:14 +04004673 if(!graphics || !hdc)
4674 return InvalidParameter;
4675
Nikolay Sivov366ae1e2008-08-24 14:45:18 +04004676 if(graphics->busy)
4677 return ObjectBusy;
4678
Vincent Povirk9d0cd092010-08-16 16:31:18 -05004679 if (!graphics->hdc ||
4680 (graphics->image && graphics->image->type == ImageTypeBitmap && ((GpBitmap*)graphics->image)->format & PixelFormatAlpha))
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05004681 {
Vincent Povirk9d0cd092010-08-16 16:31:18 -05004682 /* Create a fake HDC and fill it with a constant color. */
4683 HDC temp_hdc;
4684 HBITMAP hbitmap;
4685 GpStatus stat;
4686 GpRectF bounds;
4687 BITMAPINFOHEADER bmih;
4688 int i;
4689
4690 stat = get_graphics_bounds(graphics, &bounds);
4691 if (stat != Ok)
4692 return stat;
4693
4694 graphics->temp_hbitmap_width = bounds.Width;
4695 graphics->temp_hbitmap_height = bounds.Height;
4696
4697 bmih.biSize = sizeof(bmih);
4698 bmih.biWidth = graphics->temp_hbitmap_width;
4699 bmih.biHeight = -graphics->temp_hbitmap_height;
4700 bmih.biPlanes = 1;
4701 bmih.biBitCount = 32;
4702 bmih.biCompression = BI_RGB;
4703 bmih.biSizeImage = 0;
4704 bmih.biXPelsPerMeter = 0;
4705 bmih.biYPelsPerMeter = 0;
4706 bmih.biClrUsed = 0;
4707 bmih.biClrImportant = 0;
4708
4709 hbitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
4710 (void**)&graphics->temp_bits, NULL, 0);
4711 if (!hbitmap)
4712 return GenericError;
4713
4714 temp_hdc = CreateCompatibleDC(0);
4715 if (!temp_hdc)
4716 {
4717 DeleteObject(hbitmap);
4718 return GenericError;
4719 }
4720
4721 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
4722 ((DWORD*)graphics->temp_bits)[i] = DC_BACKGROUND_KEY;
4723
4724 SelectObject(temp_hdc, hbitmap);
4725
4726 graphics->temp_hbitmap = hbitmap;
4727 *hdc = graphics->temp_hdc = temp_hdc;
4728 }
4729 else
4730 {
4731 *hdc = graphics->hdc;
Vincent Povirkc3ca6be2010-08-08 15:34:23 -05004732 }
4733
Nikolay Sivov366ae1e2008-08-24 14:45:18 +04004734 graphics->busy = TRUE;
4735
4736 return Ok;
Huw Davies6cfb4692008-05-12 16:51:32 +01004737}
4738
4739GpStatus WINGDIPAPI GdipReleaseDC(GpGraphics *graphics, HDC hdc)
4740{
Nikolay Sivov29f4c9d2008-09-02 23:45:39 +04004741 TRACE("(%p, %p)\n", graphics, hdc);
4742
Vincent Povirk9d0cd092010-08-16 16:31:18 -05004743 if(!graphics || !hdc)
Nikolay Sivov45705012008-08-24 14:45:14 +04004744 return InvalidParameter;
4745
Vincent Povirk9d0cd092010-08-16 16:31:18 -05004746 if((graphics->hdc != hdc && graphics->temp_hdc != hdc) || !(graphics->busy))
Nikolay Sivov45705012008-08-24 14:45:14 +04004747 return InvalidParameter;
4748
Vincent Povirk9d0cd092010-08-16 16:31:18 -05004749 if (graphics->temp_hdc == hdc)
4750 {
4751 DWORD* pos;
4752 int i;
4753
4754 /* Find the pixels that have changed, and mark them as opaque. */
4755 pos = (DWORD*)graphics->temp_bits;
4756 for (i=0; i<(graphics->temp_hbitmap_width * graphics->temp_hbitmap_height); i++)
4757 {
4758 if (*pos != DC_BACKGROUND_KEY)
4759 {
4760 *pos |= 0xff000000;
4761 }
4762 pos++;
4763 }
4764
4765 /* Write the changed pixels to the real target. */
4766 alpha_blend_pixels(graphics, 0, 0, graphics->temp_bits,
4767 graphics->temp_hbitmap_width, graphics->temp_hbitmap_height,
4768 graphics->temp_hbitmap_width * 4);
4769
4770 /* Clean up. */
4771 DeleteDC(graphics->temp_hdc);
4772 DeleteObject(graphics->temp_hbitmap);
4773 graphics->temp_hdc = NULL;
4774 graphics->temp_hbitmap = NULL;
4775 }
4776
Nikolay Sivov366ae1e2008-08-24 14:45:18 +04004777 graphics->busy = FALSE;
4778
4779 return Ok;
Huw Davies6cfb4692008-05-12 16:51:32 +01004780}
Huw Daviesd5ccbe22008-05-12 16:57:28 +01004781
4782GpStatus WINGDIPAPI GdipGetClip(GpGraphics *graphics, GpRegion *region)
4783{
Nikolay Sivovef50aa32008-08-27 02:03:27 +04004784 GpRegion *clip;
4785 GpStatus status;
4786
4787 TRACE("(%p, %p)\n", graphics, region);
4788
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004789 if(!graphics || !region)
4790 return InvalidParameter;
Huw Daviesd5ccbe22008-05-12 16:57:28 +01004791
Nikolay Sivovf0a507e2008-08-24 14:45:23 +04004792 if(graphics->busy)
4793 return ObjectBusy;
4794
Nikolay Sivovef50aa32008-08-27 02:03:27 +04004795 if((status = GdipCloneRegion(graphics->clip, &clip)) != Ok)
4796 return status;
4797
4798 /* free everything except root node and header */
4799 delete_element(&region->node);
4800 memcpy(region, clip, sizeof(GpRegion));
Huw Davies68bacfb2009-12-12 16:49:15 +00004801 GdipFree(clip);
Nikolay Sivovef50aa32008-08-27 02:03:27 +04004802
4803 return Ok;
Huw Daviesd5ccbe22008-05-12 16:57:28 +01004804}
Huw Davies3ab76662008-07-10 15:26:58 +01004805
4806GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace dst_space,
4807 GpCoordinateSpace src_space, GpPointF *points, INT count)
4808{
Vincent Povirk2af29ed2009-03-23 16:34:12 -05004809 GpMatrix *matrix;
4810 GpStatus stat;
4811 REAL unitscale;
4812
Nikolay Sivovc61ece62008-08-26 01:58:42 +04004813 if(!graphics || !points || count <= 0)
4814 return InvalidParameter;
4815
4816 if(graphics->busy)
4817 return ObjectBusy;
4818
Vincent Povirk2af29ed2009-03-23 16:34:12 -05004819 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
Huw Davies3ab76662008-07-10 15:26:58 +01004820
Vincent Povirk2af29ed2009-03-23 16:34:12 -05004821 if (src_space == dst_space) return Ok;
4822
4823 stat = GdipCreateMatrix(&matrix);
4824 if (stat == Ok)
4825 {
Vincent Povirk85a57102010-08-08 15:24:45 -05004826 unitscale = convert_unit(graphics_res(graphics), graphics->unit);
Vincent Povirk2af29ed2009-03-23 16:34:12 -05004827
4828 if(graphics->unit != UnitDisplay)
4829 unitscale *= graphics->scale;
4830
4831 /* transform from src_space to CoordinateSpacePage */
4832 switch (src_space)
4833 {
4834 case CoordinateSpaceWorld:
4835 GdipMultiplyMatrix(matrix, graphics->worldtrans, MatrixOrderAppend);
4836 break;
4837 case CoordinateSpacePage:
4838 break;
4839 case CoordinateSpaceDevice:
4840 GdipScaleMatrix(matrix, 1.0/unitscale, 1.0/unitscale, MatrixOrderAppend);
4841 break;
4842 }
4843
4844 /* transform from CoordinateSpacePage to dst_space */
4845 switch (dst_space)
4846 {
4847 case CoordinateSpaceWorld:
4848 {
4849 GpMatrix *inverted_transform;
4850 stat = GdipCloneMatrix(graphics->worldtrans, &inverted_transform);
4851 if (stat == Ok)
4852 {
4853 stat = GdipInvertMatrix(inverted_transform);
4854 if (stat == Ok)
4855 GdipMultiplyMatrix(matrix, inverted_transform, MatrixOrderAppend);
4856 GdipDeleteMatrix(inverted_transform);
4857 }
4858 break;
4859 }
4860 case CoordinateSpacePage:
4861 break;
4862 case CoordinateSpaceDevice:
4863 GdipScaleMatrix(matrix, unitscale, unitscale, MatrixOrderAppend);
4864 break;
4865 }
4866
4867 if (stat == Ok)
4868 stat = GdipTransformMatrixPoints(matrix, points, count);
4869
4870 GdipDeleteMatrix(matrix);
4871 }
4872
4873 return stat;
Huw Davies3ab76662008-07-10 15:26:58 +01004874}
4875
4876GpStatus WINGDIPAPI GdipTransformPointsI(GpGraphics *graphics, GpCoordinateSpace dst_space,
4877 GpCoordinateSpace src_space, GpPoint *points, INT count)
4878{
Vincent Povirkc486e812009-05-19 15:40:43 -05004879 GpPointF *pointsF;
4880 GpStatus ret;
4881 INT i;
Huw Davies3ab76662008-07-10 15:26:58 +01004882
Vincent Povirkc486e812009-05-19 15:40:43 -05004883 TRACE("(%p, %d, %d, %p, %d)\n", graphics, dst_space, src_space, points, count);
4884
4885 if(count <= 0)
4886 return InvalidParameter;
4887
4888 pointsF = GdipAlloc(sizeof(GpPointF) * count);
4889 if(!pointsF)
4890 return OutOfMemory;
4891
4892 for(i = 0; i < count; i++){
4893 pointsF[i].X = (REAL)points[i].X;
4894 pointsF[i].Y = (REAL)points[i].Y;
4895 }
4896
4897 ret = GdipTransformPoints(graphics, dst_space, src_space, pointsF, count);
4898
4899 if(ret == Ok)
4900 for(i = 0; i < count; i++){
4901 points[i].X = roundr(pointsF[i].X);
4902 points[i].Y = roundr(pointsF[i].Y);
4903 }
4904 GdipFree(pointsF);
4905
4906 return ret;
Huw Davies3ab76662008-07-10 15:26:58 +01004907}
Hans Leidekker6122c772008-11-24 10:23:03 +01004908
4909HPALETTE WINGDIPAPI GdipCreateHalftonePalette(void)
4910{
Vincent Povirk9a4618a2010-04-09 10:32:22 -05004911 static int calls;
4912
4913 TRACE("\n");
4914
4915 if (!calls++)
4916 FIXME("stub\n");
Hans Leidekker6122c772008-11-24 10:23:03 +01004917
4918 return NULL;
4919}
Nikolay Sivov5da52e02009-01-31 00:07:30 +03004920
4921/*****************************************************************************
4922 * GdipTranslateClip [GDIPLUS.@]
4923 */
4924GpStatus WINGDIPAPI GdipTranslateClip(GpGraphics *graphics, REAL dx, REAL dy)
4925{
4926 TRACE("(%p, %.2f, %.2f)\n", graphics, dx, dy);
4927
4928 if(!graphics)
4929 return InvalidParameter;
4930
Nikolay Sivov8c096162009-02-02 23:48:01 +03004931 if(graphics->busy)
4932 return ObjectBusy;
4933
Nikolay Sivov5da52e02009-01-31 00:07:30 +03004934 return GdipTranslateRegion(graphics->clip, dx, dy);
4935}
4936
4937/*****************************************************************************
4938 * GdipTranslateClipI [GDIPLUS.@]
4939 */
4940GpStatus WINGDIPAPI GdipTranslateClipI(GpGraphics *graphics, INT dx, INT dy)
4941{
4942 TRACE("(%p, %d, %d)\n", graphics, dx, dy);
4943
4944 if(!graphics)
4945 return InvalidParameter;
4946
Nikolay Sivov8c096162009-02-02 23:48:01 +03004947 if(graphics->busy)
4948 return ObjectBusy;
4949
Nikolay Sivov5da52e02009-01-31 00:07:30 +03004950 return GdipTranslateRegion(graphics->clip, (REAL)dx, (REAL)dy);
4951}
Ken Sharpe3f48592009-06-09 21:48:05 +01004952
4953
4954/*****************************************************************************
4955 * GdipMeasureDriverString [GDIPLUS.@]
4956 */
4957GpStatus WINGDIPAPI GdipMeasureDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
4958 GDIPCONST GpFont *font, GDIPCONST PointF *positions,
4959 INT flags, GDIPCONST GpMatrix *matrix, RectF *boundingBox)
4960{
4961 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics, text, length, font, positions, flags, matrix, boundingBox);
4962 return NotImplemented;
4963}
4964
4965/*****************************************************************************
Ken Sharpe3f48592009-06-09 21:48:05 +01004966 * GdipDrawDriverString [GDIPLUS.@]
4967 */
4968GpStatus WINGDIPAPI GdipDrawDriverString(GpGraphics *graphics, GDIPCONST UINT16 *text, INT length,
4969 GDIPCONST GpFont *font, GDIPCONST GpBrush *brush,
4970 GDIPCONST PointF *positions, INT flags,
4971 GDIPCONST GpMatrix *matrix )
4972{
Francois Gouget489bd522009-06-15 11:00:03 +02004973 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics, text, length, font, brush, positions, flags, matrix);
Ken Sharpe3f48592009-06-09 21:48:05 +01004974 return NotImplemented;
4975}
Ken Sharpe096b592009-06-22 21:59:59 +01004976
Vincent Povirk48ceb3d2010-06-19 17:27:22 -05004977GpStatus WINGDIPAPI GdipRecordMetafile(HDC hdc, EmfType type, GDIPCONST GpRectF *frameRect,
4978 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
4979{
4980 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
4981 return NotImplemented;
4982}
4983
Ken Sharpe096b592009-06-22 21:59:59 +01004984/*****************************************************************************
Alistair Leslie-Hughes7b2292f2009-07-30 13:56:42 +10004985 * GdipRecordMetafileI [GDIPLUS.@]
4986 */
4987GpStatus WINGDIPAPI GdipRecordMetafileI(HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
4988 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
4989{
4990 FIXME("(%p %d %p %d %p %p): stub\n", hdc, type, frameRect, frameUnit, desc, metafile);
4991 return NotImplemented;
4992}
Alistair Leslie-Hughes03e31f92009-12-23 13:53:27 +11004993
Vincent Povirk0c8ac022010-06-19 17:29:41 -05004994GpStatus WINGDIPAPI GdipRecordMetafileStream(IStream *stream, HDC hdc, EmfType type, GDIPCONST GpRect *frameRect,
4995 MetafileFrameUnit frameUnit, GDIPCONST WCHAR *desc, GpMetafile **metafile)
4996{
4997 FIXME("(%p %p %d %p %d %p %p): stub\n", stream, hdc, type, frameRect, frameUnit, desc, metafile);
4998 return NotImplemented;
4999}
5000
Alistair Leslie-Hughes03e31f92009-12-23 13:53:27 +11005001/*****************************************************************************
5002 * GdipIsVisibleClipEmpty [GDIPLUS.@]
5003 */
5004GpStatus WINGDIPAPI GdipIsVisibleClipEmpty(GpGraphics *graphics, BOOL *res)
5005{
5006 GpStatus stat;
5007 GpRegion* rgn;
5008
5009 TRACE("(%p, %p)\n", graphics, res);
5010
5011 if((stat = GdipCreateRegion(&rgn)) != Ok)
5012 return stat;
5013
5014 if((stat = get_visible_clip_region(graphics, rgn)) != Ok)
5015 goto cleanup;
5016
5017 stat = GdipIsEmptyRegion(rgn, graphics, res);
5018
5019cleanup:
5020 GdipDeleteRegion(rgn);
5021 return stat;
5022}