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 /* on success, rgn will contain the region of the graphics object which
1066 * is visible after clipping has been applied */
1067 static GpStatus
get_visible_clip_region(GpGraphics
*graphics
, GpRegion
*rgn
)
1073 if((stat
= get_graphics_bounds(graphics
, &rectf
)) != Ok
)
1076 if((stat
= GdipCreateRegion(&tmp
)) != Ok
)
1079 if((stat
= GdipCombineRegionRect(tmp
, &rectf
, CombineModeReplace
)) != Ok
)
1082 if((stat
= GdipCombineRegionRegion(tmp
, graphics
->clip
, CombineModeIntersect
)) != Ok
)
1085 stat
= GdipCombineRegionRegion(rgn
, tmp
, CombineModeReplace
);
1088 GdipDeleteRegion(tmp
);
1092 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
1094 TRACE("(%p, %p)\n", hdc
, graphics
);
1096 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
1099 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
1103 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
1105 if(hDevice
!= NULL
) {
1106 FIXME("Don't know how to handle parameter hDevice\n");
1107 return NotImplemented
;
1113 if(graphics
== NULL
)
1114 return InvalidParameter
;
1116 *graphics
= GdipAlloc(sizeof(GpGraphics
));
1117 if(!*graphics
) return OutOfMemory
;
1119 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
1120 GdipFree(*graphics
);
1124 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
1125 GdipFree((*graphics
)->worldtrans
);
1126 GdipFree(*graphics
);
1130 (*graphics
)->hdc
= hdc
;
1131 (*graphics
)->hwnd
= WindowFromDC(hdc
);
1132 (*graphics
)->owndc
= FALSE
;
1133 (*graphics
)->smoothing
= SmoothingModeDefault
;
1134 (*graphics
)->compqual
= CompositingQualityDefault
;
1135 (*graphics
)->interpolation
= InterpolationModeDefault
;
1136 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
1137 (*graphics
)->compmode
= CompositingModeSourceOver
;
1138 (*graphics
)->unit
= UnitDisplay
;
1139 (*graphics
)->scale
= 1.0;
1140 (*graphics
)->busy
= FALSE
;
1141 (*graphics
)->textcontrast
= 4;
1142 list_init(&(*graphics
)->containers
);
1143 (*graphics
)->contid
= 0;
1148 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
1153 TRACE("(%p, %p)\n", hwnd
, graphics
);
1157 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
1159 ReleaseDC(hwnd
, hdc
);
1163 (*graphics
)->hwnd
= hwnd
;
1164 (*graphics
)->owndc
= TRUE
;
1169 /* FIXME: no icm handling */
1170 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
1172 TRACE("(%p, %p)\n", hwnd
, graphics
);
1174 return GdipCreateFromHWND(hwnd
, graphics
);
1177 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
1178 GpMetafile
**metafile
)
1182 if(!hemf
|| !metafile
)
1183 return InvalidParameter
;
1186 FIXME("not implemented\n");
1188 return NotImplemented
;
1191 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
1192 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1194 IStream
*stream
= NULL
;
1198 GpStatus retval
= GenericError
;
1200 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
1202 if(!hwmf
|| !metafile
|| !placeable
)
1203 return InvalidParameter
;
1206 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
1208 return GenericError
;
1209 copy
= GdipAlloc(read
);
1210 GetMetaFileBitsEx(hwmf
, read
, copy
);
1212 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1215 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
1216 copy
= GdipAlloc(read
);
1217 GetEnhMetaFileBits(hemf
, read
, copy
);
1218 DeleteEnhMetaFile(hemf
);
1220 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
1221 ERR("could not make stream\n");
1226 *metafile
= GdipAlloc(sizeof(GpMetafile
));
1228 retval
= OutOfMemory
;
1232 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1233 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
1237 (*metafile
)->image
.type
= ImageTypeMetafile
;
1238 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
1239 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Right
) / ((REAL
) placeable
->Inch
);
1240 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
1241 - placeable
->BoundingBox
.Left
)) / ((REAL
) placeable
->Inch
);
1242 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
1243 - placeable
->BoundingBox
.Top
)) / ((REAL
) placeable
->Inch
);
1244 (*metafile
)->unit
= UnitInch
;
1247 DeleteMetaFile(hwmf
);
1252 GdipFree(*metafile
);
1253 IStream_Release(stream
);
1257 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1258 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1260 HMETAFILE hmf
= GetMetaFileW(file
);
1262 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1264 if(!hmf
) return InvalidParameter
;
1266 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1269 GpStatus WINGDIPAPI
GdipCreateMetafileFromFile(GDIPCONST WCHAR
*file
,
1270 GpMetafile
**metafile
)
1272 FIXME("(%p, %p): stub\n", file
, metafile
);
1273 return NotImplemented
;
1276 GpStatus WINGDIPAPI
GdipCreateMetafileFromStream(IStream
*stream
,
1277 GpMetafile
**metafile
)
1279 FIXME("(%p, %p): stub\n", stream
, metafile
);
1280 return NotImplemented
;
1283 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
1284 UINT access
, IStream
**stream
)
1289 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
1291 if(!stream
|| !filename
)
1292 return InvalidParameter
;
1294 if(access
& GENERIC_WRITE
)
1295 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
1296 else if(access
& GENERIC_READ
)
1297 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
1299 return InvalidParameter
;
1301 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
1303 return hresult_to_status(ret
);
1306 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
1308 GraphicsContainerItem
*cont
, *next
;
1309 TRACE("(%p)\n", graphics
);
1311 if(!graphics
) return InvalidParameter
;
1312 if(graphics
->busy
) return ObjectBusy
;
1315 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
1317 LIST_FOR_EACH_ENTRY_SAFE(cont
, next
, &graphics
->containers
, GraphicsContainerItem
, entry
){
1318 list_remove(&cont
->entry
);
1319 delete_container(cont
);
1322 GdipDeleteRegion(graphics
->clip
);
1323 GdipDeleteMatrix(graphics
->worldtrans
);
1329 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1330 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1332 INT save_state
, num_pts
;
1333 GpPointF points
[MAX_ARC_PTS
];
1336 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1337 width
, height
, startAngle
, sweepAngle
);
1339 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
1340 return InvalidParameter
;
1345 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1347 save_state
= prepare_dc(graphics
, pen
);
1349 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
1351 restore_dc(graphics
, save_state
);
1356 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1357 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1359 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1360 width
, height
, startAngle
, sweepAngle
);
1362 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1365 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1366 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
1372 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
1373 x2
, y2
, x3
, y3
, x4
, y4
);
1375 if(!graphics
|| !pen
)
1376 return InvalidParameter
;
1390 save_state
= prepare_dc(graphics
, pen
);
1392 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1394 restore_dc(graphics
, save_state
);
1399 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1400 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
1406 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
1407 x2
, y2
, x3
, y3
, x4
, y4
);
1409 if(!graphics
|| !pen
)
1410 return InvalidParameter
;
1424 save_state
= prepare_dc(graphics
, pen
);
1426 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1428 restore_dc(graphics
, save_state
);
1433 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
1434 GDIPCONST GpPointF
*points
, INT count
)
1439 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1441 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1442 return InvalidParameter
;
1447 for(i
= 0; i
< floor(count
/ 4); i
++){
1448 ret
= GdipDrawBezier(graphics
, pen
,
1449 points
[4*i
].X
, points
[4*i
].Y
,
1450 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
1451 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
1452 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
1460 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
1461 GDIPCONST GpPoint
*points
, INT count
)
1467 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1469 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1470 return InvalidParameter
;
1475 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
1479 for(i
= 0; i
< count
; i
++){
1480 pts
[i
].X
= (REAL
)points
[i
].X
;
1481 pts
[i
].Y
= (REAL
)points
[i
].Y
;
1484 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
1491 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
1492 GDIPCONST GpPointF
*points
, INT count
)
1494 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1496 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
1499 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1500 GDIPCONST GpPoint
*points
, INT count
)
1502 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1504 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
1507 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1508 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1513 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1515 if(!graphics
|| !pen
|| !points
|| count
<= 0)
1516 return InvalidParameter
;
1521 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
1524 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1526 GdipDeletePath(path
);
1530 stat
= GdipDrawPath(graphics
, pen
, path
);
1532 GdipDeletePath(path
);
1537 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1538 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1544 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1546 if(!points
|| count
<= 0)
1547 return InvalidParameter
;
1549 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1553 for(i
= 0; i
< count
; i
++){
1554 ptf
[i
].X
= (REAL
)points
[i
].X
;
1555 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1558 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
1565 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
1566 GDIPCONST GpPointF
*points
, INT count
)
1568 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1570 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
1573 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1574 GDIPCONST GpPoint
*points
, INT count
)
1580 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1583 return InvalidParameter
;
1585 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1589 for(i
= 0; i
< count
; i
++){
1590 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1591 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1594 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
1600 /* Approximates cardinal spline with Bezier curves. */
1601 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1602 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1604 /* PolyBezier expects count*3-2 points. */
1605 INT i
, len_pt
= count
*3-2, save_state
;
1607 REAL x1
, x2
, y1
, y2
;
1610 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1612 if(!graphics
|| !pen
)
1613 return InvalidParameter
;
1619 return InvalidParameter
;
1621 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
1625 tension
= tension
* TENSION_CONST
;
1627 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
1630 pt
[0].X
= points
[0].X
;
1631 pt
[0].Y
= points
[0].Y
;
1635 for(i
= 0; i
< count
-2; i
++){
1636 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
1640 pt
[3*i
+3].X
= points
[i
+1].X
;
1641 pt
[3*i
+3].Y
= points
[i
+1].Y
;
1646 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
1647 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
1649 pt
[len_pt
-2].X
= x1
;
1650 pt
[len_pt
-2].Y
= y1
;
1651 pt
[len_pt
-1].X
= points
[count
-1].X
;
1652 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
1654 save_state
= prepare_dc(graphics
, pen
);
1656 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
1659 restore_dc(graphics
, save_state
);
1664 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1665 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1671 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1674 return InvalidParameter
;
1676 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1680 for(i
= 0; i
< count
; i
++){
1681 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1682 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1685 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
1691 GpStatus WINGDIPAPI
GdipDrawCurve3(GpGraphics
*graphics
, GpPen
*pen
,
1692 GDIPCONST GpPointF
*points
, INT count
, INT offset
, INT numberOfSegments
,
1695 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1697 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1698 return InvalidParameter
;
1701 return GdipDrawCurve2(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1704 GpStatus WINGDIPAPI
GdipDrawCurve3I(GpGraphics
*graphics
, GpPen
*pen
,
1705 GDIPCONST GpPoint
*points
, INT count
, INT offset
, INT numberOfSegments
,
1708 TRACE("(%p, %p, %p, %d, %d, %d, %.2f)\n", graphics
, pen
, points
, count
, offset
, numberOfSegments
, tension
);
1714 if(offset
>= count
|| numberOfSegments
> count
- offset
- 1 || numberOfSegments
<= 0){
1715 return InvalidParameter
;
1718 return GdipDrawCurve2I(graphics
, pen
, points
+ offset
, numberOfSegments
+ 1, tension
);
1721 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1722 REAL y
, REAL width
, REAL height
)
1728 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1730 if(!graphics
|| !pen
)
1731 return InvalidParameter
;
1738 ptf
[1].X
= x
+ width
;
1739 ptf
[1].Y
= y
+ height
;
1741 save_state
= prepare_dc(graphics
, pen
);
1742 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1744 transform_and_round_points(graphics
, pti
, ptf
, 2);
1746 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1748 restore_dc(graphics
, save_state
);
1753 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1754 INT y
, INT width
, INT height
)
1756 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1758 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1762 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
1767 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
1769 if(!graphics
|| !image
)
1770 return InvalidParameter
;
1772 GdipGetImageWidth(image
, &width
);
1773 GdipGetImageHeight(image
, &height
);
1775 /* FIXME: we should use the graphics and image dpi, somehow */
1777 points
[0].X
= points
[2].X
= x
;
1778 points
[0].Y
= points
[1].Y
= y
;
1779 points
[1].X
= x
+ width
;
1780 points
[2].Y
= y
+ height
;
1782 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, 0, 0, width
, height
,
1783 UnitPixel
, NULL
, NULL
, NULL
);
1786 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
1789 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
1791 return GdipDrawImage(graphics
, image
, (REAL
)x
, (REAL
)y
);
1794 GpStatus WINGDIPAPI
GdipDrawImagePointRect(GpGraphics
*graphics
, GpImage
*image
,
1795 REAL x
, REAL y
, REAL srcx
, REAL srcy
, REAL srcwidth
, REAL srcheight
,
1798 FIXME("(%p, %p, %f, %f, %f, %f, %f, %f, %d): stub\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
1799 return NotImplemented
;
1802 GpStatus WINGDIPAPI
GdipDrawImagePointRectI(GpGraphics
*graphics
, GpImage
*image
,
1803 INT x
, INT y
, INT srcx
, INT srcy
, INT srcwidth
, INT srcheight
,
1806 FIXME("(%p, %p, %d, %d, %d, %d, %d, %d, %d): stub\n", graphics
, image
, x
, y
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
);
1807 return NotImplemented
;
1810 GpStatus WINGDIPAPI
GdipDrawImagePoints(GpGraphics
*graphics
, GpImage
*image
,
1811 GDIPCONST GpPointF
*dstpoints
, INT count
)
1813 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
1814 return NotImplemented
;
1817 GpStatus WINGDIPAPI
GdipDrawImagePointsI(GpGraphics
*graphics
, GpImage
*image
,
1818 GDIPCONST GpPoint
*dstpoints
, INT count
)
1820 FIXME("(%p, %p, %p, %d): stub\n", graphics
, image
, dstpoints
, count
);
1821 return NotImplemented
;
1824 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1825 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
1826 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
1827 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1828 DrawImageAbort callback
, VOID
* callbackData
)
1834 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
1835 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1838 if(!graphics
|| !image
|| !points
|| count
!= 3)
1839 return InvalidParameter
;
1841 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
1842 transform_and_round_points(graphics
, pti
, ptf
, 3);
1846 if(srcUnit
== UnitInch
)
1847 dx
= dy
= (REAL
) INCH_HIMETRIC
;
1848 else if(srcUnit
== UnitPixel
){
1849 dx
= ((REAL
) INCH_HIMETRIC
) /
1850 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
1851 dy
= ((REAL
) INCH_HIMETRIC
) /
1852 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
1855 return NotImplemented
;
1857 /* IPicture renders bitmaps with the y-axis reversed
1858 * FIXME: flipping for unknown image type might not be correct. */
1859 if(image
->type
!= ImageTypeMetafile
){
1862 pti
[0].y
= pti
[2].y
;
1866 if(IPicture_Render(image
->picture
, graphics
->hdc
,
1867 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
1868 srcx
* dx
, srcy
* dy
,
1869 srcwidth
* dx
, srcheight
* dy
,
1872 callback(callbackData
);
1873 return GenericError
;
1876 else if (image
->type
== ImageTypeBitmap
&& ((GpBitmap
*)image
)->hbitmap
)
1879 GpBitmap
* bitmap
= (GpBitmap
*)image
;
1880 int temp_hdc
=0, temp_bitmap
=0;
1881 HBITMAP hbitmap
, old_hbm
=NULL
;
1883 if (srcUnit
== UnitInch
)
1884 dx
= dy
= 96.0; /* FIXME: use the image resolution */
1885 else if (srcUnit
== UnitPixel
)
1888 return NotImplemented
;
1890 if (bitmap
->format
== PixelFormat32bppARGB
)
1892 BITMAPINFOHEADER bih
;
1895 /* we need a bitmap with premultiplied alpha */
1896 hdc
= CreateCompatibleDC(0);
1900 bih
.biSize
= sizeof(BITMAPINFOHEADER
);
1901 bih
.biWidth
= bitmap
->width
;
1902 bih
.biHeight
= -bitmap
->height
;
1904 bih
.biBitCount
= 32;
1905 bih
.biCompression
= BI_RGB
;
1906 bih
.biSizeImage
= 0;
1907 bih
.biXPelsPerMeter
= 0;
1908 bih
.biYPelsPerMeter
= 0;
1910 bih
.biClrImportant
= 0;
1912 hbitmap
= CreateDIBSection(hdc
, (BITMAPINFO
*)&bih
, DIB_RGB_COLORS
,
1913 (void**)&temp_bits
, NULL
, 0);
1915 convert_32bppARGB_to_32bppPARGB(bitmap
->width
, bitmap
->height
,
1916 temp_bits
, bitmap
->width
*4, bitmap
->bits
, bitmap
->stride
);
1920 hbitmap
= bitmap
->hbitmap
;
1922 temp_hdc
= (hdc
== 0);
1927 if (!hdc
) hdc
= CreateCompatibleDC(0);
1928 old_hbm
= SelectObject(hdc
, hbitmap
);
1931 if (bitmap
->format
== PixelFormat32bppARGB
|| bitmap
->format
== PixelFormat32bppPARGB
)
1935 bf
.BlendOp
= AC_SRC_OVER
;
1937 bf
.SourceConstantAlpha
= 255;
1938 bf
.AlphaFormat
= AC_SRC_ALPHA
;
1940 GdiAlphaBlend(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
1941 hdc
, srcx
*dx
, srcy
*dy
, srcwidth
*dx
, srcheight
*dy
, bf
);
1945 StretchBlt(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
-pti
[0].x
, pti
[2].y
-pti
[0].y
,
1946 hdc
, srcx
*dx
, srcy
*dy
, srcwidth
*dx
, srcheight
*dy
, SRCCOPY
);
1951 SelectObject(hdc
, old_hbm
);
1956 DeleteObject(hbitmap
);
1960 ERR("GpImage with no IPicture or HBITMAP?!\n");
1961 return NotImplemented
;
1967 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
1968 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
1969 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1970 DrawImageAbort callback
, VOID
* callbackData
)
1972 GpPointF pointsF
[3];
1975 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
1976 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1979 if(!points
|| count
!=3)
1980 return InvalidParameter
;
1982 for(i
= 0; i
< count
; i
++){
1983 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1984 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1987 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
1988 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
1989 callback
, callbackData
);
1992 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
1993 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
1994 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
1995 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
1996 VOID
* callbackData
)
2000 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
2001 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2002 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2006 points
[1].X
= dstx
+ dstwidth
;
2009 points
[2].Y
= dsty
+ dstheight
;
2011 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2012 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
2015 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
2016 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
2017 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
2018 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
2019 VOID
* callbackData
)
2023 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
2024 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
2025 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2029 points
[1].X
= dstx
+ dstwidth
;
2032 points
[2].Y
= dsty
+ dstheight
;
2034 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
2035 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
2038 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
2039 REAL x
, REAL y
, REAL width
, REAL height
)
2045 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
2047 if(!graphics
|| !image
)
2048 return InvalidParameter
;
2050 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
2054 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
2055 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
2056 unit
, NULL
, NULL
, NULL
);
2059 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
2060 INT x
, INT y
, INT width
, INT height
)
2062 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
2064 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
2067 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
2068 REAL y1
, REAL x2
, REAL y2
)
2074 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2076 if(!pen
|| !graphics
)
2077 return InvalidParameter
;
2087 save_state
= prepare_dc(graphics
, pen
);
2089 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2091 restore_dc(graphics
, save_state
);
2096 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
2097 INT y1
, INT x2
, INT y2
)
2103 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
2105 if(!pen
|| !graphics
)
2106 return InvalidParameter
;
2116 save_state
= prepare_dc(graphics
, pen
);
2118 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
2120 restore_dc(graphics
, save_state
);
2125 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2126 GpPointF
*points
, INT count
)
2131 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2133 if(!pen
|| !graphics
|| (count
< 2))
2134 return InvalidParameter
;
2139 save_state
= prepare_dc(graphics
, pen
);
2141 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
2143 restore_dc(graphics
, save_state
);
2148 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
2149 GpPoint
*points
, INT count
)
2153 GpPointF
*ptf
= NULL
;
2156 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
2158 if(!pen
|| !graphics
|| (count
< 2))
2159 return InvalidParameter
;
2164 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2165 if(!ptf
) return OutOfMemory
;
2167 for(i
= 0; i
< count
; i
++){
2168 ptf
[i
].X
= (REAL
) points
[i
].X
;
2169 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2172 save_state
= prepare_dc(graphics
, pen
);
2174 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
2176 restore_dc(graphics
, save_state
);
2182 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
2187 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
2189 if(!pen
|| !graphics
)
2190 return InvalidParameter
;
2195 save_state
= prepare_dc(graphics
, pen
);
2197 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
2198 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
2200 restore_dc(graphics
, save_state
);
2205 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2206 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2210 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2211 width
, height
, startAngle
, sweepAngle
);
2213 if(!graphics
|| !pen
)
2214 return InvalidParameter
;
2219 save_state
= prepare_dc(graphics
, pen
);
2220 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2222 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2224 restore_dc(graphics
, save_state
);
2229 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2230 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2232 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
2233 width
, height
, startAngle
, sweepAngle
);
2235 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2238 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
2239 REAL y
, REAL width
, REAL height
)
2245 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
2247 if(!pen
|| !graphics
)
2248 return InvalidParameter
;
2255 ptf
[1].X
= x
+ width
;
2257 ptf
[2].X
= x
+ width
;
2258 ptf
[2].Y
= y
+ height
;
2260 ptf
[3].Y
= y
+ height
;
2262 save_state
= prepare_dc(graphics
, pen
);
2263 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2265 transform_and_round_points(graphics
, pti
, ptf
, 4);
2266 Polygon(graphics
->hdc
, pti
, 4);
2268 restore_dc(graphics
, save_state
);
2273 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
2274 INT y
, INT width
, INT height
)
2276 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
2278 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2281 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
2282 GDIPCONST GpRectF
* rects
, INT count
)
2288 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2290 if(!graphics
|| !pen
|| !rects
|| count
< 1)
2291 return InvalidParameter
;
2296 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
2297 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
2305 for(i
= 0; i
< count
; i
++){
2306 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
2307 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
2308 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
2309 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
2312 save_state
= prepare_dc(graphics
, pen
);
2313 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
2315 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
2317 for(i
= 0; i
< count
; i
++)
2318 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
2320 restore_dc(graphics
, save_state
);
2328 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
2329 GDIPCONST GpRect
* rects
, INT count
)
2335 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
2337 if(!rects
|| count
<=0)
2338 return InvalidParameter
;
2340 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
2344 for(i
= 0;i
< count
;i
++){
2345 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2346 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2347 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
2348 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2351 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
2357 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
2358 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
2359 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
2364 TEXTMETRICW textmet
;
2365 GpPointF pt
[2], rectcpy
[4];
2368 REAL angle
, ang_cos
, ang_sin
, rel_width
, rel_height
;
2369 INT sum
= 0, height
= 0, offsety
= 0, fit
, fitcpy
, save_state
, i
, j
, lret
, nwidth
,
2376 TRACE("(%p, %s, %i, %p, %s, %p, %p)\n", graphics
, debugstr_wn(string
, length
),
2377 length
, font
, debugstr_rectf(rect
), format
, brush
);
2379 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
2380 return InvalidParameter
;
2382 if((brush
->bt
!= BrushTypeSolidColor
)){
2383 FIXME("not implemented for given parameters\n");
2384 return NotImplemented
;
2388 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
2390 /* Should be no need to explicitly test for StringAlignmentNear as
2391 * that is default behavior if no alignment is passed. */
2392 if(format
->vertalign
!= StringAlignmentNear
){
2394 GdipMeasureString(graphics
, string
, length
, font
, rect
, format
, &bounds
, 0, 0);
2396 if(format
->vertalign
== StringAlignmentCenter
)
2397 offsety
= (rect
->Height
- bounds
.Height
) / 2;
2398 else if(format
->vertalign
== StringAlignmentFar
)
2399 offsety
= (rect
->Height
- bounds
.Height
);
2403 if(length
== -1) length
= lstrlenW(string
);
2405 stringdup
= GdipAlloc(length
* sizeof(WCHAR
));
2406 if(!stringdup
) return OutOfMemory
;
2408 save_state
= SaveDC(graphics
->hdc
);
2409 SetBkMode(graphics
->hdc
, TRANSPARENT
);
2410 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
2412 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
2413 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
+ offsety
;
2414 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
2415 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ offsety
+ rect
->Height
;
2416 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
2418 if (roundr(rect
->Width
) == 0)
2425 rel_width
= sqrt((corners
[1].x
- corners
[0].x
) * (corners
[1].x
- corners
[0].x
) +
2426 (corners
[1].y
- corners
[0].y
) * (corners
[1].y
- corners
[0].y
))
2428 nwidth
= roundr(rel_width
* rect
->Width
);
2431 if (roundr(rect
->Height
) == 0)
2438 rel_height
= sqrt((corners
[2].x
- corners
[1].x
) * (corners
[2].x
- corners
[1].x
) +
2439 (corners
[2].y
- corners
[1].y
) * (corners
[2].y
- corners
[1].y
))
2441 nheight
= roundr(rel_height
* rect
->Height
);
2444 if (roundr(rect
->Width
) != 0 && roundr(rect
->Height
) != 0)
2446 /* FIXME: If only the width or only the height is 0, we should probably still clip */
2447 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
2448 SelectClipRgn(graphics
->hdc
, rgn
);
2451 /* Use gdi to find the font, then perform transformations on it (height,
2453 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
2454 GetTextMetricsW(graphics
->hdc
, &textmet
);
2457 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
2458 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
2464 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
2465 angle
= -gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2466 ang_cos
= cos(angle
);
2467 ang_sin
= sin(angle
);
2468 lfw
.lfEscapement
= lfw
.lfOrientation
= roundr((angle
/ M_PI
) * 1800.0);
2470 gdifont
= CreateFontIndirectW(&lfw
);
2471 DeleteObject(SelectObject(graphics
->hdc
, CreateFontIndirectW(&lfw
)));
2473 for(i
= 0, j
= 0; i
< length
; i
++){
2474 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
2477 stringdup
[j
] = string
[i
];
2483 if (!format
|| format
->align
== StringAlignmentNear
)
2485 drawbase
.x
= corners
[0].x
;
2486 drawbase
.y
= corners
[0].y
;
2487 drawflags
= DT_NOCLIP
| DT_EXPANDTABS
;
2489 else if (format
->align
== StringAlignmentCenter
)
2491 drawbase
.x
= (corners
[0].x
+ corners
[1].x
)/2;
2492 drawbase
.y
= (corners
[0].y
+ corners
[1].y
)/2;
2493 drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_CENTER
;
2495 else /* (format->align == StringAlignmentFar) */
2497 drawbase
.x
= corners
[1].x
;
2498 drawbase
.y
= corners
[1].y
;
2499 drawflags
= DT_NOCLIP
| DT_EXPANDTABS
| DT_RIGHT
;
2502 while(sum
< length
){
2503 drawcoord
.left
= drawcoord
.right
= drawbase
.x
+ roundr(ang_sin
* (REAL
) height
);
2504 drawcoord
.top
= drawcoord
.bottom
= drawbase
.y
+ roundr(ang_cos
* (REAL
) height
);
2506 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
2507 nwidth
, &fit
, NULL
, &size
);
2511 DrawTextW(graphics
->hdc
, stringdup
+ sum
, 1, &drawcoord
, drawflags
);
2515 for(lret
= 0; lret
< fit
; lret
++)
2516 if(*(stringdup
+ sum
+ lret
) == '\n')
2519 /* Line break code (may look strange, but it imitates windows). */
2521 lineend
= fit
= lret
; /* this is not an off-by-one error */
2522 else if(fit
< (length
- sum
)){
2523 if(*(stringdup
+ sum
+ fit
) == ' ')
2524 while(*(stringdup
+ sum
+ fit
) == ' ')
2527 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
2530 if(*(stringdup
+ sum
+ fit
) == '\t')
2539 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
2540 *(stringdup
+ sum
+ lineend
- 1) == '\t')
2545 DrawTextW(graphics
->hdc
, stringdup
+ sum
, min(length
- sum
, lineend
),
2546 &drawcoord
, drawflags
);
2548 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
2551 if(height
> nheight
)
2554 /* Stop if this was a linewrap (but not if it was a linebreak). */
2555 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
2559 GdipFree(stringdup
);
2561 DeleteObject(gdifont
);
2563 RestoreDC(graphics
->hdc
, save_state
);
2568 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
2569 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
2574 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2575 count
, tension
, fill
);
2577 if(!graphics
|| !brush
|| !points
)
2578 return InvalidParameter
;
2583 stat
= GdipCreatePath(fill
, &path
);
2587 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2589 GdipDeletePath(path
);
2593 stat
= GdipFillPath(graphics
, brush
, path
);
2595 GdipDeletePath(path
);
2599 GdipDeletePath(path
);
2604 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
2605 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
2611 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2612 count
, tension
, fill
);
2614 if(!points
|| count
<= 0)
2615 return InvalidParameter
;
2617 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2621 for(i
= 0;i
< count
;i
++){
2622 ptf
[i
].X
= (REAL
)points
[i
].X
;
2623 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2626 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
2633 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2634 REAL y
, REAL width
, REAL height
)
2640 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2642 if(!graphics
|| !brush
)
2643 return InvalidParameter
;
2650 ptf
[1].X
= x
+ width
;
2651 ptf
[1].Y
= y
+ height
;
2653 save_state
= SaveDC(graphics
->hdc
);
2654 EndPath(graphics
->hdc
);
2656 transform_and_round_points(graphics
, pti
, ptf
, 2);
2658 BeginPath(graphics
->hdc
);
2659 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2660 EndPath(graphics
->hdc
);
2662 brush_fill_path(graphics
, brush
);
2664 RestoreDC(graphics
->hdc
, save_state
);
2669 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2670 INT y
, INT width
, INT height
)
2672 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2674 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2677 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
2682 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
2684 if(!brush
|| !graphics
|| !path
)
2685 return InvalidParameter
;
2690 save_state
= SaveDC(graphics
->hdc
);
2691 EndPath(graphics
->hdc
);
2692 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
2695 BeginPath(graphics
->hdc
);
2696 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2697 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2702 EndPath(graphics
->hdc
);
2703 brush_fill_path(graphics
, brush
);
2708 RestoreDC(graphics
->hdc
, save_state
);
2713 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2714 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2718 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2719 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2721 if(!graphics
|| !brush
)
2722 return InvalidParameter
;
2727 save_state
= SaveDC(graphics
->hdc
);
2728 EndPath(graphics
->hdc
);
2730 BeginPath(graphics
->hdc
);
2731 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2732 EndPath(graphics
->hdc
);
2734 brush_fill_path(graphics
, brush
);
2736 RestoreDC(graphics
->hdc
, save_state
);
2741 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2742 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2744 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2745 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2747 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2750 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
2751 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
2754 GpPointF
*ptf
= NULL
;
2756 GpStatus retval
= Ok
;
2758 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2760 if(!graphics
|| !brush
|| !points
|| !count
)
2761 return InvalidParameter
;
2766 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2767 pti
= GdipAlloc(count
* sizeof(POINT
));
2769 retval
= OutOfMemory
;
2773 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
2775 save_state
= SaveDC(graphics
->hdc
);
2776 EndPath(graphics
->hdc
);
2777 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2780 transform_and_round_points(graphics
, pti
, ptf
, count
);
2782 BeginPath(graphics
->hdc
);
2783 Polygon(graphics
->hdc
, pti
, count
);
2784 EndPath(graphics
->hdc
);
2786 brush_fill_path(graphics
, brush
);
2788 RestoreDC(graphics
->hdc
, save_state
);
2797 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
2798 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
2801 GpPointF
*ptf
= NULL
;
2803 GpStatus retval
= Ok
;
2805 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2807 if(!graphics
|| !brush
|| !points
|| !count
)
2808 return InvalidParameter
;
2813 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2814 pti
= GdipAlloc(count
* sizeof(POINT
));
2816 retval
= OutOfMemory
;
2820 for(i
= 0; i
< count
; i
++){
2821 ptf
[i
].X
= (REAL
) points
[i
].X
;
2822 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2825 save_state
= SaveDC(graphics
->hdc
);
2826 EndPath(graphics
->hdc
);
2827 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2830 transform_and_round_points(graphics
, pti
, ptf
, count
);
2832 BeginPath(graphics
->hdc
);
2833 Polygon(graphics
->hdc
, pti
, count
);
2834 EndPath(graphics
->hdc
);
2836 brush_fill_path(graphics
, brush
);
2838 RestoreDC(graphics
->hdc
, save_state
);
2847 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
2848 GDIPCONST GpPointF
*points
, INT count
)
2850 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2852 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
2855 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
2856 GDIPCONST GpPoint
*points
, INT count
)
2858 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2860 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
2863 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
2864 REAL x
, REAL y
, REAL width
, REAL height
)
2870 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2872 if(!graphics
|| !brush
)
2873 return InvalidParameter
;
2880 ptf
[1].X
= x
+ width
;
2882 ptf
[2].X
= x
+ width
;
2883 ptf
[2].Y
= y
+ height
;
2885 ptf
[3].Y
= y
+ height
;
2887 save_state
= SaveDC(graphics
->hdc
);
2888 EndPath(graphics
->hdc
);
2890 transform_and_round_points(graphics
, pti
, ptf
, 4);
2892 BeginPath(graphics
->hdc
);
2893 Polygon(graphics
->hdc
, pti
, 4);
2894 EndPath(graphics
->hdc
);
2896 brush_fill_path(graphics
, brush
);
2898 RestoreDC(graphics
->hdc
, save_state
);
2903 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
2904 INT x
, INT y
, INT width
, INT height
)
2910 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2912 if(!graphics
|| !brush
)
2913 return InvalidParameter
;
2920 ptf
[1].X
= x
+ width
;
2922 ptf
[2].X
= x
+ width
;
2923 ptf
[2].Y
= y
+ height
;
2925 ptf
[3].Y
= y
+ height
;
2927 save_state
= SaveDC(graphics
->hdc
);
2928 EndPath(graphics
->hdc
);
2930 transform_and_round_points(graphics
, pti
, ptf
, 4);
2932 BeginPath(graphics
->hdc
);
2933 Polygon(graphics
->hdc
, pti
, 4);
2934 EndPath(graphics
->hdc
);
2936 brush_fill_path(graphics
, brush
);
2938 RestoreDC(graphics
->hdc
, save_state
);
2943 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
2949 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2952 return InvalidParameter
;
2954 for(i
= 0; i
< count
; i
++){
2955 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
2956 if(ret
!= Ok
) return ret
;
2962 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
2969 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2971 if(!rects
|| count
<= 0)
2972 return InvalidParameter
;
2974 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
2978 for(i
= 0; i
< count
; i
++){
2979 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2980 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2981 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
2982 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2985 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
2991 /*****************************************************************************
2992 * GdipFillRegion [GDIPLUS.@]
2994 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
3002 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
3004 if (!(graphics
&& brush
&& region
))
3005 return InvalidParameter
;
3010 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
3014 save_state
= SaveDC(graphics
->hdc
);
3015 EndPath(graphics
->hdc
);
3017 ExtSelectClipRgn(graphics
->hdc
, hrgn
, RGN_AND
);
3019 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
3021 BeginPath(graphics
->hdc
);
3022 Rectangle(graphics
->hdc
, rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
3023 EndPath(graphics
->hdc
);
3025 brush_fill_path(graphics
, brush
);
3028 RestoreDC(graphics
->hdc
, save_state
);
3035 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
3040 return InvalidParameter
;
3046 FIXME("not implemented\n");
3048 return NotImplemented
;
3051 /*****************************************************************************
3052 * GdipGetClipBounds [GDIPLUS.@]
3054 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
3056 TRACE("(%p, %p)\n", graphics
, rect
);
3059 return InvalidParameter
;
3064 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
3067 /*****************************************************************************
3068 * GdipGetClipBoundsI [GDIPLUS.@]
3070 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
3072 TRACE("(%p, %p)\n", graphics
, rect
);
3075 return InvalidParameter
;
3080 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
3083 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
3084 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
3085 CompositingMode
*mode
)
3087 TRACE("(%p, %p)\n", graphics
, mode
);
3089 if(!graphics
|| !mode
)
3090 return InvalidParameter
;
3095 *mode
= graphics
->compmode
;
3100 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
3101 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
3102 CompositingQuality
*quality
)
3104 TRACE("(%p, %p)\n", graphics
, quality
);
3106 if(!graphics
|| !quality
)
3107 return InvalidParameter
;
3112 *quality
= graphics
->compqual
;
3117 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
3118 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
3119 InterpolationMode
*mode
)
3121 TRACE("(%p, %p)\n", graphics
, mode
);
3123 if(!graphics
|| !mode
)
3124 return InvalidParameter
;
3129 *mode
= graphics
->interpolation
;
3134 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
3136 if(!graphics
|| !argb
)
3137 return InvalidParameter
;
3142 FIXME("(%p, %p): stub\n", graphics
, argb
);
3144 return NotImplemented
;
3147 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
3149 TRACE("(%p, %p)\n", graphics
, scale
);
3151 if(!graphics
|| !scale
)
3152 return InvalidParameter
;
3157 *scale
= graphics
->scale
;
3162 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
3164 TRACE("(%p, %p)\n", graphics
, unit
);
3166 if(!graphics
|| !unit
)
3167 return InvalidParameter
;
3172 *unit
= graphics
->unit
;
3177 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
3178 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3181 TRACE("(%p, %p)\n", graphics
, mode
);
3183 if(!graphics
|| !mode
)
3184 return InvalidParameter
;
3189 *mode
= graphics
->pixeloffset
;
3194 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
3195 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
3197 TRACE("(%p, %p)\n", graphics
, mode
);
3199 if(!graphics
|| !mode
)
3200 return InvalidParameter
;
3205 *mode
= graphics
->smoothing
;
3210 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
3212 TRACE("(%p, %p)\n", graphics
, contrast
);
3214 if(!graphics
|| !contrast
)
3215 return InvalidParameter
;
3217 *contrast
= graphics
->textcontrast
;
3222 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
3223 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
3224 TextRenderingHint
*hint
)
3226 TRACE("(%p, %p)\n", graphics
, hint
);
3228 if(!graphics
|| !hint
)
3229 return InvalidParameter
;
3234 *hint
= graphics
->texthint
;
3239 GpStatus WINGDIPAPI
GdipGetVisibleClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
3244 TRACE("(%p, %p)\n", graphics
, rect
);
3246 if(!graphics
|| !rect
)
3247 return InvalidParameter
;
3252 /* intersect window and graphics clipping regions */
3253 if((stat
= GdipCreateRegion(&clip_rgn
)) != Ok
)
3256 if((stat
= get_visible_clip_region(graphics
, clip_rgn
)) != Ok
)
3259 /* get bounds of the region */
3260 stat
= GdipGetRegionBounds(clip_rgn
, graphics
, rect
);
3263 GdipDeleteRegion(clip_rgn
);
3268 GpStatus WINGDIPAPI
GdipGetVisibleClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
3273 TRACE("(%p, %p)\n", graphics
, rect
);
3275 if(!graphics
|| !rect
)
3276 return InvalidParameter
;
3278 if((stat
= GdipGetVisibleClipBounds(graphics
, &rectf
)) == Ok
)
3280 rect
->X
= roundr(rectf
.X
);
3281 rect
->Y
= roundr(rectf
.Y
);
3282 rect
->Width
= roundr(rectf
.Width
);
3283 rect
->Height
= roundr(rectf
.Height
);
3289 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3291 TRACE("(%p, %p)\n", graphics
, matrix
);
3293 if(!graphics
|| !matrix
)
3294 return InvalidParameter
;
3299 *matrix
= *graphics
->worldtrans
;
3303 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
3309 TRACE("(%p, %x)\n", graphics
, color
);
3312 return InvalidParameter
;
3317 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
3320 if((stat
= get_graphics_bounds(graphics
, &wnd_rect
)) != Ok
){
3321 GdipDeleteBrush((GpBrush
*)brush
);
3325 GdipFillRectangle(graphics
, (GpBrush
*)brush
, wnd_rect
.X
, wnd_rect
.Y
,
3326 wnd_rect
.Width
, wnd_rect
.Height
);
3328 GdipDeleteBrush((GpBrush
*)brush
);
3333 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
3335 TRACE("(%p, %p)\n", graphics
, res
);
3337 if(!graphics
|| !res
)
3338 return InvalidParameter
;
3340 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
3343 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
3349 TRACE("(%p, %.2f, %.2f, %p)\n", graphics
, x
, y
, result
);
3351 if(!graphics
|| !result
)
3352 return InvalidParameter
;
3359 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
3360 CoordinateSpaceWorld
, &pt
, 1)) != Ok
)
3363 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
3366 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
3369 stat
= GdipIsVisibleRegionPoint(rgn
, pt
.X
, pt
.Y
, graphics
, result
);
3372 GdipDeleteRegion(rgn
);
3376 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
3378 return GdipIsVisiblePoint(graphics
, (REAL
)x
, (REAL
)y
, result
);
3381 GpStatus WINGDIPAPI
GdipIsVisibleRect(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
, REAL height
, BOOL
*result
)
3387 TRACE("(%p %.2f %.2f %.2f %.2f %p)\n", graphics
, x
, y
, width
, height
, result
);
3389 if(!graphics
|| !result
)
3390 return InvalidParameter
;
3397 pts
[1].X
= x
+ width
;
3398 pts
[1].Y
= y
+ height
;
3400 if((stat
= GdipTransformPoints(graphics
, CoordinateSpaceDevice
,
3401 CoordinateSpaceWorld
, pts
, 2)) != Ok
)
3404 pts
[1].X
-= pts
[0].X
;
3405 pts
[1].Y
-= pts
[0].Y
;
3407 if((stat
= GdipCreateRegion(&rgn
)) != Ok
)
3410 if((stat
= get_visible_clip_region(graphics
, rgn
)) != Ok
)
3413 stat
= GdipIsVisibleRegionRect(rgn
, pts
[0].X
, pts
[0].Y
, pts
[1].X
, pts
[1].Y
, graphics
, result
);
3416 GdipDeleteRegion(rgn
);
3420 GpStatus WINGDIPAPI
GdipIsVisibleRectI(GpGraphics
*graphics
, INT x
, INT y
, INT width
, INT height
, BOOL
*result
)
3422 return GdipIsVisibleRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, result
);
3425 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
3426 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
3427 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
3428 INT regionCount
, GpRegion
** regions
)
3430 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
3431 return InvalidParameter
;
3433 FIXME("stub: %p %s %d %p %p %p %d %p\n", graphics
, debugstr_w(string
),
3434 length
, font
, layoutRect
, stringFormat
, regionCount
, regions
);
3436 return NotImplemented
;
3439 /* Find the smallest rectangle that bounds the text when it is printed in rect
3440 * according to the format options listed in format. If rect has 0 width and
3441 * height, then just find the smallest rectangle that bounds the text when it's
3442 * printed at location (rect->X, rect-Y). */
3443 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
3444 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
3445 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
3446 INT
*codepointsfitted
, INT
*linesfilled
)
3450 INT sum
= 0, height
= 0, fit
, fitcpy
, max_width
= 0, i
, j
, lret
, nwidth
,
3454 TRACE("(%p, %s, %i, %p, %s, %p, %p, %p, %p)\n", graphics
,
3455 debugstr_wn(string
, length
), length
, font
, debugstr_rectf(rect
), format
,
3456 bounds
, codepointsfitted
, linesfilled
);
3458 if(!graphics
|| !string
|| !font
|| !rect
)
3459 return InvalidParameter
;
3461 if(linesfilled
) *linesfilled
= 0;
3462 if(codepointsfitted
) *codepointsfitted
= 0;
3465 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
3467 if(length
== -1) length
= lstrlenW(string
);
3469 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
3470 if(!stringdup
) return OutOfMemory
;
3472 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
3473 nwidth
= roundr(rect
->Width
);
3474 nheight
= roundr(rect
->Height
);
3476 if((nwidth
== 0) && (nheight
== 0))
3477 nwidth
= nheight
= INT_MAX
;
3479 for(i
= 0, j
= 0; i
< length
; i
++){
3480 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
3483 stringdup
[j
] = string
[i
];
3490 while(sum
< length
){
3491 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
3492 nwidth
, &fit
, NULL
, &size
);
3498 for(lret
= 0; lret
< fit
; lret
++)
3499 if(*(stringdup
+ sum
+ lret
) == '\n')
3502 /* Line break code (may look strange, but it imitates windows). */
3504 lineend
= fit
= lret
; /* this is not an off-by-one error */
3505 else if(fit
< (length
- sum
)){
3506 if(*(stringdup
+ sum
+ fit
) == ' ')
3507 while(*(stringdup
+ sum
+ fit
) == ' ')
3510 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
3513 if(*(stringdup
+ sum
+ fit
) == '\t')
3522 while(*(stringdup
+ sum
+ lineend
- 1) == ' ' ||
3523 *(stringdup
+ sum
+ lineend
- 1) == '\t')
3529 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, lineend
,
3530 nwidth
, &j
, NULL
, &size
);
3532 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
3533 if(codepointsfitted
) *codepointsfitted
= sum
;
3536 if(linesfilled
) *linesfilled
+= size
.cy
;
3537 max_width
= max(max_width
, size
.cx
);
3539 if(height
> nheight
)
3542 /* Stop if this was a linewrap (but not if it was a linebreak). */
3543 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
3547 bounds
->X
= rect
->X
;
3548 bounds
->Y
= rect
->Y
;
3549 bounds
->Width
= (REAL
)max_width
;
3550 bounds
->Height
= (REAL
) min(height
, nheight
);
3552 GdipFree(stringdup
);
3553 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
3558 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
3560 TRACE("(%p)\n", graphics
);
3563 return InvalidParameter
;
3568 return GdipSetInfinite(graphics
->clip
);
3571 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
3573 TRACE("(%p)\n", graphics
);
3576 return InvalidParameter
;
3581 graphics
->worldtrans
->matrix
[0] = 1.0;
3582 graphics
->worldtrans
->matrix
[1] = 0.0;
3583 graphics
->worldtrans
->matrix
[2] = 0.0;
3584 graphics
->worldtrans
->matrix
[3] = 1.0;
3585 graphics
->worldtrans
->matrix
[4] = 0.0;
3586 graphics
->worldtrans
->matrix
[5] = 0.0;
3591 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
3593 return GdipEndContainer(graphics
, state
);
3596 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
3597 GpMatrixOrder order
)
3599 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
3602 return InvalidParameter
;
3607 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
3610 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
3612 return GdipBeginContainer2(graphics
, state
);
3615 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
,
3616 GraphicsContainer
*state
)
3618 GraphicsContainerItem
*container
;
3621 TRACE("(%p, %p)\n", graphics
, state
);
3623 if(!graphics
|| !state
)
3624 return InvalidParameter
;
3626 sts
= init_container(&container
, graphics
);
3630 list_add_head(&graphics
->containers
, &container
->entry
);
3631 *state
= graphics
->contid
= container
->contid
;
3636 GpStatus WINGDIPAPI
GdipBeginContainer(GpGraphics
*graphics
, GDIPCONST GpRectF
*dstrect
, GDIPCONST GpRectF
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
3638 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
3639 return NotImplemented
;
3642 GpStatus WINGDIPAPI
GdipBeginContainerI(GpGraphics
*graphics
, GDIPCONST GpRect
*dstrect
, GDIPCONST GpRect
*srcrect
, GpUnit unit
, GraphicsContainer
*state
)
3644 FIXME("(%p, %p, %p, %d, %p): stub\n", graphics
, dstrect
, srcrect
, unit
, state
);
3645 return NotImplemented
;
3648 GpStatus WINGDIPAPI
GdipComment(GpGraphics
*graphics
, UINT sizeData
, GDIPCONST BYTE
*data
)
3650 FIXME("(%p, %d, %p): stub\n", graphics
, sizeData
, data
);
3651 return NotImplemented
;
3654 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsContainer state
)
3657 GraphicsContainerItem
*container
, *container2
;
3659 TRACE("(%p, %x)\n", graphics
, state
);
3662 return InvalidParameter
;
3664 LIST_FOR_EACH_ENTRY(container
, &graphics
->containers
, GraphicsContainerItem
, entry
){
3665 if(container
->contid
== state
)
3669 /* did not find a matching container */
3670 if(&container
->entry
== &graphics
->containers
)
3673 sts
= restore_container(graphics
, container
);
3677 /* remove all of the containers on top of the found container */
3678 LIST_FOR_EACH_ENTRY_SAFE(container
, container2
, &graphics
->containers
, GraphicsContainerItem
, entry
){
3679 if(container
->contid
== state
)
3681 list_remove(&container
->entry
);
3682 delete_container(container
);
3685 list_remove(&container
->entry
);
3686 delete_container(container
);
3691 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
3692 REAL sy
, GpMatrixOrder order
)
3694 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
3697 return InvalidParameter
;
3702 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
3705 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
3708 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
3710 if(!graphics
|| !srcgraphics
)
3711 return InvalidParameter
;
3713 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
3716 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
3717 CompositingMode mode
)
3719 TRACE("(%p, %d)\n", graphics
, mode
);
3722 return InvalidParameter
;
3727 graphics
->compmode
= mode
;
3732 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
3733 CompositingQuality quality
)
3735 TRACE("(%p, %d)\n", graphics
, quality
);
3738 return InvalidParameter
;
3743 graphics
->compqual
= quality
;
3748 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
3749 InterpolationMode mode
)
3751 TRACE("(%p, %d)\n", graphics
, mode
);
3754 return InvalidParameter
;
3759 graphics
->interpolation
= mode
;
3764 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
3766 TRACE("(%p, %.2f)\n", graphics
, scale
);
3768 if(!graphics
|| (scale
<= 0.0))
3769 return InvalidParameter
;
3774 graphics
->scale
= scale
;
3779 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
3781 TRACE("(%p, %d)\n", graphics
, unit
);
3784 return InvalidParameter
;
3789 if(unit
== UnitWorld
)
3790 return InvalidParameter
;
3792 graphics
->unit
= unit
;
3797 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3800 TRACE("(%p, %d)\n", graphics
, mode
);
3803 return InvalidParameter
;
3808 graphics
->pixeloffset
= mode
;
3813 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
3817 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
3820 FIXME("not implemented\n");
3822 return NotImplemented
;
3825 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
3827 TRACE("(%p, %d)\n", graphics
, mode
);
3830 return InvalidParameter
;
3835 graphics
->smoothing
= mode
;
3840 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
3842 TRACE("(%p, %d)\n", graphics
, contrast
);
3845 return InvalidParameter
;
3847 graphics
->textcontrast
= contrast
;
3852 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
3853 TextRenderingHint hint
)
3855 TRACE("(%p, %d)\n", graphics
, hint
);
3858 return InvalidParameter
;
3863 graphics
->texthint
= hint
;
3868 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3870 TRACE("(%p, %p)\n", graphics
, matrix
);
3872 if(!graphics
|| !matrix
)
3873 return InvalidParameter
;
3878 GdipDeleteMatrix(graphics
->worldtrans
);
3879 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
3882 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
3883 REAL dy
, GpMatrixOrder order
)
3885 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
3888 return InvalidParameter
;
3893 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
3896 /*****************************************************************************
3897 * GdipSetClipHrgn [GDIPLUS.@]
3899 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
3904 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
3907 return InvalidParameter
;
3909 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
3913 status
= GdipSetClipRegion(graphics
, region
, mode
);
3915 GdipDeleteRegion(region
);
3919 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
3921 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
3924 return InvalidParameter
;
3929 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
3932 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
3933 REAL width
, REAL height
,
3938 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3941 return InvalidParameter
;
3949 rect
.Height
= height
;
3951 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
3954 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
3955 INT width
, INT height
,
3958 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3961 return InvalidParameter
;
3966 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
3969 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
3972 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
3974 if(!graphics
|| !region
)
3975 return InvalidParameter
;
3980 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
3983 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
3989 FIXME("not implemented\n");
3991 return NotImplemented
;
3994 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
4000 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
4002 if(!graphics
|| !pen
|| count
<=0)
4003 return InvalidParameter
;
4008 pti
= GdipAlloc(sizeof(POINT
) * count
);
4010 save_state
= prepare_dc(graphics
, pen
);
4011 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
4013 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
4014 Polygon(graphics
->hdc
, pti
, count
);
4016 restore_dc(graphics
, save_state
);
4022 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
4029 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
4031 if(count
<=0) return InvalidParameter
;
4032 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
4034 for(i
= 0;i
< count
; i
++){
4035 ptf
[i
].X
= (REAL
)points
[i
].X
;
4036 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
4039 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
4045 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
4047 TRACE("(%p, %p)\n", graphics
, dpi
);
4049 if(!graphics
|| !dpi
)
4050 return InvalidParameter
;
4055 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
4060 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
4062 TRACE("(%p, %p)\n", graphics
, dpi
);
4064 if(!graphics
|| !dpi
)
4065 return InvalidParameter
;
4070 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
4075 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
4076 GpMatrixOrder order
)
4081 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
4083 if(!graphics
|| !matrix
)
4084 return InvalidParameter
;
4089 m
= *(graphics
->worldtrans
);
4091 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
4093 *(graphics
->worldtrans
) = m
;
4098 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
4100 TRACE("(%p, %p)\n", graphics
, hdc
);
4102 if(!graphics
|| !hdc
)
4103 return InvalidParameter
;
4108 *hdc
= graphics
->hdc
;
4109 graphics
->busy
= TRUE
;
4114 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
4116 TRACE("(%p, %p)\n", graphics
, hdc
);
4119 return InvalidParameter
;
4121 if(graphics
->hdc
!= hdc
|| !(graphics
->busy
))
4122 return InvalidParameter
;
4124 graphics
->busy
= FALSE
;
4129 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
4134 TRACE("(%p, %p)\n", graphics
, region
);
4136 if(!graphics
|| !region
)
4137 return InvalidParameter
;
4142 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
4145 /* free everything except root node and header */
4146 delete_element(®ion
->node
);
4147 memcpy(region
, clip
, sizeof(GpRegion
));
4152 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
4153 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
4159 if(!graphics
|| !points
|| count
<= 0)
4160 return InvalidParameter
;
4165 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
4167 if (src_space
== dst_space
) return Ok
;
4169 stat
= GdipCreateMatrix(&matrix
);
4172 unitscale
= convert_unit(graphics
->hdc
, graphics
->unit
);
4174 if(graphics
->unit
!= UnitDisplay
)
4175 unitscale
*= graphics
->scale
;
4177 /* transform from src_space to CoordinateSpacePage */
4180 case CoordinateSpaceWorld
:
4181 GdipMultiplyMatrix(matrix
, graphics
->worldtrans
, MatrixOrderAppend
);
4183 case CoordinateSpacePage
:
4185 case CoordinateSpaceDevice
:
4186 GdipScaleMatrix(matrix
, 1.0/unitscale
, 1.0/unitscale
, MatrixOrderAppend
);
4190 /* transform from CoordinateSpacePage to dst_space */
4193 case CoordinateSpaceWorld
:
4195 GpMatrix
*inverted_transform
;
4196 stat
= GdipCloneMatrix(graphics
->worldtrans
, &inverted_transform
);
4199 stat
= GdipInvertMatrix(inverted_transform
);
4201 GdipMultiplyMatrix(matrix
, inverted_transform
, MatrixOrderAppend
);
4202 GdipDeleteMatrix(inverted_transform
);
4206 case CoordinateSpacePage
:
4208 case CoordinateSpaceDevice
:
4209 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
4214 stat
= GdipTransformMatrixPoints(matrix
, points
, count
);
4216 GdipDeleteMatrix(matrix
);
4222 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
4223 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
4229 TRACE("(%p, %d, %d, %p, %d)\n", graphics
, dst_space
, src_space
, points
, count
);
4232 return InvalidParameter
;
4234 pointsF
= GdipAlloc(sizeof(GpPointF
) * count
);
4238 for(i
= 0; i
< count
; i
++){
4239 pointsF
[i
].X
= (REAL
)points
[i
].X
;
4240 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
4243 ret
= GdipTransformPoints(graphics
, dst_space
, src_space
, pointsF
, count
);
4246 for(i
= 0; i
< count
; i
++){
4247 points
[i
].X
= roundr(pointsF
[i
].X
);
4248 points
[i
].Y
= roundr(pointsF
[i
].Y
);
4255 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
4262 /*****************************************************************************
4263 * GdipTranslateClip [GDIPLUS.@]
4265 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
4267 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
4270 return InvalidParameter
;
4275 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
4278 /*****************************************************************************
4279 * GdipTranslateClipI [GDIPLUS.@]
4281 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
4283 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
4286 return InvalidParameter
;
4291 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);
4295 /*****************************************************************************
4296 * GdipMeasureDriverString [GDIPLUS.@]
4298 GpStatus WINGDIPAPI
GdipMeasureDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
4299 GDIPCONST GpFont
*font
, GDIPCONST PointF
*positions
,
4300 INT flags
, GDIPCONST GpMatrix
*matrix
, RectF
*boundingBox
)
4302 FIXME("(%p %p %d %p %p %d %p %p): stub\n", graphics
, text
, length
, font
, positions
, flags
, matrix
, boundingBox
);
4303 return NotImplemented
;
4306 /*****************************************************************************
4307 * GdipDrawDriverString [GDIPLUS.@]
4309 GpStatus WINGDIPAPI
GdipDrawDriverString(GpGraphics
*graphics
, GDIPCONST UINT16
*text
, INT length
,
4310 GDIPCONST GpFont
*font
, GDIPCONST GpBrush
*brush
,
4311 GDIPCONST PointF
*positions
, INT flags
,
4312 GDIPCONST GpMatrix
*matrix
)
4314 FIXME("(%p %p %d %p %p %p %d %p): stub\n", graphics
, text
, length
, font
, brush
, positions
, flags
, matrix
);
4315 return NotImplemented
;
4318 /*****************************************************************************
4319 * GdipRecordMetafileI [GDIPLUS.@]
4321 GpStatus WINGDIPAPI
GdipRecordMetafileI(HDC hdc
, EmfType type
, GDIPCONST GpRect
*frameRect
,
4322 MetafileFrameUnit frameUnit
, GDIPCONST WCHAR
*desc
, GpMetafile
**metafile
)
4324 FIXME("(%p %d %p %d %p %p): stub\n", hdc
, type
, frameRect
, frameUnit
, desc
, metafile
);
4325 return NotImplemented
;