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
, i
, numdashes
;
99 DWORD dash_array
[MAX_DASHLEN
];
103 FIXME("graphics object has no HDC\n");
106 save_state
= SaveDC(graphics
->hdc
);
108 EndPath(graphics
->hdc
);
110 if(pen
->unit
== UnitPixel
){
114 /* Get an estimate for the amount the pen width is affected by the world
115 * transform. (This is similar to what some of the wine drivers do.) */
120 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
121 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
122 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
124 width
*= pen
->width
* convert_unit(graphics_res(graphics
),
125 pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
);
128 if(pen
->dash
== DashStyleCustom
){
129 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
131 TRACE("dashes are: ");
132 for(i
= 0; i
< numdashes
; i
++){
133 dash_array
[i
] = roundr(width
* pen
->dashes
[i
]);
134 TRACE("%d, ", dash_array
[i
]);
136 TRACE("\n and the pen style is %x\n", pen
->style
);
138 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
,
139 numdashes
, dash_array
);
142 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
, 0, NULL
);
144 SelectObject(graphics
->hdc
, gdipen
);
149 static void restore_dc(GpGraphics
*graphics
, INT state
)
151 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
152 RestoreDC(graphics
->hdc
, state
);
155 /* This helper applies all the changes that the points listed in ptf need in
156 * order to be drawn on the device context. In the end, this should include at
158 * -scaling by page unit
159 * -applying world transformation
160 * -converting from float to int
161 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
162 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
163 * gdi to draw, and these functions would irreparably mess with line widths.
165 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
166 GpPointF
*ptf
, INT count
)
172 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
174 /* apply page scale */
175 if(graphics
->unit
!= UnitDisplay
)
176 unitscale
*= graphics
->scale
;
178 GdipCloneMatrix(graphics
->worldtrans
, &matrix
);
179 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
180 GdipTransformMatrixPoints(matrix
, ptf
, count
);
181 GdipDeleteMatrix(matrix
);
183 for(i
= 0; i
< count
; i
++){
184 pti
[i
].x
= roundr(ptf
[i
].X
);
185 pti
[i
].y
= roundr(ptf
[i
].Y
);
189 /* Draw non-premultiplied ARGB data to the given graphics object */
190 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
191 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
193 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
195 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
198 for (x
=0; x
<src_width
; x
++)
200 for (y
=0; y
<src_height
; y
++)
202 ARGB dst_color
, src_color
;
203 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
204 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
205 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
214 HBITMAP hbitmap
, old_hbm
=NULL
;
215 BITMAPINFOHEADER bih
;
219 hdc
= CreateCompatibleDC(0);
221 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
222 bih
.biWidth
= src_width
;
223 bih
.biHeight
= -src_height
;
226 bih
.biCompression
= BI_RGB
;
228 bih
.biXPelsPerMeter
= 0;
229 bih
.biYPelsPerMeter
= 0;
231 bih
.biClrImportant
= 0;
233 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
234 (void**)&temp_bits
, NULL
, 0);
236 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
237 4 * src_width
, src
, src_stride
);
239 old_hbm
= SelectObject(hdc
, hbitmap
);
241 bf
.BlendOp
= AC_SRC_OVER
;
243 bf
.SourceConstantAlpha
= 255;
244 bf
.AlphaFormat
= AC_SRC_ALPHA
;
246 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, src_width
, src_height
,
247 hdc
, 0, 0, src_width
, src_height
, bf
);
249 SelectObject(hdc
, old_hbm
);
251 DeleteObject(hbitmap
);
257 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
261 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
262 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
266 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
270 /* clamp to between 0.0 and 1.0, using the wrap mode */
271 if (brush
->wrap
== WrapModeTile
)
273 position
= fmodf(position
, 1.0f
);
274 if (position
< 0.0f
) position
+= 1.0f
;
276 else /* WrapModeFlip* */
278 position
= fmodf(position
, 2.0f
);
279 if (position
< 0.0f
) position
+= 2.0f
;
280 if (position
> 1.0f
) position
= 2.0f
- position
;
283 if (brush
->blendcount
== 1)
288 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
291 /* locate the blend positions surrounding this position */
292 while (position
> brush
->blendpos
[i
])
295 /* interpolate between the blend positions */
296 left_blendpos
= brush
->blendpos
[i
-1];
297 left_blendfac
= brush
->blendfac
[i
-1];
298 right_blendpos
= brush
->blendpos
[i
];
299 right_blendfac
= brush
->blendfac
[i
];
300 range
= right_blendpos
- left_blendpos
;
301 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
302 right_blendfac
* (position
- left_blendpos
)) / range
;
305 if (brush
->pblendcount
== 0)
306 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
310 ARGB left_blendcolor
, right_blendcolor
;
311 REAL left_blendpos
, right_blendpos
;
313 /* locate the blend colors surrounding this position */
314 while (blendfac
> brush
->pblendpos
[i
])
317 /* interpolate between the blend colors */
318 left_blendpos
= brush
->pblendpos
[i
-1];
319 left_blendcolor
= brush
->pblendcolor
[i
-1];
320 right_blendpos
= brush
->pblendpos
[i
];
321 right_blendcolor
= brush
->pblendcolor
[i
];
322 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
323 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
327 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
331 case BrushTypeLinearGradient
:
333 GpLineGradient
*line
= (GpLineGradient
*)brush
;
336 SelectClipPath(graphics
->hdc
, RGN_AND
);
337 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
339 GpPointF endpointsf
[2];
343 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
345 endpointsf
[0] = line
->startpoint
;
346 endpointsf
[1] = line
->endpoint
;
347 transform_and_round_points(graphics
, endpointsi
, endpointsf
, 2);
349 if (abs(endpointsi
[0].x
-endpointsi
[1].x
) > abs(endpointsi
[0].y
-endpointsi
[1].y
))
351 /* vertical-ish gradient */
352 int startx
, endx
; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
353 int startbottomx
; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
356 HBRUSH hbrush
, hprevbrush
;
357 int leftx
, rightx
; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
359 int tilt
; /* horizontal distance covered by a gradient line */
361 startx
= roundr((rc
.top
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
362 endx
= roundr((rc
.top
- endpointsf
[1].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[1].X
);
363 width
= endx
- startx
;
364 startbottomx
= roundr((rc
.bottom
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
365 tilt
= startx
- startbottomx
;
367 if (startx
>= startbottomx
)
370 rightx
= rc
.right
+ tilt
;
374 leftx
= rc
.left
+ tilt
;
378 poly
[0].y
= rc
.bottom
;
381 poly
[3].y
= rc
.bottom
;
383 for (x
=leftx
; x
<=rightx
; x
++)
385 ARGB argb
= blend_line_gradient(line
, (x
-startx
)/(REAL
)width
);
386 col
= ARGB2COLORREF(argb
);
387 hbrush
= CreateSolidBrush(col
);
388 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
389 poly
[0].x
= x
- tilt
- 1;
392 poly
[3].x
= x
- tilt
;
393 Polygon(graphics
->hdc
, poly
, 4);
394 SelectObject(graphics
->hdc
, hprevbrush
);
395 DeleteObject(hbrush
);
398 else if (endpointsi
[0].y
!= endpointsi
[1].y
)
400 /* horizontal-ish gradient */
401 int starty
, endy
; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
402 int startrighty
; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
405 HBRUSH hbrush
, hprevbrush
;
406 int topy
, bottomy
; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
408 int tilt
; /* vertical distance covered by a gradient line */
410 starty
= roundr((rc
.left
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
411 endy
= roundr((rc
.left
- endpointsf
[1].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[1].Y
);
412 height
= endy
- starty
;
413 startrighty
= roundr((rc
.right
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
414 tilt
= starty
- startrighty
;
416 if (starty
>= startrighty
)
419 bottomy
= rc
.bottom
+ tilt
;
423 topy
= rc
.top
+ tilt
;
427 poly
[0].x
= rc
.right
;
430 poly
[3].x
= rc
.right
;
432 for (y
=topy
; y
<=bottomy
; y
++)
434 ARGB argb
= blend_line_gradient(line
, (y
-starty
)/(REAL
)height
);
435 col
= ARGB2COLORREF(argb
);
436 hbrush
= CreateSolidBrush(col
);
437 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
438 poly
[0].y
= y
- tilt
- 1;
441 poly
[3].y
= y
- tilt
;
442 Polygon(graphics
->hdc
, poly
, 4);
443 SelectObject(graphics
->hdc
, hprevbrush
);
444 DeleteObject(hbrush
);
447 /* else startpoint == endpoint */
451 case BrushTypeSolidColor
:
453 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
457 /* partially transparent fill */
459 SelectClipPath(graphics
->hdc
, RGN_AND
);
460 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
462 HDC hdc
= CreateCompatibleDC(NULL
);
468 oldbmp
= SelectObject(hdc
, fill
->bmp
);
470 bf
.BlendOp
= AC_SRC_OVER
;
472 bf
.SourceConstantAlpha
= 255;
473 bf
.AlphaFormat
= AC_SRC_ALPHA
;
475 GdiAlphaBlend(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, hdc
, 0, 0, 1, 1, bf
);
477 SelectObject(hdc
, oldbmp
);
483 /* else fall through */
486 SelectObject(graphics
->hdc
, brush
->gdibrush
);
487 FillPath(graphics
->hdc
);
492 /* GdipDrawPie/GdipFillPie helper function */
493 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
494 REAL height
, REAL startAngle
, REAL sweepAngle
)
501 ptf
[1].X
= x
+ width
;
502 ptf
[1].Y
= y
+ height
;
504 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
505 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
507 transform_and_round_points(graphics
, pti
, ptf
, 4);
509 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
510 pti
[2].y
, pti
[3].x
, pti
[3].y
);
513 /* Draws the linecap the specified color and size on the hdc. The linecap is in
514 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
515 * should not be called on an hdc that has a path you care about. */
516 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
517 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
519 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
520 GpMatrix
*matrix
= NULL
;
523 PointF ptf
[4], *custptf
= NULL
;
524 POINT pt
[4], *custpt
= NULL
;
526 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
531 if((x1
== x2
) && (y1
== y2
))
534 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
536 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
538 brush
= CreateSolidBrush(color
);
539 lb
.lbStyle
= BS_SOLID
;
542 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
543 PS_JOIN_MITER
, 1, &lb
, 0,
545 oldbrush
= SelectObject(graphics
->hdc
, brush
);
546 oldpen
= SelectObject(graphics
->hdc
, pen
);
553 case LineCapSquareAnchor
:
554 case LineCapDiamondAnchor
:
555 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
556 if(cap
== LineCapDiamondAnchor
){
557 dsmall
= cos(theta
+ M_PI_2
) * size
;
558 dbig
= sin(theta
+ M_PI_2
) * size
;
561 dsmall
= cos(theta
+ M_PI_4
) * size
;
562 dbig
= sin(theta
+ M_PI_4
) * size
;
565 ptf
[0].X
= x2
- dsmall
;
566 ptf
[1].X
= x2
+ dbig
;
568 ptf
[0].Y
= y2
- dbig
;
569 ptf
[3].Y
= y2
+ dsmall
;
571 ptf
[1].Y
= y2
- dsmall
;
572 ptf
[2].Y
= y2
+ dbig
;
574 ptf
[3].X
= x2
- dbig
;
575 ptf
[2].X
= x2
+ dsmall
;
577 transform_and_round_points(graphics
, pt
, ptf
, 4);
578 Polygon(graphics
->hdc
, pt
, 4);
581 case LineCapArrowAnchor
:
582 size
= size
* 4.0 / sqrt(3.0);
584 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
585 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
590 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
591 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
599 transform_and_round_points(graphics
, pt
, ptf
, 3);
600 Polygon(graphics
->hdc
, pt
, 3);
603 case LineCapRoundAnchor
:
604 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
611 transform_and_round_points(graphics
, pt
, ptf
, 2);
612 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
615 case LineCapTriangle
:
617 dx
= cos(M_PI_2
+ theta
) * size
;
618 dy
= sin(M_PI_2
+ theta
) * size
;
625 dx
= cos(theta
) * size
;
626 dy
= sin(theta
) * size
;
631 transform_and_round_points(graphics
, pt
, ptf
, 3);
632 Polygon(graphics
->hdc
, pt
, 3);
636 dx
= dy
= size
/ 2.0;
643 dx
= -cos(M_PI_2
+ theta
) * size
;
644 dy
= -sin(M_PI_2
+ theta
) * size
;
651 transform_and_round_points(graphics
, pt
, ptf
, 4);
652 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
653 pt
[2].y
, pt
[3].x
, pt
[3].y
);
660 count
= custom
->pathdata
.Count
;
661 custptf
= GdipAlloc(count
* sizeof(PointF
));
662 custpt
= GdipAlloc(count
* sizeof(POINT
));
663 tp
= GdipAlloc(count
);
665 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
668 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
670 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
671 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
673 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
674 GdipTransformMatrixPoints(matrix
, custptf
, count
);
676 transform_and_round_points(graphics
, custpt
, custptf
, count
);
678 for(i
= 0; i
< count
; i
++)
679 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
682 BeginPath(graphics
->hdc
);
683 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
684 EndPath(graphics
->hdc
);
685 StrokeAndFillPath(graphics
->hdc
);
688 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
694 GdipDeleteMatrix(matrix
);
701 SelectObject(graphics
->hdc
, oldbrush
);
702 SelectObject(graphics
->hdc
, oldpen
);
708 /* Shortens the line by the given percent by changing x2, y2.
709 * If percent is > 1.0 then the line will change direction.
710 * If percent is negative it can lengthen the line. */
711 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
713 REAL dist
, theta
, dx
, dy
;
715 if((y1
== *y2
) && (x1
== *x2
))
718 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
719 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
720 dx
= cos(theta
) * dist
;
721 dy
= sin(theta
) * dist
;
727 /* Shortens the line by the given amount by changing x2, y2.
728 * If the amount is greater than the distance, the line will become length 0.
729 * If the amount is negative, it can lengthen the line. */
730 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
732 REAL dx
, dy
, percent
;
736 if(dx
== 0 && dy
== 0)
739 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
746 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
749 /* Draws lines between the given points, and if caps is true then draws an endcap
750 * at the end of the last line. */
751 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
752 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
755 GpPointF
*ptcopy
= NULL
;
756 GpStatus status
= GenericError
;
761 pti
= GdipAlloc(count
* sizeof(POINT
));
762 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
765 status
= OutOfMemory
;
769 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
772 if(pen
->endcap
== LineCapArrowAnchor
)
773 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
774 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
775 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
776 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
777 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
778 pen
->customend
->inset
* pen
->width
);
780 if(pen
->startcap
== LineCapArrowAnchor
)
781 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
782 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
783 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
784 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
785 &ptcopy
[0].X
, &ptcopy
[0].Y
,
786 pen
->customstart
->inset
* pen
->width
);
788 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
789 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
790 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
791 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
794 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
796 if(Polyline(graphics
->hdc
, pti
, count
))
806 /* Conducts a linear search to find the bezier points that will back off
807 * the endpoint of the curve by a distance of amt. Linear search works
808 * better than binary in this case because there are multiple solutions,
809 * and binary searches often find a bad one. I don't think this is what
810 * Windows does but short of rendering the bezier without GDI's help it's
811 * the best we can do. If rev then work from the start of the passed points
812 * instead of the end. */
813 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
816 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
817 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
826 origx
= pt
[fourth
].X
;
827 origy
= pt
[fourth
].Y
;
828 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
830 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
831 /* reset bezier points to original values */
832 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
833 /* Perform magic on bezier points. Order is important here.*/
834 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
835 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
836 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
837 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
838 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
839 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
841 dx
= pt
[fourth
].X
- origx
;
842 dy
= pt
[fourth
].Y
- origy
;
844 diff
= sqrt(dx
* dx
+ dy
* dy
);
845 percent
+= 0.0005 * amt
;
849 /* Draws bezier curves between given points, and if caps is true then draws an
850 * endcap at the end of the last line. */
851 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
852 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
856 GpStatus status
= GenericError
;
861 pti
= GdipAlloc(count
* sizeof(POINT
));
862 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
865 status
= OutOfMemory
;
869 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
872 if(pen
->endcap
== LineCapArrowAnchor
)
873 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
874 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
875 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
878 if(pen
->startcap
== LineCapArrowAnchor
)
879 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
880 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
881 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
883 /* the direction of the line cap is parallel to the direction at the
884 * end of the bezier (which, if it has been shortened, is not the same
885 * as the direction from pt[count-2] to pt[count-1]) */
886 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
887 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
888 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
889 pt
[count
- 1].X
, pt
[count
- 1].Y
);
891 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
892 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
893 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
896 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
898 PolyBezier(graphics
->hdc
, pti
, count
);
909 /* Draws a combination of bezier curves and lines between points. */
910 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
911 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
913 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
914 BYTE
*tp
= GdipAlloc(count
);
915 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
917 GpStatus status
= GenericError
;
923 if(!pti
|| !tp
|| !ptcopy
){
924 status
= OutOfMemory
;
928 for(i
= 1; i
< count
; i
++){
929 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
930 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
931 || !(types
[i
+ 1] & PathPointTypeBezier
)){
932 ERR("Bad bezier points\n");
939 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
941 /* If we are drawing caps, go through the points and adjust them accordingly,
942 * and draw the caps. */
944 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
945 case PathPointTypeBezier
:
946 if(pen
->endcap
== LineCapArrowAnchor
)
947 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
948 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
949 shorten_bezier_amt(&ptcopy
[count
- 4],
950 pen
->width
* pen
->customend
->inset
, FALSE
);
952 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
953 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
954 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
955 pt
[count
- 1].X
, pt
[count
- 1].Y
);
958 case PathPointTypeLine
:
959 if(pen
->endcap
== LineCapArrowAnchor
)
960 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
961 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
963 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
964 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
965 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
966 pen
->customend
->inset
* pen
->width
);
968 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
969 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
974 ERR("Bad path last point\n");
978 /* Find start of points */
979 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
980 == PathPointTypeStart
); j
++);
982 switch(types
[j
] & PathPointTypePathTypeMask
){
983 case PathPointTypeBezier
:
984 if(pen
->startcap
== LineCapArrowAnchor
)
985 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
986 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
987 shorten_bezier_amt(&ptcopy
[j
- 1],
988 pen
->width
* pen
->customstart
->inset
, TRUE
);
990 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
991 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
992 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
993 pt
[j
- 1].X
, pt
[j
- 1].Y
);
996 case PathPointTypeLine
:
997 if(pen
->startcap
== LineCapArrowAnchor
)
998 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
999 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1001 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
1002 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
1003 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
1004 pen
->customstart
->inset
* pen
->width
);
1006 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
1007 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1012 ERR("Bad path points\n");
1017 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1019 for(i
= 0; i
< count
; i
++){
1020 tp
[i
] = convert_path_point_type(types
[i
]);
1023 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1035 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1039 BeginPath(graphics
->hdc
);
1040 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1041 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1042 EndPath(graphics
->hdc
);
1046 typedef struct _GraphicsContainerItem
{
1048 GraphicsContainer contid
;
1050 SmoothingMode smoothing
;
1051 CompositingQuality compqual
;
1052 InterpolationMode interpolation
;
1053 CompositingMode compmode
;
1054 TextRenderingHint texthint
;
1057 PixelOffsetMode pixeloffset
;
1059 GpMatrix
* worldtrans
;
1061 } GraphicsContainerItem
;
1063 static GpStatus
init_container(GraphicsContainerItem
** container
,
1064 GDIPCONST GpGraphics
* graphics
){
1067 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1071 (*container
)->contid
= graphics
->contid
+ 1;
1073 (*container
)->smoothing
= graphics
->smoothing
;
1074 (*container
)->compqual
= graphics
->compqual
;
1075 (*container
)->interpolation
= graphics
->interpolation
;
1076 (*container
)->compmode
= graphics
->compmode
;
1077 (*container
)->texthint
= graphics
->texthint
;
1078 (*container
)->scale
= graphics
->scale
;
1079 (*container
)->unit
= graphics
->unit
;
1080 (*container
)->textcontrast
= graphics
->textcontrast
;
1081 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1083 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
1085 GdipFree(*container
);
1090 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1092 GdipDeleteMatrix((*container
)->worldtrans
);
1093 GdipFree(*container
);
1101 static void delete_container(GraphicsContainerItem
* container
){
1102 GdipDeleteMatrix(container
->worldtrans
);
1103 GdipDeleteRegion(container
->clip
);
1104 GdipFree(container
);
1107 static GpStatus
restore_container(GpGraphics
* graphics
,
1108 GDIPCONST GraphicsContainerItem
* container
){
1113 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
1117 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1119 GdipDeleteMatrix(newTrans
);
1123 GdipDeleteMatrix(graphics
->worldtrans
);
1124 graphics
->worldtrans
= newTrans
;
1126 GdipDeleteRegion(graphics
->clip
);
1127 graphics
->clip
= newClip
;
1129 graphics
->contid
= container
->contid
- 1;
1131 graphics
->smoothing
= container
->smoothing
;
1132 graphics
->compqual
= container
->compqual
;
1133 graphics
->interpolation
= container
->interpolation
;
1134 graphics
->compmode
= container
->compmode
;
1135 graphics
->texthint
= container
->texthint
;
1136 graphics
->scale
= container
->scale
;
1137 graphics
->unit
= container
->unit
;
1138 graphics
->textcontrast
= container
->textcontrast
;
1139 graphics
->pixeloffset
= container
->pixeloffset
;
1144 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1150 if(graphics
->hwnd
) {
1151 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1152 return GenericError
;
1154 rect
->X
= wnd_rect
.left
;
1155 rect
->Y
= wnd_rect
.top
;
1156 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1157 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1158 }else if (graphics
->image
){
1159 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
1160 if (stat
== Ok
&& unit
!= UnitPixel
)
1161 FIXME("need to convert from unit %i\n", unit
);
1165 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
1166 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
1172 /* on success, rgn will contain the region of the graphics object which
1173 * is visible after clipping has been applied */
1174 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
1180 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
1183 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
1186 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
1189 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
1192 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
1195 GdipDeleteRegion(tmp
);
1199 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
1201 TRACE("(%p, %p)\n", hdc
, graphics
);
1203 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
1206 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
1210 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
1212 if(hDevice
!= NULL
) {
1213 FIXME("Don't know how to handle parameter hDevice\n");
1214 return NotImplemented
;
1220 if(graphics
== NULL
)
1221 return InvalidParameter
;
1223 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1224 if(!*graphics
) return OutOfMemory
;
1226 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1227 GdipFree(*graphics
);
1231 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1232 GdipFree((*graphics
)->worldtrans
);
1233 GdipFree(*graphics
);
1237 (*graphics
)->hdc
= hdc
;
1238 (*graphics
)->hwnd
= WindowFromDC(hdc
);
1239 (*graphics
)->owndc
= FALSE
;
1240 (*graphics
)->smoothing
= SmoothingModeDefault
;
1241 (*graphics
)->compqual
= CompositingQualityDefault
;
1242 (*graphics
)->interpolation
= InterpolationModeDefault
;
1243 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1244 (*graphics
)->compmode
= CompositingModeSourceOver
;
1245 (*graphics
)->unit
= UnitDisplay
;
1246 (*graphics
)->scale
= 1.0;
1247 (*graphics
)->busy
= FALSE
;
1248 (*graphics
)->textcontrast
= 4;
1249 list_init(&(*graphics
)->containers
);
1250 (*graphics
)->contid
= 0;
1252 TRACE("<-- %p\n", *graphics
);
1257 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
1261 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1262 if(!*graphics
) return OutOfMemory
;
1264 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1265 GdipFree(*graphics
);
1269 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1270 GdipFree((*graphics
)->worldtrans
);
1271 GdipFree(*graphics
);
1275 (*graphics
)->hdc
= NULL
;
1276 (*graphics
)->hwnd
= NULL
;
1277 (*graphics
)->owndc
= FALSE
;
1278 (*graphics
)->image
= image
;
1279 (*graphics
)->smoothing
= SmoothingModeDefault
;
1280 (*graphics
)->compqual
= CompositingQualityDefault
;
1281 (*graphics
)->interpolation
= InterpolationModeDefault
;
1282 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1283 (*graphics
)->compmode
= CompositingModeSourceOver
;
1284 (*graphics
)->unit
= UnitDisplay
;
1285 (*graphics
)->scale
= 1.0;
1286 (*graphics
)->busy
= FALSE
;
1287 (*graphics
)->textcontrast
= 4;
1288 list_init(&(*graphics
)->containers
);
1289 (*graphics
)->contid
= 0;
1291 TRACE("<-- %p\n", *graphics
);
1296 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
1301 TRACE("(%p, %p)\n", hwnd
, graphics
);
1305 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
1307 ReleaseDC(hwnd
, hdc
);
1311 (*graphics
)->hwnd
= hwnd
;
1312 (*graphics
)->owndc
= TRUE
;
1317 /* FIXME: no icm handling */
1318 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
1320 TRACE("(%p, %p)\n", hwnd
, graphics
);
1322 return GdipCreateFromHWND(hwnd
, graphics
);
1325 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
1326 GpMetafile
**metafile
)
1330 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
1332 if(!hemf
|| !metafile
)
1333 return InvalidParameter
;
1336 FIXME("not implemented\n");
1338 return NotImplemented
;
1341 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
1342 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1344 IStream
*stream
= NULL
;
1348 GpStatus retval
= Ok
;
1350 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
1352 if(!hwmf
|| !metafile
|| !placeable
)
1353 return InvalidParameter
;
1356 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
1358 return GenericError
;
1359 copy
= GdipAlloc(read
);
1360 GetMetaFileBitsEx(hwmf
, read
, copy
);
1362 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1365 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
1366 copy
= GdipAlloc(read
);
1367 GetEnhMetaFileBits(hemf
, read
, copy
);
1368 DeleteEnhMetaFile(hemf
);
1370 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
1371 ERR("could not make stream\n");
1373 retval
= GenericError
;
1377 *metafile
= GdipAlloc(sizeof(GpMetafile
));
1379 retval
= OutOfMemory
;
1383 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1384 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
1386 retval
= GenericError
;
1391 (*metafile
)->image
.type
= ImageTypeMetafile
;
1392 memcpy(&(*metafile
)->image
.format
, &ImageFormatWMF
, sizeof(GUID
));
1393 (*metafile
)->image
.palette_flags
= 0;
1394 (*metafile
)->image
.palette_count
= 0;
1395 (*metafile
)->image
.palette_size
= 0;
1396 (*metafile
)->image
.palette_entries
= NULL
;
1397 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
1398 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
1399 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
1400 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Top
) / ((REAL
) placeable
->Inch
);
1401 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
1402 - placeable
->BoundingBox
.Left
));
1403 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
1404 - placeable
->BoundingBox
.Top
));
1405 (*metafile
)->unit
= UnitPixel
;
1408 DeleteMetaFile(hwmf
);
1410 TRACE("<-- %p\n", *metafile
);
1414 GdipFree(*metafile
);
1415 IStream_Release(stream
);
1419 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1420 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1422 HMETAFILE hmf
= GetMetaFileW(file
);
1424 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1426 if(!hmf
) return InvalidParameter
;
1428 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1431 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
1432 GpMetafile
**metafile
)
1434 FIXME("(%p, %p): stub\n", file
, metafile
);
1435 return NotImplemented
;
1438 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
1439 GpMetafile
**metafile
)
1441 FIXME("(%p, %p): stub\n", stream
, metafile
);
1442 return NotImplemented
;
1445 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
1446 UINT access
, IStream
**stream
)
1451 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
1453 if(!stream
|| !filename
)
1454 return InvalidParameter
;
1456 if(access
& GENERIC_WRITE
)
1457 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
1458 else if(access
& GENERIC_READ
)
1459 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
1461 return InvalidParameter
;
1463 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
1465 return hresult_to_status(ret
);
1468 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
1470 GraphicsContainerItem
*cont
, *next
;
1471 TRACE("(%p)\n", graphics
);
1473 if(!graphics
) return InvalidParameter
;
1474 if(graphics
->busy
) return ObjectBusy
;
1477 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
1479 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
1480 list_remove(&cont
->entry
);
1481 delete_container(cont
);
1484 GdipDeleteRegion(graphics
->clip
);
1485 GdipDeleteMatrix(graphics
->worldtrans
);
1491 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1492 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1494 INT save_state
, num_pts
;
1495 GpPointF points
[MAX_ARC_PTS
];
1498 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1499 width
, height
, startAngle
, sweepAngle
);
1501 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
1502 return InvalidParameter
;
1507 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1509 save_state
= prepare_dc(graphics
, pen
);
1511 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
1513 restore_dc(graphics
, save_state
);
1518 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1519 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1521 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1522 width
, height
, startAngle
, sweepAngle
);
1524 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1527 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1528 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
1534 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
1535 x2
, y2
, x3
, y3
, x4
, y4
);
1537 if(!graphics
|| !pen
)
1538 return InvalidParameter
;
1552 save_state
= prepare_dc(graphics
, pen
);
1554 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1556 restore_dc(graphics
, save_state
);
1561 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1562 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
1568 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
1569 x2
, y2
, x3
, y3
, x4
, y4
);
1571 if(!graphics
|| !pen
)
1572 return InvalidParameter
;
1586 save_state
= prepare_dc(graphics
, pen
);
1588 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1590 restore_dc(graphics
, save_state
);
1595 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
1596 GDIPCONST GpPointF
*points
, INT count
)
1601 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1603 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1604 return InvalidParameter
;
1609 for(i
= 0; i
< floor(count
/ 4); i
++){
1610 ret
= GdipDrawBezier(graphics
, pen
,
1611 points
[4*i
].X
, points
[4*i
].Y
,
1612 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
1613 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
1614 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
1622 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
1623 GDIPCONST GpPoint
*points
, INT count
)
1629 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1631 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1632 return InvalidParameter
;
1637 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
1641 for(i
= 0; i
< count
; i
++){
1642 pts
[i
].X
= (REAL
)points
[i
].X
;
1643 pts
[i
].Y
= (REAL
)points
[i
].Y
;
1646 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
1653 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
1654 GDIPCONST GpPointF
*points
, INT count
)
1656 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1658 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
1661 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1662 GDIPCONST GpPoint
*points
, INT count
)
1664 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1666 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
1669 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1670 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1675 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1677 if(!graphics
|| !pen
|| !points
|| count
<= 0)
1678 return InvalidParameter
;
1683 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
1686 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1688 GdipDeletePath(path
);
1692 stat
= GdipDrawPath(graphics
, pen
, path
);
1694 GdipDeletePath(path
);
1699 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1700 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1706 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1708 if(!points
|| count
<= 0)
1709 return InvalidParameter
;
1711 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1715 for(i
= 0; i
< count
; i
++){
1716 ptf
[i
].X
= (REAL
)points
[i
].X
;
1717 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1720 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
1727 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
1728 GDIPCONST GpPointF
*points
, INT count
)
1730 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1732 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
1735 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1736 GDIPCONST GpPoint
*points
, INT count
)
1742 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1745 return InvalidParameter
;
1747 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1751 for(i
= 0; i
< count
; i
++){
1752 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1753 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1756 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
1762 /* Approximates cardinal spline with Bezier curves. */
1763 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1764 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1766 /* PolyBezier expects count*3-2 points. */
1767 INT i
, len_pt
= count
*3-2, save_state
;
1769 REAL x1
, x2
, y1
, y2
;
1772 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1774 if(!graphics
|| !pen
)
1775 return InvalidParameter
;
1781 return InvalidParameter
;
1783 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
1787 tension
= tension
* TENSION_CONST
;
1789 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
1792 pt
[0].X
= points
[0].X
;
1793 pt
[0].Y
= points
[0].Y
;
1797 for(i
= 0; i
< count
-2; i
++){
1798 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
1802 pt
[3*i
+3].X
= points
[i
+1].X
;
1803 pt
[3*i
+3].Y
= points
[i
+1].Y
;
1808 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
1809 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
1811 pt
[len_pt
-2].X
= x1
;
1812 pt
[len_pt
-2].Y
= y1
;
1813 pt
[len_pt
-1].X
= points
[count
-1].X
;
1814 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
1816 save_state
= prepare_dc(graphics
, pen
);
1818 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
1821 restore_dc(graphics
, save_state
);
1826 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1827 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1833 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1836 return InvalidParameter
;
1838 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1842 for(i
= 0; i
< count
; i
++){
1843 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1844 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1847 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
1853 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
1854 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
1857 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1859 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1860 return InvalidParameter
;
1863 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1866 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
1867 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
1870 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1876 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1877 return InvalidParameter
;
1880 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1883 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1884 REAL y
, REAL width
, REAL height
)
1890 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1892 if(!graphics
|| !pen
)
1893 return InvalidParameter
;
1900 ptf
[1].X
= x
+ width
;
1901 ptf
[1].Y
= y
+ height
;
1903 save_state
= prepare_dc(graphics
, pen
);
1904 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1906 transform_and_round_points(graphics
, pti
, ptf
, 2);
1908 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1910 restore_dc(graphics
, save_state
);
1915 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1916 INT y
, INT width
, INT height
)
1918 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1920 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1924 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
1929 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
1931 if(!graphics
|| !image
)
1932 return InvalidParameter
;
1934 GdipGetImageWidth(image
, &width
);
1935 GdipGetImageHeight(image
, &height
);
1937 /* FIXME: we should use the graphics and image dpi, somehow */
1939 points
[0].X
= points
[2].X
= x
;
1940 points
[0].Y
= points
[1].Y
= y
;
1941 points
[1].X
= x
+ width
;
1942 points
[2].Y
= y
+ height
;
1944 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, 0, 0, width
, height
,
1945 UnitPixel
, NULL
, NULL
, NULL
);
1948 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
1951 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
1953 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
1956 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
1957 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
1961 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
1963 points
[0].X
= points
[2].X
= x
;
1964 points
[0].Y
= points
[1].Y
= y
;
1966 /* FIXME: convert image coordinates to Graphics coordinates? */
1967 points
[1].X
= x
+ srcwidth
;
1968 points
[2].Y
= y
+ srcheight
;
1970 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1971 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
1974 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
1975 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
1978 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
1981 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
1982 GDIPCONST GpPointF
*dstpoints
, INT count
)
1984 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
1985 return NotImplemented
;
1988 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
1989 GDIPCONST GpPoint
*dstpoints
, INT count
)
1991 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
1992 return NotImplemented
;
1995 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
1996 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
1997 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1998 DrawImageAbort callback
, VOID
* callbackData
)
2005 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2006 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2009 if(!graphics
|| !image
|| !points
|| count
!= 3)
2010 return InvalidParameter
;
2012 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2013 debugstr_pointf(&points
[2]));
2015 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2016 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2017 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2018 transform_and_round_points(graphics
, pti
, ptf
, 4);
2024 FIXME("graphics object has no HDC\n");
2027 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2028 if(srcUnit
== UnitInch
)
2029 dx
= dy
= (REAL
) INCH_HIMETRIC
;
2030 else if(srcUnit
== UnitPixel
){
2031 dx
= ((REAL
) INCH_HIMETRIC
) /
2032 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
2033 dy
= ((REAL
) INCH_HIMETRIC
) /
2034 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
2037 return NotImplemented
;
2039 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2040 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2041 srcx
* dx
, srcy
* dy
,
2042 srcwidth
* dx
, srcheight
* dy
,
2045 callback(callbackData
);
2046 return GenericError
;
2049 else if (image
->type
== ImageTypeBitmap
)
2051 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2054 if (srcUnit
== UnitInch
)
2055 dx
= dy
= 96.0; /* FIXME: use the image resolution */
2056 else if (srcUnit
== UnitPixel
)
2059 return NotImplemented
;
2061 if (imageAttributes
||
2062 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
2063 !((GpBitmap
*)image
)->hbitmap
||
2064 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
)
2069 RECT src_area
, dst_area
;
2070 int i
, x
, y
, stride
;
2071 GpMatrix
*dst_to_src
;
2072 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2075 src_area
.left
= srcx
*dx
;
2076 src_area
.top
= srcy
*dy
;
2077 src_area
.right
= (srcx
+srcwidth
)*dx
;
2078 src_area
.bottom
= (srcy
+srcheight
)*dy
;
2080 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2081 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2084 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2085 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2086 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2087 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2090 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2091 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2092 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2093 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2094 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2095 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2097 stat
= GdipCreateMatrix2(m11
, m12
, m21
, m22
, mdx
, mdy
, &dst_to_src
);
2098 if (stat
!= Ok
) return stat
;
2100 stat
= GdipInvertMatrix(dst_to_src
);
2103 GdipDeleteMatrix(dst_to_src
);
2107 data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
2110 GdipDeleteMatrix(dst_to_src
);
2114 stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
2116 if (imageAttributes
&&
2117 (imageAttributes
->wrap
!= WrapModeClamp
||
2118 imageAttributes
->outside_color
!= 0x00000000 ||
2119 imageAttributes
->clamp
))
2123 FIXME("Image wrap mode not implemented\n");
2126 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2128 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2130 GpPointF src_pointf
;
2137 GdipTransformMatrixPoints(dst_to_src
, &src_pointf
, 1);
2139 src_x
= roundr(src_pointf
.X
);
2140 src_y
= roundr(src_pointf
.Y
);
2142 src_color
= (ARGB
*)(data
+ stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2144 if (src_x
< src_area
.left
|| src_x
>= src_area
.right
||
2145 src_y
< src_area
.top
|| src_y
>= src_area
.bottom
)
2148 GdipBitmapGetPixel(bitmap
, src_x
, src_y
, src_color
);
2152 GdipDeleteMatrix(dst_to_src
);
2154 if (imageAttributes
)
2156 if (imageAttributes
->colorkeys
[ColorAdjustTypeBitmap
].enabled
||
2157 imageAttributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
2159 const struct color_key
*key
;
2160 BYTE min_blue
, min_green
, min_red
;
2161 BYTE max_blue
, max_green
, max_red
;
2163 if (imageAttributes
->colorkeys
[ColorAdjustTypeBitmap
].enabled
)
2164 key
= &imageAttributes
->colorkeys
[ColorAdjustTypeBitmap
];
2166 key
= &imageAttributes
->colorkeys
[ColorAdjustTypeDefault
];
2168 min_blue
= key
->low
&0xff;
2169 min_green
= (key
->low
>>8)&0xff;
2170 min_red
= (key
->low
>>16)&0xff;
2172 max_blue
= key
->high
&0xff;
2173 max_green
= (key
->high
>>8)&0xff;
2174 max_red
= (key
->high
>>16)&0xff;
2176 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2177 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2180 BYTE blue
, green
, red
;
2181 src_color
= (ARGB
*)(data
+ stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2182 blue
= *src_color
&0xff;
2183 green
= (*src_color
>>8)&0xff;
2184 red
= (*src_color
>>16)&0xff;
2185 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
2186 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
2187 *src_color
= 0x00000000;
2191 if (imageAttributes
->colorremaptables
[ColorAdjustTypeBitmap
].enabled
||
2192 imageAttributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
2194 const struct color_remap_table
*table
;
2196 if (imageAttributes
->colorremaptables
[ColorAdjustTypeBitmap
].enabled
)
2197 table
= &imageAttributes
->colorremaptables
[ColorAdjustTypeBitmap
];
2199 table
= &imageAttributes
->colorremaptables
[ColorAdjustTypeDefault
];
2201 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2202 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2205 src_color
= (ARGB
*)(data
+ stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2206 for (i
=0; i
<table
->mapsize
; i
++)
2208 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
2210 *src_color
= table
->colormap
[i
].newColor
.Argb
;
2217 if (imageAttributes
->colormatrices
[ColorAdjustTypeBitmap
].enabled
||
2218 imageAttributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
2222 FIXME("Color transforms not implemented\n");
2225 if (imageAttributes
->gamma_enabled
[ColorAdjustTypeBitmap
] ||
2226 imageAttributes
->gamma_enabled
[ColorAdjustTypeDefault
])
2230 FIXME("Gamma adjustment not implemented\n");
2234 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
2235 data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, stride
);
2244 int temp_hdc
=0, temp_bitmap
=0;
2245 HBITMAP hbitmap
, old_hbm
=NULL
;
2247 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
2248 bitmap
->format
== PixelFormat24bppRGB
||
2249 bitmap
->format
== PixelFormat32bppRGB
||
2250 bitmap
->format
== PixelFormat32bppPARGB
))
2252 BITMAPINFOHEADER bih
;
2254 PixelFormat dst_format
;
2256 /* we can't draw a bitmap of this format directly */
2257 hdc
= CreateCompatibleDC(0);
2261 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
2262 bih
.biWidth
= bitmap
->width
;
2263 bih
.biHeight
= -bitmap
->height
;
2265 bih
.biBitCount
= 32;
2266 bih
.biCompression
= BI_RGB
;
2267 bih
.biSizeImage
= 0;
2268 bih
.biXPelsPerMeter
= 0;
2269 bih
.biYPelsPerMeter
= 0;
2271 bih
.biClrImportant
= 0;
2273 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
2274 (void**)&temp_bits
, NULL
, 0);
2276 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2277 dst_format
= PixelFormat32bppPARGB
;
2279 dst_format
= PixelFormat32bppRGB
;
2281 convert_pixels(bitmap
->width
, bitmap
->height
,
2282 bitmap
->width
*4, temp_bits
, dst_format
,
2283 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette_entries
);
2287 hbitmap
= bitmap
->hbitmap
;
2289 temp_hdc
= (hdc
== 0);
2294 if (!hdc
) hdc
= CreateCompatibleDC(0);
2295 old_hbm
= SelectObject(hdc
, hbitmap
);
2298 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2302 bf
.BlendOp
= AC_SRC_OVER
;
2304 bf
.SourceConstantAlpha
= 255;
2305 bf
.AlphaFormat
= AC_SRC_ALPHA
;
2307 GdiAlphaBlend(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
2308 hdc
, srcx
*dx
, srcy
*dy
, srcwidth
*dx
, srcheight
*dy
, bf
);
2312 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
2313 hdc
, srcx
*dx
, srcy
*dy
, srcwidth
*dx
, srcheight
*dy
, SRCCOPY
);
2318 SelectObject(hdc
, old_hbm
);
2323 DeleteObject(hbitmap
);
2328 ERR("GpImage with no IPicture or HBITMAP?!\n");
2329 return NotImplemented
;
2335 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
2336 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
2337 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2338 DrawImageAbort callback
, VOID
* callbackData
)
2340 GpPointF pointsF
[3];
2343 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
2344 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2347 if(!points
|| count
!=3)
2348 return InvalidParameter
;
2350 for(i
= 0; i
< count
; i
++){
2351 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2352 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2355 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
2356 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
2357 callback
, callbackData
);
2360 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
2361 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
2362 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
2363 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
2364 VOID
* callbackData
)
2368 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
2369 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2370 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2374 points
[1].X
= dstx
+ dstwidth
;
2377 points
[2].Y
= dsty
+ dstheight
;
2379 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2380 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2383 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
2384 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
2385 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
2386 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
2387 VOID
* callbackData
)
2391 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
2392 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2393 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2397 points
[1].X
= dstx
+ dstwidth
;
2400 points
[2].Y
= dsty
+ dstheight
;
2402 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2403 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2406 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
2407 REAL x
, REAL y
, REAL width
, REAL height
)
2413 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
2415 if(!graphics
|| !image
)
2416 return InvalidParameter
;
2418 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
2422 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
2423 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
2424 unit
, NULL
, NULL
, NULL
);
2427 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
2428 INT x
, INT y
, INT width
, INT height
)
2430 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
2432 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
2435 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2436 REAL y1
, REAL x2
, REAL y2
)
2442 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2444 if(!pen
|| !graphics
)
2445 return InvalidParameter
;
2455 save_state
= prepare_dc(graphics
, pen
);
2457 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2459 restore_dc(graphics
, save_state
);
2464 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2465 INT y1
, INT x2
, INT y2
)
2471 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2473 if(!pen
|| !graphics
)
2474 return InvalidParameter
;
2484 save_state
= prepare_dc(graphics
, pen
);
2486 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2488 restore_dc(graphics
, save_state
);
2493 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2494 GpPointF
*points
, INT count
)
2499 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2501 if(!pen
|| !graphics
|| (count
< 2))
2502 return InvalidParameter
;
2507 save_state
= prepare_dc(graphics
, pen
);
2509 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
2511 restore_dc(graphics
, save_state
);
2516 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2517 GpPoint
*points
, INT count
)
2521 GpPointF
*ptf
= NULL
;
2524 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2526 if(!pen
|| !graphics
|| (count
< 2))
2527 return InvalidParameter
;
2532 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2533 if(!ptf
) return OutOfMemory
;
2535 for(i
= 0; i
< count
; i
++){
2536 ptf
[i
].X
= (REAL
) points
[i
].X
;
2537 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2540 save_state
= prepare_dc(graphics
, pen
);
2542 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
2544 restore_dc(graphics
, save_state
);
2550 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
2555 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
2557 if(!pen
|| !graphics
)
2558 return InvalidParameter
;
2563 save_state
= prepare_dc(graphics
, pen
);
2565 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
2566 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
2568 restore_dc(graphics
, save_state
);
2573 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2574 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2578 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2579 width
, height
, startAngle
, sweepAngle
);
2581 if(!graphics
|| !pen
)
2582 return InvalidParameter
;
2587 save_state
= prepare_dc(graphics
, pen
);
2588 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2590 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2592 restore_dc(graphics
, save_state
);
2597 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2598 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2600 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2601 width
, height
, startAngle
, sweepAngle
);
2603 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2606 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2607 REAL y
, REAL width
, REAL height
)
2613 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2615 if(!pen
|| !graphics
)
2616 return InvalidParameter
;
2623 ptf
[1].X
= x
+ width
;
2625 ptf
[2].X
= x
+ width
;
2626 ptf
[2].Y
= y
+ height
;
2628 ptf
[3].Y
= y
+ height
;
2630 save_state
= prepare_dc(graphics
, pen
);
2631 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2633 transform_and_round_points(graphics
, pti
, ptf
, 4);
2634 Polygon(graphics
->hdc
, pti
, 4);
2636 restore_dc(graphics
, save_state
);
2641 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2642 INT y
, INT width
, INT height
)
2644 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2646 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2649 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
2650 GDIPCONST GpRectF
* rects
, INT count
)
2656 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2658 if(!graphics
|| !pen
|| !rects
|| count
< 1)
2659 return InvalidParameter
;
2664 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
2665 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
2673 for(i
= 0; i
< count
; i
++){
2674 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
2675 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
2676 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
2677 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
2680 save_state
= prepare_dc(graphics
, pen
);
2681 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2683 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
2685 for(i
= 0; i
< count
; i
++)
2686 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
2688 restore_dc(graphics
, save_state
);
2696 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
2697 GDIPCONST GpRect
* rects
, INT count
)
2703 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2705 if(!rects
|| count
<=0)
2706 return InvalidParameter
;
2708 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
2712 for(i
= 0;i
< count
;i
++){
2713 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2714 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2715 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
2716 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2719 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
2725 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
2726 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
2731 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2732 count
, tension
, fill
);
2734 if(!graphics
|| !brush
|| !points
)
2735 return InvalidParameter
;
2740 if(count
== 1) /* Do nothing */
2743 stat
= GdipCreatePath(fill
, &path
);
2747 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2749 GdipDeletePath(path
);
2753 stat
= GdipFillPath(graphics
, brush
, path
);
2755 GdipDeletePath(path
);
2759 GdipDeletePath(path
);
2764 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
2765 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
2771 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2772 count
, tension
, fill
);
2774 if(!points
|| count
== 0)
2775 return InvalidParameter
;
2777 if(count
== 1) /* Do nothing */
2780 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2784 for(i
= 0;i
< count
;i
++){
2785 ptf
[i
].X
= (REAL
)points
[i
].X
;
2786 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2789 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
2796 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
2797 GDIPCONST GpPointF
*points
, INT count
)
2799 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2800 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
2801 0.5f
, FillModeAlternate
);
2804 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
2805 GDIPCONST GpPoint
*points
, INT count
)
2807 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2808 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
2809 0.5f
, FillModeAlternate
);
2812 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2813 REAL y
, REAL width
, REAL height
)
2819 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2821 if(!graphics
|| !brush
)
2822 return InvalidParameter
;
2829 FIXME("graphics object has no HDC\n");
2835 ptf
[1].X
= x
+ width
;
2836 ptf
[1].Y
= y
+ height
;
2838 save_state
= SaveDC(graphics
->hdc
);
2839 EndPath(graphics
->hdc
);
2841 transform_and_round_points(graphics
, pti
, ptf
, 2);
2843 BeginPath(graphics
->hdc
);
2844 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2845 EndPath(graphics
->hdc
);
2847 brush_fill_path(graphics
, brush
);
2849 RestoreDC(graphics
->hdc
, save_state
);
2854 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2855 INT y
, INT width
, INT height
)
2857 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2859 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2862 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
2867 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
2869 if(!brush
|| !graphics
|| !path
)
2870 return InvalidParameter
;
2877 FIXME("graphics object has no HDC\n");
2881 save_state
= SaveDC(graphics
->hdc
);
2882 EndPath(graphics
->hdc
);
2883 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
2886 BeginPath(graphics
->hdc
);
2887 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2888 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2893 EndPath(graphics
->hdc
);
2894 brush_fill_path(graphics
, brush
);
2899 RestoreDC(graphics
->hdc
, save_state
);
2904 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2905 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2909 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2910 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2912 if(!graphics
|| !brush
)
2913 return InvalidParameter
;
2920 FIXME("graphics object has no HDC\n");
2924 save_state
= SaveDC(graphics
->hdc
);
2925 EndPath(graphics
->hdc
);
2927 BeginPath(graphics
->hdc
);
2928 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2929 EndPath(graphics
->hdc
);
2931 brush_fill_path(graphics
, brush
);
2933 RestoreDC(graphics
->hdc
, save_state
);
2938 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2939 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2941 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2942 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2944 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2947 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
2948 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
2951 GpPointF
*ptf
= NULL
;
2953 GpStatus retval
= Ok
;
2955 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2957 if(!graphics
|| !brush
|| !points
|| !count
)
2958 return InvalidParameter
;
2965 FIXME("graphics object has no HDC\n");
2969 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2970 pti
= GdipAlloc(count
* sizeof(POINT
));
2972 retval
= OutOfMemory
;
2976 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
2978 save_state
= SaveDC(graphics
->hdc
);
2979 EndPath(graphics
->hdc
);
2980 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2983 transform_and_round_points(graphics
, pti
, ptf
, count
);
2985 BeginPath(graphics
->hdc
);
2986 Polygon(graphics
->hdc
, pti
, count
);
2987 EndPath(graphics
->hdc
);
2989 brush_fill_path(graphics
, brush
);
2991 RestoreDC(graphics
->hdc
, save_state
);
3000 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3001 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3004 GpPointF
*ptf
= NULL
;
3006 GpStatus retval
= Ok
;
3008 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3010 if(!graphics
|| !brush
|| !points
|| !count
)
3011 return InvalidParameter
;
3018 FIXME("graphics object has no HDC\n");
3022 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3023 pti
= GdipAlloc(count
* sizeof(POINT
));
3025 retval
= OutOfMemory
;
3029 for(i
= 0; i
< count
; i
++){
3030 ptf
[i
].X
= (REAL
) points
[i
].X
;
3031 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3034 save_state
= SaveDC(graphics
->hdc
);
3035 EndPath(graphics
->hdc
);
3036 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
3039 transform_and_round_points(graphics
, pti
, ptf
, count
);
3041 BeginPath(graphics
->hdc
);
3042 Polygon(graphics
->hdc
, pti
, count
);
3043 EndPath(graphics
->hdc
);
3045 brush_fill_path(graphics
, brush
);
3047 RestoreDC(graphics
->hdc
, save_state
);
3056 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3057 GDIPCONST GpPointF
*points
, INT count
)
3059 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3061 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3064 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3065 GDIPCONST GpPoint
*points
, INT count
)
3067 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3069 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3072 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3073 REAL x
, REAL y
, REAL width
, REAL height
)
3079 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3081 if(!graphics
|| !brush
)
3082 return InvalidParameter
;
3089 FIXME("graphics object has no HDC\n");
3095 ptf
[1].X
= x
+ width
;
3097 ptf
[2].X
= x
+ width
;
3098 ptf
[2].Y
= y
+ height
;
3100 ptf
[3].Y
= y
+ height
;
3102 save_state
= SaveDC(graphics
->hdc
);
3103 EndPath(graphics
->hdc
);
3105 transform_and_round_points(graphics
, pti
, ptf
, 4);
3107 BeginPath(graphics
->hdc
);
3108 Polygon(graphics
->hdc
, pti
, 4);
3109 EndPath(graphics
->hdc
);
3111 brush_fill_path(graphics
, brush
);
3113 RestoreDC(graphics
->hdc
, save_state
);
3118 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3119 INT x
, INT y
, INT width
, INT height
)
3125 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3127 if(!graphics
|| !brush
)
3128 return InvalidParameter
;
3135 FIXME("graphics object has no HDC\n");
3141 ptf
[1].X
= x
+ width
;
3143 ptf
[2].X
= x
+ width
;
3144 ptf
[2].Y
= y
+ height
;
3146 ptf
[3].Y
= y
+ height
;
3148 save_state
= SaveDC(graphics
->hdc
);
3149 EndPath(graphics
->hdc
);
3151 transform_and_round_points(graphics
, pti
, ptf
, 4);
3153 BeginPath(graphics
->hdc
);
3154 Polygon(graphics
->hdc
, pti
, 4);
3155 EndPath(graphics
->hdc
);
3157 brush_fill_path(graphics
, brush
);
3159 RestoreDC(graphics
->hdc
, save_state
);
3164 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3170 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3173 return InvalidParameter
;
3175 for(i
= 0; i
< count
; i
++){
3176 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
3177 if(ret
!= Ok
) return ret
;
3183 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3190 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3192 if(!rects
|| count
<= 0)
3193 return InvalidParameter
;
3195 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3199 for(i
= 0; i
< count
; i
++){
3200 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3201 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3202 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3203 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3206 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3212 /*****************************************************************************
3213 * GdipFillRegion [GDIPLUS.@]
3215 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3223 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
3225 if (!(graphics
&& brush
&& region
))
3226 return InvalidParameter
;
3233 FIXME("graphics object has no HDC\n");
3237 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3241 save_state
= SaveDC(graphics
->hdc
);
3242 EndPath(graphics
->hdc
);
3244 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3246 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3248 BeginPath(graphics
->hdc
);
3249 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3250 EndPath(graphics
->hdc
);
3252 brush_fill_path(graphics
, brush
);
3255 RestoreDC(graphics
->hdc
, save_state
);
3262 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
3264 TRACE("(%p,%u)\n", graphics
, intention
);
3267 return InvalidParameter
;
3272 /* We have no internal operation queue, so there's no need to clear it. */
3280 /*****************************************************************************
3281 * GdipGetClipBounds [GDIPLUS.@]
3283 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
3285 TRACE("(%p, %p)\n", graphics
, rect
);
3288 return InvalidParameter
;
3293 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
3296 /*****************************************************************************
3297 * GdipGetClipBoundsI [GDIPLUS.@]
3299 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
3301 TRACE("(%p, %p)\n", graphics
, rect
);
3304 return InvalidParameter
;
3309 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
3312 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3313 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
3314 CompositingMode
*mode
)
3316 TRACE("(%p, %p)\n", graphics
, mode
);
3318 if(!graphics
|| !mode
)
3319 return InvalidParameter
;
3324 *mode
= graphics
->compmode
;
3329 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3330 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
3331 CompositingQuality
*quality
)
3333 TRACE("(%p, %p)\n", graphics
, quality
);
3335 if(!graphics
|| !quality
)
3336 return InvalidParameter
;
3341 *quality
= graphics
->compqual
;
3346 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3347 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
3348 InterpolationMode
*mode
)
3350 TRACE("(%p, %p)\n", graphics
, mode
);
3352 if(!graphics
|| !mode
)
3353 return InvalidParameter
;
3358 *mode
= graphics
->interpolation
;
3363 /* FIXME: Need to handle color depths less than 24bpp */
3364 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
3366 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
3368 if(!graphics
|| !argb
)
3369 return InvalidParameter
;
3377 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
3379 TRACE("(%p, %p)\n", graphics
, scale
);
3381 if(!graphics
|| !scale
)
3382 return InvalidParameter
;
3387 *scale
= graphics
->scale
;
3392 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
3394 TRACE("(%p, %p)\n", graphics
, unit
);
3396 if(!graphics
|| !unit
)
3397 return InvalidParameter
;
3402 *unit
= graphics
->unit
;
3407 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3408 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3411 TRACE("(%p, %p)\n", graphics
, mode
);
3413 if(!graphics
|| !mode
)
3414 return InvalidParameter
;
3419 *mode
= graphics
->pixeloffset
;
3424 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3425 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
3427 TRACE("(%p, %p)\n", graphics
, mode
);
3429 if(!graphics
|| !mode
)
3430 return InvalidParameter
;
3435 *mode
= graphics
->smoothing
;
3440 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
3442 TRACE("(%p, %p)\n", graphics
, contrast
);
3444 if(!graphics
|| !contrast
)
3445 return InvalidParameter
;
3447 *contrast
= graphics
->textcontrast
;
3452 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3453 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
3454 TextRenderingHint
*hint
)
3456 TRACE("(%p, %p)\n", graphics
, hint
);
3458 if(!graphics
|| !hint
)
3459 return InvalidParameter
;
3464 *hint
= graphics
->texthint
;
3469 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
3474 TRACE("(%p, %p)\n", graphics
, rect
);
3476 if(!graphics
|| !rect
)
3477 return InvalidParameter
;
3482 /* intersect window and graphics clipping regions */
3483 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
3486 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
3489 /* get bounds of the region */
3490 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
3493 GdipDeleteRegion(clip_rgn
);
3498 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
3503 TRACE("(%p, %p)\n", graphics
, rect
);
3505 if(!graphics
|| !rect
)
3506 return InvalidParameter
;
3508 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
3510 rect
->X
= roundr(rectf
.X
);
3511 rect
->Y
= roundr(rectf
.Y
);
3512 rect
->Width
= roundr(rectf
.Width
);
3513 rect
->Height
= roundr(rectf
.Height
);
3519 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3521 TRACE("(%p, %p)\n", graphics
, matrix
);
3523 if(!graphics
|| !matrix
)
3524 return InvalidParameter
;
3529 *matrix
= *graphics
->worldtrans
;
3533 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
3539 TRACE("(%p, %x)\n", graphics
, color
);
3542 return InvalidParameter
;
3547 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
3550 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
3551 GdipDeleteBrush((GpBrush
*)brush
);
3555 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
3556 wnd_rect
.Width
, wnd_rect
.Height
);
3558 GdipDeleteBrush((GpBrush
*)brush
);
3563 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
3565 TRACE("(%p, %p)\n", graphics
, res
);
3567 if(!graphics
|| !res
)
3568 return InvalidParameter
;
3570 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
3573 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
3579 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
3581 if(!graphics
|| !result
)
3582 return InvalidParameter
;
3589 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
3590 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
3593 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
3596 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
3599 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
3602 GdipDeleteRegion(rgn
);
3606 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
3608 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
3611 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
3617 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
3619 if(!graphics
|| !result
)
3620 return InvalidParameter
;
3627 pts
[1].X
= x
+ width
;
3628 pts
[1].Y
= y
+ height
;
3630 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
3631 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
3634 pts
[1].X
-= pts
[0].X
;
3635 pts
[1].Y
-= pts
[0].Y
;
3637 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
3640 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
3643 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
3646 GdipDeleteRegion(rgn
);
3650 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
3652 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
3655 typedef GpStatus (*gdip_format_string_callback
)(GpGraphics
*graphics
,
3656 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3657 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3658 INT lineno
, const RectF
*bounds
, void *user_data
);
3660 static GpStatus
gdip_format_string(GpGraphics
*graphics
,
3661 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
3662 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3663 gdip_format_string_callback callback
, void *user_data
)
3666 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
3667 nheight
, lineend
, lineno
= 0;
3669 StringAlignment halign
;
3673 if(length
== -1) length
= lstrlenW(string
);
3675 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
3676 if(!stringdup
) return OutOfMemory
;
3678 nwidth
= roundr(rect
->Width
);
3679 nheight
= roundr(rect
->Height
);
3681 if (rect
->Width
>= INT_MAX
|| rect
->Width
< 0.5) nwidth
= INT_MAX
;
3682 if (rect
->Height
>= INT_MAX
|| rect
->Width
< 0.5) nheight
= INT_MAX
;
3684 for(i
= 0, j
= 0; i
< length
; i
++){
3685 /* FIXME: This makes the indexes passed to callback inaccurate. */
3686 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
3689 stringdup
[j
] = string
[i
];
3695 if (format
) halign
= format
->align
;
3696 else halign
= StringAlignmentNear
;
3698 while(sum
< length
){
3699 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
3700 nwidth
, &fit
, NULL
, &size
);
3706 for(lret
= 0; lret
< fit
; lret
++)
3707 if(*(stringdup
+ sum
+ lret
) == '\n')
3710 /* Line break code (may look strange, but it imitates windows). */
3712 lineend
= fit
= lret
; /* this is not an off-by-one error */
3713 else if(fit
< (length
- sum
)){
3714 if(*(stringdup
+ sum
+ fit
) == ' ')
3715 while(*(stringdup
+ sum
+ fit
) == ' ')
3718 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
3721 if(*(stringdup
+ sum
+ fit
) == '\t')
3730 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
3731 *(stringdup
+ sum
+ lineend
- 1) == '\t')
3737 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, lineend
,
3738 nwidth
, &j
, NULL
, &size
);
3740 bounds
.Width
= size
.cx
;
3742 if(height
+ size
.cy
> nheight
)
3743 bounds
.Height
= nheight
- (height
+ size
.cy
);
3745 bounds
.Height
= size
.cy
;
3747 bounds
.Y
= rect
->Y
+ height
;
3751 case StringAlignmentNear
:
3755 case StringAlignmentCenter
:
3756 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
3758 case StringAlignmentFar
:
3759 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
3763 stat
= callback(graphics
, stringdup
, sum
, lineend
,
3764 font
, rect
, format
, lineno
, &bounds
, user_data
);
3769 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
3773 if(height
> nheight
)
3776 /* Stop if this was a linewrap (but not if it was a linebreak). */
3777 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
3781 GdipFree(stringdup
);
3786 struct measure_ranges_args
{
3790 static GpStatus
measure_ranges_callback(GpGraphics
*graphics
,
3791 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3792 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3793 INT lineno
, const RectF
*bounds
, void *user_data
)
3797 struct measure_ranges_args
*args
= user_data
;
3799 for (i
=0; i
<format
->range_count
; i
++)
3801 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
3802 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
3803 if (range_start
< range_end
)
3808 range_rect
.Y
= bounds
->Y
;
3809 range_rect
.Height
= bounds
->Height
;
3811 GetTextExtentExPointW(graphics
->hdc
, string
+ index
, range_start
- index
,
3812 INT_MAX
, NULL
, NULL
, &range_size
);
3813 range_rect
.X
= bounds
->X
+ range_size
.cx
;
3815 GetTextExtentExPointW(graphics
->hdc
, string
+ index
, range_end
- index
,
3816 INT_MAX
, NULL
, NULL
, &range_size
);
3817 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) - range_rect
.X
;
3819 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
3828 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
3829 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
3830 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
3831 INT regionCount
, GpRegion
** regions
)
3836 struct measure_ranges_args args
;
3839 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
3840 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
3842 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
3843 return InvalidParameter
;
3845 if (regionCount
< stringFormat
->range_count
)
3846 return InvalidParameter
;
3850 temp_hdc
= graphics
->hdc
= CreateCompatibleDC(0);
3851 if (!temp_hdc
) return OutOfMemory
;
3854 if (stringFormat
->attr
)
3855 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
3857 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
3859 for (i
=0; i
<stringFormat
->range_count
; i
++)
3861 stat
= GdipSetEmpty(regions
[i
]);
3866 args
.regions
= regions
;
3868 stat
= gdip_format_string(graphics
, string
, length
, font
, layoutRect
, stringFormat
,
3869 measure_ranges_callback
, &args
);
3871 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
3875 graphics
->hdc
= NULL
;
3882 struct measure_string_args
{
3884 INT
*codepointsfitted
;
3888 static GpStatus
measure_string_callback(GpGraphics
*graphics
,
3889 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3890 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3891 INT lineno
, const RectF
*bounds
, void *user_data
)
3893 struct measure_string_args
*args
= user_data
;
3895 if (bounds
->Width
> args
->bounds
->Width
)
3896 args
->bounds
->Width
= bounds
->Width
;
3898 if (bounds
->Height
+ bounds
->Y
> args
->bounds
->Height
+ args
->bounds
->Y
)
3899 args
->bounds
->Height
= bounds
->Height
+ bounds
->Y
- args
->bounds
->Y
;
3901 if (args
->codepointsfitted
)
3902 *args
->codepointsfitted
= index
+ length
;
3904 if (args
->linesfilled
)
3905 (*args
->linesfilled
)++;
3910 /* Find the smallest rectangle that bounds the text when it is printed in rect
3911 * according to the format options listed in format. If rect has 0 width and
3912 * height, then just find the smallest rectangle that bounds the text when it's
3913 * printed at location (rect->X, rect-Y). */
3914 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
3915 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
3916 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
3917 INT
*codepointsfitted
, INT
*linesfilled
)
3920 struct measure_string_args args
;
3923 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
3924 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
3925 bounds
, codepointsfitted
, linesfilled
);
3927 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
3928 return InvalidParameter
;
3932 temp_hdc
= graphics
->hdc
= CreateCompatibleDC(0);
3933 if (!temp_hdc
) return OutOfMemory
;
3936 if(linesfilled
) *linesfilled
= 0;
3937 if(codepointsfitted
) *codepointsfitted
= 0;
3940 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
3942 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
3944 bounds
->X
= rect
->X
;
3945 bounds
->Y
= rect
->Y
;
3946 bounds
->Width
= 0.0;
3947 bounds
->Height
= 0.0;
3949 args
.bounds
= bounds
;
3950 args
.codepointsfitted
= codepointsfitted
;
3951 args
.linesfilled
= linesfilled
;
3953 gdip_format_string(graphics
, string
, length
, font
, rect
, format
,
3954 measure_string_callback
, &args
);
3956 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
3960 graphics
->hdc
= NULL
;
3967 struct draw_string_args
{
3970 REAL ang_cos
, ang_sin
;
3973 static GpStatus
draw_string_callback(GpGraphics
*graphics
,
3974 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3975 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3976 INT lineno
, const RectF
*bounds
, void *user_data
)
3978 struct draw_string_args
*args
= user_data
;
3981 drawcoord
.left
= drawcoord
.right
= args
->drawbase
.x
+ roundr(args
->ang_sin
* bounds
->Y
);
3982 drawcoord
.top
= drawcoord
.bottom
= args
->drawbase
.y
+ roundr(args
->ang_cos
* bounds
->Y
);
3984 DrawTextW(graphics
->hdc
, string
+ index
, length
, &drawcoord
, args
->drawflags
);
3989 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
3990 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
3991 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
3996 TEXTMETRICW textmet
;
3997 GpPointF pt
[3], rectcpy
[4];
3999 REAL angle
, rel_width
, rel_height
;
4000 INT offsety
= 0, save_state
;
4001 struct draw_string_args args
;
4004 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4005 length
, font
, debugstr_rectf(rect
), format
, brush
);
4007 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4008 return InvalidParameter
;
4010 if((brush
->bt
!= BrushTypeSolidColor
)){
4011 FIXME("not implemented for given parameters\n");
4012 return NotImplemented
;
4017 FIXME("graphics object has no HDC\n");
4018 return NotImplemented
;
4022 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4024 /* Should be no need to explicitly test for StringAlignmentNear as
4025 * that is default behavior if no alignment is passed. */
4026 if(format
->vertalign
!= StringAlignmentNear
){
4028 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
4030 if(format
->vertalign
== StringAlignmentCenter
)
4031 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4032 else if(format
->vertalign
== StringAlignmentFar
)
4033 offsety
= (rect
->Height
- bounds
.Height
);
4037 save_state
= SaveDC(graphics
->hdc
);
4038 SetBkMode(graphics
->hdc
, TRANSPARENT
);
4039 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
4047 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4048 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
4049 args
.ang_cos
= cos(angle
);
4050 args
.ang_sin
= sin(angle
);
4051 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4052 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4053 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4054 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4056 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
4057 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
4058 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
4059 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
4060 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
4062 scaled_rect
.X
= 0.0;
4063 scaled_rect
.Y
= 0.0;
4064 scaled_rect
.Width
= rel_width
* rect
->Width
;
4065 scaled_rect
.Height
= rel_height
* rect
->Height
;
4067 if (roundr(scaled_rect
.Width
) != 0 && roundr(scaled_rect
.Height
) != 0)
4069 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4070 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
4071 SelectClipRgn(graphics
->hdc
, rgn
);
4074 /* Use gdi to find the font, then perform transformations on it (height,
4076 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
4077 GetTextMetricsW(graphics
->hdc
, &textmet
);
4080 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
4081 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
4083 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
4085 gdifont
= CreateFontIndirectW(&lfw
);
4086 DeleteObject(SelectObject(graphics
->hdc
, CreateFontIndirectW(&lfw
)));
4088 if (!format
|| format
->align
== StringAlignmentNear
)
4090 args
.drawbase
.x
= corners
[0].x
;
4091 args
.drawbase
.y
= corners
[0].y
;
4092 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
;
4094 else if (format
->align
== StringAlignmentCenter
)
4096 args
.drawbase
.x
= (corners
[0].x
+ corners
[1].x
)/2;
4097 args
.drawbase
.y
= (corners
[0].y
+ corners
[1].y
)/2;
4098 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_CENTER
;
4100 else /* (format->align == StringAlignmentFar) */
4102 args
.drawbase
.x
= corners
[1].x
;
4103 args
.drawbase
.y
= corners
[1].y
;
4104 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_RIGHT
;
4107 gdip_format_string(graphics
, string
, length
, font
, &scaled_rect
, format
,
4108 draw_string_callback
, &args
);
4111 DeleteObject(gdifont
);
4113 RestoreDC(graphics
->hdc
, save_state
);
4118 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
4120 TRACE("(%p)\n", graphics
);
4123 return InvalidParameter
;
4128 return GdipSetInfinite(graphics
->clip
);
4131 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
4133 TRACE("(%p)\n", graphics
);
4136 return InvalidParameter
;
4141 graphics
->worldtrans
->matrix
[0] = 1.0;
4142 graphics
->worldtrans
->matrix
[1] = 0.0;
4143 graphics
->worldtrans
->matrix
[2] = 0.0;
4144 graphics
->worldtrans
->matrix
[3] = 1.0;
4145 graphics
->worldtrans
->matrix
[4] = 0.0;
4146 graphics
->worldtrans
->matrix
[5] = 0.0;
4151 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
4153 return GdipEndContainer(graphics
, state
);
4156 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
4157 GpMatrixOrder order
)
4159 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
4162 return InvalidParameter
;
4167 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
4170 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
4172 return GdipBeginContainer2(graphics
, state
);
4175 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
4176 GraphicsContainer
*state
)
4178 GraphicsContainerItem
*container
;
4181 TRACE("(%p, %p)\n", graphics
, state
);
4183 if(!graphics
|| !state
)
4184 return InvalidParameter
;
4186 sts
= init_container(&container
, graphics
);
4190 list_add_head(&graphics
->containers
, &container
->entry
);
4191 *state
= graphics
->contid
= container
->contid
;
4196 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4198 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4199 return NotImplemented
;
4202 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4204 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4205 return NotImplemented
;
4208 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
4210 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
4211 return NotImplemented
;
4214 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
4217 GraphicsContainerItem
*container
, *container2
;
4219 TRACE("(%p, %x)\n", graphics
, state
);
4222 return InvalidParameter
;
4224 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
4225 if(container
->contid
== state
)
4229 /* did not find a matching container */
4230 if(&container
->entry
== &graphics
->containers
)
4233 sts
= restore_container(graphics
, container
);
4237 /* remove all of the containers on top of the found container */
4238 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
4239 if(container
->contid
== state
)
4241 list_remove(&container
->entry
);
4242 delete_container(container
);
4245 list_remove(&container
->entry
);
4246 delete_container(container
);
4251 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
4252 REAL sy
, GpMatrixOrder order
)
4254 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
4257 return InvalidParameter
;
4262 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
4265 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
4268 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
4270 if(!graphics
|| !srcgraphics
)
4271 return InvalidParameter
;
4273 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
4276 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
4277 CompositingMode mode
)
4279 TRACE("(%p, %d)\n", graphics
, mode
);
4282 return InvalidParameter
;
4287 graphics
->compmode
= mode
;
4292 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
4293 CompositingQuality quality
)
4295 TRACE("(%p, %d)\n", graphics
, quality
);
4298 return InvalidParameter
;
4303 graphics
->compqual
= quality
;
4308 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
4309 InterpolationMode mode
)
4311 TRACE("(%p, %d)\n", graphics
, mode
);
4314 return InvalidParameter
;
4319 graphics
->interpolation
= mode
;
4324 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
4326 TRACE("(%p, %.2f)\n", graphics
, scale
);
4328 if(!graphics
|| (scale
<= 0.0))
4329 return InvalidParameter
;
4334 graphics
->scale
= scale
;
4339 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
4341 TRACE("(%p, %d)\n", graphics
, unit
);
4344 return InvalidParameter
;
4349 if(unit
== UnitWorld
)
4350 return InvalidParameter
;
4352 graphics
->unit
= unit
;
4357 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4360 TRACE("(%p, %d)\n", graphics
, mode
);
4363 return InvalidParameter
;
4368 graphics
->pixeloffset
= mode
;
4373 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
4377 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
4380 FIXME("not implemented\n");
4382 return NotImplemented
;
4385 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
4389 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
4392 FIXME("not implemented\n");
4396 return NotImplemented
;
4399 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
4401 TRACE("(%p, %d)\n", graphics
, mode
);
4404 return InvalidParameter
;
4409 graphics
->smoothing
= mode
;
4414 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
4416 TRACE("(%p, %d)\n", graphics
, contrast
);
4419 return InvalidParameter
;
4421 graphics
->textcontrast
= contrast
;
4426 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
4427 TextRenderingHint hint
)
4429 TRACE("(%p, %d)\n", graphics
, hint
);
4432 return InvalidParameter
;
4437 graphics
->texthint
= hint
;
4442 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4444 TRACE("(%p, %p)\n", graphics
, matrix
);
4446 if(!graphics
|| !matrix
)
4447 return InvalidParameter
;
4452 GdipDeleteMatrix(graphics
->worldtrans
);
4453 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
4456 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
4457 REAL dy
, GpMatrixOrder order
)
4459 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
4462 return InvalidParameter
;
4467 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
4470 /*****************************************************************************
4471 * GdipSetClipHrgn [GDIPLUS.@]
4473 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
4478 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
4481 return InvalidParameter
;
4483 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
4487 status
= GdipSetClipRegion(graphics
, region
, mode
);
4489 GdipDeleteRegion(region
);
4493 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
4495 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
4498 return InvalidParameter
;
4503 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
4506 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
4507 REAL width
, REAL height
,
4512 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
4515 return InvalidParameter
;
4523 rect
.Height
= height
;
4525 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
4528 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
4529 INT width
, INT height
,
4532 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
4535 return InvalidParameter
;
4540 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
4543 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
4546 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
4548 if(!graphics
|| !region
)
4549 return InvalidParameter
;
4554 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
4557 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
4562 TRACE("(%p,%u)\n", metafile
, limitDpi
);
4565 FIXME("not implemented\n");
4567 return NotImplemented
;
4570 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
4576 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
4578 if(!graphics
|| !pen
|| count
<=0)
4579 return InvalidParameter
;
4584 pti
= GdipAlloc(sizeof(POINT
) * count
);
4586 save_state
= prepare_dc(graphics
, pen
);
4587 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
4589 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
4590 Polygon(graphics
->hdc
, pti
, count
);
4592 restore_dc(graphics
, save_state
);
4598 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
4605 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
4607 if(count
<=0) return InvalidParameter
;
4608 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
4610 for(i
= 0;i
< count
; i
++){
4611 ptf
[i
].X
= (REAL
)points
[i
].X
;
4612 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
4615 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
4621 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
4623 TRACE("(%p, %p)\n", graphics
, dpi
);
4625 if(!graphics
|| !dpi
)
4626 return InvalidParameter
;
4631 if (graphics
->image
)
4632 *dpi
= graphics
->image
->xres
;
4634 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
4639 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
4641 TRACE("(%p, %p)\n", graphics
, dpi
);
4643 if(!graphics
|| !dpi
)
4644 return InvalidParameter
;
4649 if (graphics
->image
)
4650 *dpi
= graphics
->image
->yres
;
4652 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
4657 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
4658 GpMatrixOrder order
)
4663 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
4665 if(!graphics
|| !matrix
)
4666 return InvalidParameter
;
4671 m
= *(graphics
->worldtrans
);
4673 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
4675 *(graphics
->worldtrans
) = m
;
4680 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
4681 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
4683 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
4685 TRACE("(%p, %p)\n", graphics
, hdc
);
4687 if(!graphics
|| !hdc
)
4688 return InvalidParameter
;
4693 if (!graphics
->hdc
||
4694 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
4696 /* Create a fake HDC and fill it with a constant color. */
4701 BITMAPINFOHEADER bmih
;
4704 stat
= get_graphics_bounds(graphics
, &bounds
);
4708 graphics
->temp_hbitmap_width
= bounds
.Width
;
4709 graphics
->temp_hbitmap_height
= bounds
.Height
;
4711 bmih
.biSize
= sizeof(bmih
);
4712 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
4713 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
4715 bmih
.biBitCount
= 32;
4716 bmih
.biCompression
= BI_RGB
;
4717 bmih
.biSizeImage
= 0;
4718 bmih
.biXPelsPerMeter
= 0;
4719 bmih
.biYPelsPerMeter
= 0;
4721 bmih
.biClrImportant
= 0;
4723 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
4724 (void**)&graphics
->temp_bits
, NULL
, 0);
4726 return GenericError
;
4728 temp_hdc
= CreateCompatibleDC(0);
4731 DeleteObject(hbitmap
);
4732 return GenericError
;
4735 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
4736 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
4738 SelectObject(temp_hdc
, hbitmap
);
4740 graphics
->temp_hbitmap
= hbitmap
;
4741 *hdc
= graphics
->temp_hdc
= temp_hdc
;
4745 *hdc
= graphics
->hdc
;
4748 graphics
->busy
= TRUE
;
4753 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
4755 TRACE("(%p, %p)\n", graphics
, hdc
);
4757 if(!graphics
|| !hdc
)
4758 return InvalidParameter
;
4760 if((graphics
->hdc
!= hdc
&& graphics
->temp_hdc
!= hdc
) || !(graphics
->busy
))
4761 return InvalidParameter
;
4763 if (graphics
->temp_hdc
== hdc
)
4768 /* Find the pixels that have changed, and mark them as opaque. */
4769 pos
= (DWORD
*)graphics
->temp_bits
;
4770 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
4772 if (*pos
!= DC_BACKGROUND_KEY
)
4779 /* Write the changed pixels to the real target. */
4780 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
4781 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
4782 graphics
->temp_hbitmap_width
* 4);
4785 DeleteDC(graphics
->temp_hdc
);
4786 DeleteObject(graphics
->temp_hbitmap
);
4787 graphics
->temp_hdc
= NULL
;
4788 graphics
->temp_hbitmap
= NULL
;
4791 graphics
->busy
= FALSE
;
4796 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
4801 TRACE("(%p, %p)\n", graphics
, region
);
4803 if(!graphics
|| !region
)
4804 return InvalidParameter
;
4809 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
4812 /* free everything except root node and header */
4813 delete_element(®ion
->node
);
4814 memcpy(region
, clip
, sizeof(GpRegion
));
4820 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
4821 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
4827 if(!graphics
|| !points
|| count
<= 0)
4828 return InvalidParameter
;
4833 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
4835 if (src_space
== dst_space
) return Ok
;
4837 stat
= GdipCreateMatrix(&matrix
);
4840 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
4842 if(graphics
->unit
!= UnitDisplay
)
4843 unitscale
*= graphics
->scale
;
4845 /* transform from src_space to CoordinateSpacePage */
4848 case CoordinateSpaceWorld
:
4849 GdipMultiplyMatrix(matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
4851 case CoordinateSpacePage
:
4853 case CoordinateSpaceDevice
:
4854 GdipScaleMatrix(matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
4858 /* transform from CoordinateSpacePage to dst_space */
4861 case CoordinateSpaceWorld
:
4863 GpMatrix
*inverted_transform
;
4864 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
4867 stat
= GdipInvertMatrix(inverted_transform
);
4869 GdipMultiplyMatrix(matrix
, inverted_transform
, MatrixOrderAppend
);
4870 GdipDeleteMatrix(inverted_transform
);
4874 case CoordinateSpacePage
:
4876 case CoordinateSpaceDevice
:
4877 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
4882 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
4884 GdipDeleteMatrix(matrix
);
4890 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
4891 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
4897 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
4900 return InvalidParameter
;
4902 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
4906 for(i
= 0; i
< count
; i
++){
4907 pointsF
[i
].X
= (REAL
)points
[i
].X
;
4908 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
4911 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
4914 for(i
= 0; i
< count
; i
++){
4915 points
[i
].X
= roundr(pointsF
[i
].X
);
4916 points
[i
].Y
= roundr(pointsF
[i
].Y
);
4923 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
4935 /*****************************************************************************
4936 * GdipTranslateClip [GDIPLUS.@]
4938 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
4940 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
4943 return InvalidParameter
;
4948 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
4951 /*****************************************************************************
4952 * GdipTranslateClipI [GDIPLUS.@]
4954 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
4956 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
4959 return InvalidParameter
;
4964 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
4968 /*****************************************************************************
4969 * GdipMeasureDriverString [GDIPLUS.@]
4971 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
4972 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
4973 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
4975 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
4976 return NotImplemented
;
4979 /*****************************************************************************
4980 * GdipDrawDriverString [GDIPLUS.@]
4982 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
4983 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
4984 GDIPCONST PointF
*positions
, INT flags
,
4985 GDIPCONST GpMatrix
*matrix
)
4987 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics
, text
, length
, font
, brush
, positions
, flags
, matrix
);
4988 return NotImplemented
;
4991 GpStatus WINGDIPAPI
GdipRecordMetafile(HDC hdc
, EmfType type
, GDIPCONST GpRectF
*frameRect
,
4992 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
4994 FIXME("(%p %d %p %d %p %p): stub\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
4995 return NotImplemented
;
4998 /*****************************************************************************
4999 * GdipRecordMetafileI [GDIPLUS.@]
5001 GpStatus WINGDIPAPI
GdipRecordMetafileI(HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
5002 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
5004 FIXME("(%p %d %p %d %p %p): stub\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
5005 return NotImplemented
;
5008 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
5009 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
5011 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
5012 return NotImplemented
;
5015 /*****************************************************************************
5016 * GdipIsVisibleClipEmpty [GDIPLUS.@]
5018 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
5023 TRACE("(%p, %p)\n", graphics
, res
);
5025 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
5028 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
5031 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
5034 GdipDeleteRegion(rgn
);