gdiplus: Avoid calling GdipFillPath() with an empty path.
[wine.git] / dlls / gdiplus / tests / graphics.c
blob5eb0a8a4d00e689e4cb5fc35c6658d9b6116ec59
1 /*
2 * Unit test suite for graphics objects
4 * Copyright (C) 2007 Google (Evan Stade)
5 * Copyright (C) 2012 Dmitry Timoshkov
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <math.h>
24 #include "objbase.h"
25 #include "gdiplus.h"
26 #include "wine/test.h"
28 #define expect(expected, got) ok((got) == (expected), "Expected %d, got %d\n", (INT)(expected), (INT)(got))
29 #define expectf_(expected, got, precision) ok(fabs((expected) - (got)) <= (precision), "Expected %f, got %f\n", (expected), (got))
30 #define expectf(expected, got) expectf_((expected), (got), 0.001)
32 static GpStatus (WINAPI *pGdipGraphicsSetAbort)(GpGraphics*,GdiplusAbort*);
34 static const REAL mm_per_inch = 25.4;
35 static const REAL point_per_inch = 72.0;
36 static HWND hwnd;
38 static void set_rect_empty(RectF *rc)
40 rc->X = 0.0;
41 rc->Y = 0.0;
42 rc->Width = 0.0;
43 rc->Height = 0.0;
46 /* converts a given unit to its value in pixels */
47 static REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi)
49 switch (unit)
51 case UnitPixel:
52 case UnitDisplay:
53 return units;
54 case UnitPoint:
55 return units * dpi / point_per_inch;
56 case UnitInch:
57 return units * dpi;
58 case UnitDocument:
59 return units * dpi / 300.0; /* Per MSDN */
60 case UnitMillimeter:
61 return units * dpi / mm_per_inch;
62 default:
63 ok(0, "Unsupported unit: %d\n", unit);
64 return 0;
68 /* converts value in pixels to a given unit */
69 static REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi)
71 switch (unit)
73 case UnitPixel:
74 case UnitDisplay:
75 return pixels;
76 case UnitPoint:
77 return pixels * point_per_inch / dpi;
78 case UnitInch:
79 return pixels / dpi;
80 case UnitDocument:
81 return pixels * 300.0 / dpi;
82 case UnitMillimeter:
83 return pixels * mm_per_inch / dpi;
84 default:
85 ok(0, "Unsupported unit: %d\n", unit);
86 return 0;
90 static REAL units_scale(GpUnit from, GpUnit to, REAL dpi)
92 REAL pixels = units_to_pixels(1.0, from, dpi);
93 return pixels_to_units(pixels, to, dpi);
96 static GpGraphics *create_graphics(REAL res_x, REAL res_y, GpUnit unit, REAL scale, GpImage **image)
98 GpStatus status;
99 union
101 GpBitmap *bitmap;
102 GpImage *image;
103 } u;
104 GpGraphics *graphics = NULL;
105 REAL res;
107 status = GdipCreateBitmapFromScan0(1, 1, 4, PixelFormat24bppRGB, NULL, &u.bitmap);
108 expect(Ok, status);
110 status = GdipBitmapSetResolution(u.bitmap, res_x, res_y);
111 expect(Ok, status);
112 status = GdipGetImageHorizontalResolution(u.image, &res);
113 expect(Ok, status);
114 expectf(res_x, res);
115 status = GdipGetImageVerticalResolution(u.image, &res);
116 expect(Ok, status);
117 expectf(res_y, res);
119 status = GdipGetImageGraphicsContext(u.image, &graphics);
120 expect(Ok, status);
122 *image = u.image;
124 status = GdipGetDpiX(graphics, &res);
125 expect(Ok, status);
126 expectf(res_x, res);
127 status = GdipGetDpiY(graphics, &res);
128 expect(Ok, status);
129 expectf(res_y, res);
131 status = GdipSetPageUnit(graphics, unit);
132 expect(Ok, status);
133 status = GdipSetPageScale(graphics, scale);
134 expect(Ok, status);
136 return graphics;
139 static void test_constructor_destructor(void)
141 GpStatus stat;
142 GpGraphics *graphics = NULL;
143 HDC hdc = GetDC( hwnd );
145 stat = GdipCreateFromHDC(NULL, &graphics);
146 expect(OutOfMemory, stat);
147 stat = GdipDeleteGraphics(graphics);
148 expect(InvalidParameter, stat);
150 stat = GdipCreateFromHDC(hdc, &graphics);
151 expect(Ok, stat);
152 stat = GdipDeleteGraphics(graphics);
153 expect(Ok, stat);
155 stat = GdipCreateFromHWND(NULL, &graphics);
156 expect(Ok, stat);
157 stat = GdipDeleteGraphics(graphics);
158 expect(Ok, stat);
160 stat = GdipCreateFromHWNDICM(NULL, &graphics);
161 expect(Ok, stat);
162 stat = GdipDeleteGraphics(graphics);
163 expect(Ok, stat);
165 stat = GdipDeleteGraphics(NULL);
166 expect(InvalidParameter, stat);
167 ReleaseDC(hwnd, hdc);
170 typedef struct node{
171 GraphicsState data;
172 struct node * next;
173 } node;
175 /* Linked list prepend function. */
176 static void log_state(GraphicsState data, node ** log)
178 node * new_entry = HeapAlloc(GetProcessHeap(), 0, sizeof(node));
180 new_entry->data = data;
181 new_entry->next = *log;
182 *log = new_entry;
185 /* Checks if there are duplicates in the list, and frees it. */
186 static void check_no_duplicates(node * log)
188 INT dups = 0;
189 node * temp = NULL;
190 node * temp2 = NULL;
191 node * orig = log;
193 if(!log)
194 goto end;
197 temp = log;
198 while((temp = temp->next)){
199 if(log->data == temp->data){
200 dups++;
201 break;
203 if(dups > 0)
204 break;
206 }while((log = log->next));
208 temp = orig;
210 temp2 = temp->next;
211 HeapFree(GetProcessHeap(), 0, temp);
212 temp = temp2;
213 }while(temp);
215 end:
216 expect(0, dups);
219 static void test_save_restore(void)
221 GpStatus stat;
222 GraphicsState state_a, state_b, state_c;
223 InterpolationMode mode;
224 GpGraphics *graphics1, *graphics2;
225 node * state_log = NULL;
226 HDC hdc = GetDC( hwnd );
227 state_a = state_b = state_c = 0xdeadbeef;
229 /* Invalid saving. */
230 GdipCreateFromHDC(hdc, &graphics1);
231 stat = GdipSaveGraphics(graphics1, NULL);
232 expect(InvalidParameter, stat);
233 stat = GdipSaveGraphics(NULL, &state_a);
234 expect(InvalidParameter, stat);
235 GdipDeleteGraphics(graphics1);
237 log_state(state_a, &state_log);
239 /* Basic save/restore. */
240 GdipCreateFromHDC(hdc, &graphics1);
241 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
242 stat = GdipSaveGraphics(graphics1, &state_a);
243 expect(Ok, stat);
244 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
245 stat = GdipRestoreGraphics(graphics1, state_a);
246 expect(Ok, stat);
247 GdipGetInterpolationMode(graphics1, &mode);
248 expect(InterpolationModeBilinear, mode);
249 GdipDeleteGraphics(graphics1);
251 log_state(state_a, &state_log);
253 /* Restoring garbage doesn't affect saves. */
254 GdipCreateFromHDC(hdc, &graphics1);
255 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
256 GdipSaveGraphics(graphics1, &state_a);
257 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
258 GdipSaveGraphics(graphics1, &state_b);
259 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
260 stat = GdipRestoreGraphics(graphics1, 0xdeadbeef);
261 expect(Ok, stat);
262 GdipRestoreGraphics(graphics1, state_b);
263 GdipGetInterpolationMode(graphics1, &mode);
264 expect(InterpolationModeBicubic, mode);
265 GdipRestoreGraphics(graphics1, state_a);
266 GdipGetInterpolationMode(graphics1, &mode);
267 expect(InterpolationModeBilinear, mode);
268 GdipDeleteGraphics(graphics1);
270 log_state(state_a, &state_log);
271 log_state(state_b, &state_log);
273 /* Restoring older state invalidates newer saves (but not older saves). */
274 GdipCreateFromHDC(hdc, &graphics1);
275 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
276 GdipSaveGraphics(graphics1, &state_a);
277 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
278 GdipSaveGraphics(graphics1, &state_b);
279 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
280 GdipSaveGraphics(graphics1, &state_c);
281 GdipSetInterpolationMode(graphics1, InterpolationModeHighQualityBilinear);
282 GdipRestoreGraphics(graphics1, state_b);
283 GdipGetInterpolationMode(graphics1, &mode);
284 expect(InterpolationModeBicubic, mode);
285 GdipRestoreGraphics(graphics1, state_c);
286 GdipGetInterpolationMode(graphics1, &mode);
287 expect(InterpolationModeBicubic, mode);
288 GdipRestoreGraphics(graphics1, state_a);
289 GdipGetInterpolationMode(graphics1, &mode);
290 expect(InterpolationModeBilinear, mode);
291 GdipDeleteGraphics(graphics1);
293 log_state(state_a, &state_log);
294 log_state(state_b, &state_log);
295 log_state(state_c, &state_log);
297 /* Restoring older save from one graphics object does not invalidate
298 * newer save from other graphics object. */
299 GdipCreateFromHDC(hdc, &graphics1);
300 GdipCreateFromHDC(hdc, &graphics2);
301 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
302 GdipSaveGraphics(graphics1, &state_a);
303 GdipSetInterpolationMode(graphics2, InterpolationModeBicubic);
304 GdipSaveGraphics(graphics2, &state_b);
305 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
306 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
307 GdipRestoreGraphics(graphics1, state_a);
308 GdipGetInterpolationMode(graphics1, &mode);
309 expect(InterpolationModeBilinear, mode);
310 GdipRestoreGraphics(graphics2, state_b);
311 GdipGetInterpolationMode(graphics2, &mode);
312 expect(InterpolationModeBicubic, mode);
313 GdipDeleteGraphics(graphics1);
314 GdipDeleteGraphics(graphics2);
316 /* You can't restore a state to a graphics object that didn't save it. */
317 GdipCreateFromHDC(hdc, &graphics1);
318 GdipCreateFromHDC(hdc, &graphics2);
319 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
320 GdipSaveGraphics(graphics1, &state_a);
321 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
322 GdipSetInterpolationMode(graphics2, InterpolationModeNearestNeighbor);
323 GdipRestoreGraphics(graphics2, state_a);
324 GdipGetInterpolationMode(graphics2, &mode);
325 expect(InterpolationModeNearestNeighbor, mode);
326 GdipDeleteGraphics(graphics1);
327 GdipDeleteGraphics(graphics2);
329 log_state(state_a, &state_log);
331 /* A state created by SaveGraphics cannot be restored with EndContainer. */
332 GdipCreateFromHDC(hdc, &graphics1);
333 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
334 stat = GdipSaveGraphics(graphics1, &state_a);
335 expect(Ok, stat);
336 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
337 stat = GdipEndContainer(graphics1, state_a);
338 expect(Ok, stat);
339 GdipGetInterpolationMode(graphics1, &mode);
340 expect(InterpolationModeBicubic, mode);
341 stat = GdipRestoreGraphics(graphics1, state_a);
342 expect(Ok, stat);
343 GdipGetInterpolationMode(graphics1, &mode);
344 expect(InterpolationModeBilinear, mode);
345 GdipDeleteGraphics(graphics1);
347 log_state(state_a, &state_log);
349 /* A state created by BeginContainer cannot be restored with RestoreGraphics. */
350 GdipCreateFromHDC(hdc, &graphics1);
351 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
352 stat = GdipBeginContainer2(graphics1, &state_a);
353 expect(Ok, stat);
354 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
355 stat = GdipRestoreGraphics(graphics1, state_a);
356 expect(Ok, stat);
357 GdipGetInterpolationMode(graphics1, &mode);
358 expect(InterpolationModeBicubic, mode);
359 stat = GdipEndContainer(graphics1, state_a);
360 expect(Ok, stat);
361 GdipGetInterpolationMode(graphics1, &mode);
362 expect(InterpolationModeBilinear, mode);
363 GdipDeleteGraphics(graphics1);
365 log_state(state_a, &state_log);
367 /* BeginContainer and SaveGraphics use the same stack. */
368 stat = GdipCreateFromHDC(hdc, &graphics1);
369 expect(Ok, stat);
370 GdipSetInterpolationMode(graphics1, InterpolationModeBilinear);
371 stat = GdipBeginContainer2(graphics1, &state_a);
372 expect(Ok, stat);
373 GdipSetInterpolationMode(graphics1, InterpolationModeBicubic);
374 stat = GdipSaveGraphics(graphics1, &state_b);
375 expect(Ok, stat);
376 GdipSetInterpolationMode(graphics1, InterpolationModeNearestNeighbor);
377 stat = GdipEndContainer(graphics1, state_a);
378 expect(Ok, stat);
379 GdipGetInterpolationMode(graphics1, &mode);
380 expect(InterpolationModeBilinear, mode);
381 stat = GdipRestoreGraphics(graphics1, state_b);
382 expect(Ok, stat);
383 GdipGetInterpolationMode(graphics1, &mode);
384 expect(InterpolationModeBilinear, mode);
385 GdipDeleteGraphics(graphics1);
387 log_state(state_a, &state_log);
388 log_state(state_b, &state_log);
390 /* The same state value should never be returned twice. */
391 todo_wine
392 check_no_duplicates(state_log);
394 ReleaseDC(hwnd, hdc);
397 static void test_GdipFillClosedCurve2(void)
399 GpStatus status;
400 GpGraphics *graphics = NULL;
401 GpSolidFill *brush = NULL;
402 HDC hdc = GetDC( hwnd );
403 GpPointF points[3];
405 points[0].X = 0;
406 points[0].Y = 0;
408 points[1].X = 40;
409 points[1].Y = 20;
411 points[2].X = 10;
412 points[2].Y = 40;
414 /* make a graphics object and brush object */
415 ok(hdc != NULL, "Expected HDC to be initialized\n");
417 status = GdipCreateFromHDC(hdc, &graphics);
418 expect(Ok, status);
419 ok(graphics != NULL, "Expected graphics to be initialized\n");
421 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
423 /* InvalidParameter cases: null graphics, null brush, null points */
424 status = GdipFillClosedCurve2(NULL, NULL, NULL, 3, 0.5, FillModeAlternate);
425 expect(InvalidParameter, status);
427 status = GdipFillClosedCurve2(graphics, NULL, NULL, 3, 0.5, FillModeAlternate);
428 expect(InvalidParameter, status);
430 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
431 expect(InvalidParameter, status);
433 status = GdipFillClosedCurve2(NULL, NULL, points, 3, 0.5, FillModeAlternate);
434 expect(InvalidParameter, status);
436 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, NULL, 3, 0.5, FillModeAlternate);
437 expect(InvalidParameter, status);
439 status = GdipFillClosedCurve2(graphics, NULL, points, 3, 0.5, FillModeAlternate);
440 expect(InvalidParameter, status);
442 status = GdipFillClosedCurve2(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
443 expect(InvalidParameter, status);
445 /* InvalidParameter cases: invalid count */
446 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
447 expect(InvalidParameter, status);
449 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
450 expect(InvalidParameter, status);
452 /* Valid test cases */
453 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
454 expect(Ok, status);
456 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
457 expect(Ok, status);
459 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
460 expect(Ok, status);
462 GdipDeleteGraphics(graphics);
463 GdipDeleteBrush((GpBrush*)brush);
465 ReleaseDC(hwnd, hdc);
468 static void test_GdipFillClosedCurve2I(void)
470 GpStatus status;
471 GpGraphics *graphics = NULL;
472 GpSolidFill *brush = NULL;
473 HDC hdc = GetDC( hwnd );
474 GpPoint points[3];
476 points[0].X = 0;
477 points[0].Y = 0;
479 points[1].X = 40;
480 points[1].Y = 20;
482 points[2].X = 10;
483 points[2].Y = 40;
485 /* make a graphics object and brush object */
486 ok(hdc != NULL, "Expected HDC to be initialized\n");
488 status = GdipCreateFromHDC(hdc, &graphics);
489 expect(Ok, status);
490 ok(graphics != NULL, "Expected graphics to be initialized\n");
492 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
494 /* InvalidParameter cases: null graphics, null brush */
495 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
496 when points == NULL, so don't test this condition */
497 status = GdipFillClosedCurve2I(NULL, NULL, points, 3, 0.5, FillModeAlternate);
498 expect(InvalidParameter, status);
500 status = GdipFillClosedCurve2I(graphics, NULL, points, 3, 0.5, FillModeAlternate);
501 expect(InvalidParameter, status);
503 status = GdipFillClosedCurve2I(NULL, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
504 expect(InvalidParameter, status);
506 /* InvalidParameter cases: invalid count */
507 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 0, 0.5, FillModeAlternate);
508 expect(InvalidParameter, status);
510 /* OutOfMemory cases: large (unsigned) int */
511 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, -1, 0.5, FillModeAlternate);
512 expect(OutOfMemory, status);
514 /* Valid test cases */
515 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 1, 0.5, FillModeAlternate);
516 expect(Ok, status);
518 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 2, 0.5, FillModeAlternate);
519 expect(Ok, status);
521 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, points, 3, 0.5, FillModeAlternate);
522 expect(Ok, status);
524 GdipDeleteGraphics(graphics);
525 GdipDeleteBrush((GpBrush*)brush);
527 ReleaseDC(hwnd, hdc);
530 static void test_GdipDrawArc(void)
532 GpStatus status;
533 GpGraphics *graphics = NULL;
534 GpPen *pen = NULL;
535 HDC hdc = GetDC( hwnd );
537 /* make a graphics object and pen object */
538 ok(hdc != NULL, "Expected HDC to be initialized\n");
540 status = GdipCreateFromHDC(hdc, &graphics);
541 expect(Ok, status);
542 ok(graphics != NULL, "Expected graphics to be initialized\n");
544 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
545 expect(Ok, status);
546 ok(pen != NULL, "Expected pen to be initialized\n");
548 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
549 status = GdipDrawArc(NULL, NULL, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
550 expect(InvalidParameter, status);
552 status = GdipDrawArc(graphics, NULL, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
553 expect(InvalidParameter, status);
555 status = GdipDrawArc(NULL, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
556 expect(InvalidParameter, status);
558 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0);
559 expect(InvalidParameter, status);
561 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
562 expect(InvalidParameter, status);
564 /* successful case */
565 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
566 expect(Ok, status);
568 GdipDeletePen(pen);
569 GdipDeleteGraphics(graphics);
571 ReleaseDC(hwnd, hdc);
574 static void test_GdipDrawArcI(void)
576 GpStatus status;
577 GpGraphics *graphics = NULL;
578 GpPen *pen = NULL;
579 HDC hdc = GetDC( hwnd );
581 /* make a graphics object and pen object */
582 ok(hdc != NULL, "Expected HDC to be initialized\n");
584 status = GdipCreateFromHDC(hdc, &graphics);
585 expect(Ok, status);
586 ok(graphics != NULL, "Expected graphics to be initialized\n");
588 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
589 expect(Ok, status);
590 ok(pen != NULL, "Expected pen to be initialized\n");
592 /* InvalidParameter cases: null graphics, null pen, non-positive width, non-positive height */
593 status = GdipDrawArcI(NULL, NULL, 0, 0, 0, 0, 0, 0);
594 expect(InvalidParameter, status);
596 status = GdipDrawArcI(graphics, NULL, 0, 0, 1, 1, 0, 0);
597 expect(InvalidParameter, status);
599 status = GdipDrawArcI(NULL, pen, 0, 0, 1, 1, 0, 0);
600 expect(InvalidParameter, status);
602 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 0, 0, 0);
603 expect(InvalidParameter, status);
605 status = GdipDrawArcI(graphics, pen, 0, 0, 0, 1, 0, 0);
606 expect(InvalidParameter, status);
608 /* successful case */
609 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0, 0);
610 expect(Ok, status);
612 GdipDeletePen(pen);
613 GdipDeleteGraphics(graphics);
615 ReleaseDC(hwnd, hdc);
618 static void test_BeginContainer2(void)
620 GpMatrix *transform;
621 GpRectF clip;
622 REAL defClip[] = {5, 10, 15, 20};
623 REAL elems[6], defTrans[] = {1, 2, 3, 4, 5, 6};
624 GraphicsContainer cont1, cont2, cont3, cont4;
625 CompositingQuality compqual, defCompqual = CompositingQualityHighSpeed;
626 CompositingMode compmode, defCompmode = CompositingModeSourceOver;
627 InterpolationMode interp, defInterp = InterpolationModeHighQualityBicubic;
628 REAL scale, defScale = 17;
629 GpUnit unit, defUnit = UnitPixel;
630 PixelOffsetMode offsetmode, defOffsetmode = PixelOffsetModeHighSpeed;
631 SmoothingMode smoothmode, defSmoothmode = SmoothingModeAntiAlias;
632 UINT contrast, defContrast = 5;
633 TextRenderingHint texthint, defTexthint = TextRenderingHintAntiAlias;
635 GpStatus status;
636 GpGraphics *graphics = NULL;
637 HDC hdc = GetDC( hwnd );
639 ok(hdc != NULL, "Expected HDC to be initialized\n");
641 status = GdipCreateFromHDC(hdc, &graphics);
642 expect(Ok, status);
643 ok(graphics != NULL, "Expected graphics to be initialized\n");
645 /* null graphics, null container */
646 status = GdipBeginContainer2(NULL, &cont1);
647 expect(InvalidParameter, status);
649 status = GdipBeginContainer2(graphics, NULL);
650 expect(InvalidParameter, status);
652 status = GdipEndContainer(NULL, cont1);
653 expect(InvalidParameter, status);
655 /* test all quality-related values */
656 GdipSetCompositingMode(graphics, defCompmode);
657 GdipSetCompositingQuality(graphics, defCompqual);
658 GdipSetInterpolationMode(graphics, defInterp);
659 GdipSetPageScale(graphics, defScale);
660 GdipSetPageUnit(graphics, defUnit);
661 GdipSetPixelOffsetMode(graphics, defOffsetmode);
662 GdipSetSmoothingMode(graphics, defSmoothmode);
663 GdipSetTextContrast(graphics, defContrast);
664 GdipSetTextRenderingHint(graphics, defTexthint);
666 status = GdipBeginContainer2(graphics, &cont1);
667 expect(Ok, status);
669 GdipSetCompositingMode(graphics, CompositingModeSourceCopy);
670 GdipSetCompositingQuality(graphics, CompositingQualityHighQuality);
671 GdipSetInterpolationMode(graphics, InterpolationModeBilinear);
672 GdipSetPageScale(graphics, 10);
673 GdipSetPageUnit(graphics, UnitDocument);
674 GdipSetPixelOffsetMode(graphics, PixelOffsetModeHalf);
675 GdipSetSmoothingMode(graphics, SmoothingModeNone);
676 GdipSetTextContrast(graphics, 7);
677 GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit);
679 status = GdipEndContainer(graphics, cont1);
680 expect(Ok, status);
682 GdipGetCompositingMode(graphics, &compmode);
683 ok(defCompmode == compmode, "Expected Compositing Mode to be restored to %d, got %d\n", defCompmode, compmode);
685 GdipGetCompositingQuality(graphics, &compqual);
686 ok(defCompqual == compqual, "Expected Compositing Quality to be restored to %d, got %d\n", defCompqual, compqual);
688 GdipGetInterpolationMode(graphics, &interp);
689 ok(defInterp == interp, "Expected Interpolation Mode to be restored to %d, got %d\n", defInterp, interp);
691 GdipGetPageScale(graphics, &scale);
692 ok(fabs(defScale - scale) < 0.0001, "Expected Page Scale to be restored to %f, got %f\n", defScale, scale);
694 GdipGetPageUnit(graphics, &unit);
695 ok(defUnit == unit, "Expected Page Unit to be restored to %d, got %d\n", defUnit, unit);
697 GdipGetPixelOffsetMode(graphics, &offsetmode);
698 ok(defOffsetmode == offsetmode, "Expected Pixel Offset Mode to be restored to %d, got %d\n", defOffsetmode, offsetmode);
700 GdipGetSmoothingMode(graphics, &smoothmode);
701 ok(defSmoothmode == smoothmode, "Expected Smoothing Mode to be restored to %d, got %d\n", defSmoothmode, smoothmode);
703 GdipGetTextContrast(graphics, &contrast);
704 ok(defContrast == contrast, "Expected Text Contrast to be restored to %d, got %d\n", defContrast, contrast);
706 GdipGetTextRenderingHint(graphics, &texthint);
707 ok(defTexthint == texthint, "Expected Text Hint to be restored to %d, got %d\n", defTexthint, texthint);
709 /* test world transform */
710 status = GdipBeginContainer2(graphics, &cont1);
711 expect(Ok, status);
713 status = GdipCreateMatrix2(defTrans[0], defTrans[1], defTrans[2], defTrans[3],
714 defTrans[4], defTrans[5], &transform);
715 expect(Ok, status);
716 GdipSetWorldTransform(graphics, transform);
717 GdipDeleteMatrix(transform);
718 transform = NULL;
720 status = GdipBeginContainer2(graphics, &cont2);
721 expect(Ok, status);
723 status = GdipCreateMatrix2(10, 20, 30, 40, 50, 60, &transform);
724 expect(Ok, status);
725 GdipSetWorldTransform(graphics, transform);
726 GdipDeleteMatrix(transform);
727 transform = NULL;
729 status = GdipEndContainer(graphics, cont2);
730 expect(Ok, status);
732 status = GdipCreateMatrix(&transform);
733 expect(Ok, status);
734 GdipGetWorldTransform(graphics, transform);
735 status = GdipGetMatrixElements(transform, elems);
736 expect(Ok, status);
737 ok(fabs(defTrans[0] - elems[0]) < 0.0001 &&
738 fabs(defTrans[1] - elems[1]) < 0.0001 &&
739 fabs(defTrans[2] - elems[2]) < 0.0001 &&
740 fabs(defTrans[3] - elems[3]) < 0.0001 &&
741 fabs(defTrans[4] - elems[4]) < 0.0001 &&
742 fabs(defTrans[5] - elems[5]) < 0.0001,
743 "Expected World Transform Matrix to be restored to [%f, %f, %f, %f, %f, %f], got [%f, %f, %f, %f, %f, %f]\n",
744 defTrans[0], defTrans[1], defTrans[2], defTrans[3], defTrans[4], defTrans[5],
745 elems[0], elems[1], elems[2], elems[3], elems[4], elems[5]);
746 GdipDeleteMatrix(transform);
747 transform = NULL;
749 status = GdipEndContainer(graphics, cont1);
750 expect(Ok, status);
752 /* test clipping */
753 status = GdipBeginContainer2(graphics, &cont1);
754 expect(Ok, status);
756 GdipSetClipRect(graphics, defClip[0], defClip[1], defClip[2], defClip[3], CombineModeReplace);
758 status = GdipBeginContainer2(graphics, &cont2);
759 expect(Ok, status);
761 GdipSetClipRect(graphics, 2, 4, 6, 8, CombineModeReplace);
763 status = GdipEndContainer(graphics, cont2);
764 expect(Ok, status);
766 status = GdipGetClipBounds(graphics, &clip);
767 expect(Ok, status);
769 ok(fabs(defClip[0] - clip.X) < 0.0001 &&
770 fabs(defClip[1] - clip.Y) < 0.0001 &&
771 fabs(defClip[2] - clip.Width) < 0.0001 &&
772 fabs(defClip[3] - clip.Height) < 0.0001,
773 "Expected Clipping Rectangle to be restored to [%f, %f, %f, %f], got [%f, %f, %f, %f]\n",
774 defClip[0], defClip[1], defClip[2], defClip[3],
775 clip.X, clip.Y, clip.Width, clip.Height);
777 status = GdipEndContainer(graphics, cont1);
778 expect(Ok, status);
780 /* nesting */
781 status = GdipBeginContainer2(graphics, &cont1);
782 expect(Ok, status);
784 status = GdipBeginContainer2(graphics, &cont2);
785 expect(Ok, status);
787 status = GdipBeginContainer2(graphics, &cont3);
788 expect(Ok, status);
790 status = GdipEndContainer(graphics, cont3);
791 expect(Ok, status);
793 status = GdipBeginContainer2(graphics, &cont4);
794 expect(Ok, status);
796 status = GdipEndContainer(graphics, cont4);
797 expect(Ok, status);
799 /* skip cont2 */
800 status = GdipEndContainer(graphics, cont1);
801 expect(Ok, status);
803 /* end an already-ended container */
804 status = GdipEndContainer(graphics, cont1);
805 expect(Ok, status);
807 GdipDeleteGraphics(graphics);
808 ReleaseDC(hwnd, hdc);
811 static void test_GdipDrawBezierI(void)
813 GpStatus status;
814 GpGraphics *graphics = NULL;
815 GpPen *pen = NULL;
816 HDC hdc = GetDC( hwnd );
818 /* make a graphics object and pen object */
819 ok(hdc != NULL, "Expected HDC to be initialized\n");
821 status = GdipCreateFromHDC(hdc, &graphics);
822 expect(Ok, status);
823 ok(graphics != NULL, "Expected graphics to be initialized\n");
825 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
826 expect(Ok, status);
827 ok(pen != NULL, "Expected pen to be initialized\n");
829 /* InvalidParameter cases: null graphics, null pen */
830 status = GdipDrawBezierI(NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
831 expect(InvalidParameter, status);
833 status = GdipDrawBezierI(graphics, NULL, 0, 0, 0, 0, 0, 0, 0, 0);
834 expect(InvalidParameter, status);
836 status = GdipDrawBezierI(NULL, pen, 0, 0, 0, 0, 0, 0, 0, 0);
837 expect(InvalidParameter, status);
839 /* successful case */
840 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
841 expect(Ok, status);
843 GdipDeletePen(pen);
844 GdipDeleteGraphics(graphics);
846 ReleaseDC(hwnd, hdc);
849 static void test_GdipDrawCurve3(void)
851 GpStatus status;
852 GpGraphics *graphics = NULL;
853 GpPen *pen = NULL;
854 HDC hdc = GetDC( hwnd );
855 GpPointF points[3];
857 points[0].X = 0;
858 points[0].Y = 0;
860 points[1].X = 40;
861 points[1].Y = 20;
863 points[2].X = 10;
864 points[2].Y = 40;
866 /* make a graphics object and pen object */
867 ok(hdc != NULL, "Expected HDC to be initialized\n");
869 status = GdipCreateFromHDC(hdc, &graphics);
870 expect(Ok, status);
871 ok(graphics != NULL, "Expected graphics to be initialized\n");
873 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
874 expect(Ok, status);
875 ok(pen != NULL, "Expected pen to be initialized\n");
877 /* InvalidParameter cases: null graphics, null pen */
878 status = GdipDrawCurve3(NULL, NULL, points, 3, 0, 2, 1);
879 expect(InvalidParameter, status);
881 status = GdipDrawCurve3(graphics, NULL, points, 3, 0, 2, 1);
882 expect(InvalidParameter, status);
884 status = GdipDrawCurve3(NULL, pen, points, 3, 0, 2, 1);
885 expect(InvalidParameter, status);
887 /* InvalidParameter cases: invalid count */
888 status = GdipDrawCurve3(graphics, pen, points, -1, 0, 2, 1);
889 expect(InvalidParameter, status);
891 status = GdipDrawCurve3(graphics, pen, points, 0, 0, 2, 1);
892 expect(InvalidParameter, status);
894 status = GdipDrawCurve3(graphics, pen, points, 1, 0, 0, 1);
895 expect(InvalidParameter, status);
897 status = GdipDrawCurve3(graphics, pen, points, 3, 4, 2, 1);
898 expect(InvalidParameter, status);
900 /* InvalidParameter cases: invalid number of segments */
901 status = GdipDrawCurve3(graphics, pen, points, 3, 0, -1, 1);
902 expect(InvalidParameter, status);
904 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 2, 1);
905 expect(InvalidParameter, status);
907 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 2, 1);
908 expect(InvalidParameter, status);
910 /* Valid test cases */
911 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, 1);
912 expect(Ok, status);
914 status = GdipDrawCurve3(graphics, pen, points, 3, 0, 2, 2);
915 expect(Ok, status);
917 status = GdipDrawCurve3(graphics, pen, points, 2, 0, 1, -2);
918 expect(Ok, status);
920 status = GdipDrawCurve3(graphics, pen, points, 3, 1, 1, 0);
921 expect(Ok, status);
923 GdipDeletePen(pen);
924 GdipDeleteGraphics(graphics);
926 ReleaseDC(hwnd, hdc);
929 static void test_GdipDrawCurve3I(void)
931 GpStatus status;
932 GpGraphics *graphics = NULL;
933 GpPen *pen = NULL;
934 HDC hdc = GetDC( hwnd );
935 GpPoint points[3];
937 points[0].X = 0;
938 points[0].Y = 0;
940 points[1].X = 40;
941 points[1].Y = 20;
943 points[2].X = 10;
944 points[2].Y = 40;
946 /* make a graphics object and pen object */
947 ok(hdc != NULL, "Expected HDC to be initialized\n");
949 status = GdipCreateFromHDC(hdc, &graphics);
950 expect(Ok, status);
951 ok(graphics != NULL, "Expected graphics to be initialized\n");
953 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
954 expect(Ok, status);
955 ok(pen != NULL, "Expected pen to be initialized\n");
957 /* InvalidParameter cases: null graphics, null pen */
958 status = GdipDrawCurve3I(NULL, NULL, points, 3, 0, 2, 1);
959 expect(InvalidParameter, status);
961 status = GdipDrawCurve3I(graphics, NULL, points, 3, 0, 2, 1);
962 expect(InvalidParameter, status);
964 status = GdipDrawCurve3I(NULL, pen, points, 3, 0, 2, 1);
965 expect(InvalidParameter, status);
967 /* InvalidParameter cases: invalid count */
968 status = GdipDrawCurve3I(graphics, pen, points, -1, -1, -1, 1);
969 expect(OutOfMemory, status);
971 status = GdipDrawCurve3I(graphics, pen, points, 0, 0, 2, 1);
972 expect(InvalidParameter, status);
974 status = GdipDrawCurve3I(graphics, pen, points, 1, 0, 0, 1);
975 expect(InvalidParameter, status);
977 status = GdipDrawCurve3I(graphics, pen, points, 3, 4, 2, 1);
978 expect(InvalidParameter, status);
980 /* InvalidParameter cases: invalid number of segments */
981 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, -1, 1);
982 expect(InvalidParameter, status);
984 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 2, 1);
985 expect(InvalidParameter, status);
987 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 2, 1);
988 expect(InvalidParameter, status);
990 /* Valid test cases */
991 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, 1);
992 expect(Ok, status);
994 status = GdipDrawCurve3I(graphics, pen, points, 3, 0, 2, 2);
995 expect(Ok, status);
997 status = GdipDrawCurve3I(graphics, pen, points, 2, 0, 1, -2);
998 expect(Ok, status);
1000 status = GdipDrawCurve3I(graphics, pen, points, 3, 1, 1, 0);
1001 expect(Ok, status);
1003 GdipDeletePen(pen);
1004 GdipDeleteGraphics(graphics);
1006 ReleaseDC(hwnd, hdc);
1009 static void test_GdipDrawCurve2(void)
1011 GpStatus status;
1012 GpGraphics *graphics = NULL;
1013 GpPen *pen = NULL;
1014 HDC hdc = GetDC( hwnd );
1015 GpPointF points[3];
1017 points[0].X = 0;
1018 points[0].Y = 0;
1020 points[1].X = 40;
1021 points[1].Y = 20;
1023 points[2].X = 10;
1024 points[2].Y = 40;
1026 /* make a graphics object and pen object */
1027 ok(hdc != NULL, "Expected HDC to be initialized\n");
1029 status = GdipCreateFromHDC(hdc, &graphics);
1030 expect(Ok, status);
1031 ok(graphics != NULL, "Expected graphics to be initialized\n");
1033 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1034 expect(Ok, status);
1035 ok(pen != NULL, "Expected pen to be initialized\n");
1037 /* InvalidParameter cases: null graphics, null pen */
1038 status = GdipDrawCurve2(NULL, NULL, points, 3, 1);
1039 expect(InvalidParameter, status);
1041 status = GdipDrawCurve2(graphics, NULL, points, 3, 1);
1042 expect(InvalidParameter, status);
1044 status = GdipDrawCurve2(NULL, pen, points, 3, 1);
1045 expect(InvalidParameter, status);
1047 /* InvalidParameter cases: invalid count */
1048 status = GdipDrawCurve2(graphics, pen, points, -1, 1);
1049 expect(InvalidParameter, status);
1051 status = GdipDrawCurve2(graphics, pen, points, 0, 1);
1052 expect(InvalidParameter, status);
1054 status = GdipDrawCurve2(graphics, pen, points, 1, 1);
1055 expect(InvalidParameter, status);
1057 /* Valid test cases */
1058 status = GdipDrawCurve2(graphics, pen, points, 2, 1);
1059 expect(Ok, status);
1061 status = GdipDrawCurve2(graphics, pen, points, 3, 2);
1062 expect(Ok, status);
1064 status = GdipDrawCurve2(graphics, pen, points, 3, -2);
1065 expect(Ok, status);
1067 status = GdipDrawCurve2(graphics, pen, points, 3, 0);
1068 expect(Ok, status);
1070 GdipDeletePen(pen);
1071 GdipDeleteGraphics(graphics);
1073 ReleaseDC(hwnd, hdc);
1076 static void test_GdipDrawCurve2I(void)
1078 GpStatus status;
1079 GpGraphics *graphics = NULL;
1080 GpPen *pen = NULL;
1081 HDC hdc = GetDC( hwnd );
1082 GpPoint points[3];
1084 points[0].X = 0;
1085 points[0].Y = 0;
1087 points[1].X = 40;
1088 points[1].Y = 20;
1090 points[2].X = 10;
1091 points[2].Y = 40;
1093 /* make a graphics object and pen object */
1094 ok(hdc != NULL, "Expected HDC to be initialized\n");
1096 status = GdipCreateFromHDC(hdc, &graphics);
1097 expect(Ok, status);
1098 ok(graphics != NULL, "Expected graphics to be initialized\n");
1100 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1101 expect(Ok, status);
1102 ok(pen != NULL, "Expected pen to be initialized\n");
1104 /* InvalidParameter cases: null graphics, null pen */
1105 status = GdipDrawCurve2I(NULL, NULL, points, 3, 1);
1106 expect(InvalidParameter, status);
1108 status = GdipDrawCurve2I(graphics, NULL, points, 3, 1);
1109 expect(InvalidParameter, status);
1111 status = GdipDrawCurve2I(NULL, pen, points, 3, 1);
1112 expect(InvalidParameter, status);
1114 /* InvalidParameter cases: invalid count */
1115 status = GdipDrawCurve2I(graphics, pen, points, -1, 1);
1116 expect(OutOfMemory, status);
1118 status = GdipDrawCurve2I(graphics, pen, points, 0, 1);
1119 expect(InvalidParameter, status);
1121 status = GdipDrawCurve2I(graphics, pen, points, 1, 1);
1122 expect(InvalidParameter, status);
1124 /* Valid test cases */
1125 status = GdipDrawCurve2I(graphics, pen, points, 2, 1);
1126 expect(Ok, status);
1128 status = GdipDrawCurve2I(graphics, pen, points, 3, 2);
1129 expect(Ok, status);
1131 status = GdipDrawCurve2I(graphics, pen, points, 3, -2);
1132 expect(Ok, status);
1134 status = GdipDrawCurve2I(graphics, pen, points, 3, 0);
1135 expect(Ok, status);
1137 GdipDeletePen(pen);
1138 GdipDeleteGraphics(graphics);
1140 ReleaseDC(hwnd, hdc);
1143 static void test_GdipDrawCurve(void)
1145 GpStatus status;
1146 GpGraphics *graphics = NULL;
1147 GpPen *pen = NULL;
1148 HDC hdc = GetDC( hwnd );
1149 GpPointF points[3];
1151 points[0].X = 0;
1152 points[0].Y = 0;
1154 points[1].X = 40;
1155 points[1].Y = 20;
1157 points[2].X = 10;
1158 points[2].Y = 40;
1160 /* make a graphics object and pen object */
1161 ok(hdc != NULL, "Expected HDC to be initialized\n");
1163 status = GdipCreateFromHDC(hdc, &graphics);
1164 expect(Ok, status);
1165 ok(graphics != NULL, "Expected graphics to be initialized\n");
1167 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1168 expect(Ok, status);
1169 ok(pen != NULL, "Expected pen to be initialized\n");
1171 /* InvalidParameter cases: null graphics, null pen */
1172 status = GdipDrawCurve(NULL, NULL, points, 3);
1173 expect(InvalidParameter, status);
1175 status = GdipDrawCurve(graphics, NULL, points, 3);
1176 expect(InvalidParameter, status);
1178 status = GdipDrawCurve(NULL, pen, points, 3);
1179 expect(InvalidParameter, status);
1181 /* InvalidParameter cases: invalid count */
1182 status = GdipDrawCurve(graphics, pen, points, -1);
1183 expect(InvalidParameter, status);
1185 status = GdipDrawCurve(graphics, pen, points, 0);
1186 expect(InvalidParameter, status);
1188 status = GdipDrawCurve(graphics, pen, points, 1);
1189 expect(InvalidParameter, status);
1191 /* Valid test cases */
1192 status = GdipDrawCurve(graphics, pen, points, 2);
1193 expect(Ok, status);
1195 status = GdipDrawCurve(graphics, pen, points, 3);
1196 expect(Ok, status);
1198 GdipDeletePen(pen);
1199 GdipDeleteGraphics(graphics);
1201 ReleaseDC(hwnd, hdc);
1204 static void test_GdipDrawCurveI(void)
1206 GpStatus status;
1207 GpGraphics *graphics = NULL;
1208 GpPen *pen = NULL;
1209 HDC hdc = GetDC( hwnd );
1210 GpPoint points[3];
1212 points[0].X = 0;
1213 points[0].Y = 0;
1215 points[1].X = 40;
1216 points[1].Y = 20;
1218 points[2].X = 10;
1219 points[2].Y = 40;
1221 /* make a graphics object and pen object */
1222 ok(hdc != NULL, "Expected HDC to be initialized\n");
1224 status = GdipCreateFromHDC(hdc, &graphics);
1225 expect(Ok, status);
1226 ok(graphics != NULL, "Expected graphics to be initialized\n");
1228 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1229 expect(Ok, status);
1230 ok(pen != NULL, "Expected pen to be initialized\n");
1232 /* InvalidParameter cases: null graphics, null pen */
1233 status = GdipDrawCurveI(NULL, NULL, points, 3);
1234 expect(InvalidParameter, status);
1236 status = GdipDrawCurveI(graphics, NULL, points, 3);
1237 expect(InvalidParameter, status);
1239 status = GdipDrawCurveI(NULL, pen, points, 3);
1240 expect(InvalidParameter, status);
1242 /* InvalidParameter cases: invalid count */
1243 status = GdipDrawCurveI(graphics, pen, points, -1);
1244 expect(OutOfMemory, status);
1246 status = GdipDrawCurveI(graphics, pen, points, 0);
1247 expect(InvalidParameter, status);
1249 status = GdipDrawCurveI(graphics, pen, points, 1);
1250 expect(InvalidParameter, status);
1252 /* Valid test cases */
1253 status = GdipDrawCurveI(graphics, pen, points, 2);
1254 expect(Ok, status);
1256 status = GdipDrawCurveI(graphics, pen, points, 3);
1257 expect(Ok, status);
1259 GdipDeletePen(pen);
1260 GdipDeleteGraphics(graphics);
1262 ReleaseDC(hwnd, hdc);
1265 static void test_GdipDrawLineI(void)
1267 GpStatus status;
1268 GpGraphics *graphics = NULL;
1269 GpPen *pen = NULL;
1270 HDC hdc = GetDC( hwnd );
1272 /* make a graphics object and pen object */
1273 ok(hdc != NULL, "Expected HDC to be initialized\n");
1275 status = GdipCreateFromHDC(hdc, &graphics);
1276 expect(Ok, status);
1277 ok(graphics != NULL, "Expected graphics to be initialized\n");
1279 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1280 expect(Ok, status);
1281 ok(pen != NULL, "Expected pen to be initialized\n");
1283 /* InvalidParameter cases: null graphics, null pen */
1284 status = GdipDrawLineI(NULL, NULL, 0, 0, 0, 0);
1285 expect(InvalidParameter, status);
1287 status = GdipDrawLineI(graphics, NULL, 0, 0, 0, 0);
1288 expect(InvalidParameter, status);
1290 status = GdipDrawLineI(NULL, pen, 0, 0, 0, 0);
1291 expect(InvalidParameter, status);
1293 /* successful case */
1294 status = GdipDrawLineI(graphics, pen, 0, 0, 0, 0);
1295 expect(Ok, status);
1297 GdipDeletePen(pen);
1298 GdipDeleteGraphics(graphics);
1300 ReleaseDC(hwnd, hdc);
1303 static void test_GdipDrawImagePointsRect(void)
1305 GpStatus status;
1306 GpGraphics *graphics = NULL;
1307 GpPointF ptf[4];
1308 GpBitmap *bm = NULL;
1309 BYTE rbmi[sizeof(BITMAPINFOHEADER)];
1310 BYTE buff[400];
1311 BITMAPINFO *bmi = (BITMAPINFO*)rbmi;
1312 HDC hdc = GetDC( hwnd );
1313 if (!hdc)
1314 return;
1316 memset(rbmi, 0, sizeof(rbmi));
1317 bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1318 bmi->bmiHeader.biWidth = 10;
1319 bmi->bmiHeader.biHeight = 10;
1320 bmi->bmiHeader.biPlanes = 1;
1321 bmi->bmiHeader.biBitCount = 32;
1322 bmi->bmiHeader.biCompression = BI_RGB;
1323 status = GdipCreateBitmapFromGdiDib(bmi, buff, &bm);
1324 expect(Ok, status);
1325 ok(NULL != bm, "Expected bitmap to be initialized\n");
1326 status = GdipCreateFromHDC(hdc, &graphics);
1327 expect(Ok, status);
1328 ptf[0].X = 0;
1329 ptf[0].Y = 0;
1330 ptf[1].X = 10;
1331 ptf[1].Y = 0;
1332 ptf[2].X = 0;
1333 ptf[2].Y = 10;
1334 ptf[3].X = 10;
1335 ptf[3].Y = 10;
1336 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 4, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1337 expect(NotImplemented, status);
1338 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 2, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1339 expect(InvalidParameter, status);
1340 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1341 expect(Ok, status);
1342 status = GdipDrawImagePointsRect(graphics, NULL, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1343 expect(InvalidParameter, status);
1344 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, NULL, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1345 expect(InvalidParameter, status);
1346 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 0, 0, UnitPixel, NULL, NULL, NULL);
1347 expect(Ok, status);
1348 memset(ptf, 0, sizeof(ptf));
1349 status = GdipDrawImagePointsRect(graphics, (GpImage*)bm, ptf, 3, 0, 0, 10, 10, UnitPixel, NULL, NULL, NULL);
1350 expect(Ok, status);
1352 GdipDisposeImage((GpImage*)bm);
1353 GdipDeleteGraphics(graphics);
1354 ReleaseDC(hwnd, hdc);
1357 static void test_GdipDrawLinesI(void)
1359 GpStatus status;
1360 GpGraphics *graphics = NULL;
1361 GpPen *pen = NULL;
1362 GpPoint *ptf = NULL;
1363 HDC hdc = GetDC( hwnd );
1365 /* make a graphics object and pen object */
1366 ok(hdc != NULL, "Expected HDC to be initialized\n");
1368 status = GdipCreateFromHDC(hdc, &graphics);
1369 expect(Ok, status);
1370 ok(graphics != NULL, "Expected graphics to be initialized\n");
1372 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1373 expect(Ok, status);
1374 ok(pen != NULL, "Expected pen to be initialized\n");
1376 /* make some arbitrary valid points*/
1377 ptf = GdipAlloc(2 * sizeof(GpPointF));
1379 ptf[0].X = 1;
1380 ptf[0].Y = 1;
1382 ptf[1].X = 2;
1383 ptf[1].Y = 2;
1385 /* InvalidParameter cases: null graphics, null pen, null points, count < 2*/
1386 status = GdipDrawLinesI(NULL, NULL, NULL, 0);
1387 expect(InvalidParameter, status);
1389 status = GdipDrawLinesI(graphics, pen, ptf, 0);
1390 expect(InvalidParameter, status);
1392 status = GdipDrawLinesI(graphics, NULL, ptf, 2);
1393 expect(InvalidParameter, status);
1395 status = GdipDrawLinesI(NULL, pen, ptf, 2);
1396 expect(InvalidParameter, status);
1398 /* successful case */
1399 status = GdipDrawLinesI(graphics, pen, ptf, 2);
1400 expect(Ok, status);
1402 GdipFree(ptf);
1403 GdipDeletePen(pen);
1404 GdipDeleteGraphics(graphics);
1406 ReleaseDC(hwnd, hdc);
1409 static void test_GdipFillClosedCurve(void)
1411 GpStatus status;
1412 GpGraphics *graphics = NULL;
1413 GpSolidFill *brush = NULL;
1414 HDC hdc = GetDC( hwnd );
1415 GpPointF points[3];
1417 points[0].X = 0;
1418 points[0].Y = 0;
1420 points[1].X = 40;
1421 points[1].Y = 20;
1423 points[2].X = 10;
1424 points[2].Y = 40;
1426 /* make a graphics object and brush object */
1427 ok(hdc != NULL, "Expected HDC to be initialized\n");
1429 status = GdipCreateFromHDC(hdc, &graphics);
1430 expect(Ok, status);
1431 ok(graphics != NULL, "Expected graphics to be initialized\n");
1433 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1435 /* InvalidParameter cases: null graphics, null brush, null points */
1436 status = GdipFillClosedCurve(NULL, NULL, NULL, 3);
1437 expect(InvalidParameter, status);
1439 status = GdipFillClosedCurve(graphics, NULL, NULL, 3);
1440 expect(InvalidParameter, status);
1442 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, NULL, 3);
1443 expect(InvalidParameter, status);
1445 status = GdipFillClosedCurve(NULL, NULL, points, 3);
1446 expect(InvalidParameter, status);
1448 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, NULL, 3);
1449 expect(InvalidParameter, status);
1451 status = GdipFillClosedCurve(graphics, NULL, points, 3);
1452 expect(InvalidParameter, status);
1454 status = GdipFillClosedCurve(NULL, (GpBrush*)brush, points, 3);
1455 expect(InvalidParameter, status);
1457 /* InvalidParameter cases: invalid count */
1458 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, -1);
1459 expect(InvalidParameter, status);
1461 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 0);
1462 expect(InvalidParameter, status);
1464 /* Valid test cases */
1465 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 1);
1466 expect(Ok, status);
1468 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 2);
1469 expect(Ok, status);
1471 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, points, 3);
1472 expect(Ok, status);
1474 GdipDeleteGraphics(graphics);
1475 GdipDeleteBrush((GpBrush*)brush);
1477 ReleaseDC(hwnd, hdc);
1480 static void test_GdipFillClosedCurveI(void)
1482 GpStatus status;
1483 GpGraphics *graphics = NULL;
1484 GpSolidFill *brush = NULL;
1485 HDC hdc = GetDC( hwnd );
1486 GpPoint points[3];
1488 points[0].X = 0;
1489 points[0].Y = 0;
1491 points[1].X = 40;
1492 points[1].Y = 20;
1494 points[2].X = 10;
1495 points[2].Y = 40;
1497 /* make a graphics object and brush object */
1498 ok(hdc != NULL, "Expected HDC to be initialized\n");
1500 status = GdipCreateFromHDC(hdc, &graphics);
1501 expect(Ok, status);
1502 ok(graphics != NULL, "Expected graphics to be initialized\n");
1504 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1506 /* InvalidParameter cases: null graphics, null brush */
1507 /* Note: GdipFillClosedCurveI and GdipFillClosedCurve2I hang in Windows
1508 when points == NULL, so don't test this condition */
1509 status = GdipFillClosedCurveI(NULL, NULL, points, 3);
1510 expect(InvalidParameter, status);
1512 status = GdipFillClosedCurveI(graphics, NULL, points, 3);
1513 expect(InvalidParameter, status);
1515 status = GdipFillClosedCurveI(NULL, (GpBrush*)brush, points, 3);
1516 expect(InvalidParameter, status);
1518 /* InvalidParameter cases: invalid count */
1519 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 0);
1520 expect(InvalidParameter, status);
1522 /* OutOfMemory cases: large (unsigned) int */
1523 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, -1);
1524 expect(OutOfMemory, status);
1526 /* Valid test cases */
1527 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 1);
1528 expect(Ok, status);
1530 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 2);
1531 expect(Ok, status);
1533 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, points, 3);
1534 expect(Ok, status);
1536 GdipDeleteGraphics(graphics);
1537 GdipDeleteBrush((GpBrush*)brush);
1539 ReleaseDC(hwnd, hdc);
1542 static void test_GdipFillPath(void)
1544 GpStatus status;
1545 GpGraphics *graphics;
1546 GpSolidFill *brush;
1547 GpPath *path;
1548 HDC hdc = GetDC(hwnd);
1550 ok(hdc != NULL, "Expected HDC to be initialized\n");
1551 status = GdipCreateFromHDC(hdc, &graphics);
1552 expect(Ok, status);
1553 ok(graphics != NULL, "Expected graphics to be initialized\n");
1554 status = GdipCreateSolidFill((ARGB)0xffffffff, &brush);
1555 expect(Ok, status);
1556 ok(brush != NULL, "Expected brush to be initialized\n");
1557 status = GdipCreatePath(FillModeAlternate, &path);
1558 expect(Ok, status);
1559 ok(path != NULL, "Expected path to be initialized\n");
1561 /* Empty path */
1562 GdipResetPath(path);
1563 status = GdipFillPath(graphics, (GpBrush *)brush, path);
1564 expect(Ok, status);
1566 /* Not closed path */
1567 GdipResetPath(path);
1568 status = GdipAddPathLineI(path, 0, 0, 2, 2);
1569 expect(Ok, status);
1570 status = GdipAddPathLineI(path, 2, 2, 4, 0);
1571 expect(Ok, status);
1572 status = GdipFillPath(graphics, (GpBrush *)brush, path);
1573 expect(Ok, status);
1575 /* Closed path */
1576 GdipResetPath(path);
1577 status = GdipAddPathRectangle(path, 0, 0, 4, 4);
1578 expect(Ok, status);
1579 status = GdipFillPath(graphics, (GpBrush *)brush, path);
1580 expect(Ok, status);
1582 GdipDeletePath(path);
1583 GdipDeleteBrush((GpBrush *)brush);
1584 GdipDeleteGraphics(graphics);
1585 ReleaseDC(hwnd, hdc);
1588 static void test_Get_Release_DC(void)
1590 GpStatus status;
1591 GpGraphics *graphics = NULL;
1592 GpPen *pen;
1593 GpSolidFill *brush;
1594 GpPath *path;
1595 HDC hdc = GetDC( hwnd );
1596 HDC retdc;
1597 REAL r;
1598 CompositingQuality quality;
1599 CompositingMode compmode;
1600 InterpolationMode intmode;
1601 GpMatrix *m;
1602 GpRegion *region;
1603 GpUnit unit;
1604 PixelOffsetMode offsetmode;
1605 SmoothingMode smoothmode;
1606 TextRenderingHint texthint;
1607 GpPointF ptf[5];
1608 GpPoint pt[5];
1609 GpRectF rectf[2];
1610 GpRect rect[2];
1611 GpRegion *clip;
1612 INT i;
1613 BOOL res;
1614 ARGB color = 0x00000000;
1615 HRGN hrgn = CreateRectRgn(0, 0, 10, 10);
1617 pt[0].X = 10;
1618 pt[0].Y = 10;
1619 pt[1].X = 20;
1620 pt[1].Y = 15;
1621 pt[2].X = 40;
1622 pt[2].Y = 80;
1623 pt[3].X = -20;
1624 pt[3].Y = 20;
1625 pt[4].X = 50;
1626 pt[4].Y = 110;
1628 for(i = 0; i < 5;i++){
1629 ptf[i].X = (REAL)pt[i].X;
1630 ptf[i].Y = (REAL)pt[i].Y;
1633 rect[0].X = 0;
1634 rect[0].Y = 0;
1635 rect[0].Width = 50;
1636 rect[0].Height = 70;
1637 rect[1].X = 0;
1638 rect[1].Y = 0;
1639 rect[1].Width = 10;
1640 rect[1].Height = 20;
1642 for(i = 0; i < 2;i++){
1643 rectf[i].X = (REAL)rect[i].X;
1644 rectf[i].Y = (REAL)rect[i].Y;
1645 rectf[i].Height = (REAL)rect[i].Height;
1646 rectf[i].Width = (REAL)rect[i].Width;
1649 status = GdipCreateMatrix(&m);
1650 expect(Ok, status);
1651 status = GdipCreateRegion(&region);
1652 expect(Ok, status);
1653 GdipCreateSolidFill((ARGB)0xdeadbeef, &brush);
1654 GdipCreatePath(FillModeAlternate, &path);
1655 status = GdipCreateRegion(&clip);
1656 expect(Ok, status);
1658 status = GdipCreateFromHDC(hdc, &graphics);
1659 expect(Ok, status);
1660 ok(graphics != NULL, "Expected graphics to be initialized\n");
1661 status = GdipCreatePen1((ARGB)0xffff00ff, 10.0f, UnitPixel, &pen);
1662 expect(Ok, status);
1664 /* NULL arguments */
1665 status = GdipGetDC(NULL, NULL);
1666 expect(InvalidParameter, status);
1667 status = GdipGetDC(graphics, NULL);
1668 expect(InvalidParameter, status);
1669 status = GdipGetDC(NULL, &retdc);
1670 expect(InvalidParameter, status);
1672 status = GdipReleaseDC(NULL, NULL);
1673 expect(InvalidParameter, status);
1674 status = GdipReleaseDC(graphics, NULL);
1675 expect(InvalidParameter, status);
1676 status = GdipReleaseDC(NULL, (HDC)0xdeadbeef);
1677 expect(InvalidParameter, status);
1679 /* Release without Get */
1680 status = GdipReleaseDC(graphics, hdc);
1681 expect(InvalidParameter, status);
1683 retdc = NULL;
1684 status = GdipGetDC(graphics, &retdc);
1685 expect(Ok, status);
1686 ok(retdc == hdc, "Invalid HDC returned\n");
1687 /* call it once more */
1688 status = GdipGetDC(graphics, &retdc);
1689 expect(ObjectBusy, status);
1691 /* try all Graphics calls here */
1692 status = GdipDrawArc(graphics, pen, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0);
1693 expect(ObjectBusy, status);
1694 status = GdipDrawArcI(graphics, pen, 0, 0, 1, 1, 0.0, 0.0);
1695 expect(ObjectBusy, status);
1696 status = GdipDrawBezier(graphics, pen, 0.0, 10.0, 20.0, 15.0, 35.0, -10.0, 10.0, 10.0);
1697 expect(ObjectBusy, status);
1698 status = GdipDrawBezierI(graphics, pen, 0, 0, 0, 0, 0, 0, 0, 0);
1699 expect(ObjectBusy, status);
1700 status = GdipDrawBeziers(graphics, pen, ptf, 5);
1701 expect(ObjectBusy, status);
1702 status = GdipDrawBeziersI(graphics, pen, pt, 5);
1703 expect(ObjectBusy, status);
1704 status = GdipDrawClosedCurve(graphics, pen, ptf, 5);
1705 expect(ObjectBusy, status);
1706 status = GdipDrawClosedCurveI(graphics, pen, pt, 5);
1707 expect(ObjectBusy, status);
1708 status = GdipDrawClosedCurve2(graphics, pen, ptf, 5, 1.0);
1709 expect(ObjectBusy, status);
1710 status = GdipDrawClosedCurve2I(graphics, pen, pt, 5, 1.0);
1711 expect(ObjectBusy, status);
1712 status = GdipDrawCurve(graphics, pen, ptf, 5);
1713 expect(ObjectBusy, status);
1714 status = GdipDrawCurveI(graphics, pen, pt, 5);
1715 expect(ObjectBusy, status);
1716 status = GdipDrawCurve2(graphics, pen, ptf, 5, 1.0);
1717 expect(ObjectBusy, status);
1718 status = GdipDrawCurve2I(graphics, pen, pt, 5, 1.0);
1719 expect(ObjectBusy, status);
1720 status = GdipDrawEllipse(graphics, pen, 0.0, 0.0, 100.0, 50.0);
1721 expect(ObjectBusy, status);
1722 status = GdipDrawEllipseI(graphics, pen, 0, 0, 100, 50);
1723 expect(ObjectBusy, status);
1724 /* GdipDrawImage/GdipDrawImageI */
1725 /* GdipDrawImagePointsRect/GdipDrawImagePointsRectI */
1726 /* GdipDrawImageRectRect/GdipDrawImageRectRectI */
1727 /* GdipDrawImageRect/GdipDrawImageRectI */
1728 status = GdipDrawLine(graphics, pen, 0.0, 0.0, 100.0, 200.0);
1729 expect(ObjectBusy, status);
1730 status = GdipDrawLineI(graphics, pen, 0, 0, 100, 200);
1731 expect(ObjectBusy, status);
1732 status = GdipDrawLines(graphics, pen, ptf, 5);
1733 expect(ObjectBusy, status);
1734 status = GdipDrawLinesI(graphics, pen, pt, 5);
1735 expect(ObjectBusy, status);
1736 status = GdipDrawPath(graphics, pen, path);
1737 expect(ObjectBusy, status);
1738 status = GdipDrawPie(graphics, pen, 0.0, 0.0, 100.0, 100.0, 0.0, 90.0);
1739 expect(ObjectBusy, status);
1740 status = GdipDrawPieI(graphics, pen, 0, 0, 100, 100, 0.0, 90.0);
1741 expect(ObjectBusy, status);
1742 status = GdipDrawRectangle(graphics, pen, 0.0, 0.0, 100.0, 300.0);
1743 expect(ObjectBusy, status);
1744 status = GdipDrawRectangleI(graphics, pen, 0, 0, 100, 300);
1745 expect(ObjectBusy, status);
1746 status = GdipDrawRectangles(graphics, pen, rectf, 2);
1747 expect(ObjectBusy, status);
1748 status = GdipDrawRectanglesI(graphics, pen, rect, 2);
1749 expect(ObjectBusy, status);
1750 /* GdipDrawString */
1751 status = GdipFillClosedCurve2(graphics, (GpBrush*)brush, ptf, 5, 1.0, FillModeAlternate);
1752 expect(ObjectBusy, status);
1753 status = GdipFillClosedCurve2I(graphics, (GpBrush*)brush, pt, 5, 1.0, FillModeAlternate);
1754 expect(ObjectBusy, status);
1755 status = GdipFillClosedCurve(graphics, (GpBrush*)brush, ptf, 5);
1756 expect(ObjectBusy, status);
1757 status = GdipFillClosedCurveI(graphics, (GpBrush*)brush, pt, 5);
1758 expect(ObjectBusy, status);
1759 status = GdipFillEllipse(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1760 expect(ObjectBusy, status);
1761 status = GdipFillEllipseI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1762 expect(ObjectBusy, status);
1763 status = GdipFillPath(graphics, (GpBrush*)brush, path);
1764 expect(ObjectBusy, status);
1765 status = GdipFillPie(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0, 0.0, 15.0);
1766 expect(ObjectBusy, status);
1767 status = GdipFillPieI(graphics, (GpBrush*)brush, 0, 0, 100, 100, 0.0, 15.0);
1768 expect(ObjectBusy, status);
1769 status = GdipFillPolygon(graphics, (GpBrush*)brush, ptf, 5, FillModeAlternate);
1770 expect(ObjectBusy, status);
1771 status = GdipFillPolygonI(graphics, (GpBrush*)brush, pt, 5, FillModeAlternate);
1772 expect(ObjectBusy, status);
1773 status = GdipFillPolygon2(graphics, (GpBrush*)brush, ptf, 5);
1774 expect(ObjectBusy, status);
1775 status = GdipFillPolygon2I(graphics, (GpBrush*)brush, pt, 5);
1776 expect(ObjectBusy, status);
1777 status = GdipFillRectangle(graphics, (GpBrush*)brush, 0.0, 0.0, 100.0, 100.0);
1778 expect(ObjectBusy, status);
1779 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, 100, 100);
1780 expect(ObjectBusy, status);
1781 status = GdipFillRectangles(graphics, (GpBrush*)brush, rectf, 2);
1782 expect(ObjectBusy, status);
1783 status = GdipFillRectanglesI(graphics, (GpBrush*)brush, rect, 2);
1784 expect(ObjectBusy, status);
1785 status = GdipFillRegion(graphics, (GpBrush*)brush, region);
1786 expect(ObjectBusy, status);
1787 status = GdipFlush(graphics, FlushIntentionFlush);
1788 expect(ObjectBusy, status);
1789 status = GdipGetClipBounds(graphics, rectf);
1790 expect(ObjectBusy, status);
1791 status = GdipGetClipBoundsI(graphics, rect);
1792 expect(ObjectBusy, status);
1793 status = GdipGetCompositingMode(graphics, &compmode);
1794 expect(ObjectBusy, status);
1795 status = GdipGetCompositingQuality(graphics, &quality);
1796 expect(ObjectBusy, status);
1797 status = GdipGetInterpolationMode(graphics, &intmode);
1798 expect(ObjectBusy, status);
1799 status = GdipGetNearestColor(graphics, &color);
1800 expect(ObjectBusy, status);
1801 status = GdipGetPageScale(graphics, &r);
1802 expect(ObjectBusy, status);
1803 status = GdipGetPageUnit(graphics, &unit);
1804 expect(ObjectBusy, status);
1805 status = GdipGetPixelOffsetMode(graphics, &offsetmode);
1806 expect(ObjectBusy, status);
1807 status = GdipGetSmoothingMode(graphics, &smoothmode);
1808 expect(ObjectBusy, status);
1809 status = GdipGetTextRenderingHint(graphics, &texthint);
1810 expect(ObjectBusy, status);
1811 status = GdipGetWorldTransform(graphics, m);
1812 expect(ObjectBusy, status);
1813 status = GdipGraphicsClear(graphics, 0xdeadbeef);
1814 expect(ObjectBusy, status);
1815 status = GdipIsVisiblePoint(graphics, 0.0, 0.0, &res);
1816 expect(ObjectBusy, status);
1817 status = GdipIsVisiblePointI(graphics, 0, 0, &res);
1818 expect(ObjectBusy, status);
1819 /* GdipMeasureCharacterRanges */
1820 /* GdipMeasureString */
1821 status = GdipResetClip(graphics);
1822 expect(ObjectBusy, status);
1823 status = GdipResetWorldTransform(graphics);
1824 expect(ObjectBusy, status);
1825 /* GdipRestoreGraphics */
1826 status = GdipRotateWorldTransform(graphics, 15.0, MatrixOrderPrepend);
1827 expect(ObjectBusy, status);
1828 /* GdipSaveGraphics */
1829 status = GdipScaleWorldTransform(graphics, 1.0, 1.0, MatrixOrderPrepend);
1830 expect(ObjectBusy, status);
1831 status = GdipSetCompositingMode(graphics, CompositingModeSourceOver);
1832 expect(ObjectBusy, status);
1833 status = GdipSetCompositingQuality(graphics, CompositingQualityDefault);
1834 expect(ObjectBusy, status);
1835 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
1836 expect(ObjectBusy, status);
1837 status = GdipSetPageScale(graphics, 1.0);
1838 expect(ObjectBusy, status);
1839 status = GdipSetPageUnit(graphics, UnitWorld);
1840 expect(ObjectBusy, status);
1841 status = GdipSetPixelOffsetMode(graphics, PixelOffsetModeDefault);
1842 expect(ObjectBusy, status);
1843 status = GdipSetSmoothingMode(graphics, SmoothingModeDefault);
1844 expect(ObjectBusy, status);
1845 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
1846 expect(ObjectBusy, status);
1847 status = GdipSetWorldTransform(graphics, m);
1848 expect(ObjectBusy, status);
1849 status = GdipTranslateWorldTransform(graphics, 0.0, 0.0, MatrixOrderPrepend);
1850 expect(ObjectBusy, status);
1851 status = GdipSetClipHrgn(graphics, hrgn, CombineModeReplace);
1852 expect(ObjectBusy, status);
1853 status = GdipSetClipPath(graphics, path, CombineModeReplace);
1854 expect(ObjectBusy, status);
1855 status = GdipSetClipRect(graphics, 0.0, 0.0, 10.0, 10.0, CombineModeReplace);
1856 expect(ObjectBusy, status);
1857 status = GdipSetClipRectI(graphics, 0, 0, 10, 10, CombineModeReplace);
1858 expect(ObjectBusy, status);
1859 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
1860 expect(ObjectBusy, status);
1861 status = GdipTranslateClip(graphics, 0.0, 0.0);
1862 expect(ObjectBusy, status);
1863 status = GdipTranslateClipI(graphics, 0, 0);
1864 expect(ObjectBusy, status);
1865 status = GdipDrawPolygon(graphics, pen, ptf, 5);
1866 expect(ObjectBusy, status);
1867 status = GdipDrawPolygonI(graphics, pen, pt, 5);
1868 expect(ObjectBusy, status);
1869 status = GdipGetDpiX(graphics, &r);
1870 expect(ObjectBusy, status);
1871 status = GdipGetDpiY(graphics, &r);
1872 expect(ObjectBusy, status);
1873 status = GdipMultiplyWorldTransform(graphics, m, MatrixOrderPrepend);
1874 expect(ObjectBusy, status);
1875 status = GdipGetClip(graphics, region);
1876 expect(ObjectBusy, status);
1877 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 5);
1878 expect(ObjectBusy, status);
1880 /* try to delete before release */
1881 status = GdipDeleteGraphics(graphics);
1882 expect(ObjectBusy, status);
1884 status = GdipReleaseDC(graphics, retdc);
1885 expect(Ok, status);
1887 GdipDeletePen(pen);
1888 GdipDeleteGraphics(graphics);
1890 GdipDeleteRegion(clip);
1891 GdipDeletePath(path);
1892 GdipDeleteBrush((GpBrush*)brush);
1893 GdipDeleteRegion(region);
1894 GdipDeleteMatrix(m);
1895 DeleteObject(hrgn);
1897 ReleaseDC(hwnd, hdc);
1900 static void test_transformpoints(void)
1902 GpStatus status;
1903 GpGraphics *graphics = NULL;
1904 HDC hdc = GetDC( hwnd );
1905 GpPointF ptf[2];
1906 GpPoint pt[2];
1908 status = GdipCreateFromHDC(hdc, &graphics);
1909 expect(Ok, status);
1911 /* NULL arguments */
1912 status = GdipTransformPoints(NULL, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1913 expect(InvalidParameter, status);
1914 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, NULL, 0);
1915 expect(InvalidParameter, status);
1916 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 0);
1917 expect(InvalidParameter, status);
1918 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, -1);
1919 expect(InvalidParameter, status);
1921 status = GdipTransformPoints(graphics, CoordinateSpaceDevice+1, CoordinateSpaceWorld, ptf, 2);
1922 expect(InvalidParameter, status);
1923 status = GdipTransformPoints(graphics, -1, CoordinateSpaceWorld, ptf, 2);
1924 expect(InvalidParameter, status);
1925 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceDevice+1, ptf, 2);
1926 expect(InvalidParameter, status);
1927 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, -1, ptf, 2);
1928 expect(InvalidParameter, status);
1930 ptf[0].X = 1.0;
1931 ptf[0].Y = 0.0;
1932 ptf[1].X = 0.0;
1933 ptf[1].Y = 1.0;
1934 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1935 expect(Ok, status);
1936 expectf(1.0, ptf[0].X);
1937 expectf(0.0, ptf[0].Y);
1938 expectf(0.0, ptf[1].X);
1939 expectf(1.0, ptf[1].Y);
1941 status = GdipTranslateWorldTransform(graphics, 5.0, 5.0, MatrixOrderAppend);
1942 expect(Ok, status);
1943 status = GdipSetPageUnit(graphics, UnitPixel);
1944 expect(Ok, status);
1945 status = GdipSetPageScale(graphics, 3.0);
1946 expect(Ok, status);
1948 ptf[0].X = 1.0;
1949 ptf[0].Y = 0.0;
1950 ptf[1].X = 0.0;
1951 ptf[1].Y = 1.0;
1952 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
1953 expect(Ok, status);
1954 expectf(18.0, ptf[0].X);
1955 expectf(15.0, ptf[0].Y);
1956 expectf(15.0, ptf[1].X);
1957 expectf(18.0, ptf[1].Y);
1959 ptf[0].X = 1.0;
1960 ptf[0].Y = 0.0;
1961 ptf[1].X = 0.0;
1962 ptf[1].Y = 1.0;
1963 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceWorld, ptf, 2);
1964 expect(Ok, status);
1965 expectf(6.0, ptf[0].X);
1966 expectf(5.0, ptf[0].Y);
1967 expectf(5.0, ptf[1].X);
1968 expectf(6.0, ptf[1].Y);
1970 ptf[0].X = 1.0;
1971 ptf[0].Y = 0.0;
1972 ptf[1].X = 0.0;
1973 ptf[1].Y = 1.0;
1974 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpacePage, ptf, 2);
1975 expect(Ok, status);
1976 expectf(3.0, ptf[0].X);
1977 expectf(0.0, ptf[0].Y);
1978 expectf(0.0, ptf[1].X);
1979 expectf(3.0, ptf[1].Y);
1981 ptf[0].X = 18.0;
1982 ptf[0].Y = 15.0;
1983 ptf[1].X = 15.0;
1984 ptf[1].Y = 18.0;
1985 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
1986 expect(Ok, status);
1987 expectf(1.0, ptf[0].X);
1988 expectf(0.0, ptf[0].Y);
1989 expectf(0.0, ptf[1].X);
1990 expectf(1.0, ptf[1].Y);
1992 ptf[0].X = 6.0;
1993 ptf[0].Y = 5.0;
1994 ptf[1].X = 5.0;
1995 ptf[1].Y = 6.0;
1996 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpacePage, ptf, 2);
1997 expect(Ok, status);
1998 expectf(1.0, ptf[0].X);
1999 expectf(0.0, ptf[0].Y);
2000 expectf(0.0, ptf[1].X);
2001 expectf(1.0, ptf[1].Y);
2003 ptf[0].X = 3.0;
2004 ptf[0].Y = 0.0;
2005 ptf[1].X = 0.0;
2006 ptf[1].Y = 3.0;
2007 status = GdipTransformPoints(graphics, CoordinateSpacePage, CoordinateSpaceDevice, ptf, 2);
2008 expect(Ok, status);
2009 expectf(1.0, ptf[0].X);
2010 expectf(0.0, ptf[0].Y);
2011 expectf(0.0, ptf[1].X);
2012 expectf(1.0, ptf[1].Y);
2014 pt[0].X = 1;
2015 pt[0].Y = 0;
2016 pt[1].X = 0;
2017 pt[1].Y = 1;
2018 status = GdipTransformPointsI(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, pt, 2);
2019 expect(Ok, status);
2020 expect(18, pt[0].X);
2021 expect(15, pt[0].Y);
2022 expect(15, pt[1].X);
2023 expect(18, pt[1].Y);
2025 GdipDeleteGraphics(graphics);
2026 ReleaseDC(hwnd, hdc);
2029 static void test_get_set_clip(void)
2031 GpStatus status;
2032 GpGraphics *graphics = NULL;
2033 HDC hdc = GetDC( hwnd );
2034 GpRegion *clip;
2035 GpRectF rect;
2036 BOOL res;
2038 status = GdipCreateFromHDC(hdc, &graphics);
2039 expect(Ok, status);
2041 rect.X = rect.Y = 0.0;
2042 rect.Height = rect.Width = 100.0;
2044 status = GdipCreateRegionRect(&rect, &clip);
2045 expect(Ok, status);
2047 /* NULL arguments */
2048 status = GdipGetClip(NULL, NULL);
2049 expect(InvalidParameter, status);
2050 status = GdipGetClip(graphics, NULL);
2051 expect(InvalidParameter, status);
2052 status = GdipGetClip(NULL, clip);
2053 expect(InvalidParameter, status);
2055 status = GdipSetClipRegion(NULL, NULL, CombineModeReplace);
2056 expect(InvalidParameter, status);
2057 status = GdipSetClipRegion(graphics, NULL, CombineModeReplace);
2058 expect(InvalidParameter, status);
2060 status = GdipSetClipPath(NULL, NULL, CombineModeReplace);
2061 expect(InvalidParameter, status);
2062 status = GdipSetClipPath(graphics, NULL, CombineModeReplace);
2063 expect(InvalidParameter, status);
2065 res = FALSE;
2066 status = GdipGetClip(graphics, clip);
2067 expect(Ok, status);
2068 status = GdipIsInfiniteRegion(clip, graphics, &res);
2069 expect(Ok, status);
2070 expect(TRUE, res);
2072 /* remains infinite after reset */
2073 res = FALSE;
2074 status = GdipResetClip(graphics);
2075 expect(Ok, status);
2076 status = GdipGetClip(graphics, clip);
2077 expect(Ok, status);
2078 status = GdipIsInfiniteRegion(clip, graphics, &res);
2079 expect(Ok, status);
2080 expect(TRUE, res);
2082 /* set to empty and then reset to infinite */
2083 status = GdipSetEmpty(clip);
2084 expect(Ok, status);
2085 status = GdipSetClipRegion(graphics, clip, CombineModeReplace);
2086 expect(Ok, status);
2088 status = GdipGetClip(graphics, clip);
2089 expect(Ok, status);
2090 res = FALSE;
2091 status = GdipIsEmptyRegion(clip, graphics, &res);
2092 expect(Ok, status);
2093 expect(TRUE, res);
2094 status = GdipResetClip(graphics);
2095 expect(Ok, status);
2096 status = GdipGetClip(graphics, clip);
2097 expect(Ok, status);
2098 res = FALSE;
2099 status = GdipIsInfiniteRegion(clip, graphics, &res);
2100 expect(Ok, status);
2101 expect(TRUE, res);
2103 GdipDeleteRegion(clip);
2105 GdipDeleteGraphics(graphics);
2106 ReleaseDC(hwnd, hdc);
2109 static void test_clip_xform(void)
2111 GpStatus status;
2112 GpGraphics *graphics = NULL;
2113 HDC hdc = GetDC( hwnd );
2114 GpRegion *clip;
2115 COLORREF color;
2116 UINT region_data_size;
2117 struct {
2118 DWORD size;
2119 DWORD checksum;
2120 DWORD magic;
2121 DWORD num_children;
2122 DWORD element_type;
2123 REAL x;
2124 REAL y;
2125 REAL width;
2126 REAL height;
2127 } region_data;
2129 status = GdipCreateFromHDC(hdc, &graphics);
2130 expect(Ok, status);
2131 status = GdipCreateRegion(&clip);
2132 expect(Ok, status);
2134 status = GdipGraphicsClear(graphics, 0xff000000);
2135 expect(Ok, status);
2137 status = GdipSetClipRect(graphics, 10, 10, -10, -10, CombineModeReplace);
2138 expect(Ok, status);
2139 status = GdipGetClip(graphics, clip);
2140 expect(Ok, status);
2141 status = GdipGetRegionData(clip, (BYTE*)&region_data, sizeof(region_data), &region_data_size);
2142 expect(Ok, status);
2143 expect(36, region_data_size);
2144 expect(28, region_data.size);
2145 expect(0, region_data.num_children);
2146 expect(0x10000000 /* RegionDataRect */, region_data.element_type);
2147 expectf(0.0, region_data.x);
2148 expectf(0.0, region_data.y);
2149 expectf(10.0, region_data.width);
2150 expectf(10.0, region_data.height);
2152 /* No effect with negative width/height */
2153 status = GdipGraphicsClear(graphics, 0xffff0000);
2154 expect(Ok, status);
2155 color = GetPixel(hdc, 5, 5);
2156 expect(0, color);
2158 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderAppend);
2159 expect(Ok, status);
2161 status = GdipGraphicsClear(graphics, 0xffff0000);
2162 expect(Ok, status);
2163 color = GetPixel(hdc, 5, 5);
2164 expect(0, color);
2166 status = GdipResetClip(graphics);
2167 expect(Ok, status);
2168 status = GdipResetWorldTransform(graphics);
2169 expect(Ok, status);
2170 status = GdipGraphicsClear(graphics, 0xff000000);
2171 expect(Ok, status);
2173 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderAppend);
2174 expect(Ok, status);
2176 status = GdipSetClipRect(graphics, 5, 5, -5, -5, CombineModeReplace);
2177 expect(Ok, status);
2178 status = GdipGetClip(graphics, clip);
2179 expect(Ok, status);
2180 status = GdipGetRegionData(clip, (BYTE*)&region_data, sizeof(region_data), &region_data_size);
2181 expect(Ok, status);
2182 expect(36, region_data_size);
2183 expect(28, region_data.size);
2184 expect(0, region_data.num_children);
2185 expect(0x10000000 /* RegionDataRect */, region_data.element_type);
2186 expectf(0.0, region_data.x);
2187 expectf(0.0, region_data.y);
2188 expectf(5.0, region_data.width);
2189 expectf(5.0, region_data.height);
2191 status = GdipGraphicsClear(graphics, 0xffff0000);
2192 expect(Ok, status);
2193 color = GetPixel(hdc, 5, 5);
2194 expect(0xff, color);
2196 GdipDeleteGraphics(graphics);
2197 ReleaseDC(hwnd, hdc);
2200 static void test_isempty(void)
2202 GpStatus status;
2203 GpGraphics *graphics = NULL;
2204 HDC hdc = GetDC( hwnd );
2205 GpRegion *clip;
2206 BOOL res;
2208 status = GdipCreateFromHDC(hdc, &graphics);
2209 expect(Ok, status);
2211 status = GdipCreateRegion(&clip);
2212 expect(Ok, status);
2214 /* NULL */
2215 status = GdipIsClipEmpty(NULL, NULL);
2216 expect(InvalidParameter, status);
2217 status = GdipIsClipEmpty(graphics, NULL);
2218 expect(InvalidParameter, status);
2219 status = GdipIsClipEmpty(NULL, &res);
2220 expect(InvalidParameter, status);
2222 /* default is infinite */
2223 res = TRUE;
2224 status = GdipIsClipEmpty(graphics, &res);
2225 expect(Ok, status);
2226 expect(FALSE, res);
2228 GdipDeleteRegion(clip);
2230 GdipDeleteGraphics(graphics);
2231 ReleaseDC(hwnd, hdc);
2234 static void test_clear(void)
2236 GpStatus status;
2238 status = GdipGraphicsClear(NULL, 0xdeadbeef);
2239 expect(InvalidParameter, status);
2242 static void test_textcontrast(void)
2244 GpStatus status;
2245 HDC hdc = GetDC( hwnd );
2246 GpGraphics *graphics;
2247 UINT contrast;
2249 status = GdipGetTextContrast(NULL, NULL);
2250 expect(InvalidParameter, status);
2252 status = GdipCreateFromHDC(hdc, &graphics);
2253 expect(Ok, status);
2255 status = GdipGetTextContrast(graphics, NULL);
2256 expect(InvalidParameter, status);
2257 status = GdipGetTextContrast(graphics, &contrast);
2258 expect(Ok, status);
2259 expect(4, contrast);
2261 GdipDeleteGraphics(graphics);
2262 ReleaseDC(hwnd, hdc);
2265 static void test_GdipDrawString(void)
2267 GpStatus status;
2268 GpGraphics *graphics = NULL;
2269 GpFont *fnt = NULL;
2270 RectF rect;
2271 GpStringFormat *format;
2272 GpBrush *brush;
2273 LOGFONTA logfont;
2274 HDC hdc = GetDC( hwnd );
2275 static const WCHAR string[] = {'T','e','s','t',0};
2276 static const PointF positions[4] = {{0,0}, {1,1}, {2,2}, {3,3}};
2277 GpMatrix *matrix;
2279 memset(&logfont,0,sizeof(logfont));
2280 strcpy(logfont.lfFaceName,"Arial");
2281 logfont.lfHeight = 12;
2282 logfont.lfCharSet = DEFAULT_CHARSET;
2284 status = GdipCreateFromHDC(hdc, &graphics);
2285 expect(Ok, status);
2287 status = GdipCreateFontFromLogfontA(hdc, &logfont, &fnt);
2288 if (status == NotTrueTypeFont || status == FileNotFound)
2290 skip("Arial not installed.\n");
2291 return;
2293 expect(Ok, status);
2295 status = GdipCreateSolidFill((ARGB)0xdeadbeef, (GpSolidFill**)&brush);
2296 expect(Ok, status);
2298 status = GdipCreateStringFormat(0,0,&format);
2299 expect(Ok, status);
2301 rect.X = 0;
2302 rect.Y = 0;
2303 rect.Width = 0;
2304 rect.Height = 12;
2306 status = GdipDrawString(graphics, string, 4, fnt, &rect, format, brush);
2307 expect(Ok, status);
2309 status = GdipCreateMatrix(&matrix);
2310 expect(Ok, status);
2312 status = GdipDrawDriverString(NULL, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2313 expect(InvalidParameter, status);
2315 status = GdipDrawDriverString(graphics, NULL, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2316 expect(InvalidParameter, status);
2318 status = GdipDrawDriverString(graphics, string, 4, NULL, brush, positions, DriverStringOptionsCmapLookup, matrix);
2319 expect(InvalidParameter, status);
2321 status = GdipDrawDriverString(graphics, string, 4, fnt, NULL, positions, DriverStringOptionsCmapLookup, matrix);
2322 expect(InvalidParameter, status);
2324 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, NULL, DriverStringOptionsCmapLookup, matrix);
2325 expect(InvalidParameter, status);
2327 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup|0x10, matrix);
2328 expect(Ok, status);
2330 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, NULL);
2331 expect(Ok, status);
2333 status = GdipDrawDriverString(graphics, string, 4, fnt, brush, positions, DriverStringOptionsCmapLookup, matrix);
2334 expect(Ok, status);
2336 GdipDeleteMatrix(matrix);
2337 GdipDeleteGraphics(graphics);
2338 GdipDeleteBrush(brush);
2339 GdipDeleteFont(fnt);
2340 GdipDeleteStringFormat(format);
2342 ReleaseDC(hwnd, hdc);
2345 static void test_GdipGetVisibleClipBounds_screen(void)
2347 GpStatus status;
2348 GpGraphics *graphics = NULL;
2349 HDC hdc = GetDC(0);
2350 GpRectF rectf, exp, clipr;
2351 GpRect recti;
2353 ok(hdc != NULL, "Expected HDC to be initialized\n");
2355 status = GdipCreateFromHDC(hdc, &graphics);
2356 expect(Ok, status);
2357 ok(graphics != NULL, "Expected graphics to be initialized\n");
2359 /* no clipping rect */
2360 exp.X = 0;
2361 exp.Y = 0;
2362 exp.Width = GetDeviceCaps(hdc, HORZRES);
2363 exp.Height = GetDeviceCaps(hdc, VERTRES);
2365 status = GdipGetVisibleClipBounds(graphics, &rectf);
2366 expect(Ok, status);
2367 ok(rectf.X == exp.X &&
2368 rectf.Y == exp.Y &&
2369 rectf.Width == exp.Width &&
2370 rectf.Height == exp.Height,
2371 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2372 "the screen (%0.f, %0.f, %0.f, %0.f)\n",
2373 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2374 exp.X, exp.Y, exp.Width, exp.Height);
2376 /* clipping rect entirely within window */
2377 exp.X = clipr.X = 10;
2378 exp.Y = clipr.Y = 12;
2379 exp.Width = clipr.Width = 14;
2380 exp.Height = clipr.Height = 16;
2382 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2383 expect(Ok, status);
2385 status = GdipGetVisibleClipBounds(graphics, &rectf);
2386 expect(Ok, status);
2387 ok(rectf.X == exp.X &&
2388 rectf.Y == exp.Y &&
2389 rectf.Width == exp.Width &&
2390 rectf.Height == exp.Height,
2391 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2392 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2393 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2394 exp.X, exp.Y, exp.Width, exp.Height);
2396 /* clipping rect partially outside of screen */
2397 clipr.X = -10;
2398 clipr.Y = -12;
2399 clipr.Width = 20;
2400 clipr.Height = 24;
2402 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2403 expect(Ok, status);
2405 exp.X = 0;
2406 exp.Y = 0;
2407 exp.Width = 10;
2408 exp.Height = 12;
2410 status = GdipGetVisibleClipBounds(graphics, &rectf);
2411 expect(Ok, status);
2412 ok(rectf.X == exp.X &&
2413 rectf.Y == exp.Y &&
2414 rectf.Width == exp.Width &&
2415 rectf.Height == exp.Height,
2416 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2417 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2418 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2419 exp.X, exp.Y, exp.Width, exp.Height);
2421 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2422 expect(Ok, status);
2423 ok(recti.X == exp.X &&
2424 recti.Y == exp.Y &&
2425 recti.Width == exp.Width &&
2426 recti.Height == exp.Height,
2427 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2428 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2429 recti.X, recti.Y, recti.Width, recti.Height,
2430 exp.X, exp.Y, exp.Width, exp.Height);
2432 GdipDeleteGraphics(graphics);
2433 ReleaseDC(0, hdc);
2436 static void test_GdipGetVisibleClipBounds_window(void)
2438 GpStatus status;
2439 GpGraphics *graphics = NULL;
2440 GpRectF rectf, window, exp, clipr;
2441 GpRect recti;
2442 HDC hdc;
2443 PAINTSTRUCT ps;
2444 RECT wnd_rect;
2446 /* get client area size */
2447 ok(GetClientRect(hwnd, &wnd_rect), "GetClientRect should have succeeded\n");
2448 window.X = wnd_rect.left;
2449 window.Y = wnd_rect.top;
2450 window.Width = wnd_rect.right - wnd_rect.left;
2451 window.Height = wnd_rect.bottom - wnd_rect.top;
2453 hdc = BeginPaint(hwnd, &ps);
2455 status = GdipCreateFromHDC(hdc, &graphics);
2456 expect(Ok, status);
2457 ok(graphics != NULL, "Expected graphics to be initialized\n");
2459 status = GdipGetVisibleClipBounds(graphics, &rectf);
2460 expect(Ok, status);
2461 ok(rectf.X == window.X &&
2462 rectf.Y == window.Y &&
2463 rectf.Width == window.Width &&
2464 rectf.Height == window.Height,
2465 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2466 "the window (%0.f, %0.f, %0.f, %0.f)\n",
2467 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2468 window.X, window.Y, window.Width, window.Height);
2470 /* clipping rect entirely within window */
2471 exp.X = clipr.X = 20;
2472 exp.Y = clipr.Y = 8;
2473 exp.Width = clipr.Width = 30;
2474 exp.Height = clipr.Height = 20;
2476 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2477 expect(Ok, status);
2479 status = GdipGetVisibleClipBounds(graphics, &rectf);
2480 expect(Ok, status);
2481 ok(rectf.X == exp.X &&
2482 rectf.Y == exp.Y &&
2483 rectf.Width == exp.Width &&
2484 rectf.Height == exp.Height,
2485 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2486 "the clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2487 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2488 exp.X, exp.Y, exp.Width, exp.Height);
2490 /* clipping rect partially outside of window */
2491 clipr.X = window.Width - 10;
2492 clipr.Y = window.Height - 15;
2493 clipr.Width = 20;
2494 clipr.Height = 30;
2496 status = GdipSetClipRect(graphics, clipr.X, clipr.Y, clipr.Width, clipr.Height, CombineModeReplace);
2497 expect(Ok, status);
2499 exp.X = window.Width - 10;
2500 exp.Y = window.Height - 15;
2501 exp.Width = 10;
2502 exp.Height = 15;
2504 status = GdipGetVisibleClipBounds(graphics, &rectf);
2505 expect(Ok, status);
2506 ok(rectf.X == exp.X &&
2507 rectf.Y == exp.Y &&
2508 rectf.Width == exp.Width &&
2509 rectf.Height == exp.Height,
2510 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be the size of "
2511 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2512 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2513 exp.X, exp.Y, exp.Width, exp.Height);
2515 status = GdipGetVisibleClipBoundsI(graphics, &recti);
2516 expect(Ok, status);
2517 ok(recti.X == exp.X &&
2518 recti.Y == exp.Y &&
2519 recti.Width == exp.Width &&
2520 recti.Height == exp.Height,
2521 "Expected clip bounds (%d, %d, %d, %d) to be the size of "
2522 "the visible clipping rect (%0.f, %0.f, %0.f, %0.f)\n",
2523 recti.X, recti.Y, recti.Width, recti.Height,
2524 exp.X, exp.Y, exp.Width, exp.Height);
2526 /* window bounds with transform applied */
2527 status = GdipResetClip(graphics);
2528 expect(Ok, status);
2530 status = GdipScaleWorldTransform(graphics, 0.5, 0.5, MatrixOrderPrepend);
2531 expect(Ok, status);
2533 exp.X = window.X * 2.0;
2534 exp.Y = window.Y * 2.0;
2535 exp.Width = window.Width * 2.0;
2536 exp.Height = window.Height * 2.0;
2538 status = GdipGetVisibleClipBounds(graphics, &rectf);
2539 expect(Ok, status);
2540 ok(rectf.X == exp.X &&
2541 rectf.Y == exp.Y &&
2542 rectf.Width == exp.Width &&
2543 rectf.Height == exp.Height,
2544 "Expected clip bounds (%0.f, %0.f, %0.f, %0.f) to be "
2545 "twice the window size (%0.f, %0.f, %0.f, %0.f)\n",
2546 rectf.X, rectf.Y, rectf.Width, rectf.Height,
2547 exp.X, exp.Y, exp.Width, exp.Height);
2549 GdipDeleteGraphics(graphics);
2550 EndPaint(hwnd, &ps);
2553 static void test_GdipGetVisibleClipBounds(void)
2555 GpGraphics* graphics = NULL;
2556 GpRectF rectf;
2557 GpRect rect;
2558 HDC hdc = GetDC( hwnd );
2559 GpStatus status;
2561 status = GdipCreateFromHDC(hdc, &graphics);
2562 expect(Ok, status);
2563 ok(graphics != NULL, "Expected graphics to be initialized\n");
2565 /* test null parameters */
2566 status = GdipGetVisibleClipBounds(graphics, NULL);
2567 expect(InvalidParameter, status);
2569 status = GdipGetVisibleClipBounds(NULL, &rectf);
2570 expect(InvalidParameter, status);
2572 status = GdipGetVisibleClipBoundsI(graphics, NULL);
2573 expect(InvalidParameter, status);
2575 status = GdipGetVisibleClipBoundsI(NULL, &rect);
2576 expect(InvalidParameter, status);
2578 GdipDeleteGraphics(graphics);
2579 ReleaseDC(hwnd, hdc);
2581 test_GdipGetVisibleClipBounds_screen();
2582 test_GdipGetVisibleClipBounds_window();
2585 static void test_fromMemoryBitmap(void)
2587 GpStatus status;
2588 GpGraphics *graphics = NULL;
2589 GpBitmap *bitmap = NULL;
2590 BYTE bits[48] = {0};
2591 HDC hdc=NULL;
2592 COLORREF color;
2594 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, bits, &bitmap);
2595 expect(Ok, status);
2597 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2598 expect(Ok, status);
2600 status = GdipGraphicsClear(graphics, 0xff686868);
2601 expect(Ok, status);
2603 GdipDeleteGraphics(graphics);
2605 /* drawing writes to the memory provided */
2606 expect(0x68, bits[10]);
2608 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2609 expect(Ok, status);
2611 status = GdipGetDC(graphics, &hdc);
2612 expect(Ok, status);
2613 ok(hdc != NULL, "got NULL hdc\n");
2615 color = GetPixel(hdc, 0, 0);
2616 /* The HDC is write-only, and native fills with a solid color to figure out
2617 * which pixels have changed. */
2618 todo_wine expect(0x0c0b0d, color);
2620 SetPixel(hdc, 0, 0, 0x797979);
2621 SetPixel(hdc, 1, 0, 0x0c0b0d);
2623 status = GdipReleaseDC(graphics, hdc);
2624 expect(Ok, status);
2626 GdipDeleteGraphics(graphics);
2628 expect(0x79, bits[0]);
2629 todo_wine expect(0x68, bits[3]);
2631 GdipDisposeImage((GpImage*)bitmap);
2633 /* We get the same kind of write-only HDC for a "normal" bitmap */
2634 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, NULL, &bitmap);
2635 expect(Ok, status);
2637 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2638 expect(Ok, status);
2640 status = GdipGetDC(graphics, &hdc);
2641 expect(Ok, status);
2642 ok(hdc != NULL, "got NULL hdc\n");
2644 color = GetPixel(hdc, 0, 0);
2645 todo_wine expect(0x0c0b0d, color);
2647 status = GdipReleaseDC(graphics, hdc);
2648 expect(Ok, status);
2650 GdipDeleteGraphics(graphics);
2652 GdipDisposeImage((GpImage*)bitmap);
2654 /* If we don't draw to the HDC, the bits are never accessed */
2655 status = GdipCreateBitmapFromScan0(4, 4, 12, PixelFormat24bppRGB, (BYTE*)1, &bitmap);
2656 expect(Ok, status);
2658 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
2659 expect(Ok, status);
2661 status = GdipGetDC(graphics, &hdc);
2662 expect(Ok, status);
2663 ok(hdc != NULL, "got NULL hdc\n");
2665 color = GetPixel(hdc, 0, 0);
2666 todo_wine expect(0x0c0b0d, color);
2668 status = GdipReleaseDC(graphics, hdc);
2669 expect(Ok, status);
2671 GdipDeleteGraphics(graphics);
2673 GdipDisposeImage((GpImage*)bitmap);
2676 static void test_GdipIsVisiblePoint(void)
2678 GpStatus status;
2679 GpGraphics *graphics = NULL;
2680 HDC hdc = GetDC( hwnd );
2681 REAL x, y;
2682 BOOL val;
2684 ok(hdc != NULL, "Expected HDC to be initialized\n");
2686 status = GdipCreateFromHDC(hdc, &graphics);
2687 expect(Ok, status);
2688 ok(graphics != NULL, "Expected graphics to be initialized\n");
2690 /* null parameters */
2691 status = GdipIsVisiblePoint(NULL, 0, 0, &val);
2692 expect(InvalidParameter, status);
2694 status = GdipIsVisiblePoint(graphics, 0, 0, NULL);
2695 expect(InvalidParameter, status);
2697 status = GdipIsVisiblePointI(NULL, 0, 0, &val);
2698 expect(InvalidParameter, status);
2700 status = GdipIsVisiblePointI(graphics, 0, 0, NULL);
2701 expect(InvalidParameter, status);
2703 x = 0;
2704 y = 0;
2705 status = GdipIsVisiblePoint(graphics, x, y, &val);
2706 expect(Ok, status);
2707 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2709 x = -10;
2710 y = 0;
2711 status = GdipIsVisiblePoint(graphics, x, y, &val);
2712 expect(Ok, status);
2713 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2715 x = 0;
2716 y = -5;
2717 status = GdipIsVisiblePoint(graphics, x, y, &val);
2718 expect(Ok, status);
2719 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2721 x = 1;
2722 y = 1;
2723 status = GdipIsVisiblePoint(graphics, x, y, &val);
2724 expect(Ok, status);
2725 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2727 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2728 expect(Ok, status);
2730 x = 1;
2731 y = 1;
2732 status = GdipIsVisiblePoint(graphics, x, y, &val);
2733 expect(Ok, status);
2734 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2736 x = 15.5;
2737 y = 40.5;
2738 status = GdipIsVisiblePoint(graphics, x, y, &val);
2739 expect(Ok, status);
2740 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2742 /* translate into the center of the rect */
2743 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2745 x = 0;
2746 y = 0;
2747 status = GdipIsVisiblePoint(graphics, x, y, &val);
2748 expect(Ok, status);
2749 ok(val == TRUE, "Expected (%.2f, %.2f) to be visible\n", x, y);
2751 x = 25;
2752 y = 40;
2753 status = GdipIsVisiblePoint(graphics, x, y, &val);
2754 expect(Ok, status);
2755 ok(val == FALSE, "Expected (%.2f, %.2f) not to be visible\n", x, y);
2757 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2759 /* corner cases */
2760 x = 9;
2761 y = 19;
2762 status = GdipIsVisiblePoint(graphics, x, y, &val);
2763 expect(Ok, status);
2764 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2766 x = 9.25;
2767 y = 19.25;
2768 status = GdipIsVisiblePoint(graphics, x, y, &val);
2769 expect(Ok, status);
2770 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2772 x = 9.5;
2773 y = 19.5;
2774 status = GdipIsVisiblePoint(graphics, x, y, &val);
2775 expect(Ok, status);
2776 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2778 x = 9.75;
2779 y = 19.75;
2780 status = GdipIsVisiblePoint(graphics, x, y, &val);
2781 expect(Ok, status);
2782 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2784 x = 10;
2785 y = 20;
2786 status = GdipIsVisiblePoint(graphics, x, y, &val);
2787 expect(Ok, status);
2788 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2790 x = 40;
2791 y = 20;
2792 status = GdipIsVisiblePoint(graphics, x, y, &val);
2793 expect(Ok, status);
2794 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2796 x = 39;
2797 y = 59;
2798 status = GdipIsVisiblePoint(graphics, x, y, &val);
2799 expect(Ok, status);
2800 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2802 x = 39.25;
2803 y = 59.25;
2804 status = GdipIsVisiblePoint(graphics, x, y, &val);
2805 expect(Ok, status);
2806 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2808 x = 39.5;
2809 y = 39.5;
2810 status = GdipIsVisiblePoint(graphics, x, y, &val);
2811 expect(Ok, status);
2812 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2814 x = 39.75;
2815 y = 59.75;
2816 status = GdipIsVisiblePoint(graphics, x, y, &val);
2817 expect(Ok, status);
2818 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2820 x = 40;
2821 y = 60;
2822 status = GdipIsVisiblePoint(graphics, x, y, &val);
2823 expect(Ok, status);
2824 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2826 x = 40.15;
2827 y = 60.15;
2828 status = GdipIsVisiblePoint(graphics, x, y, &val);
2829 expect(Ok, status);
2830 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2832 x = 10;
2833 y = 60;
2834 status = GdipIsVisiblePoint(graphics, x, y, &val);
2835 expect(Ok, status);
2836 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2838 /* integer version */
2839 x = 25;
2840 y = 30;
2841 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2842 expect(Ok, status);
2843 ok(val == TRUE, "After clipping, expected (%.2f, %.2f) to be visible\n", x, y);
2845 x = 50;
2846 y = 100;
2847 status = GdipIsVisiblePointI(graphics, (INT)x, (INT)y, &val);
2848 expect(Ok, status);
2849 ok(val == FALSE, "After clipping, expected (%.2f, %.2f) not to be visible\n", x, y);
2851 GdipDeleteGraphics(graphics);
2852 ReleaseDC(hwnd, hdc);
2855 static void test_GdipIsVisibleRect(void)
2857 GpStatus status;
2858 GpGraphics *graphics = NULL;
2859 HDC hdc = GetDC( hwnd );
2860 REAL x, y, width, height;
2861 BOOL val;
2863 ok(hdc != NULL, "Expected HDC to be initialized\n");
2865 status = GdipCreateFromHDC(hdc, &graphics);
2866 expect(Ok, status);
2867 ok(graphics != NULL, "Expected graphics to be initialized\n");
2869 status = GdipIsVisibleRect(NULL, 0, 0, 0, 0, &val);
2870 expect(InvalidParameter, status);
2872 status = GdipIsVisibleRect(graphics, 0, 0, 0, 0, NULL);
2873 expect(InvalidParameter, status);
2875 status = GdipIsVisibleRectI(NULL, 0, 0, 0, 0, &val);
2876 expect(InvalidParameter, status);
2878 status = GdipIsVisibleRectI(graphics, 0, 0, 0, 0, NULL);
2879 expect(InvalidParameter, status);
2881 /* entirely within the visible region */
2882 x = 0; width = 10;
2883 y = 0; height = 10;
2884 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2885 expect(Ok, status);
2886 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2888 /* partially outside */
2889 x = -10; width = 20;
2890 y = -10; height = 20;
2891 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2892 expect(Ok, status);
2893 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2895 /* entirely outside */
2896 x = -10; width = 5;
2897 y = -10; height = 5;
2898 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2899 expect(Ok, status);
2900 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2902 status = GdipSetClipRect(graphics, 10, 20, 30, 40, CombineModeReplace);
2903 expect(Ok, status);
2905 /* entirely within the visible region */
2906 x = 12; width = 10;
2907 y = 22; height = 10;
2908 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2909 expect(Ok, status);
2910 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2912 /* partially outside */
2913 x = 35; width = 10;
2914 y = 55; height = 10;
2915 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2916 expect(Ok, status);
2917 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2919 /* entirely outside */
2920 x = 45; width = 5;
2921 y = 65; height = 5;
2922 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2923 expect(Ok, status);
2924 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2926 /* translate into center of clipping rect */
2927 GdipTranslateWorldTransform(graphics, 25, 40, MatrixOrderAppend);
2929 x = 0; width = 10;
2930 y = 0; height = 10;
2931 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2932 expect(Ok, status);
2933 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2935 x = 25; width = 5;
2936 y = 40; height = 5;
2937 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2938 expect(Ok, status);
2939 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2941 GdipTranslateWorldTransform(graphics, -25, -40, MatrixOrderAppend);
2943 /* corners entirely outside, but some intersections */
2944 x = 0; width = 70;
2945 y = 0; height = 90;
2946 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2947 expect(Ok, status);
2948 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2950 x = 0; width = 70;
2951 y = 0; height = 30;
2952 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2953 expect(Ok, status);
2954 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2956 x = 0; width = 30;
2957 y = 0; height = 90;
2958 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2959 expect(Ok, status);
2960 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2962 /* edge cases */
2963 x = 0; width = 10;
2964 y = 20; height = 40;
2965 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2966 expect(Ok, status);
2967 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2969 x = 10; width = 30;
2970 y = 0; height = 20;
2971 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2972 expect(Ok, status);
2973 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2975 x = 40; width = 10;
2976 y = 20; height = 40;
2977 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2978 expect(Ok, status);
2979 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2981 x = 10; width = 30;
2982 y = 60; height = 10;
2983 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2984 expect(Ok, status);
2985 ok(val == FALSE, "Expected (%.2f, %.2f, %.2f, %.2f) not to be visible\n", x, y, width, height);
2987 /* rounding tests */
2988 x = 0.4; width = 10.4;
2989 y = 20; height = 40;
2990 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2991 expect(Ok, status);
2992 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
2994 x = 10; width = 30;
2995 y = 0.4; height = 20.4;
2996 status = GdipIsVisibleRect(graphics, x, y, width, height, &val);
2997 expect(Ok, status);
2998 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
3000 /* integer version */
3001 x = 0; width = 30;
3002 y = 0; height = 90;
3003 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
3004 expect(Ok, status);
3005 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
3007 x = 12; width = 10;
3008 y = 22; height = 10;
3009 status = GdipIsVisibleRectI(graphics, (INT)x, (INT)y, (INT)width, (INT)height, &val);
3010 expect(Ok, status);
3011 ok(val == TRUE, "Expected (%.2f, %.2f, %.2f, %.2f) to be visible\n", x, y, width, height);
3013 GdipDeleteGraphics(graphics);
3014 ReleaseDC(hwnd, hdc);
3017 static void test_GdipGetNearestColor(void)
3019 GpStatus status;
3020 GpGraphics *graphics;
3021 GpBitmap *bitmap;
3022 ARGB color = 0xdeadbeef;
3023 HDC hdc = GetDC( hwnd );
3025 /* create a graphics object */
3026 ok(hdc != NULL, "Expected HDC to be initialized\n");
3028 status = GdipCreateFromHDC(hdc, &graphics);
3029 expect(Ok, status);
3030 ok(graphics != NULL, "Expected graphics to be initialized\n");
3032 status = GdipGetNearestColor(graphics, NULL);
3033 expect(InvalidParameter, status);
3035 status = GdipGetNearestColor(NULL, &color);
3036 expect(InvalidParameter, status);
3037 GdipDeleteGraphics(graphics);
3039 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat1bppIndexed, NULL, &bitmap);
3040 expect(Ok, status);
3041 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3042 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
3043 if (status == Ok)
3045 status = GdipGetNearestColor(graphics, &color);
3046 expect(Ok, status);
3047 expect(0xdeadbeef, color);
3048 GdipDeleteGraphics(graphics);
3050 GdipDisposeImage((GpImage*)bitmap);
3052 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat4bppIndexed, NULL, &bitmap);
3053 expect(Ok, status);
3054 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3055 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
3056 if (status == Ok)
3058 status = GdipGetNearestColor(graphics, &color);
3059 expect(Ok, status);
3060 expect(0xdeadbeef, color);
3061 GdipDeleteGraphics(graphics);
3063 GdipDisposeImage((GpImage*)bitmap);
3065 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat8bppIndexed, NULL, &bitmap);
3066 expect(Ok, status);
3067 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3068 ok(broken(status == OutOfMemory) /* winver < Win7 */ || status == Ok, "status=%u\n", status);
3069 if (status == Ok)
3071 status = GdipGetNearestColor(graphics, &color);
3072 expect(Ok, status);
3073 expect(0xdeadbeef, color);
3074 GdipDeleteGraphics(graphics);
3076 GdipDisposeImage((GpImage*)bitmap);
3078 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppGrayScale, NULL, &bitmap);
3079 expect(Ok, status);
3080 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3081 todo_wine expect(OutOfMemory, status);
3082 if (status == Ok)
3083 GdipDeleteGraphics(graphics);
3084 GdipDisposeImage((GpImage*)bitmap);
3086 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat24bppRGB, NULL, &bitmap);
3087 expect(Ok, status);
3088 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3089 expect(Ok, status);
3090 status = GdipGetNearestColor(graphics, &color);
3091 expect(Ok, status);
3092 expect(0xdeadbeef, color);
3093 GdipDeleteGraphics(graphics);
3094 GdipDisposeImage((GpImage*)bitmap);
3096 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppRGB, NULL, &bitmap);
3097 expect(Ok, status);
3098 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3099 expect(Ok, status);
3100 status = GdipGetNearestColor(graphics, &color);
3101 expect(Ok, status);
3102 expect(0xdeadbeef, color);
3103 GdipDeleteGraphics(graphics);
3104 GdipDisposeImage((GpImage*)bitmap);
3106 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat32bppARGB, NULL, &bitmap);
3107 expect(Ok, status);
3108 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3109 expect(Ok, status);
3110 status = GdipGetNearestColor(graphics, &color);
3111 expect(Ok, status);
3112 expect(0xdeadbeef, color);
3113 GdipDeleteGraphics(graphics);
3114 GdipDisposeImage((GpImage*)bitmap);
3116 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat48bppRGB, NULL, &bitmap);
3117 expect(Ok, status);
3118 if (status == Ok)
3120 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3121 expect(Ok, status);
3122 status = GdipGetNearestColor(graphics, &color);
3123 expect(Ok, status);
3124 expect(0xdeadbeef, color);
3125 GdipDeleteGraphics(graphics);
3126 GdipDisposeImage((GpImage*)bitmap);
3129 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppARGB, NULL, &bitmap);
3130 expect(Ok, status);
3131 if (status == Ok)
3133 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3134 expect(Ok, status);
3135 status = GdipGetNearestColor(graphics, &color);
3136 expect(Ok, status);
3137 expect(0xdeadbeef, color);
3138 GdipDeleteGraphics(graphics);
3139 GdipDisposeImage((GpImage*)bitmap);
3142 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat64bppPARGB, NULL, &bitmap);
3143 expect(Ok, status);
3144 if (status == Ok)
3146 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3147 expect(Ok, status);
3148 status = GdipGetNearestColor(graphics, &color);
3149 expect(Ok, status);
3150 expect(0xdeadbeef, color);
3151 GdipDeleteGraphics(graphics);
3152 GdipDisposeImage((GpImage*)bitmap);
3155 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB565, NULL, &bitmap);
3156 expect(Ok, status);
3157 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3158 expect(Ok, status);
3159 status = GdipGetNearestColor(graphics, &color);
3160 expect(Ok, status);
3161 todo_wine expect(0xffa8bce8, color);
3162 GdipDeleteGraphics(graphics);
3163 GdipDisposeImage((GpImage*)bitmap);
3165 status = GdipCreateBitmapFromScan0(10, 10, 10, PixelFormat16bppRGB555, NULL, &bitmap);
3166 expect(Ok, status);
3167 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3168 expect(Ok, status);
3169 status = GdipGetNearestColor(graphics, &color);
3170 expect(Ok, status);
3171 todo_wine
3172 ok(color == 0xffa8b8e8 ||
3173 broken(color == 0xffa0b8e0), /* Win98/WinMe */
3174 "Expected ffa8b8e8, got %.8x\n", color);
3175 GdipDeleteGraphics(graphics);
3176 GdipDisposeImage((GpImage*)bitmap);
3178 ReleaseDC(hwnd, hdc);
3181 static void test_string_functions(void)
3183 GpStatus status;
3184 GpGraphics *graphics;
3185 GpFontFamily *family;
3186 GpFont *font;
3187 RectF rc, char_bounds, bounds;
3188 GpBrush *brush;
3189 ARGB color = 0xff000000;
3190 HDC hdc = GetDC( hwnd );
3191 const WCHAR fontname[] = {'T','a','h','o','m','a',0};
3192 const WCHAR teststring[] = {'M','M',' ','M','\n','M',0};
3193 const WCHAR teststring2[] = {'j',0};
3194 REAL char_width, char_height;
3195 INT codepointsfitted, linesfilled;
3196 GpStringFormat *format;
3197 CharacterRange ranges[3] = {{0, 1}, {1, 3}, {5, 1}};
3198 GpRegion *regions[4];
3199 BOOL region_isempty[4];
3200 int i;
3201 PointF positions[8];
3202 GpMatrix *identity;
3204 ok(hdc != NULL, "Expected HDC to be initialized\n");
3205 status = GdipCreateFromHDC(hdc, &graphics);
3206 expect(Ok, status);
3207 ok(graphics != NULL, "Expected graphics to be initialized\n");
3209 status = GdipCreateFontFamilyFromName(fontname, NULL, &family);
3210 expect(Ok, status);
3212 status = GdipCreateFont(family, 10.0, FontStyleRegular, UnitPixel, &font);
3213 expect(Ok, status);
3215 status = GdipCreateSolidFill(color, (GpSolidFill**)&brush);
3216 expect(Ok, status);
3218 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3219 expect(Ok, status);
3221 rc.X = 0;
3222 rc.Y = 0;
3223 rc.Width = 100.0;
3224 rc.Height = 100.0;
3226 status = GdipDrawString(NULL, teststring, 6, font, &rc, NULL, brush);
3227 expect(InvalidParameter, status);
3229 status = GdipDrawString(graphics, NULL, 6, font, &rc, NULL, brush);
3230 expect(InvalidParameter, status);
3232 status = GdipDrawString(graphics, teststring, 6, NULL, &rc, NULL, brush);
3233 expect(InvalidParameter, status);
3235 status = GdipDrawString(graphics, teststring, 6, font, NULL, NULL, brush);
3236 expect(InvalidParameter, status);
3238 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, NULL);
3239 expect(InvalidParameter, status);
3241 status = GdipDrawString(graphics, teststring, 6, font, &rc, NULL, brush);
3242 expect(Ok, status);
3244 status = GdipMeasureString(NULL, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3245 expect(InvalidParameter, status);
3247 status = GdipMeasureString(graphics, NULL, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3248 expect(InvalidParameter, status);
3250 status = GdipMeasureString(graphics, teststring, 6, NULL, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3251 expect(InvalidParameter, status);
3253 status = GdipMeasureString(graphics, teststring, 6, font, NULL, NULL, &bounds, &codepointsfitted, &linesfilled);
3254 expect(InvalidParameter, status);
3256 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, NULL, &codepointsfitted, &linesfilled);
3257 expect(InvalidParameter, status);
3259 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, NULL, &linesfilled);
3260 expect(Ok, status);
3262 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, NULL);
3263 expect(Ok, status);
3265 status = GdipMeasureString(graphics, teststring, 1, font, &rc, NULL, &char_bounds, &codepointsfitted, &linesfilled);
3266 expect(Ok, status);
3267 expectf(0.0, char_bounds.X);
3268 expectf(0.0, char_bounds.Y);
3269 ok(char_bounds.Width > 0, "got %0.2f\n", bounds.Width);
3270 ok(char_bounds.Height > 0, "got %0.2f\n", bounds.Height);
3271 expect(1, codepointsfitted);
3272 expect(1, linesfilled);
3274 status = GdipMeasureString(graphics, teststring, 2, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3275 expect(Ok, status);
3276 expectf(0.0, bounds.X);
3277 expectf(0.0, bounds.Y);
3278 ok(bounds.Width > char_bounds.Width, "got %0.2f, expected at least %0.2f\n", bounds.Width, char_bounds.Width);
3279 expectf(char_bounds.Height, bounds.Height);
3280 expect(2, codepointsfitted);
3281 expect(1, linesfilled);
3282 char_width = bounds.Width - char_bounds.Width;
3284 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3285 expect(Ok, status);
3286 expectf(0.0, bounds.X);
3287 expectf(0.0, bounds.Y);
3288 ok(bounds.Width > char_bounds.Width + char_width * 2, "got %0.2f, expected at least %0.2f\n",
3289 bounds.Width, char_bounds.Width + char_width * 2);
3290 ok(bounds.Height > char_bounds.Height, "got %0.2f, expected at least %0.2f\n", bounds.Height, char_bounds.Height);
3291 expect(6, codepointsfitted);
3292 expect(2, linesfilled);
3293 char_height = bounds.Height - char_bounds.Height;
3295 /* Measure the first line. */
3296 status = GdipMeasureString(graphics, teststring, 4, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3297 expect(Ok, status);
3298 expectf(0.0, bounds.X);
3299 expectf(0.0, bounds.Y);
3300 expect(4, codepointsfitted);
3301 expect(1, linesfilled);
3303 /* Give just enough space to fit the first line. */
3304 rc.Width = bounds.Width;
3305 status = GdipMeasureString(graphics, teststring, 5, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3306 expect(Ok, status);
3307 expectf(0.0, bounds.X);
3308 expectf(0.0, bounds.Y);
3309 todo_wine expect(5, codepointsfitted);
3310 todo_wine expect(1, linesfilled);
3312 /* Cut off everything after the first space. */
3313 rc.Width = char_bounds.Width + char_width * 2.1;
3315 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3316 expect(Ok, status);
3317 expectf(0.0, bounds.X);
3318 expectf(0.0, bounds.Y);
3319 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3320 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3321 expect(6, codepointsfitted);
3322 expect(3, linesfilled);
3324 /* Cut off everything including the first space. */
3325 rc.Width = char_bounds.Width + char_width * 1.7;
3327 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3328 expect(Ok, status);
3329 expectf(0.0, bounds.X);
3330 expectf(0.0, bounds.Y);
3331 expectf_(char_bounds.Width + char_width, bounds.Width, 0.01);
3332 expectf_(char_bounds.Height + char_height * 2, bounds.Height, 0.01);
3333 expect(6, codepointsfitted);
3334 expect(3, linesfilled);
3336 /* Cut off everything after the first character. */
3337 rc.Width = char_bounds.Width + char_width * 0.8;
3339 status = GdipMeasureString(graphics, teststring, 6, font, &rc, NULL, &bounds, &codepointsfitted, &linesfilled);
3340 expect(Ok, status);
3341 expectf(0.0, bounds.X);
3342 expectf(0.0, bounds.Y);
3343 expectf_(char_bounds.Width, bounds.Width, 0.01);
3344 expectf_(char_bounds.Height + char_height * 3, bounds.Height, 0.05);
3345 expect(6, codepointsfitted);
3346 todo_wine expect(4, linesfilled);
3348 for (i = 0; i < 4; i++)
3349 regions[i] = (GpRegion *)0xdeadbeef;
3351 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 0, regions);
3352 expect(Ok, status);
3354 for (i = 0; i < 4; i++)
3355 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3357 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3358 expect(Ok, status);
3360 for (i = 0; i < 4; i++)
3361 ok(regions[i] == (GpRegion *)0xdeadbeef, "expected 0xdeadbeef, got %p\n", regions[i]);
3363 status = GdipSetStringFormatMeasurableCharacterRanges(format, 3, ranges);
3364 expect(Ok, status);
3366 set_rect_empty(&rc);
3368 for (i=0; i<4; i++)
3370 status = GdipCreateRegion(&regions[i]);
3371 expect(Ok, status);
3372 status = GdipSetEmpty(regions[i]);
3373 expect(Ok, status);
3376 status = GdipMeasureCharacterRanges(NULL, teststring, 6, font, &rc, format, 3, regions);
3377 expect(InvalidParameter, status);
3379 status = GdipMeasureCharacterRanges(graphics, NULL, 6, font, &rc, format, 3, regions);
3380 expect(InvalidParameter, status);
3382 status = GdipMeasureCharacterRanges(graphics, teststring, 6, NULL, &rc, format, 3, regions);
3383 expect(InvalidParameter, status);
3385 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, NULL, format, 3, regions);
3386 expect(InvalidParameter, status);
3388 if (0)
3390 /* Crashes on Windows XP */
3391 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, NULL, 3, regions);
3392 expect(InvalidParameter, status);
3395 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, NULL);
3396 expect(InvalidParameter, status);
3398 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 2, regions);
3399 expect(InvalidParameter, status);
3401 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3402 expect(Ok, status);
3404 for (i = 0; i < 4; i++)
3406 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3407 expect(Ok, status);
3410 ok(region_isempty[0], "region should be empty\n");
3411 ok(region_isempty[1], "region should be empty\n");
3412 ok(region_isempty[2], "region should be empty\n");
3413 ok(region_isempty[3], "region should be empty\n");
3415 rc.Width = 100.0;
3416 rc.Height = 100.0;
3418 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 4, regions);
3419 expect(Ok, status);
3421 for (i=0; i<4; i++)
3423 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3424 expect(Ok, status);
3427 ok(!region_isempty[0], "region shouldn't be empty\n");
3428 ok(!region_isempty[1], "region shouldn't be empty\n");
3429 ok(!region_isempty[2], "region shouldn't be empty\n");
3430 ok(region_isempty[3], "region should be empty\n");
3432 /* Cut off everything after the first space, and the second line. */
3433 rc.Width = char_bounds.Width + char_width * 2.1;
3434 rc.Height = char_bounds.Height + char_height * 0.5;
3436 status = GdipMeasureCharacterRanges(graphics, teststring, 6, font, &rc, format, 3, regions);
3437 expect(Ok, status);
3439 for (i=0; i<4; i++)
3441 status = GdipIsEmptyRegion(regions[i], graphics, &region_isempty[i]);
3442 expect(Ok, status);
3445 ok(!region_isempty[0], "region shouldn't be empty\n");
3446 ok(!region_isempty[1], "region shouldn't be empty\n");
3447 ok(region_isempty[2], "region should be empty\n");
3448 ok(region_isempty[3], "region should be empty\n");
3450 for (i=0; i<4; i++)
3451 GdipDeleteRegion(regions[i]);
3453 status = GdipCreateMatrix(&identity);
3454 expect(Ok, status);
3456 rc.X = 0;
3457 rc.Y = 0;
3458 rc.Width = 0;
3459 rc.Height = 0;
3460 memset(positions, 0, sizeof(positions));
3461 status = GdipMeasureDriverString(NULL, teststring, 6, font, positions,
3462 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3463 identity, &rc);
3464 expect(InvalidParameter, status);
3466 status = GdipMeasureDriverString(graphics, NULL, 6, font, positions,
3467 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3468 identity, &rc);
3469 expect(InvalidParameter, status);
3471 status = GdipMeasureDriverString(graphics, teststring, 6, NULL, positions,
3472 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3473 identity, &rc);
3474 expect(InvalidParameter, status);
3476 status = GdipMeasureDriverString(graphics, teststring, 6, font, NULL,
3477 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3478 identity, &rc);
3479 expect(InvalidParameter, status);
3481 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3482 0x100, identity, &rc);
3483 expect(Ok, status);
3485 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3486 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3487 NULL, &rc);
3488 expect(Ok, status);
3490 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3491 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3492 identity, NULL);
3493 expect(InvalidParameter, status);
3495 rc.X = 0;
3496 rc.Y = 0;
3497 rc.Width = 0;
3498 rc.Height = 0;
3499 status = GdipMeasureDriverString(graphics, teststring, 6, font, positions,
3500 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3501 identity, &rc);
3502 expect(Ok, status);
3504 expectf(0.0, rc.X);
3505 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3506 ok(rc.Width > 0.0, "unexpected Width %0.2f\n", rc.Width);
3507 ok(rc.Height > 0.0, "unexpected Y %0.2f\n", rc.Y);
3509 char_width = rc.Width;
3510 char_height = rc.Height;
3512 rc.X = 0;
3513 rc.Y = 0;
3514 rc.Width = 0;
3515 rc.Height = 0;
3516 status = GdipMeasureDriverString(graphics, teststring, 4, font, positions,
3517 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3518 identity, &rc);
3519 expect(Ok, status);
3521 expectf(0.0, rc.X);
3522 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3523 ok(rc.Width < char_width, "got Width %0.2f, expecting less than %0.2f\n", rc.Width, char_width);
3524 expectf(char_height, rc.Height);
3526 rc.X = 0;
3527 rc.Y = 0;
3528 rc.Width = 0;
3529 rc.Height = 0;
3530 status = GdipMeasureDriverString(graphics, teststring2, 1, font, positions,
3531 DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance,
3532 identity, &rc);
3533 expect(Ok, status);
3535 expectf(rc.X, 0.0);
3536 ok(rc.Y < 0.0, "unexpected Y %0.2f\n", rc.Y);
3537 ok(rc.Width > 0, "unexpected Width %0.2f\n", rc.Width);
3538 expectf(rc.Height, char_height);
3540 GdipDeleteMatrix(identity);
3541 GdipDeleteStringFormat(format);
3542 GdipDeleteBrush(brush);
3543 GdipDeleteFont(font);
3544 GdipDeleteFontFamily(family);
3545 GdipDeleteGraphics(graphics);
3547 ReleaseDC(hwnd, hdc);
3550 static void test_get_set_interpolation(void)
3552 GpGraphics *graphics;
3553 HDC hdc = GetDC( hwnd );
3554 GpStatus status;
3555 InterpolationMode mode;
3557 ok(hdc != NULL, "Expected HDC to be initialized\n");
3558 status = GdipCreateFromHDC(hdc, &graphics);
3559 expect(Ok, status);
3560 ok(graphics != NULL, "Expected graphics to be initialized\n");
3562 status = GdipGetInterpolationMode(NULL, &mode);
3563 expect(InvalidParameter, status);
3565 if (0)
3567 /* Crashes on Windows XP */
3568 status = GdipGetInterpolationMode(graphics, NULL);
3569 expect(InvalidParameter, status);
3572 status = GdipSetInterpolationMode(NULL, InterpolationModeNearestNeighbor);
3573 expect(InvalidParameter, status);
3575 /* out of range */
3576 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQualityBicubic+1);
3577 expect(InvalidParameter, status);
3579 status = GdipSetInterpolationMode(graphics, InterpolationModeInvalid);
3580 expect(InvalidParameter, status);
3582 status = GdipGetInterpolationMode(graphics, &mode);
3583 expect(Ok, status);
3584 expect(InterpolationModeBilinear, mode);
3586 status = GdipSetInterpolationMode(graphics, InterpolationModeNearestNeighbor);
3587 expect(Ok, status);
3589 status = GdipGetInterpolationMode(graphics, &mode);
3590 expect(Ok, status);
3591 expect(InterpolationModeNearestNeighbor, mode);
3593 status = GdipSetInterpolationMode(graphics, InterpolationModeDefault);
3594 expect(Ok, status);
3596 status = GdipGetInterpolationMode(graphics, &mode);
3597 expect(Ok, status);
3598 expect(InterpolationModeBilinear, mode);
3600 status = GdipSetInterpolationMode(graphics, InterpolationModeLowQuality);
3601 expect(Ok, status);
3603 status = GdipGetInterpolationMode(graphics, &mode);
3604 expect(Ok, status);
3605 expect(InterpolationModeBilinear, mode);
3607 status = GdipSetInterpolationMode(graphics, InterpolationModeHighQuality);
3608 expect(Ok, status);
3610 status = GdipGetInterpolationMode(graphics, &mode);
3611 expect(Ok, status);
3612 expect(InterpolationModeHighQualityBicubic, mode);
3614 GdipDeleteGraphics(graphics);
3616 ReleaseDC(hwnd, hdc);
3619 static void test_get_set_textrenderinghint(void)
3621 GpGraphics *graphics;
3622 HDC hdc = GetDC( hwnd );
3623 GpStatus status;
3624 TextRenderingHint hint;
3626 ok(hdc != NULL, "Expected HDC to be initialized\n");
3627 status = GdipCreateFromHDC(hdc, &graphics);
3628 expect(Ok, status);
3629 ok(graphics != NULL, "Expected graphics to be initialized\n");
3631 status = GdipGetTextRenderingHint(NULL, &hint);
3632 expect(InvalidParameter, status);
3634 status = GdipGetTextRenderingHint(graphics, NULL);
3635 expect(InvalidParameter, status);
3637 status = GdipSetTextRenderingHint(NULL, TextRenderingHintAntiAlias);
3638 expect(InvalidParameter, status);
3640 /* out of range */
3641 status = GdipSetTextRenderingHint(graphics, TextRenderingHintClearTypeGridFit+1);
3642 expect(InvalidParameter, status);
3644 status = GdipGetTextRenderingHint(graphics, &hint);
3645 expect(Ok, status);
3646 expect(TextRenderingHintSystemDefault, hint);
3648 status = GdipSetTextRenderingHint(graphics, TextRenderingHintSystemDefault);
3649 expect(Ok, status);
3651 status = GdipGetTextRenderingHint(graphics, &hint);
3652 expect(Ok, status);
3653 expect(TextRenderingHintSystemDefault, hint);
3655 status = GdipSetTextRenderingHint(graphics, TextRenderingHintAntiAliasGridFit);
3656 expect(Ok, status);
3658 status = GdipGetTextRenderingHint(graphics, &hint);
3659 expect(Ok, status);
3660 expect(TextRenderingHintAntiAliasGridFit, hint);
3662 GdipDeleteGraphics(graphics);
3664 ReleaseDC(hwnd, hdc);
3667 static void test_getdc_scaled(void)
3669 GpStatus status;
3670 GpGraphics *graphics = NULL;
3671 GpBitmap *bitmap = NULL;
3672 HDC hdc=NULL;
3673 HBRUSH hbrush, holdbrush;
3674 ARGB color;
3676 status = GdipCreateBitmapFromScan0(10, 10, 12, PixelFormat24bppRGB, NULL, &bitmap);
3677 expect(Ok, status);
3679 status = GdipGetImageGraphicsContext((GpImage*)bitmap, &graphics);
3680 expect(Ok, status);
3682 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
3683 expect(Ok, status);
3685 status = GdipGetDC(graphics, &hdc);
3686 expect(Ok, status);
3687 ok(hdc != NULL, "got NULL hdc\n");
3689 hbrush = CreateSolidBrush(RGB(255, 0, 0));
3691 holdbrush = SelectObject(hdc, hbrush);
3693 Rectangle(hdc, 2, 2, 6, 6);
3695 SelectObject(hdc, holdbrush);
3697 DeleteObject(hbrush);
3699 status = GdipReleaseDC(graphics, hdc);
3700 expect(Ok, status);
3702 GdipDeleteGraphics(graphics);
3704 status = GdipBitmapGetPixel(bitmap, 3, 3, &color);
3705 expect(Ok, status);
3706 expect(0xffff0000, color);
3708 status = GdipBitmapGetPixel(bitmap, 8, 8, &color);
3709 expect(Ok, status);
3710 expect(0xff000000, color);
3712 GdipDisposeImage((GpImage*)bitmap);
3715 static void test_GdipMeasureString(void)
3717 static const struct test_data
3719 REAL res_x, res_y, page_scale;
3720 GpUnit unit;
3721 } td[] =
3723 { 200.0, 200.0, 1.0, UnitPixel }, /* base */
3724 { 200.0, 200.0, 2.0, UnitPixel },
3725 { 200.0, 200.0, 1.0, UnitDisplay },
3726 { 200.0, 200.0, 2.0, UnitDisplay },
3727 { 200.0, 200.0, 1.0, UnitInch },
3728 { 200.0, 200.0, 2.0, UnitInch },
3729 { 200.0, 600.0, 1.0, UnitPoint },
3730 { 200.0, 600.0, 2.0, UnitPoint },
3731 { 200.0, 600.0, 1.0, UnitDocument },
3732 { 200.0, 600.0, 2.0, UnitDocument },
3733 { 200.0, 600.0, 1.0, UnitMillimeter },
3734 { 200.0, 600.0, 2.0, UnitMillimeter },
3735 { 200.0, 600.0, 1.0, UnitDisplay },
3736 { 200.0, 600.0, 2.0, UnitDisplay },
3737 { 200.0, 600.0, 1.0, UnitPixel },
3738 { 200.0, 600.0, 2.0, UnitPixel },
3740 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
3741 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
3742 GpStatus status;
3743 GpGraphics *graphics;
3744 GpFontFamily *family;
3745 GpFont *font;
3746 GpStringFormat *format;
3747 RectF bounds, rc;
3748 REAL base_cx = 0, base_cy = 0, height;
3749 INT chars, lines;
3750 LOGFONTW lf;
3751 UINT i;
3752 REAL font_size;
3753 GpUnit font_unit, unit;
3755 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
3756 expect(Ok, status);
3757 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
3758 expect(Ok, status);
3760 /* font size in pixels */
3761 status = GdipCreateFont(family, 100.0, FontStyleRegular, UnitPixel, &font);
3762 expect(Ok, status);
3763 status = GdipGetFontSize(font, &font_size);
3764 expect(Ok, status);
3765 expectf(100.0, font_size);
3766 status = GdipGetFontUnit(font, &font_unit);
3767 expect(Ok, status);
3768 expect(UnitPixel, font_unit);
3770 for (i = 0; i < ARRAY_SIZE(td); i++)
3772 GpImage *image;
3774 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3776 lf.lfHeight = 0xdeadbeef;
3777 status = GdipGetLogFontW(font, graphics, &lf);
3778 expect(Ok, status);
3779 height = units_to_pixels(font_size, td[i].unit, td[i].res_y);
3780 if (td[i].unit != UnitDisplay)
3781 height *= td[i].page_scale;
3782 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3783 i, (LONG)(height + 0.5), height, lf.lfHeight);
3785 height = font_size + 2.0 * font_size / 6.0;
3787 set_rect_empty(&rc);
3788 set_rect_empty(&bounds);
3789 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3790 expect(Ok, status);
3792 if (i == 0)
3794 base_cx = bounds.Width;
3795 base_cy = bounds.Height;
3798 expectf(0.0, bounds.X);
3799 expectf(0.0, bounds.Y);
3800 todo_wine
3801 expectf_(height, bounds.Height, height / 100.0);
3802 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3803 expect(7, chars);
3804 expect(1, lines);
3806 /* make sure it really fits */
3807 bounds.Width += 1.0;
3808 bounds.Height += 1.0;
3809 rc = bounds;
3810 rc.X = 50.0;
3811 rc.Y = 50.0;
3812 set_rect_empty(&bounds);
3813 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3814 expect(Ok, status);
3815 expectf(50.0, bounds.X);
3816 expectf(50.0, bounds.Y);
3817 todo_wine
3818 expectf_(height, bounds.Height, height / 100.0);
3819 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3820 expect(7, chars);
3821 expect(1, lines);
3823 status = GdipDeleteGraphics(graphics);
3824 expect(Ok, status);
3826 status = GdipDisposeImage(image);
3827 expect(Ok, status);
3830 GdipDeleteFont(font);
3832 /* font size in logical units */
3833 /* UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
3834 for (unit = 3; unit <= 6; unit++)
3836 /* create a font which final height is 100.0 pixels with 200 dpi device */
3837 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
3838 height = pixels_to_units(75.0, unit, 200.0);
3839 status = GdipCreateFont(family, height, FontStyleRegular, unit, &font);
3840 expect(Ok, status);
3841 status = GdipGetFontSize(font, &font_size);
3842 expect(Ok, status);
3843 expectf(height, font_size);
3844 status = GdipGetFontUnit(font, &font_unit);
3845 expect(Ok, status);
3846 expect(unit, font_unit);
3848 for (i = 0; i < ARRAY_SIZE(td); i++)
3850 REAL unit_scale;
3851 GpImage *image;
3853 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3855 lf.lfHeight = 0xdeadbeef;
3856 status = GdipGetLogFontW(font, graphics, &lf);
3857 expect(Ok, status);
3858 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3859 height = units_to_pixels(font_size, font_unit, td[i].res_x);
3860 else
3861 height = units_to_pixels(font_size, font_unit, td[i].res_y);
3862 /*trace("%.1f font units = %f pixels with %.1f dpi, page_scale %.1f\n", font_size, height, td[i].res_y, td[i].page_scale);*/
3863 ok(-lf.lfHeight == (LONG)(height + 0.5), "%u: expected %d (%f), got %d\n",
3864 i, (LONG)(height + 0.5), height, lf.lfHeight);
3866 if (td[i].unit == UnitDisplay || td[i].unit == UnitPixel)
3867 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_x);
3868 else
3869 unit_scale = units_scale(font_unit, td[i].unit, td[i].res_y);
3870 /*trace("%u: %d to %d, %.1f dpi => unit_scale %f\n", i, font_unit, td[i].unit, td[i].res_y, unit_scale);*/
3871 height = (font_size + 2.0 * font_size / 6.0) * unit_scale;
3872 if (td[i].unit != UnitDisplay)
3873 height /= td[i].page_scale;
3874 /*trace("%u: %.1f font units = %f units with %.1f dpi, page_scale %.1f\n", i, font_size, height, td[i].res_y, td[i].page_scale);*/
3876 set_rect_empty(&rc);
3877 set_rect_empty(&bounds);
3878 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3879 expect(Ok, status);
3881 if (i == 0)
3883 base_cx = bounds.Width;
3884 base_cy = bounds.Height;
3887 expectf(0.0, bounds.X);
3888 expectf(0.0, bounds.Y);
3889 todo_wine
3890 expectf_(height, bounds.Height, height / 85.0);
3891 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3892 expect(7, chars);
3893 expect(1, lines);
3895 /* make sure it really fits */
3896 bounds.Width += 1.0;
3897 bounds.Height += 1.0;
3898 rc = bounds;
3899 rc.X = 50.0;
3900 rc.Y = 50.0;
3901 set_rect_empty(&bounds);
3902 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3903 expect(Ok, status);
3904 expectf(50.0, bounds.X);
3905 expectf(50.0, bounds.Y);
3906 todo_wine
3907 expectf_(height, bounds.Height, height / 85.0);
3908 expectf_(bounds.Height / base_cy, bounds.Width / base_cx, 0.1);
3909 expect(7, chars);
3910 expect(1, lines);
3912 /* verify the result */
3913 height = units_to_pixels(bounds.Height, td[i].unit, td[i].res_x);
3914 if (td[i].unit != UnitDisplay)
3915 height *= td[i].page_scale;
3916 /*trace("%u: unit %u, %.1fx%.1f dpi, scale %.1f, height %f, pixels %f\n",
3917 i, td[i].unit, td[i].res_x, td[i].res_y, td[i].page_scale, bounds.Height, height);*/
3918 todo_wine
3919 expectf_(100.0, height, 1.1);
3921 status = GdipDeleteGraphics(graphics);
3922 expect(Ok, status);
3924 status = GdipDisposeImage(image);
3925 expect(Ok, status);
3928 GdipDeleteFont(font);
3931 /* Font with units = UnitWorld */
3932 for (i = 0; i < ARRAY_SIZE(td); i++)
3934 GpPointF pt = {0.0, 100.0};
3935 GpImage* image;
3936 REAL expected_width, expected_height;
3938 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].page_scale, &image);
3940 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &pt, 1);
3941 expect(Ok, status);
3943 status = GdipCreateFont(family, pt.Y, FontStyleRegular, UnitWorld, &font);
3944 expect(Ok, status);
3946 status = GdipGetFontUnit(font, &font_unit);
3947 expect(Ok, status);
3948 expect(UnitWorld, font_unit);
3950 lf.lfHeight = 0xdeadbeef;
3951 status = GdipGetLogFontW(font, graphics, &lf);
3952 expect(Ok, status);
3953 ok(lf.lfHeight == -100, "%u: expected -100, got %d\n", i, lf.lfHeight);
3955 set_rect_empty(&rc);
3956 set_rect_empty(&bounds);
3957 status = GdipMeasureString(graphics, string, -1, font, &rc, format, &bounds, &chars, &lines);
3958 expect(Ok, status);
3960 if (i == 0)
3962 base_cx = bounds.Width;
3963 base_cy = bounds.Height;
3966 pt.X = 1.0;
3967 pt.Y = 1.0;
3969 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &pt, 1);
3970 expect(Ok, status);
3972 /* height is constant in device space, width is proportional to height in world space */
3973 expected_width = base_cx * pt.Y;
3974 expected_height = base_cy * pt.Y;
3976 todo_wine_if(td[i].unit != UnitDisplay && td[i].unit != UnitPixel)
3977 ok(fabs(expected_width - bounds.Width) <= 0.001, "%u: expected %f, got %f\n", i, expected_width, bounds.Width);
3978 ok(fabs(expected_height - bounds.Height) <= 0.001, "%u: expected %f, got %f\n", i, expected_height, bounds.Height);
3980 GdipDeleteGraphics(graphics);
3981 GdipDisposeImage(image);
3982 GdipDeleteFont(font);
3985 GdipDeleteFontFamily(family);
3986 GdipDeleteStringFormat(format);
3989 static void test_transform(void)
3991 static const struct test_data
3993 REAL res_x, res_y, scale;
3994 GpUnit unit;
3995 GpPointF in[2], out[2];
3996 } td[] =
3998 { 96.0, 96.0, 1.0, UnitPixel,
3999 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
4000 { 96.0, 96.0, 1.0, UnitDisplay,
4001 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
4002 { 96.0, 96.0, 1.0, UnitInch,
4003 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 9600.0, 0.0 }, { 0.0, 9600.0 } } },
4004 { 123.0, 456.0, 1.0, UnitPoint,
4005 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 170.833313, 0.0 }, { 0.0, 633.333252 } } },
4006 { 123.0, 456.0, 1.0, UnitDocument,
4007 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 40.999996, 0.0 }, { 0.0, 151.999985 } } },
4008 { 123.0, 456.0, 2.0, UnitMillimeter,
4009 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 968.503845, 0.0 }, { 0.0, 3590.550781 } } },
4010 { 196.0, 296.0, 1.0, UnitDisplay,
4011 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
4012 { 196.0, 296.0, 1.0, UnitPixel,
4013 { { 100.0, 0.0 }, { 0.0, 100.0 } }, { { 100.0, 0.0 }, { 0.0, 100.0 } } },
4015 GpStatus status;
4016 GpGraphics *graphics;
4017 GpImage *image;
4018 GpPointF ptf[2];
4019 UINT i;
4021 for (i = 0; i < ARRAY_SIZE(td); i++)
4023 graphics = create_graphics(td[i].res_x, td[i].res_y, td[i].unit, td[i].scale, &image);
4024 ptf[0].X = td[i].in[0].X;
4025 ptf[0].Y = td[i].in[0].Y;
4026 ptf[1].X = td[i].in[1].X;
4027 ptf[1].Y = td[i].in[1].Y;
4028 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, ptf, 2);
4029 expect(Ok, status);
4030 expectf(td[i].out[0].X, ptf[0].X);
4031 expectf(td[i].out[0].Y, ptf[0].Y);
4032 expectf(td[i].out[1].X, ptf[1].X);
4033 expectf(td[i].out[1].Y, ptf[1].Y);
4034 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
4035 expect(Ok, status);
4036 expectf(td[i].in[0].X, ptf[0].X);
4037 expectf(td[i].in[0].Y, ptf[0].Y);
4038 expectf(td[i].in[1].X, ptf[1].X);
4039 expectf(td[i].in[1].Y, ptf[1].Y);
4040 status = GdipDeleteGraphics(graphics);
4041 expect(Ok, status);
4042 status = GdipDisposeImage(image);
4043 expect(Ok, status);
4047 static void test_pen_thickness(void)
4049 static const struct test_data
4051 REAL res_x, res_y, scale;
4052 GpUnit pen_unit, page_unit;
4053 REAL pen_width;
4054 INT cx, cy, path_cx, path_cy;
4055 } td[] =
4057 { 10.0, 10.0, 1.0, UnitPixel, UnitPixel, 1.0, 1, 1, 1, 1 },
4058 { 10.0, 10.0, 1.0, UnitPixel, UnitPixel, 0.0, 0, 0, 1, 1 },
4059 { 10.0, 10.0, 1.0, UnitPixel, UnitPixel, 0.1, 1, 1, 1, 1 },
4060 { 10.0, 10.0, 3.0, UnitPixel, UnitPixel, 2.0, 2, 2, 2, 2 },
4061 { 10.0, 10.0, 30.0, UnitPixel, UnitInch, 1.0, 1, 1, 1, 1 },
4062 { 10.0, 10.0, 1.0, UnitWorld, UnitPixel, 1.0, 1, 1, 1, 1 },
4063 { 10.0, 10.0, 1.0, UnitWorld, UnitPixel, 0.0, 1, 1, 1, 1 },
4064 { 10.0, 10.0, 3.0, UnitWorld, UnitPixel, 2.0, 6, 6, 6, 6 },
4065 { 10.0, 10.0, 2.0, UnitWorld, UnitInch, 1.0, 20, 20, 20, 20 },
4067 GpStatus status;
4068 int i, j;
4069 GpGraphics *graphics;
4070 union
4072 GpBitmap *bitmap;
4073 GpImage *image;
4074 } u;
4075 GpPen *pen;
4076 GpPointF corner;
4077 GpPath *path;
4078 BitmapData bd;
4079 INT min, max, size;
4081 for (i = 0; i < ARRAY_SIZE(td); i++)
4083 status = GdipCreateBitmapFromScan0(100, 100, 0, PixelFormat24bppRGB, NULL, &u.bitmap);
4084 expect(Ok, status);
4086 status = GdipBitmapSetResolution(u.bitmap, td[i].res_x, td[i].res_y);
4087 expect(Ok, status);
4089 status = GdipGetImageGraphicsContext(u.image, &graphics);
4090 expect(Ok, status);
4092 status = GdipSetPageUnit(graphics, td[i].page_unit);
4093 expect(Ok, status);
4095 status = GdipSetPageScale(graphics, td[i].scale);
4096 expect(Ok, status);
4098 status = GdipCreatePen1(0xffffffff, td[i].pen_width, td[i].pen_unit, &pen);
4099 expect(Ok, status);
4101 corner.X = corner.Y = 100.0;
4102 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &corner, 1);
4103 expect(Ok, status);
4105 status = GdipDrawLine(graphics, pen, corner.X/2, 0, corner.X/2, corner.Y);
4106 expect(Ok, status);
4108 status = GdipDrawLine(graphics, pen, 0, corner.Y/2, corner.X, corner.Y/2);
4109 expect(Ok, status);
4111 status = GdipBitmapLockBits(u.bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
4112 expect(Ok, status);
4114 min = -1;
4115 max = -2;
4117 for (j=0; j<100; j++)
4119 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
4121 min = j;
4122 break;
4126 for (j=99; j>=0; j--)
4128 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
4130 max = j;
4131 break;
4135 size = max-min+1;
4137 ok(size == td[i].cx, "%u: expected %d, got %d\n", i, td[i].cx, size);
4139 min = -1;
4140 max = -2;
4142 for (j=0; j<100; j++)
4144 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
4146 min = j;
4147 break;
4151 for (j=99; j>=0; j--)
4153 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
4155 max = j;
4156 break;
4160 size = max-min+1;
4162 ok(size == td[i].cy, "%u: expected %d, got %d\n", i, td[i].cy, size);
4164 status = GdipBitmapUnlockBits(u.bitmap, &bd);
4165 expect(Ok, status);
4167 status = GdipGraphicsClear(graphics, 0xff000000);
4168 expect(Ok, status);
4170 status = GdipCreatePath(FillModeAlternate, &path);
4171 expect(Ok, status);
4173 status = GdipAddPathLine(path, corner.X/2, 0, corner.X/2, corner.Y);
4174 expect(Ok, status);
4176 status = GdipClosePathFigure(path);
4177 expect(Ok, status);
4179 status = GdipAddPathLine(path, 0, corner.Y/2, corner.X, corner.Y/2);
4180 expect(Ok, status);
4182 status = GdipDrawPath(graphics, pen, path);
4183 expect(Ok, status);
4185 GdipDeletePath(path);
4187 status = GdipBitmapLockBits(u.bitmap, NULL, ImageLockModeRead, PixelFormat24bppRGB, &bd);
4188 expect(Ok, status);
4190 min = -1;
4191 max = -2;
4193 for (j=0; j<100; j++)
4195 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
4197 min = j;
4198 break;
4202 for (j=99; j>=0; j--)
4204 if (((BYTE*)bd.Scan0)[j*3] == 0xff)
4206 max = j;
4207 break;
4211 size = max-min+1;
4213 ok(size == td[i].path_cx, "%u: expected %d, got %d\n", i, td[i].path_cx, size);
4215 min = -1;
4216 max = -2;
4218 for (j=0; j<100; j++)
4220 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
4222 min = j;
4223 break;
4227 for (j=99; j>=0; j--)
4229 if (((BYTE*)bd.Scan0)[bd.Stride*j] == 0xff)
4231 max = j;
4232 break;
4236 size = max-min+1;
4238 ok(size == td[i].path_cy, "%u: expected %d, got %d\n", i, td[i].path_cy, size);
4240 status = GdipBitmapUnlockBits(u.bitmap, &bd);
4241 expect(Ok, status);
4243 GdipDeletePen(pen);
4244 GdipDeleteGraphics(graphics);
4245 GdipDisposeImage(u.image);
4249 /* Many people on the net ask why there is so much difference in rendered
4250 * text height between gdiplus and gdi32, this test suggests an answer to
4251 * that question. Important: this test assumes that font dpi == device dpi.
4253 static void test_font_height_scaling(void)
4255 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4256 static const WCHAR string[] = { '1','2','3','4','5','6','7',0 };
4257 HDC hdc;
4258 GpStringFormat *format;
4259 CharacterRange range = { 0, 7 };
4260 GpRegion *region;
4261 GpGraphics *graphics;
4262 GpFontFamily *family;
4263 GpFont *font;
4264 GpStatus status;
4265 RectF bounds, rect;
4266 REAL height, dpi, scale;
4267 PointF ptf;
4268 GpUnit gfx_unit, font_unit;
4270 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
4271 expect(Ok, status);
4272 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4273 expect(Ok, status);
4274 status = GdipCreateRegion(&region);
4275 expect(Ok, status);
4277 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4278 expect(Ok, status);
4280 hdc = CreateCompatibleDC(0);
4281 status = GdipCreateFromHDC(hdc, &graphics);
4282 expect(Ok, status);
4284 status = GdipGetDpiY(graphics, &dpi);
4285 expect(Ok, status);
4287 /* First check if tested functionality works:
4288 * under XP if font and graphics units differ then GdipTransformPoints
4289 * followed by GdipSetPageUnit to change the graphics units breaks region
4290 * scaling in GdipMeasureCharacterRanges called later.
4292 status = GdipSetPageUnit(graphics, UnitDocument);
4293 expect(Ok, status);
4295 ptf.X = 0.0;
4296 ptf.Y = 0.0;
4297 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
4298 expect(Ok, status);
4300 status = GdipSetPageUnit(graphics, UnitInch);
4301 expect(Ok, status);
4303 status = GdipCreateFont(family, 720.0, FontStyleRegular, UnitPoint, &font);
4304 expect(Ok, status);
4306 set_rect_empty(&rect);
4307 set_rect_empty(&bounds);
4308 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
4309 expect(Ok, status);
4310 trace("test bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);
4312 set_rect_empty(&rect);
4313 rect.Width = 32000.0;
4314 rect.Height = 32000.0;
4315 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4316 expect(Ok, status);
4318 set_rect_empty(&rect);
4319 status = GdipGetRegionBounds(region, graphics, &rect);
4320 expect(Ok, status);
4321 trace("test region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
4323 GdipDeleteFont(font);
4325 scale = rect.Height / bounds.Height;
4326 if (fabs(scale - 1.0) > 0.1)
4328 win_skip("GdipGetRegionBounds is broken, scale %f (should be near 1.0)\n", scale);
4329 goto cleanup;
4332 status = GdipScaleWorldTransform(graphics, 0.01, 0.01, MatrixOrderAppend);
4333 expect(Ok, status);
4335 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4336 /* UnitPixel as a font base unit is not tested because it drastically
4337 differs in behaviour */
4338 for (font_unit = 3; font_unit <= 6; font_unit++)
4340 /* create a font for the final text height of 100 pixels */
4341 /* height + 2 * (height/6) = 100 => height = 100 * 3 / 4 => 75 */
4342 status = GdipSetPageUnit(graphics, font_unit);
4343 expect(Ok, status);
4344 ptf.X = 0;
4345 ptf.Y = 75.0;
4346 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, &ptf, 1);
4347 expect(Ok, status);
4348 height = ptf.Y;
4349 /*trace("height %f units\n", height);*/
4350 status = GdipCreateFont(family, height, FontStyleRegular, font_unit, &font);
4351 expect(Ok, status);
4353 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4354 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
4356 static const WCHAR doubleW[2] = { 'W','W' };
4357 RectF bounds_1, bounds_2;
4358 REAL margin, margin_y, font_height;
4359 int match;
4361 status = GdipSetPageUnit(graphics, gfx_unit);
4362 expect(Ok, status);
4364 margin_y = units_to_pixels(height / 8.0, font_unit, dpi);
4365 margin_y = pixels_to_units(margin_y, gfx_unit, dpi);
4367 status = GdipGetFontHeight(font, graphics, &font_height);
4368 expect(Ok, status);
4370 set_rect_empty(&rect);
4371 set_rect_empty(&bounds);
4372 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, NULL, NULL);
4373 expect(Ok, status);
4374 /*trace("bounds: %f,%f,%f,%f\n", bounds.X, bounds.Y, bounds.Width, bounds.Height);*/
4375 todo_wine
4376 expectf_(font_height + margin_y, bounds.Height, 0.005);
4378 ptf.X = 0;
4379 ptf.Y = bounds.Height;
4380 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, &ptf, 1);
4381 expect(Ok, status);
4382 match = fabs(100.0 - ptf.Y) <= 1.0;
4383 todo_wine
4384 ok(match, "Expected 100.0, got %f\n", ptf.Y);
4386 /* verify the result */
4387 ptf.Y = units_to_pixels(bounds.Height, gfx_unit, dpi);
4388 ptf.Y /= 100.0;
4389 match = fabs(100.0 - ptf.Y) <= 1.0;
4390 todo_wine
4391 ok(match, "Expected 100.0, got %f\n", ptf.Y);
4393 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
4394 set_rect_empty(&rect);
4395 set_rect_empty(&bounds_1);
4396 status = GdipMeasureString(graphics, doubleW, 1, font, &rect, format, &bounds_1, NULL, NULL);
4397 expect(Ok, status);
4398 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
4399 set_rect_empty(&rect);
4400 set_rect_empty(&bounds_2);
4401 status = GdipMeasureString(graphics, doubleW, 2, font, &rect, format, &bounds_2, NULL, NULL);
4402 expect(Ok, status);
4404 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
4405 margin = bounds_1.Width - bounds_2.Width / 2.0;
4406 /*trace("margin %f\n", margin);*/
4407 ok(margin > 0.0, "wrong margin %f\n", margin);
4409 set_rect_empty(&rect);
4410 rect.Width = 320000.0;
4411 rect.Height = 320000.0;
4412 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4413 expect(Ok, status);
4414 set_rect_empty(&rect);
4415 status = GdipGetRegionBounds(region, graphics, &rect);
4416 expect(Ok, status);
4417 /*trace("region: %f,%f,%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);*/
4418 ok(rect.X > 0.0, "wrong rect.X %f\n", rect.X);
4419 expectf(0.0, rect.Y);
4420 match = fabs(1.0 - margin / rect.X) <= 0.05;
4421 ok(match, "Expected %f, got %f\n", margin, rect.X);
4422 match = fabs(1.0 - font_height / rect.Height) <= 0.1;
4423 ok(match, "Expected %f, got %f\n", font_height, rect.Height);
4424 match = fabs(1.0 - bounds.Width / (rect.Width + margin * 2.0)) <= 0.05;
4425 ok(match, "Expected %f, got %f\n", bounds.Width, rect.Width + margin * 2.0);
4428 GdipDeleteFont(font);
4431 cleanup:
4432 status = GdipDeleteGraphics(graphics);
4433 expect(Ok, status);
4434 DeleteDC(hdc);
4436 GdipDeleteFontFamily(family);
4437 GdipDeleteRegion(region);
4438 GdipDeleteStringFormat(format);
4441 static void test_measure_string(void)
4443 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4444 static const WCHAR string[] = { 'A','0','1',0 };
4445 HDC hdc;
4446 GpStringFormat *format;
4447 CharacterRange range;
4448 GpRegion *region;
4449 GpGraphics *graphics;
4450 GpFontFamily *family;
4451 GpFont *font;
4452 GpStatus status;
4453 RectF bounds, rect;
4454 REAL width, height, width_1, width_2;
4455 REAL margin_x, margin_y, width_rgn, height_rgn;
4456 int lines, glyphs;
4458 status = GdipCreateStringFormat(StringFormatFlagsNoWrap, LANG_NEUTRAL, &format);
4459 expect(Ok, status);
4460 expect(Ok, status);
4462 status = GdipCreateRegion(&region);
4463 expect(Ok, status);
4465 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4466 expect(Ok, status);
4468 hdc = CreateCompatibleDC(0);
4469 status = GdipCreateFromHDC(hdc, &graphics);
4471 status = GdipCreateFont(family, 20, FontStyleRegular, UnitPixel, &font);
4472 expect(Ok, status);
4474 margin_x = 20.0 / 6.0;
4475 margin_y = 20.0 / 8.0;
4477 set_rect_empty(&rect);
4478 set_rect_empty(&bounds);
4479 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4480 expect(Ok, status);
4481 expect(3, glyphs);
4482 expect(1, lines);
4483 expectf(0.0, bounds.X);
4484 expectf(0.0, bounds.Y);
4485 width = bounds.Width;
4486 height = bounds.Height;
4488 set_rect_empty(&rect);
4489 rect.Height = height / 2.0;
4490 set_rect_empty(&bounds);
4491 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4492 expect(Ok, status);
4493 expect(3, glyphs);
4494 expect(1, lines);
4495 expectf(0.0, bounds.X);
4496 expectf(0.0, bounds.Y);
4497 expectf(width, bounds.Width);
4498 todo_wine
4499 expectf(height / 2.0, bounds.Height);
4501 range.First = 0;
4502 range.Length = lstrlenW(string);
4503 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4504 expect(Ok, status);
4506 rect.X = 5.0;
4507 rect.Y = 5.0;
4508 rect.Width = 32000.0;
4509 rect.Height = 32000.0;
4510 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4511 expect(Ok, status);
4512 set_rect_empty(&bounds);
4513 status = GdipGetRegionBounds(region, graphics, &bounds);
4514 expect(Ok, status);
4515 expectf_(5.0 + margin_x, bounds.X, 1.0);
4516 expectf(5.0, bounds.Y);
4517 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4518 todo_wine
4519 expectf_(height - margin_y, bounds.Height, 1.0);
4521 width_rgn = bounds.Width;
4522 height_rgn = bounds.Height;
4524 range.First = 0;
4525 range.Length = 1;
4526 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4527 expect(Ok, status);
4529 set_rect_empty(&rect);
4530 rect.Width = 32000.0;
4531 rect.Height = 32000.0;
4532 status = GdipMeasureCharacterRanges(graphics, string, 1, font, &rect, format, 1, &region);
4533 expect(Ok, status);
4534 set_rect_empty(&bounds);
4535 status = GdipGetRegionBounds(region, graphics, &bounds);
4536 expect(Ok, status);
4537 expectf_(margin_x, bounds.X, 1.0);
4538 expectf(0.0, bounds.Y);
4539 ok(bounds.Width < width_rgn / 2.0, "width of 1 glyph is wrong\n");
4540 expectf(height_rgn, bounds.Height);
4541 width_1 = bounds.Width;
4543 range.First = 0;
4544 range.Length = lstrlenW(string);
4545 status = GdipSetStringFormatMeasurableCharacterRanges(format, 1, &range);
4546 expect(Ok, status);
4548 rect.X = 5.0;
4549 rect.Y = 5.0;
4550 rect.Width = 0.0;
4551 rect.Height = 0.0;
4552 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4553 expect(Ok, status);
4554 set_rect_empty(&bounds);
4555 status = GdipGetRegionBounds(region, graphics, &bounds);
4556 expect(Ok, status);
4557 expectf(0.0, bounds.X);
4558 expectf(0.0, bounds.Y);
4559 expectf(0.0, bounds.Width);
4560 expectf(0.0, bounds.Height);
4562 rect.X = 5.0;
4563 rect.Y = 5.0;
4564 rect.Width = width_rgn / 2.0;
4565 rect.Height = 32000.0;
4566 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4567 expect(Ok, status);
4568 set_rect_empty(&bounds);
4569 status = GdipGetRegionBounds(region, graphics, &bounds);
4570 expect(Ok, status);
4571 expectf_(5.0 + margin_x, bounds.X, 1.0);
4572 expectf(5.0, bounds.Y);
4573 expectf_(width_1, bounds.Width, 1.0);
4574 todo_wine
4575 expectf_(height - margin_y, bounds.Height, 1.0);
4577 status = GdipSetStringFormatFlags(format, StringFormatFlagsNoWrap | StringFormatFlagsNoClip);
4579 rect.X = 5.0;
4580 rect.Y = 5.0;
4581 rect.Width = 0.0;
4582 rect.Height = 0.0;
4583 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4584 expect(Ok, status);
4585 set_rect_empty(&bounds);
4586 status = GdipGetRegionBounds(region, graphics, &bounds);
4587 expect(Ok, status);
4588 expectf_(5.0 + margin_x, bounds.X, 1.0);
4589 expectf(5.0, bounds.Y);
4590 expectf(width_rgn, bounds.Width);
4591 expectf(height_rgn, bounds.Height);
4593 rect.X = 5.0;
4594 rect.Y = 5.0;
4595 rect.Width = width_rgn / 2.0;
4596 rect.Height = 32000.0;
4597 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4598 expect(Ok, status);
4599 set_rect_empty(&bounds);
4600 status = GdipGetRegionBounds(region, graphics, &bounds);
4601 expect(Ok, status);
4602 expectf_(5.0 + margin_x, bounds.X, 1.0);
4603 expectf(5.0, bounds.Y);
4604 expectf_(width_1, bounds.Width, 1.0);
4605 expectf(height_rgn, bounds.Height);
4607 set_rect_empty(&rect);
4608 rect.Height = height / 2.0;
4609 set_rect_empty(&bounds);
4610 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4611 expect(Ok, status);
4612 expect(3, glyphs);
4613 expect(1, lines);
4614 expectf(0.0, bounds.X);
4615 expectf(0.0, bounds.Y);
4616 expectf_(width, bounds.Width, 0.01);
4617 todo_wine
4618 expectf(height, bounds.Height);
4620 set_rect_empty(&rect);
4621 set_rect_empty(&bounds);
4622 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds, &glyphs, &lines);
4623 expect(Ok, status);
4624 expect(1, glyphs);
4625 expect(1, lines);
4626 expectf(0.0, bounds.X);
4627 expectf(0.0, bounds.Y);
4628 ok(bounds.Width < width / 2.0, "width of 1 glyph is wrong\n");
4629 expectf(height, bounds.Height);
4630 width_1 = bounds.Width;
4632 set_rect_empty(&rect);
4633 set_rect_empty(&bounds);
4634 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds, &glyphs, &lines);
4635 expect(Ok, status);
4636 expect(2, glyphs);
4637 expect(1, lines);
4638 expectf(0.0, bounds.X);
4639 expectf(0.0, bounds.Y);
4640 ok(bounds.Width < width, "width of 2 glyphs is wrong\n");
4641 ok(bounds.Width > width_1, "width of 2 glyphs is wrong\n");
4642 expectf(height, bounds.Height);
4643 width_2 = bounds.Width;
4645 set_rect_empty(&rect);
4646 rect.Width = width / 2.0;
4647 set_rect_empty(&bounds);
4648 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4649 expect(Ok, status);
4650 expect(1, glyphs);
4651 expect(1, lines);
4652 expectf(0.0, bounds.X);
4653 expectf(0.0, bounds.Y);
4654 expectf_(width_1, bounds.Width, 0.01);
4655 expectf(height, bounds.Height);
4657 set_rect_empty(&rect);
4658 rect.Height = height;
4659 rect.Width = width - 0.05;
4660 set_rect_empty(&bounds);
4661 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4662 expect(Ok, status);
4663 expect(2, glyphs);
4664 expect(1, lines);
4665 expectf(0.0, bounds.X);
4666 expectf(0.0, bounds.Y);
4667 expectf_(width_2, bounds.Width, 0.01);
4668 expectf(height, bounds.Height);
4670 set_rect_empty(&rect);
4671 rect.Height = height;
4672 rect.Width = width_2 - 0.05;
4673 set_rect_empty(&bounds);
4674 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4675 expect(Ok, status);
4676 expect(1, glyphs);
4677 expect(1, lines);
4678 expectf(0.0, bounds.X);
4679 expectf(0.0, bounds.Y);
4680 expectf_(width_1, bounds.Width, 0.01);
4681 expectf(height, bounds.Height);
4683 /* Default (Near) alignment */
4684 rect.X = 5.0;
4685 rect.Y = 5.0;
4686 rect.Width = width * 2.0;
4687 rect.Height = height * 2.0;
4688 set_rect_empty(&bounds);
4689 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4690 expect(Ok, status);
4691 expect(3, glyphs);
4692 expect(1, lines);
4693 expectf(5.0, bounds.X);
4694 expectf(5.0, bounds.Y);
4695 expectf_(width, bounds.Width, 0.01);
4696 expectf(height, bounds.Height);
4698 rect.X = 5.0;
4699 rect.Y = 5.0;
4700 rect.Width = 32000.0;
4701 rect.Height = 32000.0;
4702 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4703 expect(Ok, status);
4704 set_rect_empty(&bounds);
4705 status = GdipGetRegionBounds(region, graphics, &bounds);
4706 expect(Ok, status);
4707 expectf_(5.0 + margin_x, bounds.X, 1.0);
4708 expectf(5.0, bounds.Y);
4709 expectf_(width - margin_x*2.0, bounds.Width, 1.0);
4710 todo_wine
4711 expectf_(height - margin_y, bounds.Height, 1.0);
4713 width_rgn = bounds.Width;
4714 height_rgn = bounds.Height;
4716 /* Center alignment */
4717 GdipSetStringFormatAlign(format, StringAlignmentCenter);
4718 GdipSetStringFormatLineAlign(format, StringAlignmentCenter);
4720 rect.X = 5.0;
4721 rect.Y = 5.0;
4722 rect.Width = width * 2.0;
4723 rect.Height = height * 2.0;
4724 set_rect_empty(&bounds);
4725 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4726 expect(Ok, status);
4727 expect(3, glyphs);
4728 expect(1, lines);
4729 todo_wine
4730 expectf_(5.0 + width/2.0, bounds.X, 0.01);
4731 todo_wine
4732 expectf(5.0 + height/2.0, bounds.Y);
4733 expectf_(width, bounds.Width, 0.01);
4734 expectf(height, bounds.Height);
4736 rect.X = 5.0;
4737 rect.Y = 5.0;
4738 rect.Width = 0.0;
4739 rect.Height = 0.0;
4740 set_rect_empty(&bounds);
4741 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4742 expect(Ok, status);
4743 expect(3, glyphs);
4744 expect(1, lines);
4745 todo_wine
4746 expectf_(5.0 - width/2.0, bounds.X, 0.01);
4747 todo_wine
4748 expectf(5.0 - height/2.0, bounds.Y);
4749 expectf_(width, bounds.Width, 0.01);
4750 expectf(height, bounds.Height);
4752 rect.X = 5.0;
4753 rect.Y = 5.0;
4754 rect.Width = width_rgn * 2.0;
4755 rect.Height = height_rgn * 2.0;
4756 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4757 expect(Ok, status);
4758 set_rect_empty(&bounds);
4759 status = GdipGetRegionBounds(region, graphics, &bounds);
4760 expect(Ok, status);
4761 todo_wine
4762 expectf_(5.0 + width_rgn/2.0, bounds.X, 1.0);
4763 todo_wine
4764 expectf_(5.0 + height_rgn/2.0, bounds.Y, 1.0);
4765 expectf_(width_rgn, bounds.Width, 1.0);
4766 expectf_(height_rgn, bounds.Height, 1.0);
4768 rect.X = 5.0;
4769 rect.Y = 5.0;
4770 rect.Width = 0.0;
4771 rect.Height = 0.0;
4772 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4773 expect(Ok, status);
4774 set_rect_empty(&bounds);
4775 status = GdipGetRegionBounds(region, graphics, &bounds);
4776 expect(Ok, status);
4777 todo_wine
4778 expectf_(5.0 - width_rgn/2.0, bounds.X, 1.0);
4779 todo_wine
4780 expectf_(5.0 - height_rgn/2.0, bounds.Y, 1.0);
4781 expectf_(width_rgn, bounds.Width, 1.0);
4782 expectf_(height_rgn, bounds.Height, 1.0);
4784 /* Far alignment */
4785 GdipSetStringFormatAlign(format, StringAlignmentFar);
4786 GdipSetStringFormatLineAlign(format, StringAlignmentFar);
4788 rect.X = 5.0;
4789 rect.Y = 5.0;
4790 rect.Width = width * 2.0;
4791 rect.Height = height * 2.0;
4792 set_rect_empty(&bounds);
4793 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4794 expect(Ok, status);
4795 expect(3, glyphs);
4796 expect(1, lines);
4797 todo_wine
4798 expectf_(5.0 + width, bounds.X, 0.01);
4799 todo_wine
4800 expectf(5.0 + height, bounds.Y);
4801 expectf_(width, bounds.Width, 0.01);
4802 expectf(height, bounds.Height);
4804 rect.X = 5.0;
4805 rect.Y = 5.0;
4806 rect.Width = 0.0;
4807 rect.Height = 0.0;
4808 set_rect_empty(&bounds);
4809 status = GdipMeasureString(graphics, string, -1, font, &rect, format, &bounds, &glyphs, &lines);
4810 expect(Ok, status);
4811 expect(3, glyphs);
4812 expect(1, lines);
4813 todo_wine
4814 expectf_(5.0 - width, bounds.X, 0.01);
4815 todo_wine
4816 expectf(5.0 - height, bounds.Y);
4817 expectf_(width, bounds.Width, 0.01);
4818 expectf(height, bounds.Height);
4820 rect.X = 5.0;
4821 rect.Y = 5.0;
4822 rect.Width = width_rgn * 2.0;
4823 rect.Height = height_rgn * 2.0;
4824 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4825 expect(Ok, status);
4826 set_rect_empty(&bounds);
4827 status = GdipGetRegionBounds(region, graphics, &bounds);
4828 expect(Ok, status);
4829 todo_wine
4830 expectf_(5.0 + width_rgn, bounds.X, 2.0);
4831 todo_wine
4832 expectf_(5.0 + height_rgn, bounds.Y, 1.0);
4833 expectf_(width_rgn, bounds.Width, 1.0);
4834 expectf_(height_rgn, bounds.Height, 1.0);
4836 rect.X = 5.0;
4837 rect.Y = 5.0;
4838 rect.Width = 0.0;
4839 rect.Height = 0.0;
4840 status = GdipMeasureCharacterRanges(graphics, string, -1, font, &rect, format, 1, &region);
4841 expect(Ok, status);
4842 set_rect_empty(&bounds);
4843 status = GdipGetRegionBounds(region, graphics, &bounds);
4844 expect(Ok, status);
4845 todo_wine
4846 expectf_(5.0 - width_rgn, bounds.X, 2.0);
4847 todo_wine
4848 expectf_(5.0 - height_rgn, bounds.Y, 1.0);
4849 expectf_(width_rgn, bounds.Width, 1.0);
4850 expectf_(height_rgn, bounds.Height, 1.0);
4852 status = GdipDeleteFont(font);
4853 expect(Ok, status);
4855 status = GdipDeleteGraphics(graphics);
4856 expect(Ok, status);
4857 DeleteDC(hdc);
4859 GdipDeleteFontFamily(family);
4860 GdipDeleteRegion(region);
4861 GdipDeleteStringFormat(format);
4864 static void test_measured_extra_space(void)
4866 static const WCHAR tahomaW[] = { 'T','a','h','o','m','a',0 };
4867 static const WCHAR string[2] = { 'W','W' };
4868 GpStringFormat *format;
4869 HDC hdc;
4870 GpGraphics *graphics;
4871 GpFontFamily *family;
4872 GpFont *font;
4873 GpStatus status;
4874 GpUnit gfx_unit, font_unit;
4875 RectF bounds_1, bounds_2, rect;
4876 REAL margin, font_size, dpi;
4878 status = GdipCreateStringFormat(0, LANG_NEUTRAL, &format);
4879 expect(Ok, status);
4881 status = GdipCreateFontFamilyFromName(tahomaW, NULL, &family);
4882 expect(Ok, status);
4883 hdc = CreateCompatibleDC(0);
4884 status = GdipCreateFromHDC(hdc, &graphics);
4885 expect(Ok, status);
4887 status = GdipGetDpiX(graphics, &dpi);
4888 expect(Ok, status);
4890 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4891 /* UnitPixel as a font base unit is not tested because it differs in behaviour */
4892 for (font_unit = 3; font_unit <= 6; font_unit++)
4894 status = GdipCreateFont(family, 1234.0, FontStyleRegular, font_unit, &font);
4895 expect(Ok, status);
4897 status = GdipGetFontSize(font, &font_size);
4898 expect(Ok, status);
4899 font_size = units_to_pixels(font_size, font_unit, dpi);
4900 /*trace("font size/6 = %f pixels\n", font_size / 6.0);*/
4902 /* UnitPixel = 2, UnitPoint = 3, UnitInch = 4, UnitDocument = 5, UnitMillimeter = 6 */
4903 for (gfx_unit = 2; gfx_unit <= 6; gfx_unit++)
4905 status = GdipSetPageUnit(graphics, gfx_unit);
4906 expect(Ok, status);
4908 /* bounds.width of 1 glyph: [margin]+[width]+[margin] */
4909 set_rect_empty(&rect);
4910 set_rect_empty(&bounds_1);
4911 status = GdipMeasureString(graphics, string, 1, font, &rect, format, &bounds_1, NULL, NULL);
4912 expect(Ok, status);
4913 /* bounds.width of 2 identical glyphs: [margin]+[width]+[width]+[margin] */
4914 set_rect_empty(&rect);
4915 set_rect_empty(&bounds_2);
4916 status = GdipMeasureString(graphics, string, 2, font, &rect, format, &bounds_2, NULL, NULL);
4917 expect(Ok, status);
4919 /* margin = [bounds.width of 1] - [bounds.width of 2] / 2*/
4920 margin = units_to_pixels(bounds_1.Width - bounds_2.Width / 2.0, gfx_unit, dpi);
4921 /*trace("margin %f pixels\n", margin);*/
4922 expectf_(font_size / 6.0, margin, font_size / 100.0);
4925 GdipDeleteFont(font);
4928 GdipDeleteGraphics(graphics);
4929 DeleteDC(hdc);
4930 GdipDeleteFontFamily(family);
4931 GdipDeleteStringFormat(format);
4934 static void test_alpha_hdc(void)
4936 GpStatus status;
4937 HDC hdc, gp_hdc;
4938 HBITMAP hbm, old_hbm;
4939 GpGraphics *graphics;
4940 ULONG *bits;
4941 BITMAPINFO bmi;
4942 GpRectF bounds;
4943 COLORREF colorref;
4945 hdc = CreateCompatibleDC(0);
4946 ok(hdc != NULL, "CreateCompatibleDC failed\n");
4947 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
4948 bmi.bmiHeader.biHeight = 5;
4949 bmi.bmiHeader.biWidth = 5;
4950 bmi.bmiHeader.biBitCount = 32;
4951 bmi.bmiHeader.biPlanes = 1;
4952 bmi.bmiHeader.biCompression = BI_RGB;
4953 bmi.bmiHeader.biClrUsed = 0;
4955 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
4956 ok(hbm != NULL, "CreateDIBSection failed\n");
4958 old_hbm = SelectObject(hdc, hbm);
4960 status = GdipCreateFromHDC(hdc, &graphics);
4961 expect(Ok, status);
4963 status = GdipGetVisibleClipBounds(graphics, &bounds);
4964 expect(Ok, status);
4965 expectf(0.0, bounds.X);
4966 expectf(0.0, bounds.Y);
4967 expectf(5.0, bounds.Width);
4968 expectf(5.0, bounds.Height);
4970 bits[0] = 0xdeadbeef;
4972 status = GdipGraphicsClear(graphics, 0xffaaaaaa);
4973 expect(Ok, status);
4975 expect(0xffaaaaaa, bits[0]);
4977 bits[0] = 0xdeadbeef;
4979 status = GdipGetDC(graphics, &gp_hdc);
4980 expect(Ok, status);
4982 colorref = GetPixel(gp_hdc, 0, 4);
4983 expect(0xefbead, colorref);
4985 SetPixel(gp_hdc, 0, 4, 0xffffff);
4987 expect(0xffffff, bits[0]);
4989 status = GdipReleaseDC(graphics, gp_hdc);
4990 expect(Ok, status);
4992 SelectObject(hdc, old_hbm);
4994 bits[0] = 0xdeadbeef;
4996 status = GdipGraphicsClear(graphics, 0xffbbbbbb);
4997 expect(Ok, status);
4999 todo_wine expect(0xffbbbbbb, bits[0]);
5001 GdipDeleteGraphics(graphics);
5003 DeleteObject(hbm);
5004 DeleteDC(hdc);
5007 static void test_bitmapfromgraphics(void)
5009 GpStatus stat;
5010 GpGraphics *graphics = NULL;
5011 HDC hdc = GetDC( hwnd );
5012 GpBitmap *bitmap = NULL;
5013 PixelFormat format;
5014 REAL imageres, graphicsres;
5015 UINT width, height;
5017 stat = GdipCreateFromHDC(hdc, &graphics);
5018 expect(Ok, stat);
5020 stat = GdipCreateBitmapFromGraphics(12, 13, NULL, &bitmap);
5021 expect(InvalidParameter, stat);
5023 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, NULL);
5024 expect(InvalidParameter, stat);
5026 stat = GdipCreateBitmapFromGraphics(12, 13, graphics, &bitmap);
5027 expect(Ok, stat);
5029 stat = GdipGetImagePixelFormat((GpImage*)bitmap, &format);
5030 expect(Ok, stat);
5031 expect(PixelFormat32bppPARGB, format);
5033 stat = GdipGetDpiX(graphics, &graphicsres);
5034 expect(Ok, stat);
5036 stat = GdipGetImageHorizontalResolution((GpImage*)bitmap, &imageres);
5037 expect(Ok, stat);
5038 expectf(graphicsres, imageres);
5040 stat = GdipGetDpiY(graphics, &graphicsres);
5041 expect(Ok, stat);
5043 stat = GdipGetImageVerticalResolution((GpImage*)bitmap, &imageres);
5044 expect(Ok, stat);
5045 expectf(graphicsres, imageres);
5047 stat = GdipGetImageWidth((GpImage*)bitmap, &width);
5048 expect(Ok, stat);
5049 expect(12, width);
5051 stat = GdipGetImageHeight((GpImage*)bitmap, &height);
5052 expect(Ok, stat);
5053 expect(13, height);
5055 GdipDeleteGraphics(graphics);
5056 GdipDisposeImage((GpImage*)bitmap);
5059 static void test_clipping(void)
5061 HDC hdc;
5062 GpStatus status;
5063 GpGraphics *graphics;
5064 GpRegion *region, *region100x100;
5065 GpMatrix *matrix;
5066 GpRectF rect;
5067 GpPointF ptf[4];
5068 GpUnit unit;
5069 HRGN hrgn;
5070 int ret;
5071 RECT rc;
5073 hdc = CreateCompatibleDC(0);
5074 status = GdipCreateFromHDC(hdc, &graphics);
5075 expect(Ok, status);
5077 status = GdipGetPageUnit(graphics, &unit);
5078 expect(Ok, status);
5079 expect(UnitDisplay, unit);
5081 status = GdipCreateRegion(&region);
5082 expect(Ok, status);
5083 status = GdipSetEmpty(region);
5084 expect(Ok, status);
5086 status = GdipCreateRegion(&region100x100);
5087 expect(Ok, status);
5088 status = GdipSetEmpty(region100x100);
5089 expect(Ok, status);
5091 rect.X = rect.Y = 100.0;
5092 rect.Width = rect.Height = 100.0;
5093 status = GdipCombineRegionRect(region100x100, &rect, CombineModeUnion);
5094 expect(Ok, status);
5095 status = GdipSetClipRegion(graphics, region100x100, CombineModeReplace);
5096 expect(Ok, status);
5098 status = GdipGetClipBounds(graphics, &rect);
5099 expect(Ok, status);
5100 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5101 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5103 /* Clip region does not account for changes to gdi32 transform */
5104 SetViewportOrgEx(hdc, 10, 10, NULL);
5106 status = GdipGetClipBounds(graphics, &rect);
5107 expect(Ok, status);
5108 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5109 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5111 SetViewportOrgEx(hdc, 0, 0, NULL);
5113 status = GdipSetEmpty(region);
5114 expect(Ok, status);
5115 status = GdipGetClip(graphics, region);
5116 expect(Ok, status);
5117 status = GdipGetRegionBounds(region, graphics, &rect);
5118 expect(Ok, status);
5119 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5120 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5122 ptf[0].X = 100.0;
5123 ptf[0].Y = 100.0;
5124 ptf[1].X = 200.0;
5125 ptf[1].Y = 200.0;
5126 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5127 expect(Ok, status);
5128 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5129 "expected 100.0,100.0-200.0,200.0, got %f,%f-%f,%f\n", ptf[0].X, ptf[0].Y, ptf[1].X, ptf[1].Y);
5131 status = GdipCreateMatrix(&matrix);
5132 expect(Ok, status);
5133 status = GdipScaleMatrix(matrix, 2.0, 4.0, MatrixOrderAppend);
5134 expect(Ok, status);
5135 status = GdipTranslateMatrix(matrix, 10.0, 20.0, MatrixOrderAppend);
5136 expect(Ok, status);
5137 status = GdipSetWorldTransform(graphics, matrix);
5138 expect(Ok, status);
5140 status = GdipGetClipBounds(graphics, &rect);
5141 expect(Ok, status);
5142 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
5143 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5145 status = GdipSetEmpty(region);
5146 expect(Ok, status);
5147 status = GdipGetClip(graphics, region);
5148 expect(Ok, status);
5149 status = GdipGetRegionBounds(region, graphics, &rect);
5150 expect(Ok, status);
5151 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
5152 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5154 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5155 expect(Ok, status);
5156 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5157 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5159 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5160 expect(Ok, status);
5161 ret = GetRgnBox(hrgn, &rc);
5162 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5163 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
5164 "expected 45,20-95,45, got %s\n", wine_dbgstr_rect(&rc));
5165 DeleteObject(hrgn);
5167 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5168 expect(Ok, status);
5169 ret = GetRgnBox(hrgn, &rc);
5170 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5171 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5172 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5173 DeleteObject(hrgn);
5175 ptf[0].X = 100.0;
5176 ptf[0].Y = 100.0;
5177 ptf[1].X = 200.0;
5178 ptf[1].Y = 200.0;
5179 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5180 expect(Ok, status);
5181 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
5182 "expected 45.0,20.0-95.0,45.0, got %f,%f-%f,%f\n", ptf[0].X, ptf[0].Y, ptf[1].X, ptf[1].Y);
5184 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5185 expect(Ok, status);
5186 ret = GetRgnBox(hrgn, &rc);
5187 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5188 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5189 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5190 DeleteObject(hrgn);
5192 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5193 expect(Ok, status);
5194 ret = GetRgnBox(hrgn, &rc);
5195 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5196 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5197 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5198 DeleteObject(hrgn);
5200 ptf[0].X = 210.0;
5201 ptf[0].Y = 420.0;
5202 ptf[1].X = 410.0;
5203 ptf[1].Y = 820.0;
5204 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5205 expect(Ok, status);
5206 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5207 "expected 100.0,100.0-200.0,200.0, got %f,%f-%f,%f\n", ptf[0].X, ptf[0].Y, ptf[1].X, ptf[1].Y);
5209 status = GdipSetPageScale(graphics, 2.0);
5210 expect(Ok, status);
5212 status = GdipGetClipBounds(graphics, &rect);
5213 expect(Ok, status);
5214 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
5215 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5217 status = GdipSetEmpty(region);
5218 expect(Ok, status);
5219 status = GdipGetClip(graphics, region);
5220 expect(Ok, status);
5221 status = GdipGetRegionBounds(region, graphics, &rect);
5222 expect(Ok, status);
5223 ok(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0,
5224 "expected 45.0,20.0-50.0,25.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5226 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5227 expect(Ok, status);
5228 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5229 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5231 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5232 expect(Ok, status);
5233 ret = GetRgnBox(hrgn, &rc);
5234 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5235 ok(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45,
5236 "expected 45,20-95,45, got %s\n", wine_dbgstr_rect(&rc));
5237 DeleteObject(hrgn);
5239 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5240 expect(Ok, status);
5241 ret = GetRgnBox(hrgn, &rc);
5242 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5243 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5244 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5245 DeleteObject(hrgn);
5247 ptf[0].X = 100.0;
5248 ptf[0].Y = 100.0;
5249 ptf[1].X = 200.0;
5250 ptf[1].Y = 200.0;
5251 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5252 expect(Ok, status);
5253 ok(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0,
5254 "expected 45.0,20.0-95.0,45.0, got %f,%f-%f,%f\n", ptf[0].X, ptf[0].Y, ptf[1].X, ptf[1].Y);
5256 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5257 expect(Ok, status);
5258 ret = GetRgnBox(hrgn, &rc);
5259 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5260 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5261 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5262 DeleteObject(hrgn);
5264 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5265 expect(Ok, status);
5266 ret = GetRgnBox(hrgn, &rc);
5267 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5268 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5269 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5270 DeleteObject(hrgn);
5272 ptf[0].X = 210.0;
5273 ptf[0].Y = 420.0;
5274 ptf[1].X = 410.0;
5275 ptf[1].Y = 820.0;
5276 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5277 expect(Ok, status);
5278 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5279 "expected 100.0,100.0-200.0,200.0, got %f,%f-%f,%f\n", ptf[0].X, ptf[0].Y, ptf[1].X, ptf[1].Y);
5281 GdipSetPageUnit(graphics, UnitPoint);
5282 expect(Ok, status);
5284 status = GdipGetClipBounds(graphics, &rect);
5285 expect(Ok, status);
5286 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
5287 /* rounding under Wine is slightly different */
5288 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
5289 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
5290 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5292 status = GdipSetEmpty(region);
5293 expect(Ok, status);
5294 status = GdipGetClip(graphics, region);
5295 expect(Ok, status);
5296 status = GdipGetRegionBounds(region, graphics, &rect);
5297 expect(Ok, status);
5298 ok((rect.X == 13.75 && rect.Y == 4.375 && rect.Width == 18.75 && rect.Height == 9.375) ||
5299 /* rounding under Wine is slightly different */
5300 (rect.X == 14.0 && rect.Y == 4.0 && rect.Width == 19.0 && rect.Height == 10.0) /* Wine */ ||
5301 broken(rect.X == 45.0 && rect.Y == 20.0 && rect.Width == 50.0 && rect.Height == 25.0) /* before Win7 */,
5302 "expected 13.75,4.375-18.75,9.375, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5304 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5305 expect(Ok, status);
5306 ok(rect.X == 100.0 && rect.Y == 100.0 && rect.Width == 100.0 && rect.Height == 100.0,
5307 "expected 100.0,100.0-100.0,100.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5309 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5310 expect(Ok, status);
5311 ret = GetRgnBox(hrgn, &rc);
5312 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5313 ok((rc.left == 14 && rc.top == 5 && rc.right == 33 && rc.bottom == 14) ||
5314 /* rounding under Wine is slightly different */
5315 (rc.left == 14 && rc.top == 4 && rc.right == 33 && rc.bottom == 14) /* Wine */ ||
5316 broken(rc.left == 45 && rc.top == 20 && rc.right == 95 && rc.bottom == 45) /* before Win7 */,
5317 "expected 14,5-33,14, got %s\n", wine_dbgstr_rect(&rc));
5318 DeleteObject(hrgn);
5320 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5321 expect(Ok, status);
5322 ret = GetRgnBox(hrgn, &rc);
5323 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5324 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5325 broken(rc.left == 267 && rc.top == 267 && rc.right == 534 && rc.bottom == 534) /* before Win7 */,
5326 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5327 DeleteObject(hrgn);
5329 ptf[0].X = 100.0;
5330 ptf[0].Y = 100.0;
5331 ptf[1].X = 200.0;
5332 ptf[1].Y = 200.0;
5333 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5334 expect(Ok, status);
5335 ok((ptf[0].X == 13.75 && ptf[0].Y == 4.375 && ptf[1].X == 32.5 && ptf[1].Y == 13.75) ||
5336 broken(ptf[0].X == 45.0 && ptf[0].Y == 20.0 && ptf[1].X == 95.0 && ptf[1].Y == 45.0) /* before Win7 */,
5337 "expected 13.75,4.375-32.5,13.75, got %f,%f-%f,%f\n", ptf[0].X, ptf[0].Y, ptf[1].X, ptf[1].Y);
5339 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5340 expect(Ok, status);
5341 ret = GetRgnBox(hrgn, &rc);
5342 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5343 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5344 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5345 DeleteObject(hrgn);
5347 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5348 expect(Ok, status);
5349 ret = GetRgnBox(hrgn, &rc);
5350 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5351 ok((rc.left == 560 && rc.top == 1120 && rc.right == 1094 && rc.bottom == 2187) ||
5352 /* rounding under Wine is slightly different */
5353 (rc.left == 560 && rc.top == 1120 && rc.right == 1093 && rc.bottom == 2187) /* Wine */,
5354 "expected 560,1120-1094,2187, got %s\n", wine_dbgstr_rect(&rc));
5355 DeleteObject(hrgn);
5357 ptf[0].X = 560.0;
5358 ptf[0].Y = 1120.0;
5359 ptf[1].X = 1094.0;
5360 ptf[1].Y = 2187.0;
5361 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5362 expect(Ok, status);
5363 if (fabs(ptf[0].X - 100.0) < 0.001)
5365 expectf(100.0, ptf[0].X);
5366 expectf(100.0, ptf[0].Y);
5367 expectf(200.125, ptf[1].X);
5368 expectf(200.03125, ptf[1].Y);
5370 else /* before Win7 */
5372 ok(broken(fabs(ptf[0].X - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].X);
5373 ok(broken(fabs(ptf[0].Y - 275.0) < 0.001), "expected 275.0, got %f\n", ptf[0].Y);
5374 ok(broken(fabs(ptf[1].X - 542.0) < 0.001), "expected 542.0, got %f\n", ptf[1].X);
5375 ok(broken(fabs(ptf[1].Y - 541.75) < 0.001), "expected 541.75, got %f\n", ptf[1].Y);
5378 status = GdipTransformRegion(region100x100, matrix);
5379 expect(Ok, status);
5381 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5382 expect(Ok, status);
5383 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5384 "expected 210.0,420.0-200.0,400.0, got %.2f,%.2f-%.2f,%.2f\n", rect.X, rect.Y, rect.Width, rect.Height);
5386 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5387 expect(Ok, status);
5388 ret = GetRgnBox(hrgn, &rc);
5389 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5390 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5391 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5392 DeleteObject(hrgn);
5394 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5395 expect(Ok, status);
5396 ret = GetRgnBox(hrgn, &rc);
5397 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5398 ok((rc.left == 1147 && rc.top == 4534 && rc.right == 2214 && rc.bottom == 8800) ||
5399 /* rounding under Wine is slightly different */
5400 (rc.left == 1147 && rc.top == 4533 && rc.right == 2213 && rc.bottom == 8800) /* Wine */,
5401 "expected 1147,4534-2214,8800, got %s\n", wine_dbgstr_rect(&rc));
5402 DeleteObject(hrgn);
5404 ptf[0].X = 1147.0;
5405 ptf[0].Y = 4534.0;
5406 ptf[1].X = 2214.0;
5407 ptf[1].Y = 8800.0;
5408 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5409 expect(Ok, status);
5410 if (fabs(ptf[0].X - 210.0625) < 0.001)
5412 expectf(210.0625, ptf[0].X);
5413 expectf(420.0625, ptf[0].Y);
5414 expectf(410.125, ptf[1].X);
5415 expectf(820.0, ptf[1].Y);
5417 else /* before Win7 */
5419 ok(broken(fabs(ptf[0].X - 568.5) < 0.001), "expected 568.5, got %f\n", ptf[0].X);
5420 ok(broken(fabs(ptf[0].Y - 1128.5) < 0.001), "expected 1128.5, got %f\n", ptf[0].Y);
5421 ok(broken(fabs(ptf[1].X - 1102.0) < 0.001), "expected 1102.0, got %f\n", ptf[1].X);
5422 ok(broken(fabs(ptf[1].Y - 2195.0) < 0.001), "expected 2195.0, got %f\n", ptf[1].Y);
5425 status = GdipRotateMatrix(matrix, 30.0, MatrixOrderAppend);
5426 expect(Ok, status);
5427 status = GdipSetWorldTransform(graphics, matrix);
5428 expect(Ok, status);
5430 status = GdipGetClipBounds(graphics, &rect);
5431 expect(Ok, status);
5432 expectf_(20.612978, rect.X, 1.0);
5433 expectf_(-6.256012, rect.Y, 1.5);
5434 expectf_(25.612978, rect.Width, 1.0);
5435 expectf_(12.806489, rect.Height, 1.0);
5437 status = GdipSetEmpty(region);
5438 expect(Ok, status);
5439 status = GdipGetClip(graphics, region);
5440 expect(Ok, status);
5441 status = GdipGetRegionBounds(region, graphics, &rect);
5442 expect(Ok, status);
5443 /* rounding under Wine is slightly different */
5444 expectf_(20.612978, rect.X, 1.0);
5445 expectf_(-6.256012, rect.Y, 1.5);
5446 expectf_(25.612978, rect.Width, 1.0);
5447 expectf_(12.806489, rect.Height, 1.0);
5449 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5450 expect(Ok, status);
5451 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5452 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5454 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5455 expect(Ok, status);
5456 ret = GetRgnBox(hrgn, &rc);
5457 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5458 ok((rc.left == 22 && rc.top == -6 && rc.right == 46 && rc.bottom == 7) ||
5459 /* rounding under Wine is slightly different */
5460 (rc.left == 21 && rc.top == -5 && rc.right == 46 && rc.bottom == 7) /* Wine */,
5461 "expected (22,-6)-(46,7), got %s\n", wine_dbgstr_rect(&rc));
5462 DeleteObject(hrgn);
5464 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5465 expect(Ok, status);
5466 ret = GetRgnBox(hrgn, &rc);
5467 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5468 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5469 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5470 DeleteObject(hrgn);
5472 ptf[0].X = 100.0;
5473 ptf[0].Y = 100.0;
5474 ptf[1].X = 200.0;
5475 ptf[1].Y = 200.0;
5476 ptf[2].X = 200.0;
5477 ptf[2].Y = 100.0;
5478 ptf[3].X = 100.0;
5479 ptf[3].Y = 200.0;
5480 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5481 expect(Ok, status);
5482 expectf(20.612978, ptf[0].X);
5483 expectf(-1.568512, ptf[0].Y);
5484 expectf(46.225956, ptf[1].X);
5485 expectf(1.862977, ptf[1].Y);
5486 expectf(36.850956, ptf[2].X);
5487 expectf(-6.256012, ptf[2].Y);
5488 expectf(29.987980, ptf[3].X);
5489 expectf(6.550478, ptf[3].Y);
5491 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5492 expect(Ok, status);
5493 ret = GetRgnBox(hrgn, &rc);
5494 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5495 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5496 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5497 DeleteObject(hrgn);
5499 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5500 expect(Ok, status);
5501 ret = GetRgnBox(hrgn, &rc);
5502 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5503 ok((rc.left == -3406 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) ||
5504 /* rounding under Wine is slightly different */
5505 (rc.left == -3407 && rc.top == 4500 && rc.right == -350 && rc.bottom == 8728) /* Wine */,
5506 "expected (-3406,4500)-(-350,8728), got %s\n", wine_dbgstr_rect(&rc));
5507 DeleteObject(hrgn);
5509 ptf[0].X = -3406.0;
5510 ptf[0].Y = 4500.0;
5511 ptf[1].X = -350.0;
5512 ptf[1].Y = 8728.0;
5513 ptf[2].X = -350.0;
5514 ptf[2].Y = 4500.0;
5515 ptf[3].X = -3406.0;
5516 ptf[3].Y = 8728.0;
5517 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5518 expect(Ok, status);
5519 expectf(-136.190491, ptf[0].X);
5520 expectf(520.010742, ptf[0].Y);
5521 expectf(756.417175, ptf[1].X);
5522 expectf(720.031616, ptf[1].Y);
5523 expectf(360.042114, ptf[2].X);
5524 expectf(376.760742, ptf[2].Y);
5525 expectf(260.184570, ptf[3].X);
5526 expectf(863.281616, ptf[3].Y);
5528 status = GdipRotateMatrix(matrix, -90.0, MatrixOrderAppend);
5529 expect(Ok, status);
5530 status = GdipSetWorldTransform(graphics, matrix);
5531 expect(Ok, status);
5533 status = GdipGetClipBounds(graphics, &rect);
5534 expect(Ok, status);
5535 expectf_(-28.100956, rect.X, 1.0);
5536 expectf_(7.806488, rect.Y, 1.5);
5537 expectf_(25.612978, rect.Width, 1.0);
5538 expectf_(12.806489, rect.Height, 1.0);
5540 status = GdipSetEmpty(region);
5541 expect(Ok, status);
5542 status = GdipGetClip(graphics, region);
5543 expect(Ok, status);
5544 status = GdipGetRegionBounds(region, graphics, &rect);
5545 expect(Ok, status);
5546 /* rounding under Wine is slightly different */
5547 expectf_(-28.100956, rect.X, 1.0);
5548 expectf_(7.806488, rect.Y, 1.5);
5549 expectf_(25.612978, rect.Width, 1.0);
5550 expectf_(12.806489, rect.Height, 1.0);
5552 status = GdipGetRegionBounds(region100x100, graphics, &rect);
5553 expect(Ok, status);
5554 ok(rect.X == 210.0 && rect.Y == 420.0 && rect.Width == 200.0 && rect.Height == 400.0,
5555 "expected 210.0,420.0-200.0,400.0, got %f,%f-%f,%f\n", rect.X, rect.Y, rect.Width, rect.Height);
5557 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5558 expect(Ok, status);
5559 ret = GetRgnBox(hrgn, &rc);
5560 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5561 ok((rc.left == -27 && rc.top == 8 && rc.right == -2 && rc.bottom == 21) ||
5562 /* rounding under Wine is slightly different */
5563 (rc.left == -28 && rc.top == 9 && rc.right == -2 && rc.bottom == 21) /* Wine */,
5564 "expected (-27,8)-(-2,21), got %s\n", wine_dbgstr_rect(&rc));
5565 DeleteObject(hrgn);
5567 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5568 expect(Ok, status);
5569 ret = GetRgnBox(hrgn, &rc);
5570 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5571 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5572 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5573 DeleteObject(hrgn);
5575 ptf[0].X = 100.0;
5576 ptf[0].Y = 100.0;
5577 ptf[1].X = 200.0;
5578 ptf[1].Y = 200.0;
5579 ptf[2].X = 200.0;
5580 ptf[2].Y = 100.0;
5581 ptf[3].X = 100.0;
5582 ptf[3].Y = 200.0;
5583 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5584 expect(Ok, status);
5585 expectf(-11.862979, ptf[0].X);
5586 expectf(7.806488, ptf[0].Y);
5587 expectf(-18.725958, ptf[1].X);
5588 expectf(20.612976, ptf[1].Y);
5589 expectf(-2.487981, ptf[2].X);
5590 expectf(15.925477, ptf[2].Y);
5591 expectf(-28.100956, ptf[3].X);
5592 expectf(12.493987, ptf[3].Y);
5594 status = GdipGetRegionHRgn(region100x100, NULL, &hrgn);
5595 expect(Ok, status);
5596 ret = GetRgnBox(hrgn, &rc);
5597 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5598 ok(rc.left == 210 && rc.top == 420 && rc.right == 410 && rc.bottom == 820,
5599 "expected 210,420-410,820, got %s\n", wine_dbgstr_rect(&rc));
5600 DeleteObject(hrgn);
5602 status = GdipGetRegionHRgn(region100x100, graphics, &hrgn);
5603 expect(Ok, status);
5604 ret = GetRgnBox(hrgn, &rc);
5605 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5606 ok((rc.left == 4500 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) ||
5607 /* rounding under Wine is slightly different */
5608 (rc.left == 4499 && rc.top == 351 && rc.right == 8728 && rc.bottom == 3407) /* Wine */,
5609 "expected (4500,351)-(8728,3407), got %s\n", wine_dbgstr_rect(&rc));
5610 DeleteObject(hrgn);
5612 ptf[0].X = -3406.0;
5613 ptf[0].Y = 4500.0;
5614 ptf[1].X = -350.0;
5615 ptf[1].Y = 8728.0;
5616 ptf[2].X = -350.0;
5617 ptf[2].Y = 4500.0;
5618 ptf[3].X = -3406.0;
5619 ptf[3].Y = 8728.0;
5620 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5621 expect(Ok, status);
5622 expectf(-1055.021484, ptf[0].X);
5623 expectf(-70.595329, ptf[0].Y);
5624 expectf(-1455.063232, ptf[1].X);
5625 expectf(375.708435, ptf[1].Y);
5626 expectf(-768.521484, ptf[2].X);
5627 expectf(177.520981, ptf[2].Y);
5628 expectf(-1741.563110, ptf[3].X);
5629 expectf(127.592125, ptf[3].Y);
5631 GdipDeleteMatrix(matrix);
5632 GdipDeleteRegion(region);
5633 GdipDeleteRegion(region100x100);
5634 GdipDeleteGraphics(graphics);
5635 DeleteDC(hdc);
5638 static void test_clipping_2(void)
5641 HDC hdc;
5642 GpStatus status;
5643 GpGraphics *graphics;
5644 GpRegion *region;
5645 GpMatrix *matrix;
5646 GpRectF rect;
5647 GpPointF ptf[4];
5648 GpUnit unit;
5649 HRGN hrgn;
5650 int ret;
5651 RECT rc;
5653 hdc = CreateCompatibleDC(0);
5654 status = GdipCreateFromHDC(hdc, &graphics);
5655 expect(Ok, status);
5657 status = GdipGetPageUnit(graphics, &unit);
5658 expect(Ok, status);
5659 expect(UnitDisplay, unit);
5661 GdipSetPageUnit(graphics, UnitInch);
5663 status = GdipCreateRegion(&region);
5664 expect(Ok, status);
5665 status = GdipSetEmpty(region);
5666 expect(Ok, status);
5667 rect.X = rect.Y = 100.0;
5668 rect.Width = rect.Height = 100.0;
5669 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5670 expect(Ok, status);
5671 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5672 expect(Ok, status);
5674 status = GdipGetClip(graphics, region);
5675 expect(Ok, status);
5676 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5677 expect(Ok, status);
5678 ret = GetRgnBox(hrgn, &rc);
5679 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5680 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5681 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5682 DeleteObject(hrgn);
5683 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5684 expect(Ok, status);
5685 ret = GetRgnBox(hrgn, &rc);
5686 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5687 ok(rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200,
5688 "expected 9600,9600-19200,19200, got %s\n", wine_dbgstr_rect(&rc));
5689 DeleteObject(hrgn);
5691 ptf[0].X = 9600.0;
5692 ptf[0].Y = 9600.0;
5693 ptf[1].X = 19200.0;
5694 ptf[1].Y = 19200.0;
5695 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5696 expect(Ok, status);
5697 expectf(100.0, ptf[0].X);
5698 expectf(100.0, ptf[0].Y);
5699 expectf(200.0, ptf[1].X);
5700 expectf(200.0, ptf[1].X);
5702 GdipSetPageUnit(graphics, UnitPoint);
5704 status = GdipGetClip(graphics, region);
5705 expect(Ok, status);
5706 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5707 expect(Ok, status);
5708 ret = GetRgnBox(hrgn, &rc);
5709 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5710 ok((rc.left == 7200 && rc.top == 7200 && rc.right == 14400 && rc.bottom == 14400) ||
5711 broken(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) /* before Win7 */,
5712 "expected 7200,7200-14400,14400, got %s\n", wine_dbgstr_rect(&rc));
5713 DeleteObject(hrgn);
5714 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5715 expect(Ok, status);
5716 ret = GetRgnBox(hrgn, &rc);
5717 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5718 ok((rc.left == 9600 && rc.top == 9600 && rc.right == 19200 && rc.bottom == 19200) ||
5719 broken(rc.left == 134 && rc.top == 134 && rc.right == 267 && rc.bottom == 267) /* before Win7 */,
5720 "expected 9600,9600-19200,19200, got %s\n", wine_dbgstr_rect(&rc));
5721 DeleteObject(hrgn);
5723 ptf[0].X = 9600.0;
5724 ptf[0].Y = 9600.0;
5725 ptf[1].X = 19200.0;
5726 ptf[1].Y = 19200.0;
5727 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5728 expect(Ok, status);
5729 if (fabs(ptf[0].X - 7200.0) < 0.001)
5730 ok(ptf[0].X == 7200.0 && ptf[0].Y == 7200.0 && ptf[1].X == 14400.0 && ptf[1].Y == 14400.0,
5731 "expected 7200.0,7200.0-14400.0,14400.0, got %f,%f-%f,%f\n", ptf[0].X, ptf[0].Y, ptf[1].X, ptf[1].Y);
5732 else /* before Win7 */
5734 ok(broken(fabs(ptf[0].X - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].X);
5735 ok(broken(fabs(ptf[0].Y - 100.0) < 0.001), "expected 100.0, got %f\n", ptf[0].Y);
5736 ok(broken(fabs(ptf[1].X - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].X);
5737 ok(broken(fabs(ptf[1].Y - 200.0) < 0.001), "expected 200.0, got %f\n", ptf[1].Y);
5740 GdipDeleteRegion(region);
5742 GdipSetPageUnit(graphics, UnitPixel);
5744 status = GdipCreateRegion(&region);
5745 expect(Ok, status);
5746 status = GdipSetEmpty(region);
5747 expect(Ok, status);
5748 rect.X = rect.Y = 100.0;
5749 rect.Width = rect.Height = 100.0;
5750 status = GdipCombineRegionRect(region, &rect, CombineModeUnion);
5751 expect(Ok, status);
5752 status = GdipSetClipRegion(graphics, region, CombineModeReplace);
5753 expect(Ok, status);
5755 status = GdipGetClip(graphics, region);
5756 expect(Ok, status);
5757 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5758 expect(Ok, status);
5759 ret = GetRgnBox(hrgn, &rc);
5760 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5761 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5762 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5763 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5764 DeleteObject(hrgn);
5765 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5766 expect(Ok, status);
5767 ret = GetRgnBox(hrgn, &rc);
5768 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5769 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5770 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5771 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5772 DeleteObject(hrgn);
5774 ptf[0].X = 100.0;
5775 ptf[0].Y = 100.0;
5776 ptf[1].X = 200.0;
5777 ptf[1].Y = 200.0;
5778 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5779 expect(Ok, status);
5780 if (fabs(ptf[0].X - 100.0) < 0.001)
5781 ok(ptf[0].X == 100.0 && ptf[0].Y == 100.0 && ptf[1].X == 200.0 && ptf[1].Y == 200.0,
5782 "expected 100.0,100.0-200.0,200.0, got %f,%f-%f,%f\n", ptf[0].X, ptf[0].Y, ptf[1].X, ptf[1].Y);
5783 else /* before Win7 */
5785 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5786 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5787 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5788 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5791 GdipSetPageUnit(graphics, UnitPoint);
5793 status = GdipGetClip(graphics, region);
5794 expect(Ok, status);
5795 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5796 expect(Ok, status);
5797 ret = GetRgnBox(hrgn, &rc);
5798 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5799 ok((rc.left == 75 && rc.top == 75 && rc.right == 150 && rc.bottom == 150) ||
5800 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5801 "expected 75,75-150,150, got %s\n", wine_dbgstr_rect(&rc));
5802 DeleteObject(hrgn);
5803 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5804 expect(Ok, status);
5805 ret = GetRgnBox(hrgn, &rc);
5806 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5807 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5808 broken(rc.left == 2 && rc.top == 2 && rc.right == 3 && rc.bottom == 3) /* before Win7 */,
5809 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5810 DeleteObject(hrgn);
5812 ptf[0].X = 100.0;
5813 ptf[0].Y = 100.0;
5814 ptf[1].X = 200.0;
5815 ptf[1].Y = 200.0;
5816 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5817 expect(Ok, status);
5818 if (fabs(ptf[0].X - 75.0) < 0.001)
5819 ok(ptf[0].X == 75.0 && ptf[0].Y == 75.0 && ptf[1].X == 150.0 && ptf[1].Y == 150.0,
5820 "expected 75.0,75.0-150.0,150.0, got %f,%f-%f,%f\n", ptf[0].X, ptf[0].Y, ptf[1].X, ptf[1].Y);
5821 else /* before Win7 */
5823 ok(broken(fabs(ptf[0].X - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].X);
5824 ok(broken(fabs(ptf[0].Y - 1.041667) < 0.001), "expected 1.041667, got %f\n", ptf[0].Y);
5825 ok(broken(fabs(ptf[1].X - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].X);
5826 ok(broken(fabs(ptf[1].Y - 2.083333) < 0.001), "expected 2.083333, got %f\n", ptf[1].Y);
5829 status = GdipCreateMatrix(&matrix);
5830 expect(Ok, status);
5831 status = GdipTranslateMatrix(matrix, 10.0, 10.0, MatrixOrderAppend);
5832 expect(Ok, status);
5833 status = GdipSetWorldTransform(graphics, matrix);
5834 expect(Ok, status);
5835 GdipDeleteMatrix(matrix);
5837 status = GdipGetClip(graphics, region);
5838 expect(Ok, status);
5839 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5840 expect(Ok, status);
5841 ret = GetRgnBox(hrgn, &rc);
5842 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5843 ok(rc.left == 65 && rc.top == 65 && rc.right == 140 && rc.bottom == 140,
5844 "expected 65,65-140,140, got %s\n", wine_dbgstr_rect(&rc));
5845 DeleteObject(hrgn);
5846 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5847 expect(Ok, status);
5848 ret = GetRgnBox(hrgn, &rc);
5849 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5850 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5851 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5852 DeleteObject(hrgn);
5854 ptf[0].X = 100.0;
5855 ptf[0].Y = 100.0;
5856 ptf[1].X = 200.0;
5857 ptf[1].Y = 200.0;
5858 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5859 expect(Ok, status);
5860 expectf(65.0, ptf[0].X);
5861 expectf(65.0, ptf[0].Y);
5862 expectf(140.0, ptf[1].X);
5863 expectf(140.0, ptf[1].X);
5865 status = GdipCreateMatrix(&matrix);
5866 expect(Ok, status);
5867 status = GdipScaleMatrix(matrix, 0.25, 0.5, MatrixOrderAppend);
5868 expect(Ok, status);
5869 status = GdipSetWorldTransform(graphics, matrix);
5870 expect(Ok, status);
5871 GdipDeleteMatrix(matrix);
5873 status = GdipGetClip(graphics, region);
5874 expect(Ok, status);
5875 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5876 expect(Ok, status);
5877 ret = GetRgnBox(hrgn, &rc);
5878 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5879 ok(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300,
5880 "expected 300,150-600,300, got %s\n", wine_dbgstr_rect(&rc));
5881 DeleteObject(hrgn);
5882 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5883 expect(Ok, status);
5884 ret = GetRgnBox(hrgn, &rc);
5885 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5886 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5887 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5888 DeleteObject(hrgn);
5890 ptf[0].X = 100.0;
5891 ptf[0].Y = 100.0;
5892 ptf[1].X = 200.0;
5893 ptf[1].Y = 200.0;
5894 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5895 expect(Ok, status);
5896 expectf(300.0, ptf[0].X);
5897 expectf(150.0, ptf[0].Y);
5898 expectf(600.0, ptf[1].X);
5899 expectf(300.0, ptf[1].Y);
5901 status = GdipSetPageScale(graphics, 2.0);
5902 expect(Ok, status);
5904 status = GdipGetClip(graphics, region);
5905 expect(Ok, status);
5906 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5907 expect(Ok, status);
5908 ret = GetRgnBox(hrgn, &rc);
5909 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5910 ok((rc.left == 150 && rc.top == 75 && rc.right == 300 && rc.bottom == 150) ||
5911 broken(rc.left == 300 && rc.top == 150 && rc.right == 600 && rc.bottom == 300) /* before Win7 */,
5912 "expected 150,75-300,150, got %s\n", wine_dbgstr_rect(&rc));
5913 DeleteObject(hrgn);
5914 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5915 expect(Ok, status);
5916 ret = GetRgnBox(hrgn, &rc);
5917 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5918 ok((rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200) ||
5919 broken(rc.left == 200 && rc.top == 200 && rc.right == 400 && rc.bottom == 400) /* before Win7 */,
5920 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5921 DeleteObject(hrgn);
5923 ptf[0].X = 100.0;
5924 ptf[0].Y = 100.0;
5925 ptf[1].X = 200.0;
5926 ptf[1].Y = 200.0;
5927 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 2);
5928 expect(Ok, status);
5929 if (fabs(ptf[0].X - 150.0) < 0.001)
5931 expectf(150.0, ptf[0].X);
5932 expectf(75.0, ptf[0].Y);
5933 expectf(300.0, ptf[1].X);
5934 expectf(150.0, ptf[1].Y);
5936 else /* before Win7 */
5938 ok(broken(fabs(ptf[0].X - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[0].X);
5939 ok(broken(fabs(ptf[0].Y - 150.0) < 0.001), "expected 150.0, got %f\n", ptf[0].Y);
5940 ok(broken(fabs(ptf[1].X - 600.0) < 0.001), "expected 600.0, got %f\n", ptf[1].X);
5941 ok(broken(fabs(ptf[1].Y - 300.0) < 0.001), "expected 300.0, got %f\n", ptf[1].Y);
5944 status = GdipCreateMatrix(&matrix);
5945 expect(Ok, status);
5946 status = GdipRotateMatrix(matrix, 45.0, MatrixOrderAppend);
5947 expect(Ok, status);
5948 status = GdipSetWorldTransform(graphics, matrix);
5949 expect(Ok, status);
5950 GdipDeleteMatrix(matrix);
5952 status = GdipGetClip(graphics, region);
5953 expect(Ok, status);
5954 status = GdipGetRegionHRgn(region, NULL, &hrgn);
5955 expect(Ok, status);
5956 ret = GetRgnBox(hrgn, &rc);
5957 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
5958 ok((rc.left == 54 && rc.top == -26 && rc.right == 107 && rc.bottom == 27) ||
5959 /* rounding under Wine is slightly different */
5960 (rc.left == 53 && rc.top == -26 && rc.right == 106 && rc.bottom == 27) /* Wine */,
5961 "expected 54,-26-107,27, got %s\n", wine_dbgstr_rect(&rc));
5962 DeleteObject(hrgn);
5963 status = GdipGetRegionHRgn(region, graphics, &hrgn);
5964 expect(Ok, status);
5965 ret = GetRgnBox(hrgn, &rc);
5966 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
5967 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
5968 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
5969 DeleteObject(hrgn);
5971 ptf[0].X = 100.0;
5972 ptf[0].Y = 100.0;
5973 ptf[1].X = 200.0;
5974 ptf[1].Y = 200.0;
5975 ptf[2].X = 200.0;
5976 ptf[2].Y = 100.0;
5977 ptf[3].X = 100.0;
5978 ptf[3].Y = 200.0;
5979 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
5980 expect(Ok, status);
5981 expectf(53.033016, ptf[0].X);
5982 expectf(0.0, ptf[0].Y);
5983 expectf(106.066032, ptf[1].X);
5984 expectf(0.0, ptf[1].Y);
5985 expectf(79.549522, ptf[2].X);
5986 expectf(-26.516510, ptf[2].Y);
5987 expectf(79.549522, ptf[3].X);
5988 expectf(26.516508, ptf[3].Y);
5990 status = GdipCreateMatrix(&matrix);
5991 expect(Ok, status);
5992 status = GdipRotateMatrix(matrix, -45.0, MatrixOrderAppend);
5993 expect(Ok, status);
5994 status = GdipSetWorldTransform(graphics, matrix);
5995 expect(Ok, status);
5996 GdipDeleteMatrix(matrix);
5998 status = GdipGetClip(graphics, region);
5999 expect(Ok, status);
6000 status = GdipGetRegionHRgn(region, NULL, &hrgn);
6001 expect(Ok, status);
6002 ret = GetRgnBox(hrgn, &rc);
6003 ok(ret == COMPLEXREGION, "expected COMPLEXREGION, got %d\n", ret);
6004 ok((rc.left == -26 && rc.top == 54 && rc.right == 27 && rc.bottom == 107) ||
6005 /* rounding under Wine is slightly different */
6006 (rc.left == -27 && rc.top == 54 && rc.right == 27 && rc.bottom == 106) /* Wine */,
6007 "expected -26,54-27,107, got %s\n", wine_dbgstr_rect(&rc));
6008 DeleteObject(hrgn);
6009 status = GdipGetRegionHRgn(region, graphics, &hrgn);
6010 expect(Ok, status);
6011 ret = GetRgnBox(hrgn, &rc);
6012 ok(ret == SIMPLEREGION, "expected SIMPLEREGION, got %d\n", ret);
6013 ok(rc.left == 100 && rc.top == 100 && rc.right == 200 && rc.bottom == 200,
6014 "expected 100,100-200,200, got %s\n", wine_dbgstr_rect(&rc));
6015 DeleteObject(hrgn);
6017 ptf[0].X = 100.0;
6018 ptf[0].Y = 100.0;
6019 ptf[1].X = 200.0;
6020 ptf[1].Y = 200.0;
6021 ptf[2].X = 200.0;
6022 ptf[2].Y = 100.0;
6023 ptf[3].X = 100.0;
6024 ptf[3].Y = 200.0;
6025 status = GdipTransformPoints(graphics, CoordinateSpaceWorld, CoordinateSpaceDevice, ptf, 4);
6026 expect(Ok, status);
6027 expectf(0.0, ptf[0].X);
6028 expectf(53.033005, ptf[0].Y);
6029 expectf(0.0, ptf[1].X);
6030 expectf(106.066010, ptf[1].Y);
6031 expectf(26.516491, ptf[2].X);
6032 expectf(79.549507, ptf[2].Y);
6033 expectf(-26.516520, ptf[3].X);
6034 expectf(79.549500, ptf[3].Y);
6036 GdipDeleteRegion(region);
6037 GdipDeleteGraphics(graphics);
6038 DeleteDC(hdc);
6042 static void test_GdipFillRectangles(void)
6044 GpStatus status;
6045 GpGraphics *graphics = NULL;
6046 GpBrush *brush = NULL;
6047 HDC hdc = GetDC( hwnd );
6048 GpRectF rects[2] = {{0,0,10,10}, {10,10,10,10}};
6050 ok(hdc != NULL, "Expected HDC to be initialized\n");
6052 status = GdipCreateFromHDC(hdc, &graphics);
6053 expect(Ok, status);
6054 ok(graphics != NULL, "Expected graphics to be initialized\n");
6056 status = GdipCreateSolidFill((ARGB)0xffff00ff, (GpSolidFill**)&brush);
6057 expect(Ok, status);
6058 ok(brush != NULL, "Expected brush to be initialized\n");
6060 status = GdipFillRectangles(NULL, brush, rects, 2);
6061 expect(InvalidParameter, status);
6063 status = GdipFillRectangles(graphics, NULL, rects, 2);
6064 expect(InvalidParameter, status);
6066 status = GdipFillRectangles(graphics, brush, NULL, 2);
6067 expect(InvalidParameter, status);
6069 status = GdipFillRectangles(graphics, brush, rects, 0);
6070 expect(InvalidParameter, status);
6072 status = GdipFillRectangles(graphics, brush, rects, -1);
6073 expect(InvalidParameter, status);
6075 status = GdipFillRectangles(graphics, brush, rects, 1);
6076 expect(Ok, status);
6078 status = GdipFillRectangles(graphics, brush, rects, 2);
6079 expect(Ok, status);
6081 GdipDeleteBrush(brush);
6082 GdipDeleteGraphics(graphics);
6084 ReleaseDC(hwnd, hdc);
6087 static void test_GdipGetVisibleClipBounds_memoryDC(void)
6089 HDC hdc,dc;
6090 HBITMAP bmp;
6091 HGDIOBJ old;
6092 RECT rect;
6093 POINT pt;
6094 int width = 0;
6095 int height = 0;
6096 GpGraphics* graphics = NULL;
6097 GpRect boundRect;
6098 GpStatus status;
6100 ok(GetClientRect(hwnd, &rect), "GetClientRect should have succeeded\n");
6101 width = rect.right - rect.left;
6102 height = rect.bottom - rect.top;
6104 dc = GetDC(hwnd);
6105 hdc = CreateCompatibleDC ( dc );
6106 bmp = CreateCompatibleBitmap ( dc, width, height );
6107 old = SelectObject (hdc, bmp);
6109 /*change the window origin is the key test point*/
6110 SetWindowOrgEx (hdc, rect.left+10, rect.top+10, &pt);
6112 status = GdipCreateFromHDC(hdc, &graphics);
6113 expect(Ok, status);
6115 status = GdipGetVisibleClipBoundsI(graphics, &boundRect);
6116 expect(Ok, status);
6118 ok(boundRect.X==rect.left+10 &&
6119 boundRect.Y==rect.top+10 &&
6120 boundRect.Width==width &&
6121 boundRect.Height==height, "Expected GdipGetVisibleClipBoundsI ok\n");
6123 status = GdipSetClipRectI(graphics, 0, 0, width, height, CombineModeReplace);
6124 expect(Ok, status);
6126 status = GdipGetVisibleClipBoundsI(graphics, &boundRect);
6127 expect(Ok, status);
6129 ok(boundRect.X==rect.left+10 &&
6130 boundRect.Y==rect.top+10 &&
6131 boundRect.Width==width-10 &&
6132 boundRect.Height==height-10, "Expected GdipGetVisibleClipBoundsI ok\n");
6134 GdipDeleteGraphics(graphics);
6136 SelectObject (hdc, old);
6137 DeleteObject (bmp);
6138 DeleteDC (hdc);
6139 ReleaseDC(hwnd, dc);
6142 static void test_container_rects(void)
6144 GpStatus status;
6145 GpGraphics *graphics;
6146 HDC hdc = GetDC( hwnd );
6147 GpRectF dstrect, srcrect;
6148 GraphicsContainer state;
6149 static const GpPointF test_points[3] = {{0.0,0.0}, {1.0,0.0}, {0.0,1.0}};
6150 GpPointF points[3];
6151 REAL dpix, dpiy;
6153 status = GdipCreateFromHDC(hdc, &graphics);
6154 expect(Ok, status);
6156 dstrect.X = 0.0;
6157 dstrect.Y = 0.0;
6158 dstrect.Width = 1.0;
6159 dstrect.Height = 1.0;
6160 srcrect = dstrect;
6162 status = GdipGetDpiX(graphics, &dpix);
6163 expect(Ok, status);
6165 status = GdipGetDpiY(graphics, &dpiy);
6166 expect(Ok, status);
6168 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitWorld, &state);
6169 expect(InvalidParameter, status);
6171 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitDisplay, &state);
6172 expect(InvalidParameter, status);
6174 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitMillimeter+1, &state);
6175 expect(InvalidParameter, status);
6177 status = GdipBeginContainer(NULL, &dstrect, &srcrect, UnitPixel, &state);
6178 expect(InvalidParameter, status);
6180 status = GdipBeginContainer(graphics, NULL, &srcrect, UnitPixel, &state);
6181 expect(InvalidParameter, status);
6183 status = GdipBeginContainer(graphics, &dstrect, NULL, UnitPixel, &state);
6184 expect(InvalidParameter, status);
6186 status = GdipBeginContainer(graphics, &dstrect, &srcrect, -1, &state);
6187 expect(InvalidParameter, status);
6189 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitPixel, NULL);
6190 expect(InvalidParameter, status);
6192 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitPixel, &state);
6193 expect(Ok, status);
6195 memcpy(points, test_points, sizeof(points));
6196 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6197 expect(Ok, status);
6198 expectf(0.0, points[0].X);
6199 expectf(0.0, points[0].Y);
6200 expectf(1.0, points[1].X);
6201 expectf(0.0, points[1].Y);
6202 expectf(0.0, points[2].X);
6203 expectf(1.0, points[2].Y);
6205 status = GdipEndContainer(graphics, state);
6206 expect(Ok, status);
6208 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitInch, &state);
6209 expect(Ok, status);
6211 memcpy(points, test_points, sizeof(points));
6212 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6213 expect(Ok, status);
6214 expectf(0.0, points[0].X);
6215 expectf(0.0, points[0].Y);
6216 expectf(1.0/dpix, points[1].X);
6217 expectf(0.0, points[1].Y);
6218 expectf(0.0, points[2].X);
6219 expectf(1.0/dpiy, points[2].Y);
6221 status = GdipEndContainer(graphics, state);
6222 expect(Ok, status);
6224 status = GdipScaleWorldTransform(graphics, 2.0, 2.0, MatrixOrderPrepend);
6225 expect(Ok, status);
6227 dstrect.X = 1.0;
6228 dstrect.Height = 3.0;
6229 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitPixel, &state);
6230 expect(Ok, status);
6232 memcpy(points, test_points, sizeof(points));
6233 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6234 expect(Ok, status);
6235 expectf(2.0, points[0].X);
6236 expectf(0.0, points[0].Y);
6237 expectf(4.0, points[1].X);
6238 expectf(0.0, points[1].Y);
6239 expectf(2.0, points[2].X);
6240 expectf(6.0, points[2].Y);
6242 status = GdipEndContainer(graphics, state);
6243 expect(Ok, status);
6245 memcpy(points, test_points, sizeof(points));
6246 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6247 expect(Ok, status);
6248 expectf(0.0, points[0].X);
6249 expectf(0.0, points[0].Y);
6250 expectf(2.0, points[1].X);
6251 expectf(0.0, points[1].Y);
6252 expectf(0.0, points[2].X);
6253 expectf(2.0, points[2].Y);
6255 status = GdipResetWorldTransform(graphics);
6256 expect(Ok, status);
6258 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitInch, &state);
6259 expect(Ok, status);
6261 memcpy(points, test_points, sizeof(points));
6262 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6263 expect(Ok, status);
6264 expectf(1.0, points[0].X);
6265 expectf(0.0, points[0].Y);
6266 expectf((dpix+1.0)/dpix, points[1].X);
6267 expectf(0.0, points[1].Y);
6268 expectf(1.0, points[2].X);
6269 expectf(3.0/dpiy, points[2].Y);
6271 status = GdipEndContainer(graphics, state);
6272 expect(Ok, status);
6274 status = GdipSetPageUnit(graphics, UnitInch);
6275 expect(Ok, status);
6277 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitPixel, &state);
6278 expect(Ok, status);
6280 memcpy(points, test_points, sizeof(points));
6281 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6282 expect(Ok, status);
6283 expectf(dpix, points[0].X);
6284 expectf(0.0, points[0].Y);
6285 expectf(dpix*2, points[1].X);
6286 expectf(0.0, points[1].Y);
6287 expectf(dpix, points[2].X);
6288 expectf(dpiy*3, points[2].Y);
6290 status = GdipEndContainer(graphics, state);
6291 expect(Ok, status);
6293 status = GdipBeginContainer(graphics, &dstrect, &srcrect, UnitInch, &state);
6294 expect(Ok, status);
6296 memcpy(points, test_points, sizeof(points));
6297 status = GdipTransformPoints(graphics, CoordinateSpaceDevice, CoordinateSpaceWorld, points, 3);
6298 expect(Ok, status);
6299 expectf(dpix, points[0].X);
6300 expectf(0.0, points[0].Y);
6301 expectf(dpix+1.0, points[1].X);
6302 expectf(0.0, points[1].Y);
6303 expectf(dpix, points[2].X);
6304 expectf(3.0, points[2].Y);
6306 status = GdipEndContainer(graphics, state);
6307 expect(Ok, status);
6309 GdipDeleteGraphics(graphics);
6311 ReleaseDC(hwnd, hdc);
6314 static void test_GdipGraphicsSetAbort(void)
6316 HDC hdc;
6317 GpStatus status;
6318 GpGraphics *graphics;
6320 if (!pGdipGraphicsSetAbort)
6322 win_skip("GdipGraphicsSetAbort() is not supported.\n");
6323 return;
6326 hdc = GetDC(hwnd);
6328 status = GdipCreateFromHDC(hdc, &graphics);
6329 expect(Ok, status);
6331 status = pGdipGraphicsSetAbort(NULL, NULL);
6332 expect(InvalidParameter, status);
6334 status = pGdipGraphicsSetAbort(graphics, NULL);
6335 expect(Ok, status);
6337 GdipDeleteGraphics(graphics);
6339 ReleaseDC(hwnd, hdc);
6342 #define BLUE_COLOR (0xff0000ff)
6343 #define is_blue_color(color) ( ((color) & 0x00ffffff) == 0xff )
6344 #define get_bitmap_pixel(x,y) pixel[(y)*(width) + (x)]
6345 static DWORD* GetBitmapPixelBuffer(HDC hdc, HBITMAP hbmp, int width, int height)
6347 BITMAPINFOHEADER bi;
6348 UINT lines = 0;
6349 DWORD *buffer = (DWORD *)GdipAlloc(width*height*4);
6351 bi.biSize = sizeof(BITMAPINFOHEADER);
6352 bi.biWidth = width;
6353 bi.biHeight = -height; /*very Important, set negative, indicating a top-down DIB*/
6354 bi.biPlanes = 1;
6355 bi.biBitCount = 32;
6356 bi.biCompression = BI_RGB;
6357 bi.biSizeImage = 0;
6358 bi.biXPelsPerMeter = 0;
6359 bi.biYPelsPerMeter = 0;
6360 bi.biClrUsed = 0;
6361 bi.biClrImportant = 0;
6363 lines = GetDIBits(hdc, hbmp, 0, height, buffer, (BITMAPINFO *)&bi, DIB_RGB_COLORS);
6364 ok(lines == height, "Expected GetDIBits:%p,%d->%d,%d\n", buffer, height, lines, GetLastError());
6366 return buffer;
6369 static void test_GdipFillRectanglesOnMemoryDCSolidBrush(void)
6371 ARGB color[6] = {0,0,0,0,0,0};
6372 POINT pt = {0,0};
6373 RECT rect = {100, 100, 180, 180};
6374 UINT width = rect.right - rect.left;
6375 UINT height = rect.bottom - rect.top;
6376 GpStatus status = 0;
6377 GpSolidFill *brush = NULL;
6378 GpGraphics *graphics = NULL;
6379 HDC dc = GetDC( hwnd);
6380 HDC hdc = CreateCompatibleDC(dc);
6381 HBITMAP bmp = CreateCompatibleBitmap(dc, width, height);
6382 HGDIOBJ old = SelectObject(hdc, bmp);
6383 DWORD* pixel = NULL;
6385 /*Change the window origin is the key test point*/
6386 SetWindowOrgEx(hdc, rect.left, rect.top, &pt);
6388 status = GdipCreateSolidFill(BLUE_COLOR, &brush);
6389 expect(Ok, status);
6391 status = GdipCreateFromHDC(hdc, &graphics);
6392 expect(Ok, status);
6394 status = GdipSetClipRectI(graphics, rect.left+width/2, rect.top+height/2,
6395 width, height, CombineModeReplace);
6396 expect(Ok, status);
6398 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, rect.right, rect.bottom);
6399 expect(Ok, status);
6401 GdipDeleteBrush((GpBrush*)brush);
6402 GdipDeleteGraphics(graphics);
6404 pixel = GetBitmapPixelBuffer(hdc, bmp, width, height);
6405 if (pixel)
6407 color[0] = get_bitmap_pixel(width/2, height/2);
6408 color[1] = get_bitmap_pixel(width/2+1, height/2);
6409 color[2] = get_bitmap_pixel(width/2, height/2+1);
6410 color[3] = get_bitmap_pixel(width/2-1, height/2-1);
6411 color[4] = get_bitmap_pixel(width/2-1, height-1);
6412 color[5] = get_bitmap_pixel(width-1, height/2-1);
6415 ok(is_blue_color(color[0]) && is_blue_color(color[1]) && is_blue_color(color[2]) &&
6416 color[3] == 0 && color[4] == 0 && color[5] == 0,
6417 "Expected GdipFillRectangleI take effect!\n" );
6418 GdipFree(pixel);
6420 SelectObject(hdc, old);
6421 DeleteObject(bmp);
6422 DeleteDC(hdc);
6423 ReleaseDC(hwnd, dc);
6426 static void test_GdipFillRectanglesOnMemoryDCTextureBrush(void)
6428 ARGB color[6] = {0,0,0,0,0,0};
6429 POINT pt = {0,0};
6430 RECT rect = {100, 100, 180, 180};
6431 UINT width = rect.right - rect.left;
6432 UINT height = rect.bottom - rect.top;
6433 GpStatus status = 0;
6434 union
6436 GpBitmap *bitmap;
6437 GpImage *image;
6438 } src_img;
6439 GpTexture *brush = NULL;
6440 GpGraphics *graphics = NULL;
6441 HDC dc = GetDC( hwnd);
6442 HDC hdc = CreateCompatibleDC(dc);
6443 HBITMAP bmp = CreateCompatibleBitmap(dc, width, height);
6444 HGDIOBJ old = SelectObject(hdc, bmp);
6446 UINT x = 0;
6447 UINT y = 0;
6448 UINT src_img_width = width/2;
6449 UINT src_img_height = height/2;
6450 BYTE *src_img_data = GdipAlloc(src_img_width*src_img_height*4);
6451 DWORD *pixel = (DWORD *)src_img_data;
6452 ok(pixel != NULL, "Expected src_img_data is valid\n");
6454 /*Change the window origin is the key test point*/
6455 SetWindowOrgEx(hdc, rect.left, rect.top, &pt);
6457 /*build a blue solid image!*/
6458 for(y = 0; y < src_img_height; ++y)
6460 for(x = 0; x < src_img_width; ++x)
6462 pixel[x] = BLUE_COLOR;
6465 pixel += src_img_width;
6468 status = GdipCreateBitmapFromScan0(src_img_width, src_img_height, src_img_width*4,
6469 PixelFormat32bppARGB, src_img_data, &src_img.bitmap);
6470 expect(Ok, status);
6472 status = GdipCreateTexture(src_img.image, 0, &brush);
6473 expect(Ok, status);
6475 status = GdipCreateFromHDC(hdc, &graphics);
6476 expect(Ok, status);
6478 status = GdipSetClipRectI(graphics, rect.left+width/2, rect.top+height/2,
6479 width, height, CombineModeReplace);
6480 expect(Ok, status);
6482 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, rect.right, rect.bottom);
6483 expect(Ok, status);
6485 GdipDisposeImage(src_img.image);
6486 GdipDeleteBrush((GpBrush*)brush);
6487 GdipDeleteGraphics(graphics);
6488 GdipFree(src_img_data);
6490 pixel = GetBitmapPixelBuffer(hdc, bmp, width, height);
6491 if (pixel)
6493 color[0] = get_bitmap_pixel(width/2, height/2);
6494 color[1] = get_bitmap_pixel(width/2+1, height/2);
6495 color[2] = get_bitmap_pixel(width/2, height/2+1);
6496 color[3] = get_bitmap_pixel(width/2-1, height/2-1);
6497 color[4] = get_bitmap_pixel(width/2-1, height-1);
6498 color[5] = get_bitmap_pixel(width-1, height/2-1);
6500 ok(is_blue_color(color[0]) && is_blue_color(color[1]) && is_blue_color(color[2]) &&
6501 color[3] == 0 && color[4] == 0 && color[5] == 0,
6502 "Expected GdipFillRectangleI take effect!\n" );
6503 GdipFree(pixel);
6505 SelectObject(hdc, old);
6506 DeleteObject(bmp);
6507 DeleteDC(hdc);
6508 ReleaseDC(hwnd, dc);
6511 static void test_GdipFillRectanglesOnBitmapTextureBrush(void)
6513 ARGB color[6] = {0,0,0,0,0,0};
6514 UINT x = 0;
6515 UINT y = 0;
6516 RECT rect = {100, 100, 180, 180};
6517 UINT width = rect.right - rect.left;
6518 UINT height = rect.bottom - rect.top;
6519 UINT src_img_width = width/2;
6520 UINT src_img_height = height/2;
6522 GpStatus status = 0;
6523 union
6525 GpBitmap *bitmap;
6526 GpImage *image;
6527 } src_img;
6528 union
6530 GpBitmap *bitmap;
6531 GpImage *image;
6532 } dst_img;
6534 GpTexture *brush = NULL;
6535 GpGraphics *graphics = NULL;
6536 BYTE *src_img_data = GdipAlloc(src_img_width*src_img_height*4);
6537 DWORD *pixel = (DWORD *)src_img_data;
6538 ok(pixel != NULL, "Expected src_img_data is valid\n");
6540 status = GdipCreateBitmapFromScan0(width, height, width*4,
6541 PixelFormat32bppARGB, NULL, &dst_img.bitmap);
6542 expect(Ok, status);
6544 /*build a blue solid image!*/
6545 for(y = 0; y < src_img_height; ++y)
6547 for(x = 0; x < src_img_width; ++x)
6549 pixel[x] = BLUE_COLOR;
6552 pixel += src_img_width;
6555 status = GdipCreateBitmapFromScan0(src_img_width, src_img_height, src_img_width*4,
6556 PixelFormat32bppARGB, src_img_data, &src_img.bitmap);
6557 expect(Ok, status);
6559 status = GdipCreateTexture(src_img.image, 0, &brush);
6560 expect(Ok, status);
6562 status = GdipGetImageGraphicsContext(dst_img.image, &graphics);
6563 expect(Ok, status);
6565 status = GdipSetClipRectI(graphics, 0, 0, width, height, CombineModeReplace);
6566 expect(Ok, status);
6568 status = GdipFillRectangleI(graphics, (GpBrush*)brush, 0, 0, width/2, height/2);
6569 expect(Ok, status);
6571 GdipDeleteBrush((GpBrush*)brush);
6572 GdipDeleteGraphics(graphics);
6574 GdipBitmapGetPixel(dst_img.bitmap, 0, 0, &color[0]);
6575 GdipBitmapGetPixel(dst_img.bitmap, 0, 1, &color[1]);
6576 GdipBitmapGetPixel(dst_img.bitmap, 1, 0, &color[2]);
6577 GdipBitmapGetPixel(dst_img.bitmap, width/2, 0, &color[3]);
6578 GdipBitmapGetPixel(dst_img.bitmap, width/2, height/2, &color[4]);
6579 GdipBitmapGetPixel(dst_img.bitmap, 0, height/2, &color[5]);
6581 ok(is_blue_color(color[0]) && is_blue_color(color[1]) && is_blue_color(color[2]) &&
6582 color[3] == 0 && color[4] == 0 && color[5] == 0,
6583 "Expected GdipFillRectangleI take effect!\n" );
6585 GdipDisposeImage(src_img.image);
6586 GdipDisposeImage(dst_img.image);
6587 GdipFree(src_img_data);
6590 static void test_GdipDrawImagePointsRectOnMemoryDC(void)
6592 ARGB color[6] = {0,0,0,0,0,0};
6593 POINT pt = {0,0};
6594 RECT rect = {100, 100, 180, 180};
6595 UINT width = rect.right - rect.left;
6596 UINT height = rect.bottom - rect.top;
6597 GpStatus status = 0;
6598 union
6600 GpBitmap *bitmap;
6601 GpImage *image;
6602 } src_img;
6603 GpGraphics *graphics = NULL;
6604 HDC dc = GetDC( hwnd);
6605 HDC hdc = CreateCompatibleDC(dc);
6606 HBITMAP bmp = CreateCompatibleBitmap(dc, width, height);
6607 HGDIOBJ old = SelectObject(hdc, bmp);
6609 UINT x = 0;
6610 UINT y = 0;
6611 UINT src_img_width = width/2;
6612 UINT src_img_height = height/2;
6613 BYTE *src_img_data = GdipAlloc(src_img_width*src_img_height*4);
6614 DWORD *pixel = (DWORD *)src_img_data;
6615 ok(pixel != NULL, "Expected src_img_data is valid\n");
6617 /*Change the window origin is the key test point*/
6618 SetWindowOrgEx(hdc, rect.left, rect.top, &pt);
6620 /*build a blue solid image!*/
6621 for(y = 0; y < src_img_height; ++y)
6623 for(x = 0; x < src_img_width; ++x)
6625 pixel[x] = BLUE_COLOR;
6628 pixel += src_img_width;
6631 status = GdipCreateBitmapFromScan0(src_img_width, src_img_height, src_img_width*4,
6632 PixelFormat32bppARGB, src_img_data, &src_img.bitmap);
6633 expect(Ok, status);
6635 status = GdipCreateFromHDC(hdc, &graphics);
6636 expect(Ok, status);
6638 status = GdipDrawImageRectRectI(graphics, src_img.image,
6639 rect.left+width/2, rect.top+height/2, width/2, height/2,
6640 0, 0, src_img_width, src_img_height, UnitPixel, NULL, NULL, NULL);
6641 expect(Ok, status);
6643 GdipDisposeImage(src_img.image);
6644 GdipDeleteGraphics(graphics);
6645 GdipFree(src_img_data);
6647 pixel = GetBitmapPixelBuffer(hdc, bmp, width, height);
6648 if (pixel)
6650 color[0] = get_bitmap_pixel(width/2, height/2);
6651 color[1] = get_bitmap_pixel(width/2+1, height/2);
6652 color[2] = get_bitmap_pixel(width/2, height/2+1);
6653 color[3] = get_bitmap_pixel(width/2-1, height/2-1);
6654 color[4] = get_bitmap_pixel(width/2-1, height-1);
6655 color[5] = get_bitmap_pixel(width-1, height/2-1);
6657 ok(is_blue_color(color[0]) && is_blue_color(color[1]) && is_blue_color(color[2]) &&
6658 color[3] == 0 && color[4] == 0 && color[5] == 0,
6659 "Expected GdipDrawImageRectRectI take effect!\n" );
6660 GdipFree(pixel);
6662 SelectObject(hdc, old);
6663 DeleteObject(bmp);
6664 DeleteDC(hdc);
6665 ReleaseDC(hwnd, dc);
6668 static void test_cliphrgn_transform(void)
6670 HDC hdc;
6671 GpStatus status;
6672 GpGraphics *graphics;
6673 HRGN rgn;
6674 RectF rectf;
6675 BOOL res;
6677 hdc = GetDC(hwnd);
6679 SetViewportOrgEx(hdc, 10, 10, NULL);
6681 status = GdipCreateFromHDC(hdc, &graphics);
6682 expect(Ok, status);
6684 rgn = CreateRectRgn(0, 0, 100, 100);
6686 status = GdipSetClipHrgn(graphics, rgn, CombineModeReplace);
6687 expect(Ok, status);
6689 status = GdipGetVisibleClipBounds(graphics, &rectf);
6690 expect(Ok, status);
6691 expectf(-10.0, rectf.X);
6692 expectf(-10.0, rectf.Y);
6693 expectf(100.0, rectf.Width);
6694 expectf(100.0, rectf.Height);
6696 status = GdipIsVisiblePoint(graphics, 95, 95, &res);
6697 expect(Ok, status);
6698 expect(FALSE, res);
6700 status = GdipIsVisiblePoint(graphics, -5, -5, &res);
6701 expect(Ok, status);
6702 expect(TRUE, res);
6704 DeleteObject(rgn);
6706 GdipDeleteGraphics(graphics);
6708 SetViewportOrgEx(hdc, 0, 0, NULL);
6710 ReleaseDC(hwnd, hdc);
6713 static void test_hdc_caching(void)
6715 GpStatus status;
6716 HDC hdc;
6717 HBITMAP hbm;
6718 GpGraphics *graphics;
6719 ULONG *bits;
6720 BITMAPINFO bmi;
6721 HRGN hrgn;
6722 GpBrush *brush;
6724 hdc = CreateCompatibleDC(0);
6725 ok(hdc != NULL, "CreateCompatibleDC failed\n");
6726 bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
6727 bmi.bmiHeader.biHeight = -5;
6728 bmi.bmiHeader.biWidth = 5;
6729 bmi.bmiHeader.biBitCount = 32;
6730 bmi.bmiHeader.biPlanes = 1;
6731 bmi.bmiHeader.biCompression = BI_RGB;
6732 bmi.bmiHeader.biClrUsed = 0;
6734 hbm = CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, (void**)&bits, NULL, 0);
6735 ok(hbm != NULL, "CreateDIBSection failed\n");
6737 SelectObject(hdc, hbm);
6739 SetViewportOrgEx(hdc, 1, 1, NULL);
6741 hrgn = CreateRectRgn(0, 0, 3, 3);
6742 SelectClipRgn(hdc, hrgn);
6743 DeleteObject(hrgn);
6745 status = GdipCreateSolidFill((ARGB)0xffaaaaaa, (GpSolidFill**)&brush);
6746 expect(Ok, status);
6748 status = GdipCreateFromHDC(hdc, &graphics);
6749 expect(Ok, status);
6751 memset(bits, 0, sizeof(*bits) * 25);
6752 status = GdipFillRectangleI(graphics, brush, 0, 0, 4, 4);
6753 expect(Ok, status);
6755 expect(0, bits[0]);
6756 expect(0xffaaaaaa, bits[6]);
6757 expect(0xffaaaaaa, bits[12]);
6758 expect(0, bits[18]);
6759 expect(0, bits[24]);
6761 SetViewportOrgEx(hdc, 0, 0, NULL);
6762 OffsetClipRgn(hdc, 2, 2);
6764 memset(bits, 0, sizeof(*bits) * 25);
6765 status = GdipFillRectangleI(graphics, brush, 0, 0, 4, 4);
6766 expect(Ok, status);
6768 expect(0, bits[0]);
6769 expect(0xffaaaaaa, bits[6]);
6770 expect(0xffaaaaaa, bits[12]);
6771 expect(0, bits[18]);
6772 expect(0, bits[24]);
6774 GdipDeleteGraphics(graphics);
6776 GdipDeleteBrush(brush);
6778 DeleteDC(hdc);
6779 DeleteObject(hbm);
6782 START_TEST(graphics)
6784 struct GdiplusStartupInput gdiplusStartupInput;
6785 ULONG_PTR gdiplusToken;
6786 WNDCLASSA class;
6787 HMODULE gdiplus_mod = GetModuleHandleA("gdiplus.dll");
6788 HMODULE hmsvcrt;
6789 int (CDECL * _controlfp_s)(unsigned int *cur, unsigned int newval, unsigned int mask);
6791 /* Enable all FP exceptions except _EM_INEXACT, which gdi32 can trigger */
6792 hmsvcrt = LoadLibraryA("msvcrt");
6793 _controlfp_s = (void*)GetProcAddress(hmsvcrt, "_controlfp_s");
6794 if (_controlfp_s) _controlfp_s(0, 0, 0x0008001e);
6796 pGdipGraphicsSetAbort = (void*)GetProcAddress(gdiplus_mod, "GdipGraphicsSetAbort");
6798 memset( &class, 0, sizeof(class) );
6799 class.lpszClassName = "gdiplus_test";
6800 class.style = CS_HREDRAW | CS_VREDRAW;
6801 class.lpfnWndProc = DefWindowProcA;
6802 class.hInstance = GetModuleHandleA(0);
6803 class.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
6804 class.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
6805 class.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
6806 RegisterClassA( &class );
6807 hwnd = CreateWindowA( "gdiplus_test", "graphics test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
6808 CW_USEDEFAULT, CW_USEDEFAULT, 200, 200, 0, 0, GetModuleHandleA(0), 0 );
6809 ok(hwnd != NULL, "Expected window to be created\n");
6811 gdiplusStartupInput.GdiplusVersion = 1;
6812 gdiplusStartupInput.DebugEventCallback = NULL;
6813 gdiplusStartupInput.SuppressBackgroundThread = 0;
6814 gdiplusStartupInput.SuppressExternalCodecs = 0;
6816 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
6818 test_clipping();
6819 test_clipping_2();
6820 test_measured_extra_space();
6821 test_measure_string();
6822 test_font_height_scaling();
6823 test_transform();
6824 test_pen_thickness();
6825 test_GdipMeasureString();
6826 test_constructor_destructor();
6827 test_save_restore();
6828 test_GdipFillClosedCurve2();
6829 test_GdipFillClosedCurve2I();
6830 test_GdipDrawBezierI();
6831 test_GdipDrawArc();
6832 test_GdipDrawArcI();
6833 test_GdipDrawCurve();
6834 test_GdipDrawCurveI();
6835 test_GdipDrawCurve2();
6836 test_GdipDrawCurve2I();
6837 test_GdipDrawCurve3();
6838 test_GdipDrawCurve3I();
6839 test_GdipDrawLineI();
6840 test_GdipDrawLinesI();
6841 test_GdipDrawImagePointsRect();
6842 test_GdipFillClosedCurve();
6843 test_GdipFillClosedCurveI();
6844 test_GdipFillPath();
6845 test_GdipDrawString();
6846 test_GdipGetNearestColor();
6847 test_GdipGetVisibleClipBounds();
6848 test_GdipIsVisiblePoint();
6849 test_GdipIsVisibleRect();
6850 test_Get_Release_DC();
6851 test_BeginContainer2();
6852 test_transformpoints();
6853 test_get_set_clip();
6854 test_clip_xform();
6855 test_isempty();
6856 test_clear();
6857 test_textcontrast();
6858 test_fromMemoryBitmap();
6859 test_string_functions();
6860 test_get_set_interpolation();
6861 test_get_set_textrenderinghint();
6862 test_getdc_scaled();
6863 test_alpha_hdc();
6864 test_bitmapfromgraphics();
6865 test_GdipFillRectangles();
6866 test_GdipGetVisibleClipBounds_memoryDC();
6867 test_GdipFillRectanglesOnMemoryDCSolidBrush();
6868 test_GdipFillRectanglesOnMemoryDCTextureBrush();
6869 test_GdipFillRectanglesOnBitmapTextureBrush();
6870 test_GdipDrawImagePointsRectOnMemoryDC();
6871 test_container_rects();
6872 test_GdipGraphicsSetAbort();
6873 test_cliphrgn_transform();
6874 test_hdc_caching();
6876 GdiplusShutdown(gdiplusToken);
6877 DestroyWindow( hwnd );