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"
42 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus
);
44 /* looks-right constants */
45 #define ANCHOR_WIDTH (2.0)
46 #define MAX_ITERS (50)
48 /* Converts angle (in degrees) to x/y coordinates */
49 static void deg2xy(REAL angle
, REAL x_0
, REAL y_0
, REAL
*x
, REAL
*y
)
51 REAL radAngle
, hypotenuse
;
53 radAngle
= deg2rad(angle
);
54 hypotenuse
= 50.0; /* arbitrary */
56 *x
= x_0
+ cos(radAngle
) * hypotenuse
;
57 *y
= y_0
+ sin(radAngle
) * hypotenuse
;
60 /* Converts from gdiplus path point type to gdi path point type. */
61 static BYTE
convert_path_point_type(BYTE type
)
65 switch(type
& PathPointTypePathTypeMask
){
66 case PathPointTypeBezier
:
69 case PathPointTypeLine
:
72 case PathPointTypeStart
:
76 ERR("Bad point type\n");
80 if(type
& PathPointTypeCloseSubpath
)
81 ret
|= PT_CLOSEFIGURE
;
86 static INT
prepare_dc(GpGraphics
*graphics
, GpPen
*pen
)
90 INT save_state
= SaveDC(graphics
->hdc
), i
, numdashes
;
92 DWORD dash_array
[MAX_DASHLEN
];
94 EndPath(graphics
->hdc
);
96 if(pen
->unit
== UnitPixel
){
100 /* Get an estimate for the amount the pen width is affected by the world
101 * transform. (This is similar to what some of the wine drivers do.) */
106 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
107 width
= sqrt((pt
[1].X
- pt
[0].X
) * (pt
[1].X
- pt
[0].X
) +
108 (pt
[1].Y
- pt
[0].Y
) * (pt
[1].Y
- pt
[0].Y
)) / sqrt(2.0);
110 width
*= pen
->width
* convert_unit(graphics
->hdc
,
111 pen
->unit
== UnitWorld
? graphics
->unit
: pen
->unit
);
114 if(pen
->dash
== DashStyleCustom
){
115 numdashes
= min(pen
->numdashes
, MAX_DASHLEN
);
117 TRACE("dashes are: ");
118 for(i
= 0; i
< numdashes
; i
++){
119 dash_array
[i
] = roundr(width
* pen
->dashes
[i
]);
120 TRACE("%d, ", dash_array
[i
]);
122 TRACE("\n and the pen style is %x\n", pen
->style
);
124 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
,
125 numdashes
, dash_array
);
128 gdipen
= ExtCreatePen(pen
->style
, roundr(width
), &pen
->brush
->lb
, 0, NULL
);
130 SelectObject(graphics
->hdc
, gdipen
);
135 static void restore_dc(GpGraphics
*graphics
, INT state
)
137 DeleteObject(SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
)));
138 RestoreDC(graphics
->hdc
, state
);
141 /* This helper applies all the changes that the points listed in ptf need in
142 * order to be drawn on the device context. In the end, this should include at
144 * -scaling by page unit
145 * -applying world transformation
146 * -converting from float to int
147 * Native gdiplus uses gdi32 to do all this (via SetMapMode, SetViewportExtEx,
148 * SetWindowExtEx, SetWorldTransform, etc.) but we cannot because we are using
149 * gdi to draw, and these functions would irreparably mess with line widths.
151 static void transform_and_round_points(GpGraphics
*graphics
, POINT
*pti
,
152 GpPointF
*ptf
, INT count
)
158 unitscale
= convert_unit(graphics
->hdc
, graphics
->unit
);
160 /* apply page scale */
161 if(graphics
->unit
!= UnitDisplay
)
162 unitscale
*= graphics
->scale
;
164 GdipCloneMatrix(graphics
->worldtrans
, &matrix
);
165 GdipScaleMatrix(matrix
, unitscale
, unitscale
, MatrixOrderAppend
);
166 GdipTransformMatrixPoints(matrix
, ptf
, count
);
167 GdipDeleteMatrix(matrix
);
169 for(i
= 0; i
< count
; i
++){
170 pti
[i
].x
= roundr(ptf
[i
].X
);
171 pti
[i
].y
= roundr(ptf
[i
].Y
);
175 static ARGB
blend_colors(ARGB start
, ARGB end
, REAL position
)
179 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
180 result
|= (int)((start
&i
)*(1.0f
- position
)+(end
&i
)*(position
))&i
;
184 static ARGB
blend_line_gradient(GpLineGradient
* brush
, REAL position
)
188 /* clamp to between 0.0 and 1.0, using the wrap mode */
189 if (brush
->wrap
== WrapModeTile
)
191 position
= fmodf(position
, 1.0f
);
192 if (position
< 0.0f
) position
+= 1.0f
;
194 else /* WrapModeFlip* */
196 position
= fmodf(position
, 2.0f
);
197 if (position
< 0.0f
) position
+= 2.0f
;
198 if (position
> 1.0f
) position
= 2.0f
- position
;
201 if (brush
->blendcount
== 1)
206 REAL left_blendpos
, left_blendfac
, right_blendpos
, right_blendfac
;
209 /* locate the blend positions surrounding this position */
210 while (position
> brush
->blendpos
[i
])
213 /* interpolate between the blend positions */
214 left_blendpos
= brush
->blendpos
[i
-1];
215 left_blendfac
= brush
->blendfac
[i
-1];
216 right_blendpos
= brush
->blendpos
[i
];
217 right_blendfac
= brush
->blendfac
[i
];
218 range
= right_blendpos
- left_blendpos
;
219 blendfac
= (left_blendfac
* (right_blendpos
- position
) +
220 right_blendfac
* (position
- left_blendpos
)) / range
;
222 return blend_colors(brush
->startcolor
, brush
->endcolor
, blendfac
);
225 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
229 case BrushTypeLinearGradient
:
231 GpLineGradient
*line
= (GpLineGradient
*)brush
;
234 SelectClipPath(graphics
->hdc
, RGN_AND
);
235 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
237 GpPointF endpointsf
[2];
241 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
243 endpointsf
[0] = line
->startpoint
;
244 endpointsf
[1] = line
->endpoint
;
245 transform_and_round_points(graphics
, endpointsi
, endpointsf
, 2);
247 if (abs(endpointsi
[0].x
-endpointsi
[1].x
) > abs(endpointsi
[0].y
-endpointsi
[1].y
))
249 /* vertical-ish gradient */
250 int startx
, endx
; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
251 int startbottomx
; /* x co-ordinate of start point shifted to intersect the bottom of the visible rectangle */
254 HBRUSH hbrush
, hprevbrush
;
255 int leftx
, rightx
; /* x co-ordinates where the leftmost and rightmost gradient lines hit the top of the visible rectangle */
257 int tilt
; /* horizontal distance covered by a gradient line */
259 startx
= roundr((rc
.top
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
260 endx
= roundr((rc
.top
- endpointsf
[1].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[1].X
);
261 width
= endx
- startx
;
262 startbottomx
= roundr((rc
.bottom
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
263 tilt
= startx
- startbottomx
;
265 if (startx
>= startbottomx
)
268 rightx
= rc
.right
+ tilt
;
272 leftx
= rc
.left
+ tilt
;
276 poly
[0].y
= rc
.bottom
;
279 poly
[3].y
= rc
.bottom
;
281 for (x
=leftx
; x
<=rightx
; x
++)
283 ARGB argb
= blend_line_gradient(line
, (x
-startx
)/(REAL
)width
);
284 col
= ARGB2COLORREF(argb
);
285 hbrush
= CreateSolidBrush(col
);
286 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
287 poly
[0].x
= x
- tilt
- 1;
290 poly
[3].x
= x
- tilt
;
291 Polygon(graphics
->hdc
, poly
, 4);
292 SelectObject(graphics
->hdc
, hprevbrush
);
293 DeleteObject(hbrush
);
296 else if (endpointsi
[0].y
!= endpointsi
[1].y
)
298 /* horizontal-ish gradient */
299 int starty
, endy
; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
300 int startrighty
; /* y co-ordinate of start point shifted to intersect the right of the visible rectangle */
303 HBRUSH hbrush
, hprevbrush
;
304 int topy
, bottomy
; /* y co-ordinates where the topmost and bottommost gradient lines hit the left of the visible rectangle */
306 int tilt
; /* vertical distance covered by a gradient line */
308 starty
= roundr((rc
.left
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
309 endy
= roundr((rc
.left
- endpointsf
[1].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[1].Y
);
310 height
= endy
- starty
;
311 startrighty
= roundr((rc
.right
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
312 tilt
= starty
- startrighty
;
314 if (starty
>= startrighty
)
317 bottomy
= rc
.bottom
+ tilt
;
321 topy
= rc
.top
+ tilt
;
325 poly
[0].x
= rc
.right
;
328 poly
[3].x
= rc
.right
;
330 for (y
=topy
; y
<=bottomy
; y
++)
332 ARGB argb
= blend_line_gradient(line
, (y
-starty
)/(REAL
)height
);
333 col
= ARGB2COLORREF(argb
);
334 hbrush
= CreateSolidBrush(col
);
335 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
336 poly
[0].y
= y
- tilt
- 1;
339 poly
[3].y
= y
- tilt
;
340 Polygon(graphics
->hdc
, poly
, 4);
341 SelectObject(graphics
->hdc
, hprevbrush
);
342 DeleteObject(hbrush
);
345 /* else startpoint == endpoint */
350 SelectObject(graphics
->hdc
, brush
->gdibrush
);
351 FillPath(graphics
->hdc
);
356 /* GdipDrawPie/GdipFillPie helper function */
357 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
358 REAL height
, REAL startAngle
, REAL sweepAngle
)
365 ptf
[1].X
= x
+ width
;
366 ptf
[1].Y
= y
+ height
;
368 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
369 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
371 transform_and_round_points(graphics
, pti
, ptf
, 4);
373 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
374 pti
[2].y
, pti
[3].x
, pti
[3].y
);
377 /* Draws the linecap the specified color and size on the hdc. The linecap is in
378 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
379 * should not be called on an hdc that has a path you care about. */
380 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
381 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
383 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
384 GpMatrix
*matrix
= NULL
;
387 PointF ptf
[4], *custptf
= NULL
;
388 POINT pt
[4], *custpt
= NULL
;
390 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
395 if((x1
== x2
) && (y1
== y2
))
398 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
400 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
402 brush
= CreateSolidBrush(color
);
403 lb
.lbStyle
= BS_SOLID
;
406 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
407 PS_JOIN_MITER
, 1, &lb
, 0,
409 oldbrush
= SelectObject(graphics
->hdc
, brush
);
410 oldpen
= SelectObject(graphics
->hdc
, pen
);
417 case LineCapSquareAnchor
:
418 case LineCapDiamondAnchor
:
419 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
420 if(cap
== LineCapDiamondAnchor
){
421 dsmall
= cos(theta
+ M_PI_2
) * size
;
422 dbig
= sin(theta
+ M_PI_2
) * size
;
425 dsmall
= cos(theta
+ M_PI_4
) * size
;
426 dbig
= sin(theta
+ M_PI_4
) * size
;
429 ptf
[0].X
= x2
- dsmall
;
430 ptf
[1].X
= x2
+ dbig
;
432 ptf
[0].Y
= y2
- dbig
;
433 ptf
[3].Y
= y2
+ dsmall
;
435 ptf
[1].Y
= y2
- dsmall
;
436 ptf
[2].Y
= y2
+ dbig
;
438 ptf
[3].X
= x2
- dbig
;
439 ptf
[2].X
= x2
+ dsmall
;
441 transform_and_round_points(graphics
, pt
, ptf
, 4);
442 Polygon(graphics
->hdc
, pt
, 4);
445 case LineCapArrowAnchor
:
446 size
= size
* 4.0 / sqrt(3.0);
448 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
449 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
454 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
455 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
463 transform_and_round_points(graphics
, pt
, ptf
, 3);
464 Polygon(graphics
->hdc
, pt
, 3);
467 case LineCapRoundAnchor
:
468 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
475 transform_and_round_points(graphics
, pt
, ptf
, 2);
476 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
479 case LineCapTriangle
:
481 dx
= cos(M_PI_2
+ theta
) * size
;
482 dy
= sin(M_PI_2
+ theta
) * size
;
489 dx
= cos(theta
) * size
;
490 dy
= sin(theta
) * size
;
495 transform_and_round_points(graphics
, pt
, ptf
, 3);
496 Polygon(graphics
->hdc
, pt
, 3);
500 dx
= dy
= size
/ 2.0;
507 dx
= -cos(M_PI_2
+ theta
) * size
;
508 dy
= -sin(M_PI_2
+ theta
) * size
;
515 transform_and_round_points(graphics
, pt
, ptf
, 4);
516 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
517 pt
[2].y
, pt
[3].x
, pt
[3].y
);
524 count
= custom
->pathdata
.Count
;
525 custptf
= GdipAlloc(count
* sizeof(PointF
));
526 custpt
= GdipAlloc(count
* sizeof(POINT
));
527 tp
= GdipAlloc(count
);
529 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
532 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
534 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
535 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
537 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
538 GdipTransformMatrixPoints(matrix
, custptf
, count
);
540 transform_and_round_points(graphics
, custpt
, custptf
, count
);
542 for(i
= 0; i
< count
; i
++)
543 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
546 BeginPath(graphics
->hdc
);
547 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
548 EndPath(graphics
->hdc
);
549 StrokeAndFillPath(graphics
->hdc
);
552 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
558 GdipDeleteMatrix(matrix
);
565 SelectObject(graphics
->hdc
, oldbrush
);
566 SelectObject(graphics
->hdc
, oldpen
);
572 /* Shortens the line by the given percent by changing x2, y2.
573 * If percent is > 1.0 then the line will change direction.
574 * If percent is negative it can lengthen the line. */
575 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
577 REAL dist
, theta
, dx
, dy
;
579 if((y1
== *y2
) && (x1
== *x2
))
582 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
583 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
584 dx
= cos(theta
) * dist
;
585 dy
= sin(theta
) * dist
;
591 /* Shortens the line by the given amount by changing x2, y2.
592 * If the amount is greater than the distance, the line will become length 0.
593 * If the amount is negative, it can lengthen the line. */
594 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
596 REAL dx
, dy
, percent
;
600 if(dx
== 0 && dy
== 0)
603 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
610 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
613 /* Draws lines between the given points, and if caps is true then draws an endcap
614 * at the end of the last line. */
615 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
616 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
619 GpPointF
*ptcopy
= NULL
;
620 GpStatus status
= GenericError
;
625 pti
= GdipAlloc(count
* sizeof(POINT
));
626 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
629 status
= OutOfMemory
;
633 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
636 if(pen
->endcap
== LineCapArrowAnchor
)
637 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
638 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
639 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
640 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
641 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
642 pen
->customend
->inset
* pen
->width
);
644 if(pen
->startcap
== LineCapArrowAnchor
)
645 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
646 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
647 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
648 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
649 &ptcopy
[0].X
, &ptcopy
[0].Y
,
650 pen
->customstart
->inset
* pen
->width
);
652 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
653 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
654 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
655 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
658 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
660 if(Polyline(graphics
->hdc
, pti
, count
))
670 /* Conducts a linear search to find the bezier points that will back off
671 * the endpoint of the curve by a distance of amt. Linear search works
672 * better than binary in this case because there are multiple solutions,
673 * and binary searches often find a bad one. I don't think this is what
674 * Windows does but short of rendering the bezier without GDI's help it's
675 * the best we can do. If rev then work from the start of the passed points
676 * instead of the end. */
677 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
680 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
681 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
690 origx
= pt
[fourth
].X
;
691 origy
= pt
[fourth
].Y
;
692 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
694 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
695 /* reset bezier points to original values */
696 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
697 /* Perform magic on bezier points. Order is important here.*/
698 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
699 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
700 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
701 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
702 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
703 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
705 dx
= pt
[fourth
].X
- origx
;
706 dy
= pt
[fourth
].Y
- origy
;
708 diff
= sqrt(dx
* dx
+ dy
* dy
);
709 percent
+= 0.0005 * amt
;
713 /* Draws bezier curves between given points, and if caps is true then draws an
714 * endcap at the end of the last line. */
715 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
716 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
720 GpStatus status
= GenericError
;
725 pti
= GdipAlloc(count
* sizeof(POINT
));
726 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
729 status
= OutOfMemory
;
733 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
736 if(pen
->endcap
== LineCapArrowAnchor
)
737 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
738 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
739 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
742 if(pen
->startcap
== LineCapArrowAnchor
)
743 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
744 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
745 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
747 /* the direction of the line cap is parallel to the direction at the
748 * end of the bezier (which, if it has been shortened, is not the same
749 * as the direction from pt[count-2] to pt[count-1]) */
750 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
751 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
752 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
753 pt
[count
- 1].X
, pt
[count
- 1].Y
);
755 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
756 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
757 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
760 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
762 PolyBezier(graphics
->hdc
, pti
, count
);
773 /* Draws a combination of bezier curves and lines between points. */
774 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
775 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
777 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
778 BYTE
*tp
= GdipAlloc(count
);
779 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
781 GpStatus status
= GenericError
;
787 if(!pti
|| !tp
|| !ptcopy
){
788 status
= OutOfMemory
;
792 for(i
= 1; i
< count
; i
++){
793 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
794 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
795 || !(types
[i
+ 1] & PathPointTypeBezier
)){
796 ERR("Bad bezier points\n");
803 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
805 /* If we are drawing caps, go through the points and adjust them accordingly,
806 * and draw the caps. */
808 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
809 case PathPointTypeBezier
:
810 if(pen
->endcap
== LineCapArrowAnchor
)
811 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
812 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
813 shorten_bezier_amt(&ptcopy
[count
- 4],
814 pen
->width
* pen
->customend
->inset
, FALSE
);
816 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
817 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
818 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
819 pt
[count
- 1].X
, pt
[count
- 1].Y
);
822 case PathPointTypeLine
:
823 if(pen
->endcap
== LineCapArrowAnchor
)
824 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
825 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
827 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
828 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
829 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
830 pen
->customend
->inset
* pen
->width
);
832 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
833 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
838 ERR("Bad path last point\n");
842 /* Find start of points */
843 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
844 == PathPointTypeStart
); j
++);
846 switch(types
[j
] & PathPointTypePathTypeMask
){
847 case PathPointTypeBezier
:
848 if(pen
->startcap
== LineCapArrowAnchor
)
849 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
850 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
851 shorten_bezier_amt(&ptcopy
[j
- 1],
852 pen
->width
* pen
->customstart
->inset
, TRUE
);
854 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
855 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
856 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
857 pt
[j
- 1].X
, pt
[j
- 1].Y
);
860 case PathPointTypeLine
:
861 if(pen
->startcap
== LineCapArrowAnchor
)
862 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
863 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
865 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
866 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
867 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
868 pen
->customstart
->inset
* pen
->width
);
870 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
871 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
876 ERR("Bad path points\n");
881 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
883 for(i
= 0; i
< count
; i
++){
884 tp
[i
] = convert_path_point_type(types
[i
]);
887 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
899 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
903 BeginPath(graphics
->hdc
);
904 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
905 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
906 EndPath(graphics
->hdc
);
910 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
912 TRACE("(%p, %p)\n", hdc
, graphics
);
914 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
917 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
921 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
923 if(hDevice
!= NULL
) {
924 FIXME("Don't know how to hadle parameter hDevice\n");
925 return NotImplemented
;
932 return InvalidParameter
;
934 *graphics
= GdipAlloc(sizeof(GpGraphics
));
935 if(!*graphics
) return OutOfMemory
;
937 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
942 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
943 GdipFree((*graphics
)->worldtrans
);
948 (*graphics
)->hdc
= hdc
;
949 (*graphics
)->hwnd
= WindowFromDC(hdc
);
950 (*graphics
)->owndc
= FALSE
;
951 (*graphics
)->smoothing
= SmoothingModeDefault
;
952 (*graphics
)->compqual
= CompositingQualityDefault
;
953 (*graphics
)->interpolation
= InterpolationModeDefault
;
954 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
955 (*graphics
)->compmode
= CompositingModeSourceOver
;
956 (*graphics
)->unit
= UnitDisplay
;
957 (*graphics
)->scale
= 1.0;
958 (*graphics
)->busy
= FALSE
;
959 (*graphics
)->textcontrast
= 4;
964 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
969 TRACE("(%p, %p)\n", hwnd
, graphics
);
973 if((ret
= GdipCreateFromHDC(hdc
, graphics
)) != Ok
)
975 ReleaseDC(hwnd
, hdc
);
979 (*graphics
)->hwnd
= hwnd
;
980 (*graphics
)->owndc
= TRUE
;
985 /* FIXME: no icm handling */
986 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
988 TRACE("(%p, %p)\n", hwnd
, graphics
);
990 return GdipCreateFromHWND(hwnd
, graphics
);
993 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
994 GpMetafile
**metafile
)
998 if(!hemf
|| !metafile
)
999 return InvalidParameter
;
1002 FIXME("not implemented\n");
1004 return NotImplemented
;
1007 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
1008 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1010 IStream
*stream
= NULL
;
1014 GpStatus retval
= GenericError
;
1016 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
1018 if(!hwmf
|| !metafile
|| !placeable
)
1019 return InvalidParameter
;
1022 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
1024 return GenericError
;
1025 copy
= GdipAlloc(read
);
1026 GetMetaFileBitsEx(hwmf
, read
, copy
);
1028 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1031 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
1032 copy
= GdipAlloc(read
);
1033 GetEnhMetaFileBits(hemf
, read
, copy
);
1034 DeleteEnhMetaFile(hemf
);
1036 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
1037 ERR("could not make stream\n");
1042 *metafile
= GdipAlloc(sizeof(GpMetafile
));
1044 retval
= OutOfMemory
;
1048 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1049 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
1053 (*metafile
)->image
.type
= ImageTypeMetafile
;
1054 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
1055 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Right
) / ((REAL
) placeable
->Inch
);
1056 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
1057 - placeable
->BoundingBox
.Left
)) / ((REAL
) placeable
->Inch
);
1058 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
1059 - placeable
->BoundingBox
.Top
)) / ((REAL
) placeable
->Inch
);
1060 (*metafile
)->unit
= UnitInch
;
1063 DeleteMetaFile(hwmf
);
1068 GdipFree(*metafile
);
1069 IStream_Release(stream
);
1073 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1074 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1076 HMETAFILE hmf
= GetMetaFileW(file
);
1078 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1080 if(!hmf
) return InvalidParameter
;
1082 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1085 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
1086 UINT access
, IStream
**stream
)
1091 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
1093 if(!stream
|| !filename
)
1094 return InvalidParameter
;
1096 if(access
& GENERIC_WRITE
)
1097 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
1098 else if(access
& GENERIC_READ
)
1099 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
1101 return InvalidParameter
;
1103 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
1105 return hresult_to_status(ret
);
1108 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
1110 TRACE("(%p)\n", graphics
);
1112 if(!graphics
) return InvalidParameter
;
1113 if(graphics
->busy
) return ObjectBusy
;
1116 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
1118 GdipDeleteRegion(graphics
->clip
);
1119 GdipDeleteMatrix(graphics
->worldtrans
);
1125 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1126 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1128 INT save_state
, num_pts
;
1129 GpPointF points
[MAX_ARC_PTS
];
1132 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1133 width
, height
, startAngle
, sweepAngle
);
1135 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
1136 return InvalidParameter
;
1141 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1143 save_state
= prepare_dc(graphics
, pen
);
1145 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
1147 restore_dc(graphics
, save_state
);
1152 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1153 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1155 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1156 width
, height
, startAngle
, sweepAngle
);
1158 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1161 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1162 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
1168 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
1169 x2
, y2
, x3
, y3
, x4
, y4
);
1171 if(!graphics
|| !pen
)
1172 return InvalidParameter
;
1186 save_state
= prepare_dc(graphics
, pen
);
1188 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1190 restore_dc(graphics
, save_state
);
1195 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1196 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
1202 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
1203 x2
, y2
, x3
, y3
, x4
, y4
);
1205 if(!graphics
|| !pen
)
1206 return InvalidParameter
;
1220 save_state
= prepare_dc(graphics
, pen
);
1222 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1224 restore_dc(graphics
, save_state
);
1229 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
1230 GDIPCONST GpPointF
*points
, INT count
)
1235 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1237 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1238 return InvalidParameter
;
1243 for(i
= 0; i
< floor(count
/ 4); i
++){
1244 ret
= GdipDrawBezier(graphics
, pen
,
1245 points
[4*i
].X
, points
[4*i
].Y
,
1246 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
1247 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
1248 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
1256 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
1257 GDIPCONST GpPoint
*points
, INT count
)
1263 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1265 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1266 return InvalidParameter
;
1271 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
1275 for(i
= 0; i
< count
; i
++){
1276 pts
[i
].X
= (REAL
)points
[i
].X
;
1277 pts
[i
].Y
= (REAL
)points
[i
].Y
;
1280 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
1287 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
1288 GDIPCONST GpPointF
*points
, INT count
)
1290 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1292 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
1295 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1296 GDIPCONST GpPoint
*points
, INT count
)
1298 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1300 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
1303 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1304 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1309 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1311 if(!graphics
|| !pen
|| !points
|| count
<= 0)
1312 return InvalidParameter
;
1317 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
1320 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1322 GdipDeletePath(path
);
1326 stat
= GdipDrawPath(graphics
, pen
, path
);
1328 GdipDeletePath(path
);
1333 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1334 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1340 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1342 if(!points
|| count
<= 0)
1343 return InvalidParameter
;
1345 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1349 for(i
= 0; i
< count
; i
++){
1350 ptf
[i
].X
= (REAL
)points
[i
].X
;
1351 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1354 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
1361 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
1362 GDIPCONST GpPointF
*points
, INT count
)
1364 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1366 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
1369 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1370 GDIPCONST GpPoint
*points
, INT count
)
1376 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1378 if(!points
|| count
<= 0)
1379 return InvalidParameter
;
1381 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1385 for(i
= 0; i
< count
; i
++){
1386 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1387 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1390 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
1396 /* Approximates cardinal spline with Bezier curves. */
1397 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1398 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1400 /* PolyBezier expects count*3-2 points. */
1401 INT i
, len_pt
= count
*3-2, save_state
;
1403 REAL x1
, x2
, y1
, y2
;
1406 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1408 if(!graphics
|| !pen
)
1409 return InvalidParameter
;
1414 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
1415 tension
= tension
* TENSION_CONST
;
1417 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
1420 pt
[0].X
= points
[0].X
;
1421 pt
[0].Y
= points
[0].Y
;
1425 for(i
= 0; i
< count
-2; i
++){
1426 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
1430 pt
[3*i
+3].X
= points
[i
+1].X
;
1431 pt
[3*i
+3].Y
= points
[i
+1].Y
;
1436 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
1437 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
1439 pt
[len_pt
-2].X
= x1
;
1440 pt
[len_pt
-2].Y
= y1
;
1441 pt
[len_pt
-1].X
= points
[count
-1].X
;
1442 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
1444 save_state
= prepare_dc(graphics
, pen
);
1446 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
1449 restore_dc(graphics
, save_state
);
1454 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1455 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1461 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1463 if(!points
|| count
<= 0)
1464 return InvalidParameter
;
1466 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1470 for(i
= 0; i
< count
; i
++){
1471 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1472 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1475 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
1481 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1482 REAL y
, REAL width
, REAL height
)
1488 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1490 if(!graphics
|| !pen
)
1491 return InvalidParameter
;
1498 ptf
[1].X
= x
+ width
;
1499 ptf
[1].Y
= y
+ height
;
1501 save_state
= prepare_dc(graphics
, pen
);
1502 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1504 transform_and_round_points(graphics
, pti
, ptf
, 2);
1506 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1508 restore_dc(graphics
, save_state
);
1513 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1514 INT y
, INT width
, INT height
)
1516 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1518 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1522 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
1524 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
1526 /* IPicture::Render uses LONG coords */
1527 return GdipDrawImageI(graphics
,image
,roundr(x
),roundr(y
));
1530 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
1533 UINT width
, height
, srcw
, srch
;
1535 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
1537 if(!graphics
|| !image
)
1538 return InvalidParameter
;
1540 GdipGetImageWidth(image
, &width
);
1541 GdipGetImageHeight(image
, &height
);
1543 srcw
= width
* (((REAL
) INCH_HIMETRIC
) /
1544 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
)));
1545 srch
= height
* (((REAL
) INCH_HIMETRIC
) /
1546 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
)));
1548 if(image
->type
!= ImageTypeMetafile
){
1553 IPicture_Render(image
->picture
, graphics
->hdc
, x
, y
, width
, height
,
1554 0, 0, srcw
, srch
, NULL
);
1559 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1560 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
1561 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
1562 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1563 DrawImageAbort callback
, VOID
* callbackData
)
1569 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
1570 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1573 if(!graphics
|| !image
|| !points
|| count
!= 3)
1574 return InvalidParameter
;
1576 if(srcUnit
== UnitInch
)
1577 dx
= dy
= (REAL
) INCH_HIMETRIC
;
1578 else if(srcUnit
== UnitPixel
){
1579 dx
= ((REAL
) INCH_HIMETRIC
) /
1580 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
1581 dy
= ((REAL
) INCH_HIMETRIC
) /
1582 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
1585 return NotImplemented
;
1587 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
1588 transform_and_round_points(graphics
, pti
, ptf
, 3);
1590 /* IPicture renders bitmaps with the y-axis reversed
1591 * FIXME: flipping for unknown image type might not be correct. */
1592 if(image
->type
!= ImageTypeMetafile
){
1595 pti
[0].y
= pti
[2].y
;
1599 if(IPicture_Render(image
->picture
, graphics
->hdc
,
1600 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
1601 srcx
* dx
, srcy
* dy
,
1602 srcwidth
* dx
, srcheight
* dy
,
1605 callback(callbackData
);
1606 return GenericError
;
1612 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
1613 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
1614 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1615 DrawImageAbort callback
, VOID
* callbackData
)
1617 GpPointF pointsF
[3];
1620 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
1621 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1624 if(!points
|| count
!=3)
1625 return InvalidParameter
;
1627 for(i
= 0; i
< count
; i
++){
1628 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1629 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1632 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
1633 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
1634 callback
, callbackData
);
1637 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
1638 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
1639 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
1640 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
1641 VOID
* callbackData
)
1645 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
1646 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
1647 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1651 points
[1].X
= dstx
+ dstwidth
;
1654 points
[2].Y
= dsty
+ dstheight
;
1656 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1657 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1660 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
1661 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
1662 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
1663 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
1664 VOID
* callbackData
)
1668 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
1669 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
1670 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1674 points
[1].X
= dstx
+ dstwidth
;
1677 points
[2].Y
= dsty
+ dstheight
;
1679 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1680 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1683 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
1684 REAL x
, REAL y
, REAL width
, REAL height
)
1690 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
1692 if(!graphics
|| !image
)
1693 return InvalidParameter
;
1695 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
1699 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
1700 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
1701 unit
, NULL
, NULL
, NULL
);
1704 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
1705 INT x
, INT y
, INT width
, INT height
)
1707 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
1709 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
1712 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1713 REAL y1
, REAL x2
, REAL y2
)
1719 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
1721 if(!pen
|| !graphics
)
1722 return InvalidParameter
;
1732 save_state
= prepare_dc(graphics
, pen
);
1734 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1736 restore_dc(graphics
, save_state
);
1741 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1742 INT y1
, INT x2
, INT y2
)
1748 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
1750 if(!pen
|| !graphics
)
1751 return InvalidParameter
;
1761 save_state
= prepare_dc(graphics
, pen
);
1763 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1765 restore_dc(graphics
, save_state
);
1770 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
1771 GpPointF
*points
, INT count
)
1776 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1778 if(!pen
|| !graphics
|| (count
< 2))
1779 return InvalidParameter
;
1784 save_state
= prepare_dc(graphics
, pen
);
1786 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
1788 restore_dc(graphics
, save_state
);
1793 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
1794 GpPoint
*points
, INT count
)
1798 GpPointF
*ptf
= NULL
;
1801 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1803 if(!pen
|| !graphics
|| (count
< 2))
1804 return InvalidParameter
;
1809 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
1810 if(!ptf
) return OutOfMemory
;
1812 for(i
= 0; i
< count
; i
++){
1813 ptf
[i
].X
= (REAL
) points
[i
].X
;
1814 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
1817 save_state
= prepare_dc(graphics
, pen
);
1819 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
1821 restore_dc(graphics
, save_state
);
1827 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
1832 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
1834 if(!pen
|| !graphics
)
1835 return InvalidParameter
;
1840 save_state
= prepare_dc(graphics
, pen
);
1842 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
1843 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
1845 restore_dc(graphics
, save_state
);
1850 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1851 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1855 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1856 width
, height
, startAngle
, sweepAngle
);
1858 if(!graphics
|| !pen
)
1859 return InvalidParameter
;
1864 save_state
= prepare_dc(graphics
, pen
);
1865 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1867 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1869 restore_dc(graphics
, save_state
);
1874 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1875 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1877 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1878 width
, height
, startAngle
, sweepAngle
);
1880 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1883 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1884 REAL y
, REAL width
, REAL height
)
1890 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1892 if(!pen
|| !graphics
)
1893 return InvalidParameter
;
1900 ptf
[1].X
= x
+ width
;
1902 ptf
[2].X
= x
+ width
;
1903 ptf
[2].Y
= y
+ height
;
1905 ptf
[3].Y
= y
+ height
;
1907 save_state
= prepare_dc(graphics
, pen
);
1908 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1910 transform_and_round_points(graphics
, pti
, ptf
, 4);
1911 Polygon(graphics
->hdc
, pti
, 4);
1913 restore_dc(graphics
, save_state
);
1918 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1919 INT y
, INT width
, INT height
)
1921 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1923 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1926 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
1927 GDIPCONST GpRectF
* rects
, INT count
)
1933 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
1935 if(!graphics
|| !pen
|| !rects
|| count
< 1)
1936 return InvalidParameter
;
1941 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
1942 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
1950 for(i
= 0; i
< count
; i
++){
1951 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
1952 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
1953 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
1954 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
1957 save_state
= prepare_dc(graphics
, pen
);
1958 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1960 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
1962 for(i
= 0; i
< count
; i
++)
1963 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
1965 restore_dc(graphics
, save_state
);
1973 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
1974 GDIPCONST GpRect
* rects
, INT count
)
1980 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
1982 if(!rects
|| count
<=0)
1983 return InvalidParameter
;
1985 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
1989 for(i
= 0;i
< count
;i
++){
1990 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
1991 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
1992 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
1993 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
1996 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
2002 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
2003 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
2004 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
2009 TEXTMETRICW textmet
;
2010 GpPointF pt
[2], rectcpy
[4];
2013 REAL angle
, ang_cos
, ang_sin
, rel_width
, rel_height
;
2014 INT sum
= 0, height
= 0, fit
, fitcpy
, save_state
, i
, j
, lret
, nwidth
,
2019 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
2020 return InvalidParameter
;
2022 if((brush
->bt
!= BrushTypeSolidColor
)){
2023 FIXME("not implemented for given parameters\n");
2024 return NotImplemented
;
2028 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
2030 if(length
== -1) length
= lstrlenW(string
);
2032 stringdup
= GdipAlloc(length
* sizeof(WCHAR
));
2033 if(!stringdup
) return OutOfMemory
;
2035 save_state
= SaveDC(graphics
->hdc
);
2036 SetBkMode(graphics
->hdc
, TRANSPARENT
);
2037 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
2039 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
2040 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
2041 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
2042 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
2043 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
2045 if (roundr(rect
->Width
) == 0)
2052 rel_width
= sqrt((corners
[1].x
- corners
[0].x
) * (corners
[1].x
- corners
[0].x
) +
2053 (corners
[1].y
- corners
[0].y
) * (corners
[1].y
- corners
[0].y
))
2055 nwidth
= roundr(rel_width
* rect
->Width
);
2058 if (roundr(rect
->Height
) == 0)
2065 rel_height
= sqrt((corners
[2].x
- corners
[1].x
) * (corners
[2].x
- corners
[1].x
) +
2066 (corners
[2].y
- corners
[1].y
) * (corners
[2].y
- corners
[1].y
))
2068 nheight
= roundr(rel_height
* rect
->Height
);
2071 if (roundr(rect
->Width
) != 0 && roundr(rect
->Height
) != 0)
2073 /* FIXME: If only the width or only the height is 0, we should probably still clip */
2074 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
2075 SelectClipRgn(graphics
->hdc
, rgn
);
2078 /* Use gdi to find the font, then perform transformations on it (height,
2080 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
2081 GetTextMetricsW(graphics
->hdc
, &textmet
);
2084 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
2085 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
2091 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
2092 angle
= gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2093 ang_cos
= cos(angle
);
2094 ang_sin
= sin(angle
);
2095 lfw
.lfEscapement
= lfw
.lfOrientation
= -roundr((angle
/ M_PI
) * 1800.0);
2097 gdifont
= CreateFontIndirectW(&lfw
);
2098 DeleteObject(SelectObject(graphics
->hdc
, CreateFontIndirectW(&lfw
)));
2100 for(i
= 0, j
= 0; i
< length
; i
++){
2101 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
2104 stringdup
[j
] = string
[i
];
2110 while(sum
< length
){
2111 drawcoord
.left
= corners
[0].x
+ roundr(ang_sin
* (REAL
) height
);
2112 drawcoord
.top
= corners
[0].y
+ roundr(ang_cos
* (REAL
) height
);
2114 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
2115 nwidth
, &fit
, NULL
, &size
);
2119 DrawTextW(graphics
->hdc
, stringdup
+ sum
, 1, &drawcoord
, DT_NOCLIP
|
2124 for(lret
= 0; lret
< fit
; lret
++)
2125 if(*(stringdup
+ sum
+ lret
) == '\n')
2128 /* Line break code (may look strange, but it imitates windows). */
2130 fit
= lret
; /* this is not an off-by-one error */
2131 else if(fit
< (length
- sum
)){
2132 if(*(stringdup
+ sum
+ fit
) == ' ')
2133 while(*(stringdup
+ sum
+ fit
) == ' ')
2136 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
2139 if(*(stringdup
+ sum
+ fit
) == '\t')
2148 DrawTextW(graphics
->hdc
, stringdup
+ sum
, min(length
- sum
, fit
),
2149 &drawcoord
, DT_NOCLIP
| DT_EXPANDTABS
);
2151 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
2154 if(height
> nheight
)
2157 /* Stop if this was a linewrap (but not if it was a linebreak). */
2158 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
2162 GdipFree(stringdup
);
2164 DeleteObject(gdifont
);
2166 RestoreDC(graphics
->hdc
, save_state
);
2171 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
2172 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
2177 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2178 count
, tension
, fill
);
2180 if(!graphics
|| !brush
|| !points
)
2181 return InvalidParameter
;
2186 stat
= GdipCreatePath(fill
, &path
);
2190 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2192 GdipDeletePath(path
);
2196 stat
= GdipFillPath(graphics
, brush
, path
);
2198 GdipDeletePath(path
);
2202 GdipDeletePath(path
);
2207 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
2208 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
2214 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2215 count
, tension
, fill
);
2217 if(!points
|| count
<= 0)
2218 return InvalidParameter
;
2220 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2224 for(i
= 0;i
< count
;i
++){
2225 ptf
[i
].X
= (REAL
)points
[i
].X
;
2226 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2229 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
2236 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2237 REAL y
, REAL width
, REAL height
)
2243 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2245 if(!graphics
|| !brush
)
2246 return InvalidParameter
;
2253 ptf
[1].X
= x
+ width
;
2254 ptf
[1].Y
= y
+ height
;
2256 save_state
= SaveDC(graphics
->hdc
);
2257 EndPath(graphics
->hdc
);
2258 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2259 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2261 transform_and_round_points(graphics
, pti
, ptf
, 2);
2263 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2265 RestoreDC(graphics
->hdc
, save_state
);
2270 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2271 INT y
, INT width
, INT height
)
2273 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2275 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2278 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
2283 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
2285 if(!brush
|| !graphics
|| !path
)
2286 return InvalidParameter
;
2291 save_state
= SaveDC(graphics
->hdc
);
2292 EndPath(graphics
->hdc
);
2293 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
2296 BeginPath(graphics
->hdc
);
2297 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2298 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2303 EndPath(graphics
->hdc
);
2304 brush_fill_path(graphics
, brush
);
2309 RestoreDC(graphics
->hdc
, save_state
);
2314 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2315 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2319 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2320 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2322 if(!graphics
|| !brush
)
2323 return InvalidParameter
;
2328 save_state
= SaveDC(graphics
->hdc
);
2329 EndPath(graphics
->hdc
);
2330 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2331 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2333 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2335 RestoreDC(graphics
->hdc
, save_state
);
2340 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2341 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2343 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2344 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2346 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2349 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
2350 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
2353 GpPointF
*ptf
= NULL
;
2355 GpStatus retval
= Ok
;
2357 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2359 if(!graphics
|| !brush
|| !points
|| !count
)
2360 return InvalidParameter
;
2365 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2366 pti
= GdipAlloc(count
* sizeof(POINT
));
2368 retval
= OutOfMemory
;
2372 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
2374 save_state
= SaveDC(graphics
->hdc
);
2375 EndPath(graphics
->hdc
);
2376 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2377 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2378 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2381 transform_and_round_points(graphics
, pti
, ptf
, count
);
2382 Polygon(graphics
->hdc
, pti
, count
);
2384 RestoreDC(graphics
->hdc
, save_state
);
2393 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
2394 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
2397 GpPointF
*ptf
= NULL
;
2399 GpStatus retval
= Ok
;
2401 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2403 if(!graphics
|| !brush
|| !points
|| !count
)
2404 return InvalidParameter
;
2409 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2410 pti
= GdipAlloc(count
* sizeof(POINT
));
2412 retval
= OutOfMemory
;
2416 for(i
= 0; i
< count
; i
++){
2417 ptf
[i
].X
= (REAL
) points
[i
].X
;
2418 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2421 save_state
= SaveDC(graphics
->hdc
);
2422 EndPath(graphics
->hdc
);
2423 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2424 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2425 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2428 transform_and_round_points(graphics
, pti
, ptf
, count
);
2429 Polygon(graphics
->hdc
, pti
, count
);
2431 RestoreDC(graphics
->hdc
, save_state
);
2440 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
2441 GDIPCONST GpPointF
*points
, INT count
)
2443 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2445 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
2448 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
2449 GDIPCONST GpPoint
*points
, INT count
)
2451 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2453 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
2456 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
2457 REAL x
, REAL y
, REAL width
, REAL height
)
2463 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2465 if(!graphics
|| !brush
)
2466 return InvalidParameter
;
2473 ptf
[1].X
= x
+ width
;
2475 ptf
[2].X
= x
+ width
;
2476 ptf
[2].Y
= y
+ height
;
2478 ptf
[3].Y
= y
+ height
;
2480 save_state
= SaveDC(graphics
->hdc
);
2481 EndPath(graphics
->hdc
);
2483 transform_and_round_points(graphics
, pti
, ptf
, 4);
2485 BeginPath(graphics
->hdc
);
2486 Polygon(graphics
->hdc
, pti
, 4);
2487 EndPath(graphics
->hdc
);
2489 brush_fill_path(graphics
, brush
);
2491 RestoreDC(graphics
->hdc
, save_state
);
2496 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
2497 INT x
, INT y
, INT width
, INT height
)
2503 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2505 if(!graphics
|| !brush
)
2506 return InvalidParameter
;
2513 ptf
[1].X
= x
+ width
;
2515 ptf
[2].X
= x
+ width
;
2516 ptf
[2].Y
= y
+ height
;
2518 ptf
[3].Y
= y
+ height
;
2520 save_state
= SaveDC(graphics
->hdc
);
2521 EndPath(graphics
->hdc
);
2522 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2523 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2525 transform_and_round_points(graphics
, pti
, ptf
, 4);
2527 Polygon(graphics
->hdc
, pti
, 4);
2529 RestoreDC(graphics
->hdc
, save_state
);
2534 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
2540 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2543 return InvalidParameter
;
2545 for(i
= 0; i
< count
; i
++){
2546 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
2547 if(ret
!= Ok
) return ret
;
2553 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
2560 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2562 if(!rects
|| count
<= 0)
2563 return InvalidParameter
;
2565 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
2569 for(i
= 0; i
< count
; i
++){
2570 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2571 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2572 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
2573 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2576 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
2582 /*****************************************************************************
2583 * GdipFillRegion [GDIPLUS.@]
2585 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
2592 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
2594 if (!(graphics
&& brush
&& region
))
2595 return InvalidParameter
;
2600 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
2604 save_state
= SaveDC(graphics
->hdc
);
2605 EndPath(graphics
->hdc
);
2606 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2608 FillRgn(graphics
->hdc
, hrgn
, brush
->gdibrush
);
2610 RestoreDC(graphics
->hdc
, save_state
);
2617 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
2622 return InvalidParameter
;
2628 FIXME("not implemented\n");
2630 return NotImplemented
;
2633 /*****************************************************************************
2634 * GdipGetClipBounds [GDIPLUS.@]
2636 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
2638 TRACE("(%p, %p)\n", graphics
, rect
);
2641 return InvalidParameter
;
2646 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
2649 /*****************************************************************************
2650 * GdipGetClipBoundsI [GDIPLUS.@]
2652 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
2654 TRACE("(%p, %p)\n", graphics
, rect
);
2657 return InvalidParameter
;
2662 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
2665 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
2666 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
2667 CompositingMode
*mode
)
2669 TRACE("(%p, %p)\n", graphics
, mode
);
2671 if(!graphics
|| !mode
)
2672 return InvalidParameter
;
2677 *mode
= graphics
->compmode
;
2682 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
2683 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
2684 CompositingQuality
*quality
)
2686 TRACE("(%p, %p)\n", graphics
, quality
);
2688 if(!graphics
|| !quality
)
2689 return InvalidParameter
;
2694 *quality
= graphics
->compqual
;
2699 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
2700 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
2701 InterpolationMode
*mode
)
2703 TRACE("(%p, %p)\n", graphics
, mode
);
2705 if(!graphics
|| !mode
)
2706 return InvalidParameter
;
2711 *mode
= graphics
->interpolation
;
2716 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
2718 if(!graphics
|| !argb
)
2719 return InvalidParameter
;
2724 FIXME("(%p, %p): stub\n", graphics
, argb
);
2726 return NotImplemented
;
2729 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
2731 TRACE("(%p, %p)\n", graphics
, scale
);
2733 if(!graphics
|| !scale
)
2734 return InvalidParameter
;
2739 *scale
= graphics
->scale
;
2744 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
2746 TRACE("(%p, %p)\n", graphics
, unit
);
2748 if(!graphics
|| !unit
)
2749 return InvalidParameter
;
2754 *unit
= graphics
->unit
;
2759 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
2760 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
2763 TRACE("(%p, %p)\n", graphics
, mode
);
2765 if(!graphics
|| !mode
)
2766 return InvalidParameter
;
2771 *mode
= graphics
->pixeloffset
;
2776 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
2777 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
2779 TRACE("(%p, %p)\n", graphics
, mode
);
2781 if(!graphics
|| !mode
)
2782 return InvalidParameter
;
2787 *mode
= graphics
->smoothing
;
2792 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
2794 TRACE("(%p, %p)\n", graphics
, contrast
);
2796 if(!graphics
|| !contrast
)
2797 return InvalidParameter
;
2799 *contrast
= graphics
->textcontrast
;
2804 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
2805 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
2806 TextRenderingHint
*hint
)
2808 TRACE("(%p, %p)\n", graphics
, hint
);
2810 if(!graphics
|| !hint
)
2811 return InvalidParameter
;
2816 *hint
= graphics
->texthint
;
2821 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
2823 TRACE("(%p, %p)\n", graphics
, matrix
);
2825 if(!graphics
|| !matrix
)
2826 return InvalidParameter
;
2831 *matrix
= *graphics
->worldtrans
;
2835 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
2841 TRACE("(%p, %x)\n", graphics
, color
);
2844 return InvalidParameter
;
2849 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
2853 if(!GetWindowRect(graphics
->hwnd
, &rect
)){
2854 GdipDeleteBrush((GpBrush
*)brush
);
2855 return GenericError
;
2858 GdipFillRectangle(graphics
, (GpBrush
*)brush
, 0.0, 0.0, (REAL
)(rect
.right
- rect
.left
),
2859 (REAL
)(rect
.bottom
- rect
.top
));
2862 GdipFillRectangle(graphics
, (GpBrush
*)brush
, 0.0, 0.0, (REAL
)GetDeviceCaps(graphics
->hdc
, HORZRES
),
2863 (REAL
)GetDeviceCaps(graphics
->hdc
, VERTRES
));
2865 GdipDeleteBrush((GpBrush
*)brush
);
2870 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
2872 TRACE("(%p, %p)\n", graphics
, res
);
2874 if(!graphics
|| !res
)
2875 return InvalidParameter
;
2877 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
2880 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
2882 FIXME("(%p, %.2f, %.2f, %p) stub\n", graphics
, x
, y
, result
);
2884 if(!graphics
|| !result
)
2885 return InvalidParameter
;
2890 return NotImplemented
;
2893 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
2895 FIXME("(%p, %d, %d, %p) stub\n", graphics
, x
, y
, result
);
2897 if(!graphics
|| !result
)
2898 return InvalidParameter
;
2903 return NotImplemented
;
2906 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
2907 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
2908 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
2909 INT regionCount
, GpRegion
** regions
)
2911 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
2912 return InvalidParameter
;
2914 FIXME("stub: %p %s %d %p %p %p %d %p\n", graphics
, debugstr_w(string
),
2915 length
, font
, layoutRect
, stringFormat
, regionCount
, regions
);
2917 return NotImplemented
;
2920 /* Find the smallest rectangle that bounds the text when it is printed in rect
2921 * according to the format options listed in format. If rect has 0 width and
2922 * height, then just find the smallest rectangle that bounds the text when it's
2923 * printed at location (rect->X, rect-Y). */
2924 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
2925 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
2926 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
2927 INT
*codepointsfitted
, INT
*linesfilled
)
2931 INT sum
= 0, height
= 0, fit
, fitcpy
, max_width
= 0, i
, j
, lret
, nwidth
,
2935 if(!graphics
|| !string
|| !font
|| !rect
)
2936 return InvalidParameter
;
2938 if(linesfilled
) *linesfilled
= 0;
2939 if(codepointsfitted
) *codepointsfitted
= 0;
2942 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
2944 if(length
== -1) length
= lstrlenW(string
);
2946 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
2947 if(!stringdup
) return OutOfMemory
;
2949 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
2950 nwidth
= roundr(rect
->Width
);
2951 nheight
= roundr(rect
->Height
);
2953 if((nwidth
== 0) && (nheight
== 0))
2954 nwidth
= nheight
= INT_MAX
;
2956 for(i
= 0, j
= 0; i
< length
; i
++){
2957 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
2960 stringdup
[j
] = string
[i
];
2967 while(sum
< length
){
2968 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
2969 nwidth
, &fit
, NULL
, &size
);
2975 for(lret
= 0; lret
< fit
; lret
++)
2976 if(*(stringdup
+ sum
+ lret
) == '\n')
2979 /* Line break code (may look strange, but it imitates windows). */
2981 fit
= lret
; /* this is not an off-by-one error */
2982 else if(fit
< (length
- sum
)){
2983 if(*(stringdup
+ sum
+ fit
) == ' ')
2984 while(*(stringdup
+ sum
+ fit
) == ' ')
2987 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
2990 if(*(stringdup
+ sum
+ fit
) == '\t')
3000 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, fit
,
3001 nwidth
, &j
, NULL
, &size
);
3003 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
3004 if(codepointsfitted
) *codepointsfitted
= sum
;
3007 if(linesfilled
) *linesfilled
+= size
.cy
;
3008 max_width
= max(max_width
, size
.cx
);
3010 if(height
> nheight
)
3013 /* Stop if this was a linewrap (but not if it was a linebreak). */
3014 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
3018 bounds
->X
= rect
->X
;
3019 bounds
->Y
= rect
->Y
;
3020 bounds
->Width
= (REAL
)max_width
;
3021 bounds
->Height
= (REAL
) min(height
, nheight
);
3023 GdipFree(stringdup
);
3024 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
3029 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
3031 TRACE("(%p)\n", graphics
);
3034 return InvalidParameter
;
3039 return GdipSetInfinite(graphics
->clip
);
3042 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
3044 TRACE("(%p)\n", graphics
);
3047 return InvalidParameter
;
3052 graphics
->worldtrans
->matrix
[0] = 1.0;
3053 graphics
->worldtrans
->matrix
[1] = 0.0;
3054 graphics
->worldtrans
->matrix
[2] = 0.0;
3055 graphics
->worldtrans
->matrix
[3] = 1.0;
3056 graphics
->worldtrans
->matrix
[4] = 0.0;
3057 graphics
->worldtrans
->matrix
[5] = 0.0;
3062 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
3067 return InvalidParameter
;
3070 FIXME("graphics state not implemented\n");
3075 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
3076 GpMatrixOrder order
)
3078 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
3081 return InvalidParameter
;
3086 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
3089 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
3093 if(!graphics
|| !state
)
3094 return InvalidParameter
;
3097 FIXME("graphics state not implemented\n");
3099 *state
= 0xdeadbeef;
3103 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
, GraphicsContainer
*state
)
3105 FIXME("(%p, %p)\n", graphics
, state
);
3107 if(!graphics
|| !state
)
3108 return InvalidParameter
;
3110 *state
= 0xdeadbeef;
3114 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsState state
)
3116 FIXME("(%p, 0x%x)\n", graphics
, state
);
3118 if(!graphics
|| !state
)
3119 return InvalidParameter
;
3124 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
3125 REAL sy
, GpMatrixOrder order
)
3127 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
3130 return InvalidParameter
;
3135 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
3138 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
3141 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
3143 if(!graphics
|| !srcgraphics
)
3144 return InvalidParameter
;
3146 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
3149 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
3150 CompositingMode mode
)
3152 TRACE("(%p, %d)\n", graphics
, mode
);
3155 return InvalidParameter
;
3160 graphics
->compmode
= mode
;
3165 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
3166 CompositingQuality quality
)
3168 TRACE("(%p, %d)\n", graphics
, quality
);
3171 return InvalidParameter
;
3176 graphics
->compqual
= quality
;
3181 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
3182 InterpolationMode mode
)
3184 TRACE("(%p, %d)\n", graphics
, mode
);
3187 return InvalidParameter
;
3192 graphics
->interpolation
= mode
;
3197 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
3199 TRACE("(%p, %.2f)\n", graphics
, scale
);
3201 if(!graphics
|| (scale
<= 0.0))
3202 return InvalidParameter
;
3207 graphics
->scale
= scale
;
3212 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
3214 TRACE("(%p, %d)\n", graphics
, unit
);
3217 return InvalidParameter
;
3222 if(unit
== UnitWorld
)
3223 return InvalidParameter
;
3225 graphics
->unit
= unit
;
3230 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3233 TRACE("(%p, %d)\n", graphics
, mode
);
3236 return InvalidParameter
;
3241 graphics
->pixeloffset
= mode
;
3246 GpStatus WINGDIPAPI
GdipSetRenderingOrigin(GpGraphics
*graphics
, INT x
, INT y
)
3250 TRACE("(%p,%i,%i)\n", graphics
, x
, y
);
3253 FIXME("not implemented\n");
3255 return NotImplemented
;
3258 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
3260 TRACE("(%p, %d)\n", graphics
, mode
);
3263 return InvalidParameter
;
3268 graphics
->smoothing
= mode
;
3273 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
3275 TRACE("(%p, %d)\n", graphics
, contrast
);
3278 return InvalidParameter
;
3280 graphics
->textcontrast
= contrast
;
3285 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
3286 TextRenderingHint hint
)
3288 TRACE("(%p, %d)\n", graphics
, hint
);
3291 return InvalidParameter
;
3296 graphics
->texthint
= hint
;
3301 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3303 TRACE("(%p, %p)\n", graphics
, matrix
);
3305 if(!graphics
|| !matrix
)
3306 return InvalidParameter
;
3311 GdipDeleteMatrix(graphics
->worldtrans
);
3312 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
3315 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
3316 REAL dy
, GpMatrixOrder order
)
3318 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
3321 return InvalidParameter
;
3326 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
3329 /*****************************************************************************
3330 * GdipSetClipHrgn [GDIPLUS.@]
3332 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
3337 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
3340 return InvalidParameter
;
3342 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
3346 status
= GdipSetClipRegion(graphics
, region
, mode
);
3348 GdipDeleteRegion(region
);
3352 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
3354 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
3357 return InvalidParameter
;
3362 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
3365 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
3366 REAL width
, REAL height
,
3371 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3374 return InvalidParameter
;
3382 rect
.Height
= height
;
3384 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
3387 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
3388 INT width
, INT height
,
3391 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3394 return InvalidParameter
;
3399 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
3402 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
3405 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
3407 if(!graphics
|| !region
)
3408 return InvalidParameter
;
3413 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
3416 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
3422 FIXME("not implemented\n");
3424 return NotImplemented
;
3427 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
3433 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
3435 if(!graphics
|| !pen
|| count
<=0)
3436 return InvalidParameter
;
3441 pti
= GdipAlloc(sizeof(POINT
) * count
);
3443 save_state
= prepare_dc(graphics
, pen
);
3444 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3446 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
3447 Polygon(graphics
->hdc
, pti
, count
);
3449 restore_dc(graphics
, save_state
);
3455 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
3462 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3464 if(count
<=0) return InvalidParameter
;
3465 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
3467 for(i
= 0;i
< count
; i
++){
3468 ptf
[i
].X
= (REAL
)points
[i
].X
;
3469 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3472 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
3478 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
3480 TRACE("(%p, %p)\n", graphics
, dpi
);
3482 if(!graphics
|| !dpi
)
3483 return InvalidParameter
;
3488 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
3493 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
3495 TRACE("(%p, %p)\n", graphics
, dpi
);
3497 if(!graphics
|| !dpi
)
3498 return InvalidParameter
;
3503 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
3508 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
3509 GpMatrixOrder order
)
3514 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
3516 if(!graphics
|| !matrix
)
3517 return InvalidParameter
;
3522 m
= *(graphics
->worldtrans
);
3524 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
3526 *(graphics
->worldtrans
) = m
;
3531 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
3533 TRACE("(%p, %p)\n", graphics
, hdc
);
3535 if(!graphics
|| !hdc
)
3536 return InvalidParameter
;
3541 *hdc
= graphics
->hdc
;
3542 graphics
->busy
= TRUE
;
3547 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
3549 TRACE("(%p, %p)\n", graphics
, hdc
);
3552 return InvalidParameter
;
3554 if(graphics
->hdc
!= hdc
|| !(graphics
->busy
))
3555 return InvalidParameter
;
3557 graphics
->busy
= FALSE
;
3562 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
3567 TRACE("(%p, %p)\n", graphics
, region
);
3569 if(!graphics
|| !region
)
3570 return InvalidParameter
;
3575 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
3578 /* free everything except root node and header */
3579 delete_element(®ion
->node
);
3580 memcpy(region
, clip
, sizeof(GpRegion
));
3585 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
3586 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
3588 if(!graphics
|| !points
|| count
<= 0)
3589 return InvalidParameter
;
3594 FIXME("(%p, %d, %d, %p, %d): stub\n", graphics
, dst_space
, src_space
, points
, count
);
3596 return NotImplemented
;
3599 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
3600 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
3602 FIXME("(%p, %d, %d, %p, %d): stub\n", graphics
, dst_space
, src_space
, points
, count
);
3604 return NotImplemented
;
3607 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
3614 /*****************************************************************************
3615 * GdipTranslateClip [GDIPLUS.@]
3617 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
3619 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
3622 return InvalidParameter
;
3627 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
3630 /*****************************************************************************
3631 * GdipTranslateClipI [GDIPLUS.@]
3633 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
3635 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
3638 return InvalidParameter
;
3643 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);