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
];
101 save_state
= SaveDC(graphics
->hdc
);
103 EndPath(graphics
->hdc
);
105 if(pen
->unit
== UnitPixel
){
109 /* Get an estimate for the amount the pen width is affected by the world
110 * transform. (This is similar to what some of the wine drivers do.) */
115 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
116 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
117 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
119 width
*= pen
->width
* convert_unit(graphics_res(graphics
),
120 pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
);
123 if(pen
->dash
== DashStyleCustom
){
124 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
126 TRACE("dashes are: ");
127 for(i
= 0; i
< numdashes
; i
++){
128 dash_array
[i
] = roundr(width
* pen
->dashes
[i
]);
129 TRACE("%d, ", dash_array
[i
]);
131 TRACE("\n and the pen style is %x\n", pen
->style
);
133 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
,
134 numdashes
, dash_array
);
137 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
, 0, NULL
);
139 SelectObject(graphics
->hdc
, gdipen
);
144 static void restore_dc(GpGraphics
*graphics
, INT state
)
146 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
147 RestoreDC(graphics
->hdc
, state
);
150 /* This helper applies all the changes that the points listed in ptf need in
151 * order to be drawn on the device context. In the end, this should include at
153 * -scaling by page unit
154 * -applying world transformation
155 * -converting from float to int
156 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
157 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
158 * gdi to draw, and these functions would irreparably mess with line widths.
160 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
161 GpPointF
*ptf
, INT count
)
167 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
169 /* apply page scale */
170 if(graphics
->unit
!= UnitDisplay
)
171 unitscale
*= graphics
->scale
;
173 GdipCloneMatrix(graphics
->worldtrans
, &matrix
);
174 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
175 GdipTransformMatrixPoints(matrix
, ptf
, count
);
176 GdipDeleteMatrix(matrix
);
178 for(i
= 0; i
< count
; i
++){
179 pti
[i
].x
= roundr(ptf
[i
].X
);
180 pti
[i
].y
= roundr(ptf
[i
].Y
);
184 /* Draw non-premultiplied ARGB data to the given graphics object */
185 static GpStatus
alpha_blend_pixels(GpGraphics
*graphics
, INT dst_x
, INT dst_y
,
186 const BYTE
*src
, INT src_width
, INT src_height
, INT src_stride
)
188 if (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
)
190 GpBitmap
*dst_bitmap
= (GpBitmap
*)graphics
->image
;
193 for (x
=0; x
<src_width
; x
++)
195 for (y
=0; y
<src_height
; y
++)
197 ARGB dst_color
, src_color
;
198 GdipBitmapGetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, &dst_color
);
199 src_color
= ((ARGB
*)(src
+ src_stride
* y
))[x
];
200 GdipBitmapSetPixel(dst_bitmap
, x
+dst_x
, y
+dst_y
, color_over(dst_color
, src_color
));
209 HBITMAP hbitmap
, old_hbm
=NULL
;
210 BITMAPINFOHEADER bih
;
214 hdc
= CreateCompatibleDC(0);
216 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
217 bih
.biWidth
= src_width
;
218 bih
.biHeight
= -src_height
;
221 bih
.biCompression
= BI_RGB
;
223 bih
.biXPelsPerMeter
= 0;
224 bih
.biYPelsPerMeter
= 0;
226 bih
.biClrImportant
= 0;
228 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
229 (void**)&temp_bits
, NULL
, 0);
231 convert_32bppARGB_to_32bppPARGB(src_width
, src_height
, temp_bits
,
232 4 * src_width
, src
, src_stride
);
234 old_hbm
= SelectObject(hdc
, hbitmap
);
236 bf
.BlendOp
= AC_SRC_OVER
;
238 bf
.SourceConstantAlpha
= 255;
239 bf
.AlphaFormat
= AC_SRC_ALPHA
;
241 GdiAlphaBlend(graphics
->hdc
, dst_x
, dst_y
, src_width
, src_height
,
242 hdc
, 0, 0, src_width
, src_height
, bf
);
244 SelectObject(hdc
, old_hbm
);
246 DeleteObject(hbitmap
);
252 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
256 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
257 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
261 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
265 /* clamp to between 0.0 and 1.0, using the wrap mode */
266 if (brush
->wrap
== WrapModeTile
)
268 position
= fmodf(position
, 1.0f
);
269 if (position
< 0.0f
) position
+= 1.0f
;
271 else /* WrapModeFlip* */
273 position
= fmodf(position
, 2.0f
);
274 if (position
< 0.0f
) position
+= 2.0f
;
275 if (position
> 1.0f
) position
= 2.0f
- position
;
278 if (brush
->blendcount
== 1)
283 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
286 /* locate the blend positions surrounding this position */
287 while (position
> brush
->blendpos
[i
])
290 /* interpolate between the blend positions */
291 left_blendpos
= brush
->blendpos
[i
-1];
292 left_blendfac
= brush
->blendfac
[i
-1];
293 right_blendpos
= brush
->blendpos
[i
];
294 right_blendfac
= brush
->blendfac
[i
];
295 range
= right_blendpos
- left_blendpos
;
296 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
297 right_blendfac
* (position
- left_blendpos
)) / range
;
300 if (brush
->pblendcount
== 0)
301 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
305 ARGB left_blendcolor
, right_blendcolor
;
306 REAL left_blendpos
, right_blendpos
;
308 /* locate the blend colors surrounding this position */
309 while (blendfac
> brush
->pblendpos
[i
])
312 /* interpolate between the blend colors */
313 left_blendpos
= brush
->pblendpos
[i
-1];
314 left_blendcolor
= brush
->pblendcolor
[i
-1];
315 right_blendpos
= brush
->pblendpos
[i
];
316 right_blendcolor
= brush
->pblendcolor
[i
];
317 blendfac
= (blendfac
- left_blendpos
) / (right_blendpos
- left_blendpos
);
318 return blend_colors(left_blendcolor
, right_blendcolor
, blendfac
);
322 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
326 case BrushTypeLinearGradient
:
328 GpLineGradient
*line
= (GpLineGradient
*)brush
;
331 SelectClipPath(graphics
->hdc
, RGN_AND
);
332 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
334 GpPointF endpointsf
[2];
338 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
340 endpointsf
[0] = line
->startpoint
;
341 endpointsf
[1] = line
->endpoint
;
342 transform_and_round_points(graphics
, endpointsi
, endpointsf
, 2);
344 if (abs(endpointsi
[0].x
-endpointsi
[1].x
) > abs(endpointsi
[0].y
-endpointsi
[1].y
))
346 /* vertical-ish gradient */
347 int startx
, endx
; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
348 int startbottomx
; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
351 HBRUSH hbrush
, hprevbrush
;
352 int leftx
, rightx
; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
354 int tilt
; /* horizontal distance covered by a gradient line */
356 startx
= roundr((rc
.top
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
357 endx
= roundr((rc
.top
- endpointsf
[1].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[1].X
);
358 width
= endx
- startx
;
359 startbottomx
= roundr((rc
.bottom
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
360 tilt
= startx
- startbottomx
;
362 if (startx
>= startbottomx
)
365 rightx
= rc
.right
+ tilt
;
369 leftx
= rc
.left
+ tilt
;
373 poly
[0].y
= rc
.bottom
;
376 poly
[3].y
= rc
.bottom
;
378 for (x
=leftx
; x
<=rightx
; x
++)
380 ARGB argb
= blend_line_gradient(line
, (x
-startx
)/(REAL
)width
);
381 col
= ARGB2COLORREF(argb
);
382 hbrush
= CreateSolidBrush(col
);
383 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
384 poly
[0].x
= x
- tilt
- 1;
387 poly
[3].x
= x
- tilt
;
388 Polygon(graphics
->hdc
, poly
, 4);
389 SelectObject(graphics
->hdc
, hprevbrush
);
390 DeleteObject(hbrush
);
393 else if (endpointsi
[0].y
!= endpointsi
[1].y
)
395 /* horizontal-ish gradient */
396 int starty
, endy
; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
397 int startrighty
; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
400 HBRUSH hbrush
, hprevbrush
;
401 int topy
, bottomy
; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
403 int tilt
; /* vertical distance covered by a gradient line */
405 starty
= roundr((rc
.left
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
406 endy
= roundr((rc
.left
- endpointsf
[1].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[1].Y
);
407 height
= endy
- starty
;
408 startrighty
= roundr((rc
.right
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
409 tilt
= starty
- startrighty
;
411 if (starty
>= startrighty
)
414 bottomy
= rc
.bottom
+ tilt
;
418 topy
= rc
.top
+ tilt
;
422 poly
[0].x
= rc
.right
;
425 poly
[3].x
= rc
.right
;
427 for (y
=topy
; y
<=bottomy
; y
++)
429 ARGB argb
= blend_line_gradient(line
, (y
-starty
)/(REAL
)height
);
430 col
= ARGB2COLORREF(argb
);
431 hbrush
= CreateSolidBrush(col
);
432 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
433 poly
[0].y
= y
- tilt
- 1;
436 poly
[3].y
= y
- tilt
;
437 Polygon(graphics
->hdc
, poly
, 4);
438 SelectObject(graphics
->hdc
, hprevbrush
);
439 DeleteObject(hbrush
);
442 /* else startpoint == endpoint */
446 case BrushTypeSolidColor
:
448 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
452 /* partially transparent fill */
454 SelectClipPath(graphics
->hdc
, RGN_AND
);
455 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
457 HDC hdc
= CreateCompatibleDC(NULL
);
463 oldbmp
= SelectObject(hdc
, fill
->bmp
);
465 bf
.BlendOp
= AC_SRC_OVER
;
467 bf
.SourceConstantAlpha
= 255;
468 bf
.AlphaFormat
= AC_SRC_ALPHA
;
470 GdiAlphaBlend(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, hdc
, 0, 0, 1, 1, bf
);
472 SelectObject(hdc
, oldbmp
);
478 /* else fall through */
481 SelectObject(graphics
->hdc
, brush
->gdibrush
);
482 FillPath(graphics
->hdc
);
487 /* GdipDrawPie/GdipFillPie helper function */
488 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
489 REAL height
, REAL startAngle
, REAL sweepAngle
)
496 ptf
[1].X
= x
+ width
;
497 ptf
[1].Y
= y
+ height
;
499 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
500 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
502 transform_and_round_points(graphics
, pti
, ptf
, 4);
504 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
505 pti
[2].y
, pti
[3].x
, pti
[3].y
);
508 /* Draws the linecap the specified color and size on the hdc. The linecap is in
509 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
510 * should not be called on an hdc that has a path you care about. */
511 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
512 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
514 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
515 GpMatrix
*matrix
= NULL
;
518 PointF ptf
[4], *custptf
= NULL
;
519 POINT pt
[4], *custpt
= NULL
;
521 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
526 if((x1
== x2
) && (y1
== y2
))
529 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
531 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
533 brush
= CreateSolidBrush(color
);
534 lb
.lbStyle
= BS_SOLID
;
537 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
538 PS_JOIN_MITER
, 1, &lb
, 0,
540 oldbrush
= SelectObject(graphics
->hdc
, brush
);
541 oldpen
= SelectObject(graphics
->hdc
, pen
);
548 case LineCapSquareAnchor
:
549 case LineCapDiamondAnchor
:
550 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
551 if(cap
== LineCapDiamondAnchor
){
552 dsmall
= cos(theta
+ M_PI_2
) * size
;
553 dbig
= sin(theta
+ M_PI_2
) * size
;
556 dsmall
= cos(theta
+ M_PI_4
) * size
;
557 dbig
= sin(theta
+ M_PI_4
) * size
;
560 ptf
[0].X
= x2
- dsmall
;
561 ptf
[1].X
= x2
+ dbig
;
563 ptf
[0].Y
= y2
- dbig
;
564 ptf
[3].Y
= y2
+ dsmall
;
566 ptf
[1].Y
= y2
- dsmall
;
567 ptf
[2].Y
= y2
+ dbig
;
569 ptf
[3].X
= x2
- dbig
;
570 ptf
[2].X
= x2
+ dsmall
;
572 transform_and_round_points(graphics
, pt
, ptf
, 4);
573 Polygon(graphics
->hdc
, pt
, 4);
576 case LineCapArrowAnchor
:
577 size
= size
* 4.0 / sqrt(3.0);
579 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
580 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
585 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
586 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
594 transform_and_round_points(graphics
, pt
, ptf
, 3);
595 Polygon(graphics
->hdc
, pt
, 3);
598 case LineCapRoundAnchor
:
599 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
606 transform_and_round_points(graphics
, pt
, ptf
, 2);
607 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
610 case LineCapTriangle
:
612 dx
= cos(M_PI_2
+ theta
) * size
;
613 dy
= sin(M_PI_2
+ theta
) * size
;
620 dx
= cos(theta
) * size
;
621 dy
= sin(theta
) * size
;
626 transform_and_round_points(graphics
, pt
, ptf
, 3);
627 Polygon(graphics
->hdc
, pt
, 3);
631 dx
= dy
= size
/ 2.0;
638 dx
= -cos(M_PI_2
+ theta
) * size
;
639 dy
= -sin(M_PI_2
+ theta
) * size
;
646 transform_and_round_points(graphics
, pt
, ptf
, 4);
647 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
648 pt
[2].y
, pt
[3].x
, pt
[3].y
);
655 count
= custom
->pathdata
.Count
;
656 custptf
= GdipAlloc(count
* sizeof(PointF
));
657 custpt
= GdipAlloc(count
* sizeof(POINT
));
658 tp
= GdipAlloc(count
);
660 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
663 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
665 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
666 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
668 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
669 GdipTransformMatrixPoints(matrix
, custptf
, count
);
671 transform_and_round_points(graphics
, custpt
, custptf
, count
);
673 for(i
= 0; i
< count
; i
++)
674 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
677 BeginPath(graphics
->hdc
);
678 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
679 EndPath(graphics
->hdc
);
680 StrokeAndFillPath(graphics
->hdc
);
683 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
689 GdipDeleteMatrix(matrix
);
696 SelectObject(graphics
->hdc
, oldbrush
);
697 SelectObject(graphics
->hdc
, oldpen
);
703 /* Shortens the line by the given percent by changing x2, y2.
704 * If percent is > 1.0 then the line will change direction.
705 * If percent is negative it can lengthen the line. */
706 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
708 REAL dist
, theta
, dx
, dy
;
710 if((y1
== *y2
) && (x1
== *x2
))
713 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
714 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
715 dx
= cos(theta
) * dist
;
716 dy
= sin(theta
) * dist
;
722 /* Shortens the line by the given amount by changing x2, y2.
723 * If the amount is greater than the distance, the line will become length 0.
724 * If the amount is negative, it can lengthen the line. */
725 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
727 REAL dx
, dy
, percent
;
731 if(dx
== 0 && dy
== 0)
734 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
741 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
744 /* Draws lines between the given points, and if caps is true then draws an endcap
745 * at the end of the last line. */
746 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
747 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
750 GpPointF
*ptcopy
= NULL
;
751 GpStatus status
= GenericError
;
756 pti
= GdipAlloc(count
* sizeof(POINT
));
757 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
760 status
= OutOfMemory
;
764 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
767 if(pen
->endcap
== LineCapArrowAnchor
)
768 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
769 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
770 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
771 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
772 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
773 pen
->customend
->inset
* pen
->width
);
775 if(pen
->startcap
== LineCapArrowAnchor
)
776 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
777 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
778 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
779 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
780 &ptcopy
[0].X
, &ptcopy
[0].Y
,
781 pen
->customstart
->inset
* pen
->width
);
783 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
784 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
785 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
786 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
789 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
791 if(Polyline(graphics
->hdc
, pti
, count
))
801 /* Conducts a linear search to find the bezier points that will back off
802 * the endpoint of the curve by a distance of amt. Linear search works
803 * better than binary in this case because there are multiple solutions,
804 * and binary searches often find a bad one. I don't think this is what
805 * Windows does but short of rendering the bezier without GDI's help it's
806 * the best we can do. If rev then work from the start of the passed points
807 * instead of the end. */
808 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
811 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
812 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
821 origx
= pt
[fourth
].X
;
822 origy
= pt
[fourth
].Y
;
823 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
825 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
826 /* reset bezier points to original values */
827 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
828 /* Perform magic on bezier points. Order is important here.*/
829 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
830 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
831 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
832 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
833 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
834 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
836 dx
= pt
[fourth
].X
- origx
;
837 dy
= pt
[fourth
].Y
- origy
;
839 diff
= sqrt(dx
* dx
+ dy
* dy
);
840 percent
+= 0.0005 * amt
;
844 /* Draws bezier curves between given points, and if caps is true then draws an
845 * endcap at the end of the last line. */
846 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
847 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
851 GpStatus status
= GenericError
;
856 pti
= GdipAlloc(count
* sizeof(POINT
));
857 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
860 status
= OutOfMemory
;
864 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
867 if(pen
->endcap
== LineCapArrowAnchor
)
868 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
869 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
870 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
873 if(pen
->startcap
== LineCapArrowAnchor
)
874 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
875 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
876 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
878 /* the direction of the line cap is parallel to the direction at the
879 * end of the bezier (which, if it has been shortened, is not the same
880 * as the direction from pt[count-2] to pt[count-1]) */
881 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
882 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
883 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
884 pt
[count
- 1].X
, pt
[count
- 1].Y
);
886 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
887 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
888 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
891 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
893 PolyBezier(graphics
->hdc
, pti
, count
);
904 /* Draws a combination of bezier curves and lines between points. */
905 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
906 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
908 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
909 BYTE
*tp
= GdipAlloc(count
);
910 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
912 GpStatus status
= GenericError
;
918 if(!pti
|| !tp
|| !ptcopy
){
919 status
= OutOfMemory
;
923 for(i
= 1; i
< count
; i
++){
924 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
925 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
926 || !(types
[i
+ 1] & PathPointTypeBezier
)){
927 ERR("Bad bezier points\n");
934 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
936 /* If we are drawing caps, go through the points and adjust them accordingly,
937 * and draw the caps. */
939 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
940 case PathPointTypeBezier
:
941 if(pen
->endcap
== LineCapArrowAnchor
)
942 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
943 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
944 shorten_bezier_amt(&ptcopy
[count
- 4],
945 pen
->width
* pen
->customend
->inset
, FALSE
);
947 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
948 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
949 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
950 pt
[count
- 1].X
, pt
[count
- 1].Y
);
953 case PathPointTypeLine
:
954 if(pen
->endcap
== LineCapArrowAnchor
)
955 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
956 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
958 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
959 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
960 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
961 pen
->customend
->inset
* pen
->width
);
963 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
964 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
969 ERR("Bad path last point\n");
973 /* Find start of points */
974 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
975 == PathPointTypeStart
); j
++);
977 switch(types
[j
] & PathPointTypePathTypeMask
){
978 case PathPointTypeBezier
:
979 if(pen
->startcap
== LineCapArrowAnchor
)
980 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
981 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
982 shorten_bezier_amt(&ptcopy
[j
- 1],
983 pen
->width
* pen
->customstart
->inset
, TRUE
);
985 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
986 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
987 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
988 pt
[j
- 1].X
, pt
[j
- 1].Y
);
991 case PathPointTypeLine
:
992 if(pen
->startcap
== LineCapArrowAnchor
)
993 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
994 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
996 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
997 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
998 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
999 pen
->customstart
->inset
* pen
->width
);
1001 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
1002 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
1007 ERR("Bad path points\n");
1012 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
1014 for(i
= 0; i
< count
; i
++){
1015 tp
[i
] = convert_path_point_type(types
[i
]);
1018 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
1030 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
1034 BeginPath(graphics
->hdc
);
1035 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
1036 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
1037 EndPath(graphics
->hdc
);
1041 typedef struct _GraphicsContainerItem
{
1043 GraphicsContainer contid
;
1045 SmoothingMode smoothing
;
1046 CompositingQuality compqual
;
1047 InterpolationMode interpolation
;
1048 CompositingMode compmode
;
1049 TextRenderingHint texthint
;
1052 PixelOffsetMode pixeloffset
;
1054 GpMatrix
* worldtrans
;
1056 } GraphicsContainerItem
;
1058 static GpStatus
init_container(GraphicsContainerItem
** container
,
1059 GDIPCONST GpGraphics
* graphics
){
1062 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
1066 (*container
)->contid
= graphics
->contid
+ 1;
1068 (*container
)->smoothing
= graphics
->smoothing
;
1069 (*container
)->compqual
= graphics
->compqual
;
1070 (*container
)->interpolation
= graphics
->interpolation
;
1071 (*container
)->compmode
= graphics
->compmode
;
1072 (*container
)->texthint
= graphics
->texthint
;
1073 (*container
)->scale
= graphics
->scale
;
1074 (*container
)->unit
= graphics
->unit
;
1075 (*container
)->textcontrast
= graphics
->textcontrast
;
1076 (*container
)->pixeloffset
= graphics
->pixeloffset
;
1078 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
1080 GdipFree(*container
);
1085 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
1087 GdipDeleteMatrix((*container
)->worldtrans
);
1088 GdipFree(*container
);
1096 static void delete_container(GraphicsContainerItem
* container
){
1097 GdipDeleteMatrix(container
->worldtrans
);
1098 GdipDeleteRegion(container
->clip
);
1099 GdipFree(container
);
1102 static GpStatus
restore_container(GpGraphics
* graphics
,
1103 GDIPCONST GraphicsContainerItem
* container
){
1108 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
1112 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1114 GdipDeleteMatrix(newTrans
);
1118 GdipDeleteMatrix(graphics
->worldtrans
);
1119 graphics
->worldtrans
= newTrans
;
1121 GdipDeleteRegion(graphics
->clip
);
1122 graphics
->clip
= newClip
;
1124 graphics
->contid
= container
->contid
- 1;
1126 graphics
->smoothing
= container
->smoothing
;
1127 graphics
->compqual
= container
->compqual
;
1128 graphics
->interpolation
= container
->interpolation
;
1129 graphics
->compmode
= container
->compmode
;
1130 graphics
->texthint
= container
->texthint
;
1131 graphics
->scale
= container
->scale
;
1132 graphics
->unit
= container
->unit
;
1133 graphics
->textcontrast
= container
->textcontrast
;
1134 graphics
->pixeloffset
= container
->pixeloffset
;
1139 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1145 if(graphics
->hwnd
) {
1146 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1147 return GenericError
;
1149 rect
->X
= wnd_rect
.left
;
1150 rect
->Y
= wnd_rect
.top
;
1151 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1152 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1153 }else if (graphics
->image
){
1154 stat
= GdipGetImageBounds(graphics
->image
, rect
, &unit
);
1155 if (stat
== Ok
&& unit
!= UnitPixel
)
1156 FIXME("need to convert from unit %i\n", unit
);
1160 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
1161 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
1167 /* on success, rgn will contain the region of the graphics object which
1168 * is visible after clipping has been applied */
1169 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
1175 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
1178 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
1181 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
1184 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
1187 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
1190 GdipDeleteRegion(tmp
);
1194 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
1196 TRACE("(%p, %p)\n", hdc
, graphics
);
1198 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
1201 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
1205 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
1207 if(hDevice
!= NULL
) {
1208 FIXME("Don't know how to handle parameter hDevice\n");
1209 return NotImplemented
;
1215 if(graphics
== NULL
)
1216 return InvalidParameter
;
1218 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1219 if(!*graphics
) return OutOfMemory
;
1221 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1222 GdipFree(*graphics
);
1226 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1227 GdipFree((*graphics
)->worldtrans
);
1228 GdipFree(*graphics
);
1232 (*graphics
)->hdc
= hdc
;
1233 (*graphics
)->hwnd
= WindowFromDC(hdc
);
1234 (*graphics
)->owndc
= FALSE
;
1235 (*graphics
)->smoothing
= SmoothingModeDefault
;
1236 (*graphics
)->compqual
= CompositingQualityDefault
;
1237 (*graphics
)->interpolation
= InterpolationModeDefault
;
1238 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1239 (*graphics
)->compmode
= CompositingModeSourceOver
;
1240 (*graphics
)->unit
= UnitDisplay
;
1241 (*graphics
)->scale
= 1.0;
1242 (*graphics
)->busy
= FALSE
;
1243 (*graphics
)->textcontrast
= 4;
1244 list_init(&(*graphics
)->containers
);
1245 (*graphics
)->contid
= 0;
1247 TRACE("<-- %p\n", *graphics
);
1252 GpStatus
graphics_from_image(GpImage
*image
, GpGraphics
**graphics
)
1256 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1257 if(!*graphics
) return OutOfMemory
;
1259 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1260 GdipFree(*graphics
);
1264 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1265 GdipFree((*graphics
)->worldtrans
);
1266 GdipFree(*graphics
);
1270 (*graphics
)->hdc
= NULL
;
1271 (*graphics
)->hwnd
= NULL
;
1272 (*graphics
)->owndc
= FALSE
;
1273 (*graphics
)->image
= image
;
1274 (*graphics
)->smoothing
= SmoothingModeDefault
;
1275 (*graphics
)->compqual
= CompositingQualityDefault
;
1276 (*graphics
)->interpolation
= InterpolationModeDefault
;
1277 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1278 (*graphics
)->compmode
= CompositingModeSourceOver
;
1279 (*graphics
)->unit
= UnitDisplay
;
1280 (*graphics
)->scale
= 1.0;
1281 (*graphics
)->busy
= FALSE
;
1282 (*graphics
)->textcontrast
= 4;
1283 list_init(&(*graphics
)->containers
);
1284 (*graphics
)->contid
= 0;
1286 TRACE("<-- %p\n", *graphics
);
1291 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
1296 TRACE("(%p, %p)\n", hwnd
, graphics
);
1300 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
1302 ReleaseDC(hwnd
, hdc
);
1306 (*graphics
)->hwnd
= hwnd
;
1307 (*graphics
)->owndc
= TRUE
;
1312 /* FIXME: no icm handling */
1313 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
1315 TRACE("(%p, %p)\n", hwnd
, graphics
);
1317 return GdipCreateFromHWND(hwnd
, graphics
);
1320 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
1321 GpMetafile
**metafile
)
1325 TRACE("(%p,%i,%p)\n", hemf
, delete, metafile
);
1327 if(!hemf
|| !metafile
)
1328 return InvalidParameter
;
1331 FIXME("not implemented\n");
1333 return NotImplemented
;
1336 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
1337 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1339 IStream
*stream
= NULL
;
1343 GpStatus retval
= Ok
;
1345 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
1347 if(!hwmf
|| !metafile
|| !placeable
)
1348 return InvalidParameter
;
1351 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
1353 return GenericError
;
1354 copy
= GdipAlloc(read
);
1355 GetMetaFileBitsEx(hwmf
, read
, copy
);
1357 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1360 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
1361 copy
= GdipAlloc(read
);
1362 GetEnhMetaFileBits(hemf
, read
, copy
);
1363 DeleteEnhMetaFile(hemf
);
1365 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
1366 ERR("could not make stream\n");
1368 retval
= GenericError
;
1372 *metafile
= GdipAlloc(sizeof(GpMetafile
));
1374 retval
= OutOfMemory
;
1378 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1379 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
1381 retval
= GenericError
;
1386 (*metafile
)->image
.type
= ImageTypeMetafile
;
1387 memcpy(&(*metafile
)->image
.format
, &ImageFormatWMF
, sizeof(GUID
));
1388 (*metafile
)->image
.palette_flags
= 0;
1389 (*metafile
)->image
.palette_count
= 0;
1390 (*metafile
)->image
.palette_size
= 0;
1391 (*metafile
)->image
.palette_entries
= NULL
;
1392 (*metafile
)->image
.xres
= (REAL
)placeable
->Inch
;
1393 (*metafile
)->image
.yres
= (REAL
)placeable
->Inch
;
1394 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
1395 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Top
) / ((REAL
) placeable
->Inch
);
1396 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
1397 - placeable
->BoundingBox
.Left
));
1398 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
1399 - placeable
->BoundingBox
.Top
));
1400 (*metafile
)->unit
= UnitPixel
;
1403 DeleteMetaFile(hwmf
);
1405 TRACE("<-- %p\n", *metafile
);
1409 GdipFree(*metafile
);
1410 IStream_Release(stream
);
1414 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1415 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1417 HMETAFILE hmf
= GetMetaFileW(file
);
1419 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1421 if(!hmf
) return InvalidParameter
;
1423 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1426 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
1427 GpMetafile
**metafile
)
1429 FIXME("(%p, %p): stub\n", file
, metafile
);
1430 return NotImplemented
;
1433 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
1434 GpMetafile
**metafile
)
1436 FIXME("(%p, %p): stub\n", stream
, metafile
);
1437 return NotImplemented
;
1440 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
1441 UINT access
, IStream
**stream
)
1446 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
1448 if(!stream
|| !filename
)
1449 return InvalidParameter
;
1451 if(access
& GENERIC_WRITE
)
1452 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
1453 else if(access
& GENERIC_READ
)
1454 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
1456 return InvalidParameter
;
1458 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
1460 return hresult_to_status(ret
);
1463 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
1465 GraphicsContainerItem
*cont
, *next
;
1466 TRACE("(%p)\n", graphics
);
1468 if(!graphics
) return InvalidParameter
;
1469 if(graphics
->busy
) return ObjectBusy
;
1472 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
1474 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
1475 list_remove(&cont
->entry
);
1476 delete_container(cont
);
1479 GdipDeleteRegion(graphics
->clip
);
1480 GdipDeleteMatrix(graphics
->worldtrans
);
1486 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1487 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1489 INT save_state
, num_pts
;
1490 GpPointF points
[MAX_ARC_PTS
];
1493 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1494 width
, height
, startAngle
, sweepAngle
);
1496 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
1497 return InvalidParameter
;
1504 FIXME("graphics object has no HDC\n");
1508 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1510 save_state
= prepare_dc(graphics
, pen
);
1512 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
1514 restore_dc(graphics
, save_state
);
1519 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1520 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1522 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1523 width
, height
, startAngle
, sweepAngle
);
1525 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1528 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1529 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
1535 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
1536 x2
, y2
, x3
, y3
, x4
, y4
);
1538 if(!graphics
|| !pen
)
1539 return InvalidParameter
;
1546 FIXME("graphics object has no HDC\n");
1559 save_state
= prepare_dc(graphics
, pen
);
1561 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1563 restore_dc(graphics
, save_state
);
1568 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1569 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
1575 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
1576 x2
, y2
, x3
, y3
, x4
, y4
);
1578 if(!graphics
|| !pen
)
1579 return InvalidParameter
;
1586 FIXME("graphics object has no HDC\n");
1599 save_state
= prepare_dc(graphics
, pen
);
1601 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1603 restore_dc(graphics
, save_state
);
1608 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
1609 GDIPCONST GpPointF
*points
, INT count
)
1614 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1616 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1617 return InvalidParameter
;
1622 for(i
= 0; i
< floor(count
/ 4); i
++){
1623 ret
= GdipDrawBezier(graphics
, pen
,
1624 points
[4*i
].X
, points
[4*i
].Y
,
1625 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
1626 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
1627 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
1635 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
1636 GDIPCONST GpPoint
*points
, INT count
)
1642 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1644 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1645 return InvalidParameter
;
1650 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
1654 for(i
= 0; i
< count
; i
++){
1655 pts
[i
].X
= (REAL
)points
[i
].X
;
1656 pts
[i
].Y
= (REAL
)points
[i
].Y
;
1659 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
1666 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
1667 GDIPCONST GpPointF
*points
, INT count
)
1669 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1671 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
1674 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1675 GDIPCONST GpPoint
*points
, INT count
)
1677 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1679 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
1682 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1683 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1688 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1690 if(!graphics
|| !pen
|| !points
|| count
<= 0)
1691 return InvalidParameter
;
1696 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
1699 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1701 GdipDeletePath(path
);
1705 stat
= GdipDrawPath(graphics
, pen
, path
);
1707 GdipDeletePath(path
);
1712 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1713 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1719 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1721 if(!points
|| count
<= 0)
1722 return InvalidParameter
;
1724 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1728 for(i
= 0; i
< count
; i
++){
1729 ptf
[i
].X
= (REAL
)points
[i
].X
;
1730 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1733 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
1740 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
1741 GDIPCONST GpPointF
*points
, INT count
)
1743 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1745 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
1748 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1749 GDIPCONST GpPoint
*points
, INT count
)
1755 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1758 return InvalidParameter
;
1760 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1764 for(i
= 0; i
< count
; i
++){
1765 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1766 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1769 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
1775 /* Approximates cardinal spline with Bezier curves. */
1776 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1777 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1779 /* PolyBezier expects count*3-2 points. */
1780 INT i
, len_pt
= count
*3-2, save_state
;
1782 REAL x1
, x2
, y1
, y2
;
1785 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1787 if(!graphics
|| !pen
)
1788 return InvalidParameter
;
1794 return InvalidParameter
;
1798 FIXME("graphics object has no HDC\n");
1802 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
1806 tension
= tension
* TENSION_CONST
;
1808 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
1811 pt
[0].X
= points
[0].X
;
1812 pt
[0].Y
= points
[0].Y
;
1816 for(i
= 0; i
< count
-2; i
++){
1817 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
1821 pt
[3*i
+3].X
= points
[i
+1].X
;
1822 pt
[3*i
+3].Y
= points
[i
+1].Y
;
1827 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
1828 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
1830 pt
[len_pt
-2].X
= x1
;
1831 pt
[len_pt
-2].Y
= y1
;
1832 pt
[len_pt
-1].X
= points
[count
-1].X
;
1833 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
1835 save_state
= prepare_dc(graphics
, pen
);
1837 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
1840 restore_dc(graphics
, save_state
);
1845 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1846 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1852 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1855 return InvalidParameter
;
1857 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1861 for(i
= 0; i
< count
; i
++){
1862 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1863 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1866 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
1872 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
1873 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
1876 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1878 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1879 return InvalidParameter
;
1882 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1885 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
1886 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
1889 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1895 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1896 return InvalidParameter
;
1899 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1902 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1903 REAL y
, REAL width
, REAL height
)
1909 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1911 if(!graphics
|| !pen
)
1912 return InvalidParameter
;
1919 FIXME("graphics object has no HDC\n");
1925 ptf
[1].X
= x
+ width
;
1926 ptf
[1].Y
= y
+ height
;
1928 save_state
= prepare_dc(graphics
, pen
);
1929 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1931 transform_and_round_points(graphics
, pti
, ptf
, 2);
1933 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1935 restore_dc(graphics
, save_state
);
1940 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1941 INT y
, INT width
, INT height
)
1943 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1945 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1949 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
1954 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
1956 if(!graphics
|| !image
)
1957 return InvalidParameter
;
1959 GdipGetImageWidth(image
, &width
);
1960 GdipGetImageHeight(image
, &height
);
1962 /* FIXME: we should use the graphics and image dpi, somehow */
1964 points
[0].X
= points
[2].X
= x
;
1965 points
[0].Y
= points
[1].Y
= y
;
1966 points
[1].X
= x
+ width
;
1967 points
[2].Y
= y
+ height
;
1969 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, 0, 0, width
, height
,
1970 UnitPixel
, NULL
, NULL
, NULL
);
1973 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
1976 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
1978 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
1981 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
1982 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
1986 TRACE("(%p, %p, %f, %f, %f, %f, %f, %f, %d)\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
1988 points
[0].X
= points
[2].X
= x
;
1989 points
[0].Y
= points
[1].Y
= y
;
1991 /* FIXME: convert image coordinates to Graphics coordinates? */
1992 points
[1].X
= x
+ srcwidth
;
1993 points
[2].Y
= y
+ srcheight
;
1995 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1996 srcwidth
, srcheight
, srcUnit
, NULL
, NULL
, NULL
);
1999 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
2000 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
2003 return GdipDrawImagePointRect(graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
2006 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
2007 GDIPCONST GpPointF
*dstpoints
, INT count
)
2009 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
2010 return NotImplemented
;
2013 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
2014 GDIPCONST GpPoint
*dstpoints
, INT count
)
2016 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
2017 return NotImplemented
;
2020 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
2021 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
2022 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2023 DrawImageAbort callback
, VOID
* callbackData
)
2030 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
2031 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2034 if(!graphics
|| !image
|| !points
|| count
!= 3)
2035 return InvalidParameter
;
2037 TRACE("%s %s %s\n", debugstr_pointf(&points
[0]), debugstr_pointf(&points
[1]),
2038 debugstr_pointf(&points
[2]));
2040 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
2041 ptf
[3].X
= ptf
[2].X
+ ptf
[1].X
- ptf
[0].X
;
2042 ptf
[3].Y
= ptf
[2].Y
+ ptf
[1].Y
- ptf
[0].Y
;
2043 transform_and_round_points(graphics
, pti
, ptf
, 4);
2049 FIXME("graphics object has no HDC\n");
2052 /* FIXME: partially implemented (only works for rectangular parallelograms) */
2053 if(srcUnit
== UnitInch
)
2054 dx
= dy
= (REAL
) INCH_HIMETRIC
;
2055 else if(srcUnit
== UnitPixel
){
2056 dx
= ((REAL
) INCH_HIMETRIC
) /
2057 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
2058 dy
= ((REAL
) INCH_HIMETRIC
) /
2059 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
2062 return NotImplemented
;
2064 if(IPicture_Render(image
->picture
, graphics
->hdc
,
2065 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
2066 srcx
* dx
, srcy
* dy
,
2067 srcwidth
* dx
, srcheight
* dy
,
2070 callback(callbackData
);
2071 return GenericError
;
2074 else if (image
->type
== ImageTypeBitmap
)
2076 GpBitmap
* bitmap
= (GpBitmap
*)image
;
2079 if (srcUnit
== UnitInch
)
2080 dx
= dy
= 96.0; /* FIXME: use the image resolution */
2081 else if (srcUnit
== UnitPixel
)
2084 return NotImplemented
;
2086 if (imageAttributes
||
2087 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
) ||
2088 !((GpBitmap
*)image
)->hbitmap
||
2089 ptf
[1].Y
!= ptf
[0].Y
|| ptf
[2].X
!= ptf
[0].X
)
2094 RECT src_area
, dst_area
;
2095 int i
, x
, y
, stride
;
2096 GpMatrix
*dst_to_src
;
2097 REAL m11
, m12
, m21
, m22
, mdx
, mdy
;
2100 src_area
.left
= srcx
*dx
;
2101 src_area
.top
= srcy
*dy
;
2102 src_area
.right
= (srcx
+srcwidth
)*dx
;
2103 src_area
.bottom
= (srcy
+srcheight
)*dy
;
2105 dst_area
.left
= dst_area
.right
= pti
[0].x
;
2106 dst_area
.top
= dst_area
.bottom
= pti
[0].y
;
2109 if (dst_area
.left
> pti
[i
].x
) dst_area
.left
= pti
[i
].x
;
2110 if (dst_area
.right
< pti
[i
].x
) dst_area
.right
= pti
[i
].x
;
2111 if (dst_area
.top
> pti
[i
].y
) dst_area
.top
= pti
[i
].y
;
2112 if (dst_area
.bottom
< pti
[i
].y
) dst_area
.bottom
= pti
[i
].y
;
2115 m11
= (ptf
[1].X
- ptf
[0].X
) / srcwidth
;
2116 m21
= (ptf
[2].X
- ptf
[0].X
) / srcheight
;
2117 mdx
= ptf
[0].X
- m11
* srcx
- m21
* srcy
;
2118 m12
= (ptf
[1].Y
- ptf
[0].Y
) / srcwidth
;
2119 m22
= (ptf
[2].Y
- ptf
[0].Y
) / srcheight
;
2120 mdy
= ptf
[0].Y
- m12
* srcx
- m22
* srcy
;
2122 stat
= GdipCreateMatrix2(m11
, m12
, m21
, m22
, mdx
, mdy
, &dst_to_src
);
2123 if (stat
!= Ok
) return stat
;
2125 stat
= GdipInvertMatrix(dst_to_src
);
2128 GdipDeleteMatrix(dst_to_src
);
2132 data
= GdipAlloc(sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
) * (dst_area
.bottom
- dst_area
.top
));
2135 GdipDeleteMatrix(dst_to_src
);
2139 stride
= sizeof(ARGB
) * (dst_area
.right
- dst_area
.left
);
2141 if (imageAttributes
&&
2142 (imageAttributes
->wrap
!= WrapModeClamp
||
2143 imageAttributes
->outside_color
!= 0x00000000 ||
2144 imageAttributes
->clamp
))
2148 FIXME("Image wrap mode not implemented\n");
2151 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2153 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2155 GpPointF src_pointf
;
2162 GdipTransformMatrixPoints(dst_to_src
, &src_pointf
, 1);
2164 src_x
= roundr(src_pointf
.X
);
2165 src_y
= roundr(src_pointf
.Y
);
2167 src_color
= (ARGB
*)(data
+ stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2169 if (src_x
< src_area
.left
|| src_x
>= src_area
.right
||
2170 src_y
< src_area
.top
|| src_y
>= src_area
.bottom
)
2173 GdipBitmapGetPixel(bitmap
, src_x
, src_y
, src_color
);
2177 GdipDeleteMatrix(dst_to_src
);
2179 if (imageAttributes
)
2181 if (imageAttributes
->colorkeys
[ColorAdjustTypeBitmap
].enabled
||
2182 imageAttributes
->colorkeys
[ColorAdjustTypeDefault
].enabled
)
2184 const struct color_key
*key
;
2185 BYTE min_blue
, min_green
, min_red
;
2186 BYTE max_blue
, max_green
, max_red
;
2188 if (imageAttributes
->colorkeys
[ColorAdjustTypeBitmap
].enabled
)
2189 key
= &imageAttributes
->colorkeys
[ColorAdjustTypeBitmap
];
2191 key
= &imageAttributes
->colorkeys
[ColorAdjustTypeDefault
];
2193 min_blue
= key
->low
&0xff;
2194 min_green
= (key
->low
>>8)&0xff;
2195 min_red
= (key
->low
>>16)&0xff;
2197 max_blue
= key
->high
&0xff;
2198 max_green
= (key
->high
>>8)&0xff;
2199 max_red
= (key
->high
>>16)&0xff;
2201 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2202 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2205 BYTE blue
, green
, red
;
2206 src_color
= (ARGB
*)(data
+ stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2207 blue
= *src_color
&0xff;
2208 green
= (*src_color
>>8)&0xff;
2209 red
= (*src_color
>>16)&0xff;
2210 if (blue
>= min_blue
&& green
>= min_green
&& red
>= min_red
&&
2211 blue
<= max_blue
&& green
<= max_green
&& red
<= max_red
)
2212 *src_color
= 0x00000000;
2216 if (imageAttributes
->colorremaptables
[ColorAdjustTypeBitmap
].enabled
||
2217 imageAttributes
->colorremaptables
[ColorAdjustTypeDefault
].enabled
)
2219 const struct color_remap_table
*table
;
2221 if (imageAttributes
->colorremaptables
[ColorAdjustTypeBitmap
].enabled
)
2222 table
= &imageAttributes
->colorremaptables
[ColorAdjustTypeBitmap
];
2224 table
= &imageAttributes
->colorremaptables
[ColorAdjustTypeDefault
];
2226 for (x
=dst_area
.left
; x
<dst_area
.right
; x
++)
2227 for (y
=dst_area
.top
; y
<dst_area
.bottom
; y
++)
2230 src_color
= (ARGB
*)(data
+ stride
* (y
- dst_area
.top
) + sizeof(ARGB
) * (x
- dst_area
.left
));
2231 for (i
=0; i
<table
->mapsize
; i
++)
2233 if (*src_color
== table
->colormap
[i
].oldColor
.Argb
)
2235 *src_color
= table
->colormap
[i
].newColor
.Argb
;
2242 if (imageAttributes
->colormatrices
[ColorAdjustTypeBitmap
].enabled
||
2243 imageAttributes
->colormatrices
[ColorAdjustTypeDefault
].enabled
)
2247 FIXME("Color transforms not implemented\n");
2250 if (imageAttributes
->gamma_enabled
[ColorAdjustTypeBitmap
] ||
2251 imageAttributes
->gamma_enabled
[ColorAdjustTypeDefault
])
2255 FIXME("Gamma adjustment not implemented\n");
2259 stat
= alpha_blend_pixels(graphics
, dst_area
.left
, dst_area
.top
,
2260 data
, dst_area
.right
- dst_area
.left
, dst_area
.bottom
- dst_area
.top
, stride
);
2269 int temp_hdc
=0, temp_bitmap
=0;
2270 HBITMAP hbitmap
, old_hbm
=NULL
;
2272 if (!(bitmap
->format
== PixelFormat16bppRGB555
||
2273 bitmap
->format
== PixelFormat24bppRGB
||
2274 bitmap
->format
== PixelFormat32bppRGB
||
2275 bitmap
->format
== PixelFormat32bppPARGB
))
2277 BITMAPINFOHEADER bih
;
2279 PixelFormat dst_format
;
2281 /* we can't draw a bitmap of this format directly */
2282 hdc
= CreateCompatibleDC(0);
2286 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
2287 bih
.biWidth
= bitmap
->width
;
2288 bih
.biHeight
= -bitmap
->height
;
2290 bih
.biBitCount
= 32;
2291 bih
.biCompression
= BI_RGB
;
2292 bih
.biSizeImage
= 0;
2293 bih
.biXPelsPerMeter
= 0;
2294 bih
.biYPelsPerMeter
= 0;
2296 bih
.biClrImportant
= 0;
2298 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
2299 (void**)&temp_bits
, NULL
, 0);
2301 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2302 dst_format
= PixelFormat32bppPARGB
;
2304 dst_format
= PixelFormat32bppRGB
;
2306 convert_pixels(bitmap
->width
, bitmap
->height
,
2307 bitmap
->width
*4, temp_bits
, dst_format
,
2308 bitmap
->stride
, bitmap
->bits
, bitmap
->format
, bitmap
->image
.palette_entries
);
2312 hbitmap
= bitmap
->hbitmap
;
2314 temp_hdc
= (hdc
== 0);
2319 if (!hdc
) hdc
= CreateCompatibleDC(0);
2320 old_hbm
= SelectObject(hdc
, hbitmap
);
2323 if (bitmap
->format
& (PixelFormatAlpha
|PixelFormatPAlpha
))
2327 bf
.BlendOp
= AC_SRC_OVER
;
2329 bf
.SourceConstantAlpha
= 255;
2330 bf
.AlphaFormat
= AC_SRC_ALPHA
;
2332 GdiAlphaBlend(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
2333 hdc
, srcx
*dx
, srcy
*dy
, srcwidth
*dx
, srcheight
*dy
, bf
);
2337 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
2338 hdc
, srcx
*dx
, srcy
*dy
, srcwidth
*dx
, srcheight
*dy
, SRCCOPY
);
2343 SelectObject(hdc
, old_hbm
);
2348 DeleteObject(hbitmap
);
2353 ERR("GpImage with no IPicture or HBITMAP?!\n");
2354 return NotImplemented
;
2360 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
2361 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
2362 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
2363 DrawImageAbort callback
, VOID
* callbackData
)
2365 GpPointF pointsF
[3];
2368 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
2369 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
2372 if(!points
|| count
!=3)
2373 return InvalidParameter
;
2375 for(i
= 0; i
< count
; i
++){
2376 pointsF
[i
].X
= (REAL
)points
[i
].X
;
2377 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
2380 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
2381 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
2382 callback
, callbackData
);
2385 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
2386 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
2387 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
2388 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
2389 VOID
* callbackData
)
2393 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
2394 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2395 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2399 points
[1].X
= dstx
+ dstwidth
;
2402 points
[2].Y
= dsty
+ dstheight
;
2404 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2405 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2408 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
2409 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
2410 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
2411 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
2412 VOID
* callbackData
)
2416 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
2417 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2418 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2422 points
[1].X
= dstx
+ dstwidth
;
2425 points
[2].Y
= dsty
+ dstheight
;
2427 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2428 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2431 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
2432 REAL x
, REAL y
, REAL width
, REAL height
)
2438 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
2440 if(!graphics
|| !image
)
2441 return InvalidParameter
;
2443 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
2447 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
2448 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
2449 unit
, NULL
, NULL
, NULL
);
2452 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
2453 INT x
, INT y
, INT width
, INT height
)
2455 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
2457 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
2460 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2461 REAL y1
, REAL x2
, REAL y2
)
2467 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2469 if(!pen
|| !graphics
)
2470 return InvalidParameter
;
2477 FIXME("graphics object has no HDC\n");
2486 save_state
= prepare_dc(graphics
, pen
);
2488 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2490 restore_dc(graphics
, save_state
);
2495 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2496 INT y1
, INT x2
, INT y2
)
2502 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2504 if(!pen
|| !graphics
)
2505 return InvalidParameter
;
2512 FIXME("graphics object has no HDC\n");
2521 save_state
= prepare_dc(graphics
, pen
);
2523 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2525 restore_dc(graphics
, save_state
);
2530 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2531 GpPointF
*points
, INT count
)
2536 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2538 if(!pen
|| !graphics
|| (count
< 2))
2539 return InvalidParameter
;
2546 FIXME("graphics object has no HDC\n");
2550 save_state
= prepare_dc(graphics
, pen
);
2552 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
2554 restore_dc(graphics
, save_state
);
2559 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2560 GpPoint
*points
, INT count
)
2564 GpPointF
*ptf
= NULL
;
2567 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2569 if(!pen
|| !graphics
|| (count
< 2))
2570 return InvalidParameter
;
2577 FIXME("graphics object has no HDC\n");
2581 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2582 if(!ptf
) return OutOfMemory
;
2584 for(i
= 0; i
< count
; i
++){
2585 ptf
[i
].X
= (REAL
) points
[i
].X
;
2586 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2589 save_state
= prepare_dc(graphics
, pen
);
2591 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
2593 restore_dc(graphics
, save_state
);
2599 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
2604 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
2606 if(!pen
|| !graphics
)
2607 return InvalidParameter
;
2614 FIXME("graphics object has no HDC\n");
2618 save_state
= prepare_dc(graphics
, pen
);
2620 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
2621 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
2623 restore_dc(graphics
, save_state
);
2628 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2629 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2633 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2634 width
, height
, startAngle
, sweepAngle
);
2636 if(!graphics
|| !pen
)
2637 return InvalidParameter
;
2644 FIXME("graphics object has no HDC\n");
2648 save_state
= prepare_dc(graphics
, pen
);
2649 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2651 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2653 restore_dc(graphics
, save_state
);
2658 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2659 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2661 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2662 width
, height
, startAngle
, sweepAngle
);
2664 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2667 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2668 REAL y
, REAL width
, REAL height
)
2674 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2676 if(!pen
|| !graphics
)
2677 return InvalidParameter
;
2684 FIXME("graphics object has no HDC\n");
2690 ptf
[1].X
= x
+ width
;
2692 ptf
[2].X
= x
+ width
;
2693 ptf
[2].Y
= y
+ height
;
2695 ptf
[3].Y
= y
+ height
;
2697 save_state
= prepare_dc(graphics
, pen
);
2698 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2700 transform_and_round_points(graphics
, pti
, ptf
, 4);
2701 Polygon(graphics
->hdc
, pti
, 4);
2703 restore_dc(graphics
, save_state
);
2708 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2709 INT y
, INT width
, INT height
)
2711 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2713 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2716 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
2717 GDIPCONST GpRectF
* rects
, INT count
)
2723 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2725 if(!graphics
|| !pen
|| !rects
|| count
< 1)
2726 return InvalidParameter
;
2733 FIXME("graphics object has no HDC\n");
2737 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
2738 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
2746 for(i
= 0; i
< count
; i
++){
2747 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
2748 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
2749 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
2750 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
2753 save_state
= prepare_dc(graphics
, pen
);
2754 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2756 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
2758 for(i
= 0; i
< count
; i
++)
2759 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
2761 restore_dc(graphics
, save_state
);
2769 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
2770 GDIPCONST GpRect
* rects
, INT count
)
2776 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2778 if(!rects
|| count
<=0)
2779 return InvalidParameter
;
2781 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
2785 for(i
= 0;i
< count
;i
++){
2786 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2787 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2788 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
2789 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2792 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
2798 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
2799 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
2804 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2805 count
, tension
, fill
);
2807 if(!graphics
|| !brush
|| !points
)
2808 return InvalidParameter
;
2813 if(count
== 1) /* Do nothing */
2816 stat
= GdipCreatePath(fill
, &path
);
2820 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2822 GdipDeletePath(path
);
2826 stat
= GdipFillPath(graphics
, brush
, path
);
2828 GdipDeletePath(path
);
2832 GdipDeletePath(path
);
2837 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
2838 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
2844 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2845 count
, tension
, fill
);
2847 if(!points
|| count
== 0)
2848 return InvalidParameter
;
2850 if(count
== 1) /* Do nothing */
2853 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2857 for(i
= 0;i
< count
;i
++){
2858 ptf
[i
].X
= (REAL
)points
[i
].X
;
2859 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2862 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
2869 GpStatus WINGDIPAPI
GdipFillClosedCurve(GpGraphics
*graphics
, GpBrush
*brush
,
2870 GDIPCONST GpPointF
*points
, INT count
)
2872 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2873 return GdipFillClosedCurve2(graphics
, brush
, points
, count
,
2874 0.5f
, FillModeAlternate
);
2877 GpStatus WINGDIPAPI
GdipFillClosedCurveI(GpGraphics
*graphics
, GpBrush
*brush
,
2878 GDIPCONST GpPoint
*points
, INT count
)
2880 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2881 return GdipFillClosedCurve2I(graphics
, brush
, points
, count
,
2882 0.5f
, FillModeAlternate
);
2885 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2886 REAL y
, REAL width
, REAL height
)
2892 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2894 if(!graphics
|| !brush
)
2895 return InvalidParameter
;
2902 FIXME("graphics object has no HDC\n");
2908 ptf
[1].X
= x
+ width
;
2909 ptf
[1].Y
= y
+ height
;
2911 save_state
= SaveDC(graphics
->hdc
);
2912 EndPath(graphics
->hdc
);
2914 transform_and_round_points(graphics
, pti
, ptf
, 2);
2916 BeginPath(graphics
->hdc
);
2917 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2918 EndPath(graphics
->hdc
);
2920 brush_fill_path(graphics
, brush
);
2922 RestoreDC(graphics
->hdc
, save_state
);
2927 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2928 INT y
, INT width
, INT height
)
2930 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2932 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2935 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
2940 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
2942 if(!brush
|| !graphics
|| !path
)
2943 return InvalidParameter
;
2950 FIXME("graphics object has no HDC\n");
2954 save_state
= SaveDC(graphics
->hdc
);
2955 EndPath(graphics
->hdc
);
2956 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
2959 BeginPath(graphics
->hdc
);
2960 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2961 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2966 EndPath(graphics
->hdc
);
2967 brush_fill_path(graphics
, brush
);
2972 RestoreDC(graphics
->hdc
, save_state
);
2977 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2978 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2982 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2983 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2985 if(!graphics
|| !brush
)
2986 return InvalidParameter
;
2993 FIXME("graphics object has no HDC\n");
2997 save_state
= SaveDC(graphics
->hdc
);
2998 EndPath(graphics
->hdc
);
3000 BeginPath(graphics
->hdc
);
3001 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3002 EndPath(graphics
->hdc
);
3004 brush_fill_path(graphics
, brush
);
3006 RestoreDC(graphics
->hdc
, save_state
);
3011 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
3012 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
3014 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
3015 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
3017 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
3020 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
3021 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
3024 GpPointF
*ptf
= NULL
;
3026 GpStatus retval
= Ok
;
3028 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3030 if(!graphics
|| !brush
|| !points
|| !count
)
3031 return InvalidParameter
;
3038 FIXME("graphics object has no HDC\n");
3042 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3043 pti
= GdipAlloc(count
* sizeof(POINT
));
3045 retval
= OutOfMemory
;
3049 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
3051 save_state
= SaveDC(graphics
->hdc
);
3052 EndPath(graphics
->hdc
);
3053 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
3056 transform_and_round_points(graphics
, pti
, ptf
, count
);
3058 BeginPath(graphics
->hdc
);
3059 Polygon(graphics
->hdc
, pti
, count
);
3060 EndPath(graphics
->hdc
);
3062 brush_fill_path(graphics
, brush
);
3064 RestoreDC(graphics
->hdc
, save_state
);
3073 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
3074 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
3077 GpPointF
*ptf
= NULL
;
3079 GpStatus retval
= Ok
;
3081 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
3083 if(!graphics
|| !brush
|| !points
|| !count
)
3084 return InvalidParameter
;
3091 FIXME("graphics object has no HDC\n");
3095 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
3096 pti
= GdipAlloc(count
* sizeof(POINT
));
3098 retval
= OutOfMemory
;
3102 for(i
= 0; i
< count
; i
++){
3103 ptf
[i
].X
= (REAL
) points
[i
].X
;
3104 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
3107 save_state
= SaveDC(graphics
->hdc
);
3108 EndPath(graphics
->hdc
);
3109 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
3112 transform_and_round_points(graphics
, pti
, ptf
, count
);
3114 BeginPath(graphics
->hdc
);
3115 Polygon(graphics
->hdc
, pti
, count
);
3116 EndPath(graphics
->hdc
);
3118 brush_fill_path(graphics
, brush
);
3120 RestoreDC(graphics
->hdc
, save_state
);
3129 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
3130 GDIPCONST GpPointF
*points
, INT count
)
3132 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3134 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
3137 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
3138 GDIPCONST GpPoint
*points
, INT count
)
3140 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
3142 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
3145 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
3146 REAL x
, REAL y
, REAL width
, REAL height
)
3152 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
3154 if(!graphics
|| !brush
)
3155 return InvalidParameter
;
3162 FIXME("graphics object has no HDC\n");
3168 ptf
[1].X
= x
+ width
;
3170 ptf
[2].X
= x
+ width
;
3171 ptf
[2].Y
= y
+ height
;
3173 ptf
[3].Y
= y
+ height
;
3175 save_state
= SaveDC(graphics
->hdc
);
3176 EndPath(graphics
->hdc
);
3178 transform_and_round_points(graphics
, pti
, ptf
, 4);
3180 BeginPath(graphics
->hdc
);
3181 Polygon(graphics
->hdc
, pti
, 4);
3182 EndPath(graphics
->hdc
);
3184 brush_fill_path(graphics
, brush
);
3186 RestoreDC(graphics
->hdc
, save_state
);
3191 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
3192 INT x
, INT y
, INT width
, INT height
)
3198 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
3200 if(!graphics
|| !brush
)
3201 return InvalidParameter
;
3208 FIXME("graphics object has no HDC\n");
3214 ptf
[1].X
= x
+ width
;
3216 ptf
[2].X
= x
+ width
;
3217 ptf
[2].Y
= y
+ height
;
3219 ptf
[3].Y
= y
+ height
;
3221 save_state
= SaveDC(graphics
->hdc
);
3222 EndPath(graphics
->hdc
);
3224 transform_and_round_points(graphics
, pti
, ptf
, 4);
3226 BeginPath(graphics
->hdc
);
3227 Polygon(graphics
->hdc
, pti
, 4);
3228 EndPath(graphics
->hdc
);
3230 brush_fill_path(graphics
, brush
);
3232 RestoreDC(graphics
->hdc
, save_state
);
3237 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
3243 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3246 return InvalidParameter
;
3248 for(i
= 0; i
< count
; i
++){
3249 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
3250 if(ret
!= Ok
) return ret
;
3256 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
3263 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
3265 if(!rects
|| count
<= 0)
3266 return InvalidParameter
;
3268 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
3272 for(i
= 0; i
< count
; i
++){
3273 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
3274 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
3275 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
3276 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
3279 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
3285 static GpStatus
GDI32_GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3294 return NotImplemented
;
3296 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3300 save_state
= SaveDC(graphics
->hdc
);
3301 EndPath(graphics
->hdc
);
3303 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3305 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3307 BeginPath(graphics
->hdc
);
3308 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3309 EndPath(graphics
->hdc
);
3311 brush_fill_path(graphics
, brush
);
3314 RestoreDC(graphics
->hdc
, save_state
);
3321 /*****************************************************************************
3322 * GdipFillRegion [GDIPLUS.@]
3324 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3329 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
3331 if (!(graphics
&& brush
&& region
))
3332 return InvalidParameter
;
3337 stat
= GDI32_GdipFillRegion(graphics
, brush
, region
);
3339 if (stat
== NotImplemented
)
3341 FIXME("partially implemented\n");
3348 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
3350 TRACE("(%p,%u)\n", graphics
, intention
);
3353 return InvalidParameter
;
3358 /* We have no internal operation queue, so there's no need to clear it. */
3366 /*****************************************************************************
3367 * GdipGetClipBounds [GDIPLUS.@]
3369 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
3371 TRACE("(%p, %p)\n", graphics
, rect
);
3374 return InvalidParameter
;
3379 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
3382 /*****************************************************************************
3383 * GdipGetClipBoundsI [GDIPLUS.@]
3385 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
3387 TRACE("(%p, %p)\n", graphics
, rect
);
3390 return InvalidParameter
;
3395 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
3398 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3399 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
3400 CompositingMode
*mode
)
3402 TRACE("(%p, %p)\n", graphics
, mode
);
3404 if(!graphics
|| !mode
)
3405 return InvalidParameter
;
3410 *mode
= graphics
->compmode
;
3415 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3416 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
3417 CompositingQuality
*quality
)
3419 TRACE("(%p, %p)\n", graphics
, quality
);
3421 if(!graphics
|| !quality
)
3422 return InvalidParameter
;
3427 *quality
= graphics
->compqual
;
3432 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3433 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
3434 InterpolationMode
*mode
)
3436 TRACE("(%p, %p)\n", graphics
, mode
);
3438 if(!graphics
|| !mode
)
3439 return InvalidParameter
;
3444 *mode
= graphics
->interpolation
;
3449 /* FIXME: Need to handle color depths less than 24bpp */
3450 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
3452 FIXME("(%p, %p): Passing color unmodified\n", graphics
, argb
);
3454 if(!graphics
|| !argb
)
3455 return InvalidParameter
;
3463 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
3465 TRACE("(%p, %p)\n", graphics
, scale
);
3467 if(!graphics
|| !scale
)
3468 return InvalidParameter
;
3473 *scale
= graphics
->scale
;
3478 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
3480 TRACE("(%p, %p)\n", graphics
, unit
);
3482 if(!graphics
|| !unit
)
3483 return InvalidParameter
;
3488 *unit
= graphics
->unit
;
3493 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3494 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3497 TRACE("(%p, %p)\n", graphics
, mode
);
3499 if(!graphics
|| !mode
)
3500 return InvalidParameter
;
3505 *mode
= graphics
->pixeloffset
;
3510 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3511 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
3513 TRACE("(%p, %p)\n", graphics
, mode
);
3515 if(!graphics
|| !mode
)
3516 return InvalidParameter
;
3521 *mode
= graphics
->smoothing
;
3526 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
3528 TRACE("(%p, %p)\n", graphics
, contrast
);
3530 if(!graphics
|| !contrast
)
3531 return InvalidParameter
;
3533 *contrast
= graphics
->textcontrast
;
3538 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3539 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
3540 TextRenderingHint
*hint
)
3542 TRACE("(%p, %p)\n", graphics
, hint
);
3544 if(!graphics
|| !hint
)
3545 return InvalidParameter
;
3550 *hint
= graphics
->texthint
;
3555 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
3560 TRACE("(%p, %p)\n", graphics
, rect
);
3562 if(!graphics
|| !rect
)
3563 return InvalidParameter
;
3568 /* intersect window and graphics clipping regions */
3569 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
3572 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
3575 /* get bounds of the region */
3576 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
3579 GdipDeleteRegion(clip_rgn
);
3584 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
3589 TRACE("(%p, %p)\n", graphics
, rect
);
3591 if(!graphics
|| !rect
)
3592 return InvalidParameter
;
3594 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
3596 rect
->X
= roundr(rectf
.X
);
3597 rect
->Y
= roundr(rectf
.Y
);
3598 rect
->Width
= roundr(rectf
.Width
);
3599 rect
->Height
= roundr(rectf
.Height
);
3605 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3607 TRACE("(%p, %p)\n", graphics
, matrix
);
3609 if(!graphics
|| !matrix
)
3610 return InvalidParameter
;
3615 *matrix
= *graphics
->worldtrans
;
3619 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
3625 TRACE("(%p, %x)\n", graphics
, color
);
3628 return InvalidParameter
;
3633 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
3636 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
3637 GdipDeleteBrush((GpBrush
*)brush
);
3641 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
3642 wnd_rect
.Width
, wnd_rect
.Height
);
3644 GdipDeleteBrush((GpBrush
*)brush
);
3649 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
3651 TRACE("(%p, %p)\n", graphics
, res
);
3653 if(!graphics
|| !res
)
3654 return InvalidParameter
;
3656 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
3659 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
3665 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
3667 if(!graphics
|| !result
)
3668 return InvalidParameter
;
3675 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
3676 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
3679 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
3682 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
3685 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
3688 GdipDeleteRegion(rgn
);
3692 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
3694 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
3697 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
3703 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
3705 if(!graphics
|| !result
)
3706 return InvalidParameter
;
3713 pts
[1].X
= x
+ width
;
3714 pts
[1].Y
= y
+ height
;
3716 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
3717 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
3720 pts
[1].X
-= pts
[0].X
;
3721 pts
[1].Y
-= pts
[0].Y
;
3723 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
3726 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
3729 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
3732 GdipDeleteRegion(rgn
);
3736 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
3738 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
3741 typedef GpStatus (*gdip_format_string_callback
)(GpGraphics
*graphics
,
3742 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3743 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3744 INT lineno
, const RectF
*bounds
, void *user_data
);
3746 static GpStatus
gdip_format_string(GpGraphics
*graphics
,
3747 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
3748 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3749 gdip_format_string_callback callback
, void *user_data
)
3752 int sum
= 0, height
= 0, fit
, fitcpy
, i
, j
, lret
, nwidth
,
3753 nheight
, lineend
, lineno
= 0;
3755 StringAlignment halign
;
3759 if(length
== -1) length
= lstrlenW(string
);
3761 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
3762 if(!stringdup
) return OutOfMemory
;
3764 nwidth
= roundr(rect
->Width
);
3765 nheight
= roundr(rect
->Height
);
3767 if (rect
->Width
>= INT_MAX
|| rect
->Width
< 0.5) nwidth
= INT_MAX
;
3768 if (rect
->Height
>= INT_MAX
|| rect
->Width
< 0.5) nheight
= INT_MAX
;
3770 for(i
= 0, j
= 0; i
< length
; i
++){
3771 /* FIXME: This makes the indexes passed to callback inaccurate. */
3772 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
3775 stringdup
[j
] = string
[i
];
3781 if (format
) halign
= format
->align
;
3782 else halign
= StringAlignmentNear
;
3784 while(sum
< length
){
3785 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
3786 nwidth
, &fit
, NULL
, &size
);
3792 for(lret
= 0; lret
< fit
; lret
++)
3793 if(*(stringdup
+ sum
+ lret
) == '\n')
3796 /* Line break code (may look strange, but it imitates windows). */
3798 lineend
= fit
= lret
; /* this is not an off-by-one error */
3799 else if(fit
< (length
- sum
)){
3800 if(*(stringdup
+ sum
+ fit
) == ' ')
3801 while(*(stringdup
+ sum
+ fit
) == ' ')
3804 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
3807 if(*(stringdup
+ sum
+ fit
) == '\t')
3816 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
3817 *(stringdup
+ sum
+ lineend
- 1) == '\t')
3823 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, lineend
,
3824 nwidth
, &j
, NULL
, &size
);
3826 bounds
.Width
= size
.cx
;
3828 if(height
+ size
.cy
> nheight
)
3829 bounds
.Height
= nheight
- (height
+ size
.cy
);
3831 bounds
.Height
= size
.cy
;
3833 bounds
.Y
= rect
->Y
+ height
;
3837 case StringAlignmentNear
:
3841 case StringAlignmentCenter
:
3842 bounds
.X
= rect
->X
+ (rect
->Width
/2) - (bounds
.Width
/2);
3844 case StringAlignmentFar
:
3845 bounds
.X
= rect
->X
+ rect
->Width
- bounds
.Width
;
3849 stat
= callback(graphics
, stringdup
, sum
, lineend
,
3850 font
, rect
, format
, lineno
, &bounds
, user_data
);
3855 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
3859 if(height
> nheight
)
3862 /* Stop if this was a linewrap (but not if it was a linebreak). */
3863 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
3867 GdipFree(stringdup
);
3872 struct measure_ranges_args
{
3876 static GpStatus
measure_ranges_callback(GpGraphics
*graphics
,
3877 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3878 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3879 INT lineno
, const RectF
*bounds
, void *user_data
)
3883 struct measure_ranges_args
*args
= user_data
;
3885 for (i
=0; i
<format
->range_count
; i
++)
3887 INT range_start
= max(index
, format
->character_ranges
[i
].First
);
3888 INT range_end
= min(index
+length
, format
->character_ranges
[i
].First
+format
->character_ranges
[i
].Length
);
3889 if (range_start
< range_end
)
3894 range_rect
.Y
= bounds
->Y
;
3895 range_rect
.Height
= bounds
->Height
;
3897 GetTextExtentExPointW(graphics
->hdc
, string
+ index
, range_start
- index
,
3898 INT_MAX
, NULL
, NULL
, &range_size
);
3899 range_rect
.X
= bounds
->X
+ range_size
.cx
;
3901 GetTextExtentExPointW(graphics
->hdc
, string
+ index
, range_end
- index
,
3902 INT_MAX
, NULL
, NULL
, &range_size
);
3903 range_rect
.Width
= (bounds
->X
+ range_size
.cx
) - range_rect
.X
;
3905 stat
= GdipCombineRegionRect(args
->regions
[i
], &range_rect
, CombineModeUnion
);
3914 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
3915 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
3916 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
3917 INT regionCount
, GpRegion
** regions
)
3922 struct measure_ranges_args args
;
3925 TRACE("(%p %s %d %p %s %p %d %p)\n", graphics
, debugstr_w(string
),
3926 length
, font
, debugstr_rectf(layoutRect
), stringFormat
, regionCount
, regions
);
3928 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
3929 return InvalidParameter
;
3931 if (regionCount
< stringFormat
->range_count
)
3932 return InvalidParameter
;
3936 temp_hdc
= graphics
->hdc
= CreateCompatibleDC(0);
3937 if (!temp_hdc
) return OutOfMemory
;
3940 if (stringFormat
->attr
)
3941 TRACE("may be ignoring some format flags: attr %x\n", stringFormat
->attr
);
3943 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
3945 for (i
=0; i
<stringFormat
->range_count
; i
++)
3947 stat
= GdipSetEmpty(regions
[i
]);
3952 args
.regions
= regions
;
3954 stat
= gdip_format_string(graphics
, string
, length
, font
, layoutRect
, stringFormat
,
3955 measure_ranges_callback
, &args
);
3957 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
3961 graphics
->hdc
= NULL
;
3968 struct measure_string_args
{
3970 INT
*codepointsfitted
;
3974 static GpStatus
measure_string_callback(GpGraphics
*graphics
,
3975 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
3976 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
3977 INT lineno
, const RectF
*bounds
, void *user_data
)
3979 struct measure_string_args
*args
= user_data
;
3981 if (bounds
->Width
> args
->bounds
->Width
)
3982 args
->bounds
->Width
= bounds
->Width
;
3984 if (bounds
->Height
+ bounds
->Y
> args
->bounds
->Height
+ args
->bounds
->Y
)
3985 args
->bounds
->Height
= bounds
->Height
+ bounds
->Y
- args
->bounds
->Y
;
3987 if (args
->codepointsfitted
)
3988 *args
->codepointsfitted
= index
+ length
;
3990 if (args
->linesfilled
)
3991 (*args
->linesfilled
)++;
3996 /* Find the smallest rectangle that bounds the text when it is printed in rect
3997 * according to the format options listed in format. If rect has 0 width and
3998 * height, then just find the smallest rectangle that bounds the text when it's
3999 * printed at location (rect->X, rect-Y). */
4000 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
4001 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
4002 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
4003 INT
*codepointsfitted
, INT
*linesfilled
)
4006 struct measure_string_args args
;
4009 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
4010 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
4011 bounds
, codepointsfitted
, linesfilled
);
4013 if(!graphics
|| !string
|| !font
|| !rect
|| !bounds
)
4014 return InvalidParameter
;
4018 temp_hdc
= graphics
->hdc
= CreateCompatibleDC(0);
4019 if (!temp_hdc
) return OutOfMemory
;
4022 if(linesfilled
) *linesfilled
= 0;
4023 if(codepointsfitted
) *codepointsfitted
= 0;
4026 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4028 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
4030 bounds
->X
= rect
->X
;
4031 bounds
->Y
= rect
->Y
;
4032 bounds
->Width
= 0.0;
4033 bounds
->Height
= 0.0;
4035 args
.bounds
= bounds
;
4036 args
.codepointsfitted
= codepointsfitted
;
4037 args
.linesfilled
= linesfilled
;
4039 gdip_format_string(graphics
, string
, length
, font
, rect
, format
,
4040 measure_string_callback
, &args
);
4042 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
4046 graphics
->hdc
= NULL
;
4053 struct draw_string_args
{
4056 REAL ang_cos
, ang_sin
;
4059 static GpStatus
draw_string_callback(GpGraphics
*graphics
,
4060 GDIPCONST WCHAR
*string
, INT index
, INT length
, GDIPCONST GpFont
*font
,
4061 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
,
4062 INT lineno
, const RectF
*bounds
, void *user_data
)
4064 struct draw_string_args
*args
= user_data
;
4067 drawcoord
.left
= drawcoord
.right
= args
->drawbase
.x
+ roundr(args
->ang_sin
* bounds
->Y
);
4068 drawcoord
.top
= drawcoord
.bottom
= args
->drawbase
.y
+ roundr(args
->ang_cos
* bounds
->Y
);
4070 DrawTextW(graphics
->hdc
, string
+ index
, length
, &drawcoord
, args
->drawflags
);
4075 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
4076 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
4077 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
4082 TEXTMETRICW textmet
;
4083 GpPointF pt
[3], rectcpy
[4];
4085 REAL angle
, rel_width
, rel_height
;
4086 INT offsety
= 0, save_state
;
4087 struct draw_string_args args
;
4090 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
4091 length
, font
, debugstr_rectf(rect
), format
, brush
);
4093 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
4094 return InvalidParameter
;
4096 if((brush
->bt
!= BrushTypeSolidColor
)){
4097 FIXME("not implemented for given parameters\n");
4098 return NotImplemented
;
4103 FIXME("graphics object has no HDC\n");
4108 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
4110 /* Should be no need to explicitly test for StringAlignmentNear as
4111 * that is default behavior if no alignment is passed. */
4112 if(format
->vertalign
!= StringAlignmentNear
){
4114 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
4116 if(format
->vertalign
== StringAlignmentCenter
)
4117 offsety
= (rect
->Height
- bounds
.Height
) / 2;
4118 else if(format
->vertalign
== StringAlignmentFar
)
4119 offsety
= (rect
->Height
- bounds
.Height
);
4123 save_state
= SaveDC(graphics
->hdc
);
4124 SetBkMode(graphics
->hdc
, TRANSPARENT
);
4125 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
4133 GdipTransformPoints(graphics
, CoordinateSpaceDevice
, CoordinateSpaceWorld
, pt
, 3);
4134 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
4135 args
.ang_cos
= cos(angle
);
4136 args
.ang_sin
= sin(angle
);
4137 rel_width
= sqrt((pt
[1].Y
-pt
[0].Y
)*(pt
[1].Y
-pt
[0].Y
)+
4138 (pt
[1].X
-pt
[0].X
)*(pt
[1].X
-pt
[0].X
));
4139 rel_height
= sqrt((pt
[2].Y
-pt
[0].Y
)*(pt
[2].Y
-pt
[0].Y
)+
4140 (pt
[2].X
-pt
[0].X
)*(pt
[2].X
-pt
[0].X
));
4142 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
4143 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
4144 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
4145 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
4146 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
4148 scaled_rect
.X
= 0.0;
4149 scaled_rect
.Y
= 0.0;
4150 scaled_rect
.Width
= rel_width
* rect
->Width
;
4151 scaled_rect
.Height
= rel_height
* rect
->Height
;
4153 if (roundr(scaled_rect
.Width
) != 0 && roundr(scaled_rect
.Height
) != 0)
4155 /* FIXME: If only the width or only the height is 0, we should probably still clip */
4156 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
4157 SelectClipRgn(graphics
->hdc
, rgn
);
4160 /* Use gdi to find the font, then perform transformations on it (height,
4162 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
4163 GetTextMetricsW(graphics
->hdc
, &textmet
);
4166 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
4167 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
4169 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
4171 gdifont
= CreateFontIndirectW(&lfw
);
4172 DeleteObject(SelectObject(graphics
->hdc
, CreateFontIndirectW(&lfw
)));
4174 if (!format
|| format
->align
== StringAlignmentNear
)
4176 args
.drawbase
.x
= corners
[0].x
;
4177 args
.drawbase
.y
= corners
[0].y
;
4178 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
;
4180 else if (format
->align
== StringAlignmentCenter
)
4182 args
.drawbase
.x
= (corners
[0].x
+ corners
[1].x
)/2;
4183 args
.drawbase
.y
= (corners
[0].y
+ corners
[1].y
)/2;
4184 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_CENTER
;
4186 else /* (format->align == StringAlignmentFar) */
4188 args
.drawbase
.x
= corners
[1].x
;
4189 args
.drawbase
.y
= corners
[1].y
;
4190 args
.drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_RIGHT
;
4193 gdip_format_string(graphics
, string
, length
, font
, &scaled_rect
, format
,
4194 draw_string_callback
, &args
);
4197 DeleteObject(gdifont
);
4199 RestoreDC(graphics
->hdc
, save_state
);
4204 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
4206 TRACE("(%p)\n", graphics
);
4209 return InvalidParameter
;
4214 return GdipSetInfinite(graphics
->clip
);
4217 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
4219 TRACE("(%p)\n", graphics
);
4222 return InvalidParameter
;
4227 graphics
->worldtrans
->matrix
[0] = 1.0;
4228 graphics
->worldtrans
->matrix
[1] = 0.0;
4229 graphics
->worldtrans
->matrix
[2] = 0.0;
4230 graphics
->worldtrans
->matrix
[3] = 1.0;
4231 graphics
->worldtrans
->matrix
[4] = 0.0;
4232 graphics
->worldtrans
->matrix
[5] = 0.0;
4237 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
4239 return GdipEndContainer(graphics
, state
);
4242 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
4243 GpMatrixOrder order
)
4245 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
4248 return InvalidParameter
;
4253 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
4256 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
4258 return GdipBeginContainer2(graphics
, state
);
4261 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
4262 GraphicsContainer
*state
)
4264 GraphicsContainerItem
*container
;
4267 TRACE("(%p, %p)\n", graphics
, state
);
4269 if(!graphics
|| !state
)
4270 return InvalidParameter
;
4272 sts
= init_container(&container
, graphics
);
4276 list_add_head(&graphics
->containers
, &container
->entry
);
4277 *state
= graphics
->contid
= container
->contid
;
4282 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4284 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4285 return NotImplemented
;
4288 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
4290 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
4291 return NotImplemented
;
4294 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
4296 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
4297 return NotImplemented
;
4300 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
4303 GraphicsContainerItem
*container
, *container2
;
4305 TRACE("(%p, %x)\n", graphics
, state
);
4308 return InvalidParameter
;
4310 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
4311 if(container
->contid
== state
)
4315 /* did not find a matching container */
4316 if(&container
->entry
== &graphics
->containers
)
4319 sts
= restore_container(graphics
, container
);
4323 /* remove all of the containers on top of the found container */
4324 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
4325 if(container
->contid
== state
)
4327 list_remove(&container
->entry
);
4328 delete_container(container
);
4331 list_remove(&container
->entry
);
4332 delete_container(container
);
4337 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
4338 REAL sy
, GpMatrixOrder order
)
4340 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
4343 return InvalidParameter
;
4348 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
4351 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
4354 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
4356 if(!graphics
|| !srcgraphics
)
4357 return InvalidParameter
;
4359 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
4362 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
4363 CompositingMode mode
)
4365 TRACE("(%p, %d)\n", graphics
, mode
);
4368 return InvalidParameter
;
4373 graphics
->compmode
= mode
;
4378 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
4379 CompositingQuality quality
)
4381 TRACE("(%p, %d)\n", graphics
, quality
);
4384 return InvalidParameter
;
4389 graphics
->compqual
= quality
;
4394 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
4395 InterpolationMode mode
)
4397 TRACE("(%p, %d)\n", graphics
, mode
);
4400 return InvalidParameter
;
4405 graphics
->interpolation
= mode
;
4410 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
4412 TRACE("(%p, %.2f)\n", graphics
, scale
);
4414 if(!graphics
|| (scale
<= 0.0))
4415 return InvalidParameter
;
4420 graphics
->scale
= scale
;
4425 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
4427 TRACE("(%p, %d)\n", graphics
, unit
);
4430 return InvalidParameter
;
4435 if(unit
== UnitWorld
)
4436 return InvalidParameter
;
4438 graphics
->unit
= unit
;
4443 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
4446 TRACE("(%p, %d)\n", graphics
, mode
);
4449 return InvalidParameter
;
4454 graphics
->pixeloffset
= mode
;
4459 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
4463 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
4466 FIXME("not implemented\n");
4468 return NotImplemented
;
4471 GpStatus WINGDIPAPI
GdipGetRenderingOrigin(GpGraphics
*graphics
, INT
*x
, INT
*y
)
4475 TRACE("(%p,%p,%p)\n", graphics
, x
, y
);
4478 FIXME("not implemented\n");
4482 return NotImplemented
;
4485 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
4487 TRACE("(%p, %d)\n", graphics
, mode
);
4490 return InvalidParameter
;
4495 graphics
->smoothing
= mode
;
4500 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
4502 TRACE("(%p, %d)\n", graphics
, contrast
);
4505 return InvalidParameter
;
4507 graphics
->textcontrast
= contrast
;
4512 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
4513 TextRenderingHint hint
)
4515 TRACE("(%p, %d)\n", graphics
, hint
);
4518 return InvalidParameter
;
4523 graphics
->texthint
= hint
;
4528 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
4530 TRACE("(%p, %p)\n", graphics
, matrix
);
4532 if(!graphics
|| !matrix
)
4533 return InvalidParameter
;
4538 GdipDeleteMatrix(graphics
->worldtrans
);
4539 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
4542 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
4543 REAL dy
, GpMatrixOrder order
)
4545 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
4548 return InvalidParameter
;
4553 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
4556 /*****************************************************************************
4557 * GdipSetClipHrgn [GDIPLUS.@]
4559 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
4564 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
4567 return InvalidParameter
;
4569 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
4573 status
= GdipSetClipRegion(graphics
, region
, mode
);
4575 GdipDeleteRegion(region
);
4579 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
4581 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
4584 return InvalidParameter
;
4589 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
4592 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
4593 REAL width
, REAL height
,
4598 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
4601 return InvalidParameter
;
4609 rect
.Height
= height
;
4611 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
4614 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
4615 INT width
, INT height
,
4618 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
4621 return InvalidParameter
;
4626 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
4629 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
4632 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
4634 if(!graphics
|| !region
)
4635 return InvalidParameter
;
4640 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
4643 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
4648 TRACE("(%p,%u)\n", metafile
, limitDpi
);
4651 FIXME("not implemented\n");
4653 return NotImplemented
;
4656 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
4662 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
4664 if(!graphics
|| !pen
|| count
<=0)
4665 return InvalidParameter
;
4672 FIXME("graphics object has no HDC\n");
4676 pti
= GdipAlloc(sizeof(POINT
) * count
);
4678 save_state
= prepare_dc(graphics
, pen
);
4679 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
4681 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
4682 Polygon(graphics
->hdc
, pti
, count
);
4684 restore_dc(graphics
, save_state
);
4690 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
4697 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
4699 if(count
<=0) return InvalidParameter
;
4700 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
4702 for(i
= 0;i
< count
; i
++){
4703 ptf
[i
].X
= (REAL
)points
[i
].X
;
4704 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
4707 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
4713 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
4715 TRACE("(%p, %p)\n", graphics
, dpi
);
4717 if(!graphics
|| !dpi
)
4718 return InvalidParameter
;
4723 if (graphics
->image
)
4724 *dpi
= graphics
->image
->xres
;
4726 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
4731 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
4733 TRACE("(%p, %p)\n", graphics
, dpi
);
4735 if(!graphics
|| !dpi
)
4736 return InvalidParameter
;
4741 if (graphics
->image
)
4742 *dpi
= graphics
->image
->yres
;
4744 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
4749 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
4750 GpMatrixOrder order
)
4755 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
4757 if(!graphics
|| !matrix
)
4758 return InvalidParameter
;
4763 m
= *(graphics
->worldtrans
);
4765 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
4767 *(graphics
->worldtrans
) = m
;
4772 /* Color used to fill bitmaps so we can tell which parts have been drawn over by gdi32. */
4773 static const COLORREF DC_BACKGROUND_KEY
= 0x0c0b0d;
4775 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
4777 TRACE("(%p, %p)\n", graphics
, hdc
);
4779 if(!graphics
|| !hdc
)
4780 return InvalidParameter
;
4785 if (!graphics
->hdc
||
4786 (graphics
->image
&& graphics
->image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)graphics
->image
)->format
& PixelFormatAlpha
))
4788 /* Create a fake HDC and fill it with a constant color. */
4793 BITMAPINFOHEADER bmih
;
4796 stat
= get_graphics_bounds(graphics
, &bounds
);
4800 graphics
->temp_hbitmap_width
= bounds
.Width
;
4801 graphics
->temp_hbitmap_height
= bounds
.Height
;
4803 bmih
.biSize
= sizeof(bmih
);
4804 bmih
.biWidth
= graphics
->temp_hbitmap_width
;
4805 bmih
.biHeight
= -graphics
->temp_hbitmap_height
;
4807 bmih
.biBitCount
= 32;
4808 bmih
.biCompression
= BI_RGB
;
4809 bmih
.biSizeImage
= 0;
4810 bmih
.biXPelsPerMeter
= 0;
4811 bmih
.biYPelsPerMeter
= 0;
4813 bmih
.biClrImportant
= 0;
4815 hbitmap
= CreateDIBSection(NULL
, (BITMAPINFO
*)&bmih
, DIB_RGB_COLORS
,
4816 (void**)&graphics
->temp_bits
, NULL
, 0);
4818 return GenericError
;
4820 temp_hdc
= CreateCompatibleDC(0);
4823 DeleteObject(hbitmap
);
4824 return GenericError
;
4827 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
4828 ((DWORD
*)graphics
->temp_bits
)[i
] = DC_BACKGROUND_KEY
;
4830 SelectObject(temp_hdc
, hbitmap
);
4832 graphics
->temp_hbitmap
= hbitmap
;
4833 *hdc
= graphics
->temp_hdc
= temp_hdc
;
4837 *hdc
= graphics
->hdc
;
4840 graphics
->busy
= TRUE
;
4845 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
4847 TRACE("(%p, %p)\n", graphics
, hdc
);
4849 if(!graphics
|| !hdc
)
4850 return InvalidParameter
;
4852 if((graphics
->hdc
!= hdc
&& graphics
->temp_hdc
!= hdc
) || !(graphics
->busy
))
4853 return InvalidParameter
;
4855 if (graphics
->temp_hdc
== hdc
)
4860 /* Find the pixels that have changed, and mark them as opaque. */
4861 pos
= (DWORD
*)graphics
->temp_bits
;
4862 for (i
=0; i
<(graphics
->temp_hbitmap_width
* graphics
->temp_hbitmap_height
); i
++)
4864 if (*pos
!= DC_BACKGROUND_KEY
)
4871 /* Write the changed pixels to the real target. */
4872 alpha_blend_pixels(graphics
, 0, 0, graphics
->temp_bits
,
4873 graphics
->temp_hbitmap_width
, graphics
->temp_hbitmap_height
,
4874 graphics
->temp_hbitmap_width
* 4);
4877 DeleteDC(graphics
->temp_hdc
);
4878 DeleteObject(graphics
->temp_hbitmap
);
4879 graphics
->temp_hdc
= NULL
;
4880 graphics
->temp_hbitmap
= NULL
;
4883 graphics
->busy
= FALSE
;
4888 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
4893 TRACE("(%p, %p)\n", graphics
, region
);
4895 if(!graphics
|| !region
)
4896 return InvalidParameter
;
4901 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
4904 /* free everything except root node and header */
4905 delete_element(®ion
->node
);
4906 memcpy(region
, clip
, sizeof(GpRegion
));
4912 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
4913 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
4919 if(!graphics
|| !points
|| count
<= 0)
4920 return InvalidParameter
;
4925 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
4927 if (src_space
== dst_space
) return Ok
;
4929 stat
= GdipCreateMatrix(&matrix
);
4932 unitscale
= convert_unit(graphics_res(graphics
), graphics
->unit
);
4934 if(graphics
->unit
!= UnitDisplay
)
4935 unitscale
*= graphics
->scale
;
4937 /* transform from src_space to CoordinateSpacePage */
4940 case CoordinateSpaceWorld
:
4941 GdipMultiplyMatrix(matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
4943 case CoordinateSpacePage
:
4945 case CoordinateSpaceDevice
:
4946 GdipScaleMatrix(matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
4950 /* transform from CoordinateSpacePage to dst_space */
4953 case CoordinateSpaceWorld
:
4955 GpMatrix
*inverted_transform
;
4956 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
4959 stat
= GdipInvertMatrix(inverted_transform
);
4961 GdipMultiplyMatrix(matrix
, inverted_transform
, MatrixOrderAppend
);
4962 GdipDeleteMatrix(inverted_transform
);
4966 case CoordinateSpacePage
:
4968 case CoordinateSpaceDevice
:
4969 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
4974 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
4976 GdipDeleteMatrix(matrix
);
4982 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
4983 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
4989 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
4992 return InvalidParameter
;
4994 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
4998 for(i
= 0; i
< count
; i
++){
4999 pointsF
[i
].X
= (REAL
)points
[i
].X
;
5000 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
5003 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
5006 for(i
= 0; i
< count
; i
++){
5007 points
[i
].X
= roundr(pointsF
[i
].X
);
5008 points
[i
].Y
= roundr(pointsF
[i
].Y
);
5015 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
5027 /*****************************************************************************
5028 * GdipTranslateClip [GDIPLUS.@]
5030 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
5032 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
5035 return InvalidParameter
;
5040 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
5043 /*****************************************************************************
5044 * GdipTranslateClipI [GDIPLUS.@]
5046 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
5048 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
5051 return InvalidParameter
;
5056 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
5060 /*****************************************************************************
5061 * GdipMeasureDriverString [GDIPLUS.@]
5063 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5064 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
5065 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
5067 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
5068 return NotImplemented
;
5071 /*****************************************************************************
5072 * GdipDrawDriverString [GDIPLUS.@]
5074 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
5075 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
5076 GDIPCONST PointF
*positions
, INT flags
,
5077 GDIPCONST GpMatrix
*matrix
)
5079 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics
, text
, length
, font
, brush
, positions
, flags
, matrix
);
5080 return NotImplemented
;
5083 GpStatus WINGDIPAPI
GdipRecordMetafile(HDC hdc
, EmfType type
, GDIPCONST GpRectF
*frameRect
,
5084 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
5086 FIXME("(%p %d %p %d %p %p): stub\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
5087 return NotImplemented
;
5090 /*****************************************************************************
5091 * GdipRecordMetafileI [GDIPLUS.@]
5093 GpStatus WINGDIPAPI
GdipRecordMetafileI(HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
5094 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
5096 FIXME("(%p %d %p %d %p %p): stub\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
5097 return NotImplemented
;
5100 GpStatus WINGDIPAPI
GdipRecordMetafileStream(IStream
*stream
, HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
5101 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
5103 FIXME("(%p %p %d %p %d %p %p): stub\n", stream
, hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
5104 return NotImplemented
;
5107 /*****************************************************************************
5108 * GdipIsVisibleClipEmpty [GDIPLUS.@]
5110 GpStatus WINGDIPAPI
GdipIsVisibleClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
5115 TRACE("(%p, %p)\n", graphics
, res
);
5117 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
5120 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
5123 stat
= GdipIsEmptyRegion(rgn
, graphics
, res
);
5126 GdipDeleteRegion(rgn
);