2 * Copyright (C) 2007 Google (Evan Stade)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/unicode.h"
39 #include "gdiplus_private.h"
40 #include "wine/debug.h"
41 #include "wine/list.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
45 /* looks-right constants */
46 #define ANCHOR_WIDTH (2.0)
47 #define MAX_ITERS (50)
49 /* Converts angle (in degrees) to x/y coordinates */
50 static void deg2xy(REAL angle
, REAL x_0
, REAL y_0
, REAL
*x
, REAL
*y
)
52 REAL radAngle
, hypotenuse
;
54 radAngle
= deg2rad(angle
);
55 hypotenuse
= 50.0; /* arbitrary */
57 *x
= x_0
+ cos(radAngle
) * hypotenuse
;
58 *y
= y_0
+ sin(radAngle
) * hypotenuse
;
61 /* Converts from gdiplus path point type to gdi path point type. */
62 static BYTE
convert_path_point_type(BYTE type
)
66 switch(type
& PathPointTypePathTypeMask
){
67 case PathPointTypeBezier
:
70 case PathPointTypeLine
:
73 case PathPointTypeStart
:
77 ERR("Bad point type\n");
81 if(type
& PathPointTypeCloseSubpath
)
82 ret
|= PT_CLOSEFIGURE
;
87 static REAL
graphics_res(GpGraphics
*graphics
)
89 if (graphics
->image
) return graphics
->image
->xres
;
90 else return (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
93 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
97 INT save_state
= SaveDC(graphics
->hdc
), i
, numdashes
;
99 DWORD dash_array
[MAX_DASHLEN
];
101 EndPath(graphics
->hdc
);
103 if(pen
->unit
== UnitPixel
){
107 /* Get an estimate for the amount the pen width is affected by the world
108 * transform. (This is similar to what some of the wine drivers do.) */
113 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
114 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
115 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
117 width
*= pen
->width
* convert_unit(graphics_res(graphics
),
118 pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
);
121 if(pen
->dash
== DashStyleCustom
){
122 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
124 TRACE("dashes are: ");
125 for(i
= 0; i
< numdashes
; i
++){
126 dash_array
[i
] = roundr(width
* pen
->dashes
[i
]);
127 TRACE("%d, ", dash_array
[i
]);
129 TRACE("\n and the pen style is %x\n", pen
->style
);
131 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
,
132 numdashes
, dash_array
);
135 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
, 0, NULL
);
137 SelectObject(graphics
->hdc
, gdipen
);
142 static void restore_dc(GpGraphics
*graphics
, INT state
)
144 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
145 RestoreDC(graphics
->hdc
, state
);
148 /* This helper applies all the changes that the points listed in ptf need in
149 * order to be drawn on the device context. In the end, this should include at
151 * -scaling by page unit
152 * -applying world transformation
153 * -converting from float to int
154 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
155 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
156 * gdi to draw, and these functions would irreparably mess with line widths.
158 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
159 GpPointF
*ptf
, INT count
)
165 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
167 /* apply page scale */
168 if(graphics
->unit
!= UnitDisplay
)
169 unitscale
*= graphics
->scale
;
171 GdipCloneMatrix(graphics
->worldtrans
, &matrix
);
172 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
173 GdipTransformMatrixPoints(matrix
, ptf
, count
);
174 GdipDeleteMatrix(matrix
);
176 for(i
= 0; i
< count
; i
++){
177 pti
[i
].x
= roundr(ptf
[i
].X
);
178 pti
[i
].y
= roundr(ptf
[i
].Y
);
182 /* Draw non-premultiplied ARGB data to the given graphics object */
183 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
184 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
186 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
188 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
191 for (x
=0; x
<src_width
; x
++)
193 for (y
=0; y
<src_height
; y
++)
195 ARGB dst_color
, src_color
;
196 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
197 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
198 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
207 HBITMAP hbitmap
, old_hbm
=NULL
;
208 BITMAPINFOHEADER bih
;
212 hdc
= CreateCompatibleDC(0);
214 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
215 bih
.biWidth
= src_width
;
216 bih
.biHeight
= -src_height
;
219 bih
.biCompression
= BI_RGB
;
221 bih
.biXPelsPerMeter
= 0;
222 bih
.biYPelsPerMeter
= 0;
224 bih
.biClrImportant
= 0;
226 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
227 (void**)&temp_bits
, NULL
, 0);
229 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
230 4 * src_width
, src
, src_stride
);
232 old_hbm
= SelectObject(hdc
, hbitmap
);
234 bf
.BlendOp
= AC_SRC_OVER
;
236 bf
.SourceConstantAlpha
= 255;
237 bf
.AlphaFormat
= AC_SRC_ALPHA
;
239 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, src_width
, src_height
,
240 hdc
, 0, 0, src_width
, src_height
, bf
);
242 SelectObject(hdc
, old_hbm
);
244 DeleteObject(hbitmap
);
250 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
254 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
255 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
259 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
263 /* clamp to between 0.0 and 1.0, using the wrap mode */
264 if (brush
->wrap
== WrapModeTile
)
266 position
= fmodf(position
, 1.0f
);
267 if (position
< 0.0f
) position
+= 1.0f
;
269 else /* WrapModeFlip* */
271 position
= fmodf(position
, 2.0f
);
272 if (position
< 0.0f
) position
+= 2.0f
;
273 if (position
> 1.0f
) position
= 2.0f
- position
;
276 if (brush
->blendcount
== 1)
281 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
284 /* locate the blend positions surrounding this position */
285 while (position
> brush
->blendpos
[i
])
288 /* interpolate between the blend positions */
289 left_blendpos
= brush
->blendpos
[i
-1];
290 left_blendfac
= brush
->blendfac
[i
-1];
291 right_blendpos
= brush
->blendpos
[i
];
292 right_blendfac
= brush
->blendfac
[i
];
293 range
= right_blendpos
- left_blendpos
;
294 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
295 right_blendfac
* (position
- left_blendpos
)) / range
;
298 if (brush
->pblendcount
== 0)
299 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
303 ARGB left_blendcolor
, right_blendcolor
;
304 REAL left_blendpos
, right_blendpos
;
306 /* locate the blend colors surrounding this position */
307 while (blendfac
> brush
->pblendpos
[i
])
310 /* interpolate between the blend colors */
311 left_blendpos
= brush
->pblendpos
[i
-1];
312 left_blendcolor
= brush
->pblendcolor
[i
-1];
313 right_blendpos
= brush
->pblendpos
[i
];
314 right_blendcolor
= brush
->pblendcolor
[i
];
315 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
316 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
320 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
324 case BrushTypeLinearGradient
:
326 GpLineGradient
*line
= (GpLineGradient
*)brush
;
329 SelectClipPath(graphics
->hdc
, RGN_AND
);
330 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
332 GpPointF endpointsf
[2];
336 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
338 endpointsf
[0] = line
->startpoint
;
339 endpointsf
[1] = line
->endpoint
;
340 transform_and_round_points(graphics
, endpointsi
, endpointsf
, 2);
342 if (abs(endpointsi
[0].x
-endpointsi
[1].x
) > abs(endpointsi
[0].y
-endpointsi
[1].y
))
344 /* vertical-ish gradient */
345 int startx
, endx
; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
346 int startbottomx
; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
349 HBRUSH hbrush
, hprevbrush
;
350 int leftx
, rightx
; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
352 int tilt
; /* horizontal distance covered by a gradient line */
354 startx
= roundr((rc
.top
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
355 endx
= roundr((rc
.top
- endpointsf
[1].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[1].X
);
356 width
= endx
- startx
;
357 startbottomx
= roundr((rc
.bottom
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
358 tilt
= startx
- startbottomx
;
360 if (startx
>= startbottomx
)
363 rightx
= rc
.right
+ tilt
;
367 leftx
= rc
.left
+ tilt
;
371 poly
[0].y
= rc
.bottom
;
374 poly
[3].y
= rc
.bottom
;
376 for (x
=leftx
; x
<=rightx
; x
++)
378 ARGB argb
= blend_line_gradient(line
, (x
-startx
)/(REAL
)width
);
379 col
= ARGB2COLORREF(argb
);
380 hbrush
= CreateSolidBrush(col
);
381 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
382 poly
[0].x
= x
- tilt
- 1;
385 poly
[3].x
= x
- tilt
;
386 Polygon(graphics
->hdc
, poly
, 4);
387 SelectObject(graphics
->hdc
, hprevbrush
);
388 DeleteObject(hbrush
);
391 else if (endpointsi
[0].y
!= endpointsi
[1].y
)
393 /* horizontal-ish gradient */
394 int starty
, endy
; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
395 int startrighty
; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
398 HBRUSH hbrush
, hprevbrush
;
399 int topy
, bottomy
; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
401 int tilt
; /* vertical distance covered by a gradient line */
403 starty
= roundr((rc
.left
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
404 endy
= roundr((rc
.left
- endpointsf
[1].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[1].Y
);
405 height
= endy
- starty
;
406 startrighty
= roundr((rc
.right
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
407 tilt
= starty
- startrighty
;
409 if (starty
>= startrighty
)
412 bottomy
= rc
.bottom
+ tilt
;
416 topy
= rc
.top
+ tilt
;
420 poly
[0].x
= rc
.right
;
423 poly
[3].x
= rc
.right
;
425 for (y
=topy
; y
<=bottomy
; y
++)
427 ARGB argb
= blend_line_gradient(line
, (y
-starty
)/(REAL
)height
);
428 col
= ARGB2COLORREF(argb
);
429 hbrush
= CreateSolidBrush(col
);
430 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
431 poly
[0].y
= y
- tilt
- 1;
434 poly
[3].y
= y
- tilt
;
435 Polygon(graphics
->hdc
, poly
, 4);
436 SelectObject(graphics
->hdc
, hprevbrush
);
437 DeleteObject(hbrush
);
440 /* else startpoint == endpoint */
444 case BrushTypeSolidColor
:
446 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
450 /* partially transparent fill */
452 SelectClipPath(graphics
->hdc
, RGN_AND
);
453 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
455 HDC hdc
= CreateCompatibleDC(NULL
);
461 oldbmp
= SelectObject(hdc
, fill
->bmp
);
463 bf
.BlendOp
= AC_SRC_OVER
;
465 bf
.SourceConstantAlpha
= 255;
466 bf
.AlphaFormat
= AC_SRC_ALPHA
;
468 GdiAlphaBlend(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, hdc
, 0, 0, 1, 1, bf
);
470 SelectObject(hdc
, oldbmp
);
476 /* else fall through */
479 SelectObject(graphics
->hdc
, brush
->gdibrush
);
480 FillPath(graphics
->hdc
);
485 /* GdipDrawPie/GdipFillPie helper function */
486 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
487 REAL height
, REAL startAngle
, REAL sweepAngle
)
494 ptf
[1].X
= x
+ width
;
495 ptf
[1].Y
= y
+ height
;
497 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
498 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
500 transform_and_round_points(graphics
, pti
, ptf
, 4);
502 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
503 pti
[2].y
, pti
[3].x
, pti
[3].y
);
506 /* Draws the linecap the specified color and size on the hdc. The linecap is in
507 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
508 * should not be called on an hdc that has a path you care about. */
509 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
510 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
512 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
513 GpMatrix
*matrix
= NULL
;
516 PointF ptf
[4], *custptf
= NULL
;
517 POINT pt
[4], *custpt
= NULL
;
519 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
524 if((x1
== x2
) && (y1
== y2
))
527 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
529 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
531 brush
= CreateSolidBrush(color
);
532 lb
.lbStyle
= BS_SOLID
;
535 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
536 PS_JOIN_MITER
, 1, &lb
, 0,
538 oldbrush
= SelectObject(graphics
->hdc
, brush
);
539 oldpen
= SelectObject(graphics
->hdc
, pen
);
546 case LineCapSquareAnchor
:
547 case LineCapDiamondAnchor
:
548 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
549 if(cap
== LineCapDiamondAnchor
){
550 dsmall
= cos(theta
+ M_PI_2
) * size
;
551 dbig
= sin(theta
+ M_PI_2
) * size
;
554 dsmall
= cos(theta
+ M_PI_4
) * size
;
555 dbig
= sin(theta
+ M_PI_4
) * size
;
558 ptf
[0].X
= x2
- dsmall
;
559 ptf
[1].X
= x2
+ dbig
;
561 ptf
[0].Y
= y2
- dbig
;
562 ptf
[3].Y
= y2
+ dsmall
;
564 ptf
[1].Y
= y2
- dsmall
;
565 ptf
[2].Y
= y2
+ dbig
;
567 ptf
[3].X
= x2
- dbig
;
568 ptf
[2].X
= x2
+ dsmall
;
570 transform_and_round_points(graphics
, pt
, ptf
, 4);
571 Polygon(graphics
->hdc
, pt
, 4);
574 case LineCapArrowAnchor
:
575 size
= size
* 4.0 / sqrt(3.0);
577 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
578 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
583 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
584 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
592 transform_and_round_points(graphics
, pt
, ptf
, 3);
593 Polygon(graphics
->hdc
, pt
, 3);
596 case LineCapRoundAnchor
:
597 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
604 transform_and_round_points(graphics
, pt
, ptf
, 2);
605 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
608 case LineCapTriangle
:
610 dx
= cos(M_PI_2
+ theta
) * size
;
611 dy
= sin(M_PI_2
+ theta
) * size
;
618 dx
= cos(theta
) * size
;
619 dy
= sin(theta
) * size
;
624 transform_and_round_points(graphics
, pt
, ptf
, 3);
625 Polygon(graphics
->hdc
, pt
, 3);
629 dx
= dy
= size
/ 2.0;
636 dx
= -cos(M_PI_2
+ theta
) * size
;
637 dy
= -sin(M_PI_2
+ theta
) * size
;
644 transform_and_round_points(graphics
, pt
, ptf
, 4);
645 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
646 pt
[2].y
, pt
[3].x
, pt
[3].y
);
653 count
= custom
->pathdata
.Count
;
654 custptf
= GdipAlloc(count
* sizeof(PointF
));
655 custpt
= GdipAlloc(count
* sizeof(POINT
));
656 tp
= GdipAlloc(count
);
658 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
661 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
663 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
664 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
666 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
667 GdipTransformMatrixPoints(matrix
, custptf
, count
);
669 transform_and_round_points(graphics
, custpt
, custptf
, count
);
671 for(i
= 0; i
< count
; i
++)
672 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
675 BeginPath(graphics
->hdc
);
676 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
677 EndPath(graphics
->hdc
);
678 StrokeAndFillPath(graphics
->hdc
);
681 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
687 GdipDeleteMatrix(matrix
);
694 SelectObject(graphics
->hdc
, oldbrush
);
695 SelectObject(graphics
->hdc
, oldpen
);
701 /* Shortens the line by the given percent by changing x2, y2.
702 * If percent is > 1.0 then the line will change direction.
703 * If percent is negative it can lengthen the line. */
704 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
706 REAL dist
, theta
, dx
, dy
;
708 if((y1
== *y2
) && (x1
== *x2
))
711 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
712 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
713 dx
= cos(theta
) * dist
;
714 dy
= sin(theta
) * dist
;
720 /* Shortens the line by the given amount by changing x2, y2.
721 * If the amount is greater than the distance, the line will become length 0.
722 * If the amount is negative, it can lengthen the line. */
723 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
725 REAL dx
, dy
, percent
;
729 if(dx
== 0 && dy
== 0)
732 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
739 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
742 /* Draws lines between the given points, and if caps is true then draws an endcap
743 * at the end of the last line. */
744 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
745 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
748 GpPointF
*ptcopy
= NULL
;
749 GpStatus status
= GenericError
;
754 pti
= GdipAlloc(count
* sizeof(POINT
));
755 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
758 status
= OutOfMemory
;
762 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
765 if(pen
->endcap
== LineCapArrowAnchor
)
766 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
767 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
768 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
769 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
770 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
771 pen
->customend
->inset
* pen
->width
);
773 if(pen
->startcap
== LineCapArrowAnchor
)
774 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
775 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
776 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
777 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
778 &ptcopy
[0].X
, &ptcopy
[0].Y
,
779 pen
->customstart
->inset
* pen
->width
);
781 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
782 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
783 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
784 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
787 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
789 if(Polyline(graphics
->hdc
, pti
, count
))
799 /* Conducts a linear search to find the bezier points that will back off
800 * the endpoint of the curve by a distance of amt. Linear search works
801 * better than binary in this case because there are multiple solutions,
802 * and binary searches often find a bad one. I don't think this is what
803 * Windows does but short of rendering the bezier without GDI's help it's
804 * the best we can do. If rev then work from the start of the passed points
805 * instead of the end. */
806 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
809 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
810 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
819 origx
= pt
[fourth
].X
;
820 origy
= pt
[fourth
].Y
;
821 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
823 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
824 /* reset bezier points to original values */
825 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
826 /* Perform magic on bezier points. Order is important here.*/
827 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
828 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
829 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
830 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
831 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
832 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
834 dx
= pt
[fourth
].X
- origx
;
835 dy
= pt
[fourth
].Y
- origy
;
837 diff
= sqrt(dx
* dx
+ dy
* dy
);
838 percent
+= 0.0005 * amt
;
842 /* Draws bezier curves between given points, and if caps is true then draws an
843 * endcap at the end of the last line. */
844 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
845 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
849 GpStatus status
= GenericError
;
854 pti
= GdipAlloc(count
* sizeof(POINT
));
855 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
858 status
= OutOfMemory
;
862 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
865 if(pen
->endcap
== LineCapArrowAnchor
)
866 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
867 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
868 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
871 if(pen
->startcap
== LineCapArrowAnchor
)
872 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
873 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
874 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
876 /* the direction of the line cap is parallel to the direction at the
877 * end of the bezier (which, if it has been shortened, is not the same
878 * as the direction from pt[count-2] to pt[count-1]) */
879 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
880 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
881 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
882 pt
[count
- 1].X
, pt
[count
- 1].Y
);
884 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
885 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
886 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
889 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
891 PolyBezier(graphics
->hdc
, pti
, count
);
902 /* Draws a combination of bezier curves and lines between points. */
903 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
904 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
906 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
907 BYTE
*tp
= GdipAlloc(count
);
908 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
910 GpStatus status
= GenericError
;
916 if(!pti
|| !tp
|| !ptcopy
){
917 status
= OutOfMemory
;
921 for(i
= 1; i
< count
; i
++){
922 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
923 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
924 || !(types
[i
+ 1] & PathPointTypeBezier
)){
925 ERR("Bad bezier points\n");
932 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
934 /* If we are drawing caps, go through the points and adjust them accordingly,
935 * and draw the caps. */
937 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
938 case PathPointTypeBezier
:
939 if(pen
->endcap
== LineCapArrowAnchor
)
940 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
941 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
942 shorten_bezier_amt(&ptcopy
[count
- 4],
943 pen
->width
* pen
->customend
->inset
, FALSE
);
945 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
946 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
947 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
948 pt
[count
- 1].X
, pt
[count
- 1].Y
);
951 case PathPointTypeLine
:
952 if(pen
->endcap
== LineCapArrowAnchor
)
953 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
954 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
956 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
957 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
958 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
959 pen
->customend
->inset
* pen
->width
);
961 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
962 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
967 ERR("Bad path last point\n");
971 /* Find start of points */
972 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
973 == PathPointTypeStart
); j
++);
975 switch(types
[j
] & PathPointTypePathTypeMask
){
976 case PathPointTypeBezier
:
977 if(pen
->startcap
== LineCapArrowAnchor
)
978 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
979 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
980 shorten_bezier_amt(&ptcopy
[j
- 1],
981 pen
->width
* pen
->customstart
->inset
, TRUE
);
983 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
984 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
985 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
986 pt
[j
- 1].X
, pt
[j
- 1].Y
);
989 case PathPointTypeLine
:
990 if(pen
->startcap
== LineCapArrowAnchor
)
991 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
992 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
994 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
995 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
996 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
997 pen
->customstart
->inset
* pen
->width
);
999 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
1000 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1005 ERR("Bad path points\n");
1010 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1012 for(i
= 0; i
< count
; i
++){
1013 tp
[i
] = convert_path_point_type(types
[i
]);
1016 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1028 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1032 BeginPath(graphics
->hdc
);
1033 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1034 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1035 EndPath(graphics
->hdc
);
1039 typedef struct _GraphicsContainerItem
{
1041 GraphicsContainer contid
;
1043 SmoothingMode smoothing
;
1044 CompositingQuality compqual
;
1045 InterpolationMode interpolation
;
1046 CompositingMode compmode
;
1047 TextRenderingHint texthint
;
1050 PixelOffsetMode pixeloffset
;
1052 GpMatrix
* worldtrans
;
1054 } GraphicsContainerItem
;
1056 static GpStatus
init_container(GraphicsContainerItem
** container
,
1057 GDIPCONST GpGraphics
* graphics
){
1060 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1064 (*container
)->contid
= graphics
->contid
+ 1;
1066 (*container
)->smoothing
= graphics
->smoothing
;
1067 (*container
)->compqual
= graphics
->compqual
;
1068 (*container
)->interpolation
= graphics
->interpolation
;
1069 (*container
)->compmode
= graphics
->compmode
;
1070 (*container
)->texthint
= graphics
->texthint
;
1071 (*container
)->scale
= graphics
->scale
;
1072 (*container
)->unit
= graphics
->unit
;
1073 (*container
)->textcontrast
= graphics
->textcontrast
;
1074 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1076 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
1078 GdipFree(*container
);
1083 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1085 GdipDeleteMatrix((*container
)->worldtrans
);
1086 GdipFree(*container
);
1094 static void delete_container(GraphicsContainerItem
* container
){
1095 GdipDeleteMatrix(container
->worldtrans
);
1096 GdipDeleteRegion(container
->clip
);
1097 GdipFree(container
);
1100 static GpStatus
restore_container(GpGraphics
* graphics
,
1101 GDIPCONST GraphicsContainerItem
* container
){
1106 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
1110 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1112 GdipDeleteMatrix(newTrans
);
1116 GdipDeleteMatrix(graphics
->worldtrans
);
1117 graphics
->worldtrans
= newTrans
;
1119 GdipDeleteRegion(graphics
->clip
);
1120 graphics
->clip
= newClip
;
1122 graphics
->contid
= container
->contid
- 1;
1124 graphics
->smoothing
= container
->smoothing
;
1125 graphics
->compqual
= container
->compqual
;
1126 graphics
->interpolation
= container
->interpolation
;
1127 graphics
->compmode
= container
->compmode
;
1128 graphics
->texthint
= container
->texthint
;
1129 graphics
->scale
= container
->scale
;
1130 graphics
->unit
= container
->unit
;
1131 graphics
->textcontrast
= container
->textcontrast
;
1132 graphics
->pixeloffset
= container
->pixeloffset
;
1137 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1141 if(graphics
->hwnd
) {
1142 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1143 return GenericError
;
1145 rect
->X
= wnd_rect
.left
;
1146 rect
->Y
= wnd_rect
.top
;
1147 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1148 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1152 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
1153 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
1159 /* on success, rgn will contain the region of the graphics object which
1160 * is visible after clipping has been applied */
1161 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
1167 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
1170 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
1173 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
1176 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
1179 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
1182 GdipDeleteRegion(tmp
);
1186 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
1188 TRACE("(%p, %p)\n", hdc
, graphics
);
1190 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
1193 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
1197 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
1199 if(hDevice
!= NULL
) {
1200 FIXME("Don't know how to handle parameter hDevice\n");
1201 return NotImplemented
;
1207 if(graphics
== NULL
)
1208 return InvalidParameter
;
1210 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1211 if(!*graphics
) return OutOfMemory
;
1213 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1214 GdipFree(*graphics
);
1218 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1219 GdipFree((*graphics
)->worldtrans
);
1220 GdipFree(*graphics
);
1224 (*graphics
)->hdc
= hdc
;
1225 (*graphics
)->hwnd
= WindowFromDC(hdc
);
1226 (*graphics
)->owndc
= FALSE
;
1227 (*graphics
)->smoothing
= SmoothingModeDefault
;
1228 (*graphics
)->compqual
= CompositingQualityDefault
;
1229 (*graphics
)->interpolation
= InterpolationModeDefault
;
1230 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1231 (*graphics
)->compmode
= CompositingModeSourceOver
;
1232 (*graphics
)->unit
= UnitDisplay
;
1233 (*graphics
)->scale
= 1.0;
1234 (*graphics
)->busy
= FALSE
;
1235 (*graphics
)->textcontrast
= 4;
1236 list_init(&(*graphics
)->containers
);
1237 (*graphics
)->contid
= 0;
1239 TRACE("<-- %p\n", *graphics
);
1244 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
1249 TRACE("(%p, %p)\n", hwnd
, graphics
);
1253 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
1255 ReleaseDC(hwnd
, hdc
);
1259 (*graphics
)->hwnd
= hwnd
;
1260 (*graphics
)->owndc
= TRUE
;
1265 /* FIXME: no icm handling */
1266 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
1268 TRACE("(%p, %p)\n", hwnd
, graphics
);
1270 return GdipCreateFromHWND(hwnd
, graphics
);
1273 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
1274 GpMetafile
**metafile
)
1278 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
1280 if(!hemf
|| !metafile
)
1281 return InvalidParameter
;
1284 FIXME("not implemented\n");
1286 return NotImplemented
;
1289 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
1290 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1292 IStream
*stream
= NULL
;
1296 GpStatus retval
= Ok
;
1298 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
1300 if(!hwmf
|| !metafile
|| !placeable
)
1301 return InvalidParameter
;
1304 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
1306 return GenericError
;
1307 copy
= GdipAlloc(read
);
1308 GetMetaFileBitsEx(hwmf
, read
, copy
);
1310 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1313 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
1314 copy
= GdipAlloc(read
);
1315 GetEnhMetaFileBits(hemf
, read
, copy
);
1316 DeleteEnhMetaFile(hemf
);
1318 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
1319 ERR("could not make stream\n");
1321 retval
= GenericError
;
1325 *metafile
= GdipAlloc(sizeof(GpMetafile
));
1327 retval
= OutOfMemory
;
1331 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1332 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
1334 retval
= GenericError
;
1339 (*metafile
)->image
.type
= ImageTypeMetafile
;
1340 memcpy(&(*metafile
)->image
.format
, &ImageFormatWMF
, sizeof(GUID
));
1341 (*metafile
)->image
.palette_flags
= 0;
1342 (*metafile
)->image
.palette_count
= 0;
1343 (*metafile
)->image
.palette_size
= 0;
1344 (*metafile
)->image
.palette_entries
= NULL
;
1345 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
1346 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
1347 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
1348 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Top
) / ((REAL
) placeable
->Inch
);
1349 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
1350 - placeable
->BoundingBox
.Left
));
1351 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
1352 - placeable
->BoundingBox
.Top
));
1353 (*metafile
)->unit
= UnitPixel
;
1356 DeleteMetaFile(hwmf
);
1358 TRACE("<-- %p\n", *metafile
);
1362 GdipFree(*metafile
);
1363 IStream_Release(stream
);
1367 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1368 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1370 HMETAFILE hmf
= GetMetaFileW(file
);
1372 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1374 if(!hmf
) return InvalidParameter
;
1376 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1379 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
1380 GpMetafile
**metafile
)
1382 FIXME("(%p, %p): stub\n", file
, metafile
);
1383 return NotImplemented
;
1386 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
1387 GpMetafile
**metafile
)
1389 FIXME("(%p, %p): stub\n", stream
, metafile
);
1390 return NotImplemented
;
1393 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
1394 UINT access
, IStream
**stream
)
1399 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
1401 if(!stream
|| !filename
)
1402 return InvalidParameter
;
1404 if(access
& GENERIC_WRITE
)
1405 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
1406 else if(access
& GENERIC_READ
)
1407 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
1409 return InvalidParameter
;
1411 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
1413 return hresult_to_status(ret
);
1416 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
1418 GraphicsContainerItem
*cont
, *next
;
1419 TRACE("(%p)\n", graphics
);
1421 if(!graphics
) return InvalidParameter
;
1422 if(graphics
->busy
) return ObjectBusy
;
1425 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
1427 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
1428 list_remove(&cont
->entry
);
1429 delete_container(cont
);
1432 GdipDeleteRegion(graphics
->clip
);
1433 GdipDeleteMatrix(graphics
->worldtrans
);
1439 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1440 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1442 INT save_state
, num_pts
;
1443 GpPointF points
[MAX_ARC_PTS
];
1446 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1447 width
, height
, startAngle
, sweepAngle
);
1449 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
1450 return InvalidParameter
;
1455 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1457 save_state
= prepare_dc(graphics
, pen
);
1459 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
1461 restore_dc(graphics
, save_state
);
1466 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1467 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1469 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1470 width
, height
, startAngle
, sweepAngle
);
1472 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1475 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1476 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
1482 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
1483 x2
, y2
, x3
, y3
, x4
, y4
);
1485 if(!graphics
|| !pen
)
1486 return InvalidParameter
;
1500 save_state
= prepare_dc(graphics
, pen
);
1502 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1504 restore_dc(graphics
, save_state
);
1509 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1510 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
1516 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
1517 x2
, y2
, x3
, y3
, x4
, y4
);
1519 if(!graphics
|| !pen
)
1520 return InvalidParameter
;
1534 save_state
= prepare_dc(graphics
, pen
);
1536 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1538 restore_dc(graphics
, save_state
);
1543 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
1544 GDIPCONST GpPointF
*points
, INT count
)
1549 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1551 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1552 return InvalidParameter
;
1557 for(i
= 0; i
< floor(count
/ 4); i
++){
1558 ret
= GdipDrawBezier(graphics
, pen
,
1559 points
[4*i
].X
, points
[4*i
].Y
,
1560 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
1561 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
1562 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
1570 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
1571 GDIPCONST GpPoint
*points
, INT count
)
1577 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1579 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1580 return InvalidParameter
;
1585 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
1589 for(i
= 0; i
< count
; i
++){
1590 pts
[i
].X
= (REAL
)points
[i
].X
;
1591 pts
[i
].Y
= (REAL
)points
[i
].Y
;
1594 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
1601 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
1602 GDIPCONST GpPointF
*points
, INT count
)
1604 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1606 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
1609 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1610 GDIPCONST GpPoint
*points
, INT count
)
1612 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1614 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
1617 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1618 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1623 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1625 if(!graphics
|| !pen
|| !points
|| count
<= 0)
1626 return InvalidParameter
;
1631 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
1634 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1636 GdipDeletePath(path
);
1640 stat
= GdipDrawPath(graphics
, pen
, path
);
1642 GdipDeletePath(path
);
1647 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1648 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1654 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1656 if(!points
|| count
<= 0)
1657 return InvalidParameter
;
1659 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1663 for(i
= 0; i
< count
; i
++){
1664 ptf
[i
].X
= (REAL
)points
[i
].X
;
1665 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1668 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
1675 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
1676 GDIPCONST GpPointF
*points
, INT count
)
1678 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1680 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
1683 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1684 GDIPCONST GpPoint
*points
, INT count
)
1690 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1693 return InvalidParameter
;
1695 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1699 for(i
= 0; i
< count
; i
++){
1700 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1701 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1704 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
1710 /* Approximates cardinal spline with Bezier curves. */
1711 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1712 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1714 /* PolyBezier expects count*3-2 points. */
1715 INT i
, len_pt
= count
*3-2, save_state
;
1717 REAL x1
, x2
, y1
, y2
;
1720 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1722 if(!graphics
|| !pen
)
1723 return InvalidParameter
;
1729 return InvalidParameter
;
1731 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
1735 tension
= tension
* TENSION_CONST
;
1737 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
1740 pt
[0].X
= points
[0].X
;
1741 pt
[0].Y
= points
[0].Y
;
1745 for(i
= 0; i
< count
-2; i
++){
1746 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
1750 pt
[3*i
+3].X
= points
[i
+1].X
;
1751 pt
[3*i
+3].Y
= points
[i
+1].Y
;
1756 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
1757 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
1759 pt
[len_pt
-2].X
= x1
;
1760 pt
[len_pt
-2].Y
= y1
;
1761 pt
[len_pt
-1].X
= points
[count
-1].X
;
1762 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
1764 save_state
= prepare_dc(graphics
, pen
);
1766 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
1769 restore_dc(graphics
, save_state
);
1774 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1775 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1781 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1784 return InvalidParameter
;
1786 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1790 for(i
= 0; i
< count
; i
++){
1791 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1792 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1795 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
1801 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
1802 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
1805 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1807 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1808 return InvalidParameter
;
1811 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1814 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
1815 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
1818 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1824 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1825 return InvalidParameter
;
1828 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1831 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1832 REAL y
, REAL width
, REAL height
)
1838 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1840 if(!graphics
|| !pen
)
1841 return InvalidParameter
;
1848 ptf
[1].X
= x
+ width
;
1849 ptf
[1].Y
= y
+ height
;
1851 save_state
= prepare_dc(graphics
, pen
);
1852 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1854 transform_and_round_points(graphics
, pti
, ptf
, 2);
1856 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1858 restore_dc(graphics
, save_state
);
1863 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1864 INT y
, INT width
, INT height
)
1866 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1868 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1872 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
1877 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
1879 if(!graphics
|| !image
)
1880 return InvalidParameter
;
1882 GdipGetImageWidth(image
, &width
);
1883 GdipGetImageHeight(image
, &height
);
1885 /* FIXME: we should use the graphics and image dpi, somehow */
1887 points
[0].X
= points
[2].X
= x
;
1888 points
[0].Y
= points
[1].Y
= y
;
1889 points
[1].X
= x
+ width
;
1890 points
[2].Y
= y
+ height
;
1892 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, 0, 0, width
, height
,
1893 UnitPixel
, NULL
, NULL
, NULL
);
1896 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
1899 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
1901 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
1904 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
1905 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
1909 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
1911 points
[0].X
= points
[2].X
= x
;
1912 points
[0].Y
= points
[1].Y
= y
;
1914 /* FIXME: convert image coordinates to Graphics coordinates? */
1915 points
[1].X
= x
+ srcwidth
;
1916 points
[2].Y
= y
+ srcheight
;
1918 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1919 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
1922 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
1923 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
1926 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
1929 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
1930 GDIPCONST GpPointF
*dstpoints
, INT count
)
1932 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
1933 return NotImplemented
;
1936 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
1937 GDIPCONST GpPoint
*dstpoints
, INT count
)
1939 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
1940 return NotImplemented
;
1943 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
1944 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
1945 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1946 DrawImageAbort callback
, VOID
* callbackData
)
1953 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
1954 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1957 if(!graphics
|| !image
|| !points
|| count
!= 3)
1958 return InvalidParameter
;
1960 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
1961 debugstr_pointf(&points
[2]));
1963 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
1964 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
1965 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
1966 transform_and_round_points(graphics
, pti
, ptf
, 4);
1970 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1971 if(srcUnit
== UnitInch
)
1972 dx
= dy
= (REAL
) INCH_HIMETRIC
;
1973 else if(srcUnit
== UnitPixel
){
1974 dx
= ((REAL
) INCH_HIMETRIC
) /
1975 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
1976 dy
= ((REAL
) INCH_HIMETRIC
) /
1977 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
1980 return NotImplemented
;
1982 if(IPicture_Render(image
->picture
, graphics
->hdc
,
1983 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
1984 srcx
* dx
, srcy
* dy
,
1985 srcwidth
* dx
, srcheight
* dy
,
1988 callback(callbackData
);
1989 return GenericError
;
1992 else if (image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)image
)->hbitmap
)
1994 GpBitmap
* bitmap
= (GpBitmap
*)image
;
1997 if (srcUnit
== UnitInch
)
1998 dx
= dy
= 96.0; /* FIXME: use the image resolution */
1999 else if (srcUnit
== UnitPixel
)
2002 return NotImplemented
;
2004 if (imageAttributes
||
2005 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
2006 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
)
2011 RECT src_area
, dst_area
;
2012 int i
, x
, y
, stride
;
2013 GpMatrix
*dst_to_src
;
2014 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2017 src_area
.left
= srcx
*dx
;
2018 src_area
.top
= srcy
*dy
;
2019 src_area
.right
= (srcx
+srcwidth
)*dx
;
2020 src_area
.bottom
= (srcy
+srcheight
)*dy
;
2022 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2023 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2026 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2027 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2028 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2029 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2032 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2033 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2034 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2035 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2036 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2037 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2039 stat
= GdipCreateMatrix2(m11
, m12
, m21
, m22
, mdx
, mdy
, &dst_to_src
);
2040 if (stat
!= Ok
) return stat
;
2042 stat
= GdipInvertMatrix(dst_to_src
);
2045 GdipDeleteMatrix(dst_to_src
);
2049 data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
2052 GdipDeleteMatrix(dst_to_src
);
2056 stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
2058 if (imageAttributes
&&
2059 (imageAttributes
->wrap
!= WrapModeClamp
||
2060 imageAttributes
->outside_color
!= 0x00000000 ||
2061 imageAttributes
->clamp
))
2065 FIXME("Image wrap mode not implemented\n");
2068 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2070 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2072 GpPointF src_pointf
;
2079 GdipTransformMatrixPoints(dst_to_src
, &src_pointf
, 1);
2081 src_x
= roundr(src_pointf
.X
);
2082 src_y
= roundr(src_pointf
.Y
);
2084 src_color
= (ARGB
*)(data
+ stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2086 if (src_x
< src_area
.left
|| src_x
>= src_area
.right
||
2087 src_y
< src_area
.top
|| src_y
>= src_area
.bottom
)
2090 GdipBitmapGetPixel(bitmap
, src_x
, src_y
, src_color
);
2094 GdipDeleteMatrix(dst_to_src
);
2096 if (imageAttributes
)
2098 if (imageAttributes
->colorkeys
[ColorAdjustTypeBitmap
].enabled
||
2099 imageAttributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
2101 const struct color_key
*key
;
2102 BYTE min_blue
, min_green
, min_red
;
2103 BYTE max_blue
, max_green
, max_red
;
2105 if (imageAttributes
->colorkeys
[ColorAdjustTypeBitmap
].enabled
)
2106 key
= &imageAttributes
->colorkeys
[ColorAdjustTypeBitmap
];
2108 key
= &imageAttributes
->colorkeys
[ColorAdjustTypeDefault
];
2110 min_blue
= key
->low
&0xff;
2111 min_green
= (key
->low
>>8)&0xff;
2112 min_red
= (key
->low
>>16)&0xff;
2114 max_blue
= key
->high
&0xff;
2115 max_green
= (key
->high
>>8)&0xff;
2116 max_red
= (key
->high
>>16)&0xff;
2118 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2119 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2122 BYTE blue
, green
, red
;
2123 src_color
= (ARGB
*)(data
+ stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2124 blue
= *src_color
&0xff;
2125 green
= (*src_color
>>8)&0xff;
2126 red
= (*src_color
>>16)&0xff;
2127 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
2128 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
2129 *src_color
= 0x00000000;
2133 if (imageAttributes
->colorremaptables
[ColorAdjustTypeBitmap
].enabled
||
2134 imageAttributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
2136 const struct color_remap_table
*table
;
2138 if (imageAttributes
->colorremaptables
[ColorAdjustTypeBitmap
].enabled
)
2139 table
= &imageAttributes
->colorremaptables
[ColorAdjustTypeBitmap
];
2141 table
= &imageAttributes
->colorremaptables
[ColorAdjustTypeDefault
];
2143 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2144 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2147 src_color
= (ARGB
*)(data
+ stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2148 for (i
=0; i
<table
->mapsize
; i
++)
2150 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
2152 *src_color
= table
->colormap
[i
].newColor
.Argb
;
2159 if (imageAttributes
->colormatrices
[ColorAdjustTypeBitmap
].enabled
||
2160 imageAttributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
2164 FIXME("Color transforms not implemented\n");
2167 if (imageAttributes
->gamma_enabled
[ColorAdjustTypeBitmap
] ||
2168 imageAttributes
->gamma_enabled
[ColorAdjustTypeDefault
])
2172 FIXME("Gamma adjustment not implemented\n");
2176 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
2177 data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, stride
);
2186 int temp_hdc
=0, temp_bitmap
=0;
2187 HBITMAP hbitmap
, old_hbm
=NULL
;
2189 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
2190 bitmap
->format
== PixelFormat24bppRGB
||
2191 bitmap
->format
== PixelFormat32bppRGB
||
2192 bitmap
->format
== PixelFormat32bppPARGB
))
2194 BITMAPINFOHEADER bih
;
2196 PixelFormat dst_format
;
2198 /* we can't draw a bitmap of this format directly */
2199 hdc
= CreateCompatibleDC(0);
2203 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
2204 bih
.biWidth
= bitmap
->width
;
2205 bih
.biHeight
= -bitmap
->height
;
2207 bih
.biBitCount
= 32;
2208 bih
.biCompression
= BI_RGB
;
2209 bih
.biSizeImage
= 0;
2210 bih
.biXPelsPerMeter
= 0;
2211 bih
.biYPelsPerMeter
= 0;
2213 bih
.biClrImportant
= 0;
2215 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
2216 (void**)&temp_bits
, NULL
, 0);
2218 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2219 dst_format
= PixelFormat32bppPARGB
;
2221 dst_format
= PixelFormat32bppRGB
;
2223 convert_pixels(bitmap
->width
, bitmap
->height
,
2224 bitmap
->width
*4, temp_bits
, dst_format
,
2225 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette_entries
);
2229 hbitmap
= bitmap
->hbitmap
;
2231 temp_hdc
= (hdc
== 0);
2236 if (!hdc
) hdc
= CreateCompatibleDC(0);
2237 old_hbm
= SelectObject(hdc
, hbitmap
);
2240 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2244 bf
.BlendOp
= AC_SRC_OVER
;
2246 bf
.SourceConstantAlpha
= 255;
2247 bf
.AlphaFormat
= AC_SRC_ALPHA
;
2249 GdiAlphaBlend(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
2250 hdc
, srcx
*dx
, srcy
*dy
, srcwidth
*dx
, srcheight
*dy
, bf
);
2254 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
2255 hdc
, srcx
*dx
, srcy
*dy
, srcwidth
*dx
, srcheight
*dy
, SRCCOPY
);
2260 SelectObject(hdc
, old_hbm
);
2265 DeleteObject(hbitmap
);
2270 ERR("GpImage with no IPicture or HBITMAP?!\n");
2271 return NotImplemented
;
2277 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
2278 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
2279 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2280 DrawImageAbort callback
, VOID
* callbackData
)
2282 GpPointF pointsF
[3];
2285 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
2286 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2289 if(!points
|| count
!=3)
2290 return InvalidParameter
;
2292 for(i
= 0; i
< count
; i
++){
2293 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2294 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2297 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
2298 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
2299 callback
, callbackData
);
2302 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
2303 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
2304 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
2305 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
2306 VOID
* callbackData
)
2310 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
2311 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2312 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2316 points
[1].X
= dstx
+ dstwidth
;
2319 points
[2].Y
= dsty
+ dstheight
;
2321 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2322 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2325 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
2326 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
2327 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
2328 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
2329 VOID
* callbackData
)
2333 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
2334 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2335 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2339 points
[1].X
= dstx
+ dstwidth
;
2342 points
[2].Y
= dsty
+ dstheight
;
2344 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2345 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2348 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
2349 REAL x
, REAL y
, REAL width
, REAL height
)
2355 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
2357 if(!graphics
|| !image
)
2358 return InvalidParameter
;
2360 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
2364 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
2365 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
2366 unit
, NULL
, NULL
, NULL
);
2369 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
2370 INT x
, INT y
, INT width
, INT height
)
2372 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
2374 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
2377 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2378 REAL y1
, REAL x2
, REAL y2
)
2384 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2386 if(!pen
|| !graphics
)
2387 return InvalidParameter
;
2397 save_state
= prepare_dc(graphics
, pen
);
2399 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2401 restore_dc(graphics
, save_state
);
2406 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2407 INT y1
, INT x2
, INT y2
)
2413 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2415 if(!pen
|| !graphics
)
2416 return InvalidParameter
;
2426 save_state
= prepare_dc(graphics
, pen
);
2428 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2430 restore_dc(graphics
, save_state
);
2435 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2436 GpPointF
*points
, INT count
)
2441 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2443 if(!pen
|| !graphics
|| (count
< 2))
2444 return InvalidParameter
;
2449 save_state
= prepare_dc(graphics
, pen
);
2451 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
2453 restore_dc(graphics
, save_state
);
2458 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2459 GpPoint
*points
, INT count
)
2463 GpPointF
*ptf
= NULL
;
2466 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2468 if(!pen
|| !graphics
|| (count
< 2))
2469 return InvalidParameter
;
2474 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2475 if(!ptf
) return OutOfMemory
;
2477 for(i
= 0; i
< count
; i
++){
2478 ptf
[i
].X
= (REAL
) points
[i
].X
;
2479 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2482 save_state
= prepare_dc(graphics
, pen
);
2484 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
2486 restore_dc(graphics
, save_state
);
2492 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
2497 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
2499 if(!pen
|| !graphics
)
2500 return InvalidParameter
;
2505 save_state
= prepare_dc(graphics
, pen
);
2507 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
2508 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
2510 restore_dc(graphics
, save_state
);
2515 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2516 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2520 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2521 width
, height
, startAngle
, sweepAngle
);
2523 if(!graphics
|| !pen
)
2524 return InvalidParameter
;
2529 save_state
= prepare_dc(graphics
, pen
);
2530 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2532 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2534 restore_dc(graphics
, save_state
);
2539 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2540 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2542 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2543 width
, height
, startAngle
, sweepAngle
);
2545 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2548 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2549 REAL y
, REAL width
, REAL height
)
2555 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2557 if(!pen
|| !graphics
)
2558 return InvalidParameter
;
2565 ptf
[1].X
= x
+ width
;
2567 ptf
[2].X
= x
+ width
;
2568 ptf
[2].Y
= y
+ height
;
2570 ptf
[3].Y
= y
+ height
;
2572 save_state
= prepare_dc(graphics
, pen
);
2573 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2575 transform_and_round_points(graphics
, pti
, ptf
, 4);
2576 Polygon(graphics
->hdc
, pti
, 4);
2578 restore_dc(graphics
, save_state
);
2583 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2584 INT y
, INT width
, INT height
)
2586 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2588 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2591 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
2592 GDIPCONST GpRectF
* rects
, INT count
)
2598 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2600 if(!graphics
|| !pen
|| !rects
|| count
< 1)
2601 return InvalidParameter
;
2606 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
2607 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
2615 for(i
= 0; i
< count
; i
++){
2616 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
2617 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
2618 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
2619 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
2622 save_state
= prepare_dc(graphics
, pen
);
2623 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2625 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
2627 for(i
= 0; i
< count
; i
++)
2628 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
2630 restore_dc(graphics
, save_state
);
2638 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
2639 GDIPCONST GpRect
* rects
, INT count
)
2645 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2647 if(!rects
|| count
<=0)
2648 return InvalidParameter
;
2650 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
2654 for(i
= 0;i
< count
;i
++){
2655 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2656 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2657 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
2658 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2661 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
2667 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
2668 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
2673 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2674 count
, tension
, fill
);
2676 if(!graphics
|| !brush
|| !points
)
2677 return InvalidParameter
;
2682 if(count
== 1) /* Do nothing */
2685 stat
= GdipCreatePath(fill
, &path
);
2689 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2691 GdipDeletePath(path
);
2695 stat
= GdipFillPath(graphics
, brush
, path
);
2697 GdipDeletePath(path
);
2701 GdipDeletePath(path
);
2706 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
2707 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
2713 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2714 count
, tension
, fill
);
2716 if(!points
|| count
== 0)
2717 return InvalidParameter
;
2719 if(count
== 1) /* Do nothing */
2722 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2726 for(i
= 0;i
< count
;i
++){
2727 ptf
[i
].X
= (REAL
)points
[i
].X
;
2728 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2731 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
2738 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
2739 GDIPCONST GpPointF
*points
, INT count
)
2741 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2742 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
2743 0.5f
, FillModeAlternate
);
2746 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
2747 GDIPCONST GpPoint
*points
, INT count
)
2749 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2750 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
2751 0.5f
, FillModeAlternate
);
2754 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2755 REAL y
, REAL width
, REAL height
)
2761 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2763 if(!graphics
|| !brush
)
2764 return InvalidParameter
;
2771 ptf
[1].X
= x
+ width
;
2772 ptf
[1].Y
= y
+ height
;
2774 save_state
= SaveDC(graphics
->hdc
);
2775 EndPath(graphics
->hdc
);
2777 transform_and_round_points(graphics
, pti
, ptf
, 2);
2779 BeginPath(graphics
->hdc
);
2780 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2781 EndPath(graphics
->hdc
);
2783 brush_fill_path(graphics
, brush
);
2785 RestoreDC(graphics
->hdc
, save_state
);
2790 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2791 INT y
, INT width
, INT height
)
2793 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2795 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2798 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
2803 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
2805 if(!brush
|| !graphics
|| !path
)
2806 return InvalidParameter
;
2811 save_state
= SaveDC(graphics
->hdc
);
2812 EndPath(graphics
->hdc
);
2813 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
2816 BeginPath(graphics
->hdc
);
2817 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2818 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2823 EndPath(graphics
->hdc
);
2824 brush_fill_path(graphics
, brush
);
2829 RestoreDC(graphics
->hdc
, save_state
);
2834 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2835 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2839 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2840 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2842 if(!graphics
|| !brush
)
2843 return InvalidParameter
;
2848 save_state
= SaveDC(graphics
->hdc
);
2849 EndPath(graphics
->hdc
);
2851 BeginPath(graphics
->hdc
);
2852 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2853 EndPath(graphics
->hdc
);
2855 brush_fill_path(graphics
, brush
);
2857 RestoreDC(graphics
->hdc
, save_state
);
2862 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2863 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2865 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2866 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2868 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2871 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
2872 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
2875 GpPointF
*ptf
= NULL
;
2877 GpStatus retval
= Ok
;
2879 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2881 if(!graphics
|| !brush
|| !points
|| !count
)
2882 return InvalidParameter
;
2887 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2888 pti
= GdipAlloc(count
* sizeof(POINT
));
2890 retval
= OutOfMemory
;
2894 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
2896 save_state
= SaveDC(graphics
->hdc
);
2897 EndPath(graphics
->hdc
);
2898 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2901 transform_and_round_points(graphics
, pti
, ptf
, count
);
2903 BeginPath(graphics
->hdc
);
2904 Polygon(graphics
->hdc
, pti
, count
);
2905 EndPath(graphics
->hdc
);
2907 brush_fill_path(graphics
, brush
);
2909 RestoreDC(graphics
->hdc
, save_state
);
2918 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
2919 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
2922 GpPointF
*ptf
= NULL
;
2924 GpStatus retval
= Ok
;
2926 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2928 if(!graphics
|| !brush
|| !points
|| !count
)
2929 return InvalidParameter
;
2934 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2935 pti
= GdipAlloc(count
* sizeof(POINT
));
2937 retval
= OutOfMemory
;
2941 for(i
= 0; i
< count
; i
++){
2942 ptf
[i
].X
= (REAL
) points
[i
].X
;
2943 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2946 save_state
= SaveDC(graphics
->hdc
);
2947 EndPath(graphics
->hdc
);
2948 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2951 transform_and_round_points(graphics
, pti
, ptf
, count
);
2953 BeginPath(graphics
->hdc
);
2954 Polygon(graphics
->hdc
, pti
, count
);
2955 EndPath(graphics
->hdc
);
2957 brush_fill_path(graphics
, brush
);
2959 RestoreDC(graphics
->hdc
, save_state
);
2968 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
2969 GDIPCONST GpPointF
*points
, INT count
)
2971 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2973 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
2976 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
2977 GDIPCONST GpPoint
*points
, INT count
)
2979 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2981 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
2984 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
2985 REAL x
, REAL y
, REAL width
, REAL height
)
2991 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2993 if(!graphics
|| !brush
)
2994 return InvalidParameter
;
3001 ptf
[1].X
= x
+ width
;
3003 ptf
[2].X
= x
+ width
;
3004 ptf
[2].Y
= y
+ height
;
3006 ptf
[3].Y
= y
+ height
;
3008 save_state
= SaveDC(graphics
->hdc
);
3009 EndPath(graphics
->hdc
);
3011 transform_and_round_points(graphics
, pti
, ptf
, 4);
3013 BeginPath(graphics
->hdc
);
3014 Polygon(graphics
->hdc
, pti
, 4);
3015 EndPath(graphics
->hdc
);
3017 brush_fill_path(graphics
, brush
);
3019 RestoreDC(graphics
->hdc
, save_state
);
3024 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3025 INT x
, INT y
, INT width
, INT height
)
3031 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3033 if(!graphics
|| !brush
)
3034 return InvalidParameter
;
3041 ptf
[1].X
= x
+ width
;
3043 ptf
[2].X
= x
+ width
;
3044 ptf
[2].Y
= y
+ height
;
3046 ptf
[3].Y
= y
+ height
;
3048 save_state
= SaveDC(graphics
->hdc
);
3049 EndPath(graphics
->hdc
);
3051 transform_and_round_points(graphics
, pti
, ptf
, 4);
3053 BeginPath(graphics
->hdc
);
3054 Polygon(graphics
->hdc
, pti
, 4);
3055 EndPath(graphics
->hdc
);
3057 brush_fill_path(graphics
, brush
);
3059 RestoreDC(graphics
->hdc
, save_state
);
3064 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3070 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3073 return InvalidParameter
;
3075 for(i
= 0; i
< count
; i
++){
3076 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
3077 if(ret
!= Ok
) return ret
;
3083 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3090 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3092 if(!rects
|| count
<= 0)
3093 return InvalidParameter
;
3095 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3099 for(i
= 0; i
< count
; i
++){
3100 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3101 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3102 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3103 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3106 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3112 /*****************************************************************************
3113 * GdipFillRegion [GDIPLUS.@]
3115 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3123 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
3125 if (!(graphics
&& brush
&& region
))
3126 return InvalidParameter
;
3131 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3135 save_state
= SaveDC(graphics
->hdc
);
3136 EndPath(graphics
->hdc
);
3138 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3140 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3142 BeginPath(graphics
->hdc
);
3143 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3144 EndPath(graphics
->hdc
);
3146 brush_fill_path(graphics
, brush
);
3149 RestoreDC(graphics
->hdc
, save_state
);
3156 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
3158 TRACE("(%p,%u)\n", graphics
, intention
);
3161 return InvalidParameter
;
3166 /* We have no internal operation queue, so there's no need to clear it. */
3174 /*****************************************************************************
3175 * GdipGetClipBounds [GDIPLUS.@]
3177 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
3179 TRACE("(%p, %p)\n", graphics
, rect
);
3182 return InvalidParameter
;
3187 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
3190 /*****************************************************************************
3191 * GdipGetClipBoundsI [GDIPLUS.@]
3193 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
3195 TRACE("(%p, %p)\n", graphics
, rect
);
3198 return InvalidParameter
;
3203 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
3206 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3207 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
3208 CompositingMode
*mode
)
3210 TRACE("(%p, %p)\n", graphics
, mode
);
3212 if(!graphics
|| !mode
)
3213 return InvalidParameter
;
3218 *mode
= graphics
->compmode
;
3223 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3224 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
3225 CompositingQuality
*quality
)
3227 TRACE("(%p, %p)\n", graphics
, quality
);
3229 if(!graphics
|| !quality
)
3230 return InvalidParameter
;
3235 *quality
= graphics
->compqual
;
3240 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3241 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
3242 InterpolationMode
*mode
)
3244 TRACE("(%p, %p)\n", graphics
, mode
);
3246 if(!graphics
|| !mode
)
3247 return InvalidParameter
;
3252 *mode
= graphics
->interpolation
;
3257 /* FIXME: Need to handle color depths less than 24bpp */
3258 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
3260 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
3262 if(!graphics
|| !argb
)
3263 return InvalidParameter
;
3271 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
3273 TRACE("(%p, %p)\n", graphics
, scale
);
3275 if(!graphics
|| !scale
)
3276 return InvalidParameter
;
3281 *scale
= graphics
->scale
;
3286 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
3288 TRACE("(%p, %p)\n", graphics
, unit
);
3290 if(!graphics
|| !unit
)
3291 return InvalidParameter
;
3296 *unit
= graphics
->unit
;
3301 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3302 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3305 TRACE("(%p, %p)\n", graphics
, mode
);
3307 if(!graphics
|| !mode
)
3308 return InvalidParameter
;
3313 *mode
= graphics
->pixeloffset
;
3318 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3319 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
3321 TRACE("(%p, %p)\n", graphics
, mode
);
3323 if(!graphics
|| !mode
)
3324 return InvalidParameter
;
3329 *mode
= graphics
->smoothing
;
3334 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
3336 TRACE("(%p, %p)\n", graphics
, contrast
);
3338 if(!graphics
|| !contrast
)
3339 return InvalidParameter
;
3341 *contrast
= graphics
->textcontrast
;
3346 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3347 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
3348 TextRenderingHint
*hint
)
3350 TRACE("(%p, %p)\n", graphics
, hint
);
3352 if(!graphics
|| !hint
)
3353 return InvalidParameter
;
3358 *hint
= graphics
->texthint
;
3363 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
3368 TRACE("(%p, %p)\n", graphics
, rect
);
3370 if(!graphics
|| !rect
)
3371 return InvalidParameter
;
3376 /* intersect window and graphics clipping regions */
3377 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
3380 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
3383 /* get bounds of the region */
3384 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
3387 GdipDeleteRegion(clip_rgn
);
3392 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
3397 TRACE("(%p, %p)\n", graphics
, rect
);
3399 if(!graphics
|| !rect
)
3400 return InvalidParameter
;
3402 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
3404 rect
->X
= roundr(rectf
.X
);
3405 rect
->Y
= roundr(rectf
.Y
);
3406 rect
->Width
= roundr(rectf
.Width
);
3407 rect
->Height
= roundr(rectf
.Height
);
3413 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3415 TRACE("(%p, %p)\n", graphics
, matrix
);
3417 if(!graphics
|| !matrix
)
3418 return InvalidParameter
;
3423 *matrix
= *graphics
->worldtrans
;
3427 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
3433 TRACE("(%p, %x)\n", graphics
, color
);
3436 return InvalidParameter
;
3441 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
3444 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
3445 GdipDeleteBrush((GpBrush
*)brush
);
3449 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
3450 wnd_rect
.Width
, wnd_rect
.Height
);
3452 GdipDeleteBrush((GpBrush
*)brush
);
3457 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
3459 TRACE("(%p, %p)\n", graphics
, res
);
3461 if(!graphics
|| !res
)
3462 return InvalidParameter
;
3464 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
3467 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
3473 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
3475 if(!graphics
|| !result
)
3476 return InvalidParameter
;
3483 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
3484 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
3487 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
3490 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
3493 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
3496 GdipDeleteRegion(rgn
);
3500 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
3502 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
3505 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
3511 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
3513 if(!graphics
|| !result
)
3514 return InvalidParameter
;
3521 pts
[1].X
= x
+ width
;
3522 pts
[1].Y
= y
+ height
;
3524 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
3525 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
3528 pts
[1].X
-= pts
[0].X
;
3529 pts
[1].Y
-= pts
[0].Y
;
3531 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
3534 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
3537 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
3540 GdipDeleteRegion(rgn
);
3544 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
3546 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
3549 typedef GpStatus (*gdip_format_string_callback
)(GpGraphics
*graphics
,
3550 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3551 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3552 INT lineno
, const RectF
*bounds
, void *user_data
);
3554 static GpStatus
gdip_format_string(GpGraphics
*graphics
,
3555 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
3556 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3557 gdip_format_string_callback callback
, void *user_data
)
3560 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
3561 nheight
, lineend
, lineno
= 0;
3563 StringAlignment halign
;
3567 if(length
== -1) length
= lstrlenW(string
);
3569 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
3570 if(!stringdup
) return OutOfMemory
;
3572 nwidth
= roundr(rect
->Width
);
3573 nheight
= roundr(rect
->Height
);
3575 if (rect
->Width
>= INT_MAX
|| rect
->Width
< 0.5) nwidth
= INT_MAX
;
3576 if (rect
->Height
>= INT_MAX
|| rect
->Width
< 0.5) nheight
= INT_MAX
;
3578 for(i
= 0, j
= 0; i
< length
; i
++){
3579 /* FIXME: This makes the indexes passed to callback inaccurate. */
3580 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
3583 stringdup
[j
] = string
[i
];
3589 if (format
) halign
= format
->align
;
3590 else halign
= StringAlignmentNear
;
3592 while(sum
< length
){
3593 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
3594 nwidth
, &fit
, NULL
, &size
);
3600 for(lret
= 0; lret
< fit
; lret
++)
3601 if(*(stringdup
+ sum
+ lret
) == '\n')
3604 /* Line break code (may look strange, but it imitates windows). */
3606 lineend
= fit
= lret
; /* this is not an off-by-one error */
3607 else if(fit
< (length
- sum
)){
3608 if(*(stringdup
+ sum
+ fit
) == ' ')
3609 while(*(stringdup
+ sum
+ fit
) == ' ')
3612 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
3615 if(*(stringdup
+ sum
+ fit
) == '\t')
3624 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
3625 *(stringdup
+ sum
+ lineend
- 1) == '\t')
3631 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, lineend
,
3632 nwidth
, &j
, NULL
, &size
);
3634 bounds
.Width
= size
.cx
;
3636 if(height
+ size
.cy
> nheight
)
3637 bounds
.Height
= nheight
- (height
+ size
.cy
);
3639 bounds
.Height
= size
.cy
;
3641 bounds
.Y
= rect
->Y
+ height
;
3645 case StringAlignmentNear
:
3649 case StringAlignmentCenter
:
3650 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
3652 case StringAlignmentFar
:
3653 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
3657 stat
= callback(graphics
, stringdup
, sum
, lineend
,
3658 font
, rect
, format
, lineno
, &bounds
, user_data
);
3663 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
3667 if(height
> nheight
)
3670 /* Stop if this was a linewrap (but not if it was a linebreak). */
3671 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
3675 GdipFree(stringdup
);
3680 struct measure_ranges_args
{
3684 static GpStatus
measure_ranges_callback(GpGraphics
*graphics
,
3685 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3686 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3687 INT lineno
, const RectF
*bounds
, void *user_data
)
3691 struct measure_ranges_args
*args
= user_data
;
3693 for (i
=0; i
<format
->range_count
; i
++)
3695 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
3696 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
3697 if (range_start
< range_end
)
3702 range_rect
.Y
= bounds
->Y
;
3703 range_rect
.Height
= bounds
->Height
;
3705 GetTextExtentExPointW(graphics
->hdc
, string
+ index
, range_start
- index
,
3706 INT_MAX
, NULL
, NULL
, &range_size
);
3707 range_rect
.X
= bounds
->X
+ range_size
.cx
;
3709 GetTextExtentExPointW(graphics
->hdc
, string
+ index
, range_end
- index
,
3710 INT_MAX
, NULL
, NULL
, &range_size
);
3711 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) - range_rect
.X
;
3713 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
3722 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
3723 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
3724 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
3725 INT regionCount
, GpRegion
** regions
)
3730 struct measure_ranges_args args
;
3732 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
3733 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
3735 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
3736 return InvalidParameter
;
3738 if (regionCount
< stringFormat
->range_count
)
3739 return InvalidParameter
;
3741 if (stringFormat
->attr
)
3742 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
3744 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
3746 for (i
=0; i
<stringFormat
->range_count
; i
++)
3748 stat
= GdipSetEmpty(regions
[i
]);
3753 args
.regions
= regions
;
3755 stat
= gdip_format_string(graphics
, string
, length
, font
, layoutRect
, stringFormat
,
3756 measure_ranges_callback
, &args
);
3758 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
3763 struct measure_string_args
{
3765 INT
*codepointsfitted
;
3769 static GpStatus
measure_string_callback(GpGraphics
*graphics
,
3770 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3771 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3772 INT lineno
, const RectF
*bounds
, void *user_data
)
3774 struct measure_string_args
*args
= user_data
;
3776 if (bounds
->Width
> args
->bounds
->Width
)
3777 args
->bounds
->Width
= bounds
->Width
;
3779 if (bounds
->Height
+ bounds
->Y
> args
->bounds
->Height
+ args
->bounds
->Y
)
3780 args
->bounds
->Height
= bounds
->Height
+ bounds
->Y
- args
->bounds
->Y
;
3782 if (args
->codepointsfitted
)
3783 *args
->codepointsfitted
= index
+ length
;
3785 if (args
->linesfilled
)
3786 (*args
->linesfilled
)++;
3791 /* Find the smallest rectangle that bounds the text when it is printed in rect
3792 * according to the format options listed in format. If rect has 0 width and
3793 * height, then just find the smallest rectangle that bounds the text when it's
3794 * printed at location (rect->X, rect-Y). */
3795 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
3796 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
3797 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
3798 INT
*codepointsfitted
, INT
*linesfilled
)
3801 struct measure_string_args args
;
3803 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
3804 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
3805 bounds
, codepointsfitted
, linesfilled
);
3807 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
3808 return InvalidParameter
;
3810 if(linesfilled
) *linesfilled
= 0;
3811 if(codepointsfitted
) *codepointsfitted
= 0;
3814 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
3816 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
3818 bounds
->X
= rect
->X
;
3819 bounds
->Y
= rect
->Y
;
3820 bounds
->Width
= 0.0;
3821 bounds
->Height
= 0.0;
3823 args
.bounds
= bounds
;
3824 args
.codepointsfitted
= codepointsfitted
;
3825 args
.linesfilled
= linesfilled
;
3827 gdip_format_string(graphics
, string
, length
, font
, rect
, format
,
3828 measure_string_callback
, &args
);
3830 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
3835 struct draw_string_args
{
3838 REAL ang_cos
, ang_sin
;
3841 static GpStatus
draw_string_callback(GpGraphics
*graphics
,
3842 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3843 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3844 INT lineno
, const RectF
*bounds
, void *user_data
)
3846 struct draw_string_args
*args
= user_data
;
3849 drawcoord
.left
= drawcoord
.right
= args
->drawbase
.x
+ roundr(args
->ang_sin
* bounds
->Y
);
3850 drawcoord
.top
= drawcoord
.bottom
= args
->drawbase
.y
+ roundr(args
->ang_cos
* bounds
->Y
);
3852 DrawTextW(graphics
->hdc
, string
+ index
, length
, &drawcoord
, args
->drawflags
);
3857 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
3858 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
3859 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
3864 TEXTMETRICW textmet
;
3865 GpPointF pt
[3], rectcpy
[4];
3867 REAL angle
, rel_width
, rel_height
;
3868 INT offsety
= 0, save_state
;
3869 struct draw_string_args args
;
3872 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
3873 length
, font
, debugstr_rectf(rect
), format
, brush
);
3875 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
3876 return InvalidParameter
;
3878 if((brush
->bt
!= BrushTypeSolidColor
)){
3879 FIXME("not implemented for given parameters\n");
3880 return NotImplemented
;
3884 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
3886 /* Should be no need to explicitly test for StringAlignmentNear as
3887 * that is default behavior if no alignment is passed. */
3888 if(format
->vertalign
!= StringAlignmentNear
){
3890 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
3892 if(format
->vertalign
== StringAlignmentCenter
)
3893 offsety
= (rect
->Height
- bounds
.Height
) / 2;
3894 else if(format
->vertalign
== StringAlignmentFar
)
3895 offsety
= (rect
->Height
- bounds
.Height
);
3899 save_state
= SaveDC(graphics
->hdc
);
3900 SetBkMode(graphics
->hdc
, TRANSPARENT
);
3901 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
3909 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
3910 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
3911 args
.ang_cos
= cos(angle
);
3912 args
.ang_sin
= sin(angle
);
3913 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
3914 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
3915 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
3916 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
3918 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
3919 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
3920 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
3921 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
3922 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
3924 scaled_rect
.X
= 0.0;
3925 scaled_rect
.Y
= 0.0;
3926 scaled_rect
.Width
= rel_width
* rect
->Width
;
3927 scaled_rect
.Height
= rel_height
* rect
->Height
;
3929 if (roundr(scaled_rect
.Width
) != 0 && roundr(scaled_rect
.Height
) != 0)
3931 /* FIXME: If only the width or only the height is 0, we should probably still clip */
3932 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
3933 SelectClipRgn(graphics
->hdc
, rgn
);
3936 /* Use gdi to find the font, then perform transformations on it (height,
3938 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
3939 GetTextMetricsW(graphics
->hdc
, &textmet
);
3942 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
3943 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
3945 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
3947 gdifont
= CreateFontIndirectW(&lfw
);
3948 DeleteObject(SelectObject(graphics
->hdc
, CreateFontIndirectW(&lfw
)));
3950 if (!format
|| format
->align
== StringAlignmentNear
)
3952 args
.drawbase
.x
= corners
[0].x
;
3953 args
.drawbase
.y
= corners
[0].y
;
3954 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
;
3956 else if (format
->align
== StringAlignmentCenter
)
3958 args
.drawbase
.x
= (corners
[0].x
+ corners
[1].x
)/2;
3959 args
.drawbase
.y
= (corners
[0].y
+ corners
[1].y
)/2;
3960 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_CENTER
;
3962 else /* (format->align == StringAlignmentFar) */
3964 args
.drawbase
.x
= corners
[1].x
;
3965 args
.drawbase
.y
= corners
[1].y
;
3966 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_RIGHT
;
3969 gdip_format_string(graphics
, string
, length
, font
, &scaled_rect
, format
,
3970 draw_string_callback
, &args
);
3973 DeleteObject(gdifont
);
3975 RestoreDC(graphics
->hdc
, save_state
);
3980 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
3982 TRACE("(%p)\n", graphics
);
3985 return InvalidParameter
;
3990 return GdipSetInfinite(graphics
->clip
);
3993 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
3995 TRACE("(%p)\n", graphics
);
3998 return InvalidParameter
;
4003 graphics
->worldtrans
->matrix
[0] = 1.0;
4004 graphics
->worldtrans
->matrix
[1] = 0.0;
4005 graphics
->worldtrans
->matrix
[2] = 0.0;
4006 graphics
->worldtrans
->matrix
[3] = 1.0;
4007 graphics
->worldtrans
->matrix
[4] = 0.0;
4008 graphics
->worldtrans
->matrix
[5] = 0.0;
4013 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
4015 return GdipEndContainer(graphics
, state
);
4018 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
4019 GpMatrixOrder order
)
4021 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
4024 return InvalidParameter
;
4029 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
4032 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
4034 return GdipBeginContainer2(graphics
, state
);
4037 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
4038 GraphicsContainer
*state
)
4040 GraphicsContainerItem
*container
;
4043 TRACE("(%p, %p)\n", graphics
, state
);
4045 if(!graphics
|| !state
)
4046 return InvalidParameter
;
4048 sts
= init_container(&container
, graphics
);
4052 list_add_head(&graphics
->containers
, &container
->entry
);
4053 *state
= graphics
->contid
= container
->contid
;
4058 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4060 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4061 return NotImplemented
;
4064 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4066 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4067 return NotImplemented
;
4070 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
4072 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
4073 return NotImplemented
;
4076 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
4079 GraphicsContainerItem
*container
, *container2
;
4081 TRACE("(%p, %x)\n", graphics
, state
);
4084 return InvalidParameter
;
4086 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
4087 if(container
->contid
== state
)
4091 /* did not find a matching container */
4092 if(&container
->entry
== &graphics
->containers
)
4095 sts
= restore_container(graphics
, container
);
4099 /* remove all of the containers on top of the found container */
4100 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
4101 if(container
->contid
== state
)
4103 list_remove(&container
->entry
);
4104 delete_container(container
);
4107 list_remove(&container
->entry
);
4108 delete_container(container
);
4113 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
4114 REAL sy
, GpMatrixOrder order
)
4116 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
4119 return InvalidParameter
;
4124 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
4127 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
4130 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
4132 if(!graphics
|| !srcgraphics
)
4133 return InvalidParameter
;
4135 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
4138 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
4139 CompositingMode mode
)
4141 TRACE("(%p, %d)\n", graphics
, mode
);
4144 return InvalidParameter
;
4149 graphics
->compmode
= mode
;
4154 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
4155 CompositingQuality quality
)
4157 TRACE("(%p, %d)\n", graphics
, quality
);
4160 return InvalidParameter
;
4165 graphics
->compqual
= quality
;
4170 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
4171 InterpolationMode mode
)
4173 TRACE("(%p, %d)\n", graphics
, mode
);
4176 return InvalidParameter
;
4181 graphics
->interpolation
= mode
;
4186 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
4188 TRACE("(%p, %.2f)\n", graphics
, scale
);
4190 if(!graphics
|| (scale
<= 0.0))
4191 return InvalidParameter
;
4196 graphics
->scale
= scale
;
4201 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
4203 TRACE("(%p, %d)\n", graphics
, unit
);
4206 return InvalidParameter
;
4211 if(unit
== UnitWorld
)
4212 return InvalidParameter
;
4214 graphics
->unit
= unit
;
4219 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4222 TRACE("(%p, %d)\n", graphics
, mode
);
4225 return InvalidParameter
;
4230 graphics
->pixeloffset
= mode
;
4235 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
4239 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
4242 FIXME("not implemented\n");
4244 return NotImplemented
;
4247 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
4251 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
4254 FIXME("not implemented\n");
4258 return NotImplemented
;
4261 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
4263 TRACE("(%p, %d)\n", graphics
, mode
);
4266 return InvalidParameter
;
4271 graphics
->smoothing
= mode
;
4276 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
4278 TRACE("(%p, %d)\n", graphics
, contrast
);
4281 return InvalidParameter
;
4283 graphics
->textcontrast
= contrast
;
4288 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
4289 TextRenderingHint hint
)
4291 TRACE("(%p, %d)\n", graphics
, hint
);
4294 return InvalidParameter
;
4299 graphics
->texthint
= hint
;
4304 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4306 TRACE("(%p, %p)\n", graphics
, matrix
);
4308 if(!graphics
|| !matrix
)
4309 return InvalidParameter
;
4314 GdipDeleteMatrix(graphics
->worldtrans
);
4315 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
4318 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
4319 REAL dy
, GpMatrixOrder order
)
4321 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
4324 return InvalidParameter
;
4329 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
4332 /*****************************************************************************
4333 * GdipSetClipHrgn [GDIPLUS.@]
4335 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
4340 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
4343 return InvalidParameter
;
4345 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
4349 status
= GdipSetClipRegion(graphics
, region
, mode
);
4351 GdipDeleteRegion(region
);
4355 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
4357 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
4360 return InvalidParameter
;
4365 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
4368 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
4369 REAL width
, REAL height
,
4374 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
4377 return InvalidParameter
;
4385 rect
.Height
= height
;
4387 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
4390 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
4391 INT width
, INT height
,
4394 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
4397 return InvalidParameter
;
4402 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
4405 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
4408 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
4410 if(!graphics
|| !region
)
4411 return InvalidParameter
;
4416 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
4419 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
4424 TRACE("(%p,%u)\n", metafile
, limitDpi
);
4427 FIXME("not implemented\n");
4429 return NotImplemented
;
4432 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
4438 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
4440 if(!graphics
|| !pen
|| count
<=0)
4441 return InvalidParameter
;
4446 pti
= GdipAlloc(sizeof(POINT
) * count
);
4448 save_state
= prepare_dc(graphics
, pen
);
4449 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
4451 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
4452 Polygon(graphics
->hdc
, pti
, count
);
4454 restore_dc(graphics
, save_state
);
4460 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
4467 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
4469 if(count
<=0) return InvalidParameter
;
4470 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
4472 for(i
= 0;i
< count
; i
++){
4473 ptf
[i
].X
= (REAL
)points
[i
].X
;
4474 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
4477 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
4483 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
4485 TRACE("(%p, %p)\n", graphics
, dpi
);
4487 if(!graphics
|| !dpi
)
4488 return InvalidParameter
;
4493 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
4498 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
4500 TRACE("(%p, %p)\n", graphics
, dpi
);
4502 if(!graphics
|| !dpi
)
4503 return InvalidParameter
;
4508 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
4513 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
4514 GpMatrixOrder order
)
4519 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
4521 if(!graphics
|| !matrix
)
4522 return InvalidParameter
;
4527 m
= *(graphics
->worldtrans
);
4529 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
4531 *(graphics
->worldtrans
) = m
;
4536 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
4538 TRACE("(%p, %p)\n", graphics
, hdc
);
4540 if(!graphics
|| !hdc
)
4541 return InvalidParameter
;
4546 *hdc
= graphics
->hdc
;
4547 graphics
->busy
= TRUE
;
4552 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
4554 TRACE("(%p, %p)\n", graphics
, hdc
);
4557 return InvalidParameter
;
4559 if(graphics
->hdc
!= hdc
|| !(graphics
->busy
))
4560 return InvalidParameter
;
4562 graphics
->busy
= FALSE
;
4567 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
4572 TRACE("(%p, %p)\n", graphics
, region
);
4574 if(!graphics
|| !region
)
4575 return InvalidParameter
;
4580 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
4583 /* free everything except root node and header */
4584 delete_element(®ion
->node
);
4585 memcpy(region
, clip
, sizeof(GpRegion
));
4591 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
4592 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
4598 if(!graphics
|| !points
|| count
<= 0)
4599 return InvalidParameter
;
4604 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
4606 if (src_space
== dst_space
) return Ok
;
4608 stat
= GdipCreateMatrix(&matrix
);
4611 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
4613 if(graphics
->unit
!= UnitDisplay
)
4614 unitscale
*= graphics
->scale
;
4616 /* transform from src_space to CoordinateSpacePage */
4619 case CoordinateSpaceWorld
:
4620 GdipMultiplyMatrix(matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
4622 case CoordinateSpacePage
:
4624 case CoordinateSpaceDevice
:
4625 GdipScaleMatrix(matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
4629 /* transform from CoordinateSpacePage to dst_space */
4632 case CoordinateSpaceWorld
:
4634 GpMatrix
*inverted_transform
;
4635 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
4638 stat
= GdipInvertMatrix(inverted_transform
);
4640 GdipMultiplyMatrix(matrix
, inverted_transform
, MatrixOrderAppend
);
4641 GdipDeleteMatrix(inverted_transform
);
4645 case CoordinateSpacePage
:
4647 case CoordinateSpaceDevice
:
4648 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
4653 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
4655 GdipDeleteMatrix(matrix
);
4661 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
4662 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
4668 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
4671 return InvalidParameter
;
4673 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
4677 for(i
= 0; i
< count
; i
++){
4678 pointsF
[i
].X
= (REAL
)points
[i
].X
;
4679 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
4682 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
4685 for(i
= 0; i
< count
; i
++){
4686 points
[i
].X
= roundr(pointsF
[i
].X
);
4687 points
[i
].Y
= roundr(pointsF
[i
].Y
);
4694 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
4706 /*****************************************************************************
4707 * GdipTranslateClip [GDIPLUS.@]
4709 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
4711 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
4714 return InvalidParameter
;
4719 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
4722 /*****************************************************************************
4723 * GdipTranslateClipI [GDIPLUS.@]
4725 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
4727 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
4730 return InvalidParameter
;
4735 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
4739 /*****************************************************************************
4740 * GdipMeasureDriverString [GDIPLUS.@]
4742 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
4743 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
4744 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
4746 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
4747 return NotImplemented
;
4750 /*****************************************************************************
4751 * GdipDrawDriverString [GDIPLUS.@]
4753 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
4754 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
4755 GDIPCONST PointF
*positions
, INT flags
,
4756 GDIPCONST GpMatrix
*matrix
)
4758 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics
, text
, length
, font
, brush
, positions
, flags
, matrix
);
4759 return NotImplemented
;
4762 GpStatus WINGDIPAPI
GdipRecordMetafile(HDC hdc
, EmfType type
, GDIPCONST GpRectF
*frameRect
,
4763 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
4765 FIXME("(%p %d %p %d %p %p): stub\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
4766 return NotImplemented
;
4769 /*****************************************************************************
4770 * GdipRecordMetafileI [GDIPLUS.@]
4772 GpStatus WINGDIPAPI
GdipRecordMetafileI(HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
4773 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
4775 FIXME("(%p %d %p %d %p %p): stub\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
4776 return NotImplemented
;
4779 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
4780 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
4782 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
4783 return NotImplemented
;
4786 /*****************************************************************************
4787 * GdipIsVisibleClipEmpty [GDIPLUS.@]
4789 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
4794 TRACE("(%p, %p)\n", graphics
, res
);
4796 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
4799 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
4802 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
4805 GdipDeleteRegion(rgn
);