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 INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
91 INT save_state
= SaveDC(graphics
->hdc
), i
, numdashes
;
93 DWORD dash_array
[MAX_DASHLEN
];
95 EndPath(graphics
->hdc
);
97 if(pen
->unit
== UnitPixel
){
101 /* Get an estimate for the amount the pen width is affected by the world
102 * transform. (This is similar to what some of the wine drivers do.) */
107 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
108 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
109 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
111 width
*= pen
->width
* convert_unit(graphics
->hdc
,
112 pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
);
115 if(pen
->dash
== DashStyleCustom
){
116 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
118 TRACE("dashes are: ");
119 for(i
= 0; i
< numdashes
; i
++){
120 dash_array
[i
] = roundr(width
* pen
->dashes
[i
]);
121 TRACE("%d, ", dash_array
[i
]);
123 TRACE("\n and the pen style is %x\n", pen
->style
);
125 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
,
126 numdashes
, dash_array
);
129 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
, 0, NULL
);
131 SelectObject(graphics
->hdc
, gdipen
);
136 static void restore_dc(GpGraphics
*graphics
, INT state
)
138 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
139 RestoreDC(graphics
->hdc
, state
);
142 /* This helper applies all the changes that the points listed in ptf need in
143 * order to be drawn on the device context. In the end, this should include at
145 * -scaling by page unit
146 * -applying world transformation
147 * -converting from float to int
148 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
149 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
150 * gdi to draw, and these functions would irreparably mess with line widths.
152 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
153 GpPointF
*ptf
, INT count
)
159 unitscale
= convert_unit(graphics
->hdc
, graphics
->unit
);
161 /* apply page scale */
162 if(graphics
->unit
!= UnitDisplay
)
163 unitscale
*= graphics
->scale
;
165 GdipCloneMatrix(graphics
->worldtrans
, &matrix
);
166 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
167 GdipTransformMatrixPoints(matrix
, ptf
, count
);
168 GdipDeleteMatrix(matrix
);
170 for(i
= 0; i
< count
; i
++){
171 pti
[i
].x
= roundr(ptf
[i
].X
);
172 pti
[i
].y
= roundr(ptf
[i
].Y
);
176 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
180 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
181 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
185 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
189 /* clamp to between 0.0 and 1.0, using the wrap mode */
190 if (brush
->wrap
== WrapModeTile
)
192 position
= fmodf(position
, 1.0f
);
193 if (position
< 0.0f
) position
+= 1.0f
;
195 else /* WrapModeFlip* */
197 position
= fmodf(position
, 2.0f
);
198 if (position
< 0.0f
) position
+= 2.0f
;
199 if (position
> 1.0f
) position
= 2.0f
- position
;
202 if (brush
->blendcount
== 1)
207 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
210 /* locate the blend positions surrounding this position */
211 while (position
> brush
->blendpos
[i
])
214 /* interpolate between the blend positions */
215 left_blendpos
= brush
->blendpos
[i
-1];
216 left_blendfac
= brush
->blendfac
[i
-1];
217 right_blendpos
= brush
->blendpos
[i
];
218 right_blendfac
= brush
->blendfac
[i
];
219 range
= right_blendpos
- left_blendpos
;
220 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
221 right_blendfac
* (position
- left_blendpos
)) / range
;
223 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
226 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
230 case BrushTypeLinearGradient
:
232 GpLineGradient
*line
= (GpLineGradient
*)brush
;
235 SelectClipPath(graphics
->hdc
, RGN_AND
);
236 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
238 GpPointF endpointsf
[2];
242 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
244 endpointsf
[0] = line
->startpoint
;
245 endpointsf
[1] = line
->endpoint
;
246 transform_and_round_points(graphics
, endpointsi
, endpointsf
, 2);
248 if (abs(endpointsi
[0].x
-endpointsi
[1].x
) > abs(endpointsi
[0].y
-endpointsi
[1].y
))
250 /* vertical-ish gradient */
251 int startx
, endx
; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
252 int startbottomx
; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
255 HBRUSH hbrush
, hprevbrush
;
256 int leftx
, rightx
; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
258 int tilt
; /* horizontal distance covered by a gradient line */
260 startx
= roundr((rc
.top
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
261 endx
= roundr((rc
.top
- endpointsf
[1].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[1].X
);
262 width
= endx
- startx
;
263 startbottomx
= roundr((rc
.bottom
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
264 tilt
= startx
- startbottomx
;
266 if (startx
>= startbottomx
)
269 rightx
= rc
.right
+ tilt
;
273 leftx
= rc
.left
+ tilt
;
277 poly
[0].y
= rc
.bottom
;
280 poly
[3].y
= rc
.bottom
;
282 for (x
=leftx
; x
<=rightx
; x
++)
284 ARGB argb
= blend_line_gradient(line
, (x
-startx
)/(REAL
)width
);
285 col
= ARGB2COLORREF(argb
);
286 hbrush
= CreateSolidBrush(col
);
287 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
288 poly
[0].x
= x
- tilt
- 1;
291 poly
[3].x
= x
- tilt
;
292 Polygon(graphics
->hdc
, poly
, 4);
293 SelectObject(graphics
->hdc
, hprevbrush
);
294 DeleteObject(hbrush
);
297 else if (endpointsi
[0].y
!= endpointsi
[1].y
)
299 /* horizontal-ish gradient */
300 int starty
, endy
; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
301 int startrighty
; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
304 HBRUSH hbrush
, hprevbrush
;
305 int topy
, bottomy
; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
307 int tilt
; /* vertical distance covered by a gradient line */
309 starty
= roundr((rc
.left
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
310 endy
= roundr((rc
.left
- endpointsf
[1].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[1].Y
);
311 height
= endy
- starty
;
312 startrighty
= roundr((rc
.right
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
313 tilt
= starty
- startrighty
;
315 if (starty
>= startrighty
)
318 bottomy
= rc
.bottom
+ tilt
;
322 topy
= rc
.top
+ tilt
;
326 poly
[0].x
= rc
.right
;
329 poly
[3].x
= rc
.right
;
331 for (y
=topy
; y
<=bottomy
; y
++)
333 ARGB argb
= blend_line_gradient(line
, (y
-starty
)/(REAL
)height
);
334 col
= ARGB2COLORREF(argb
);
335 hbrush
= CreateSolidBrush(col
);
336 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
337 poly
[0].y
= y
- tilt
- 1;
340 poly
[3].y
= y
- tilt
;
341 Polygon(graphics
->hdc
, poly
, 4);
342 SelectObject(graphics
->hdc
, hprevbrush
);
343 DeleteObject(hbrush
);
346 /* else startpoint == endpoint */
350 case BrushTypeSolidColor
:
352 GpSolidFill
*fill
= (GpSolidFill
*)brush
;
356 /* partially transparent fill */
358 SelectClipPath(graphics
->hdc
, RGN_AND
);
359 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
361 HDC hdc
= CreateCompatibleDC(NULL
);
367 oldbmp
= SelectObject(hdc
, fill
->bmp
);
369 bf
.BlendOp
= AC_SRC_OVER
;
371 bf
.SourceConstantAlpha
= 255;
372 bf
.AlphaFormat
= AC_SRC_ALPHA
;
374 GdiAlphaBlend(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
-rc
.left
, rc
.bottom
-rc
.top
, hdc
, 0, 0, 1, 1, bf
);
376 SelectObject(hdc
, oldbmp
);
382 /* else fall through */
385 SelectObject(graphics
->hdc
, brush
->gdibrush
);
386 FillPath(graphics
->hdc
);
391 /* GdipDrawPie/GdipFillPie helper function */
392 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
393 REAL height
, REAL startAngle
, REAL sweepAngle
)
400 ptf
[1].X
= x
+ width
;
401 ptf
[1].Y
= y
+ height
;
403 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
404 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
406 transform_and_round_points(graphics
, pti
, ptf
, 4);
408 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
409 pti
[2].y
, pti
[3].x
, pti
[3].y
);
412 /* Draws the linecap the specified color and size on the hdc. The linecap is in
413 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
414 * should not be called on an hdc that has a path you care about. */
415 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
416 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
418 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
419 GpMatrix
*matrix
= NULL
;
422 PointF ptf
[4], *custptf
= NULL
;
423 POINT pt
[4], *custpt
= NULL
;
425 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
430 if((x1
== x2
) && (y1
== y2
))
433 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
435 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
437 brush
= CreateSolidBrush(color
);
438 lb
.lbStyle
= BS_SOLID
;
441 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
442 PS_JOIN_MITER
, 1, &lb
, 0,
444 oldbrush
= SelectObject(graphics
->hdc
, brush
);
445 oldpen
= SelectObject(graphics
->hdc
, pen
);
452 case LineCapSquareAnchor
:
453 case LineCapDiamondAnchor
:
454 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
455 if(cap
== LineCapDiamondAnchor
){
456 dsmall
= cos(theta
+ M_PI_2
) * size
;
457 dbig
= sin(theta
+ M_PI_2
) * size
;
460 dsmall
= cos(theta
+ M_PI_4
) * size
;
461 dbig
= sin(theta
+ M_PI_4
) * size
;
464 ptf
[0].X
= x2
- dsmall
;
465 ptf
[1].X
= x2
+ dbig
;
467 ptf
[0].Y
= y2
- dbig
;
468 ptf
[3].Y
= y2
+ dsmall
;
470 ptf
[1].Y
= y2
- dsmall
;
471 ptf
[2].Y
= y2
+ dbig
;
473 ptf
[3].X
= x2
- dbig
;
474 ptf
[2].X
= x2
+ dsmall
;
476 transform_and_round_points(graphics
, pt
, ptf
, 4);
477 Polygon(graphics
->hdc
, pt
, 4);
480 case LineCapArrowAnchor
:
481 size
= size
* 4.0 / sqrt(3.0);
483 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
484 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
489 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
490 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
498 transform_and_round_points(graphics
, pt
, ptf
, 3);
499 Polygon(graphics
->hdc
, pt
, 3);
502 case LineCapRoundAnchor
:
503 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
510 transform_and_round_points(graphics
, pt
, ptf
, 2);
511 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
514 case LineCapTriangle
:
516 dx
= cos(M_PI_2
+ theta
) * size
;
517 dy
= sin(M_PI_2
+ theta
) * size
;
524 dx
= cos(theta
) * size
;
525 dy
= sin(theta
) * size
;
530 transform_and_round_points(graphics
, pt
, ptf
, 3);
531 Polygon(graphics
->hdc
, pt
, 3);
535 dx
= dy
= size
/ 2.0;
542 dx
= -cos(M_PI_2
+ theta
) * size
;
543 dy
= -sin(M_PI_2
+ theta
) * size
;
550 transform_and_round_points(graphics
, pt
, ptf
, 4);
551 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
552 pt
[2].y
, pt
[3].x
, pt
[3].y
);
559 count
= custom
->pathdata
.Count
;
560 custptf
= GdipAlloc(count
* sizeof(PointF
));
561 custpt
= GdipAlloc(count
* sizeof(POINT
));
562 tp
= GdipAlloc(count
);
564 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
567 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
569 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
570 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
572 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
573 GdipTransformMatrixPoints(matrix
, custptf
, count
);
575 transform_and_round_points(graphics
, custpt
, custptf
, count
);
577 for(i
= 0; i
< count
; i
++)
578 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
581 BeginPath(graphics
->hdc
);
582 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
583 EndPath(graphics
->hdc
);
584 StrokeAndFillPath(graphics
->hdc
);
587 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
593 GdipDeleteMatrix(matrix
);
600 SelectObject(graphics
->hdc
, oldbrush
);
601 SelectObject(graphics
->hdc
, oldpen
);
607 /* Shortens the line by the given percent by changing x2, y2.
608 * If percent is > 1.0 then the line will change direction.
609 * If percent is negative it can lengthen the line. */
610 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
612 REAL dist
, theta
, dx
, dy
;
614 if((y1
== *y2
) && (x1
== *x2
))
617 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
618 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
619 dx
= cos(theta
) * dist
;
620 dy
= sin(theta
) * dist
;
626 /* Shortens the line by the given amount by changing x2, y2.
627 * If the amount is greater than the distance, the line will become length 0.
628 * If the amount is negative, it can lengthen the line. */
629 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
631 REAL dx
, dy
, percent
;
635 if(dx
== 0 && dy
== 0)
638 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
645 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
648 /* Draws lines between the given points, and if caps is true then draws an endcap
649 * at the end of the last line. */
650 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
651 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
654 GpPointF
*ptcopy
= NULL
;
655 GpStatus status
= GenericError
;
660 pti
= GdipAlloc(count
* sizeof(POINT
));
661 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
664 status
= OutOfMemory
;
668 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
671 if(pen
->endcap
== LineCapArrowAnchor
)
672 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
673 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
674 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
675 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
676 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
677 pen
->customend
->inset
* pen
->width
);
679 if(pen
->startcap
== LineCapArrowAnchor
)
680 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
681 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
682 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
683 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
684 &ptcopy
[0].X
, &ptcopy
[0].Y
,
685 pen
->customstart
->inset
* pen
->width
);
687 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
688 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
689 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
690 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
693 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
695 if(Polyline(graphics
->hdc
, pti
, count
))
705 /* Conducts a linear search to find the bezier points that will back off
706 * the endpoint of the curve by a distance of amt. Linear search works
707 * better than binary in this case because there are multiple solutions,
708 * and binary searches often find a bad one. I don't think this is what
709 * Windows does but short of rendering the bezier without GDI's help it's
710 * the best we can do. If rev then work from the start of the passed points
711 * instead of the end. */
712 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
715 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
716 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
725 origx
= pt
[fourth
].X
;
726 origy
= pt
[fourth
].Y
;
727 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
729 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
730 /* reset bezier points to original values */
731 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
732 /* Perform magic on bezier points. Order is important here.*/
733 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
734 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
735 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
736 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
737 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
738 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
740 dx
= pt
[fourth
].X
- origx
;
741 dy
= pt
[fourth
].Y
- origy
;
743 diff
= sqrt(dx
* dx
+ dy
* dy
);
744 percent
+= 0.0005 * amt
;
748 /* Draws bezier curves between given points, and if caps is true then draws an
749 * endcap at the end of the last line. */
750 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
751 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
755 GpStatus status
= GenericError
;
760 pti
= GdipAlloc(count
* sizeof(POINT
));
761 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
764 status
= OutOfMemory
;
768 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
771 if(pen
->endcap
== LineCapArrowAnchor
)
772 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
773 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
774 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
777 if(pen
->startcap
== LineCapArrowAnchor
)
778 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
779 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
780 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
782 /* the direction of the line cap is parallel to the direction at the
783 * end of the bezier (which, if it has been shortened, is not the same
784 * as the direction from pt[count-2] to pt[count-1]) */
785 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
786 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
787 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
788 pt
[count
- 1].X
, pt
[count
- 1].Y
);
790 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
791 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
792 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
795 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
797 PolyBezier(graphics
->hdc
, pti
, count
);
808 /* Draws a combination of bezier curves and lines between points. */
809 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
810 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
812 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
813 BYTE
*tp
= GdipAlloc(count
);
814 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
816 GpStatus status
= GenericError
;
822 if(!pti
|| !tp
|| !ptcopy
){
823 status
= OutOfMemory
;
827 for(i
= 1; i
< count
; i
++){
828 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
829 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
830 || !(types
[i
+ 1] & PathPointTypeBezier
)){
831 ERR("Bad bezier points\n");
838 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
840 /* If we are drawing caps, go through the points and adjust them accordingly,
841 * and draw the caps. */
843 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
844 case PathPointTypeBezier
:
845 if(pen
->endcap
== LineCapArrowAnchor
)
846 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
847 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
848 shorten_bezier_amt(&ptcopy
[count
- 4],
849 pen
->width
* pen
->customend
->inset
, FALSE
);
851 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
852 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
853 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
854 pt
[count
- 1].X
, pt
[count
- 1].Y
);
857 case PathPointTypeLine
:
858 if(pen
->endcap
== LineCapArrowAnchor
)
859 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
860 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
862 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
863 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
864 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
865 pen
->customend
->inset
* pen
->width
);
867 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
868 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
873 ERR("Bad path last point\n");
877 /* Find start of points */
878 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
879 == PathPointTypeStart
); j
++);
881 switch(types
[j
] & PathPointTypePathTypeMask
){
882 case PathPointTypeBezier
:
883 if(pen
->startcap
== LineCapArrowAnchor
)
884 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
885 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
886 shorten_bezier_amt(&ptcopy
[j
- 1],
887 pen
->width
* pen
->customstart
->inset
, TRUE
);
889 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
890 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
891 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
892 pt
[j
- 1].X
, pt
[j
- 1].Y
);
895 case PathPointTypeLine
:
896 if(pen
->startcap
== LineCapArrowAnchor
)
897 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
898 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
900 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
901 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
902 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
903 pen
->customstart
->inset
* pen
->width
);
905 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
906 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
911 ERR("Bad path points\n");
916 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
918 for(i
= 0; i
< count
; i
++){
919 tp
[i
] = convert_path_point_type(types
[i
]);
922 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
934 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
938 BeginPath(graphics
->hdc
);
939 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
940 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
941 EndPath(graphics
->hdc
);
945 typedef struct _GraphicsContainerItem
{
947 GraphicsContainer contid
;
949 SmoothingMode smoothing
;
950 CompositingQuality compqual
;
951 InterpolationMode interpolation
;
952 CompositingMode compmode
;
953 TextRenderingHint texthint
;
956 PixelOffsetMode pixeloffset
;
958 GpMatrix
* worldtrans
;
960 } GraphicsContainerItem
;
962 static GpStatus
init_container(GraphicsContainerItem
** container
,
963 GDIPCONST GpGraphics
* graphics
){
966 *container
= GdipAlloc(sizeof(GraphicsContainerItem
));
970 (*container
)->contid
= graphics
->contid
+ 1;
972 (*container
)->smoothing
= graphics
->smoothing
;
973 (*container
)->compqual
= graphics
->compqual
;
974 (*container
)->interpolation
= graphics
->interpolation
;
975 (*container
)->compmode
= graphics
->compmode
;
976 (*container
)->texthint
= graphics
->texthint
;
977 (*container
)->scale
= graphics
->scale
;
978 (*container
)->unit
= graphics
->unit
;
979 (*container
)->textcontrast
= graphics
->textcontrast
;
980 (*container
)->pixeloffset
= graphics
->pixeloffset
;
982 sts
= GdipCloneMatrix(graphics
->worldtrans
, &(*container
)->worldtrans
);
984 GdipFree(*container
);
989 sts
= GdipCloneRegion(graphics
->clip
, &(*container
)->clip
);
991 GdipDeleteMatrix((*container
)->worldtrans
);
992 GdipFree(*container
);
1000 static void delete_container(GraphicsContainerItem
* container
){
1001 GdipDeleteMatrix(container
->worldtrans
);
1002 GdipDeleteRegion(container
->clip
);
1003 GdipFree(container
);
1006 static GpStatus
restore_container(GpGraphics
* graphics
,
1007 GDIPCONST GraphicsContainerItem
* container
){
1012 sts
= GdipCloneMatrix(container
->worldtrans
, &newTrans
);
1016 sts
= GdipCloneRegion(container
->clip
, &newClip
);
1018 GdipDeleteMatrix(newTrans
);
1022 GdipDeleteMatrix(graphics
->worldtrans
);
1023 graphics
->worldtrans
= newTrans
;
1025 GdipDeleteRegion(graphics
->clip
);
1026 graphics
->clip
= newClip
;
1028 graphics
->contid
= container
->contid
- 1;
1030 graphics
->smoothing
= container
->smoothing
;
1031 graphics
->compqual
= container
->compqual
;
1032 graphics
->interpolation
= container
->interpolation
;
1033 graphics
->compmode
= container
->compmode
;
1034 graphics
->texthint
= container
->texthint
;
1035 graphics
->scale
= container
->scale
;
1036 graphics
->unit
= container
->unit
;
1037 graphics
->textcontrast
= container
->textcontrast
;
1038 graphics
->pixeloffset
= container
->pixeloffset
;
1043 static GpStatus
get_graphics_bounds(GpGraphics
* graphics
, GpRectF
* rect
)
1047 if(graphics
->hwnd
) {
1048 if(!GetClientRect(graphics
->hwnd
, &wnd_rect
))
1049 return GenericError
;
1051 rect
->X
= wnd_rect
.left
;
1052 rect
->Y
= wnd_rect
.top
;
1053 rect
->Width
= wnd_rect
.right
- wnd_rect
.left
;
1054 rect
->Height
= wnd_rect
.bottom
- wnd_rect
.top
;
1058 rect
->Width
= GetDeviceCaps(graphics
->hdc
, HORZRES
);
1059 rect
->Height
= GetDeviceCaps(graphics
->hdc
, VERTRES
);
1065 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
1067 TRACE("(%p, %p)\n", hdc
, graphics
);
1069 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
1072 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
1076 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
1078 if(hDevice
!= NULL
) {
1079 FIXME("Don't know how to handle parameter hDevice\n");
1080 return NotImplemented
;
1086 if(graphics
== NULL
)
1087 return InvalidParameter
;
1089 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1090 if(!*graphics
) return OutOfMemory
;
1092 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1093 GdipFree(*graphics
);
1097 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1098 GdipFree((*graphics
)->worldtrans
);
1099 GdipFree(*graphics
);
1103 (*graphics
)->hdc
= hdc
;
1104 (*graphics
)->hwnd
= WindowFromDC(hdc
);
1105 (*graphics
)->owndc
= FALSE
;
1106 (*graphics
)->smoothing
= SmoothingModeDefault
;
1107 (*graphics
)->compqual
= CompositingQualityDefault
;
1108 (*graphics
)->interpolation
= InterpolationModeDefault
;
1109 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1110 (*graphics
)->compmode
= CompositingModeSourceOver
;
1111 (*graphics
)->unit
= UnitDisplay
;
1112 (*graphics
)->scale
= 1.0;
1113 (*graphics
)->busy
= FALSE
;
1114 (*graphics
)->textcontrast
= 4;
1115 list_init(&(*graphics
)->containers
);
1116 (*graphics
)->contid
= 0;
1121 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
1126 TRACE("(%p, %p)\n", hwnd
, graphics
);
1130 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
1132 ReleaseDC(hwnd
, hdc
);
1136 (*graphics
)->hwnd
= hwnd
;
1137 (*graphics
)->owndc
= TRUE
;
1142 /* FIXME: no icm handling */
1143 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
1145 TRACE("(%p, %p)\n", hwnd
, graphics
);
1147 return GdipCreateFromHWND(hwnd
, graphics
);
1150 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
1151 GpMetafile
**metafile
)
1155 if(!hemf
|| !metafile
)
1156 return InvalidParameter
;
1159 FIXME("not implemented\n");
1161 return NotImplemented
;
1164 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
1165 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1167 IStream
*stream
= NULL
;
1171 GpStatus retval
= GenericError
;
1173 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
1175 if(!hwmf
|| !metafile
|| !placeable
)
1176 return InvalidParameter
;
1179 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
1181 return GenericError
;
1182 copy
= GdipAlloc(read
);
1183 GetMetaFileBitsEx(hwmf
, read
, copy
);
1185 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1188 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
1189 copy
= GdipAlloc(read
);
1190 GetEnhMetaFileBits(hemf
, read
, copy
);
1191 DeleteEnhMetaFile(hemf
);
1193 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
1194 ERR("could not make stream\n");
1199 *metafile
= GdipAlloc(sizeof(GpMetafile
));
1201 retval
= OutOfMemory
;
1205 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1206 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
1210 (*metafile
)->image
.type
= ImageTypeMetafile
;
1211 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
1212 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Right
) / ((REAL
) placeable
->Inch
);
1213 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
1214 - placeable
->BoundingBox
.Left
)) / ((REAL
) placeable
->Inch
);
1215 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
1216 - placeable
->BoundingBox
.Top
)) / ((REAL
) placeable
->Inch
);
1217 (*metafile
)->unit
= UnitInch
;
1220 DeleteMetaFile(hwmf
);
1225 GdipFree(*metafile
);
1226 IStream_Release(stream
);
1230 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1231 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1233 HMETAFILE hmf
= GetMetaFileW(file
);
1235 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1237 if(!hmf
) return InvalidParameter
;
1239 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1242 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
1243 GpMetafile
**metafile
)
1245 FIXME("(%p, %p): stub\n", file
, metafile
);
1246 return NotImplemented
;
1249 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
1250 GpMetafile
**metafile
)
1252 FIXME("(%p, %p): stub\n", stream
, metafile
);
1253 return NotImplemented
;
1256 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
1257 UINT access
, IStream
**stream
)
1262 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
1264 if(!stream
|| !filename
)
1265 return InvalidParameter
;
1267 if(access
& GENERIC_WRITE
)
1268 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
1269 else if(access
& GENERIC_READ
)
1270 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
1272 return InvalidParameter
;
1274 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
1276 return hresult_to_status(ret
);
1279 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
1281 GraphicsContainerItem
*cont
, *next
;
1282 TRACE("(%p)\n", graphics
);
1284 if(!graphics
) return InvalidParameter
;
1285 if(graphics
->busy
) return ObjectBusy
;
1288 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
1290 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
1291 list_remove(&cont
->entry
);
1292 delete_container(cont
);
1295 GdipDeleteRegion(graphics
->clip
);
1296 GdipDeleteMatrix(graphics
->worldtrans
);
1302 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1303 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1305 INT save_state
, num_pts
;
1306 GpPointF points
[MAX_ARC_PTS
];
1309 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1310 width
, height
, startAngle
, sweepAngle
);
1312 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
1313 return InvalidParameter
;
1318 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1320 save_state
= prepare_dc(graphics
, pen
);
1322 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
1324 restore_dc(graphics
, save_state
);
1329 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1330 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1332 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1333 width
, height
, startAngle
, sweepAngle
);
1335 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1338 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1339 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
1345 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
1346 x2
, y2
, x3
, y3
, x4
, y4
);
1348 if(!graphics
|| !pen
)
1349 return InvalidParameter
;
1363 save_state
= prepare_dc(graphics
, pen
);
1365 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1367 restore_dc(graphics
, save_state
);
1372 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1373 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
1379 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
1380 x2
, y2
, x3
, y3
, x4
, y4
);
1382 if(!graphics
|| !pen
)
1383 return InvalidParameter
;
1397 save_state
= prepare_dc(graphics
, pen
);
1399 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1401 restore_dc(graphics
, save_state
);
1406 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
1407 GDIPCONST GpPointF
*points
, INT count
)
1412 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1414 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1415 return InvalidParameter
;
1420 for(i
= 0; i
< floor(count
/ 4); i
++){
1421 ret
= GdipDrawBezier(graphics
, pen
,
1422 points
[4*i
].X
, points
[4*i
].Y
,
1423 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
1424 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
1425 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
1433 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
1434 GDIPCONST GpPoint
*points
, INT count
)
1440 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1442 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1443 return InvalidParameter
;
1448 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
1452 for(i
= 0; i
< count
; i
++){
1453 pts
[i
].X
= (REAL
)points
[i
].X
;
1454 pts
[i
].Y
= (REAL
)points
[i
].Y
;
1457 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
1464 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
1465 GDIPCONST GpPointF
*points
, INT count
)
1467 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1469 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
1472 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1473 GDIPCONST GpPoint
*points
, INT count
)
1475 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1477 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
1480 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1481 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1486 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1488 if(!graphics
|| !pen
|| !points
|| count
<= 0)
1489 return InvalidParameter
;
1494 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
1497 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1499 GdipDeletePath(path
);
1503 stat
= GdipDrawPath(graphics
, pen
, path
);
1505 GdipDeletePath(path
);
1510 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1511 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1517 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1519 if(!points
|| count
<= 0)
1520 return InvalidParameter
;
1522 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1526 for(i
= 0; i
< count
; i
++){
1527 ptf
[i
].X
= (REAL
)points
[i
].X
;
1528 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1531 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
1538 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
1539 GDIPCONST GpPointF
*points
, INT count
)
1541 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1543 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
1546 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1547 GDIPCONST GpPoint
*points
, INT count
)
1553 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1556 return InvalidParameter
;
1558 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1562 for(i
= 0; i
< count
; i
++){
1563 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1564 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1567 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
1573 /* Approximates cardinal spline with Bezier curves. */
1574 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1575 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1577 /* PolyBezier expects count*3-2 points. */
1578 INT i
, len_pt
= count
*3-2, save_state
;
1580 REAL x1
, x2
, y1
, y2
;
1583 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1585 if(!graphics
|| !pen
)
1586 return InvalidParameter
;
1592 return InvalidParameter
;
1594 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
1598 tension
= tension
* TENSION_CONST
;
1600 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
1603 pt
[0].X
= points
[0].X
;
1604 pt
[0].Y
= points
[0].Y
;
1608 for(i
= 0; i
< count
-2; i
++){
1609 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
1613 pt
[3*i
+3].X
= points
[i
+1].X
;
1614 pt
[3*i
+3].Y
= points
[i
+1].Y
;
1619 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
1620 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
1622 pt
[len_pt
-2].X
= x1
;
1623 pt
[len_pt
-2].Y
= y1
;
1624 pt
[len_pt
-1].X
= points
[count
-1].X
;
1625 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
1627 save_state
= prepare_dc(graphics
, pen
);
1629 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
1632 restore_dc(graphics
, save_state
);
1637 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1638 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1644 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1647 return InvalidParameter
;
1649 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1653 for(i
= 0; i
< count
; i
++){
1654 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1655 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1658 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
1664 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
1665 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
1668 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1670 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1671 return InvalidParameter
;
1674 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1677 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
1678 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
1681 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1687 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1688 return InvalidParameter
;
1691 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1694 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1695 REAL y
, REAL width
, REAL height
)
1701 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1703 if(!graphics
|| !pen
)
1704 return InvalidParameter
;
1711 ptf
[1].X
= x
+ width
;
1712 ptf
[1].Y
= y
+ height
;
1714 save_state
= prepare_dc(graphics
, pen
);
1715 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1717 transform_and_round_points(graphics
, pti
, ptf
, 2);
1719 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1721 restore_dc(graphics
, save_state
);
1726 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1727 INT y
, INT width
, INT height
)
1729 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1731 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1735 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
1740 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
1742 if(!graphics
|| !image
)
1743 return InvalidParameter
;
1745 GdipGetImageWidth(image
, &width
);
1746 GdipGetImageHeight(image
, &height
);
1748 /* FIXME: we should use the graphics and image dpi, somehow */
1750 points
[0].X
= points
[2].X
= x
;
1751 points
[0].Y
= points
[1].Y
= y
;
1752 points
[1].X
= x
+ width
;
1753 points
[2].Y
= y
+ height
;
1755 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, 0, 0, width
, height
,
1756 UnitPixel
, NULL
, NULL
, NULL
);
1759 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
1762 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
1764 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
1767 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
1768 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
1771 FIXME("(%p, %p, %f, %f, %f, %f, %f, %f, %d): stub\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
1772 return NotImplemented
;
1775 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
1776 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
1779 FIXME("(%p, %p, %d, %d, %d, %d, %d, %d, %d): stub\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
1780 return NotImplemented
;
1783 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
1784 GDIPCONST GpPointF
*dstpoints
, INT count
)
1786 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
1787 return NotImplemented
;
1790 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
1791 GDIPCONST GpPoint
*dstpoints
, INT count
)
1793 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
1794 return NotImplemented
;
1797 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1798 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
1799 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
1800 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1801 DrawImageAbort callback
, VOID
* callbackData
)
1807 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
1808 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1811 if(!graphics
|| !image
|| !points
|| count
!= 3)
1812 return InvalidParameter
;
1814 if(srcUnit
== UnitInch
)
1815 dx
= dy
= (REAL
) INCH_HIMETRIC
;
1816 else if(srcUnit
== UnitPixel
){
1817 dx
= ((REAL
) INCH_HIMETRIC
) /
1818 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
1819 dy
= ((REAL
) INCH_HIMETRIC
) /
1820 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
1823 return NotImplemented
;
1825 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
1826 transform_and_round_points(graphics
, pti
, ptf
, 3);
1828 /* IPicture renders bitmaps with the y-axis reversed
1829 * FIXME: flipping for unknown image type might not be correct. */
1830 if(image
->type
!= ImageTypeMetafile
){
1833 pti
[0].y
= pti
[2].y
;
1837 if(IPicture_Render(image
->picture
, graphics
->hdc
,
1838 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
1839 srcx
* dx
, srcy
* dy
,
1840 srcwidth
* dx
, srcheight
* dy
,
1843 callback(callbackData
);
1844 return GenericError
;
1850 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
1851 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
1852 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1853 DrawImageAbort callback
, VOID
* callbackData
)
1855 GpPointF pointsF
[3];
1858 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
1859 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1862 if(!points
|| count
!=3)
1863 return InvalidParameter
;
1865 for(i
= 0; i
< count
; i
++){
1866 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1867 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1870 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
1871 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
1872 callback
, callbackData
);
1875 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
1876 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
1877 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
1878 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
1879 VOID
* callbackData
)
1883 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
1884 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
1885 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1889 points
[1].X
= dstx
+ dstwidth
;
1892 points
[2].Y
= dsty
+ dstheight
;
1894 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1895 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1898 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
1899 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
1900 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
1901 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
1902 VOID
* callbackData
)
1906 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
1907 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
1908 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1912 points
[1].X
= dstx
+ dstwidth
;
1915 points
[2].Y
= dsty
+ dstheight
;
1917 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1918 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1921 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
1922 REAL x
, REAL y
, REAL width
, REAL height
)
1928 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
1930 if(!graphics
|| !image
)
1931 return InvalidParameter
;
1933 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
1937 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
1938 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
1939 unit
, NULL
, NULL
, NULL
);
1942 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
1943 INT x
, INT y
, INT width
, INT height
)
1945 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
1947 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
1950 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1951 REAL y1
, REAL x2
, REAL y2
)
1957 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
1959 if(!pen
|| !graphics
)
1960 return InvalidParameter
;
1970 save_state
= prepare_dc(graphics
, pen
);
1972 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1974 restore_dc(graphics
, save_state
);
1979 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1980 INT y1
, INT x2
, INT y2
)
1986 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
1988 if(!pen
|| !graphics
)
1989 return InvalidParameter
;
1999 save_state
= prepare_dc(graphics
, pen
);
2001 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2003 restore_dc(graphics
, save_state
);
2008 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2009 GpPointF
*points
, INT count
)
2014 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2016 if(!pen
|| !graphics
|| (count
< 2))
2017 return InvalidParameter
;
2022 save_state
= prepare_dc(graphics
, pen
);
2024 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
2026 restore_dc(graphics
, save_state
);
2031 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2032 GpPoint
*points
, INT count
)
2036 GpPointF
*ptf
= NULL
;
2039 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2041 if(!pen
|| !graphics
|| (count
< 2))
2042 return InvalidParameter
;
2047 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2048 if(!ptf
) return OutOfMemory
;
2050 for(i
= 0; i
< count
; i
++){
2051 ptf
[i
].X
= (REAL
) points
[i
].X
;
2052 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2055 save_state
= prepare_dc(graphics
, pen
);
2057 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
2059 restore_dc(graphics
, save_state
);
2065 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
2070 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
2072 if(!pen
|| !graphics
)
2073 return InvalidParameter
;
2078 save_state
= prepare_dc(graphics
, pen
);
2080 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
2081 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
2083 restore_dc(graphics
, save_state
);
2088 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2089 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2093 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2094 width
, height
, startAngle
, sweepAngle
);
2096 if(!graphics
|| !pen
)
2097 return InvalidParameter
;
2102 save_state
= prepare_dc(graphics
, pen
);
2103 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2105 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2107 restore_dc(graphics
, save_state
);
2112 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2113 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2115 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2116 width
, height
, startAngle
, sweepAngle
);
2118 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2121 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2122 REAL y
, REAL width
, REAL height
)
2128 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2130 if(!pen
|| !graphics
)
2131 return InvalidParameter
;
2138 ptf
[1].X
= x
+ width
;
2140 ptf
[2].X
= x
+ width
;
2141 ptf
[2].Y
= y
+ height
;
2143 ptf
[3].Y
= y
+ height
;
2145 save_state
= prepare_dc(graphics
, pen
);
2146 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2148 transform_and_round_points(graphics
, pti
, ptf
, 4);
2149 Polygon(graphics
->hdc
, pti
, 4);
2151 restore_dc(graphics
, save_state
);
2156 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2157 INT y
, INT width
, INT height
)
2159 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2161 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2164 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
2165 GDIPCONST GpRectF
* rects
, INT count
)
2171 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2173 if(!graphics
|| !pen
|| !rects
|| count
< 1)
2174 return InvalidParameter
;
2179 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
2180 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
2188 for(i
= 0; i
< count
; i
++){
2189 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
2190 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
2191 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
2192 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
2195 save_state
= prepare_dc(graphics
, pen
);
2196 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2198 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
2200 for(i
= 0; i
< count
; i
++)
2201 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
2203 restore_dc(graphics
, save_state
);
2211 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
2212 GDIPCONST GpRect
* rects
, INT count
)
2218 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2220 if(!rects
|| count
<=0)
2221 return InvalidParameter
;
2223 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
2227 for(i
= 0;i
< count
;i
++){
2228 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2229 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2230 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
2231 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2234 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
2240 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
2241 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
2242 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
2247 TEXTMETRICW textmet
;
2248 GpPointF pt
[2], rectcpy
[4];
2251 REAL angle
, ang_cos
, ang_sin
, rel_width
, rel_height
;
2252 INT sum
= 0, height
= 0, offsety
= 0, fit
, fitcpy
, save_state
, i
, j
, lret
, nwidth
,
2259 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
2260 length
, font
, debugstr_rectf(rect
), format
, brush
);
2262 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
2263 return InvalidParameter
;
2265 if((brush
->bt
!= BrushTypeSolidColor
)){
2266 FIXME("not implemented for given parameters\n");
2267 return NotImplemented
;
2271 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
2273 /* Should be no need to explicitly test for StringAlignmentNear as
2274 * that is default behavior if no alignment is passed. */
2275 if(format
->vertalign
!= StringAlignmentNear
){
2277 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
2279 if(format
->vertalign
== StringAlignmentCenter
)
2280 offsety
= (rect
->Height
- bounds
.Height
) / 2;
2281 else if(format
->vertalign
== StringAlignmentFar
)
2282 offsety
= (rect
->Height
- bounds
.Height
);
2286 if(length
== -1) length
= lstrlenW(string
);
2288 stringdup
= GdipAlloc(length
* sizeof(WCHAR
));
2289 if(!stringdup
) return OutOfMemory
;
2291 save_state
= SaveDC(graphics
->hdc
);
2292 SetBkMode(graphics
->hdc
, TRANSPARENT
);
2293 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
2295 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
2296 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
2297 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
2298 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
2299 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
2301 if (roundr(rect
->Width
) == 0)
2308 rel_width
= sqrt((corners
[1].x
- corners
[0].x
) * (corners
[1].x
- corners
[0].x
) +
2309 (corners
[1].y
- corners
[0].y
) * (corners
[1].y
- corners
[0].y
))
2311 nwidth
= roundr(rel_width
* rect
->Width
);
2314 if (roundr(rect
->Height
) == 0)
2321 rel_height
= sqrt((corners
[2].x
- corners
[1].x
) * (corners
[2].x
- corners
[1].x
) +
2322 (corners
[2].y
- corners
[1].y
) * (corners
[2].y
- corners
[1].y
))
2324 nheight
= roundr(rel_height
* rect
->Height
);
2327 if (roundr(rect
->Width
) != 0 && roundr(rect
->Height
) != 0)
2329 /* FIXME: If only the width or only the height is 0, we should probably still clip */
2330 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
2331 SelectClipRgn(graphics
->hdc
, rgn
);
2334 /* Use gdi to find the font, then perform transformations on it (height,
2336 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
2337 GetTextMetricsW(graphics
->hdc
, &textmet
);
2340 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
2341 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
2347 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
2348 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2349 ang_cos
= cos(angle
);
2350 ang_sin
= sin(angle
);
2351 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
2353 gdifont
= CreateFontIndirectW(&lfw
);
2354 DeleteObject(SelectObject(graphics
->hdc
, CreateFontIndirectW(&lfw
)));
2356 for(i
= 0, j
= 0; i
< length
; i
++){
2357 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
2360 stringdup
[j
] = string
[i
];
2366 if (!format
|| format
->align
== StringAlignmentNear
)
2368 drawbase
.x
= corners
[0].x
;
2369 drawbase
.y
= corners
[0].y
;
2370 drawflags
= DT_NOCLIP
| DT_EXPANDTABS
;
2372 else if (format
->align
== StringAlignmentCenter
)
2374 drawbase
.x
= (corners
[0].x
+ corners
[1].x
)/2;
2375 drawbase
.y
= (corners
[0].y
+ corners
[1].y
)/2;
2376 drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_CENTER
;
2378 else /* (format->align == StringAlignmentFar) */
2380 drawbase
.x
= corners
[1].x
;
2381 drawbase
.y
= corners
[1].y
;
2382 drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_RIGHT
;
2385 while(sum
< length
){
2386 drawcoord
.left
= drawcoord
.right
= drawbase
.x
+ roundr(ang_sin
* (REAL
) height
);
2387 drawcoord
.top
= drawcoord
.bottom
= drawbase
.y
+ roundr(ang_cos
* (REAL
) height
);
2389 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
2390 nwidth
, &fit
, NULL
, &size
);
2394 DrawTextW(graphics
->hdc
, stringdup
+ sum
, 1, &drawcoord
, drawflags
);
2398 for(lret
= 0; lret
< fit
; lret
++)
2399 if(*(stringdup
+ sum
+ lret
) == '\n')
2402 /* Line break code (may look strange, but it imitates windows). */
2404 lineend
= fit
= lret
; /* this is not an off-by-one error */
2405 else if(fit
< (length
- sum
)){
2406 if(*(stringdup
+ sum
+ fit
) == ' ')
2407 while(*(stringdup
+ sum
+ fit
) == ' ')
2410 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
2413 if(*(stringdup
+ sum
+ fit
) == '\t')
2422 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
2423 *(stringdup
+ sum
+ lineend
- 1) == '\t')
2428 DrawTextW(graphics
->hdc
, stringdup
+ sum
, min(length
- sum
, lineend
),
2429 &drawcoord
, drawflags
);
2431 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
2434 if(height
> nheight
)
2437 /* Stop if this was a linewrap (but not if it was a linebreak). */
2438 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
2442 GdipFree(stringdup
);
2444 DeleteObject(gdifont
);
2446 RestoreDC(graphics
->hdc
, save_state
);
2451 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
2452 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
2457 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2458 count
, tension
, fill
);
2460 if(!graphics
|| !brush
|| !points
)
2461 return InvalidParameter
;
2466 stat
= GdipCreatePath(fill
, &path
);
2470 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2472 GdipDeletePath(path
);
2476 stat
= GdipFillPath(graphics
, brush
, path
);
2478 GdipDeletePath(path
);
2482 GdipDeletePath(path
);
2487 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
2488 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
2494 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2495 count
, tension
, fill
);
2497 if(!points
|| count
<= 0)
2498 return InvalidParameter
;
2500 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2504 for(i
= 0;i
< count
;i
++){
2505 ptf
[i
].X
= (REAL
)points
[i
].X
;
2506 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2509 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
2516 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2517 REAL y
, REAL width
, REAL height
)
2523 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2525 if(!graphics
|| !brush
)
2526 return InvalidParameter
;
2533 ptf
[1].X
= x
+ width
;
2534 ptf
[1].Y
= y
+ height
;
2536 save_state
= SaveDC(graphics
->hdc
);
2537 EndPath(graphics
->hdc
);
2539 transform_and_round_points(graphics
, pti
, ptf
, 2);
2541 BeginPath(graphics
->hdc
);
2542 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2543 EndPath(graphics
->hdc
);
2545 brush_fill_path(graphics
, brush
);
2547 RestoreDC(graphics
->hdc
, save_state
);
2552 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2553 INT y
, INT width
, INT height
)
2555 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2557 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2560 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
2565 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
2567 if(!brush
|| !graphics
|| !path
)
2568 return InvalidParameter
;
2573 save_state
= SaveDC(graphics
->hdc
);
2574 EndPath(graphics
->hdc
);
2575 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
2578 BeginPath(graphics
->hdc
);
2579 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2580 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2585 EndPath(graphics
->hdc
);
2586 brush_fill_path(graphics
, brush
);
2591 RestoreDC(graphics
->hdc
, save_state
);
2596 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2597 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2601 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2602 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2604 if(!graphics
|| !brush
)
2605 return InvalidParameter
;
2610 save_state
= SaveDC(graphics
->hdc
);
2611 EndPath(graphics
->hdc
);
2613 BeginPath(graphics
->hdc
);
2614 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2615 EndPath(graphics
->hdc
);
2617 brush_fill_path(graphics
, brush
);
2619 RestoreDC(graphics
->hdc
, save_state
);
2624 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2625 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2627 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2628 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2630 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2633 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
2634 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
2637 GpPointF
*ptf
= NULL
;
2639 GpStatus retval
= Ok
;
2641 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2643 if(!graphics
|| !brush
|| !points
|| !count
)
2644 return InvalidParameter
;
2649 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2650 pti
= GdipAlloc(count
* sizeof(POINT
));
2652 retval
= OutOfMemory
;
2656 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
2658 save_state
= SaveDC(graphics
->hdc
);
2659 EndPath(graphics
->hdc
);
2660 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2663 transform_and_round_points(graphics
, pti
, ptf
, count
);
2665 BeginPath(graphics
->hdc
);
2666 Polygon(graphics
->hdc
, pti
, count
);
2667 EndPath(graphics
->hdc
);
2669 brush_fill_path(graphics
, brush
);
2671 RestoreDC(graphics
->hdc
, save_state
);
2680 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
2681 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
2684 GpPointF
*ptf
= NULL
;
2686 GpStatus retval
= Ok
;
2688 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2690 if(!graphics
|| !brush
|| !points
|| !count
)
2691 return InvalidParameter
;
2696 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2697 pti
= GdipAlloc(count
* sizeof(POINT
));
2699 retval
= OutOfMemory
;
2703 for(i
= 0; i
< count
; i
++){
2704 ptf
[i
].X
= (REAL
) points
[i
].X
;
2705 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2708 save_state
= SaveDC(graphics
->hdc
);
2709 EndPath(graphics
->hdc
);
2710 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2713 transform_and_round_points(graphics
, pti
, ptf
, count
);
2715 BeginPath(graphics
->hdc
);
2716 Polygon(graphics
->hdc
, pti
, count
);
2717 EndPath(graphics
->hdc
);
2719 brush_fill_path(graphics
, brush
);
2721 RestoreDC(graphics
->hdc
, save_state
);
2730 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
2731 GDIPCONST GpPointF
*points
, INT count
)
2733 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2735 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
2738 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
2739 GDIPCONST GpPoint
*points
, INT count
)
2741 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2743 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
2746 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
2747 REAL x
, REAL y
, REAL width
, REAL height
)
2753 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2755 if(!graphics
|| !brush
)
2756 return InvalidParameter
;
2763 ptf
[1].X
= x
+ width
;
2765 ptf
[2].X
= x
+ width
;
2766 ptf
[2].Y
= y
+ height
;
2768 ptf
[3].Y
= y
+ height
;
2770 save_state
= SaveDC(graphics
->hdc
);
2771 EndPath(graphics
->hdc
);
2773 transform_and_round_points(graphics
, pti
, ptf
, 4);
2775 BeginPath(graphics
->hdc
);
2776 Polygon(graphics
->hdc
, pti
, 4);
2777 EndPath(graphics
->hdc
);
2779 brush_fill_path(graphics
, brush
);
2781 RestoreDC(graphics
->hdc
, save_state
);
2786 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
2787 INT x
, INT y
, INT width
, INT height
)
2793 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2795 if(!graphics
|| !brush
)
2796 return InvalidParameter
;
2803 ptf
[1].X
= x
+ width
;
2805 ptf
[2].X
= x
+ width
;
2806 ptf
[2].Y
= y
+ height
;
2808 ptf
[3].Y
= y
+ height
;
2810 save_state
= SaveDC(graphics
->hdc
);
2811 EndPath(graphics
->hdc
);
2813 transform_and_round_points(graphics
, pti
, ptf
, 4);
2815 BeginPath(graphics
->hdc
);
2816 Polygon(graphics
->hdc
, pti
, 4);
2817 EndPath(graphics
->hdc
);
2819 brush_fill_path(graphics
, brush
);
2821 RestoreDC(graphics
->hdc
, save_state
);
2826 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
2832 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2835 return InvalidParameter
;
2837 for(i
= 0; i
< count
; i
++){
2838 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
2839 if(ret
!= Ok
) return ret
;
2845 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
2852 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2854 if(!rects
|| count
<= 0)
2855 return InvalidParameter
;
2857 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
2861 for(i
= 0; i
< count
; i
++){
2862 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2863 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2864 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
2865 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2868 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
2874 /*****************************************************************************
2875 * GdipFillRegion [GDIPLUS.@]
2877 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
2885 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
2887 if (!(graphics
&& brush
&& region
))
2888 return InvalidParameter
;
2893 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
2897 save_state
= SaveDC(graphics
->hdc
);
2898 EndPath(graphics
->hdc
);
2900 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
2902 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
2904 BeginPath(graphics
->hdc
);
2905 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
2906 EndPath(graphics
->hdc
);
2908 brush_fill_path(graphics
, brush
);
2911 RestoreDC(graphics
->hdc
, save_state
);
2918 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
2923 return InvalidParameter
;
2929 FIXME("not implemented\n");
2931 return NotImplemented
;
2934 /*****************************************************************************
2935 * GdipGetClipBounds [GDIPLUS.@]
2937 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
2939 TRACE("(%p, %p)\n", graphics
, rect
);
2942 return InvalidParameter
;
2947 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
2950 /*****************************************************************************
2951 * GdipGetClipBoundsI [GDIPLUS.@]
2953 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
2955 TRACE("(%p, %p)\n", graphics
, rect
);
2958 return InvalidParameter
;
2963 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
2966 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
2967 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
2968 CompositingMode
*mode
)
2970 TRACE("(%p, %p)\n", graphics
, mode
);
2972 if(!graphics
|| !mode
)
2973 return InvalidParameter
;
2978 *mode
= graphics
->compmode
;
2983 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
2984 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
2985 CompositingQuality
*quality
)
2987 TRACE("(%p, %p)\n", graphics
, quality
);
2989 if(!graphics
|| !quality
)
2990 return InvalidParameter
;
2995 *quality
= graphics
->compqual
;
3000 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3001 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
3002 InterpolationMode
*mode
)
3004 TRACE("(%p, %p)\n", graphics
, mode
);
3006 if(!graphics
|| !mode
)
3007 return InvalidParameter
;
3012 *mode
= graphics
->interpolation
;
3017 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
3019 if(!graphics
|| !argb
)
3020 return InvalidParameter
;
3025 FIXME("(%p, %p): stub\n", graphics
, argb
);
3027 return NotImplemented
;
3030 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
3032 TRACE("(%p, %p)\n", graphics
, scale
);
3034 if(!graphics
|| !scale
)
3035 return InvalidParameter
;
3040 *scale
= graphics
->scale
;
3045 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
3047 TRACE("(%p, %p)\n", graphics
, unit
);
3049 if(!graphics
|| !unit
)
3050 return InvalidParameter
;
3055 *unit
= graphics
->unit
;
3060 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3061 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3064 TRACE("(%p, %p)\n", graphics
, mode
);
3066 if(!graphics
|| !mode
)
3067 return InvalidParameter
;
3072 *mode
= graphics
->pixeloffset
;
3077 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3078 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
3080 TRACE("(%p, %p)\n", graphics
, mode
);
3082 if(!graphics
|| !mode
)
3083 return InvalidParameter
;
3088 *mode
= graphics
->smoothing
;
3093 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
3095 TRACE("(%p, %p)\n", graphics
, contrast
);
3097 if(!graphics
|| !contrast
)
3098 return InvalidParameter
;
3100 *contrast
= graphics
->textcontrast
;
3105 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3106 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
3107 TextRenderingHint
*hint
)
3109 TRACE("(%p, %p)\n", graphics
, hint
);
3111 if(!graphics
|| !hint
)
3112 return InvalidParameter
;
3117 *hint
= graphics
->texthint
;
3122 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
3128 TRACE("(%p, %p)\n", graphics
, rect
);
3130 if(!graphics
|| !rect
)
3131 return InvalidParameter
;
3136 /* get window bounds */
3137 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
)
3140 /* intersect window and graphics clipping regions */
3141 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
3144 if((stat
= GdipCombineRegionRect(clip_rgn
, &wnd_rect
, CombineModeIntersect
)) != Ok
)
3147 if((stat
= GdipCombineRegionRegion(clip_rgn
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
3150 /* get bounds of the region */
3151 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
3154 GdipDeleteRegion(clip_rgn
);
3159 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
3164 TRACE("(%p, %p)\n", graphics
, rect
);
3166 if(!graphics
|| !rect
)
3167 return InvalidParameter
;
3169 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
3171 rect
->X
= roundr(rectf
.X
);
3172 rect
->Y
= roundr(rectf
.Y
);
3173 rect
->Width
= roundr(rectf
.Width
);
3174 rect
->Height
= roundr(rectf
.Height
);
3180 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3182 TRACE("(%p, %p)\n", graphics
, matrix
);
3184 if(!graphics
|| !matrix
)
3185 return InvalidParameter
;
3190 *matrix
= *graphics
->worldtrans
;
3194 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
3200 TRACE("(%p, %x)\n", graphics
, color
);
3203 return InvalidParameter
;
3208 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
3211 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
3212 GdipDeleteBrush((GpBrush
*)brush
);
3216 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
3217 wnd_rect
.Width
, wnd_rect
.Height
);
3219 GdipDeleteBrush((GpBrush
*)brush
);
3224 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
3226 TRACE("(%p, %p)\n", graphics
, res
);
3228 if(!graphics
|| !res
)
3229 return InvalidParameter
;
3231 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
3234 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
3236 FIXME("(%p, %.2f, %.2f, %p) stub\n", graphics
, x
, y
, result
);
3238 if(!graphics
|| !result
)
3239 return InvalidParameter
;
3244 return NotImplemented
;
3247 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
3249 FIXME("(%p, %d, %d, %p) stub\n", graphics
, x
, y
, result
);
3251 if(!graphics
|| !result
)
3252 return InvalidParameter
;
3257 return NotImplemented
;
3260 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
3261 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
3262 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
3263 INT regionCount
, GpRegion
** regions
)
3265 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
3266 return InvalidParameter
;
3268 FIXME("stub: %p %s %d %p %p %p %d %p\n", graphics
, debugstr_w(string
),
3269 length
, font
, layoutRect
, stringFormat
, regionCount
, regions
);
3271 return NotImplemented
;
3274 /* Find the smallest rectangle that bounds the text when it is printed in rect
3275 * according to the format options listed in format. If rect has 0 width and
3276 * height, then just find the smallest rectangle that bounds the text when it's
3277 * printed at location (rect->X, rect-Y). */
3278 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
3279 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
3280 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
3281 INT
*codepointsfitted
, INT
*linesfilled
)
3285 INT sum
= 0, height
= 0, fit
, fitcpy
, max_width
= 0, i
, j
, lret
, nwidth
,
3289 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
3290 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
3291 bounds
, codepointsfitted
, linesfilled
);
3293 if(!graphics
|| !string
|| !font
|| !rect
)
3294 return InvalidParameter
;
3296 if(linesfilled
) *linesfilled
= 0;
3297 if(codepointsfitted
) *codepointsfitted
= 0;
3300 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
3302 if(length
== -1) length
= lstrlenW(string
);
3304 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
3305 if(!stringdup
) return OutOfMemory
;
3307 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
3308 nwidth
= roundr(rect
->Width
);
3309 nheight
= roundr(rect
->Height
);
3311 if((nwidth
== 0) && (nheight
== 0))
3312 nwidth
= nheight
= INT_MAX
;
3314 for(i
= 0, j
= 0; i
< length
; i
++){
3315 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
3318 stringdup
[j
] = string
[i
];
3325 while(sum
< length
){
3326 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
3327 nwidth
, &fit
, NULL
, &size
);
3333 for(lret
= 0; lret
< fit
; lret
++)
3334 if(*(stringdup
+ sum
+ lret
) == '\n')
3337 /* Line break code (may look strange, but it imitates windows). */
3339 lineend
= fit
= lret
; /* this is not an off-by-one error */
3340 else if(fit
< (length
- sum
)){
3341 if(*(stringdup
+ sum
+ fit
) == ' ')
3342 while(*(stringdup
+ sum
+ fit
) == ' ')
3345 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
3348 if(*(stringdup
+ sum
+ fit
) == '\t')
3357 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
3358 *(stringdup
+ sum
+ lineend
- 1) == '\t')
3364 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, lineend
,
3365 nwidth
, &j
, NULL
, &size
);
3367 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
3368 if(codepointsfitted
) *codepointsfitted
= sum
;
3371 if(linesfilled
) *linesfilled
+= size
.cy
;
3372 max_width
= max(max_width
, size
.cx
);
3374 if(height
> nheight
)
3377 /* Stop if this was a linewrap (but not if it was a linebreak). */
3378 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
3382 bounds
->X
= rect
->X
;
3383 bounds
->Y
= rect
->Y
;
3384 bounds
->Width
= (REAL
)max_width
;
3385 bounds
->Height
= (REAL
) min(height
, nheight
);
3387 GdipFree(stringdup
);
3388 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
3393 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
3395 TRACE("(%p)\n", graphics
);
3398 return InvalidParameter
;
3403 return GdipSetInfinite(graphics
->clip
);
3406 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
3408 TRACE("(%p)\n", graphics
);
3411 return InvalidParameter
;
3416 graphics
->worldtrans
->matrix
[0] = 1.0;
3417 graphics
->worldtrans
->matrix
[1] = 0.0;
3418 graphics
->worldtrans
->matrix
[2] = 0.0;
3419 graphics
->worldtrans
->matrix
[3] = 1.0;
3420 graphics
->worldtrans
->matrix
[4] = 0.0;
3421 graphics
->worldtrans
->matrix
[5] = 0.0;
3426 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
3428 return GdipEndContainer(graphics
, state
);
3431 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
3432 GpMatrixOrder order
)
3434 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
3437 return InvalidParameter
;
3442 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
3445 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
3447 return GdipBeginContainer2(graphics
, state
);
3450 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
3451 GraphicsContainer
*state
)
3453 GraphicsContainerItem
*container
;
3456 TRACE("(%p, %p)\n", graphics
, state
);
3458 if(!graphics
|| !state
)
3459 return InvalidParameter
;
3461 sts
= init_container(&container
, graphics
);
3465 list_add_head(&graphics
->containers
, &container
->entry
);
3466 *state
= graphics
->contid
= container
->contid
;
3471 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
3473 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
3474 return NotImplemented
;
3477 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
3479 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
3480 return NotImplemented
;
3483 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
3485 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
3486 return NotImplemented
;
3489 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
3492 GraphicsContainerItem
*container
, *container2
;
3494 TRACE("(%p, %x)\n", graphics
, state
);
3497 return InvalidParameter
;
3499 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
3500 if(container
->contid
== state
)
3504 /* did not find a matching container */
3505 if(&container
->entry
== &graphics
->containers
)
3508 sts
= restore_container(graphics
, container
);
3512 /* remove all of the containers on top of the found container */
3513 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
3514 if(container
->contid
== state
)
3516 list_remove(&container
->entry
);
3517 delete_container(container
);
3520 list_remove(&container
->entry
);
3521 delete_container(container
);
3526 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
3527 REAL sy
, GpMatrixOrder order
)
3529 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
3532 return InvalidParameter
;
3537 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
3540 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
3543 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
3545 if(!graphics
|| !srcgraphics
)
3546 return InvalidParameter
;
3548 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
3551 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
3552 CompositingMode mode
)
3554 TRACE("(%p, %d)\n", graphics
, mode
);
3557 return InvalidParameter
;
3562 graphics
->compmode
= mode
;
3567 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
3568 CompositingQuality quality
)
3570 TRACE("(%p, %d)\n", graphics
, quality
);
3573 return InvalidParameter
;
3578 graphics
->compqual
= quality
;
3583 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
3584 InterpolationMode mode
)
3586 TRACE("(%p, %d)\n", graphics
, mode
);
3589 return InvalidParameter
;
3594 graphics
->interpolation
= mode
;
3599 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
3601 TRACE("(%p, %.2f)\n", graphics
, scale
);
3603 if(!graphics
|| (scale
<= 0.0))
3604 return InvalidParameter
;
3609 graphics
->scale
= scale
;
3614 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
3616 TRACE("(%p, %d)\n", graphics
, unit
);
3619 return InvalidParameter
;
3624 if(unit
== UnitWorld
)
3625 return InvalidParameter
;
3627 graphics
->unit
= unit
;
3632 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3635 TRACE("(%p, %d)\n", graphics
, mode
);
3638 return InvalidParameter
;
3643 graphics
->pixeloffset
= mode
;
3648 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
3652 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
3655 FIXME("not implemented\n");
3657 return NotImplemented
;
3660 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
3662 TRACE("(%p, %d)\n", graphics
, mode
);
3665 return InvalidParameter
;
3670 graphics
->smoothing
= mode
;
3675 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
3677 TRACE("(%p, %d)\n", graphics
, contrast
);
3680 return InvalidParameter
;
3682 graphics
->textcontrast
= contrast
;
3687 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
3688 TextRenderingHint hint
)
3690 TRACE("(%p, %d)\n", graphics
, hint
);
3693 return InvalidParameter
;
3698 graphics
->texthint
= hint
;
3703 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3705 TRACE("(%p, %p)\n", graphics
, matrix
);
3707 if(!graphics
|| !matrix
)
3708 return InvalidParameter
;
3713 GdipDeleteMatrix(graphics
->worldtrans
);
3714 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
3717 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
3718 REAL dy
, GpMatrixOrder order
)
3720 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
3723 return InvalidParameter
;
3728 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
3731 /*****************************************************************************
3732 * GdipSetClipHrgn [GDIPLUS.@]
3734 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
3739 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
3742 return InvalidParameter
;
3744 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
3748 status
= GdipSetClipRegion(graphics
, region
, mode
);
3750 GdipDeleteRegion(region
);
3754 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
3756 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
3759 return InvalidParameter
;
3764 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
3767 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
3768 REAL width
, REAL height
,
3773 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3776 return InvalidParameter
;
3784 rect
.Height
= height
;
3786 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
3789 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
3790 INT width
, INT height
,
3793 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3796 return InvalidParameter
;
3801 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
3804 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
3807 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
3809 if(!graphics
|| !region
)
3810 return InvalidParameter
;
3815 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
3818 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
3824 FIXME("not implemented\n");
3826 return NotImplemented
;
3829 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
3835 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
3837 if(!graphics
|| !pen
|| count
<=0)
3838 return InvalidParameter
;
3843 pti
= GdipAlloc(sizeof(POINT
) * count
);
3845 save_state
= prepare_dc(graphics
, pen
);
3846 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3848 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
3849 Polygon(graphics
->hdc
, pti
, count
);
3851 restore_dc(graphics
, save_state
);
3857 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
3864 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3866 if(count
<=0) return InvalidParameter
;
3867 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
3869 for(i
= 0;i
< count
; i
++){
3870 ptf
[i
].X
= (REAL
)points
[i
].X
;
3871 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3874 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
3880 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
3882 TRACE("(%p, %p)\n", graphics
, dpi
);
3884 if(!graphics
|| !dpi
)
3885 return InvalidParameter
;
3890 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
3895 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
3897 TRACE("(%p, %p)\n", graphics
, dpi
);
3899 if(!graphics
|| !dpi
)
3900 return InvalidParameter
;
3905 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
3910 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
3911 GpMatrixOrder order
)
3916 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
3918 if(!graphics
|| !matrix
)
3919 return InvalidParameter
;
3924 m
= *(graphics
->worldtrans
);
3926 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
3928 *(graphics
->worldtrans
) = m
;
3933 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
3935 TRACE("(%p, %p)\n", graphics
, hdc
);
3937 if(!graphics
|| !hdc
)
3938 return InvalidParameter
;
3943 *hdc
= graphics
->hdc
;
3944 graphics
->busy
= TRUE
;
3949 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
3951 TRACE("(%p, %p)\n", graphics
, hdc
);
3954 return InvalidParameter
;
3956 if(graphics
->hdc
!= hdc
|| !(graphics
->busy
))
3957 return InvalidParameter
;
3959 graphics
->busy
= FALSE
;
3964 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
3969 TRACE("(%p, %p)\n", graphics
, region
);
3971 if(!graphics
|| !region
)
3972 return InvalidParameter
;
3977 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
3980 /* free everything except root node and header */
3981 delete_element(®ion
->node
);
3982 memcpy(region
, clip
, sizeof(GpRegion
));
3987 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
3988 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
3994 if(!graphics
|| !points
|| count
<= 0)
3995 return InvalidParameter
;
4000 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
4002 if (src_space
== dst_space
) return Ok
;
4004 stat
= GdipCreateMatrix(&matrix
);
4007 unitscale
= convert_unit(graphics
->hdc
, graphics
->unit
);
4009 if(graphics
->unit
!= UnitDisplay
)
4010 unitscale
*= graphics
->scale
;
4012 /* transform from src_space to CoordinateSpacePage */
4015 case CoordinateSpaceWorld
:
4016 GdipMultiplyMatrix(matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
4018 case CoordinateSpacePage
:
4020 case CoordinateSpaceDevice
:
4021 GdipScaleMatrix(matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
4025 /* transform from CoordinateSpacePage to dst_space */
4028 case CoordinateSpaceWorld
:
4030 GpMatrix
*inverted_transform
;
4031 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
4034 stat
= GdipInvertMatrix(inverted_transform
);
4036 GdipMultiplyMatrix(matrix
, inverted_transform
, MatrixOrderAppend
);
4037 GdipDeleteMatrix(inverted_transform
);
4041 case CoordinateSpacePage
:
4043 case CoordinateSpaceDevice
:
4044 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
4049 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
4051 GdipDeleteMatrix(matrix
);
4057 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
4058 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
4064 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
4067 return InvalidParameter
;
4069 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
4073 for(i
= 0; i
< count
; i
++){
4074 pointsF
[i
].X
= (REAL
)points
[i
].X
;
4075 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
4078 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
4081 for(i
= 0; i
< count
; i
++){
4082 points
[i
].X
= roundr(pointsF
[i
].X
);
4083 points
[i
].Y
= roundr(pointsF
[i
].Y
);
4090 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
4097 /*****************************************************************************
4098 * GdipTranslateClip [GDIPLUS.@]
4100 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
4102 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
4105 return InvalidParameter
;
4110 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
4113 /*****************************************************************************
4114 * GdipTranslateClipI [GDIPLUS.@]
4116 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
4118 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
4121 return InvalidParameter
;
4126 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
4130 /*****************************************************************************
4131 * GdipMeasureDriverString [GDIPLUS.@]
4133 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
4134 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
4135 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
4137 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
4138 return NotImplemented
;
4141 /*****************************************************************************
4142 * GdipDrawDriverString [GDIPLUS.@]
4144 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
4145 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
4146 GDIPCONST PointF
*positions
, INT flags
,
4147 GDIPCONST GpMatrix
*matrix
)
4149 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics
, text
, length
, font
, brush
, positions
, flags
, matrix
);
4150 return NotImplemented
;
4153 /*****************************************************************************
4154 * GdipRecordMetafileI [GDIPLUS.@]
4156 GpStatus WINGDIPAPI
GdipRecordMetafileI(HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
4157 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
4159 FIXME("(%p %d %p %d %p %p): stub\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
4160 return NotImplemented
;
4163 /*****************************************************************************
4164 * GdipIsVisibleRectI [GDIPLUS.@]
4166 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
4168 FIXME("(%p %d %d %d %d %p): stub\n", graphics
, x
, y
, width
, height
, result
);
4169 return NotImplemented
;