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
, int current
, int total
)
179 for (i
=0xff; i
<=0xff0000; i
= i
<< 8)
180 result
|= (((start
&i
)*(total
- current
)+(end
&i
)*(current
))/total
)&i
;
184 static void brush_fill_path(GpGraphics
*graphics
, GpBrush
* brush
)
188 case BrushTypeLinearGradient
:
190 GpLineGradient
*line
= (GpLineGradient
*)brush
;
194 SelectClipPath(graphics
->hdc
, RGN_AND
);
195 if (GetClipBox(graphics
->hdc
, &rc
) != NULLREGION
)
197 GpPointF endpointsf
[2];
201 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
203 /* fill with starting color */
204 FillRect(graphics
->hdc
, &rc
, brush
->gdibrush
);
206 endpointsf
[0] = line
->startpoint
;
207 endpointsf
[1] = line
->endpoint
;
208 transform_and_round_points(graphics
, endpointsi
, endpointsf
, 2);
210 if (abs(endpointsi
[0].x
-endpointsi
[1].x
) > abs(endpointsi
[0].y
-endpointsi
[1].y
))
212 /* vertical-ish gradient */
213 int endborderx
; /* vertical rectangle boundary near endpoint */
214 int startx
, endx
; /* x co-ordinates of endpoints shifted to intersect the top of the visible rectangle */
215 int startbottomx
, endbottomx
; /* x co-ordinate of endpoints shifted to intersect the bottom of the visible rectangle */
218 HBRUSH hbrush
, hprevbrush
;
221 if (endpointsi
[1].x
> endpointsi
[0].x
)
222 endborderx
= rc
.right
;
224 endborderx
= rc
.left
;
226 startx
= roundr((rc
.top
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
227 endx
= roundr((rc
.top
- endpointsf
[1].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[1].X
);
228 width
= endx
- startx
;
229 startbottomx
= roundr((rc
.bottom
- endpointsf
[0].Y
) * (endpointsf
[1].Y
- endpointsf
[0].Y
) / (endpointsf
[0].X
- endpointsf
[1].X
) + endpointsf
[0].X
);
230 endbottomx
= startbottomx
+width
;
232 if (num_steps
> abs(width
)) num_steps
= abs(width
);
234 poly
[0].x
= endborderx
;
235 poly
[0].y
= rc
.bottom
;
236 poly
[1].x
= endborderx
;
239 poly
[3].y
= rc
.bottom
;
241 for (i
=1; i
<num_steps
; i
++)
243 ARGB argb
= blend_colors(line
->startcolor
, line
->endcolor
, i
, num_steps
);
244 int ofs
= width
* i
/ num_steps
;
245 col
= ARGB2COLORREF(argb
);
246 hbrush
= CreateSolidBrush(col
);
247 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
248 poly
[2].x
= startx
+ ofs
;
249 poly
[3].x
= startbottomx
+ ofs
;
250 Polygon(graphics
->hdc
, poly
, 4);
251 SelectObject(graphics
->hdc
, hprevbrush
);
252 DeleteObject(hbrush
);
256 poly
[3].x
= endbottomx
;
258 /* draw the ending color */
259 col
= ARGB2COLORREF(line
->endcolor
);
260 hbrush
= CreateSolidBrush(col
);
261 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
262 Polygon(graphics
->hdc
, poly
, 4);
263 SelectObject(graphics
->hdc
, hprevbrush
);
264 DeleteObject(hbrush
);
266 else if (endpointsi
[0].y
!= endpointsi
[1].y
)
268 /* horizontal-ish gradient */
269 int endbordery
; /* horizontal rectangle boundary near endpoint */
270 int starty
, endy
; /* y co-ordinates of endpoints shifted to intersect the left of the visible rectangle */
271 int startrighty
, endrighty
; /* y co-ordinate of endpoints shifted to intersect the right of the visible rectangle */
274 HBRUSH hbrush
, hprevbrush
;
277 if (endpointsi
[1].y
> endpointsi
[0].y
)
278 endbordery
= rc
.bottom
;
282 starty
= roundr((rc
.left
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
283 endy
= roundr((rc
.left
- endpointsf
[1].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[1].Y
);
284 height
= endy
- starty
;
285 startrighty
= roundr((rc
.right
- endpointsf
[0].X
) * (endpointsf
[0].X
- endpointsf
[1].X
) / (endpointsf
[1].Y
- endpointsf
[0].Y
) + endpointsf
[0].Y
);
286 endrighty
= startrighty
+height
;
288 if (num_steps
> abs(height
)) num_steps
= abs(height
);
290 poly
[0].x
= rc
.right
;
291 poly
[0].y
= endbordery
;
293 poly
[1].y
= endbordery
;
295 poly
[3].x
= rc
.right
;
297 for (i
=1; i
<num_steps
; i
++)
299 ARGB argb
= blend_colors(line
->startcolor
, line
->endcolor
, i
, num_steps
);
300 int ofs
= height
* i
/ num_steps
;
301 col
= ARGB2COLORREF(argb
);
302 hbrush
= CreateSolidBrush(col
);
303 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
304 poly
[2].y
= starty
+ ofs
;
305 poly
[3].y
= startrighty
+ ofs
;
306 Polygon(graphics
->hdc
, poly
, 4);
307 SelectObject(graphics
->hdc
, hprevbrush
);
308 DeleteObject(hbrush
);
312 poly
[3].y
= endrighty
;
314 /* draw the ending color */
315 col
= ARGB2COLORREF(line
->endcolor
);
316 hbrush
= CreateSolidBrush(col
);
317 hprevbrush
= SelectObject(graphics
->hdc
, hbrush
);
318 Polygon(graphics
->hdc
, poly
, 4);
319 SelectObject(graphics
->hdc
, hprevbrush
);
320 DeleteObject(hbrush
);
322 /* else startpoint == endpoint */
327 SelectObject(graphics
->hdc
, brush
->gdibrush
);
328 FillPath(graphics
->hdc
);
333 /* GdipDrawPie/GdipFillPie helper function */
334 static void draw_pie(GpGraphics
*graphics
, REAL x
, REAL y
, REAL width
,
335 REAL height
, REAL startAngle
, REAL sweepAngle
)
342 ptf
[1].X
= x
+ width
;
343 ptf
[1].Y
= y
+ height
;
345 deg2xy(startAngle
+sweepAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[2].X
, &ptf
[2].Y
);
346 deg2xy(startAngle
, x
+ width
/ 2.0, y
+ width
/ 2.0, &ptf
[3].X
, &ptf
[3].Y
);
348 transform_and_round_points(graphics
, pti
, ptf
, 4);
350 Pie(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
, pti
[2].x
,
351 pti
[2].y
, pti
[3].x
, pti
[3].y
);
354 /* Draws the linecap the specified color and size on the hdc. The linecap is in
355 * direction of the line from x1, y1 to x2, y2 and is anchored on x2, y2. Probably
356 * should not be called on an hdc that has a path you care about. */
357 static void draw_cap(GpGraphics
*graphics
, COLORREF color
, GpLineCap cap
, REAL size
,
358 const GpCustomLineCap
*custom
, REAL x1
, REAL y1
, REAL x2
, REAL y2
)
360 HGDIOBJ oldbrush
= NULL
, oldpen
= NULL
;
361 GpMatrix
*matrix
= NULL
;
364 PointF ptf
[4], *custptf
= NULL
;
365 POINT pt
[4], *custpt
= NULL
;
367 REAL theta
, dsmall
, dbig
, dx
, dy
= 0.0;
372 if((x1
== x2
) && (y1
== y2
))
375 theta
= gdiplus_atan2(y2
- y1
, x2
- x1
);
377 customstroke
= (cap
== LineCapCustom
) && custom
&& (!custom
->fill
);
379 brush
= CreateSolidBrush(color
);
380 lb
.lbStyle
= BS_SOLID
;
383 pen
= ExtCreatePen(PS_GEOMETRIC
| PS_SOLID
| PS_ENDCAP_FLAT
|
384 PS_JOIN_MITER
, 1, &lb
, 0,
386 oldbrush
= SelectObject(graphics
->hdc
, brush
);
387 oldpen
= SelectObject(graphics
->hdc
, pen
);
394 case LineCapSquareAnchor
:
395 case LineCapDiamondAnchor
:
396 size
= size
* (cap
& LineCapNoAnchor
? ANCHOR_WIDTH
: 1.0) / 2.0;
397 if(cap
== LineCapDiamondAnchor
){
398 dsmall
= cos(theta
+ M_PI_2
) * size
;
399 dbig
= sin(theta
+ M_PI_2
) * size
;
402 dsmall
= cos(theta
+ M_PI_4
) * size
;
403 dbig
= sin(theta
+ M_PI_4
) * size
;
406 ptf
[0].X
= x2
- dsmall
;
407 ptf
[1].X
= x2
+ dbig
;
409 ptf
[0].Y
= y2
- dbig
;
410 ptf
[3].Y
= y2
+ dsmall
;
412 ptf
[1].Y
= y2
- dsmall
;
413 ptf
[2].Y
= y2
+ dbig
;
415 ptf
[3].X
= x2
- dbig
;
416 ptf
[2].X
= x2
+ dsmall
;
418 transform_and_round_points(graphics
, pt
, ptf
, 4);
419 Polygon(graphics
->hdc
, pt
, 4);
422 case LineCapArrowAnchor
:
423 size
= size
* 4.0 / sqrt(3.0);
425 dx
= cos(M_PI
/ 6.0 + theta
) * size
;
426 dy
= sin(M_PI
/ 6.0 + theta
) * size
;
431 dx
= cos(- M_PI
/ 6.0 + theta
) * size
;
432 dy
= sin(- M_PI
/ 6.0 + theta
) * size
;
440 transform_and_round_points(graphics
, pt
, ptf
, 3);
441 Polygon(graphics
->hdc
, pt
, 3);
444 case LineCapRoundAnchor
:
445 dx
= dy
= ANCHOR_WIDTH
* size
/ 2.0;
452 transform_and_round_points(graphics
, pt
, ptf
, 2);
453 Ellipse(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
);
456 case LineCapTriangle
:
458 dx
= cos(M_PI_2
+ theta
) * size
;
459 dy
= sin(M_PI_2
+ theta
) * size
;
466 dx
= cos(theta
) * size
;
467 dy
= sin(theta
) * size
;
472 transform_and_round_points(graphics
, pt
, ptf
, 3);
473 Polygon(graphics
->hdc
, pt
, 3);
477 dx
= dy
= size
/ 2.0;
484 dx
= -cos(M_PI_2
+ theta
) * size
;
485 dy
= -sin(M_PI_2
+ theta
) * size
;
492 transform_and_round_points(graphics
, pt
, ptf
, 4);
493 Pie(graphics
->hdc
, pt
[0].x
, pt
[0].y
, pt
[1].x
, pt
[1].y
, pt
[2].x
,
494 pt
[2].y
, pt
[3].x
, pt
[3].y
);
501 count
= custom
->pathdata
.Count
;
502 custptf
= GdipAlloc(count
* sizeof(PointF
));
503 custpt
= GdipAlloc(count
* sizeof(POINT
));
504 tp
= GdipAlloc(count
);
506 if(!custptf
|| !custpt
|| !tp
|| (GdipCreateMatrix(&matrix
) != Ok
))
509 memcpy(custptf
, custom
->pathdata
.Points
, count
* sizeof(PointF
));
511 GdipScaleMatrix(matrix
, size
, size
, MatrixOrderAppend
);
512 GdipRotateMatrix(matrix
, (180.0 / M_PI
) * (theta
- M_PI_2
),
514 GdipTranslateMatrix(matrix
, x2
, y2
, MatrixOrderAppend
);
515 GdipTransformMatrixPoints(matrix
, custptf
, count
);
517 transform_and_round_points(graphics
, custpt
, custptf
, count
);
519 for(i
= 0; i
< count
; i
++)
520 tp
[i
] = convert_path_point_type(custom
->pathdata
.Types
[i
]);
523 BeginPath(graphics
->hdc
);
524 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
525 EndPath(graphics
->hdc
);
526 StrokeAndFillPath(graphics
->hdc
);
529 PolyDraw(graphics
->hdc
, custpt
, tp
, count
);
535 GdipDeleteMatrix(matrix
);
542 SelectObject(graphics
->hdc
, oldbrush
);
543 SelectObject(graphics
->hdc
, oldpen
);
549 /* Shortens the line by the given percent by changing x2, y2.
550 * If percent is > 1.0 then the line will change direction.
551 * If percent is negative it can lengthen the line. */
552 static void shorten_line_percent(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL percent
)
554 REAL dist
, theta
, dx
, dy
;
556 if((y1
== *y2
) && (x1
== *x2
))
559 dist
= sqrt((*x2
- x1
) * (*x2
- x1
) + (*y2
- y1
) * (*y2
- y1
)) * -percent
;
560 theta
= gdiplus_atan2((*y2
- y1
), (*x2
- x1
));
561 dx
= cos(theta
) * dist
;
562 dy
= sin(theta
) * dist
;
568 /* Shortens the line by the given amount by changing x2, y2.
569 * If the amount is greater than the distance, the line will become length 0.
570 * If the amount is negative, it can lengthen the line. */
571 static void shorten_line_amt(REAL x1
, REAL y1
, REAL
*x2
, REAL
*y2
, REAL amt
)
573 REAL dx
, dy
, percent
;
577 if(dx
== 0 && dy
== 0)
580 percent
= amt
/ sqrt(dx
* dx
+ dy
* dy
);
587 shorten_line_percent(x1
, y1
, x2
, y2
, percent
);
590 /* Draws lines between the given points, and if caps is true then draws an endcap
591 * at the end of the last line. */
592 static GpStatus
draw_polyline(GpGraphics
*graphics
, GpPen
*pen
,
593 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
596 GpPointF
*ptcopy
= NULL
;
597 GpStatus status
= GenericError
;
602 pti
= GdipAlloc(count
* sizeof(POINT
));
603 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
606 status
= OutOfMemory
;
610 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
613 if(pen
->endcap
== LineCapArrowAnchor
)
614 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
615 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
, pen
->width
);
616 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
617 shorten_line_amt(ptcopy
[count
-2].X
, ptcopy
[count
-2].Y
,
618 &ptcopy
[count
-1].X
, &ptcopy
[count
-1].Y
,
619 pen
->customend
->inset
* pen
->width
);
621 if(pen
->startcap
== LineCapArrowAnchor
)
622 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
623 &ptcopy
[0].X
, &ptcopy
[0].Y
, pen
->width
);
624 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
625 shorten_line_amt(ptcopy
[1].X
, ptcopy
[1].Y
,
626 &ptcopy
[0].X
, &ptcopy
[0].Y
,
627 pen
->customstart
->inset
* pen
->width
);
629 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
630 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
, pt
[count
- 1].Y
);
631 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
632 pt
[1].X
, pt
[1].Y
, pt
[0].X
, pt
[0].Y
);
635 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
637 if(Polyline(graphics
->hdc
, pti
, count
))
647 /* Conducts a linear search to find the bezier points that will back off
648 * the endpoint of the curve by a distance of amt. Linear search works
649 * better than binary in this case because there are multiple solutions,
650 * and binary searches often find a bad one. I don't think this is what
651 * Windows does but short of rendering the bezier without GDI's help it's
652 * the best we can do. If rev then work from the start of the passed points
653 * instead of the end. */
654 static void shorten_bezier_amt(GpPointF
* pt
, REAL amt
, BOOL rev
)
657 REAL percent
= 0.00, dx
, dy
, origx
, origy
, diff
= -1.0;
658 INT i
, first
= 0, second
= 1, third
= 2, fourth
= 3;
667 origx
= pt
[fourth
].X
;
668 origy
= pt
[fourth
].Y
;
669 memcpy(origpt
, pt
, sizeof(GpPointF
) * 4);
671 for(i
= 0; (i
< MAX_ITERS
) && (diff
< amt
); i
++){
672 /* reset bezier points to original values */
673 memcpy(pt
, origpt
, sizeof(GpPointF
) * 4);
674 /* Perform magic on bezier points. Order is important here.*/
675 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
676 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
677 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
678 shorten_line_percent(pt
[first
].X
, pt
[first
].Y
, &pt
[second
].X
, &pt
[second
].Y
, percent
);
679 shorten_line_percent(pt
[second
].X
, pt
[second
].Y
, &pt
[third
].X
, &pt
[third
].Y
, percent
);
680 shorten_line_percent(pt
[third
].X
, pt
[third
].Y
, &pt
[fourth
].X
, &pt
[fourth
].Y
, percent
);
682 dx
= pt
[fourth
].X
- origx
;
683 dy
= pt
[fourth
].Y
- origy
;
685 diff
= sqrt(dx
* dx
+ dy
* dy
);
686 percent
+= 0.0005 * amt
;
690 /* Draws bezier curves between given points, and if caps is true then draws an
691 * endcap at the end of the last line. */
692 static GpStatus
draw_polybezier(GpGraphics
*graphics
, GpPen
*pen
,
693 GDIPCONST GpPointF
* pt
, INT count
, BOOL caps
)
697 GpStatus status
= GenericError
;
702 pti
= GdipAlloc(count
* sizeof(POINT
));
703 ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
706 status
= OutOfMemory
;
710 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
713 if(pen
->endcap
== LineCapArrowAnchor
)
714 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
, FALSE
);
715 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
716 shorten_bezier_amt(&ptcopy
[count
-4], pen
->width
* pen
->customend
->inset
,
719 if(pen
->startcap
== LineCapArrowAnchor
)
720 shorten_bezier_amt(ptcopy
, pen
->width
, TRUE
);
721 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
722 shorten_bezier_amt(ptcopy
, pen
->width
* pen
->customstart
->inset
, TRUE
);
724 /* the direction of the line cap is parallel to the direction at the
725 * end of the bezier (which, if it has been shortened, is not the same
726 * as the direction from pt[count-2] to pt[count-1]) */
727 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
728 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
729 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
730 pt
[count
- 1].X
, pt
[count
- 1].Y
);
732 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
733 pt
[0].X
- (ptcopy
[0].X
- ptcopy
[1].X
),
734 pt
[0].Y
- (ptcopy
[0].Y
- ptcopy
[1].Y
), pt
[0].X
, pt
[0].Y
);
737 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
739 PolyBezier(graphics
->hdc
, pti
, count
);
750 /* Draws a combination of bezier curves and lines between points. */
751 static GpStatus
draw_poly(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST GpPointF
* pt
,
752 GDIPCONST BYTE
* types
, INT count
, BOOL caps
)
754 POINT
*pti
= GdipAlloc(count
* sizeof(POINT
));
755 BYTE
*tp
= GdipAlloc(count
);
756 GpPointF
*ptcopy
= GdipAlloc(count
* sizeof(GpPointF
));
758 GpStatus status
= GenericError
;
764 if(!pti
|| !tp
|| !ptcopy
){
765 status
= OutOfMemory
;
769 for(i
= 1; i
< count
; i
++){
770 if((types
[i
] & PathPointTypePathTypeMask
) == PathPointTypeBezier
){
771 if((i
+ 2 >= count
) || !(types
[i
+ 1] & PathPointTypeBezier
)
772 || !(types
[i
+ 1] & PathPointTypeBezier
)){
773 ERR("Bad bezier points\n");
780 memcpy(ptcopy
, pt
, count
* sizeof(GpPointF
));
782 /* If we are drawing caps, go through the points and adjust them accordingly,
783 * and draw the caps. */
785 switch(types
[count
- 1] & PathPointTypePathTypeMask
){
786 case PathPointTypeBezier
:
787 if(pen
->endcap
== LineCapArrowAnchor
)
788 shorten_bezier_amt(&ptcopy
[count
- 4], pen
->width
, FALSE
);
789 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
790 shorten_bezier_amt(&ptcopy
[count
- 4],
791 pen
->width
* pen
->customend
->inset
, FALSE
);
793 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
794 pt
[count
- 1].X
- (ptcopy
[count
- 1].X
- ptcopy
[count
- 2].X
),
795 pt
[count
- 1].Y
- (ptcopy
[count
- 1].Y
- ptcopy
[count
- 2].Y
),
796 pt
[count
- 1].X
, pt
[count
- 1].Y
);
799 case PathPointTypeLine
:
800 if(pen
->endcap
== LineCapArrowAnchor
)
801 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
802 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
804 else if((pen
->endcap
== LineCapCustom
) && pen
->customend
)
805 shorten_line_amt(ptcopy
[count
- 2].X
, ptcopy
[count
- 2].Y
,
806 &ptcopy
[count
- 1].X
, &ptcopy
[count
- 1].Y
,
807 pen
->customend
->inset
* pen
->width
);
809 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->endcap
, pen
->width
, pen
->customend
,
810 pt
[count
- 2].X
, pt
[count
- 2].Y
, pt
[count
- 1].X
,
815 ERR("Bad path last point\n");
819 /* Find start of points */
820 for(j
= 1; j
< count
&& ((types
[j
] & PathPointTypePathTypeMask
)
821 == PathPointTypeStart
); j
++);
823 switch(types
[j
] & PathPointTypePathTypeMask
){
824 case PathPointTypeBezier
:
825 if(pen
->startcap
== LineCapArrowAnchor
)
826 shorten_bezier_amt(&ptcopy
[j
- 1], pen
->width
, TRUE
);
827 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
828 shorten_bezier_amt(&ptcopy
[j
- 1],
829 pen
->width
* pen
->customstart
->inset
, TRUE
);
831 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
832 pt
[j
- 1].X
- (ptcopy
[j
- 1].X
- ptcopy
[j
].X
),
833 pt
[j
- 1].Y
- (ptcopy
[j
- 1].Y
- ptcopy
[j
].Y
),
834 pt
[j
- 1].X
, pt
[j
- 1].Y
);
837 case PathPointTypeLine
:
838 if(pen
->startcap
== LineCapArrowAnchor
)
839 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
840 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
842 else if((pen
->startcap
== LineCapCustom
) && pen
->customstart
)
843 shorten_line_amt(ptcopy
[j
].X
, ptcopy
[j
].Y
,
844 &ptcopy
[j
- 1].X
, &ptcopy
[j
- 1].Y
,
845 pen
->customstart
->inset
* pen
->width
);
847 draw_cap(graphics
, pen
->brush
->lb
.lbColor
, pen
->startcap
, pen
->width
, pen
->customstart
,
848 pt
[j
].X
, pt
[j
].Y
, pt
[j
- 1].X
,
853 ERR("Bad path points\n");
858 transform_and_round_points(graphics
, pti
, ptcopy
, count
);
860 for(i
= 0; i
< count
; i
++){
861 tp
[i
] = convert_path_point_type(types
[i
]);
864 PolyDraw(graphics
->hdc
, pti
, tp
, count
);
876 GpStatus
trace_path(GpGraphics
*graphics
, GpPath
*path
)
880 BeginPath(graphics
->hdc
);
881 result
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
882 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
883 EndPath(graphics
->hdc
);
887 GpStatus WINGDIPAPI
GdipCreateFromHDC(HDC hdc
, GpGraphics
**graphics
)
889 TRACE("(%p, %p)\n", hdc
, graphics
);
891 return GdipCreateFromHDC2(hdc
, NULL
, graphics
);
894 GpStatus WINGDIPAPI
GdipCreateFromHDC2(HDC hdc
, HANDLE hDevice
, GpGraphics
**graphics
)
898 TRACE("(%p, %p, %p)\n", hdc
, hDevice
, graphics
);
900 if(hDevice
!= NULL
) {
901 FIXME("Don't know how to hadle parameter hDevice\n");
902 return NotImplemented
;
909 return InvalidParameter
;
911 *graphics
= GdipAlloc(sizeof(GpGraphics
));
912 if(!*graphics
) return OutOfMemory
;
914 if((retval
= GdipCreateMatrix(&(*graphics
)->worldtrans
)) != Ok
){
919 if((retval
= GdipCreateRegion(&(*graphics
)->clip
)) != Ok
){
920 GdipFree((*graphics
)->worldtrans
);
925 (*graphics
)->hdc
= hdc
;
926 (*graphics
)->hwnd
= WindowFromDC(hdc
);
927 (*graphics
)->smoothing
= SmoothingModeDefault
;
928 (*graphics
)->compqual
= CompositingQualityDefault
;
929 (*graphics
)->interpolation
= InterpolationModeDefault
;
930 (*graphics
)->pixeloffset
= PixelOffsetModeDefault
;
931 (*graphics
)->compmode
= CompositingModeSourceOver
;
932 (*graphics
)->unit
= UnitDisplay
;
933 (*graphics
)->scale
= 1.0;
934 (*graphics
)->busy
= FALSE
;
935 (*graphics
)->textcontrast
= 4;
940 GpStatus WINGDIPAPI
GdipCreateFromHWND(HWND hwnd
, GpGraphics
**graphics
)
944 TRACE("(%p, %p)\n", hwnd
, graphics
);
946 if((ret
= GdipCreateFromHDC(GetDC(hwnd
), graphics
)) != Ok
)
949 (*graphics
)->hwnd
= hwnd
;
954 /* FIXME: no icm handling */
955 GpStatus WINGDIPAPI
GdipCreateFromHWNDICM(HWND hwnd
, GpGraphics
**graphics
)
957 TRACE("(%p, %p)\n", hwnd
, graphics
);
959 return GdipCreateFromHWND(hwnd
, graphics
);
962 GpStatus WINGDIPAPI
GdipCreateMetafileFromEmf(HENHMETAFILE hemf
, BOOL
delete,
963 GpMetafile
**metafile
)
967 if(!hemf
|| !metafile
)
968 return InvalidParameter
;
971 FIXME("not implemented\n");
973 return NotImplemented
;
976 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmf(HMETAFILE hwmf
, BOOL
delete,
977 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
979 IStream
*stream
= NULL
;
983 GpStatus retval
= GenericError
;
985 TRACE("(%p, %d, %p, %p)\n", hwmf
, delete, placeable
, metafile
);
987 if(!hwmf
|| !metafile
|| !placeable
)
988 return InvalidParameter
;
991 read
= GetMetaFileBitsEx(hwmf
, 0, NULL
);
994 copy
= GdipAlloc(read
);
995 GetMetaFileBitsEx(hwmf
, read
, copy
);
997 hemf
= SetWinMetaFileBits(read
, copy
, NULL
, NULL
);
1000 read
= GetEnhMetaFileBits(hemf
, 0, NULL
);
1001 copy
= GdipAlloc(read
);
1002 GetEnhMetaFileBits(hemf
, read
, copy
);
1003 DeleteEnhMetaFile(hemf
);
1005 if(CreateStreamOnHGlobal(copy
, TRUE
, &stream
) != S_OK
){
1006 ERR("could not make stream\n");
1011 *metafile
= GdipAlloc(sizeof(GpMetafile
));
1013 retval
= OutOfMemory
;
1017 if(OleLoadPicture(stream
, 0, FALSE
, &IID_IPicture
,
1018 (LPVOID
*) &((*metafile
)->image
.picture
)) != S_OK
)
1022 (*metafile
)->image
.type
= ImageTypeMetafile
;
1023 (*metafile
)->bounds
.X
= ((REAL
) placeable
->BoundingBox
.Left
) / ((REAL
) placeable
->Inch
);
1024 (*metafile
)->bounds
.Y
= ((REAL
) placeable
->BoundingBox
.Right
) / ((REAL
) placeable
->Inch
);
1025 (*metafile
)->bounds
.Width
= ((REAL
) (placeable
->BoundingBox
.Right
1026 - placeable
->BoundingBox
.Left
)) / ((REAL
) placeable
->Inch
);
1027 (*metafile
)->bounds
.Height
= ((REAL
) (placeable
->BoundingBox
.Bottom
1028 - placeable
->BoundingBox
.Top
)) / ((REAL
) placeable
->Inch
);
1029 (*metafile
)->unit
= UnitInch
;
1032 DeleteMetaFile(hwmf
);
1037 GdipFree(*metafile
);
1038 IStream_Release(stream
);
1042 GpStatus WINGDIPAPI
GdipCreateMetafileFromWmfFile(GDIPCONST WCHAR
*file
,
1043 GDIPCONST WmfPlaceableFileHeader
* placeable
, GpMetafile
**metafile
)
1045 HMETAFILE hmf
= GetMetaFileW(file
);
1047 TRACE("(%s, %p, %p)\n", debugstr_w(file
), placeable
, metafile
);
1049 if(!hmf
) return InvalidParameter
;
1051 return GdipCreateMetafileFromWmf(hmf
, TRUE
, placeable
, metafile
);
1054 GpStatus WINGDIPAPI
GdipCreateStreamOnFile(GDIPCONST WCHAR
* filename
,
1055 UINT access
, IStream
**stream
)
1060 TRACE("(%s, %u, %p)\n", debugstr_w(filename
), access
, stream
);
1062 if(!stream
|| !filename
)
1063 return InvalidParameter
;
1065 if(access
& GENERIC_WRITE
)
1066 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_WRITE
| STGM_CREATE
;
1067 else if(access
& GENERIC_READ
)
1068 dwMode
= STGM_SHARE_DENY_WRITE
| STGM_READ
| STGM_FAILIFTHERE
;
1070 return InvalidParameter
;
1072 ret
= SHCreateStreamOnFileW(filename
, dwMode
, stream
);
1074 return hresult_to_status(ret
);
1077 GpStatus WINGDIPAPI
GdipDeleteGraphics(GpGraphics
*graphics
)
1079 TRACE("(%p)\n", graphics
);
1081 if(!graphics
) return InvalidParameter
;
1082 if(graphics
->busy
) return ObjectBusy
;
1085 ReleaseDC(graphics
->hwnd
, graphics
->hdc
);
1087 GdipDeleteRegion(graphics
->clip
);
1088 GdipDeleteMatrix(graphics
->worldtrans
);
1094 GpStatus WINGDIPAPI
GdipDrawArc(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1095 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1097 INT save_state
, num_pts
;
1098 GpPointF points
[MAX_ARC_PTS
];
1101 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1102 width
, height
, startAngle
, sweepAngle
);
1104 if(!graphics
|| !pen
|| width
<= 0 || height
<= 0)
1105 return InvalidParameter
;
1110 num_pts
= arc2polybezier(points
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1112 save_state
= prepare_dc(graphics
, pen
);
1114 retval
= draw_polybezier(graphics
, pen
, points
, num_pts
, TRUE
);
1116 restore_dc(graphics
, save_state
);
1121 GpStatus WINGDIPAPI
GdipDrawArcI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1122 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1124 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1125 width
, height
, startAngle
, sweepAngle
);
1127 return GdipDrawArc(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1130 GpStatus WINGDIPAPI
GdipDrawBezier(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1131 REAL y1
, REAL x2
, REAL y2
, REAL x3
, REAL y3
, REAL x4
, REAL y4
)
1137 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
,
1138 x2
, y2
, x3
, y3
, x4
, y4
);
1140 if(!graphics
|| !pen
)
1141 return InvalidParameter
;
1155 save_state
= prepare_dc(graphics
, pen
);
1157 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1159 restore_dc(graphics
, save_state
);
1164 GpStatus WINGDIPAPI
GdipDrawBezierI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1165 INT y1
, INT x2
, INT y2
, INT x3
, INT y3
, INT x4
, INT y4
)
1171 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
,
1172 x2
, y2
, x3
, y3
, x4
, y4
);
1174 if(!graphics
|| !pen
)
1175 return InvalidParameter
;
1189 save_state
= prepare_dc(graphics
, pen
);
1191 retval
= draw_polybezier(graphics
, pen
, pt
, 4, TRUE
);
1193 restore_dc(graphics
, save_state
);
1198 GpStatus WINGDIPAPI
GdipDrawBeziers(GpGraphics
*graphics
, GpPen
*pen
,
1199 GDIPCONST GpPointF
*points
, INT count
)
1204 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1206 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1207 return InvalidParameter
;
1212 for(i
= 0; i
< floor(count
/ 4); i
++){
1213 ret
= GdipDrawBezier(graphics
, pen
,
1214 points
[4*i
].X
, points
[4*i
].Y
,
1215 points
[4*i
+ 1].X
, points
[4*i
+ 1].Y
,
1216 points
[4*i
+ 2].X
, points
[4*i
+ 2].Y
,
1217 points
[4*i
+ 3].X
, points
[4*i
+ 3].Y
);
1225 GpStatus WINGDIPAPI
GdipDrawBeziersI(GpGraphics
*graphics
, GpPen
*pen
,
1226 GDIPCONST GpPoint
*points
, INT count
)
1232 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1234 if(!graphics
|| !pen
|| !points
|| (count
<= 0))
1235 return InvalidParameter
;
1240 pts
= GdipAlloc(sizeof(GpPointF
) * count
);
1244 for(i
= 0; i
< count
; i
++){
1245 pts
[i
].X
= (REAL
)points
[i
].X
;
1246 pts
[i
].Y
= (REAL
)points
[i
].Y
;
1249 ret
= GdipDrawBeziers(graphics
,pen
,pts
,count
);
1256 GpStatus WINGDIPAPI
GdipDrawClosedCurve(GpGraphics
*graphics
, GpPen
*pen
,
1257 GDIPCONST GpPointF
*points
, INT count
)
1259 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1261 return GdipDrawClosedCurve2(graphics
, pen
, points
, count
, 1.0);
1264 GpStatus WINGDIPAPI
GdipDrawClosedCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1265 GDIPCONST GpPoint
*points
, INT count
)
1267 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1269 return GdipDrawClosedCurve2I(graphics
, pen
, points
, count
, 1.0);
1272 GpStatus WINGDIPAPI
GdipDrawClosedCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1273 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1278 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1280 if(!graphics
|| !pen
|| !points
|| count
<= 0)
1281 return InvalidParameter
;
1286 if((stat
= GdipCreatePath(FillModeAlternate
, &path
)) != Ok
)
1289 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
1291 GdipDeletePath(path
);
1295 stat
= GdipDrawPath(graphics
, pen
, path
);
1297 GdipDeletePath(path
);
1302 GpStatus WINGDIPAPI
GdipDrawClosedCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1303 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1309 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1311 if(!points
|| count
<= 0)
1312 return InvalidParameter
;
1314 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
1318 for(i
= 0; i
< count
; i
++){
1319 ptf
[i
].X
= (REAL
)points
[i
].X
;
1320 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
1323 stat
= GdipDrawClosedCurve2(graphics
, pen
, ptf
, count
, tension
);
1330 GpStatus WINGDIPAPI
GdipDrawCurve(GpGraphics
*graphics
, GpPen
*pen
,
1331 GDIPCONST GpPointF
*points
, INT count
)
1333 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1335 return GdipDrawCurve2(graphics
,pen
,points
,count
,1.0);
1338 GpStatus WINGDIPAPI
GdipDrawCurveI(GpGraphics
*graphics
, GpPen
*pen
,
1339 GDIPCONST GpPoint
*points
, INT count
)
1345 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1347 if(!points
|| count
<= 0)
1348 return InvalidParameter
;
1350 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1354 for(i
= 0; i
< count
; i
++){
1355 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1356 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1359 ret
= GdipDrawCurve(graphics
,pen
,pointsF
,count
);
1365 /* Approximates cardinal spline with Bezier curves. */
1366 GpStatus WINGDIPAPI
GdipDrawCurve2(GpGraphics
*graphics
, GpPen
*pen
,
1367 GDIPCONST GpPointF
*points
, INT count
, REAL tension
)
1369 /* PolyBezier expects count*3-2 points. */
1370 INT i
, len_pt
= count
*3-2, save_state
;
1372 REAL x1
, x2
, y1
, y2
;
1375 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1377 if(!graphics
|| !pen
)
1378 return InvalidParameter
;
1383 pt
= GdipAlloc(len_pt
* sizeof(GpPointF
));
1384 tension
= tension
* TENSION_CONST
;
1386 calc_curve_bezier_endp(points
[0].X
, points
[0].Y
, points
[1].X
, points
[1].Y
,
1389 pt
[0].X
= points
[0].X
;
1390 pt
[0].Y
= points
[0].Y
;
1394 for(i
= 0; i
< count
-2; i
++){
1395 calc_curve_bezier(&(points
[i
]), tension
, &x1
, &y1
, &x2
, &y2
);
1399 pt
[3*i
+3].X
= points
[i
+1].X
;
1400 pt
[3*i
+3].Y
= points
[i
+1].Y
;
1405 calc_curve_bezier_endp(points
[count
-1].X
, points
[count
-1].Y
,
1406 points
[count
-2].X
, points
[count
-2].Y
, tension
, &x1
, &y1
);
1408 pt
[len_pt
-2].X
= x1
;
1409 pt
[len_pt
-2].Y
= y1
;
1410 pt
[len_pt
-1].X
= points
[count
-1].X
;
1411 pt
[len_pt
-1].Y
= points
[count
-1].Y
;
1413 save_state
= prepare_dc(graphics
, pen
);
1415 retval
= draw_polybezier(graphics
, pen
, pt
, len_pt
, TRUE
);
1418 restore_dc(graphics
, save_state
);
1423 GpStatus WINGDIPAPI
GdipDrawCurve2I(GpGraphics
*graphics
, GpPen
*pen
,
1424 GDIPCONST GpPoint
*points
, INT count
, REAL tension
)
1430 TRACE("(%p, %p, %p, %d, %.2f)\n", graphics
, pen
, points
, count
, tension
);
1432 if(!points
|| count
<= 0)
1433 return InvalidParameter
;
1435 pointsF
= GdipAlloc(sizeof(GpPointF
)*count
);
1439 for(i
= 0; i
< count
; i
++){
1440 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1441 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1444 ret
= GdipDrawCurve2(graphics
,pen
,pointsF
,count
,tension
);
1450 GpStatus WINGDIPAPI
GdipDrawEllipse(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1451 REAL y
, REAL width
, REAL height
)
1457 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1459 if(!graphics
|| !pen
)
1460 return InvalidParameter
;
1467 ptf
[1].X
= x
+ width
;
1468 ptf
[1].Y
= y
+ height
;
1470 save_state
= prepare_dc(graphics
, pen
);
1471 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1473 transform_and_round_points(graphics
, pti
, ptf
, 2);
1475 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
1477 restore_dc(graphics
, save_state
);
1482 GpStatus WINGDIPAPI
GdipDrawEllipseI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1483 INT y
, INT width
, INT height
)
1485 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1487 return GdipDrawEllipse(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1491 GpStatus WINGDIPAPI
GdipDrawImage(GpGraphics
*graphics
, GpImage
*image
, REAL x
, REAL y
)
1493 TRACE("(%p, %p, %.2f, %.2f)\n", graphics
, image
, x
, y
);
1495 /* IPicture::Render uses LONG coords */
1496 return GdipDrawImageI(graphics
,image
,roundr(x
),roundr(y
));
1499 GpStatus WINGDIPAPI
GdipDrawImageI(GpGraphics
*graphics
, GpImage
*image
, INT x
,
1502 UINT width
, height
, srcw
, srch
;
1504 TRACE("(%p, %p, %d, %d)\n", graphics
, image
, x
, y
);
1506 if(!graphics
|| !image
)
1507 return InvalidParameter
;
1509 GdipGetImageWidth(image
, &width
);
1510 GdipGetImageHeight(image
, &height
);
1512 srcw
= width
* (((REAL
) INCH_HIMETRIC
) /
1513 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
)));
1514 srch
= height
* (((REAL
) INCH_HIMETRIC
) /
1515 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
)));
1517 if(image
->type
!= ImageTypeMetafile
){
1522 IPicture_Render(image
->picture
, graphics
->hdc
, x
, y
, width
, height
,
1523 0, 0, srcw
, srch
, NULL
);
1528 /* FIXME: partially implemented (only works for rectangular parallelograms) */
1529 GpStatus WINGDIPAPI
GdipDrawImagePointsRect(GpGraphics
*graphics
, GpImage
*image
,
1530 GDIPCONST GpPointF
*points
, INT count
, REAL srcx
, REAL srcy
, REAL srcwidth
,
1531 REAL srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1532 DrawImageAbort callback
, VOID
* callbackData
)
1538 TRACE("(%p, %p, %p, %d, %f, %f, %f, %f, %d, %p, %p, %p)\n", graphics
, image
, points
,
1539 count
, srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1542 if(!graphics
|| !image
|| !points
|| count
!= 3)
1543 return InvalidParameter
;
1545 if(srcUnit
== UnitInch
)
1546 dx
= dy
= (REAL
) INCH_HIMETRIC
;
1547 else if(srcUnit
== UnitPixel
){
1548 dx
= ((REAL
) INCH_HIMETRIC
) /
1549 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
));
1550 dy
= ((REAL
) INCH_HIMETRIC
) /
1551 ((REAL
) GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
));
1554 return NotImplemented
;
1556 memcpy(ptf
, points
, 3 * sizeof(GpPointF
));
1557 transform_and_round_points(graphics
, pti
, ptf
, 3);
1559 /* IPicture renders bitmaps with the y-axis reversed
1560 * FIXME: flipping for unknown image type might not be correct. */
1561 if(image
->type
!= ImageTypeMetafile
){
1564 pti
[0].y
= pti
[2].y
;
1568 if(IPicture_Render(image
->picture
, graphics
->hdc
,
1569 pti
[0].x
, pti
[0].y
, pti
[1].x
- pti
[0].x
, pti
[2].y
- pti
[0].y
,
1570 srcx
* dx
, srcy
* dy
,
1571 srcwidth
* dx
, srcheight
* dy
,
1574 callback(callbackData
);
1575 return GenericError
;
1581 GpStatus WINGDIPAPI
GdipDrawImagePointsRectI(GpGraphics
*graphics
, GpImage
*image
,
1582 GDIPCONST GpPoint
*points
, INT count
, INT srcx
, INT srcy
, INT srcwidth
,
1583 INT srcheight
, GpUnit srcUnit
, GDIPCONST GpImageAttributes
* imageAttributes
,
1584 DrawImageAbort callback
, VOID
* callbackData
)
1586 GpPointF pointsF
[3];
1589 TRACE("(%p, %p, %p, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n", graphics
, image
, points
, count
,
1590 srcx
, srcy
, srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
,
1593 if(!points
|| count
!=3)
1594 return InvalidParameter
;
1596 for(i
= 0; i
< count
; i
++){
1597 pointsF
[i
].X
= (REAL
)points
[i
].X
;
1598 pointsF
[i
].Y
= (REAL
)points
[i
].Y
;
1601 return GdipDrawImagePointsRect(graphics
, image
, pointsF
, count
, (REAL
)srcx
, (REAL
)srcy
,
1602 (REAL
)srcwidth
, (REAL
)srcheight
, srcUnit
, imageAttributes
,
1603 callback
, callbackData
);
1606 GpStatus WINGDIPAPI
GdipDrawImageRectRect(GpGraphics
*graphics
, GpImage
*image
,
1607 REAL dstx
, REAL dsty
, REAL dstwidth
, REAL dstheight
, REAL srcx
, REAL srcy
,
1608 REAL srcwidth
, REAL srcheight
, GpUnit srcUnit
,
1609 GDIPCONST GpImageAttributes
* imageattr
, DrawImageAbort callback
,
1610 VOID
* callbackData
)
1614 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f, %d, %p, %p, %p)\n",
1615 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
1616 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1620 points
[1].X
= dstx
+ dstwidth
;
1623 points
[2].Y
= dsty
+ dstheight
;
1625 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1626 srcwidth
, srcheight
, srcUnit
, imageattr
, callback
, callbackData
);
1629 GpStatus WINGDIPAPI
GdipDrawImageRectRectI(GpGraphics
*graphics
, GpImage
*image
,
1630 INT dstx
, INT dsty
, INT dstwidth
, INT dstheight
, INT srcx
, INT srcy
,
1631 INT srcwidth
, INT srcheight
, GpUnit srcUnit
,
1632 GDIPCONST GpImageAttributes
* imageAttributes
, DrawImageAbort callback
,
1633 VOID
* callbackData
)
1637 TRACE("(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %p, %p, %p)\n",
1638 graphics
, image
, dstx
, dsty
, dstwidth
, dstheight
, srcx
, srcy
,
1639 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1643 points
[1].X
= dstx
+ dstwidth
;
1646 points
[2].Y
= dsty
+ dstheight
;
1648 return GdipDrawImagePointsRect(graphics
, image
, points
, 3, srcx
, srcy
,
1649 srcwidth
, srcheight
, srcUnit
, imageAttributes
, callback
, callbackData
);
1652 GpStatus WINGDIPAPI
GdipDrawImageRect(GpGraphics
*graphics
, GpImage
*image
,
1653 REAL x
, REAL y
, REAL width
, REAL height
)
1659 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, image
, x
, y
, width
, height
);
1661 if(!graphics
|| !image
)
1662 return InvalidParameter
;
1664 ret
= GdipGetImageBounds(image
, &bounds
, &unit
);
1668 return GdipDrawImageRectRect(graphics
, image
, x
, y
, width
, height
,
1669 bounds
.X
, bounds
.Y
, bounds
.Width
, bounds
.Height
,
1670 unit
, NULL
, NULL
, NULL
);
1673 GpStatus WINGDIPAPI
GdipDrawImageRectI(GpGraphics
*graphics
, GpImage
*image
,
1674 INT x
, INT y
, INT width
, INT height
)
1676 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, image
, x
, y
, width
, height
);
1678 return GdipDrawImageRect(graphics
, image
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
);
1681 GpStatus WINGDIPAPI
GdipDrawLine(GpGraphics
*graphics
, GpPen
*pen
, REAL x1
,
1682 REAL y1
, REAL x2
, REAL y2
)
1688 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
1690 if(!pen
|| !graphics
)
1691 return InvalidParameter
;
1701 save_state
= prepare_dc(graphics
, pen
);
1703 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1705 restore_dc(graphics
, save_state
);
1710 GpStatus WINGDIPAPI
GdipDrawLineI(GpGraphics
*graphics
, GpPen
*pen
, INT x1
,
1711 INT y1
, INT x2
, INT y2
)
1717 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x1
, y1
, x2
, y2
);
1719 if(!pen
|| !graphics
)
1720 return InvalidParameter
;
1730 save_state
= prepare_dc(graphics
, pen
);
1732 retval
= draw_polyline(graphics
, pen
, pt
, 2, TRUE
);
1734 restore_dc(graphics
, save_state
);
1739 GpStatus WINGDIPAPI
GdipDrawLines(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
1740 GpPointF
*points
, INT count
)
1745 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1747 if(!pen
|| !graphics
|| (count
< 2))
1748 return InvalidParameter
;
1753 save_state
= prepare_dc(graphics
, pen
);
1755 retval
= draw_polyline(graphics
, pen
, points
, count
, TRUE
);
1757 restore_dc(graphics
, save_state
);
1762 GpStatus WINGDIPAPI
GdipDrawLinesI(GpGraphics
*graphics
, GpPen
*pen
, GDIPCONST
1763 GpPoint
*points
, INT count
)
1767 GpPointF
*ptf
= NULL
;
1770 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
1772 if(!pen
|| !graphics
|| (count
< 2))
1773 return InvalidParameter
;
1778 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
1779 if(!ptf
) return OutOfMemory
;
1781 for(i
= 0; i
< count
; i
++){
1782 ptf
[i
].X
= (REAL
) points
[i
].X
;
1783 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
1786 save_state
= prepare_dc(graphics
, pen
);
1788 retval
= draw_polyline(graphics
, pen
, ptf
, count
, TRUE
);
1790 restore_dc(graphics
, save_state
);
1796 GpStatus WINGDIPAPI
GdipDrawPath(GpGraphics
*graphics
, GpPen
*pen
, GpPath
*path
)
1801 TRACE("(%p, %p, %p)\n", graphics
, pen
, path
);
1803 if(!pen
|| !graphics
)
1804 return InvalidParameter
;
1809 save_state
= prepare_dc(graphics
, pen
);
1811 retval
= draw_poly(graphics
, pen
, path
->pathdata
.Points
,
1812 path
->pathdata
.Types
, path
->pathdata
.Count
, TRUE
);
1814 restore_dc(graphics
, save_state
);
1819 GpStatus WINGDIPAPI
GdipDrawPie(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1820 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
1824 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1825 width
, height
, startAngle
, sweepAngle
);
1827 if(!graphics
|| !pen
)
1828 return InvalidParameter
;
1833 save_state
= prepare_dc(graphics
, pen
);
1834 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1836 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
1838 restore_dc(graphics
, save_state
);
1843 GpStatus WINGDIPAPI
GdipDrawPieI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1844 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
1846 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n", graphics
, pen
, x
, y
,
1847 width
, height
, startAngle
, sweepAngle
);
1849 return GdipDrawPie(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
1852 GpStatus WINGDIPAPI
GdipDrawRectangle(GpGraphics
*graphics
, GpPen
*pen
, REAL x
,
1853 REAL y
, REAL width
, REAL height
)
1859 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, pen
, x
, y
, width
, height
);
1861 if(!pen
|| !graphics
)
1862 return InvalidParameter
;
1869 ptf
[1].X
= x
+ width
;
1871 ptf
[2].X
= x
+ width
;
1872 ptf
[2].Y
= y
+ height
;
1874 ptf
[3].Y
= y
+ height
;
1876 save_state
= prepare_dc(graphics
, pen
);
1877 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1879 transform_and_round_points(graphics
, pti
, ptf
, 4);
1880 Polygon(graphics
->hdc
, pti
, 4);
1882 restore_dc(graphics
, save_state
);
1887 GpStatus WINGDIPAPI
GdipDrawRectangleI(GpGraphics
*graphics
, GpPen
*pen
, INT x
,
1888 INT y
, INT width
, INT height
)
1890 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, pen
, x
, y
, width
, height
);
1892 return GdipDrawRectangle(graphics
,pen
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
1895 GpStatus WINGDIPAPI
GdipDrawRectangles(GpGraphics
*graphics
, GpPen
*pen
,
1896 GDIPCONST GpRectF
* rects
, INT count
)
1902 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
1904 if(!graphics
|| !pen
|| !rects
|| count
< 1)
1905 return InvalidParameter
;
1910 ptf
= GdipAlloc(4 * count
* sizeof(GpPointF
));
1911 pti
= GdipAlloc(4 * count
* sizeof(POINT
));
1919 for(i
= 0; i
< count
; i
++){
1920 ptf
[4 * i
+ 3].X
= ptf
[4 * i
].X
= rects
[i
].X
;
1921 ptf
[4 * i
+ 1].Y
= ptf
[4 * i
].Y
= rects
[i
].Y
;
1922 ptf
[4 * i
+ 2].X
= ptf
[4 * i
+ 1].X
= rects
[i
].X
+ rects
[i
].Width
;
1923 ptf
[4 * i
+ 3].Y
= ptf
[4 * i
+ 2].Y
= rects
[i
].Y
+ rects
[i
].Height
;
1926 save_state
= prepare_dc(graphics
, pen
);
1927 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
1929 transform_and_round_points(graphics
, pti
, ptf
, 4 * count
);
1931 for(i
= 0; i
< count
; i
++)
1932 Polygon(graphics
->hdc
, &pti
[4 * i
], 4);
1934 restore_dc(graphics
, save_state
);
1942 GpStatus WINGDIPAPI
GdipDrawRectanglesI(GpGraphics
*graphics
, GpPen
*pen
,
1943 GDIPCONST GpRect
* rects
, INT count
)
1949 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, rects
, count
);
1951 if(!rects
|| count
<=0)
1952 return InvalidParameter
;
1954 rectsF
= GdipAlloc(sizeof(GpRectF
) * count
);
1958 for(i
= 0;i
< count
;i
++){
1959 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
1960 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
1961 rectsF
[i
].Width
= (REAL
)rects
[i
].Width
;
1962 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
1965 ret
= GdipDrawRectangles(graphics
, pen
, rectsF
, count
);
1971 GpStatus WINGDIPAPI
GdipDrawString(GpGraphics
*graphics
, GDIPCONST WCHAR
*string
,
1972 INT length
, GDIPCONST GpFont
*font
, GDIPCONST RectF
*rect
,
1973 GDIPCONST GpStringFormat
*format
, GDIPCONST GpBrush
*brush
)
1978 TEXTMETRICW textmet
;
1979 GpPointF pt
[2], rectcpy
[4];
1982 REAL angle
, ang_cos
, ang_sin
, rel_width
, rel_height
;
1983 INT sum
= 0, height
= 0, fit
, fitcpy
, save_state
, i
, j
, lret
, nwidth
,
1988 if(!graphics
|| !string
|| !font
|| !brush
|| !rect
)
1989 return InvalidParameter
;
1991 if((brush
->bt
!= BrushTypeSolidColor
)){
1992 FIXME("not implemented for given parameters\n");
1993 return NotImplemented
;
1997 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
1999 if(length
== -1) length
= lstrlenW(string
);
2001 stringdup
= GdipAlloc(length
* sizeof(WCHAR
));
2002 if(!stringdup
) return OutOfMemory
;
2004 save_state
= SaveDC(graphics
->hdc
);
2005 SetBkMode(graphics
->hdc
, TRANSPARENT
);
2006 SetTextColor(graphics
->hdc
, brush
->lb
.lbColor
);
2008 rectcpy
[3].X
= rectcpy
[0].X
= rect
->X
;
2009 rectcpy
[1].Y
= rectcpy
[0].Y
= rect
->Y
;
2010 rectcpy
[2].X
= rectcpy
[1].X
= rect
->X
+ rect
->Width
;
2011 rectcpy
[3].Y
= rectcpy
[2].Y
= rect
->Y
+ rect
->Height
;
2012 transform_and_round_points(graphics
, corners
, rectcpy
, 4);
2014 if(roundr(rect
->Width
) == 0 && roundr(rect
->Height
) == 0){
2015 rel_width
= rel_height
= 1.0;
2016 nwidth
= nheight
= INT_MAX
;
2019 rel_width
= sqrt((corners
[1].x
- corners
[0].x
) * (corners
[1].x
- corners
[0].x
) +
2020 (corners
[1].y
- corners
[0].y
) * (corners
[1].y
- corners
[0].y
))
2022 rel_height
= sqrt((corners
[2].x
- corners
[1].x
) * (corners
[2].x
- corners
[1].x
) +
2023 (corners
[2].y
- corners
[1].y
) * (corners
[2].y
- corners
[1].y
))
2026 nwidth
= roundr(rel_width
* rect
->Width
);
2027 nheight
= roundr(rel_height
* rect
->Height
);
2028 rgn
= CreatePolygonRgn(corners
, 4, ALTERNATE
);
2029 SelectClipRgn(graphics
->hdc
, rgn
);
2032 /* Use gdi to find the font, then perform transformations on it (height,
2034 SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
2035 GetTextMetricsW(graphics
->hdc
, &textmet
);
2038 lfw
.lfHeight
= roundr(((REAL
)lfw
.lfHeight
) * rel_height
);
2039 lfw
.lfWidth
= roundr(textmet
.tmAveCharWidth
* rel_width
);
2045 GdipTransformMatrixPoints(graphics
->worldtrans
, pt
, 2);
2046 angle
= gdiplus_atan2((pt
[1].Y
- pt
[0].Y
), (pt
[1].X
- pt
[0].X
));
2047 ang_cos
= cos(angle
);
2048 ang_sin
= sin(angle
);
2049 lfw
.lfEscapement
= lfw
.lfOrientation
= -roundr((angle
/ M_PI
) * 1800.0);
2051 gdifont
= CreateFontIndirectW(&lfw
);
2052 DeleteObject(SelectObject(graphics
->hdc
, CreateFontIndirectW(&lfw
)));
2054 for(i
= 0, j
= 0; i
< length
; i
++){
2055 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
2058 stringdup
[j
] = string
[i
];
2064 while(sum
< length
){
2065 drawcoord
.left
= corners
[0].x
+ roundr(ang_sin
* (REAL
) height
);
2066 drawcoord
.top
= corners
[0].y
+ roundr(ang_cos
* (REAL
) height
);
2068 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
2069 nwidth
, &fit
, NULL
, &size
);
2073 DrawTextW(graphics
->hdc
, stringdup
+ sum
, 1, &drawcoord
, DT_NOCLIP
|
2078 for(lret
= 0; lret
< fit
; lret
++)
2079 if(*(stringdup
+ sum
+ lret
) == '\n')
2082 /* Line break code (may look strange, but it imitates windows). */
2084 fit
= lret
; /* this is not an off-by-one error */
2085 else if(fit
< (length
- sum
)){
2086 if(*(stringdup
+ sum
+ fit
) == ' ')
2087 while(*(stringdup
+ sum
+ fit
) == ' ')
2090 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
2093 if(*(stringdup
+ sum
+ fit
) == '\t')
2102 DrawTextW(graphics
->hdc
, stringdup
+ sum
, min(length
- sum
, fit
),
2103 &drawcoord
, DT_NOCLIP
| DT_EXPANDTABS
);
2105 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
2108 if(height
> nheight
)
2111 /* Stop if this was a linewrap (but not if it was a linebreak). */
2112 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
2116 GdipFree(stringdup
);
2118 DeleteObject(gdifont
);
2120 RestoreDC(graphics
->hdc
, save_state
);
2125 GpStatus WINGDIPAPI
GdipFillClosedCurve2(GpGraphics
*graphics
, GpBrush
*brush
,
2126 GDIPCONST GpPointF
*points
, INT count
, REAL tension
, GpFillMode fill
)
2131 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2132 count
, tension
, fill
);
2134 if(!graphics
|| !brush
|| !points
)
2135 return InvalidParameter
;
2140 stat
= GdipCreatePath(fill
, &path
);
2144 stat
= GdipAddPathClosedCurve2(path
, points
, count
, tension
);
2146 GdipDeletePath(path
);
2150 stat
= GdipFillPath(graphics
, brush
, path
);
2152 GdipDeletePath(path
);
2156 GdipDeletePath(path
);
2161 GpStatus WINGDIPAPI
GdipFillClosedCurve2I(GpGraphics
*graphics
, GpBrush
*brush
,
2162 GDIPCONST GpPoint
*points
, INT count
, REAL tension
, GpFillMode fill
)
2168 TRACE("(%p, %p, %p, %d, %.2f, %d)\n", graphics
, brush
, points
,
2169 count
, tension
, fill
);
2171 if(!points
|| count
<= 0)
2172 return InvalidParameter
;
2174 ptf
= GdipAlloc(sizeof(GpPointF
)*count
);
2178 for(i
= 0;i
< count
;i
++){
2179 ptf
[i
].X
= (REAL
)points
[i
].X
;
2180 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
2183 stat
= GdipFillClosedCurve2(graphics
, brush
, ptf
, count
, tension
, fill
);
2190 GpStatus WINGDIPAPI
GdipFillEllipse(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2191 REAL y
, REAL width
, REAL height
)
2197 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2199 if(!graphics
|| !brush
)
2200 return InvalidParameter
;
2207 ptf
[1].X
= x
+ width
;
2208 ptf
[1].Y
= y
+ height
;
2210 save_state
= SaveDC(graphics
->hdc
);
2211 EndPath(graphics
->hdc
);
2212 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2213 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2215 transform_and_round_points(graphics
, pti
, ptf
, 2);
2217 Ellipse(graphics
->hdc
, pti
[0].x
, pti
[0].y
, pti
[1].x
, pti
[1].y
);
2219 RestoreDC(graphics
->hdc
, save_state
);
2224 GpStatus WINGDIPAPI
GdipFillEllipseI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2225 INT y
, INT width
, INT height
)
2227 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2229 return GdipFillEllipse(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
);
2232 GpStatus WINGDIPAPI
GdipFillPath(GpGraphics
*graphics
, GpBrush
*brush
, GpPath
*path
)
2237 TRACE("(%p, %p, %p)\n", graphics
, brush
, path
);
2239 if(!brush
|| !graphics
|| !path
)
2240 return InvalidParameter
;
2245 save_state
= SaveDC(graphics
->hdc
);
2246 EndPath(graphics
->hdc
);
2247 SetPolyFillMode(graphics
->hdc
, (path
->fill
== FillModeAlternate
? ALTERNATE
2250 BeginPath(graphics
->hdc
);
2251 retval
= draw_poly(graphics
, NULL
, path
->pathdata
.Points
,
2252 path
->pathdata
.Types
, path
->pathdata
.Count
, FALSE
);
2257 EndPath(graphics
->hdc
);
2258 brush_fill_path(graphics
, brush
);
2263 RestoreDC(graphics
->hdc
, save_state
);
2268 GpStatus WINGDIPAPI
GdipFillPie(GpGraphics
*graphics
, GpBrush
*brush
, REAL x
,
2269 REAL y
, REAL width
, REAL height
, REAL startAngle
, REAL sweepAngle
)
2273 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f, %.2f, %.2f)\n",
2274 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2276 if(!graphics
|| !brush
)
2277 return InvalidParameter
;
2282 save_state
= SaveDC(graphics
->hdc
);
2283 EndPath(graphics
->hdc
);
2284 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2285 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2287 draw_pie(graphics
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2289 RestoreDC(graphics
->hdc
, save_state
);
2294 GpStatus WINGDIPAPI
GdipFillPieI(GpGraphics
*graphics
, GpBrush
*brush
, INT x
,
2295 INT y
, INT width
, INT height
, REAL startAngle
, REAL sweepAngle
)
2297 TRACE("(%p, %p, %d, %d, %d, %d, %.2f, %.2f)\n",
2298 graphics
, brush
, x
, y
, width
, height
, startAngle
, sweepAngle
);
2300 return GdipFillPie(graphics
,brush
,(REAL
)x
,(REAL
)y
,(REAL
)width
,(REAL
)height
,startAngle
,sweepAngle
);
2303 GpStatus WINGDIPAPI
GdipFillPolygon(GpGraphics
*graphics
, GpBrush
*brush
,
2304 GDIPCONST GpPointF
*points
, INT count
, GpFillMode fillMode
)
2307 GpPointF
*ptf
= NULL
;
2309 GpStatus retval
= Ok
;
2311 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2313 if(!graphics
|| !brush
|| !points
|| !count
)
2314 return InvalidParameter
;
2319 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2320 pti
= GdipAlloc(count
* sizeof(POINT
));
2322 retval
= OutOfMemory
;
2326 memcpy(ptf
, points
, count
* sizeof(GpPointF
));
2328 save_state
= SaveDC(graphics
->hdc
);
2329 EndPath(graphics
->hdc
);
2330 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2331 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2332 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2335 transform_and_round_points(graphics
, pti
, ptf
, count
);
2336 Polygon(graphics
->hdc
, pti
, count
);
2338 RestoreDC(graphics
->hdc
, save_state
);
2347 GpStatus WINGDIPAPI
GdipFillPolygonI(GpGraphics
*graphics
, GpBrush
*brush
,
2348 GDIPCONST GpPoint
*points
, INT count
, GpFillMode fillMode
)
2351 GpPointF
*ptf
= NULL
;
2353 GpStatus retval
= Ok
;
2355 TRACE("(%p, %p, %p, %d, %d)\n", graphics
, brush
, points
, count
, fillMode
);
2357 if(!graphics
|| !brush
|| !points
|| !count
)
2358 return InvalidParameter
;
2363 ptf
= GdipAlloc(count
* sizeof(GpPointF
));
2364 pti
= GdipAlloc(count
* sizeof(POINT
));
2366 retval
= OutOfMemory
;
2370 for(i
= 0; i
< count
; i
++){
2371 ptf
[i
].X
= (REAL
) points
[i
].X
;
2372 ptf
[i
].Y
= (REAL
) points
[i
].Y
;
2375 save_state
= SaveDC(graphics
->hdc
);
2376 EndPath(graphics
->hdc
);
2377 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2378 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2379 SetPolyFillMode(graphics
->hdc
, (fillMode
== FillModeAlternate
? ALTERNATE
2382 transform_and_round_points(graphics
, pti
, ptf
, count
);
2383 Polygon(graphics
->hdc
, pti
, count
);
2385 RestoreDC(graphics
->hdc
, save_state
);
2394 GpStatus WINGDIPAPI
GdipFillPolygon2(GpGraphics
*graphics
, GpBrush
*brush
,
2395 GDIPCONST GpPointF
*points
, INT count
)
2397 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2399 return GdipFillPolygon(graphics
, brush
, points
, count
, FillModeAlternate
);
2402 GpStatus WINGDIPAPI
GdipFillPolygon2I(GpGraphics
*graphics
, GpBrush
*brush
,
2403 GDIPCONST GpPoint
*points
, INT count
)
2405 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, points
, count
);
2407 return GdipFillPolygonI(graphics
, brush
, points
, count
, FillModeAlternate
);
2410 GpStatus WINGDIPAPI
GdipFillRectangle(GpGraphics
*graphics
, GpBrush
*brush
,
2411 REAL x
, REAL y
, REAL width
, REAL height
)
2417 TRACE("(%p, %p, %.2f, %.2f, %.2f, %.2f)\n", graphics
, brush
, x
, y
, width
, height
);
2419 if(!graphics
|| !brush
)
2420 return InvalidParameter
;
2427 ptf
[1].X
= x
+ width
;
2429 ptf
[2].X
= x
+ width
;
2430 ptf
[2].Y
= y
+ height
;
2432 ptf
[3].Y
= y
+ height
;
2434 save_state
= SaveDC(graphics
->hdc
);
2435 EndPath(graphics
->hdc
);
2436 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2437 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2439 transform_and_round_points(graphics
, pti
, ptf
, 4);
2441 Polygon(graphics
->hdc
, pti
, 4);
2443 RestoreDC(graphics
->hdc
, save_state
);
2448 GpStatus WINGDIPAPI
GdipFillRectangleI(GpGraphics
*graphics
, GpBrush
*brush
,
2449 INT x
, INT y
, INT width
, INT height
)
2455 TRACE("(%p, %p, %d, %d, %d, %d)\n", graphics
, brush
, x
, y
, width
, height
);
2457 if(!graphics
|| !brush
)
2458 return InvalidParameter
;
2465 ptf
[1].X
= x
+ width
;
2467 ptf
[2].X
= x
+ width
;
2468 ptf
[2].Y
= y
+ height
;
2470 ptf
[3].Y
= y
+ height
;
2472 save_state
= SaveDC(graphics
->hdc
);
2473 EndPath(graphics
->hdc
);
2474 SelectObject(graphics
->hdc
, brush
->gdibrush
);
2475 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2477 transform_and_round_points(graphics
, pti
, ptf
, 4);
2479 Polygon(graphics
->hdc
, pti
, 4);
2481 RestoreDC(graphics
->hdc
, save_state
);
2486 GpStatus WINGDIPAPI
GdipFillRectangles(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRectF
*rects
,
2492 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2495 return InvalidParameter
;
2497 for(i
= 0; i
< count
; i
++){
2498 ret
= GdipFillRectangle(graphics
, brush
, rects
[i
].X
, rects
[i
].Y
, rects
[i
].Width
, rects
[i
].Height
);
2499 if(ret
!= Ok
) return ret
;
2505 GpStatus WINGDIPAPI
GdipFillRectanglesI(GpGraphics
*graphics
, GpBrush
*brush
, GDIPCONST GpRect
*rects
,
2512 TRACE("(%p, %p, %p, %d)\n", graphics
, brush
, rects
, count
);
2514 if(!rects
|| count
<= 0)
2515 return InvalidParameter
;
2517 rectsF
= GdipAlloc(sizeof(GpRectF
)*count
);
2521 for(i
= 0; i
< count
; i
++){
2522 rectsF
[i
].X
= (REAL
)rects
[i
].X
;
2523 rectsF
[i
].Y
= (REAL
)rects
[i
].Y
;
2524 rectsF
[i
].X
= (REAL
)rects
[i
].Width
;
2525 rectsF
[i
].Height
= (REAL
)rects
[i
].Height
;
2528 ret
= GdipFillRectangles(graphics
,brush
,rectsF
,count
);
2534 /*****************************************************************************
2535 * GdipFillRegion [GDIPLUS.@]
2537 GpStatus WINGDIPAPI
GdipFillRegion(GpGraphics
* graphics
, GpBrush
* brush
,
2544 TRACE("(%p, %p, %p)\n", graphics
, brush
, region
);
2546 if (!(graphics
&& brush
&& region
))
2547 return InvalidParameter
;
2552 status
= GdipGetRegionHRgn(region
, graphics
, &hrgn
);
2556 save_state
= SaveDC(graphics
->hdc
);
2557 EndPath(graphics
->hdc
);
2558 SelectObject(graphics
->hdc
, GetStockObject(NULL_PEN
));
2560 FillRgn(graphics
->hdc
, hrgn
, brush
->gdibrush
);
2562 RestoreDC(graphics
->hdc
, save_state
);
2569 GpStatus WINGDIPAPI
GdipFlush(GpGraphics
*graphics
, GpFlushIntention intention
)
2574 return InvalidParameter
;
2580 FIXME("not implemented\n");
2582 return NotImplemented
;
2585 /*****************************************************************************
2586 * GdipGetClipBounds [GDIPLUS.@]
2588 GpStatus WINGDIPAPI
GdipGetClipBounds(GpGraphics
*graphics
, GpRectF
*rect
)
2590 TRACE("(%p, %p)\n", graphics
, rect
);
2593 return InvalidParameter
;
2598 return GdipGetRegionBounds(graphics
->clip
, graphics
, rect
);
2601 /*****************************************************************************
2602 * GdipGetClipBoundsI [GDIPLUS.@]
2604 GpStatus WINGDIPAPI
GdipGetClipBoundsI(GpGraphics
*graphics
, GpRect
*rect
)
2606 TRACE("(%p, %p)\n", graphics
, rect
);
2609 return InvalidParameter
;
2614 return GdipGetRegionBoundsI(graphics
->clip
, graphics
, rect
);
2617 /* FIXME: Compositing mode is not used anywhere except the getter/setter. */
2618 GpStatus WINGDIPAPI
GdipGetCompositingMode(GpGraphics
*graphics
,
2619 CompositingMode
*mode
)
2621 TRACE("(%p, %p)\n", graphics
, mode
);
2623 if(!graphics
|| !mode
)
2624 return InvalidParameter
;
2629 *mode
= graphics
->compmode
;
2634 /* FIXME: Compositing quality is not used anywhere except the getter/setter. */
2635 GpStatus WINGDIPAPI
GdipGetCompositingQuality(GpGraphics
*graphics
,
2636 CompositingQuality
*quality
)
2638 TRACE("(%p, %p)\n", graphics
, quality
);
2640 if(!graphics
|| !quality
)
2641 return InvalidParameter
;
2646 *quality
= graphics
->compqual
;
2651 /* FIXME: Interpolation mode is not used anywhere except the getter/setter. */
2652 GpStatus WINGDIPAPI
GdipGetInterpolationMode(GpGraphics
*graphics
,
2653 InterpolationMode
*mode
)
2655 TRACE("(%p, %p)\n", graphics
, mode
);
2657 if(!graphics
|| !mode
)
2658 return InvalidParameter
;
2663 *mode
= graphics
->interpolation
;
2668 GpStatus WINGDIPAPI
GdipGetNearestColor(GpGraphics
*graphics
, ARGB
* argb
)
2670 if(!graphics
|| !argb
)
2671 return InvalidParameter
;
2676 FIXME("(%p, %p): stub\n", graphics
, argb
);
2678 return NotImplemented
;
2681 GpStatus WINGDIPAPI
GdipGetPageScale(GpGraphics
*graphics
, REAL
*scale
)
2683 TRACE("(%p, %p)\n", graphics
, scale
);
2685 if(!graphics
|| !scale
)
2686 return InvalidParameter
;
2691 *scale
= graphics
->scale
;
2696 GpStatus WINGDIPAPI
GdipGetPageUnit(GpGraphics
*graphics
, GpUnit
*unit
)
2698 TRACE("(%p, %p)\n", graphics
, unit
);
2700 if(!graphics
|| !unit
)
2701 return InvalidParameter
;
2706 *unit
= graphics
->unit
;
2711 /* FIXME: Pixel offset mode is not used anywhere except the getter/setter. */
2712 GpStatus WINGDIPAPI
GdipGetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
2715 TRACE("(%p, %p)\n", graphics
, mode
);
2717 if(!graphics
|| !mode
)
2718 return InvalidParameter
;
2723 *mode
= graphics
->pixeloffset
;
2728 /* FIXME: Smoothing mode is not used anywhere except the getter/setter. */
2729 GpStatus WINGDIPAPI
GdipGetSmoothingMode(GpGraphics
*graphics
, SmoothingMode
*mode
)
2731 TRACE("(%p, %p)\n", graphics
, mode
);
2733 if(!graphics
|| !mode
)
2734 return InvalidParameter
;
2739 *mode
= graphics
->smoothing
;
2744 GpStatus WINGDIPAPI
GdipGetTextContrast(GpGraphics
*graphics
, UINT
*contrast
)
2746 TRACE("(%p, %p)\n", graphics
, contrast
);
2748 if(!graphics
|| !contrast
)
2749 return InvalidParameter
;
2751 *contrast
= graphics
->textcontrast
;
2756 /* FIXME: Text rendering hint is not used anywhere except the getter/setter. */
2757 GpStatus WINGDIPAPI
GdipGetTextRenderingHint(GpGraphics
*graphics
,
2758 TextRenderingHint
*hint
)
2760 TRACE("(%p, %p)\n", graphics
, hint
);
2762 if(!graphics
|| !hint
)
2763 return InvalidParameter
;
2768 *hint
= graphics
->texthint
;
2773 GpStatus WINGDIPAPI
GdipGetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
2775 TRACE("(%p, %p)\n", graphics
, matrix
);
2777 if(!graphics
|| !matrix
)
2778 return InvalidParameter
;
2783 *matrix
= *graphics
->worldtrans
;
2787 GpStatus WINGDIPAPI
GdipGraphicsClear(GpGraphics
*graphics
, ARGB color
)
2793 TRACE("(%p, %x)\n", graphics
, color
);
2796 return InvalidParameter
;
2801 if((stat
= GdipCreateSolidFill(color
, &brush
)) != Ok
)
2805 if(!GetWindowRect(graphics
->hwnd
, &rect
)){
2806 GdipDeleteBrush((GpBrush
*)brush
);
2807 return GenericError
;
2810 GdipFillRectangle(graphics
, (GpBrush
*)brush
, 0.0, 0.0, (REAL
)(rect
.right
- rect
.left
),
2811 (REAL
)(rect
.bottom
- rect
.top
));
2814 GdipFillRectangle(graphics
, (GpBrush
*)brush
, 0.0, 0.0, (REAL
)GetDeviceCaps(graphics
->hdc
, HORZRES
),
2815 (REAL
)GetDeviceCaps(graphics
->hdc
, VERTRES
));
2817 GdipDeleteBrush((GpBrush
*)brush
);
2822 GpStatus WINGDIPAPI
GdipIsClipEmpty(GpGraphics
*graphics
, BOOL
*res
)
2824 TRACE("(%p, %p)\n", graphics
, res
);
2826 if(!graphics
|| !res
)
2827 return InvalidParameter
;
2829 return GdipIsEmptyRegion(graphics
->clip
, graphics
, res
);
2832 GpStatus WINGDIPAPI
GdipIsVisiblePoint(GpGraphics
*graphics
, REAL x
, REAL y
, BOOL
*result
)
2834 FIXME("(%p, %.2f, %.2f, %p) stub\n", graphics
, x
, y
, result
);
2836 if(!graphics
|| !result
)
2837 return InvalidParameter
;
2842 return NotImplemented
;
2845 GpStatus WINGDIPAPI
GdipIsVisiblePointI(GpGraphics
*graphics
, INT x
, INT y
, BOOL
*result
)
2847 FIXME("(%p, %d, %d, %p) stub\n", graphics
, x
, y
, result
);
2849 if(!graphics
|| !result
)
2850 return InvalidParameter
;
2855 return NotImplemented
;
2858 GpStatus WINGDIPAPI
GdipMeasureCharacterRanges(GpGraphics
* graphics
,
2859 GDIPCONST WCHAR
* string
, INT length
, GDIPCONST GpFont
* font
,
2860 GDIPCONST RectF
* layoutRect
, GDIPCONST GpStringFormat
*stringFormat
,
2861 INT regionCount
, GpRegion
** regions
)
2863 if (!(graphics
&& string
&& font
&& layoutRect
&& stringFormat
&& regions
))
2864 return InvalidParameter
;
2866 FIXME("stub: %p %s %d %p %p %p %d %p\n", graphics
, debugstr_w(string
),
2867 length
, font
, layoutRect
, stringFormat
, regionCount
, regions
);
2869 return NotImplemented
;
2872 /* Find the smallest rectangle that bounds the text when it is printed in rect
2873 * according to the format options listed in format. If rect has 0 width and
2874 * height, then just find the smallest rectangle that bounds the text when it's
2875 * printed at location (rect->X, rect-Y). */
2876 GpStatus WINGDIPAPI
GdipMeasureString(GpGraphics
*graphics
,
2877 GDIPCONST WCHAR
*string
, INT length
, GDIPCONST GpFont
*font
,
2878 GDIPCONST RectF
*rect
, GDIPCONST GpStringFormat
*format
, RectF
*bounds
,
2879 INT
*codepointsfitted
, INT
*linesfilled
)
2883 INT sum
= 0, height
= 0, fit
, fitcpy
, max_width
= 0, i
, j
, lret
, nwidth
,
2887 if(!graphics
|| !string
|| !font
|| !rect
)
2888 return InvalidParameter
;
2890 if(linesfilled
) *linesfilled
= 0;
2891 if(codepointsfitted
) *codepointsfitted
= 0;
2894 TRACE("may be ignoring some format flags: attr %x\n", format
->attr
);
2896 if(length
== -1) length
= lstrlenW(string
);
2898 stringdup
= GdipAlloc((length
+ 1) * sizeof(WCHAR
));
2899 if(!stringdup
) return OutOfMemory
;
2901 oldfont
= SelectObject(graphics
->hdc
, CreateFontIndirectW(&font
->lfw
));
2902 nwidth
= roundr(rect
->Width
);
2903 nheight
= roundr(rect
->Height
);
2905 if((nwidth
== 0) && (nheight
== 0))
2906 nwidth
= nheight
= INT_MAX
;
2908 for(i
= 0, j
= 0; i
< length
; i
++){
2909 if(!isprintW(string
[i
]) && (string
[i
] != '\n'))
2912 stringdup
[j
] = string
[i
];
2919 while(sum
< length
){
2920 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, length
- sum
,
2921 nwidth
, &fit
, NULL
, &size
);
2927 for(lret
= 0; lret
< fit
; lret
++)
2928 if(*(stringdup
+ sum
+ lret
) == '\n')
2931 /* Line break code (may look strange, but it imitates windows). */
2933 fit
= lret
; /* this is not an off-by-one error */
2934 else if(fit
< (length
- sum
)){
2935 if(*(stringdup
+ sum
+ fit
) == ' ')
2936 while(*(stringdup
+ sum
+ fit
) == ' ')
2939 while(*(stringdup
+ sum
+ fit
- 1) != ' '){
2942 if(*(stringdup
+ sum
+ fit
) == '\t')
2952 GetTextExtentExPointW(graphics
->hdc
, stringdup
+ sum
, fit
,
2953 nwidth
, &j
, NULL
, &size
);
2955 sum
+= fit
+ (lret
< fitcpy
? 1 : 0);
2956 if(codepointsfitted
) *codepointsfitted
= sum
;
2959 if(linesfilled
) *linesfilled
+= size
.cy
;
2960 max_width
= max(max_width
, size
.cx
);
2962 if(height
> nheight
)
2965 /* Stop if this was a linewrap (but not if it was a linebreak). */
2966 if((lret
== fitcpy
) && format
&& (format
->attr
& StringFormatFlagsNoWrap
))
2970 bounds
->X
= rect
->X
;
2971 bounds
->Y
= rect
->Y
;
2972 bounds
->Width
= (REAL
)max_width
;
2973 bounds
->Height
= (REAL
) min(height
, nheight
);
2975 GdipFree(stringdup
);
2976 DeleteObject(SelectObject(graphics
->hdc
, oldfont
));
2981 GpStatus WINGDIPAPI
GdipResetClip(GpGraphics
*graphics
)
2983 TRACE("(%p)\n", graphics
);
2986 return InvalidParameter
;
2991 return GdipSetInfinite(graphics
->clip
);
2994 GpStatus WINGDIPAPI
GdipResetWorldTransform(GpGraphics
*graphics
)
2996 TRACE("(%p)\n", graphics
);
2999 return InvalidParameter
;
3004 graphics
->worldtrans
->matrix
[0] = 1.0;
3005 graphics
->worldtrans
->matrix
[1] = 0.0;
3006 graphics
->worldtrans
->matrix
[2] = 0.0;
3007 graphics
->worldtrans
->matrix
[3] = 1.0;
3008 graphics
->worldtrans
->matrix
[4] = 0.0;
3009 graphics
->worldtrans
->matrix
[5] = 0.0;
3014 GpStatus WINGDIPAPI
GdipRestoreGraphics(GpGraphics
*graphics
, GraphicsState state
)
3019 return InvalidParameter
;
3022 FIXME("graphics state not implemented\n");
3027 GpStatus WINGDIPAPI
GdipRotateWorldTransform(GpGraphics
*graphics
, REAL angle
,
3028 GpMatrixOrder order
)
3030 TRACE("(%p, %.2f, %d)\n", graphics
, angle
, order
);
3033 return InvalidParameter
;
3038 return GdipRotateMatrix(graphics
->worldtrans
, angle
, order
);
3041 GpStatus WINGDIPAPI
GdipSaveGraphics(GpGraphics
*graphics
, GraphicsState
*state
)
3045 if(!graphics
|| !state
)
3046 return InvalidParameter
;
3049 FIXME("graphics state not implemented\n");
3051 *state
= 0xdeadbeef;
3055 GpStatus WINGDIPAPI
GdipBeginContainer2(GpGraphics
*graphics
, GraphicsContainer
*state
)
3057 FIXME("(%p, %p)\n", graphics
, state
);
3059 if(!graphics
|| !state
)
3060 return InvalidParameter
;
3062 *state
= 0xdeadbeef;
3066 GpStatus WINGDIPAPI
GdipEndContainer(GpGraphics
*graphics
, GraphicsState state
)
3068 FIXME("(%p, 0x%x)\n", graphics
, state
);
3070 if(!graphics
|| !state
)
3071 return InvalidParameter
;
3076 GpStatus WINGDIPAPI
GdipScaleWorldTransform(GpGraphics
*graphics
, REAL sx
,
3077 REAL sy
, GpMatrixOrder order
)
3079 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, sx
, sy
, order
);
3082 return InvalidParameter
;
3087 return GdipScaleMatrix(graphics
->worldtrans
, sx
, sy
, order
);
3090 GpStatus WINGDIPAPI
GdipSetClipGraphics(GpGraphics
*graphics
, GpGraphics
*srcgraphics
,
3093 TRACE("(%p, %p, %d)\n", graphics
, srcgraphics
, mode
);
3095 if(!graphics
|| !srcgraphics
)
3096 return InvalidParameter
;
3098 return GdipCombineRegionRegion(graphics
->clip
, srcgraphics
->clip
, mode
);
3101 GpStatus WINGDIPAPI
GdipSetCompositingMode(GpGraphics
*graphics
,
3102 CompositingMode mode
)
3104 TRACE("(%p, %d)\n", graphics
, mode
);
3107 return InvalidParameter
;
3112 graphics
->compmode
= mode
;
3117 GpStatus WINGDIPAPI
GdipSetCompositingQuality(GpGraphics
*graphics
,
3118 CompositingQuality quality
)
3120 TRACE("(%p, %d)\n", graphics
, quality
);
3123 return InvalidParameter
;
3128 graphics
->compqual
= quality
;
3133 GpStatus WINGDIPAPI
GdipSetInterpolationMode(GpGraphics
*graphics
,
3134 InterpolationMode mode
)
3136 TRACE("(%p, %d)\n", graphics
, mode
);
3139 return InvalidParameter
;
3144 graphics
->interpolation
= mode
;
3149 GpStatus WINGDIPAPI
GdipSetPageScale(GpGraphics
*graphics
, REAL scale
)
3151 TRACE("(%p, %.2f)\n", graphics
, scale
);
3153 if(!graphics
|| (scale
<= 0.0))
3154 return InvalidParameter
;
3159 graphics
->scale
= scale
;
3164 GpStatus WINGDIPAPI
GdipSetPageUnit(GpGraphics
*graphics
, GpUnit unit
)
3166 TRACE("(%p, %d)\n", graphics
, unit
);
3169 return InvalidParameter
;
3174 if(unit
== UnitWorld
)
3175 return InvalidParameter
;
3177 graphics
->unit
= unit
;
3182 GpStatus WINGDIPAPI
GdipSetPixelOffsetMode(GpGraphics
*graphics
, PixelOffsetMode
3185 TRACE("(%p, %d)\n", graphics
, mode
);
3188 return InvalidParameter
;
3193 graphics
->pixeloffset
= mode
;
3198 GpStatus WINGDIPAPI
GdipSetSmoothingMode(GpGraphics
*graphics
, SmoothingMode mode
)
3200 TRACE("(%p, %d)\n", graphics
, mode
);
3203 return InvalidParameter
;
3208 graphics
->smoothing
= mode
;
3213 GpStatus WINGDIPAPI
GdipSetTextContrast(GpGraphics
*graphics
, UINT contrast
)
3215 TRACE("(%p, %d)\n", graphics
, contrast
);
3218 return InvalidParameter
;
3220 graphics
->textcontrast
= contrast
;
3225 GpStatus WINGDIPAPI
GdipSetTextRenderingHint(GpGraphics
*graphics
,
3226 TextRenderingHint hint
)
3228 TRACE("(%p, %d)\n", graphics
, hint
);
3231 return InvalidParameter
;
3236 graphics
->texthint
= hint
;
3241 GpStatus WINGDIPAPI
GdipSetWorldTransform(GpGraphics
*graphics
, GpMatrix
*matrix
)
3243 TRACE("(%p, %p)\n", graphics
, matrix
);
3245 if(!graphics
|| !matrix
)
3246 return InvalidParameter
;
3251 GdipDeleteMatrix(graphics
->worldtrans
);
3252 return GdipCloneMatrix(matrix
, &graphics
->worldtrans
);
3255 GpStatus WINGDIPAPI
GdipTranslateWorldTransform(GpGraphics
*graphics
, REAL dx
,
3256 REAL dy
, GpMatrixOrder order
)
3258 TRACE("(%p, %.2f, %.2f, %d)\n", graphics
, dx
, dy
, order
);
3261 return InvalidParameter
;
3266 return GdipTranslateMatrix(graphics
->worldtrans
, dx
, dy
, order
);
3269 /*****************************************************************************
3270 * GdipSetClipHrgn [GDIPLUS.@]
3272 GpStatus WINGDIPAPI
GdipSetClipHrgn(GpGraphics
*graphics
, HRGN hrgn
, CombineMode mode
)
3277 TRACE("(%p, %p, %d)\n", graphics
, hrgn
, mode
);
3280 return InvalidParameter
;
3282 status
= GdipCreateRegionHrgn(hrgn
, ®ion
);
3286 status
= GdipSetClipRegion(graphics
, region
, mode
);
3288 GdipDeleteRegion(region
);
3292 GpStatus WINGDIPAPI
GdipSetClipPath(GpGraphics
*graphics
, GpPath
*path
, CombineMode mode
)
3294 TRACE("(%p, %p, %d)\n", graphics
, path
, mode
);
3297 return InvalidParameter
;
3302 return GdipCombineRegionPath(graphics
->clip
, path
, mode
);
3305 GpStatus WINGDIPAPI
GdipSetClipRect(GpGraphics
*graphics
, REAL x
, REAL y
,
3306 REAL width
, REAL height
,
3311 TRACE("(%p, %.2f, %.2f, %.2f, %.2f, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3314 return InvalidParameter
;
3322 rect
.Height
= height
;
3324 return GdipCombineRegionRect(graphics
->clip
, &rect
, mode
);
3327 GpStatus WINGDIPAPI
GdipSetClipRectI(GpGraphics
*graphics
, INT x
, INT y
,
3328 INT width
, INT height
,
3331 TRACE("(%p, %d, %d, %d, %d, %d)\n", graphics
, x
, y
, width
, height
, mode
);
3334 return InvalidParameter
;
3339 return GdipSetClipRect(graphics
, (REAL
)x
, (REAL
)y
, (REAL
)width
, (REAL
)height
, mode
);
3342 GpStatus WINGDIPAPI
GdipSetClipRegion(GpGraphics
*graphics
, GpRegion
*region
,
3345 TRACE("(%p, %p, %d)\n", graphics
, region
, mode
);
3347 if(!graphics
|| !region
)
3348 return InvalidParameter
;
3353 return GdipCombineRegionRegion(graphics
->clip
, region
, mode
);
3356 GpStatus WINGDIPAPI
GdipSetMetafileDownLevelRasterizationLimit(GpMetafile
*metafile
,
3362 FIXME("not implemented\n");
3364 return NotImplemented
;
3367 GpStatus WINGDIPAPI
GdipDrawPolygon(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPointF
*points
,
3373 TRACE("(%p, %p, %d)\n", graphics
, points
, count
);
3375 if(!graphics
|| !pen
|| count
<=0)
3376 return InvalidParameter
;
3381 pti
= GdipAlloc(sizeof(POINT
) * count
);
3383 save_state
= prepare_dc(graphics
, pen
);
3384 SelectObject(graphics
->hdc
, GetStockObject(NULL_BRUSH
));
3386 transform_and_round_points(graphics
, pti
, (GpPointF
*)points
, count
);
3387 Polygon(graphics
->hdc
, pti
, count
);
3389 restore_dc(graphics
, save_state
);
3395 GpStatus WINGDIPAPI
GdipDrawPolygonI(GpGraphics
*graphics
,GpPen
*pen
,GDIPCONST GpPoint
*points
,
3402 TRACE("(%p, %p, %p, %d)\n", graphics
, pen
, points
, count
);
3404 if(count
<=0) return InvalidParameter
;
3405 ptf
= GdipAlloc(sizeof(GpPointF
) * count
);
3407 for(i
= 0;i
< count
; i
++){
3408 ptf
[i
].X
= (REAL
)points
[i
].X
;
3409 ptf
[i
].Y
= (REAL
)points
[i
].Y
;
3412 ret
= GdipDrawPolygon(graphics
,pen
,ptf
,count
);
3418 GpStatus WINGDIPAPI
GdipGetDpiX(GpGraphics
*graphics
, REAL
* dpi
)
3420 TRACE("(%p, %p)\n", graphics
, dpi
);
3422 if(!graphics
|| !dpi
)
3423 return InvalidParameter
;
3428 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSX
);
3433 GpStatus WINGDIPAPI
GdipGetDpiY(GpGraphics
*graphics
, REAL
* dpi
)
3435 TRACE("(%p, %p)\n", graphics
, dpi
);
3437 if(!graphics
|| !dpi
)
3438 return InvalidParameter
;
3443 *dpi
= (REAL
)GetDeviceCaps(graphics
->hdc
, LOGPIXELSY
);
3448 GpStatus WINGDIPAPI
GdipMultiplyWorldTransform(GpGraphics
*graphics
, GDIPCONST GpMatrix
*matrix
,
3449 GpMatrixOrder order
)
3454 TRACE("(%p, %p, %d)\n", graphics
, matrix
, order
);
3456 if(!graphics
|| !matrix
)
3457 return InvalidParameter
;
3462 m
= *(graphics
->worldtrans
);
3464 ret
= GdipMultiplyMatrix(&m
, matrix
, order
);
3466 *(graphics
->worldtrans
) = m
;
3471 GpStatus WINGDIPAPI
GdipGetDC(GpGraphics
*graphics
, HDC
*hdc
)
3473 TRACE("(%p, %p)\n", graphics
, hdc
);
3475 if(!graphics
|| !hdc
)
3476 return InvalidParameter
;
3481 *hdc
= graphics
->hdc
;
3482 graphics
->busy
= TRUE
;
3487 GpStatus WINGDIPAPI
GdipReleaseDC(GpGraphics
*graphics
, HDC hdc
)
3489 TRACE("(%p, %p)\n", graphics
, hdc
);
3492 return InvalidParameter
;
3494 if(graphics
->hdc
!= hdc
|| !(graphics
->busy
))
3495 return InvalidParameter
;
3497 graphics
->busy
= FALSE
;
3502 GpStatus WINGDIPAPI
GdipGetClip(GpGraphics
*graphics
, GpRegion
*region
)
3507 TRACE("(%p, %p)\n", graphics
, region
);
3509 if(!graphics
|| !region
)
3510 return InvalidParameter
;
3515 if((status
= GdipCloneRegion(graphics
->clip
, &clip
)) != Ok
)
3518 /* free everything except root node and header */
3519 delete_element(®ion
->node
);
3520 memcpy(region
, clip
, sizeof(GpRegion
));
3525 GpStatus WINGDIPAPI
GdipTransformPoints(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
3526 GpCoordinateSpace src_space
, GpPointF
*points
, INT count
)
3528 if(!graphics
|| !points
|| count
<= 0)
3529 return InvalidParameter
;
3534 FIXME("(%p, %d, %d, %p, %d): stub\n", graphics
, dst_space
, src_space
, points
, count
);
3536 return NotImplemented
;
3539 GpStatus WINGDIPAPI
GdipTransformPointsI(GpGraphics
*graphics
, GpCoordinateSpace dst_space
,
3540 GpCoordinateSpace src_space
, GpPoint
*points
, INT count
)
3542 FIXME("(%p, %d, %d, %p, %d): stub\n", graphics
, dst_space
, src_space
, points
, count
);
3544 return NotImplemented
;
3547 HPALETTE WINGDIPAPI
GdipCreateHalftonePalette(void)
3554 /*****************************************************************************
3555 * GdipTranslateClip [GDIPLUS.@]
3557 GpStatus WINGDIPAPI
GdipTranslateClip(GpGraphics
*graphics
, REAL dx
, REAL dy
)
3559 TRACE("(%p, %.2f, %.2f)\n", graphics
, dx
, dy
);
3562 return InvalidParameter
;
3567 return GdipTranslateRegion(graphics
->clip
, dx
, dy
);
3570 /*****************************************************************************
3571 * GdipTranslateClipI [GDIPLUS.@]
3573 GpStatus WINGDIPAPI
GdipTranslateClipI(GpGraphics
*graphics
, INT dx
, INT dy
)
3575 TRACE("(%p, %d, %d)\n", graphics
, dx
, dy
);
3578 return InvalidParameter
;
3583 return GdipTranslateRegion(graphics
->clip
, (REAL
)dx
, (REAL
)dy
);